我正在使用标准new THREE.CubeGeometry
创建多维数据集。我也在改变网格的位置(x,y,z),然后将它添加到场景中。稍后当用户点击该选项时,我想在立方体的所有6个角上绘制一个立方体。如何获得坐标系中每个顶点的位置?
答案 0 :(得分:0)
你可以做到:
var geometry = new THREE.CubeGeometry(...);
var verices = geometry.vertices;
答案 1 :(得分:0)
如果您正在寻找 8个顶点/角落 ... http://jsfiddle.net/ebeit303/54uQ9/
function addShapes() {
width = 100;
height = 100
depth = 100;
var geometry = new THREE.CubeGeometry( width, height, depth );
var material = new THREE.MeshBasicMaterial({color:0xffccff, side:2, overdraw:true} );
mesh = new THREE.Mesh( geometry, material );
group.add( mesh );
mesh.position.set(10,20,20);
var x = mesh.position.x;
var y = mesh.position.y;
var z = mesh.position.z;
console.log(geometry.vertices);
var len = geometry.vertices.length;
for(var i = 0; i < len; i++){
var vx = geometry.vertices[i].x;
var vy = geometry.vertices[i].y;
var vz = geometry.vertices[i].z;
var material1 = new THREE.MeshBasicMaterial({color:Math.random()*0xffffff, side:2, overdraw:true, opacity:0.6, transparent:true} );
var mesh1 = new THREE.Mesh( geometry, material1 );
group.add(mesh1);
mesh1.position.set( (vx*2)+x,(vy*2)+y,(vz*2)+z);
}
}
这里的立方体由 8个顶点/角落组成,现在绘制了新的立方体,并在中间立方体的每个顶点上定位,这是一个简单的逻辑...... 立方几何 - geometry.vertices 和 mesh position 用于简单计算....只需浏览 jsfiddle 链接......它可能会给你一些公平的想法......