@xort/cga 0.0.85 → 0.0.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/build/cga.d.ts +2032 -0
  2. package/dist/IKanimation/CCDSolver.js +2 -2
  3. package/dist/IKanimation/constaint/hinge.js +3 -1
  4. package/dist/IKanimation/constaint/slider.js +3 -1
  5. package/dist/alg/common.js +2 -2
  6. package/dist/alg/delaunay.js +1 -1
  7. package/dist/alg/extrude.js +52 -50
  8. package/dist/alg/pointset.js +5 -5
  9. package/dist/alg/trianglution.js +12 -10
  10. package/dist/alg/voronoi.js +1 -1
  11. package/dist/app.js +14 -10
  12. package/dist/diamondMaterialShader.js +6 -2
  13. package/dist/effect/breath-light.js +3 -1
  14. package/dist/extends/geometryaid.js +4 -4
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.js +7 -2
  17. package/dist/math/Color.d.ts +4 -0
  18. package/dist/math/Color.js +30 -6
  19. package/dist/math/Euler.js +9 -9
  20. package/dist/math/Mat3.js +1 -1
  21. package/dist/math/Mat4.js +6 -6
  22. package/dist/math/Quat.js +1 -1
  23. package/dist/math/Vec3.js +4 -4
  24. package/dist/math/vecs.js +9 -7
  25. package/dist/render/bufferAttribute.js +12 -28
  26. package/dist/render/geometry.js +2 -2
  27. package/dist/render/mesh.js +11 -9
  28. package/dist/render/types.d.ts +2 -2
  29. package/dist/render/types.js +2 -1
  30. package/dist/struct/3d/Box.js +3 -3
  31. package/dist/struct/3d/Capsule.js +3 -1
  32. package/dist/struct/3d/Circle.d.ts +12 -3
  33. package/dist/struct/3d/Circle.js +34 -6
  34. package/dist/struct/3d/Disk.js +1 -1
  35. package/dist/struct/3d/Line.js +4 -4
  36. package/dist/struct/3d/Path.js +13 -11
  37. package/dist/struct/3d/Plane.d.ts +3 -3
  38. package/dist/struct/3d/Plane.js +23 -18
  39. package/dist/struct/3d/Point.js +3 -1
  40. package/dist/struct/3d/Polygon.js +3 -1
  41. package/dist/struct/3d/Polyline.d.ts +9 -0
  42. package/dist/struct/3d/Polyline.js +25 -2
  43. package/dist/struct/3d/Rectangle.js +3 -1
  44. package/dist/struct/3d/Segment.js +9 -7
  45. package/dist/struct/3d/Shape.js +3 -1
  46. package/dist/struct/3d/Sphere.js +1 -1
  47. package/dist/struct/3d/Triangle.js +3 -1
  48. package/dist/struct/bsp.d.ts +0 -0
  49. package/dist/struct/bsp.js +1 -0
  50. package/dist/struct/btree.d.ts +0 -0
  51. package/dist/struct/btree.js +1 -0
  52. package/dist/struct/data/ArrayList.js +11 -9
  53. package/dist/struct/data/ArrayObject.js +3 -1
  54. package/dist/struct/kdtree.d.ts +0 -0
  55. package/dist/struct/kdtree.js +1 -0
  56. package/dist/struct/polyTree.d.ts +4 -0
  57. package/dist/struct/polyTree.js +27 -0
  58. package/dist/struct/quatTree.d.ts +0 -0
  59. package/dist/struct/quatTree.js +1 -0
  60. package/dist/struct/tree.d.ts +11 -0
  61. package/dist/struct/tree.js +26 -0
  62. package/dist/utils/types.d.ts +2 -2
  63. package/package.json +4 -3
  64. package/rollup.config.js +22 -14
  65. package/src/index.ts +1 -0
  66. package/src/math/Color.ts +6 -0
  67. package/src/struct/3d/Circle.ts +37 -8
  68. package/src/struct/3d/Plane.ts +15 -11
  69. package/src/struct/3d/PolyLine.ts +18 -1
  70. package/src/struct/3d/Polygon.ts +2 -0
  71. package/src/struct/bsp.ts +0 -0
  72. package/src/struct/btree.ts +0 -0
  73. package/src/struct/kdtree.ts +0 -0
  74. package/src/struct/polyTree.ts +8 -0
  75. package/src/struct/quatTree.ts +0 -0
  76. package/src/struct/tree.ts +30 -0
  77. package/tsconfig.json +2 -0
  78. package/dist/shape/arc.d.ts +0 -2
  79. package/dist/shape/arc.js +0 -14
  80. package/src/shape/arc.ts +0 -14
@@ -1,10 +1,10 @@
1
1
  import { Vec3, v3 } from '../../math/Vec3';
2
- import { angle, pointsCollinear } from '../../alg/common';
2
+ import { angle, pointsCollinear, rotate } from '../../alg/common';
3
3
  import { Line } from './Line';
4
4
 
5
5
  export class Circle {
6
6
  startAngle: number = 0;
7
- endAngle: number = Math.PI * 2;
7
+ lengthAngle: number = Math.PI * 2;
8
8
  radiusSqr: number = 0;
9
9
  /**
10
10
  * 圆圈
@@ -12,7 +12,9 @@ export class Circle {
12
12
  * @param {Vec3} normal 法线
13
13
  * @param {Number} radius 半径
14
14
  */
15
- constructor(public center: Vec3 = new Vec3(), public radius: number = 0, public normal: Vec3 = Vec3.UnitY) {
15
+ constructor(public center: Vec3 = new Vec3(), public radius: number = 0, startAngle = 0, lengthAngle = Math.PI * 2, public normal: Vec3 = Vec3.UnitY) {
16
+ this.startAngle = startAngle;
17
+ this.lengthAngle = lengthAngle;
16
18
 
17
19
  }
18
20
 
@@ -30,7 +32,7 @@ export class Circle {
30
32
  arc1(fixp0: Vec3, fixp1: Vec3, movep: Vec3, normal?: Vec3) {
31
33
  this.setFrom3Points(fixp0, fixp1, movep);
32
34
  this.startAngle = 0
33
- this.endAngle = angle(fixp0.clone().sub(this.center).normalize(), fixp1.clone().sub(this.center).normalize(), this.normal || normal)
35
+ this.lengthAngle = angle(fixp0.clone().sub(this.center).normalize(), fixp1.clone().sub(this.center).normalize(), this.normal || normal)
34
36
  }
35
37
  /**
36
38
  * 全两个点确定半径,后面点确定 弧度 ,只需要检测鼠标移动时鼠标是否跨过第一条半径即可确定顺逆时针
@@ -47,8 +49,6 @@ export class Circle {
47
49
  }
48
50
 
49
51
 
50
-
51
-
52
52
  setFrom3Points(p0: Vec3, p1: Vec3, p2: Vec3, normal?: Vec3) {
53
53
  // if (pointsCollinear(p0, p1, p2))
54
54
  // throw ("calcCircleFromThreePoint:三点共线或者距离太近");
@@ -71,8 +71,37 @@ export class Circle {
71
71
  this.normal = normal;
72
72
  return this;
73
73
  }
74
+
75
+
76
+ /**
77
+ * 将圆环或者圆弧转化为路径点,生成XY平面上得三维点
78
+ * @param center 中心点
79
+ * @param radius 半径
80
+ * @param startAngle 起始角 右手坐标系 以X正坐标轴为起点 单位弧度
81
+ * @param lengthAngle 弧度长度 单位弧度
82
+ * @param segment 分段
83
+ */
84
+ static toVertices(center: Vec3, radius: number, startAngle: number = 0, lengthAngle: number = Math.PI * 2, segment: number = 16) {
85
+ const Xvec: Vec3 = Vec3.UnitX;
86
+ Xvec.multiplyScalar(radius);
87
+
88
+ const result:Vec3[]=[]
89
+
90
+ const up: Vec3 = Vec3.UnitY;
91
+ const perAngle = lengthAngle / segment;
92
+ for (let i = 0; i <= segment; i++) {
93
+ const langlei = perAngle * i + startAngle;
94
+
95
+ const vi = Xvec.clone().applyAxisAngle(up, langlei).add(center);
96
+
97
+ result.push(vi);
98
+ }
99
+
100
+ return result;
101
+ }
102
+
74
103
  }
75
104
 
76
- export function circle(center?: Vec3, radius?: number, normal?: Vec3) {
77
- return new Circle(center, radius, normal);
105
+ export function circle(center?: Vec3, radius?: number) {
106
+ return new Circle(center, radius);
78
107
  }
@@ -15,6 +15,7 @@ import { IGeometry } from '../../render/geometry';
15
15
  import { ISplitResult } from '../../alg/split';
16
16
  import { Line } from './Line';
17
17
  import { MeshTool } from '../../render/mesh';
18
+ import { Polygon } from './Polygon';
18
19
 
19
20
  class Plane {
20
21
 
@@ -253,23 +254,26 @@ class Plane {
253
254
 
254
255
  /**
255
256
  * 平面切割线段
256
- * @param polyVS
257
+ * @param polygon
257
258
  */
258
- splitPolyVS(polyVS: Vec3[]) {
259
- polyVS = [...polyVS];
260
- MeshTool.indexable(polyVS);
259
+ splitConvexPolygon(polygon: Vec3[]) {
260
+ polygon = [...polygon];
261
+ MeshTool.indexable(polygon);
261
262
 
262
263
  let jd0 = -1;//找出第一个交点
263
264
  let jdp0: any;//找出第一个交点
264
- let lastOriention = this.orientationPoint(polyVS[0]);
265
- for (let i = 0; i < polyVS.length - 1; i++) {
266
- const v = polyVS[i];
265
+ let lastOriention = this.orientationPoint(polygon[0]);
266
+ const plen = polygon.length;
267
+ //分割点
268
+ const splitPoints = [];
269
+ const pVs = [];
270
+ const nVs = [];
271
+ for (let i = 1; i <= plen; i++) {
272
+ const v = polygon[i % plen];
267
273
  const oriention = this.orientationPoint(v);
268
- if (oriention === Orientation.Common || lastOriention !== Orientation.None && lastOriention !== oriention) {
274
+ if (oriention === Orientation.Common ) {
269
275
  jd0 = i;
270
- jdp0 = v.clone();
271
- lastOriention = oriention;
272
- break;
276
+ jdp0 = v.clone();
273
277
  }
274
278
  lastOriention = oriention;
275
279
  //TODO
@@ -6,7 +6,12 @@ import { Segment } from "./Segment";
6
6
  import { ArrayList } from '../data/ArrayList';
7
7
  import { Polygon } from "./Polygon";
8
8
 
9
-
9
+ export enum ClipType {
10
+ Intersection = 0,
11
+ Union = 1,
12
+ Difference = 2,
13
+ Xor = 3
14
+ };
10
15
  /**
11
16
  * 线段正反原则:右手坐标系中,所在平面为XZ平面,把指向方向看着负Z轴,x正为正方向,x负为负方向
12
17
  */
@@ -20,6 +25,18 @@ export class Polyline<T> extends ArrayList<T> {
20
25
  this.isCoPlanar = true;
21
26
  }
22
27
 
28
+ static CleanPolygon(polys: any, delta: number, jointype: JoinType = JoinType.Square, endtype: EndType = EndType.etClosedPolygon, limit: number) {
29
+
30
+ }
31
+ static OffsetPaths(polys: any, delta: number, jointype: JoinType = JoinType.Square, endtype: EndType = EndType.etClosedPolygon, limit: number) {
32
+
33
+ }
34
+
35
+ //转化为简单多边形 (无重复点,无相交的边 )不自交多边形
36
+ static SimplifyPolygon(polys: any, delta: number, jointype: JoinType = JoinType.Square, endtype: EndType = EndType.etClosedPolygon, limit: number) {
37
+
38
+ }
39
+
23
40
  /**
24
41
  * 偏移
25
42
  * @param {Number} distance 偏移距离
@@ -9,6 +9,8 @@ export class Polygon<T> extends Polyline<T> {
9
9
  super(vs);
10
10
  }
11
11
 
12
+
13
+
12
14
  offset(distance: number, normal: Vec3 = Vec3.UnitY): Polygon<T> {
13
15
 
14
16
  const segments = [];
File without changes
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ import { Tree } from "./tree";
2
+
3
+ export class PolyTree extends Tree{
4
+ constructor() {
5
+ super();
6
+ }
7
+
8
+ }
File without changes
@@ -0,0 +1,30 @@
1
+ export class Tree {
2
+ N: number = 2;//数量决定是N叉树;
3
+ children!: this[];
4
+ findFn!: Function;
5
+ objects: any[] = [];
6
+
7
+ constructor(N: number = -1) {
8
+ this.N = N;
9
+ if (N !== -1)
10
+ this.children = new Array(N)
11
+ }
12
+
13
+ setObject(obj: any, generateFn: Function, findFn: Function) {
14
+ generateFn(this, obj);
15
+ this.findFn = findFn;
16
+ }
17
+
18
+ add(obj: any) {
19
+
20
+ }
21
+
22
+ remove(obj: any) {
23
+
24
+ }
25
+
26
+ find(condition: any) {
27
+
28
+ this.findFn(this, condition);
29
+ }
30
+ }
package/tsconfig.json CHANGED
@@ -15,6 +15,8 @@
15
15
  // "checkJs": true, /* Report errors in .js files. */
16
16
  // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
17
17
  "declaration": true, /* Generates corresponding '.d.ts' file. */
18
+ // "declarationDir": "dist/types",
19
+ // "emitDeclarationOnly": true,
18
20
  // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
19
21
  // "sourceMap": true, /* Generates corresponding '.map' file. */
20
22
  // "outFile": "./", /* Concatenate and emit output to single file. */
@@ -1,2 +0,0 @@
1
- import { Vec3 } from "../math/Vec3";
2
- export declare function Circle(center: Vec3, radius: number, segment: number, startAngle: number, lenAngle: number): void;
package/dist/shape/arc.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- /*
3
- * @Description :
4
- * @Author : 赵耀圣
5
- * @QQ : 549184003
6
- * @Date : 2021-03-15 09:40:01
7
- * @LastEditTime : 2021-03-15 09:42:14
8
- * @FilePath : \cga.js\src\shape\arc.ts
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Circle = void 0;
12
- function Circle(center, radius, segment, startAngle, lenAngle) {
13
- }
14
- exports.Circle = Circle;
package/src/shape/arc.ts DELETED
@@ -1,14 +0,0 @@
1
- /*
2
- * @Description :
3
- * @Author : 赵耀圣
4
- * @QQ : 549184003
5
- * @Date : 2021-03-15 09:40:01
6
- * @LastEditTime : 2021-03-15 09:42:14
7
- * @FilePath : \cga.js\src\shape\arc.ts
8
- */
9
-
10
- import { Vec3 } from "../math/Vec3";
11
-
12
- export function Circle(center: Vec3, radius: number, segment: number, startAngle: number, lenAngle: number) {
13
-
14
- }