MarianG Posted October 9, 2015 Share Posted October 9, 2015 Hi guys. I have a little task that I can't complet itLet me explain.I have a sphere with 3 bones. Using bones and a slider I modify the sphere geometry, I can scale, translate or rotate the bones, It works like a morph.After deform the mesh I want to save it as new babylon file, without bones, but keep deform geometry, not original.In this scope I update positions, normals, compute normals, but all time the new babylon file is saved like original, and not deform.I have to update anything else?Or I have to save the skeleton too? ....If yes, than I have a problem, because I want to add an animation to the new mesh, that I think will overwrite the skeleton. Here are 2 picture that show my problem http://prntscr.com/8pd0co http://prntscr.com/8pd0qd first sphere is the original, and second is sphere saved. And I make a playground. http://www.babylonjs-playground.com/#1WKAQI#2 Any opinion is welcome. Thanks Quote Link to comment Share on other sites More sharing options...
MarianG Posted October 9, 2015 Author Share Posted October 9, 2015 I did it. ) with this piece of code var positionsData = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind); var normalsData = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind); var matricesIndicesData = mesh.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind); var matricesWeightsData = mesh.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind); var skeletonMatrices = skeleton.getTransformMatrices(); var tempVector3 = BABYLON.Vector3.Zero(); var finalMatrix = new BABYLON.Matrix(); var tempMatrix = new BABYLON.Matrix(); for (var index = 0; index < positionsData.length; index += 3) { var index4 = (index / 3) * 4; var matricesWeight0 = matricesWeightsData[index4]; var matricesWeight1 = matricesWeightsData[index4 + 1]; var matricesWeight2 = matricesWeightsData[index4 + 2]; var matricesWeight3 = matricesWeightsData[index4 + 3]; if (matricesWeight0 > 0) { BABYLON.Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesData[index4] * 16, matricesWeight0, tempMatrix); finalMatrix.addToSelf(tempMatrix); } if (matricesWeight1 > 0) { BABYLON.Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesData[index4 + 1] * 16, matricesWeight1, tempMatrix); finalMatrix.addToSelf(tempMatrix); } if (matricesWeight2 > 0) { BABYLON.Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesData[index4 + 2] * 16, matricesWeight2, tempMatrix); finalMatrix.addToSelf(tempMatrix); } if (matricesWeight3 > 0) { BABYLON.Matrix.FromFloat32ArrayToRefScaled(skeletonMatrices, matricesIndicesData[index4 + 3] * 16, matricesWeight3, tempMatrix); finalMatrix.addToSelf(tempMatrix); } BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(positionsData[index], positionsData[index + 1], positionsData[index + 2], finalMatrix, tempVector3); tempVector3.toArray(positionsData, index); BABYLON.Vector3.TransformNormalFromFloatsToRef(normalsData[index], normalsData[index + 1], normalsData[index + 2], finalMatrix, tempVector3); tempVector3.toArray(normalsData, index); finalMatrix.reset(); } mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positionsData); mesh.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normalsData); instead of simple update var positions = mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind) mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, false) var indices = mesh.getIndices(); var normals = mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind); BABYLON.VertexData.ComputeNormals(positions, indices, normals); mesh.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false, false); Jaskar 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 9, 2015 Share Posted October 9, 2015 Congrats Quote Link to comment Share on other sites More sharing options...
Myjestic Posted July 26, 2016 Share Posted July 26, 2016 Wow! This is exactly what I was looking for. I created a scene with different single meshes consisting of cubes. Because there are many of them and all have the same geometry and purpose I merged them all together. This drastically pushed my perfomance. Now I used the "doDownload" function from bulisors playground example to save the merged meshes to a *.babylon file. Everything works fine, export and import again. The only problem I have is, that the import of the file imports everything as single parts, they aren't merged anymore. How can I solve the problem? Quote Link to comment Share on other sites More sharing options...
Myjestic Posted July 26, 2016 Share Posted July 26, 2016 Just to simplify my question: How can I save and serialize a MERGED Mesh? And load it as merged mesh again? Quote Link to comment Share on other sites More sharing options...
Myjestic Posted July 29, 2016 Share Posted July 29, 2016 Problem solved. Bulisors code work like a charme. It was my fault. The merged meshes will be imported correctly. MarianG and GameMonetize 2 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.