Quach90

Members
  • Content Count

    6
  • Joined

  • Last visited

  1. That was the problem. I was using version 3.0. In version 3.1 it seems to have been fixed. Thank you!
  2. 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:
  3. 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?
  4. 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!
  5. Great that worked, thanks! Just to be safe with future problems. Is this the case with everything? Meshes, materials etc? Is it important that they have unique names?
  6. Hi all, I'm going to try to describe my issue as best as I can since I'm not sure how to show it properly in a playground. What I want to do is, allow a user to upload an image, that then gets converted into a texture that I place on a plane. What is happening is that the first image that is uploaded is displayed correctly in the scene, but when another image is uploaded, the same first image gets applied to the scene, and this keeps happening every time you try to add a new image to the scene. I tried to locate the error by doing a couple of test: - I used different images to see if they were the problem - they were not. - I logged the plane, texture and material every time a new image were added and inspected that the right data for the image was in them - it was. - I find the mesh after it has been created, print its texture and check the _buffer, which is set to the new image, but still the old image is showing. I simply can't seem to find the error, but was wondering if it had something to do with how textures are caches, but still doesn't make much sense. Does anyone have any insight? This is the function that is run whenever a "change" is detected on the <input type='file'> element: function addImage(evt){ if (this.files && this.files[0]) { var fileReader = new FileReader(); fileReader.addEventListener("load", function(e) { console.log(e.target.result); var plane = new BABYLON.Mesh.CreatePlane("plane", 10.0, scene); plane.material = new BABYLON.StandardMaterial("texture", scene); plane.material.diffuseTexture = new BABYLON.Texture.LoadFromDataString("data:test", e.target.result, scene); plane.material.diffuseTexture.hasAlpha = true; plane.material.diffuseTexture.uScale = 1.0; plane.material.diffuseTexture.vScale = 1.0; }); fileReader.readAsDataURL( this.files[0] ); } } I appreciate any insight or tips of how to solve this issue. Thank you!