2

我对 Three.js 非常陌生,我一直在尝试实现以下内容:

假设我有一个来自浏览器视口的某个形状的 x 和 y 坐标数组。我想在 Three.JS 中渲染这些形状,这样我就可以在 z 方向上添加一个高度。

形状本身实际上是一个“建筑物”,其中我有它的平面图坐标数组,我想通过在 Z 方向上添加一个高度来对其进行 3Dify。

我应该使用什么几何/材料/技术来实现这一目标?

4

1 回答 1

8

使用ExtrudeGeometry,您可以将 2D 元素(坐标)拉伸到 Three.js 中的 3D 对象。

此处示例:http: //stemkoski.github.io/Three.js/Extrusion.html

此处的文档:http: //threejs.org/docs/#Reference/Extras.Geometries/ExtrudeGeometry

示例中的代码:

var starPoints = [];

starPoints.push( new THREE.Vector2 (   0,  50 ) );
starPoints.push( new THREE.Vector2 (  10,  10 ) );
starPoints.push( new THREE.Vector2 (  40,  10 ) );
starPoints.push( new THREE.Vector2 (  20, -10 ) );
starPoints.push( new THREE.Vector2 (  30, -50 ) );
starPoints.push( new THREE.Vector2 (   0, -20 ) );
starPoints.push( new THREE.Vector2 ( -30, -50 ) );
starPoints.push( new THREE.Vector2 ( -20, -10 ) );
starPoints.push( new THREE.Vector2 ( -40,  10 ) );
starPoints.push( new THREE.Vector2 ( -10,  10 ) );

var starShape = new THREE.Shape( starPoints );

var extrusionSettings = {
    size: 30, height: 4, curveSegments: 3,
    bevelThickness: 1, bevelSize: 2, bevelEnabled: false,
    material: 0, extrudeMaterial: 1
};

var starGeometry = new THREE.ExtrudeGeometry( starShape, extrusionSettings );

var materialFront = new THREE.MeshBasicMaterial( { color: 0xffff00 } );
var materialSide = new THREE.MeshBasicMaterial( { color: 0xff8800 } );
var materialArray = [ materialFront, materialSide ];
var starMaterial = new THREE.MeshFaceMaterial(materialArray);

var star = new THREE.Mesh( starGeometry, starMaterial );
star.position.set(0,50,0);
scene.add(star);

// add a wireframe to model
var wireframeTexture = new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true, transparent: true } ); 
var star = new THREE.Mesh( starGeometry, wireframeTexture );
star.position.set(0,50,0);
scene.add(star);
于 2013-09-29T08:42:41.337 回答