Procedurally Generating Assets

I’ve been reading the docs for a while now, but so far I haven’t found what I’m looking for.

I want to be able to procedurally generate a bitmap to use as a texture, and later as a basis for a terrain mesh. Something tells me that the Asset class, and particularly the data property of that class, is where I need to look. However, I’m not sure what that JSON blob needs to look like for a texture asset.

Anyone have any pointers?

You can create a texture this way, and then assign it to the material:

createTexture(device, format, size) {
        return = new Texture(device, {
            width: size,
            height: size,
            format: format,
            addressU: ADDRESS_CLAMP_TO_EDGE,
            addressV: ADDRESS_CLAMP_TO_EDGE,
            type: TEXTURETYPE_DEFAULT,
            magFilter: FILTER_LINEAR,
            minFilter: FILTER_NEAREST,
            anisotropy: 1
        });
    }

    const texture = createTexture(device, PIXELFORMAT_R8_G8_B8_A8, 2);

    const pixels = texture.lock();
    pixels.fill(0);  // fill it up with black pixels, but you can use numbers in 0..255 range
    texture.unlock();

3 Likes