Quach90 Posted July 14, 2017 Share Posted July 14, 2017 Hi everyone, I have now been stuck with a problem for a while and figured I would ask here to see if anyone knew how to fix it. I have a scene where you can dynamically add your own images to it, that will than be transformed into a material with the images as the diffusetexture. The transforming happens by using the raw image data to create the texture with the function: BABYLON.Texture.LoadFromDataString - it looks something like this: material = new BABYLON.StandardMaterial("imageMaterial", scene); var imgTexture = new BABYLON.Texture.LoadFromDataString("data:" + Math.random(), RAW IMG DATA, scene); material.diffuseTexture = imgTexture; This all works fine, the problem that I am having is that I want to be able to save the scene and load it again later. But it seems the the SceneSerializer doesn't save the texture/material information (the raw image data), so that when I load the scene I get the error: Materials: Name: groundMaterial babylon.custom.js:5 Uncaught TypeError: Cannot read property 'width' of null at E (babylon.custom.js:5) at n.createTexture (babylon.custom.js:5) at new i (babylon.custom.js:11) at babylon.custom.js:11 at Function.t.Parse (babylon.custom.js:2) at Function.i.Parse (babylon.custom.js:11) at Function.t.Parse (babylon.custom.js:2) at Function.r.Parse (babylon.custom.js:17) at Function.t.Parse (babylon.custom.js:14) at Object.load (babylon.custom.js:28) Looking at the saved serialized scene, I can also see that it is not saving the raw image data, so I have customized the serialize() function to find and save the data when the scene is saved, then the idea was to unpack it when it loads somehow. But I still can't stop the above error from happening. Is there anyone that knows a good way to do this or a fix to how I'm trying to do it? In short: I am trying to save and load a scenes that have material/texture that I created from my own images. But the loader and saver, doesn't seem to recognize/save the custom material properly. Thank you! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 17, 2017 Share Posted July 17, 2017 Ping @Luaacro who works on this recently Quote Link to comment Share on other sites More sharing options...
julien-moreau Posted July 17, 2017 Share Posted July 17, 2017 Hi ! can you check if in the serialized scene object you have the textures serialized including a property named "base64String" in it ? if it is not serialized, there is another problem Quach90 1 Quote Link to comment Share on other sites More sharing options...
Quach90 Posted July 18, 2017 Author Share Posted July 18, 2017 Hi @Luaacro, Not sure I understand exactly what you mean, but the string "base64String" is no where in the serialized object. Below is a snippet of how the material looks: "materials": [..., { "tags": null, "id": "imageMaterial", "name": "imageMaterial", "checkReadyOnEveryCall": false, "checkReadyOnlyOnce": false, "state": "", "alpha": 1, "backFaceCulling": true, "sideOrientation": 1, "alphaMode": 2, "disableDepthWrite": false, "fogEnabled": true, "pointSize": 1, "zOffset": 0, "wireframe": false, "pointsCloud": false, "fillMode": 0, "diffuseTexture": { "tags": null, "name": "data:0.8948863414411619", "hasAlpha": true, "getAlphaFromRGB": false, "level": 1, "coordinatesIndex": 0, "coordinatesMode": 0, "wrapU": 1, "wrapV": 1, "anisotropicFilteringLevel": 4, "isCube": false, "gammaSpace": true, "invertZ": false, "lodLevelInAlpha": false, "lodGenerationOffset": 0, "lodGenerationScale": 0.8, "isRenderTarget": false, "url": "data:0.8948863414411619", "uOffset": 0, "vOffset": 0, "uScale": 1, "vScale": 1, "uAng": 0, "vAng": 0, "wAng": 0, "isBlocking": true, "animations": [] }, ... }] Should the serializer be able to include images/materials/textures created at run time? Quote Link to comment Share on other sites More sharing options...
Quach90 Posted July 20, 2017 Author Share Posted July 20, 2017 Basically it seems that the image data is saved in the "_buffer" on the texture, which is left out when it is serialized, which in terms gives trouble to the material when it is being loaded again. The texture looks something like this, before and after serialized: Before After serializing the above: Quote Link to comment Share on other sites More sharing options...
julien-moreau Posted July 20, 2017 Share Posted July 20, 2017 I cannot reproduce with the latest version of bjs, what version are you using ? The latest from github ? Quote Link to comment Share on other sites More sharing options...
Quach90 Posted July 21, 2017 Author Share Posted July 21, 2017 That was the problem. I was using version 3.0. In version 3.1 it seems to have been fixed. Thank you! julien-moreau 1 Quote Link to comment Share on other sites More sharing options...
julien-moreau Posted July 21, 2017 Share Posted July 21, 2017 Excellent ! Thanks for you feedback 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.