Jump to content

Mesh updatable is not serialized


Dad72
 Share

Recommended Posts

Hello,

When I serialize a mesh (ground for example), the value 'updatable' is not serialized. It does not exist in the string JSON. And I can not find a property to set updatable to true.

BABYLON.Mesh.CreateGround("ground", 100, 100, 10, scene, true, 0);

In green I find the properties in red impossible to find it and I need to have ground.updatable = true to change the terrain when it is recharging from the serialization.

Link to comment
Share on other sites

I've found a solution that may be what needed to be done, but I think a simpler function would help.

ground.setVerticesData(BABYLON.VertexBuffer.PositionKind, ground.getVerticesData(BABYLON.VertexBuffer.PositionKind), true);
ground.setVerticesData(BABYLON.VertexBuffer.NormalKind, ground.getVerticesData(BABYLON.VertexBuffer.NormalKind), true);

I have to do this every objects, this will be very repetitive. Would not it be simpler to serialize the "updatable" property of each meshes.

Link to comment
Share on other sites

I'm not sure my PR would be correct. The code below is enough to make a mesh updatable ?

What allows the property to be updatable ? I'm not sure about doing a correct PR.

In fact I have the impression that this code ( setVerticesData ) is not enough, because if I serialize, modifications of the terrain are not taken into account.

Link to comment
Share on other sites

How to redefine 'actualizable', I would like to be able to reload a terrain serialized to edit it again and save it again with seralize.

Is there an alternative solution could help to do that. Or why not just serialize the property 'updatable' which would be simpler to do I think. Please.

Link to comment
Share on other sites

I revise the code :

mesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind), true);			
mesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind), true);
mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind), true, false);
BABYLON.VertexData.ComputeNormals(mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind), mesh.getIndices(), mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind));
mesh.updateVerticesData(BABYLON.VertexBuffer.NormalKind, mesh.getVerticesData(BABYLON.VertexBuffer.NormalKind), true, false);
mesh.updateCache();

But I still have a cache problem and recording. I find myself with a file of 3Ko instead of 1600ko for example.

Serialize is not updated, why? What must I do for that?  Why can not redefine updatable to true when loading an object with ImportMesh. This works fine when creating a CreateGround object for example, but not when reloading after serialization.

 

 

Link to comment
Share on other sites

Actually i had a look and it is not that simple. This is where geometries are saved:

https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.geometry.ts#L613

So I had to add a new parameter there:

https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.geometry.ts#L618

It should work now.

Link to comment
Share on other sites

Arf, j'ai du mal avec l'anglais, je vais ecrire en Français pour être plus facilement claire. Je me suis tromper, pour les uvs, c’est tout le vertexData qui n'est pas sérialiser ou vider.

En faite je crois que depuis le début je n'indique pas la bonne erreur, ou le vrais probleme. A force des faire des testes, j'ai fini pas mieux comprendre ce qui vas pas. J'explique:

Je créer un terrain avec CreateGround et je met le terrain en Updatable a true pour l'éditer avec un outils d’élévation qui créer des montagnes et autres. Ensuite j'enregistre ce terrain une premier fois, ca fonctionne jusque là. (j'enregistre avec SerializeMesh dans un fichier .babylon en passant par du PHP avec file_put_contents() et json_decode() et json_encode()).

Ensuite je peut donc recharger ce terrain enregistrer avec ImportMesh et l’éditer grâce au bout de code au début de ce post. jusque la ca fonctionne. si j'enregistre une première fois, tout est ok, le terrain est bien sérialiser entièrement. Mais, si j'enregistre une seconde fois, modifications du terrain ou non, la sérialisation ne ce fait pas correctement. A chaque fois dans le second enregistrement, le SerializeMesh me vide le vertextData (je ne sais pas du tout pourquoi a la seconde sérialisation ?) :

Voila le resultat de la seconde sérialisation :

"geometries": {
        "boxes": [],
        "spheres": [],
        "cylinders": [],
        "toruses": [],
        "grounds": [],
        "planes": [],
        "torusKnots": [], "vertexData": []
    },

au lieux de :

"geometries": {
        "boxes": [],
        "spheres": [],
        "cylinders": [],
        "toruses": [],
        "grounds": [],
        "planes": [],
        "torusKnots": [], "vertexData": [{
            "id": "44d46d08-c2e0-438d-b1f1-5b5fba4f40e9",
            "positions": [-64, 0, 64, -62.79245283018868, 0, 64, -61.58490566037736, 0, 64, -60.37735849056604, ... ],
            "normals": [0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, ...],
            "uvs": [0, 1, 0.009433962264150943, 1, 0.018867924528301886, 1, 0.02830188679245283, 1, 0.03773584905660377, ...],
            "indices": [108, 1, 0, 107, 108, 0, 109, 2, 1, 108, 109, 1, 110, 3, 2, 109, 110, 2, 111, 4, 3, 110, 111, 3, 112, 5, ... ]
        }] },

Je vais te faire un PG demain pour essayer de reproduire ca de la manière la plus simple.

Link to comment
Share on other sites

Ok, DK, I made a playground that reproduces the problem at the simplest.

If you look in the console, in the second serialization, the vertexData [] is empty, but not in the first.

http://www.babylonjs-playground.com/#1SQFJP#2

In fact ImportMesh does not access a geometries. Hence the problem that vertexData is emptying. I would like to be able to serialize again vertexData when I load a ground with ImportMesh. 

Link to comment
Share on other sites

Resolution of bypass :

I have found a workaround. I'll get every vertexData in mesh._geometry and add ._vertexBuffers.position._buffer._data, ._vertexBuffers.normal._buffer._data ... in mesh.metadata and I serialize mesh to get serialization.geometries and add serialization.geometries.vertexData = mesh.metadata.vertexData;

http://www.babylonjs-playground.com/#1SQFJP#4

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...