Serialize mesh with textureVideo not complete in diffuseTexture


When you serialize an object that has received a textureVideo, the object is serialized and the textureDiffuse also. But without the video.

IF I reload this object serialized that I save in a file. when reloading, assetManager looks for the video texture by taking the object’s materialID reference and has an image name that does not exist because the videoTexture saved a name and not a “textureName.jpg”.

In short, an error is generated because the diffuseTexture material has missing data sought.

Error: Failed to load resource: the server responded with a status of 404 (Not Found) GET 404 (Not Found)

I do not know if what I’m saying is clear. I try to reproduce on a PG, but assetsManager.addMeshTask(“task”, “”, “”, “data:”+serialization); does not work.

Example of the serialized file I have: (I put the interesting parts in bold)

“materials”: [{
“tags”: null,
“diffuseTexture”: {
“tags”: null,
“uOffset”: 0,
“vOffset”: 0,
“uScale”: 1,
“vScale”: 1,
“uAng”: 0,
“vAng”: 0,
“wAng”: 0,
“uRotationCenter”: 0.5,
“vRotationCenter”: 0.5,
“wRotationCenter”: 0.5,
“isBlocking”: true,
“_generateMipMaps”: true,
“uniqueId”: 226,
"name": “Video0”, <= Error here
“hasAlpha”: false,
“getAlphaFromRGB”: false,
“level”: 1,
“coordinatesIndex”: 0,
“coordinatesMode”: 0,
“wrapU”: 1,
“wrapV”: 1,
“wrapR”: 1,
“anisotropicFilteringLevel”: 4,
“isCube”: false,
“is3D”: false,
“gammaSpace”: true,
“invertZ”: false,
“lodLevelInAlpha”: false,
“lodGenerationOffset”: 0,
“lodGenerationScale”: 0,
“linearSpecularLOD”: false,
“isRenderTarget”: false,
“animations”: [],
“invertY”: true,
“samplingMode”: 3
“ambient”: [0, 0, 0],
“diffuse”: [1, 1, 1],
“specular”: [1, 1, 1],
“emissive”: [0, 0, 0],
“specularPower”: 64,
“useAlphaFromDiffuseTexture”: false,
“useEmissiveAsIllumination”: false,
“linkEmissiveWithDiffuse”: false,
“useSpecularOverAlpha”: false,
“useReflectionOverAlpha”: false,
“disableLighting”: false,
“useObjectSpaceNormalMap”: false,
“useParallax”: false,
“useParallaxOcclusion”: false,
“parallaxScaleBias”: 0.05,
“roughness”: 0,
“indexOfRefraction”: 0.98,
“invertRefractionY”: true,
“alphaCutOff”: 0.4,
“useLightmapAsShadowmap”: false,
“useReflectionFresnelFromSpecular”: false,
“useGlossinessFromSpecularMapAlpha”: false,
“maxSimultaneousLights”: 4,
“invertNormalMapX”: false,
“invertNormalMapY”: false,
“twoSidedLighting”: false,
"id": “MaterialForVideo0”,
“uniqueId”: 225,
“name”: “MaterialForVideo0”,
“checkReadyOnEveryCall”: false,
“checkReadyOnlyOnce”: false,
“state”: “”,
“alpha”: 1,
“backFaceCulling”: false,
“sideOrientation”: 1,
“alphaMode”: 2,
“_needDepthPrePass”: false,
“disableDepthWrite”: false,
“forceDepthWrite”: false,
“separateCullingPass”: false,
“fogEnabled”: true,
“pointSize”: 1,
“zOffset”: 0,
“wireframe”: false,
“pointsCloud”: false,
“fillMode”: 0
“geometries”: {
“boxes”: [],
“spheres”: [],
“cylinders”: [],
“toruses”: [],
“grounds”: [],
“planes”: [],
“torusKnots”: [],
“vertexData”: [{
“id”: “20d679e6-11ef-4889-a6c7-79f2bbbff631”,
“updatable”: false,
“positions”: [-0.5, -0.5, 0, 0.5, -0.5, 0, 0.5, 0.5, 0, -0.5, 0.5, 0],
“normals”: [0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1],
“uvs”: [0, 0, 1, 0, 1, 1, 0, 1],
“indices”: [0, 1, 2, 0, 2, 3]
“meshes”: [{
“name”: “Video0”,
“id”: “Video0”,
“type”: “Mesh”,
“position”: [-11.987348797801301, 0.5099999997764826, 7.238914597717875],
“rotation”: [0, 0, 3.14],
“scaling”: [1, 1, 1],
“localMatrix”: {
“0”: 1,
“1”: 0,
“2”: 0,
“3”: 0,
“4”: 0,
“5”: 1,
“6”: 0,
“7”: 0,
“8”: 0,
“9”: 0,
“10”: 1,
“11”: 0,
“12”: 0,
“13”: 0,
“14”: 0,
“15”: 1
“isEnabled”: true,
“isVisible”: true,
“infiniteDistance”: false,
“pickable”: true,
“receiveShadows”: false,
“billboardMode”: 0,
“visibility”: 1,
“checkCollisions”: false,
“isBlocker”: false,
“isUnIndexed”: false,
“geometryId”: “20d679e6-11ef-4889-a6c7-79f2bbbff631”,
“subMeshes”: [{
“materialIndex”: 0,
“verticesStart”: 0,
“verticesCount”: 4,
“indexStart”: 0,
“indexCount”: 6
"materialId": “MaterialForVideo0”,
“metadata”: null,
“instances”: [],
“animations”: [],
“ranges”: [],
“layerMask”: 268435455,
“alphaIndex”: 1.7976931348623157e+308,
“hasVertexAlpha”: false,
“overlayAlpha”: 0.5,
“overlayColor”: [1, 0, 0],
“applyFog”: true

We do not serialize texture content unfortunately. The texture has to still be available at the same url

Is your video coming from an url of from a data string?

From a local data chain

What can I do to avoid the mistake.

I save the data of the video in mesh.metadata, and I recreate the texture of the video reloading.

But when loading the scene, I have this error that Video0 does not exist. But it is displayed after loading as I recreate it.

Maybe I should empty at the time of serialization the material? for the object having a videoTexture?

You can try it definitely. The thing is that as the data comes from a data string it has no real name.
Maybe setting the name to empty after the serialization can help

I fix the problem in this way (See code). This makes the file serialize lighter to rid it of useless data as I recreate the material afterwards… Then when I reload my scene from the serialized file, I recreate the videoTexture from the data contained in mesh.metadata.

I was wondering: there are doNotSerialize for mesh. Does this also exist for materials? This could be useful if it does not exist for materials? Because I tried and the material was still serialized : material.doNotSerialize = true;

In the meantime, this solves the problem. :

let serialization = BABYLON.SceneSerializer.SerializeMesh(mesh, true, true);
if(mesh.metadata.type == "videoTexture") { 
        serialization.materials = [];

They also exist for materials (good idea for the fix :))

Down the material is still serialized then after trying.

Well not in my tests…can you repro in the PG?


See in the console.log () The material is always present

Ok found it! SerializeMesh is ignoring the flag

Will fix that for next commit

Thanks as usual!

I saw that there was a correction on that (15J), but it did not change anything. The material is always serialized even with material.doNotSerialize = true;
The indicator doNotSerialize in SerializeMesh (and SerializeScene) must still be ignored.

I’m stupid…I will be good for next nightly. Sorry for the inconvenience

There is no problem DK. No disturbance/inconvenience. :+1:

I try the patch but I have a new problem. When I serialize the object, the material is no longer serialized, so I can save to a file, but the material is also removed from the scene.
The material should always be visible on the scene. The indicator just asks that it is not serialized, but should not update the scene that removes the material from the object that I serialize it.

line 33, if I serialize, no more material on the object.

Yep I found that earlier :slight_smile: Will be good asap

It seems to work now. The material is no longer serialized and the material is not erased from the scene after serializing the object.

Thank you Deltakosh

1 Like