创建一个圆和圆柱

首先创建圆以及圆柱的属性

varcircle= {

geometry: {

x:400,

y:24

},

position: {

x: -100,

y: -150,

z:100

},

rotation: {

x: -Math.PI/2,

y:0,

z:0

},

style: {

color:0x00ff00

}

}

varcylinder= {

geometry: {

x:200,

y:200,

z:50,

open:false

},

position: {

x: -100,

y: -180,

z:100

},

rotation: {

x:0,

y:0,

z:0

},

style: {

color:0x00ffff

}

}

代码实现

function createcircle(obj) {

geometry=newTHREE.CircleBufferGeometry(obj.geometry.x, obj.geometry.y);

materil=newTHREE.MeshBasicMaterial({

color: obj.style.color,

});

mesh=newTHREE.Mesh(geometry,materil);

if(obj.position) {

mesh.position.set(obj.position.x, obj.position.y, obj.position.z);

}

if(obj.rotation) {

mesh.rotation.set(obj.rotation.x, obj.rotation.y, obj.rotation.z);

}

scene.add(mesh)

returnmesh;

}

function createcylinder(obj) {

if(obj.geometry.open) {

open=true

}else{

open=false

}

geometry=newTHREE.CylinderBufferGeometry(obj.geometry.x, obj.geometry.y, obj.geometry.x,24,3,open);

materil=newTHREE.MeshBasicMaterial({

color: obj.style.color,

});

mesh=newTHREE.Mesh(geometry,materil);

if(obj.position) {

mesh.position.set(obj.position.x, obj.position.y, obj.position.z);

}

if(obj.rotation) {

mesh.rotation.set(obj.rotation.x, obj.rotation.y, obj.rotation.z);

}

scene.add(mesh)

returnmesh;

}

createcircle(circle)

createcylinder(cylinder);


效果图:

创建一个圆和圆柱_第1张图片

你可能感兴趣的:(创建一个圆和圆柱)