Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babylon.js 3D model importers (non-loader objects) not working consistently across microStudio versions/languages #211

Open
SugarRayLua opened this issue Jan 14, 2024 · 0 comments

Comments

@SugarRayLua
Copy link

Tried out what seem to be the two main Babylon.js methods to import 3D models with microStudio projects. Babylon.AssetManager seems to be the newer way to load 3D models, and it seems to work when using microScript 1.0 transpiled and lua but not any other version of microScript.

Problem:
After 3D model is imported, not able to modify imported mesh's properties (callback function seems to get triggered but mesh does not seem to be passed through to the callback function)

Reproducing problem:
Run script below (also uploaded to public microStudio server) first with microscript 1.0 transpiled and then again with newer version of microscript or non-transpiled version. Note how in the microscript 1.0 version, one is able to modify the mesh size but not in the other microscript versions

Code below:

init = function()
  scene = new BABYLON.Scene()
  camera = new BABYLON.FreeCamera("camera", new BABYLON.Vector3(0, 12.5, -170), scene)
  light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0), scene)
  // BABYLON.AssetsManager is a newer, comprehensive way to manage many 3D assets
  assetsManager = new BABYLON.AssetsManager(scene)
  // after creatining instance of AssetsManager, assign it a task
  // parameters ("pickNameForTask", "meshNamesSpecificallyWantElseLeaveNull"), "baseURLForAssets", "FileNameForAssets"
  meshTask = assetsManager.addMeshTask("task1","","https://assets.babylonjs.com/meshes/","both_houses_scene.babylon")
  // meshes are loaded asynch so define a callback function to do when meshes loaded
  // you can then modify assets in callback (e.g. incr y size of index 2 mesh by 20 below)
  meshTask.onSuccess = function(task) task.loadedMeshes[2].scaling.y=20 end
  // need to 'load' the AssetsManager to start the load
  assetsManager.load()
end

update = function()
end

draw = function()
  screen.render(scene)
end

Perhaps related, if change the script above to use the older method importing 3D models instead of AssetsManager:

BABYLON.SceneLoader.ImportMesh("","https://assets.babylonjs.com/meshes/","both_houses_scene.babylon",scene,
  function(newMeshes) newMeshes[0].scaling.x = 10 end)

That method does work in all versions of microscript but not with lua (snippet converted to proper lua syntax)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant