BabylonJS / Editor

Community managed visual editor for Babylon.js
http://editor.babylonjs.com/
813 stars 232 forks source link

scene.babylon does not save correctly from editor, and cannot load in a web project #127

Closed the-simian closed 4 years ago

the-simian commented 4 years ago

error message: Unable to load from ./scene/scene.babylon: Error in onSuccess callback

Howdy! I have been trying to experiment with workflows and the Babylonjs editor. Currently I wanted to see if one could alter a scene, and save it in a web project, make changes and then export again.

Right now, saving a scene and reloading works, but the exported project doesn't seem to properly load the scene.

BJS - [16:30:17]: Unable to load from ./scene/scene.babylon: Error in onSuccess callback
./Misc/logger.ts.Logger._ErrorEnabled @ logger.ts:83
errorHandler @ sceneLoader.ts:740
successHandler @ sceneLoader.ts:762
(anonymous) @ sceneLoader.ts:777
dataCallback @ sceneLoader.ts:388
onReadyStateChange @ tools.ts:915
XMLHttpRequest.send (async)
(anonymous) @ VM7878:1
./Misc/webRequest.ts.WebRequest.send @ webRequest.ts:119
retryLoop @ tools.ts:942
requestFile @ tools.ts:945
./Misc/tools.ts.Tools.LoadFile @ tools.ts:986
manifestChecked @ sceneLoader.ts:412
Database @ database.ts:69
./Offline/database.ts._Engines_engine__WEBPACK_IMPORTED_MODULE_3__.Engine.OfflineProviderFactory @ database.ts:10
./Loading/sceneLoader.ts.SceneLoader._loadData @ sceneLoader.ts:444
./Loading/sceneLoader.ts.SceneLoader.Append @ sceneLoader.ts:769
./Loading/sceneLoader.ts.SceneLoader.Load @ sceneLoader.ts:679
Game.run @ game.ts:36
(anonymous) @ (index):74
Promise.then (async)
(anonymous) @ (index):71

Is there an example of a working project that was templated from the most recent build? ~3.0.0~ 3.1.0

A few things:

the-simian commented 4 years ago

Ok I see the core issue (I think). the scene.babylon file is totally empty.

{
    "autoClear": true,
    "clearColor": [
        0,
        0,
        0,
        1
    ],
    "ambientColor": [
        0,
        0,
        0
    ],
    "gravity": [
        0,
        -9.807,
        0
    ],
    "collisionsEnabled": true,
    "morphTargetManagers": [],
    "lights": [],
    "cameras": [],
    "activeCameraID": "Editor Camera",
    "animations": [],
    "materials": [],
    "multiMaterials": [],
    "skeletons": [],
    "transformNodes": [],
    "geometries": {
        "boxes": [],
        "spheres": [],
        "cylinders": [],
        "toruses": [],
        "grounds": [],
        "planes": [],
        "torusKnots": [],
        "vertexData": []
    },
    "meshes": [],
    "particleSystems": [],
    "sounds": [],
    "shadowGenerators": []
}

The editorproject is fine, and it loads, I can see things like the name I set for the camer and stuff in that JSON, but this one is always empty. When I explore the scene object I can see the corresponding properties like meshes, cameras and so on - they're empty too. I think that is why there's never an active camera, because there's not any camera.

the-simian commented 4 years ago

Ok after experimenting, I can say that I'm getting unusual results. I've seen a lot of differnt things, either saving or exporting the template. I can see that saving writes the /scene folder and also export template. They do this if the scene is not already there.

Ok so the scene .babylon file sometimes is empty like I posted above.. sometimes it also has extra stufff in it like this: image

I can also export template and I get a file named like this: image

i can paste that file into the scene.babylon file and I see a bit more action in the console. image You can see the materials are now here...

But meshes is still empty image

Active camera and cameras are undefined. image

I think, fundamentally the scene.babylon file is not being saved correctly, both on save, save as... and export template. I think what I would expect is that resaving would write over the /scene folder in the template with the updated scene.babylon

I'm gonna rename this issue. I'd love any feedback, and anything you can say that might help. I might be misusing the tool, but I'd love to help resolve this! Even if you point me in the right place I might be able to open a PR

Also a question: when you do a build should you also transport the /scene to the .build? It doesn't seem to need to do this, but to be honest, that's what I would have expected to happen, basically the entire .build folder has everything it would need, assets included.

julien-moreau commented 4 years ago

Hi @the-simian ! Thanks a lot for reporting that and with all these informations! Really nice work!

I'm trying to find a solution for the active camera. Also, the scene files (scene blablalblalblbabajhj-gze-zgevfez-fze-fze-fze.babylon) must not be exporter so I have a real bug. The scenes are just temporary scenes serialized for when the user wants to test and debug.

I reproduced the bug. I'm fixing right now. Looks tricky :)

julien-moreau commented 4 years ago

@the-simian ok found the issue! Was introduced in the 3.0.0. The source scene files and the final one had the same name and there were a concurrence when writing the file's content on the disk. Tricky bug. It has just been fixed. Have you the possibiliy to build the editor? If yes, can you confirm that it works as expected?

Also, if you have any suggestion to improve the editor workflow, don't hesitate because I'm really open to any suggestion :)

Thanks!

the-simian commented 4 years ago

@julien-moreau : Wow! All I can say is thank you for a quick reply. I will happily give you feedback about the editor, and I'll go a step farther: I think I'd be interested in writing documentation to replace the existing documentation. I think I might be able to help contribute.

As for feedback about the workflow, I am already sure I can give you good quality feedback. Should i do that here, or should I do it in the babylon forums? Where is your preferred workspace?

As for the documentation, can I just submit a PR for that somewhere? Maybe I could submit to the wiki here for review? I am open to suggestion.

To the matter at hand: I will 100% be happy to verify the fix as soon as it is available, and will post here. Again, thank you!

Since you asked I can give you my thoughts so far and what attracted me to this project:

I will say generally, the value I see in the editor workflow is about scene editing, but less so about code-management. The thing that is difficult working 'code first' is the simple act of placing items and having a sense of orchestrating items in a scene. After I have the stage set, my instinct is to grab references to the items and then add additional functionality code-first. I think I will have more feedback after having used the editor for a while. Ideally, I imagine editing/placing meshes in a scene in the editor, and that scene outputs to a scene folder inside of a project. I can keep many scenes in this folder, and I can open them and edit them one at a time in the editor. I manage scene transitions in the code.

To make an analogy, I manage a project called create-phaser-app that abides by this. You use Tiled (in this case) to conceptualize the levels. You handle things like behavior in the code, such as with a Finite State Machine. It is hard to edit a tile-based level code first, and its difficult (in my opinion) to really assign behavior without unbridled access to the full range of code patterns. You can decorate the tiles in Tiled with certain properties you manage with behaviors in the code. For instance: you drop a tile that is a health pickup, and you give it a value of say "amount": "25". Now it is the game's responsibility to handle behaviors when a player collides with the pickup.

Big picture: you use tools to build hard-to-conceptualize pieces such as levels, sounds, animations and you use coding patterns to assemble them. Phaser has very sophisticated scene management, such as level changes and so on. These are usually the result of state changes in the system (eg. life === 0 so game.state.start('game-over-screen) ). I am still unsure how this tool fits in the context of this kind of state management.

Before I speak more to this I want to experiment with the workflow this editor has related to managing animations, states, and behaviors and see how it feels. It feel like I am just now scratching the surface of what it has to offer, and I am excited to learn more.

julien-moreau commented 4 years ago

@the-simian I love you, nothing makes me more happy than a user with the want of contributing and provide feedbacks to help improving the project!

To contribute to the documentation, the documentation repository is available here: https://github.com/BabylonJS/Documentation For the editor, all markdowns are available here: https://github.com/BabylonJS/Documentation/tree/master/content/resources/Editor The markdowns must all be improved and I have a task for that. I'll focus on improving the documentation soon so don't hesitate to tell me once you begin working on the documentation :)

Looking to your project, it is excellent and really smooth! I don't think the BabylonJS Editor allows to provide such quality for instance, it typically misses a Terrain Editor. That means creating large worlds is not possible at the moment. Anyway, other points you mentioned are possible, by applying behaviors or metadatas (JSON) to each object you want to customize.

In other words, the Editor is not yet really focusing on gaming but more on scene designing. I'm trying to provide more and more tools to help creating content without coding as I 100% agree with you for the "code first" part.

Reading your message, it shows me that the Editor misses one more feature that is "export only final scene and its assets" like the "Export Template" feature but with only the "scene" folder. I'm adding ASAP :)

Can't wait for your feedbacks. I'm releasing the editor ASAP in version 3.1.1 :)

julien-moreau commented 4 years ago

Version 3.1.1 has just been deployed. Closing the issue as we are discussing on the forum :) Thanks a lot for reporting :)

the-simian commented 4 years ago

@julien-moreau Thank you again. I'll be looking into this today and I'll move any remaining feedback to the forum here: https://forum.babylonjs.com/t/saving-and-exporting-into-a-web-project-from-the-babylon-editor/3574