[API] Resolution of a texture when changing via script

Hello,

I’m trying to change some high quality textures on the click of a button. When i do, everything is black. I tried with the textures in the API example and it works (brick.jpg for example). I noticed only a 512x512 pixels texture works. Is there a way to overpass this limit?

Thanks a lot !

Hi, the textures used in WebGL are required to have power of two dimensions, so try 1024x1024, 2048x2048 or 4096x4096. Non-square dimensions are also OK, as long as both are power of two, for example 512x4096 is OK. Some devices limit the texture dimensions to max 4096, so rather don’t use larger dimensions.

Note: these requirement apply only to textures loaded via JavaScript API. Importer textures or textures added via Shapespark editor are automatically converted to have power of two dimensions.

Oh that works ! Thanks a lot ! Would be helpful to mention it in the API doc :slight_smile:

Can you elaborate on this restriction?

I’ve been playing around with the API and noticed that I am able to apply an image of 190 x 265 onto two different materials.

Has the viewer been upgraded since this thread and is no longer relevant - or will we need to take the power of two into consideration in the near future?

Today on most devices Shapespark uses WebGL 2.0 which removes the requirement for textures to have power of two dimensions. See https://www.khronos.org/registry/webgl/specs/latest/2.0/#4.1.3
However a small set of older devices/browsers (IE, older iOS versions) do not support WebGL 2.0 and in such cases Shapespark fallbacks to WebGL 1.0.
If you aim to support WebGL 1.0 devices, loading power of two textures via API is still a requirement.