Back to the Shapespark home page

[API] Generating textures with alpha

Hi there,

we are developing an app with multi language support. So we are swapping some textures depending on the selected language. We are generating the textures on the fly by writing text to canvas elements, and then we generate the image textures. Works perfectly. But now we have a text which should have a transparent background. Generating the image works as expected, but when we generate a texture from the image, the background is black when we put it in an element. So I investigated the textures with transparency exported by shapespark and saw, that those textures seem to work with cutouts. So using simply createTextureFromHtmlImage won’t work here I guess.

Is there any way to generate textures from PNGs with alpha on the fly?

Right. The viewer API assumes the textures are opaque. Could you check if setting

texture.format = GLC.RGBA;
texture.hasAlpha = true;
texture.needsUpdate = true;

on the texture object returned by createTextureFromHtmlImage makes the transparency information transferred to the viewer?

var texture = viewer.createTextureFromHtmlImage(MY_IMAGE);
texture.format = GLC.RGBA;
texture.needsUpdate = true;

I tried this code above, but no success.

@Simon, I’ve updated the code in my previous post by adding one more statement: texture.hasAlpha = true;. This should work now.

In the next release we’ll add an additional argument to createTextureFromHtmlImage specifying whether the image has an alpha channel.

It works perfectly, thanks a lot!