satguru Posted February 3, 2016 Share Posted February 3, 2016 Load a scene from a file, serialize it and count the number of materials in the serialized string. You will see that the material count in the string is double the count in the file. Serialization doubles the count. I checked the code and I think it has to do with the way the loader and serializer work together. Loader, while loading, loads each material in the file as StandardMaterial into the scene. The Serializer while serializing adds all the material in the scene to the JSON object and then adds the material again if it is StandardMaterial - effectively doubling the count. I am working on an app which allows the user to serialize and save the scene to a file and I noticed that over subsequent saves the file kept getting bigger and bigger even though no changes were made to the scene, which is when I started looking into this issue. Quote Link to comment Share on other sites More sharing options...
RaananW Posted February 3, 2016 Share Posted February 3, 2016 Hey, can you reproduce this in the playground? I will check the code again. The serialized was rewritten for 2.3 (functions were moved and altered), it is more than possible that we missed something Quote Link to comment Share on other sites More sharing options...
RaananW Posted February 3, 2016 Share Posted February 3, 2016 Oh, and one more question - are you appending the new scene, or loading it? If I understand correctly, the main problem is that the loader is not checking if the material exists already. Is that true? Quote Link to comment Share on other sites More sharing options...
satguru Posted February 3, 2016 Author Share Posted February 3, 2016 I will try and reproduce it in the playground today I am not appending the scene. I am just loading the scene from a file. the loader loads each material as standard material, that is for each material in the file it creates a standard material and then set its property to that found in the file the serializer ends up loading each material from the scene into the serialization object twice as follows. It first loads all the materials into the serialization object then goes through the list of material one more time, this time checking if it is a standard material and if it finds it to be so then it loads it again into the serialization object. Thanks to the loader each material is a standard material and thus gets loaded twice. Quote Link to comment Share on other sites More sharing options...
satguru Posted February 3, 2016 Author Share Posted February 3, 2016 Looks like the problem might have been solved in 2.3 I tried reproducing this in playground but failed. Then I noticed that playground has switched to 2.3 Check this out http://www.babylonjs-playground.com/#1EF9PW#1 See if you can run this in 2.2 You will see different result then. The example linked above is a simple example It creates one additional material. It then prints out the number of materials in the scene. it then serializes the scene and then prints out the number of materials in the serialized object In 2.2 the count show up as 2 and 4 In 2.3 the count show up as 2 and 2 Quote Link to comment Share on other sites More sharing options...
RaananW Posted February 3, 2016 Share Posted February 3, 2016 This was solved then :-) 2.3 was just released, use it instead of 2.2. Quote Link to comment Share on other sites More sharing options...
satguru Posted February 3, 2016 Author Share Posted February 3, 2016 Great ! Will do that 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.