Dad72 Posted November 18, 2015 Share Posted November 18, 2015 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.. Quote Link to comment Share on other sites More sharing options...
Temechon Posted November 18, 2015 Share Posted November 18, 2015 Hey Dad, A material can be used by several objects, so deleting an object will not remove its material. You have to do it manually.Regarding the other points, I can't help as I don't know if it's by design or a bug. Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 18, 2015 Share Posted November 18, 2015 I will check and add those properties if they are not present. I think the workerCollision property is not being read by the scene loader, so it will have to be changed as well. Temechon is totally right about the materials, you will have to remove them manually. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 18, 2015 Author Share Posted November 18, 2015 Ah, yes, I had not thought about the materials shared. That makes sense, yes. thank you for this recall. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 18, 2015 Author Share Posted November 18, 2015 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":[]} Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 18, 2015 Share Posted November 18, 2015 Yep, they are also not read by the scene loader. I'm trying to find the best way to do that, sadly I won't make it today. Will probably commit a change to both tomorrow. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 18, 2015 Author Share Posted November 18, 2015 I'm trying to do, I think it's pretty simple Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 18, 2015 Share Posted November 18, 2015 Serializing yes, but I wanted to fix the physics engine implementation in the scene loader (add support to the engines and to gravity) Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 18, 2015 Author Share Posted November 18, 2015 Yes this I do not know how for physics engine. I done and send (for serializing): - collisionsEnabled- workerCollisions Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 22, 2015 Author Share Posted November 22, 2015 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).mdin 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.cameraToUseForPointersforceWireframeforcePointsCloudforceShowBoundingBoxesanimationsEnabledfogEnabled, fogMode and other fog... (serialisez Ok, but not in the doc)shadowsEnabledlightsEnabledtexturesEnabledparticlesEnabledspritesEnabledand 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. Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 22, 2015 Share Posted November 22, 2015 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. Dad72 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 23, 2015 Share Posted November 23, 2015 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 23, 2015 Share Posted November 23, 2015 As well workerCOllisions should not be part of the file as this is dependant on the browser implementation and has nothing to do with the file format Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 23, 2015 Author Share Posted November 23, 2015 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.cameraToUseForPointersuseDelayedTextureLoadingimportedMeshesFilesThe 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 23, 2015 Share Posted November 23, 2015 I agree with you, you should add your own info in the babylon file format. This is intented to be the case (you only need to overload the loader and the serializer) Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 23, 2015 Author Share Posted November 23, 2015 It is necessary that I learn about overloading functions with javascript. I have never done that. but I like to learn new thing. I find that, you think this is a good method?http://ejohn.org/blog/javascript-method-overloading/ Any advice or example would be very appreciated. Thank you Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 23, 2015 Share Posted November 23, 2015 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 onIn 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? GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 23, 2015 Author Share Posted November 23, 2015 Hi Raanan, I see that there are possibility for overloading in Javascript. But yes I will extend the function given that I want to complete it. Thanks Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 23, 2015 Author Share Posted November 23, 2015 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. Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 24, 2015 Share Posted November 24, 2015 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#L1141This 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. Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 24, 2015 Author Share Posted November 24, 2015 Ok, I see, Thanks Raanan . I'll watch it all ready. I think the solution to create my own format .castor is interesting Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 24, 2015 Author Share Posted November 24, 2015 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. Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 24, 2015 Share Posted November 24, 2015 Simply use the return value:var serializationObject = BABYLON.SceneSerializer.Serialize(scene);//continue Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 24, 2015 Author Share Posted November 24, 2015 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 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 24, 2015 Author Share Posted November 24, 2015 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 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.