I'm new to the three.js world... My question is: Can I bind two different shapes together as one shape? For example binding sphere and cylinder together as one?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
I updated wrapper for THREE.js r62, you can find it here: https://github.com/kraag22/csg-wrapper
Kind of, yes, there are multiple options:
add()
functionmerge()
function to merge vertices and meshes of two Geometry objects into oneMethod 1 is pretty straight forward:
Notice that 16 is repeated, so the subdivisions level in one mesh matches the other (for a decent look)
Method 2.1 - via GeometryUtils
Method 2.2 merging a Lathe half-sphere and a cylinder:
The one problem I can't address at the moment comes from the faces that are inside the mesh. Ideally those would have normals flipped so they wouldn't render, but haven't found a quick solution for that.
The 3rd is fairly straight forward. Most 3D packages allow Boolean operation on meshes (e.g. merging two meshes together with the ADD operation (meshA + meshB)). Try creating a cylinder and a sphere in Blender(free, opensource), which already has a three.js exporter. Alternatively you can export an .obj file of the merged meshes from your 3d editor or choice and use the convert_obj_three script.
Update
I've found yet another method, which might be easier/more intuitive. Remember the boolean operations I've mentioned above ?
Turns out there is an awesome js library just for that: Constructive Solid Geometry:
Chandler Prall wrote some handy functions to connect CSG with three.js. So with the CSG library and the three.js wrapper for it, you can simply do this:
Which gives you a nice result(no problems with extra faces/flipping normals/etc.):