abhishekworld
abhishekworld

Reputation: 115

Volume redering using Texture3D requires geometry.translate

I have a question regarding texture3D. I am new to the 3D world. I was looking at volume rendering and came across this example https://github.com/mrdoob/three.js/blob/master/examples/webgl2_materials_texture3d.html

My question is about these three lines.

// line 119 - 122
// THREE.Mesh
const geometry = new THREE.BoxGeometry( volume.xLength, volume.yLength, volume.zLength );
geometry.translate( volume.xLength / 2 - 0.5, volume.yLength / 2 - 0.5, volume.zLength / 2 - 0.5 );

const mesh = new THREE.Mesh( geometry, material );

Why we need geometry.translate?

Suppose I change this example to use THREE.MeshBasicMaterial without the volume rendering just a static color, then I don't need any translation.

Can someone please explain why the geometry.translate?

Upvotes: 1

Views: 164

Answers (1)

M -
M -

Reputation: 28492

When you create a box of width 1, the left is at -0.5, and the right is at +0.5. This translation was necessary to change its range from [-0.5, 0.5] => [0.0, 1.0]. This way it's easier to sample the 3D texture with the position coordinates, since texture-sampling always requires coordinates between 0 - 1.

Upvotes: 2

Related Questions