snupas Posted October 22, 2017 Share Posted October 22, 2017 I'm trying to test out morphtargets, so I load up a scene and try to create a copy of the original mesh to then scale it and morph between the two, but for some reason the original mesh isn't being rendered anymore, plus the copy isn't hidden with setEnabled(). If I remove all of the copy code, the original mesh starts being rendered fine again. var scene; var mesh; var meshCopy; if (BABYLON.Engine.isSupported()) { var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); BABYLON.SceneLoader.Load("assets/2/", "untitled.babylon", engine, function (newScene) { newScene.executeWhenReady(function () { // Attach camera to canvas inputs newScene.activeCamera.attachControl(canvas); scene = newScene; mesh = scene.meshes[0]; mesh.convertToFlatShadedMesh(); meshCopy = mesh.clone("1"); meshCopy.x -=10; // meshCopy.parent = mesh; meshCopy.setEnabled(false); meshCopy.position.y =+ 1; meshCopy.scaling = new BABYLON.Vector3(1.1, 1.5, 1.0); meshCopy.bakeCurrentTransformIntoVertices(); var manager = new BABYLON.MorphTargetManager(); mesh.morphTargetManager = manager; //var target = BABYLON.MorphTarget.FromMesh(meshCopy, "instance1", 0.25); engine.runRenderLoop(function() { newScene.render(); }); }); }, function (progress) { }); } Quote Link to comment Share on other sites More sharing options...
snupas Posted October 22, 2017 Author Share Posted October 22, 2017 Ahh firefox properly outputs the error: Error: WebGL warning: Exceeded 16 live WebGL contexts for this principal, losing the least recently used one. How am I exceeding 16 live webgl contexts with a single copy? EDIT: Nevermind, that doesn't relate to this error, I don't get this error in Chrome or Edge. Quote Link to comment Share on other sites More sharing options...
Nabroski Posted October 23, 2017 Share Posted October 23, 2017 So you have 2 Scenes, i can't spot a second renderloop ? What would happen if you just use newScene for debugging purposes Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted October 23, 2017 Share Posted October 23, 2017 Your fireFox error is unrelated. It just means you hit the refresh button too many times. Query forum should you care more. Your real problem is clone. It does not do what you think like in Java & other languages. It allows multiple meshes to share the same vertex data. It is for saving space, yet still allows for different materials on each mesh. When you scaled it you did it for both. You could load it twice, if it that is possible. FYI, doing 2 Loads is highly ill-advised. Use Append for more than one. Also do not use the callback option, or it gets really messy when you have 2. var scene = new BABYLON.Scene(engine); BABYLON.SceneLoader.Append("assets/2/", "untitled.babylon", scene); BABYLON.SceneLoader.Append("assets/2/", "untitled.babylon", scene); scene.executeWhenReady(function () { // do your stuff here // Once the scene is loaded, register a render loop engine.runRenderLoop(function() { scene.render(); }); }); The trick is you will now have 2 meshes with the same name. There is probably a better way to do this by just copying the positions / normals/ etc, and making a new mesh. I never needed to look into that, as I use a source code exporter. I just say 'var mesh1 = new moduleNm.MyMesh(scene);' twice. JSON is a pile. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 23, 2017 Share Posted October 23, 2017 You can also still using clone() but then you have to call mesh.makeGeometryUnique() so you can update geometry on only one mesh 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.