我需要在网格中获得面部的世界位置。这是我的代码:
var that = this,
addPoint,
geometry = mesh.geometry,
worldPos = mesh.getWorldPosition();
that.allMeshes[mesh.uuid] = {
mesh: mesh,
points: {}
};
addPoint = function (currPoint, face) {
var point = that.octree.add([worldPos.x + currPoint.x, worldPos.y + currPoint.y, worldPos.z + currPoint.z], {mesh: mesh, geometry: geometry, face: face});
that.allMeshes[mesh.uuid].points[point.id] = point;
};
geometry.faces.forEach(function(face) {
//Get the faces points cords
addPoint(geometry.vertices[face.a], face);
addPoint(geometry.vertices[face.b], face);
addPoint(geometry.vertices[face.c], face);
}, this);
除非父网格被缩放,否则这一切都很有效。有谁知道如何解决这个问题?
答案 0 :(得分:0)
感谢@ TheJim01,我找到了这个解决方案。
var that = this,
addPoint,
geometry = mesh.geometry;
that.allMeshes[mesh.uuid] = {
mesh: mesh,
points: {}
};
addPoint = function (currPoint, face) {
//Get the world position like this.
var vector = currPoint.clone();
mesh.localToWorld(vector);
var point = that.octree.add([vector.x, vector.y, vector.z], {mesh: mesh, geometry: geometry, face: face});
that.allMeshes[mesh.uuid].points[point.id] = point;
};
//Run this on the mesh
mesh.updateMatrixWorld();
geometry.faces.forEach(function(face) {
//Get the faces points cords
addPoint(geometry.vertices[face.a], face);
addPoint(geometry.vertices[face.b], face);
addPoint(geometry.vertices[face.c], face);
}, this);
这是一个类似的问题: How to get the absolute position of a vertex in three.js?