pmgl / microstudio

Free, open source game engine online
MIT License
936 stars 106 forks source link

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

Open SugarRayLua opened 10 months ago

SugarRayLua commented 10 months ago

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)