3

I'm working on a terrain generator, but I can't seen to figure out how to do the colors. I want to be able to generate an image that will take up my whole PlaneGeometry. My question is how can I create a single image that will cover the entire PlaneGeometry (with no wrapping) based off my height map? I can think of one way, but I'm not sure it would fully cover the PlaneGeometry and it would be very inefficient. I'd draw it in a two-dimensional view with colors on a canvas. I'd then convert the canvas to the texture Is that the best/only way?

UPDATE: Using DataTexture, I got some errors. I have absolutely no idea where I went wrong. Here's the error I got:
WebGL: drawElements: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering or is not 'texture complete'. Or the texture is Float or Half Float type with linear filtering while OES_float_linear or OES_half_float_linear extension is not enabled.
Both the DataTexture and the PlaneGeometry have a size of 512^2. What can I do to fix this?

Here's some of the code I use:

EDIT: I fixed it. Here's the working code I used.

function genDataTexture(){
    //Set the size.
    var dataMap = new Uint8Array(1 << (Math.floor(Math.log(map.length * map[0].length * 4) / Math.log(2))));
        /* ... */
        //Set the r,g,b for each pixel, color determined above
            dataMap[count++] = color.r;
            dataMap[count++] = color.g;
            dataMap[count++] = color.b;
            dataMap[count++] = 255;
        }
    var texture = new THREE.DataTexture(dataMap, map.length, map[0].length, THREE.RGBAFormat);
    texture.needsUpdate = true;
    return texture;
}
/* ... */
//Create the material
var material = new THREE.MeshBasicMaterial({map: genDataTexture()});
//Here, I mesh it and add it to scene. I don't change anything after this.

1 Answer 1

2

The optimal way, if the data is already in your Javascript code, is to use a DataTexture -- see https://threejs.org/docs/#api/textures/DataTexture for the general docs, or look at THREE.ImageUtils.generateDataTexture() for a fairly-handy way to make them. http://threejs.org/docs/#Reference/Extras/ImageUtils

Sign up to request clarification or add additional context in comments.

3 Comments

I'm getting some errors. I added them in the question. Can you show me where I'm going wrong?
I figured it out. Thanks
THREE.ImageUtils.generateDataTexture() has been removed, see stackoverflow.com/questions/47782274/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.