2015-11-27 12 views
5

THREE.Box3.setFromObject(*object*)が間違った値を返します。私がどのように作業しているかをあなたに示すことが最善の方法です。setFromObject(mesh)が間違った値を返します。時には

私は頂点から2つのメッシュを作成します。最初のものはtriangle()で、もう1つはtrapezoidForm()です。

var triangle = function (base, height) { 

    return [ 
     new THREE.Vector2(0, -height/2), 
     new THREE.Vector2(-base/2, height/2), 
     new THREE.Vector2(base/2, height/2) 
    ]; 
} 
var trapezoidForm = function (base, upperBase, height) { 

    return [ 

     new THREE.Vector2(-base/2, height/2), 
     new THREE.Vector2(-upperBase/2, -height/2), 
     new THREE.Vector2(upperBase/2, -height/2), 
     new THREE.Vector2(base/2, height/2), 
    ]; 

} 

私は私のメッシュを作成するために、返された値を使用します。

var material = new THREE.MeshPhongMaterial({ color: 0x666666, /*specular: 0x101010*//*, shininess: 200*/ }); 
var shape  = new THREE.Shape(vertices); 
var mesh  = new THREE.Mesh(new THREE.ShapeGeometry(shape), material); 

、シーンに配置して、バウンディングボックスを作成するためにそれを使用:今すぐ

mesh.position.set(posX, 0, posZ); 
mesh.rotation.set(-Math.PI/2, 0, 0); 
boundingBox.setFromObject(mesh); 

、私は私の2つの図形の中心を探したい。簡単です:私は、バウンディングボックスを取って、それを計算します。このように:それは間違って行くところ

var centerX = (boundingBox.max.x + boundingBox.min.x) * 0.5; 
var centerZ = (boundingBox.max.z + boundingBox.min.z) * 0.5; 

ここにある:三角形の場合は、右のスポットを計算しますが、台形のために、それが台無し。

以下は、コンソールのプリント画面です。最初の3つの頂点は三角形のためのもので、続いてバウンディングボックスです。次の4つは台形のもので、もう一度境界ボックスです。頂点の場合:最初の数字はX座標、2座標目はZ座標です。

Console log, showing the problem

望ましい結果:第2バウンディングボックスのようなものを返す必要があります:

max: X: 200 
    Z: 200 

min: X: -200 
    Z: -100 

イメージの現在の状態を示す(三角形は真ん中のマイナス記号を持って、台形ではない):

state of situation

答えて

0

最終的に解決策が見つかりました:

私は再配置する前に、私にBoundingBoxを作成するために持っているか、それを回転

//Boundingbox 
boundingBox.setFromObject(mesh); 

mesh.position.set(posX, 0, posZ); 
mesh.rotation.set(-Math.PI/2, 0, 0); 

の代わり:

mesh.position.set(posX, 0, posZ); 
mesh.rotation.set(-Math.PI/2, 0, 0); 
//Boundingbox 
boundingBox.setFromObject(mesh); 

三角形が問題を引き起こさなかった理由は、それが上にレンダリングしたので、 0,0。

関連する問題