1 Star 0 Fork 0

todayjm/THREE-CSGMesh

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT
# THREE-CSGMesh Conversion of a CSG - (Constructive Solid Geometry) library for use with modern THREE.js Original version: Copyright (c) 2011 Evan Wallace (http://madebyevan.com/), under the MIT license. THREE.js rework by thrax under MIT license. Here's a running demo https://manthrax.github.io/THREE-CSGMesh/demos/CSGDemo.html [![csg screenshot](https://raw.githubusercontent.com/manthrax/THREE-CSGMesh/master/assets/CSGScreenshot.jpg)](#screenshot) And a shinier, slightly more complex demo: https://manthrax.github.io/THREE-CSGMesh/demos/CSGShinyDemo.html [![csg screenshot](https://raw.githubusercontent.com/manthrax/THREE-CSGMesh/master/assets/CSGShinyScreenshot.jpg)](#screenshot) And a more complex example showing a text mesh cut into another complex mesh via an intermediate cube: https://manthrax.github.io/THREE-CSGMesh/v2/index.html [![csg screenshot](https://raw.githubusercontent.com/manthrax/THREE-CSGMesh/master/assets/V2TestScreenshot.jpg)](#screenshot) An example showing multiple material groups, and vertex color channel: https://manthrax.github.io/THREE-CSGMesh/demos/CSGStress.html [![csg screenshot](https://raw.githubusercontent.com/manthrax/THREE-CSGMesh/master/assets/CGStressScreenshot.jpg)](#screenshot) CSG is the name of a technique for generating a new geometry as a function of two input geometries. CSG is sometimes referred to as "Boolean" operators in 3d modelling packages. Internally it uses a structure called a BSP (binary space partitioning) tree to carry out these operations. The supported operations are .subtract, .union, and .intersect. By using different combinations of these 3 operations, and changing the order of the input models, you can construct any combination of the input models. In the first screenshot/demo above, I show the possible results with a cube and a sphere... In blue is the result of the .union operation, for sphere->cube and cube->sphere (the result is same in this case ) In green is the result of the .intersect operation, for sphere->cube and cube->sphere (the result is same in this case ) In red is the result of the .subtract operation, for sphere->cube and cube->sphere. Here the result differs based on the order of the inputs. Example usage: # EXAMPLE 0: ```js //Minimal example.. subtract mesh b from mesh a: import {CSG} from "three-csg.js" scene.add(CSG.toMesh(CSG.subtract(CSG.fromMesh(a),CSG.fromMesh(b)),a.material)) ``` # EXAMPLE 1. Verbose... step by step.. ```js // Make 2 box meshes.. let meshA = new THREE.Mesh(new THREE.BoxGeometry(1,1,1)) let meshB = new THREE.Mesh(new THREE.BoxGeometry(1,1,1)) //offset one of the boxes by half its width.. meshB.position.add(new THREE.Vector3( 0.5, 0.5, 0.5) //Make sure the .matrix of each mesh is current meshA.updateMatrix() meshB.updateMatrix() //Create a bsp tree from each of the meshes let bspA = CSG.fromMesh( meshA ) let bspB = CSG.fromMesh( meshB ) // Subtract one bsp from the other via .subtract... other supported modes are .union and .intersect let bspResult = bspA.subtract(bspB) //Get the resulting mesh from the result bsp, and assign meshA.material to the resulting mesh let meshResult = CSG.toMesh( bspResult, meshA.matrix, meshA.material ) ```

简介

暂无描述 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pcjm/THREE-CSGMesh.git
git@gitee.com:pcjm/THREE-CSGMesh.git
pcjm
THREE-CSGMesh
THREE-CSGMesh
master

搜索帮助