aws-samples / aws-tools-for-babylonjs-editor

AWS Tools for Babylon.JS Editor is a suite of tools meant to interact with Babylon.JS Editor by utilizing the capabilities of AWS products.
Apache License 2.0
32 stars 10 forks source link

Fix: textures/materials are not exported and reimported properly #2

Closed JuliaABurch closed 2 years ago

JuliaABurch commented 2 years ago

Notes

When adding a .gltf file to a scene through the BabylonJS editor, it expects certain pieces of metadata to be set on the textures and materials attached to a mesh so that the project-exporter correctly serializes it and the project-importer correctly re-creates it.

It would be nice if - instead of manually setting these properties ourselves - we could use the same functionality the editor does to import .gltf files in the scene, so that future updates to asset behavior doesn't break our plugin. I filed this feature request on the BabylonJS editor project, and consider this a workaround until a better alternative is made available.

Textures

The way that SceneLoader.LoadAssetContainer - which we use to add the .gltf to the scene - loads textures sets certain properties on those textures differently than the editor expects them. The editor is expecting relative paths to the assets directory of the open workspace (it will concatenate the absolute path of the assets directory with the texture path itself), and for the name property to be set as the path to the asset rather than the filename.

Materials

When the BabylonJS editor imports a .gltf file, it will add the mesh information to the .babylon scene information, and serialize the materials defined in the .gltf file to individual .material files upon the scene being saved. These material files assume they are placed in the same directory as the textures defined in them. It relies on the editorPath property being set so it knows where to serialize those files.

Testing

  1. Follow the instructions in the README for this repository to compile the code and add the plugin to the BabylonJS editor
  2. Create a new workspace
  3. Use the plugin to add a host to the scene: Sumerian Host Tools -> Add Host -> pick any host (but Fiona). See that the textures are attached correctly to the host.
  4. Save the project
  5. Reload the workspace. See that the host continues to have the correct textures rendered, even after being reimported.

Known issues

  1. The host will not properly load its animations and behaviors when the scene is reloaded. This will be fixed in a separate PR.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.