Jump to content

Serialize scene not complete


Dad72
 Share

Recommended Posts

When you serialize a scene, some property is not serialized.
 
I did not check everything, but that are not present in a scene serialized.

 

- enablePhysics

- collisionsEnabled

- workerCollisions

 

and when an object is deleted, the materials used by the deleted objects are serialized anyway, but should not be..

Link to comment
Share on other sites

I made a simple demo here:

 

http://www.babylonjs-playground.com/#2EAMX1#4

 

- enablePhysics, collisionsEnabled and workerCollisions  are not serialized :

 

 

{"autoClear":true,"clearColor":[0.2,0.2,0.3],"ambientColor":[0,0,0],"gravity":[0,-9.807,0],"lights":[],"cameras":[{"name":"camera1","tags":null,"id":"camera1","position":[0,5,-10],"fov":0.8,"minZ":1,"maxZ":10000,"inertia":0.9,"type":"FreeCamera","speed":2,"rotation":[0,0,0],"checkCollisions":false,"applyGravity":false,"ellipsoid":[0.5,1,0.5],"animations":[],"layerMask":268435455}],"activeCameraID":"camera1","materials":[{"name":"default material","ambient":[0,0,0],"diffuse":[1,1,1],"specular":[1,1,1],"specularPower":64,"emissive":[0,0,0],"alpha":1,"id":"default material","tags":null,"backFaceCulling":true},{"name":"default material","ambient":[0,0,0],"diffuse":[1,1,1],"specular":[1,1,1],"specularPower":64,"emissive":[0,0,0],"alpha":1,"id":"default material","tags":null,"backFaceCulling":true}],"multiMaterials":[],"skeletons":[],"geometries":{"boxes":[],"spheres":[],"cylinders":[],"toruses":[],"grounds":[],"planes":[],"torusKnots":[],"vertexData":[]},"meshes":[],"particleSystems":[],"lensFlareSystems":[],"shadowGenerators":[]}

Link to comment
Share on other sites

this was added to File_Format_Map _ (. babylon) but don quan look in the literature, this has not been taken into account. Maybe a bug?

    "workerCollisions": boolean,    "collisionsEnabled": boolean,    "physicsEnabled": boolean,    "physicsGravity": vector3 (defaults to [0,-9.81,0]),    "physicsEngine": string ("oimo" or "cannon", defaults to the default engine (oimo)

Link comparison:

 

.md => https://github.com/BabylonJS/Documentation/blob/master/content/generals/General/File_Format_Map_(.babylon).md

in the doc => http://doc.babylonjs.com/generals/File_Format_Map_(.babylon)/

 

By doing all the changes done on this page does not seem to take effect.

 

It lacks a lot of property in many scene and probably at serialization.
  • cameraToUseForPointers
  • forceWireframe
  • forcePointsCloud
  • forceShowBoundingBoxes
  • animationsEnabled
  • fogEnabled, fogMode and other fog... (serialisez Ok, but not in the doc)
  • shadowsEnabled
  • lightsEnabled
  • texturesEnabled
  • particlesEnabled
  • spritesEnabled
  • and other enabgled....
  • database
  • ...

The list is very long. I think he is missing is all the properties not serialized and not in the doc.

 

I think there is a huge reverification to do on its points there. but I will not have time to do so.

Link to comment
Share on other sites

I agree, a lot of properties are not being serialized, as they are never parse in the loader. Maybe a serializer/loader code review would be a good thing :-)

Having said that, the idea of the loader is mainly to load scenes created using external tools like blender and 3ds. Can those tools export all of the Babylon-supported properties? Would be nice to check that as well.

Link to comment
Share on other sites

This is a grea idea but beware: Some properties like xxxEnabled or forceXXXX should not be serialized as they are here for debugging purpose

 

The database object is an internal property as well.

 

I'm absolutely ok to add properties that I missed (because they were added after the file loader creation for instance or just because I forgot to add them :))

 

My only ask is to keep the doc in sync with the loader and the serializer

Link to comment
Share on other sites

DK I understand, it is not easy to update, the engine is changing fast and we can forget. The thing is normal.
 
In this case, if some thing should not be added, missing exactly (scene), if I understand.

 

But perhaps its properties there need not add beings? in this case everything is I guess.

  • cameraToUseForPointers
  • useDelayedTextureLoading
  • importedMeshesFiles

The engine is never serialized?

 

I think for my editor I have to create my own serialization and loading system for what did not with Babylon. because I want that all ownership changes did with my editor, is save to a file. I thought Babylon serialize all properties.

 

I'm not able to do the things listed loader changes. If Raanan  or anyone else want to take charge...  But maybe everything is ok, so I do not know exactly.

Link to comment
Share on other sites

Hi Dad,

 

there is technically no function overloading in javascript. In java, for example, you can do this:

public void saySomething(String something) {//implementation for a single string}public void saySomething(List<Integer> listOfThingsToSay) {//implementation for a list of integers}public void saySomething(String something, boolean yesNoMaybe) {//}// and so on

In JavaScript you can't. The function will always be open to all types. In JavaScript, those 3 functions are a single function and YOU should inspect the type provided. This is rather confusing and (in my opinion) should be avoided...

 

EDIT - Just read what DK said - I think he meant extending. DK?

Link to comment
Share on other sites

Is an expert among you can tell me how to extend the sceneSerializer and sceneLoader, I have big doubts about the ways to do it for the beginning. A concrete example of code would help me a lot for its two functions.

 

I use this for extend :



var Extends = function(ChildClass, ParentClass) { // ClassB (child) herite de classA (parent)
ChildClass.prototype = Object.create(ParentClass.prototype) || objectCreate(ParentClass.prototype);
ChildClass.prototype.constructor = ChildClass;
};
var Super = function(ChildClass) { //appel du constructeur de la classe mere
ChildClass.call(this);
};


 

But also for static functions as serializing and loader is that it'll work. I am not sure.

 

Then I did this, is this ok?

 



"use strict";
var CASTORENGINE = CASTORENGINE || {};
(function () {

CASTORENGINE.SceneLoader = function()
{
Super(BABYLON.SceneLoader);

};
Extends(CASTORENGINE.SceneLoader, BABYLON.SceneLoader);

CASTORENGINE.SceneLoader.Load = function (rootUrl, sceneFilename, engine, onsuccess, progressCallBack, onerror)
{

};
})();


Or should I extend the plugin. and here I do not know how.

 

 

Thank you for your help and time.

Link to comment
Share on other sites

If we are already using typescript, just take their extends implementation:

var __extends = (this && this.__extends) || function(d,  {        for (var p in             if (b.hasOwnProperty(p)) d[p] = b[p];        function __() {            this.constructor = d;        }        __.prototype = b.prototype;        d.prototype = new __();    };

To extend a class, use this:

var newClass = (function() {  __extends(newClass , OldClass);  function newClass(var1, var2, var) {    //....  }  return newClass;})()

You could also use the (relatively) new Object.assign to practically do the same... But this is a different subject :)

 

 

But, actually, there is no need for that.

Check out this line - https://github.com/BabylonJS/Babylon.js/blob/master/src/Loading/Plugins/babylon.babylonFileLoader.js#L1141

This is how the current plugin registeres. You could, of course, implement it differently (a class, containing all of the needed properties), but - this is more than enough.

 

I think you have two nice options - 

you either "empty" the plugin array in the scene laoder, and reregister a new .babylon loader plugin (while extending its functionality), or, and I think this is the better option, create your own file format.

Create a plugin to a .castor file type, and implement it the way you want. Create a new Serializer, extending the babylon serializer's code, that will export all of the needed properties for your scenes. 

 

The .castor file will be compatible with the babylon loader as well, and babylon files CAN be compatible with your castor loader. That is, if you implement it with defaults.

Link to comment
Share on other sites

For the plugin, I understood.  :)

 

How to reach serializationObject draws from babylon.sceneSerializer ?

"use strict";var CASTORENGINE = CASTORENGINE || {};(function () {		CASTORENGINE.SceneSerializer = { };	CASTORENGINE.SceneSerializer.Serialize = function(scene, engine)	{						BABYLON.SceneSerializer.Serialize(scene); // serialize scene by BABYLON		// Serialize added by CASTORENGINE		serializationObject.loadingUIText = engine._loadingScreen._loadingText;		serializationObject.loadingUIBackgroundColor = engine._loadingScreen._loadingDivBackgroundColor;		serializationObject.enableOfflineSupport = engine.enableOfflineSupport;				serializationObject.cameraToUseForPointers = scene.cameraToUseForPointers;		serializationObject.activeCamera = scene.activeCamera;		serializationObject.useOctree = scene.useOctree;						return serializationObject;	};	})();

Here, serializationObject the property is not defined, which is normal, but how can I achieve this variable on the file babylon.sceneSerializer to complete the serializer ?

 
I would like some advice please.
Link to comment
Share on other sites

yes, but in doing so, I have this error Converting circular structure to JSON on JSON.stringify().

 

[Edit:]

 

This seems to be because of:
serializationObject.cameraToUseForPointers = scene.cameraToUseForPointers;serializationObject.activeCamera = scene.activeCamera;
I guess there are already serialized. i made this and fix :
serializationObject.cameraToUseForPointersID = scene.cameraToUseForPointers.name; // cameraToUseForPointersID is personnal property
Link to comment
Share on other sites

I have one last question. When you create a plugin for loadScene with a new extension and other properties. If a load scene with "data: {}", which plugin is used? is that when you create a plugin replaces the default of Babylon ?

How to define the plugin to be used in the case of loading with "data: {}" For there is no extension to set the plugin to use. 

 

Maybe it would be nice to set the plugin to use. The doc on this subject is very minimal.

 

Thanks

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