【问题标题】:How to construct a 3D cube using javascript with THREE.js (without box/cube geometry)?如何使用带有 THREE.js 的 javascript 构建 3D 立方体(没有盒子/立方体几何)?
【发布时间】:2016-02-08 10:45:34
【问题描述】:

这就是我所拥有的。立方体的几何形状。我搞砸了输入面孔。我的项目是 JSFiddle 上的 Bizzare wall。还有什么是执行旋转的好方法?我在我的项目中使用的是由于旋转而将我的墙拆开。

function initGeom(){
/**TODO: optimize, to keep it simple in my mind I 
pictured divided the cube into six squares but
I duplicated some of the vertices.
*/

var cubeGeom = new THREE.Geometry();
var verts = [//front
            new THREE.Vector3(0,0,0),//0
            new THREE.Vector3(cubeSize,0,0),//1
            new THREE.Vector3(cubeSize,cubeSize,0),//2
            new THREE.Vector3(0,cubeSize,0),//3
            //back
            new THREE.Vector3(0,0,cubeSize),//4
            new THREE.Vector3(cubeSize,0,cubeSize),//5
            new THREE.Vector3(cubeSize,cubeSize,cubeSize),//6
            new THREE.Vector3(0,cubeSize,cubeSize)//7
            ];//15
            
            
var faces = [//===Face1===(front)WORKS!
            new THREE.Face3( 0, 3, 2),//Top Left Tri 2,3,0
            new THREE.Face3( 2, 1, 0),//Bottom Right Tri 0,1,2
            //===Face2===(right)// WORKS!
            new THREE.Face3( 5, 1, 2),//Top Left Tri 2,1,5
            new THREE.Face3( 2, 6, 5),//Bottom Right Tri 5,2,6
            //===Face5(Left)===WORKS!
            new THREE.Face3(0, 4, 7),//Top Right Tri 7,4,0
            new THREE.Face3(7, 3, 0),//Top Right Tri 0,3,7
            //===Face3===(top)//WORKS!
            new THREE.Face3( 2, 3, 7),//Top Left Tri 7, 3, 2
            new THREE.Face3( 7, 6, 2),//Bottom Right Tri 2,6,7
            //===Face 6(bottom)===(optimized) go back to
            new THREE.Face3(1, 0, 4),//Left tri 0,3,6
            new THREE.Face3(6, 4, 0),//Right tri 6,4,0
            //===Face4(back)===//some how is the front?
            new THREE.Face3(4, 5, 6),//bottomLeft Tri 6,5,4
            new THREE.Face3(6,7, 4), //Top Right Tri  4,7,6
            ];
            
            
cubeGeom.vertices = verts;
cubeGeom.faces = faces;

//scene.add(cubeMesh);
return cubeGeom;

}

【问题讨论】:

  • 旋转是一种线性变换,所以你的顶点仍然应该正确定位彼此

标签: javascript 3d three.js


【解决方案1】:

您是否有理由不想使用已经存在的 THREE.BoxGeometry ?旋转对象最简单的方法是使用网格的rotateOnAxis 方法。

【讨论】:

  • 是的。原因是,我的作业特别说不要使用 Box/CubeGeometry。 :)
  • 面 6(底部)顶点顺序:015、540。
  • 关于旋转 - 创建你的对象后稍微偏离坐标中心 0,0,0。您需要在-halfSize/+halfSize 而不是0/cubeSize 创建顶点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-19
  • 1970-01-01
  • 2014-03-12
  • 1970-01-01
  • 2022-07-12
  • 1970-01-01
  • 2014-04-28
相关资源
最近更新 更多