RawTexture with NullEngine

I am trying to create a RawTexture for serialization on the NullEngine but get an error:


NullEngine error:
“Cannot read properties of undefined (reading ‘RGB’)”

Running Babylon.js On A Server | Babylon.js Documentation mentions limitations of the NullEngine for DynamicTexture. Perhaps these also apply to RawTexture ?

Or is there some way ?

I am pretty sure now NullEngine does not allow for RawTexture but hope that I am wrong,

With the regular WebGL2 engine, the RawTexture gets created but does not show in the serialization:


RawTexture has a serialize() method but it may not be implemented ?

About serialize, the texture needs a name: https://playground.babylonjs.com/#LU0BIJ#8

Agree it is not clear, @PirateJC could you add that in the doc ?

Raw texture are not supported in NullEngine as they directly map to hardware texture. I will add support for it in the next nightly to at least prevent exceptions.

That said you would not be able to serialize them with nullEngine as it requires a canvas2d to generate the serialized base64 version which is not available in the nullEngine context.

1 Like

Yes, with a name the RawTexture gets serialized but there is no underlying texture source in the serialization ? In other words, is RawTexture supported with the .babylon json format ?


Yes, probably a good idea to prevent exceptions with NullEngine, perhaps with a warning.

An idea may be that a serialized version could not be image based but data buffer based. The data buffer could also be base64 encoded. Parsing actually then could be simpler as it also would not need to depend on images/canvas.

The nullengine is really not meant to be able to access any gpu operations. it sounds really edge case to support it only for raw texture. I am wondering the use case ?

The use case would be translating file formats to .babylon on a server. For example, RawTexture would be the closest fit to how a format like x3d can represent a small texture, or a striped Background sky pattern.

This could be a longer term goal. For a closer goal, just being able to serialize and parse back RawTexture at all (with the standard engine), may be just generally useful, for any kind of use of scenes with RawTextures ? Just like the documentation explains how RawTexture is great if you want to construct a texture pixel by pixel.

I can switch to vertex colors and/or to constructing a canvas image manually.

Translating file formats on the server might be hard :frowning: There are plenty of code paths which would rely on using canvas 2d to merge textures for instance which won t be available on the server.

I guess in your case relying on something like puppeteer to control a headless browser might be a better fit ?

Yes. exactly. I was just trying to start with a NullEngine approach to see how far that could go. Unfortunately, RawTexture was the best fit the first time I was trying to use a texture.

Leaving NullEngine aside, serializing RawTexture and parsing it back is probably not on the roadmap ? Perhaps it is too closely modeled after WebGL and WebGPU would want to expose other parameters ?

It seems quite useful to make the beachball sphere in the example above easily reusable, eg. as a mesh which can be loaded from .babylon ?

The serialization when with a real engine will work OOB it the texture has a name and we are forcing the serialization of buffers: https://playground.babylonjs.com/#LU0BIJ#10

1 Like

That’s it. Thanks so much !