【问题标题】:three.js : Disable perspective on one axisthree.js :禁用一个轴上的透视图
【发布时间】:2018-06-28 13:26:24
【问题描述】:

我想要一个不现实的特殊效果。

当我渲染网格时,我不希望渲染在 Y 轴上受到影响。这意味着对于特定列,视角必须相同。所以透视只受(x,z)位置的影响。

你觉得有可能吗?

【问题讨论】:

  • 我不知道three.js,但我知道openGL,你能有两个矩阵:一个有透视,一个没有。然后用两个矩阵乘以 (x,y,z,1) 并构造你的最终向量,从一个矩阵中获取 x 和 y 的结果,从另一个矩阵中获取 y 的结果?
  • 所以没有的只有modelView矩阵?
  • 是的,我就是这么看的。我不能保证它会产生好的结果,但值得一试。
  • 我刚试过。但结果不是我所期望的……我的对象在 y 轴上被挤压:/ 我想要的是正交相机渲染它的方式,但只有一个轴。但是谢谢你的想法!
  • 那么可能不只是ModelView,而是使用正交投影进行ModelView投影?

标签: three.js 3d


【解决方案1】:

我在 POC 中快速完成的一个小技巧是在 three.js 中更改一行。

我替换了这一行:

var project_vertex = `"vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = (projectionMatrix * mvPosition);";`

作者:

var project_vertex = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = (projectionMatrix * mvPosition);\ngl_Position.y = gl_Position.y*gl_Position.w;";

这个答案How to draw ortho axes for object in perspective projection using modern OpenGL?,它解释了将坐标乘以最后一个组件 w 会删除透视图,这对我有帮助。

现在我必须找到一种正确的方法来完成与three.js 正确集成并且适用于我们想要禁用透视的任何轴。

更新

一种无需修改 three.js 的方法:

//As stated here : https://stackoverflow.com/questions/49918798/how-to-draw-ortho-axes-for-object-in-perspective-projection-using-modern-opengl
// In order to remove the perspective in one axis, you have to muliply by the 4th component of gl_position (w)
var project_vertex_custom = "vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\ngl_Position = (projectionMatrix * mvPosition);"
if (disablePerspectiveAxis.indexOf("x") >= 0)
    project_vertex_custom += "\ngl_Position.x = gl_Position.x*gl_Position.w;";
if(disablePerspectiveAxis.indexOf("y") >= 0)
    project_vertex_custom += "\ngl_Position.y = gl_Position.y*gl_Position.w;";

//Update the glsl code in three.js
THREE.ShaderChunk.project_vertex = project_vertex_custom;

【讨论】:

  • 这个答案是金!应该有一篇关于这个的数学文章。
猜你喜欢
  • 1970-01-01
  • 2014-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多