Jump to content

save babylon mesh as new babylon file


MarianG
 Share

Recommended Posts

Hi guys. I have a little task that I can't complet it

Let 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

Link to comment
Share on other sites

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);
Link to comment
Share on other sites

  • 9 months later...

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?

 

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...