0

I'm trying to render only slice of my 3d object. In orthographic camera I want camera.near as 2.0 and camera.far as 1.5 then iterate and give camera.near = 1.5 and camera.far = 1.0. And so on. But it is not working. When I pass smaller value(2) to camera.near and larger value (10) to camera.far it kind of works. But I want just the opposite. I thought Z axis is coming outward from the screen.

WestLangley
  • 102,557
  • 10
  • 276
  • 276
spuemaacne
  • 219
  • 2
  • 4
  • 15
  • 1
    See http://stackoverflow.com/questions/17558085/three-js-orthographic-camera/17567292#17567292 – WestLangley Nov 09 '15 at 16:01
  • @WestLangley so camera.near and camera.far should be positive values. But how should we pass values if z is from 2 to -2? camera.near should be 2 and should camera.far be 2 + depth? And suppose i have to slice from z =0 to z = -2 then camera.near will be 0 and camera.far will be 0 + depth? (my depth value will be something like 0.5) – spuemaacne Nov 09 '15 at 17:03
  • 1
    To avoid seeing objects behind the camera, `near` and `far` need to be positive. Always, `near < far`. – WestLangley Nov 09 '15 at 18:14
  • @WestLangley Got it. Thanks – spuemaacne Nov 10 '15 at 03:08
  • @WestLangley Its not working. my camera is at (0,0,5) and I want to render from z = 2 to z = -2. I'm stepping by 0.4. How should I assign my camera.near and camera.far values or how should i write my loop? I tried getting distance from camera.position.z to z farthest value of my model( -2). and tried rendering both from front to back and back to front and its not working. Would you be able to tell me how should i write my loop? – spuemaacne Nov 10 '15 at 04:54
  • Your best bet is to make a new post and ask the community if you need help with your code. – WestLangley Nov 10 '15 at 05:07

1 Answers1

1

The z axis in Three.js is positive coming "out."

enter image description here

HOWEVER: the reason things can seem funny is that when you are setting view matrices, you actually specify the near/far planes as distance from the viewer. This is from the OpenGL spec:

Parameters

nearVal, farVal
Specify the distances to the nearer and farther depth clipping planes. These values are negative if the plane is to be behind the viewer.

FYI when you are using a perspective matrix, both values are always positive.

Community
  • 1
  • 1
Adam Finley
  • 1,550
  • 1
  • 16
  • 28
  • If I have to go from z = 2 to -2 then should it be like this. for (var i = minMax.zMax ; i > minMax.zMin; i = i-voxelDepth){ camera.near = i ; camera.far = i + voxelDepth; camera.updateProjectionMatrix(); renderer.render( scene, camera ); } – spuemaacne Nov 09 '15 at 16:55