Wemperer2 Posted September 8, 2016 Share Posted September 8, 2016 Hello. I'm having trouble importing a scene from blender. The screen is and enless loading loop and I'm getting this error in console: Uncaught TypeError: e.UniversalCamera is not a constructor if (BABYLON.Engine.isSupported()) { var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); engine.enableOfflineSupport = false; BABYLON.SceneLoader.Load("", "guy.babylon", engine, function (newScene) { var camera = new BABYLON.ArcRotateCamera("ArcRotateCamera", 0, 0, 0, BABYLON.Vector3.Zero(), scene); var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene); scene.clearColor = new BABYLON.Color3(0, 1, 0); camera.setPosition(new BABYLON.Vector3(-10, 50, -50)); camera.attachControl(canvas, false); light.intensity = .5; // Wait for textures and shaders to be ready newScene.executeWhenReady(function () { // Attach camera to canvas inputs newScene.activeCamera.attachControl(canvas); // Once the scene is loaded, just register a render loop to render it engine.runRenderLoop(function() { newScene.render(); }); }); }, function (progress) { // To do: give progress feedback to user }); } Quote Link to comment Share on other sites More sharing options...
gryff Posted September 9, 2016 Share Posted September 9, 2016 @Wemperer2 : Welcome to the forum I'm no coding expert by any stretch of the imagination but you appear to be attaching two active cameras to the canvas - the active camera from the Blender file and one you define in the script. What happens if you don't export the camera from Blender (either delete it or move it to another layer, tell the exporter to use only "selected layers", and make sure the layer you put the camera in is not selected) I don't think the error has anything to do with Blender. You could try dropping your file "guy.babylon" and its textures in the BJS Sandbox as a check. If it loads in the Sandbox, the error is definitely in your code. Hope that helps . cheers, gryff Quote Link to comment Share on other sites More sharing options...
Wemperer2 Posted September 9, 2016 Author Share Posted September 9, 2016 15 hours ago, gryff said: @Wemperer2 : Welcome to the forum I'm no coding expert by any stretch of the imagination but you appear to be attaching two active cameras to the canvas - the active camera from the Blender file and one you define in the script. What happens if you don't export the camera from Blender (either delete it or move it to another layer, tell the exporter to use only "selected layers", and make sure the layer you put the camera in is not selected) I don't think the error has anything to do with Blender. You could try dropping your file "guy.babylon" and its textures in the BJS Sandbox as a check. If it loads in the Sandbox, the error is definitely in your code. Hope that helps . cheers, gryff Thank you, that was indeed the problem. Now I'm having an issue importing meshes. It seems to 'work' but I don't see the supposedly imported meshes. if (BABYLON.Engine.isSupported()) { var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); engine.enableOfflineSupport = false; BABYLON.SceneLoader.Load("", "stage.babylon", engine, function (newScene) { newScene.executeWhenReady(function () { var camera = new BABYLON.ArcRotateCamera("ArcRotateCamera", 0, 0, 0, BABYLON.Vector3.Zero(), newScene); var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), newScene); camera.setPosition(new BABYLON.Vector3(-10, 50, -50)); camera.attachControl(canvas, false); light.intensity = 1.2; engine.runRenderLoop(function() { newScene.render(); }); BABYLON.SceneLoader.ImportMesh("guy", "", "guy.babylon", newScene, function (newMeshes, particleSystems) { }); }); }, function (progress) { // To do: give progress feedback to user }); } Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted September 9, 2016 Share Posted September 9, 2016 Create your scene on your own: var myScene = new BABYLON.Scene(engine); Use Append instead of Load: BABYLON.SceneLoader.Append("", "stage.babylon", myScene); Import your Guy: BABYLON.SceneLoader.ImportMesh("guy", "", "guy.babylon", myScene); Add your executeWhenReady: myScene.executeWhenReady(function(){ ...}); This is much straight forward than nested loads / callbacks. May not fix your problem, but will get rid of messy callbacks & scene scope issues. If "guy" is the only thing in "guy.babylon", use Append instead of ImportMesh. Also, turn on logging during debugging & check your console: BABYLON.SceneLoader.loggingLevel = BABYLON.SceneLoader.DETAILED_LOGGING; Wemperer2 1 Quote Link to comment Share on other sites More sharing options...
gryff Posted September 9, 2016 Share Posted September 9, 2016 @Wemperer2 : Try the method of loading that @JCPalmer suggests using append. Could the "stage" meshes be burying the "guy" meshes? And if you include the "logging" line as suggested - you can examine the scene. Failing that, can you post a .blend file for the "guy"? cheers, gryff Quote Link to comment Share on other sites More sharing options...
Wemperer2 Posted September 10, 2016 Author Share Posted September 10, 2016 19 hours ago, gryff said: @Wemperer2 : Try the method of loading that @JCPalmer suggests using append. Could the "stage" meshes be burying the "guy" meshes? And if you include the "logging" line as suggested - you can examine the scene. Failing that, can you post a .blend file for the "guy"? cheers, gryff Thanks to you both. The code looks WAY cleaner and works as far as loading the stage but my Guy still doesn't get imported. It's back to the loading loop and it is def with the import of the guy line. Is it because he has an armature? I couldn't find (I don't think its actually there) the 'export selected only' option in blender but I am kinda guessing the import is failing because 'guy' is an entire scene and I'm back to my multiple cameras issue. Am I blind or is that checkbox missing or am I exporting wrong? Here is Guy: [snip] Quote Link to comment Share on other sites More sharing options...
gryff Posted September 10, 2016 Share Posted September 10, 2016 @Wemperer2 : well I actually asked for the .blend file not the .babylon file. However, the "cameras":[], tells me that no second camera is coming from "guy.babylon". However, this bothers me: "meshes":[{"name":"ARM","id":"ARM","materialId":"guy.Material","billboardMode":0,"position":[0,2.0148,0],"rotation":[0,0,0],"scaling":[0.3647,0.3647,0.3647], so I would really like to look at the .blend file. cheers, gryff Quote Link to comment Share on other sites More sharing options...
Wemperer2 Posted September 10, 2016 Author Share Posted September 10, 2016 9 hours ago, gryff said: @Wemperer2 : well I actually asked for the .blend file not the .babylon file. However, the "cameras":[], tells me that no second camera is coming from "guy.babylon". However, this bothers me: "meshes":[{"name":"ARM","id":"ARM","materialId":"guy.Material","billboardMode":0,"position":[0,2.0148,0],"rotation":[0,0,0],"scaling":[0.3647,0.3647,0.3647], so I would really like to look at the .blend file. cheers, gryff I'm so sorry, late night. characterv2_17_7.blend Quote Link to comment Share on other sites More sharing options...
gryff Posted September 11, 2016 Share Posted September 11, 2016 @Wemperer2 : TY for the .blend file - I will look at it this evening and report later tonight. cheers, gryff Quote Link to comment Share on other sites More sharing options...
gryff Posted September 12, 2016 Share Posted September 12, 2016 @Wemperer2 : OK, and my suspicions prompted by this line that you originally posted were correct:: "meshes":[{"name":"ARM","id":"ARM","materialId":"guy.Material","billboardMode":0,"position":[0,2.0148,0],"rotation":[0,0,0],"scaling":[0.3647,0.3647,0.3647], I looked at your file with Blender 2.76 with the BE v 5.0.5 installed. First thing I tried - a straight export and it refused to export it but returned it the message in in part A of the image below. The scale has not been applied to the rig.Also the origins for the mesh and the rig are in two different places. If you are planning to animate the guy (the IK bones suggest you are) It is best to have all transformation applied and the origins of the rig and mesh in the same place. Part B of that image shows the location "Export Only Selected Layers" and the "Ignore IK Bones" option which you can use. I did some modification to your guy: 1. Applied that scale. 2. Applied the mirror modifier to the mesh. The exporter should handle it - but I always apply modifiers like that 3. Moved the rig and the mesh so that the feet were basically at z=0, then with the 3D cursor at 0,0,0 , I moved both the origins of mesh and the rig to the 3D cursor. 4. Renamed the "pull target.x" bones to pull_target_IK.x. There is no need to export the IK bones as they do not deform the mesh. 5. Added a Hemi to the scene and made the camera an ArcRotate camera. 6. As I had no "stage" blend file I made a quick "stage for the guy So with the lights and camera in layer 1 and the stage in layer 2, I exported a file which I called stage2.babylon by selecting just those two layers. Then I exported the rigged mesh by selecting Layer 10 - and called it guy2.babylon. You can see the result here : guy with stage. Everything shows fine but before you start animating, I would clean up the weight painting for the bones (see second image below) and deal with all the weird vertices highlighted in the red box. And there appear to be missing faces in the legs. A zip file containing the modified blend file, the two babylon files I exported, and the index.html file containg the simple scene loading script can be found here: the_guy cheers, gryff Quote Link to comment Share on other sites More sharing options...
Wemperer2 Posted September 12, 2016 Author Share Posted September 12, 2016 13 hours ago, gryff said: snip @gryff Holy cow man you went way above and beyond there! I really appreciate it. I'll be playing with this for awhile. I'm new to blender so that's why there is alot of stuff missing with the Guy. I just waned to practice creating a model and getting it into Babylon. Also the origins for the mesh and the rig are in two different places. If you are planning to animate the guy (the IK bones suggest you are) It is best to have all transformation applied and the origins of the rig and mesh in the same place. What exactly does this mean? The components of the mesh should be all in the same layer? What are origins/transformations? Quote Link to comment Share on other sites More sharing options...
nazimboudeffa Posted September 12, 2016 Share Posted September 12, 2016 Oh! great ! i have the same issue on a 3d model, but i am debugging it, but no time, it's about adding a backbone to a model then to use pose mode, i think i can follow this thread too thx for the question 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.