使用ThreeCSG在三个.js中的OBJ的横截面 [英] Cross-sections of OBJ in three.js using ThreeCSG

查看:264
本文介绍了使用ThreeCSG在三个.js中的OBJ的横截面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作 OBJ 的横截面使用 three.js OBJ加载程序: //github.com/chandlerprall/ThreeCSG\"rel =nofollow noreferrer> threeCSG JavaScript包装器建设性实体几何库。

I'm trying to make cross-sections of an OBJ loaded with the three.js OBJ loader using the threeCSG wrapper for the JavaScript constructive solid geometry library.

当我使用常规网格(如球体/立方体)时,交点csg操作可以很好地工作。我也可以在其初始位置(白色物体,横截面显示为红色)下方制作漂亮的横截面:

When I use a regular mesh (like a sphere/cube), the intersection csg operation works beautifully. I can also make great-looking cross-sections with an obj in its initial position (white object, cross-section displayed in red below):

然而,当我旋转对象时,横截面无论我如何更改轮换,都是一样的:

However, when I rotate the object, the cross-section is the same no matter how I change its rotation:

如何将csg交叉点操作考虑到对象的旋转?它正常工作与正常的three.js网格(立方体)。

How can I get the csg intersection operation to take into account the rotation of the object? It works as expected with a normal three.js mesh (cube).

这可能与three.js加载OBJ文件的方式有关 - 它似乎在父对象中存储一堆网格,然后可以在场景中添加/操作。这就是我执行csg操作的方式:

This may have something to do with the way three.js loads OBJ files--it appears to store a bunch of meshes in a parent object that can then be added/manipulated within a scene. This is how I do the csg operations:

threeOBJ.traverse( function ( child ) {
    if (child instanceof THREE.Mesh) {
        cc = crossSection( child );
        scene.add( cc );
    }
} );

crossSection()函数执行csg与图像和每个子网格中看到的蓝色透明平面的交叉操作。它返回一个THREE.Mesh,然后我将其添加到场景中。

The crossSection() function performs a csg intersection operation with the blue transparent plane seen in the images and each child mesh. It returns a THREE.Mesh, which I then add to the scene.

我觉得我必须指的是错误的东西,因为它没有考虑轮换但是我不知道是什么。是否有更好的方法来使用带有three.js的OBJ的csg;将所有子网格合并到一个父网格然后执行布尔运算会更好/可能吗?

I feel like I must be referring to something incorrectly since it's not taking the rotation into account but I have no idea what. Is there a better way to use csg with three.js-loaded OBJs; would it be better/possible to merge all of the child meshes into one parent mesh and then perform boolean operations?

推荐答案

要解决这个问题,我旋转飞机而不是OBJ,它完美地工作。要查看对象的所有边,您还可以简单地旋转摄像机,交替使用轨迹球控制并控制平面的移动以获得所需的视图。

To solve this problem, I rotated the plane instead of the OBJ and it worked perfectly. To see all sides of the object you can simply also rotate the camera, alternating trackball controls and controlling the movement of the plane to get the desired view.

这篇关于使用ThreeCSG在三个.js中的OBJ的横截面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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