Jump to content

Serialize scene and exclude ground or several objects


Dad72
 Share

Recommended Posts

Hello, 

 I would like to serialize the scene but exclude terrain generated by heightmap. My goal would be to generate a file for the ground and another for the rest of the scene. 

 I thought if it was possible to add an option to:

Quote

BABYLON.SceneSerializer Serialize(scene, excludeMesh); // With arry for excludeMesh

And to do better, by adding an array to excludeMesh, one could even exclude several objects which would be better. 

 What do you think about the Deltakosh idea?

Thank you

Link to comment
Share on other sites

I have an idea.  :)

Please look at  https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.sceneSerializer.js#L20

We can make that IF statement... return FALSE... I think...

	var tmpsto = BABYLON.Geometry.Primitives.Ground;
	BABYLON.Geometry.Primitives.Ground = 0;
	// do serialize here
	BABYLON.Geometry.Primitives.Ground = tmpsto;

In theory, this should cause the serializer to ignore grounds.  :)  Not sure, though.  Kind of crazy idea.

You could also add property to Babylon.Node... perhaps Node.SerializationRoute.  Then, re-code BJS serializer (or use custom). 

Similar-to steerable chute on the back of a Ready-Mix cement truck.  :)  

For each node serialization, if node.serializationRoute = "pile2" then output to pile #2.  Else output to pile #1.  Also weird.

Perhaps... BJS serializer could have customOutputRouter add-on.  Similar to particleSystem.customUpdateFunction.  User could easily write a custom output router for the serializer.  *shrug*    Just some goofy Wingnut ideas.

Link to comment
Share on other sites

This could be an idea, I will try, but I would love to know what Deltakosh thinks of the idea of excluding objects from the scene serializer. 
May be that I can attempt to create a PR for this if DK does not have time to do so.

I did this by taking up your idea Wingnut:

var tmpsto = BABYLON.Geometry.Primitives.Ground;
BABYLON.Geometry.Primitives.Ground = 0;	
var serializedScene = BABYLON.SceneSerializer.Serialize(global.scene);	
BABYLON.Geometry.Primitives.Ground = tmpsto;
var serializedGround = BABYLON.SceneSerializer.SerializeMesh(global.terrain);		
var str_scene = JSON.stringify(serializedScene);
var str_ground = JSON.stringify(serializedGround);

 

Link to comment
Share on other sites

LinesMesh might be done in line 33...  https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.sceneSerializer.js#L33

You could add some LinesMesh to a scene, and do some tests.

I have another idea.  :)

linesMesh._geometry.serializeVerticeData = function() { return; }

That should kill it dead.  heh  

Notice I recently edited this.  I removed parentheses after serializeVerticeData

Link to comment
Share on other sites

On 2016-11-15 at 2:53 PM, Dad72 said:

Hello, 

 I would like to serialize the scene but exclude terrain generated by heightmap. My goal would be to generate a file for the ground and another for the rest of the scene. 

 I thought if it was possible to add an option to:

And to do better, by adding an array to excludeMesh, one could even exclude several objects which would be better. 

 What do you think about the Deltakosh idea?

Thank you

I have another idea for this to.

I believe that you are talking about exluding things from within your editor @Dad72 ?

Why we not have:

BABYLON.SceneSerializer Serialize(scene, excludePrefix);

Example.

BABYLON.SceneSerializer Serialize(scene, "_");

Every thing that starts with an underscore will be ignored by the serializer(IF excludePrefix is set).

If there is an id of _myEditorMesh, then this mesh will be exluded from the serialization(IF excludePrefix is set).

Since everything has an id, this would be the easyest thing to implement i think.

What you all think about that?

EDIT:

excludePrefix could be an array to maybe?

Example:

If you created an editor....

You use some meshes and materials as defaults in your editor.....

You as a developer sets the editors meshes id's to eg: _myEditorMeshes1 and _myEditorMeshes2

You as a developer sets the editors materials id's to eg: _myEditorMaterials1 and _myEditorMaterials2

In your editor a user creates meshes and materials (BUT you restict the use of the prefix).(User can not create meshes with an id that starts with _myEditorMeshes,  and the user can not create materials with an id that starts with _myEditorMaterials).

eg:BABYLON.SceneSerializer Serialize(scene, "_myEditorMeshes,_myEditorMaterials");

Now....when serialized... all things are serialized, but not the editors meshes or materials.(if excludePrefix is set)

If excludePrefix is NOT set, then everything is serialized.

Link to comment
Share on other sites

Let me explain how i have to do when i serialize a scene from my editor as the serialisation works right now.

1.Before i serialize my scene, i have to remove all my meshes, materials and editor camera that my editor is using from the scene.

2. Then i do the serialization.

3. I have to recreate my meshes,materials and editor camera that my editor is using.

Note:

The meshes in my editor are pseudo meshes for showing where light's and cameras are in the scene.

And the materials are materials for giving those meshes a different look.

Conclusion:

If we get an implementation of a functionality to the serilazer, then people with editors don't have to do these steps (1 to 3).

Link to comment
Share on other sites

@Deltakosh

I see that you allready started to implement this yes.

For cameras, lights and meshes.

What about materials, instances and textures?

I think it would be good to have the option to not serialize materials, instances or textures to. (Maybe multimaterials to?).

doNotSerialize is a property of a mesh,light,camera?

Same as eg: camera.fov = 0.8

camera.doNotSerialize = true;

I think your solution is a great idea, and @dad72 will be happy to about this.

 

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