如何在three.js经过CSG.js处理后添加纹理



这是我的代码:

var materialNormal = new THREE.MeshNormalMaterial();
var cubeGeometry = new THREE.CubeGeometry( 20, 500, 1000, 1, 1, 1 );
var cubeMesh = new THREE.Mesh( cubeGeometry );
cubeMesh.position.set(-50, 60, 0);
//scene.add(cubeMesh); //Meu
var cubeBSP = new ThreeBSP( cubeMesh );
var cubeGeometry = new THREE.CubeGeometry( 90, 90, 90, 1, 1, 1 );
var mat = new THREE.MeshBasicMaterial({color:0xffffff, shading: THREE.FlatShading, overdraw:0.5});
var cube3Mesh = new THREE.Mesh( cubeGeometry, mat );
cube3Mesh.position.set(-50, 60, 0);
//scene.add(cubeMesh); //Meu
var cubeOutroBSP = new ThreeBSP( cube3Mesh );
// Example #1 - Cube subtract
var newBSP = cubeBSP.subtract(cubeOutroBSP);
var newMesh = newBSP.toMesh(materialNormal);
newMesh.position.set(-180, 60, 0);
scene.add( newMesh );

如何为减法生成的对象添加纹理?

three.CSG返回的网格就像默认的three.js mesh,您可以在其中应用具有纹理的材料。

在您的示例中,这将是newMesh,因此:

var texture = THREE.ImageUtils.loadTexture('yourtexture.jpg');
var material = new THREE.MeshPhongMaterial( { map: texture } );
//...
var newMesh = newBSP.toMesh( material );
newMesh.position.set(-180, 60, 0);
scene.add( newMesh );

相关内容

  • 没有找到相关文章

最新更新