问题
The issue:
Subtracting a cube from a sphere provides a result where the z axis retains volume, but the y and x axis produce flat disks, as show in the image. I am not sure why the sphere is losing volume on those sides. I am using a typical subtract with threeCSG.
Code:
var geometry = new THREE.CubeGeometry( 100, 100, 100 );
var material = new THREE.MeshLambertMaterial( {color: 0xff0000, side: THREE.DoubleSide, transparent:true, opacity: .5} );
var cutter = new THREE.Mesh( geometry, material );
var geometry2 = new THREE.SphereGeometry(60,32, 32);
var material2 = new THREE.MeshLambertMaterial( {color: 0x00ff00, side: THREE.DoubleSide, transparent:true, opacity: .5} );
var massing = new THREE.Mesh( geometry2, material2 );
var cutter_bsp = new ThreeBSP(cutter);
var massing_bsp = new ThreeBSP(massing);
var new_bsp = massing_bsp.subtract(cutter_bsp);
var result = new_bsp.toMesh(material2);
result.geometry.computeVertexNormals();
result.position.y = 200;
I am using v 103, but the issue seems to be irrelevant to version as 77 shows the same issue.
Question: Why are the result's sides flat? Do I need to convert the geometry in some way before the subtract operation?
Here is the result above the box and sphere:
回答1:
@manthrax posted his code here as an answer but then deleted it. It is available here: https://github.com/manthrax/THREE-CSGMesh
Forked at https://github.com/radio412/THREE-CSGMesh/ with export token removed.
Meshes need updateMatrix() called before the operation if any transformations are applied.
This code works well. I do not know why the legacy ThreeCSG code was not working however, and it would be good to have some insight.
来源:https://stackoverflow.com/questions/55499314/threecsg-flat-sides-when-expecting-volumetric-result