J girl Posted August 8, 2017 Share Posted August 8, 2017 Hello everyone!! New to babylon.js I have tried several different ways to load a 3D model into my browser, trying babylon and OBJ files. They always fail in the console, with no clear error message as to why. All the GET requests are fine, and the model appears on the web page and the code runs fine, but I cannot move it's position or do anything with it in the code because it has not completely loaded, failing. I cannot move it's position by using model.position.x or anything of that sort. I need to eventually be able to get its vertices.. that is my end goal, but I can't even do simple altercations. Here is the code, onTaskError always gets called despite the model being visible on the screen: var assetsManager = new BABYLON.AssetsManager(scene); var meshTask = assetsManager.addMeshTask("human", "", "models/", "human.babylon"); // You can handle success and error on a per-task basis (onSuccess, onError) meshTask.onSuccess = function (task) { task.loadedMeshes[0].position = new BABYLON.Vector3(0, 0, 0); human = task.loadedMeshes[0]; } assetsManager.onTaskError = function (task) { console.log("error while loading " + task.name); } In the console it says "error while loading " + task.name, and nothing else. I added mime types to the browser, I made sure the HTTP request went through.. I would appreciate anyone's guidance on how to import a 3d model into the browser, I don't need an entire scene, I just need 2 models/objects in total, and I want to know how to move them and manipulate their vertices.. Thanks J Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 8, 2017 Share Posted August 8, 2017 Hello do you mind trying to reproduce it in the playground? (sample: https://www.babylonjs-playground.com/#1U2VMI#1) Quote Link to comment Share on other sites More sharing options...
J girl Posted August 8, 2017 Author Share Posted August 8, 2017 @Deltakosh Hi, how do I upload my model/files to this playground? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 8, 2017 Share Posted August 8, 2017 You cannot, you have to reference them from an external source (github with rawgit for instance or your own public server) Quote Link to comment Share on other sites More sharing options...
J girl Posted August 9, 2017 Author Share Posted August 9, 2017 Hello again @Deltakosh Ok, I think I have got it to load after making it on playground then exporting it as a zip on my local computer. The one problem is that when loading the model this way is that I cannot reference the model outside of this block of code in the script because it says it's undefined. And the code will not run.. BABYLON.SceneLoader.ImportMesh("", "scenes/", "skull.babylon", scene, function (newMeshes) { // Set the target of the camera to the first imported mesh camera.target = newMeshes[0]; model = newMeshes[0]; var positions = model.getVerticesData(BABYLON.VertexBuffer.PositionKind); } model.position.y += 100; In the console: ReferenceError: model is not defined[Learn More] How can I move the model dynamically then Thanks in advance Quote Link to comment Share on other sites More sharing options...
Christoph Posted August 9, 2017 Share Posted August 9, 2017 AFAIK the model is not loaded at the time you are trying to move it. The place where you might do that is the render loop. Edit: Or in the callback should work as well. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 9, 2017 Share Posted August 9, 2017 @Christoph is right Quote Link to comment Share on other sites More sharing options...
J girl Posted August 10, 2017 Author Share Posted August 10, 2017 Thank you Christoph and Deltakosh for your help. That was true.. I am able to move the model around now.. Best regards, J Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.