- 最后登录
- 2022-5-23
- 在线时间
- 217 小时
- 阅读权限
- 20
- 注册时间
- 2013-10-19
- 积分
- 301
- 帖子
- 209
- 精华
- 0
- UID
- 1329505
- 积分
- 301
- 帖子
- 209
- 精华
- 0
- UID
- 1329505
|
本帖最后由 怀表 于 2022-5-12 23:32 编辑
https://github.com/worldmaker18349276/twisty-sphere
没有文档,我也搞不清楚是怎么自定义的。从例子看很炫酷。不过没边框很难看清块。
切割好像有两个方法sliceBySphere和sliceByPlane。不过球面切割生成魔方很慢,把resolution参数调小可提高速度。
调了半天弄出了个斜转,等明天再来试一下球面切割。- cube = CSG.cube({center: [0, 0, 0], radius: [1.1, 1.1, 1.1]})
- .intersect(CSG.cube({center: [ 0,-1, 0], radius: [2, 2, 2]}).setColor(1,1,1))
- .intersect(CSG.cube({center: [ 0, 1, 0], radius: [2, 2, 2]}).setColor(1,1,0))
- .intersect(CSG.cube({center: [-1, 0, 0], radius: [2, 2, 2]}).setColor(0,0,1))
- .intersect(CSG.cube({center: [ 1, 0, 0], radius: [2, 2, 2]}).setColor(0,1,0))
- .intersect(CSG.cube({center: [ 0, 0,-1], radius: [2, 2, 2]}).setColor(1,0,0))
- .intersect(CSG.cube({center: [ 0, 0, 1], radius: [2, 2, 2]}).setColor(1,0.6,0.2));
- var puzzle = new ModeledSphPuzzle(cube);
- puzzle.sliceByPlane([1,1,1],0)
- puzzle.sliceByPlane([-1,1,1],0)
- puzzle.sliceByPlane([-1,-1,1],0)
- puzzle.sliceByPlane([-1,-1,-1],0)
- puzzle.sliceByPlane([-1,1,-1],0)
- puzzle.sliceByPlane([1,-1,1],0)
- puzzle.sliceByPlane([1,-1,-1],0)
- puzzle.sliceByPlane([1,1,-1],0)
- puzzle.clean();
- puzzle.prepare();
- var world = new ModeledSphPuzzleWorld(puzzle, "display");
复制代码
- cube = CSG.cube({center: [0, 0, 0], radius: [1.1, 1.1, 1.1]})
- .intersect(CSG.cube({center: [ 0,-1, 0], radius: [2, 2, 2]}).setColor(1,1,1))
- .intersect(CSG.cube({center: [ 0, 1, 0], radius: [2, 2, 2]}).setColor(1,1,0))
- .intersect(CSG.cube({center: [-1, 0, 0], radius: [2, 2, 2]}).setColor(0,0,1))
- .intersect(CSG.cube({center: [ 1, 0, 0], radius: [2, 2, 2]}).setColor(0,1,0))
- .intersect(CSG.cube({center: [ 0, 0,-1], radius: [2, 2, 2]}).setColor(1,0,0))
- .intersect(CSG.cube({center: [ 0, 0, 1], radius: [2, 2, 2]}).setColor(1,0.6,0.2));
- var puzzle = new ModeledSphPuzzle(cube);
- puzzle.sliceByPlane([0,1,0],0)
- puzzle.sliceByPlane([1,0,1],0)
- puzzle.sliceByPlane([-1,0,1],0)
- puzzle.sliceByPlane([1,0,0],0)
- puzzle.sliceByPlane([0,0,1],0)
- puzzle.clean();
- puzzle.prepare();
- var world = new ModeledSphPuzzleWorld(puzzle, "display")
复制代码
- var phi = (Math.sqrt(5) + 1)/2;
- function fzy_add(set, elem) {
- set.add(fzy_snap(elem, set));
- }
- function csort(arr0) {
- var arr_min = arr0.slice();
- var arr_ = arr0.slice();
- for ( let i=0,len=arr0.length; i<len; i++ ) {
- if ( fzy_cmp(arr_, arr_min) < 0 )
- arr_min = arr_.slice();
- arr_.push(arr_.shift());
- }
- return arr_min;
- }
- var radius = (phi + 1)/Math.sqrt(phi + 2);
- var offset = 1;
- var faces = new Set();
- var vertices = [[1,1,1]];
- for ( let i=0; i<4; i++ )
- vertices.push(rotate(vertices[vertices.length-1], [1/2,0,1/phi/2,phi/2]));
- faces.add(csort(vertices));
- for ( let face of faces ) {
- fzy_add(faces, csort(face.map(v => rotate(v, [1/2,1/2,1/2,1/2]))));
- fzy_add(faces, csort(face.map(v => rotate(v, [1/2,0,1/phi/2,phi/2]))));
- }
- var polygons = [];
- for ( let face of faces ) {
- let polygon = new CSG.Polygon(face.map(v => new CSG.Vertex(new CSG.Vector3D(...v))));
- let {x, y, z} = polygon.plane.normal;
- let [r, g, b] = [x, y, z].map(v => Math.sign(v) * Math.ceil(Math.abs(v) - 0.01)).map(v => (v+1)/2);
- polygon.setColor(r, g, b);
- polygons.push(polygon);
- }
- var dodeca = CSG.fromPolygons(polygons);
- var puzzle = new ModeledSphPuzzle(dodeca, radius);
- puzzle.sliceByPlane([0,1,0],0)
- puzzle.sliceByPlane([1,0,1],0)
- puzzle.sliceByPlane([-1,0,1],0)
- puzzle.sliceByPlane([1,0,0],0)
- puzzle.sliceByPlane([0,0,1],0)
- puzzle.clean(1);
- puzzle.prepare();
- var world = new ModeledSphPuzzleWorld(puzzle, "display")
复制代码
感觉跟胡波的正四面体切割群魔方java助手的用法有些像,不过定义多面体得手写,切割的面的法向量也得手写,调配色也很麻烦。
居然没有打乱功能。 |
|