2017-04-19 13 views
0

メッシュ内のフェイスのワールド位置を取得する必要があります。これは私のコードです:親メッシュのスケーリング後の頂点のワールド位置の取得

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); 

親のメッシュがスケーリングされていない限り、これはすべてうまくいきます。誰もこれを解決する方法を知っていますか?

+1

ルック:

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); 

ここで同様の質問があります。使用法: 'var worldVertex = yourMesh.localToWorld(yourMesh.geometry.vertices [i]);'。 [この回答](http://stackoverflow.com/questions/43265361/rotating-icosahedron-with-circles-located-at-every-vertex-in-three-js/43325479#43325479)にはいくつかの説明があります。 – TheJim01

+0

ありがとうございます。 – arpo

+0

はい、ありがとうございます。 – arpo

答えて

関連する問題