我创建了一辆汽车使用THREE.ExtrudeGeometry,以下是我的代码:
function setExtMaterial(drawFunc,options,meshMaterial){
var geom = new THREE.ExtrudeGeometry(drawFunc(),options);
var shape = THREE.SceneUtils.createMultiMaterialObject(geom, [meshMaterial]);
return shape;
}
function drawShap1(){
var shape = new THREE.Shape();
shape.moveTo(10,10);
shape.splineThru([
new THREE.Vector2(10.2,11.8),
new THREE.Vector2(12,12)
])
shape.lineTo(18,12);
shape.splineThru([
new THREE.Vector2(19.8,11.8),
new THREE.Vector2(20,10)
])
shape.lineTo(20,4);
shape.lineTo(10,4);
shape.lineTo(10,10);
return shape;
}
var options1 = {
amount:25,
bevelThickness:1,
bevelSize:1,
beveSegments:60,
steps:60,
curveSegments:60
}
var mesh2 = new THREE.MeshPhongMaterial({
color:new THREE.Color('#FAF808')
});
var carBody = setExtMaterial(drawShap1,options1,mesh2);
carBody.position.set(-10,-3,15);
carBody.rotation.y = Math.PI/2;
car.add(carBody);
console.log(carBody)
现在我使用console.log('carBody')
查看打印内容,结果是:
群组{uuid:" 896051F5-8F4E-43C8-8EFE-B9FC4A07B7DE",名称:"",输入: " Group",parent:Object3D,children:Array 1 ...}
carBody是Group?!
现在我使用subtract():
function subtract(obj1,obj2,mesh,target){
var o1BSP = new ThreeBSP(obj1);
var o2BSP = new ThreeBSP(obj2);
var r = o1BSP.subtract(o2BSP);
var result = r.toMesh(mesh);
result.geometry.computeFaceNormals();
result.geometry.computeVertexNormals();
target.add(result);
}
var windowFront = new THREE.Mesh(new THREE.CubeGeometry(1,5,9),mesh1);
windowFront.position.set(16,6,0);
subtract(carBody,windowFront,mesh2,car);
当我使用threeBSP" subtract()时,Chrome指出了这个信息:
我看看ThreeBSP.js的代码,似乎只有Geometry和Mesh可以使用subtract()来创建这样的门:
如何在我们使用THREE.ExtrudeGeometry创建的元素上使用subtract()。非常感谢任何帮助。