Three.js:如何创建多边形/多面体?

时间:2015-01-23 12:15:46

标签: javascript three.js polyhedra

除了这个之外,还有其他方法可以在three.js中创建多边形/多面体吗?

	var polyhedronPts = [];
	polyhedronPts.push( new THREE.Vector2 ( -100, 600 ) );
	polyhedronPts.push( new THREE.Vector2 ( 300, 600 ) );
	polyhedronPts.push( new THREE.Vector2 ( 600, -100 ) );
	
	polyhedronShape = new THREE.Shape( polyhedronPts );

	var extrudeSettings = {amount: 20}; // bevelSegments: 2, steps: 2 , bevelSegments: 5, bevelSize: 8, bevelThickness:5
	
	var geometry = new THREE.ExtrudeGeometry( polyhedronShape, extrudeSettings );

	mesh = THREE.SceneUtils.createMultiMaterialObject( geometry, [ new THREE.MeshBasicMaterial( { color: 0x00cc00 } ), new THREE.MeshBasicMaterial( { color: 0xff3333, wireframe: true, transparent: true } ) ] );
	scene.add( mesh );

1 个答案:

答案 0 :(得分:0)

为什么不使用http://threejs.org/docs/#Reference/Extras.Geometries/PolyhedronGeometry

var verticesOfCube = [
    -1,-1,-1,    1,-1,-1,    1, 1,-1,    -1, 1,-1,
    -1,-1, 1,    1,-1, 1,    1, 1, 1,    -1, 1, 1,
];

var indicesOfFaces = [
    2,1,0,    0,3,2,
    0,4,7,    7,3,0,
    0,1,5,    5,4,0,
    1,2,6,    6,5,1,
    2,3,7,    7,6,2,
    4,5,6,    6,7,4
];

var geometry = new THREE.PolyhedronGeometry( verticesOfCube, indicesOfFaces, 6, 2 );