使用ThreeCSG和减法的奇怪结果

时间:2016-03-21 11:17:49

标签: javascript three.js threecsg

我正在学习three.js,对于一个项目,我需要在圆柱体和球体之间创建一个缺陷。 以下是代码中有趣的部分:



var sphere_mesh_3 = createSphereMesh(rayon_1, 145, color);//,-2,2,-2,2);
sphere_mesh_3.position.z = 6;
//scene.add(sphere_mesh_3);

var sphere_mesh_4 = createSphereMesh(rayon_2, 145, color);//,-2,2,-2,2);
sphere_mesh_4.position.z = 7.5;
//scene.add(sphere_mesh_4);


function getZmaxRelSurfaceAspherique(mesh)
{
  var zMax = 0;
  for(var i = 0; i < mesh.geometry.vertices.length; i++)
  {
    var vec = mesh.geometry.vertices[i].clone();
    var x = vec.x;
    var y = vec.y;
    var z = vec.z;
    var abs_z = Math.abs(z);
    if(x!== 0 && y!==0 && Math.abs(z) !== 1.0)
    { 
      zMax = abs_z;
    }
  }
  return zMax;
}


var min_sph_2 = getZmaxRelSurfaceAspherique(sphere_mesh_3);
var max_sph_2 = getZmaxRelSurfaceAspherique(sphere_mesh_4);

var pos_z_1 = 6 + min_sph_2;
var pos_z_2  = 7.5 + max_sph_2;

var cylindre_sph = cylindreJointure(0,0,pos_z_2,0,0,pos_z_1,Math.abs(rayon_1*80),0xffff00);
var distance = Math.abs(pos_z_1 - pos_z_2);
scene.add(cylindre_sph);



R_sph = (max_sph_2*max_sph_2 + rayon_2*rayon_2)/(2*max_sph_2);

var geometry = new THREE.SphereGeometry( R_sph, 40, 40 );
var material = new THREE.MeshBasicMaterial( {color: 0x00ffff} );
var sphere = new THREE.Mesh( geometry, material );
sphere.position.z = pos_z_2 + R_sph - max_sph_2 ;
scene.add( sphere );

var cylindre_bsp = new ThreeBSP(cylindre_sph);
var sphere_bsp = new ThreeBSP(sphere);
var inter =  cylindre_bsp.subtract(sphere_bsp);

var result_1 = inter.toMesh(new THREE.MeshBasicMaterial({color : 0x0000ff}));

result_1.position.z = 15;
result_1.rotateX( Math.PI/2 );


scene.add(result_1);
&#13;
&#13;
&#13;

这是我的两个目标:

Cylinder and Sphere

....结果:

After cylinder.subtract(sphere)...strange result

我不明白为什么圆柱体和球体之间的减法给出了这些结果。

提前谢谢你:)

PS:我使用three.js r74和threeCSG的最新版本。就像CSG不可能用r74版本来保持Mesh的位置......但是我无法改变我的版本three.js ^^&#39;&#39;

0 个答案:

没有答案