2015-10-29 49 views
0

我在ThreeJS中有一個3D模型。將3d對象投影到2d的技術是什麼?例如,我想將3D模型投影到地面。這裏是我正在尋找的圖像: enter image description hereThreeJS - 如何將3d對象轉換爲2D表示

這就是所謂的投影?如何才能做到這一點 ?

回答

0

是的,它是一個投影到一個平面,簡單的方法來做到這三個JS是取幾何點和項目他們到一個平面上

與bufferGeometry一個例子(正常幾何圖形可能重複點別的辦法或東西..)

//create someplane to project to 
var plane = new THREE.Plane().setFromCoplanarPoints(pointA,pointB,pointC) 
//create some geometry to flatten.. 
var geometry = new THREE.BufferGeometry(); 
fillGeometry(geometry); 

var positionAttr = geometry.getAttribute("position"); 
for(var i = 0; i < positionAttr.array.length; i+=3) 
{ 
    var point = new THREE.Vector3(positionAttr.array[i],positionAttr.array[i+1],positionAttr.array[i+2]); 
    var projectedPoint = plane.projectPoint(); 
    positionAttr.array[i] = projectedPoint.x; 
    positionAttr.array[i+1] = projectedPoint.y; 
    positionAttr.array[i+2] = projectedPoint.z; 
} 
positionAttr.needsUpdate = true; 

代碼將上述扁平化的幾何形狀到由3個點給定的平面,既可以處理的東西陣列或使用幾何場景作爲煎餅..