期待体积结果时的 Threecsg 平面 [英] Threecsg flat sides when expecting volumetric result

查看:16
本文介绍了期待体积结果时的 Threecsg 平面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

从球体中减去立方体得到的结果是 z 轴保留体积,但 y 轴和 x 轴产生平面圆盘,如图所示.我不确定为什么球体在这些方面的体积会减少.我正在使用带有 ThreeCSG 的典型减法.

代码:

 var geometry = new THREE.CubeGeometry( 100, 100, 100 );var material = new THREE.MeshLambertMaterial( {color: 0xff0000, side: THREE.DoubleSide, transparent:true, opacity: .5} );var cuter = 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 cuter_bsp = new ThreeBSP(cutter);var massing_bsp = new ThreeBSP(massing);var new_bsp = massing_bsp.subtract(cutter_bsp);var 结果 = new_bsp.toMesh(material2);result.geometry.computeVertexNormals();结果.位置.y = 200;

我使用的是 v 103,但该问题似乎与版本无关,因为 77 显示了相同的问题.

问题:为什么结果的边是平的?我需要在减法运算之前以某种方式转换几何体吗?

这是盒子和球体上方的结果:

解决方案

@manthrax 在这里发布了他的代码作为答案,但随后将其删除.它可以在这里找到:

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:

解决方案

@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.

这篇关于期待体积结果时的 Threecsg 平面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆