I am creating a world edit tool for Survivalcraft and this is what it looks like so far:
I use this image for the textures, and this is the code I use to set up the material:
let textureLoader = new THREE.TextureLoader();
let texture = textureLoader.load("../static/blocks.png");
texture.repeat.x = 1/16;
texture.repeat.y = 1/16;
texture.offset.x = 0/16;
texture.offset.y = 15/16;
texture.magFilter = THREE.NearestFilter; // Give textures pixelated appearance
let material = new THREE.MeshBasicMaterial({
map: texture,
});
I want to be able to have a different texture.offset x and y value for each block. This is roughly how I set up the InstancedMesh, where blocks is an array of objects representing blocks:
// transform is used to hold the matrix that will be applied to objects
let transform = new THREE.Object3D();
let geometry = new THREE.BoxBufferGeometry(1, 1, 1);
let mesh = new THREE.InstancedMesh(geometry, material, blocks.length);
for (let i = 0; i < blocks.length; i++) {
block = blocks[i];
transform.position.set(block.x, block.y, block.z);
mesh.setMatrixAt(i, transform.matrix);
}
I am able to set a different position for each block, but I want to also have a different texture offset as well. How do I do this?
