@xort/cga 0.0.71 → 0.0.74

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 (65) hide show
  1. package/build/{cga.js → @xort_cga.js} +13798 -13792
  2. package/dist/IKanimation/Bone.js +3 -1
  3. package/dist/IKanimation/CCDSolver.js +2 -2
  4. package/dist/IKanimation/constaint/hinge.js +3 -1
  5. package/dist/IKanimation/constaint/slider.js +3 -1
  6. package/dist/alg/common.js +2 -2
  7. package/dist/alg/extrude.js +56 -54
  8. package/dist/alg/pointset.js +5 -5
  9. package/dist/alg/trianglution.js +12 -10
  10. package/dist/app.js +14 -10
  11. package/dist/diamondMaterialShader.js +6 -2
  12. package/dist/effect/breath-light.js +3 -1
  13. package/dist/extends/geometryaid.js +7 -7
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +8 -2
  16. package/dist/math/Color.d.ts +29 -0
  17. package/dist/math/Color.js +201 -0
  18. package/dist/math/Euler.js +12 -10
  19. package/dist/math/HVec3.js +3 -1
  20. package/dist/math/Mat3.js +1 -1
  21. package/dist/math/Mat4.js +6 -6
  22. package/dist/math/Quat.js +4 -2
  23. package/dist/math/Vec.js +3 -1
  24. package/dist/math/Vec2.js +3 -1
  25. package/dist/math/Vec3.js +7 -5
  26. package/dist/math/Vec4.js +3 -1
  27. package/dist/math/vector.js +9 -7
  28. package/dist/render/buffer-attribute.js +12 -28
  29. package/dist/render/eventhandler.d.ts +2 -2
  30. package/dist/render/eventhandler.js +14 -8
  31. package/dist/render/geometry.d.ts +1 -1
  32. package/dist/render/geometry.js +2 -2
  33. package/dist/render/mesh.js +11 -9
  34. package/dist/render/thing.js +10 -8
  35. package/dist/render/types.js +2 -1
  36. package/dist/struct/3d/Box.js +3 -3
  37. package/dist/struct/3d/Capsule.js +3 -1
  38. package/dist/struct/3d/Circle.js +2 -2
  39. package/dist/struct/3d/Disk.js +1 -1
  40. package/dist/struct/3d/Line.js +4 -4
  41. package/dist/struct/3d/Path.js +13 -11
  42. package/dist/struct/3d/Plane.js +12 -10
  43. package/dist/struct/3d/Point.js +3 -1
  44. package/dist/struct/3d/Polygon.js +3 -1
  45. package/dist/struct/3d/Polyline.js +3 -1
  46. package/dist/struct/3d/Rectangle.js +3 -1
  47. package/dist/struct/3d/Segment.js +9 -7
  48. package/dist/struct/3d/Shape.js +3 -1
  49. package/dist/struct/3d/Sphere.js +1 -1
  50. package/dist/struct/3d/Triangle.js +3 -1
  51. package/dist/struct/data/ArrayList.js +11 -9
  52. package/dist/struct/data/ArrayObject.js +3 -1
  53. package/docs/guide/README.md +6 -6
  54. package/docs/guide/distLineAll.md +5 -5
  55. package/docs/guide/distPointAll.md +6 -6
  56. package/docs/guide/distRayAll.md +4 -4
  57. package/docs/guide/distSegmentAll.md +1 -1
  58. package/git.sh +2 -2
  59. package/package.json +2 -2
  60. package/readme.md +8 -8
  61. package/rollup.config.js +1 -1
  62. package/src/index.ts +3 -0
  63. package/src/math/Color.ts +157 -0
  64. package/src/render/eventhandler.ts +5 -2
  65. package/src/render/geometry.ts +2 -2
@@ -5,7 +5,7 @@
5
5
  ## 三维向量点
6
6
 
7
7
  ```js
8
- import * as cga from "@xtor/cga.js";
8
+ import * as cga from "@xtor/cga";
9
9
  function randomV3() {
10
10
  return cga.Vec3(
11
11
  Math.random() * 100 - 50,
@@ -25,7 +25,7 @@ function randomV3() {
25
25
  </ClientOnly>
26
26
 
27
27
  ```javascript
28
- import * as cga from "@xtor/cga.js";
28
+ import * as cga from "@xtor/cga";
29
29
  var point0 = new cga.Vec3().copy(randomV3());
30
30
  var point1 = new cga.Vec3().copy(randomV3());
31
31
  var result = point0.distancePoint(point1);
@@ -41,7 +41,7 @@ var result = point0.distancePoint(point1);
41
41
  </ClientOnly>
42
42
 
43
43
  ```javascript
44
- import * as cga from "@xtor/cga.js";
44
+ import * as cga from "@xtor/cga";
45
45
  var point = new cga.Vec3().copy(randomV3());
46
46
  var line = new cga.Line(randomV3(), randomV3());
47
47
  var result = point.distanceTo(line);
@@ -55,7 +55,7 @@ var result = point.distanceTo(line);
55
55
  </ClientOnly>
56
56
 
57
57
  ```javascript
58
- import * as cga from "@xtor/cga.js";
58
+ import * as cga from "@xtor/cga";
59
59
  var point = new cga.Vec3().copy(randomV3());
60
60
  var ray = new cga.Ray(randomV3(), randomV3().normalize());
61
61
  var result = point.distanceRay(ray);
@@ -69,7 +69,7 @@ var result = point.distanceRay(ray);
69
69
  </ClientOnly>
70
70
 
71
71
  ```javascript
72
- import * as cga from "@xtor/cga.js";
72
+ import * as cga from "@xtor/cga";
73
73
  var point = new cga.Vec3().copy(randomV3());
74
74
  var seg = new cga.Segment(randomV3(), randomV3());
75
75
  var result = point.distanceSegment(seg);
@@ -83,7 +83,7 @@ var result = point.distanceSegment(seg);
83
83
  </ClientOnly>
84
84
 
85
85
  ```javascript
86
- import * as cga from "@xtor/cga.js";
86
+ import * as cga from "@xtor/cga";
87
87
  var vs = [];
88
88
  for (let i = 0; i < 100000; i++) {
89
89
  vs.push(randomV3());
@@ -14,7 +14,7 @@ title:射线
14
14
  </ClientOnly>
15
15
 
16
16
  ```javascript
17
- import * as cga from "@xtor/cga.js";
17
+ import * as cga from "@xtor/cga";
18
18
  var ray0 = new cga.Ray(randomV3(), randomV3().normalize());
19
19
  var ray1 = new cga.Ray(randomV3(), randomV3().normalize());
20
20
  var result = ray0.distanceLine(ray1);
@@ -30,7 +30,7 @@ var result = ray0.distanceLine(ray1);
30
30
  </ClientOnly>
31
31
 
32
32
  ```javascript
33
- import * as cga from "@xtor/cga.js";
33
+ import * as cga from "@xtor/cga";
34
34
  var ray = new cga.Ray(randomV3(), randomV3().normalize());
35
35
  var segment = new cga.Segment(randomV3(), randomV3());
36
36
  var result = ray.distanceSegment(segment);
@@ -46,7 +46,7 @@ var result = ray.distanceSegment(segment);
46
46
  </ClientOnly>
47
47
 
48
48
  ```javascript
49
- import * as cga from "@xtor/cga.js";
49
+ import * as cga from "@xtor/cga";
50
50
  var ray = new cga.Ray(randomV3(), randomV3().normalize());
51
51
  var triangle = new cga.Triangle(randomV3(), randomV3(),randomV3());
52
52
  var result = ray.distanceTriangle(segment);
@@ -62,7 +62,7 @@ var result = ray.distanceTriangle(segment);
62
62
  </ClientOnly>
63
63
 
64
64
  ```javascript
65
- import * as cga from "@xtor/cga.js";
65
+ import * as cga from "@xtor/cga";
66
66
  var ray = new cga.Ray(randomV3(), randomV3());
67
67
  var tringle = new cga.Tringle(randomV3(), randomV3(), randomV3());
68
68
  var result = ray.distanceTriangle(triangle);
@@ -12,7 +12,7 @@ sidebarDepth: 2
12
12
  </ClientOnly>
13
13
 
14
14
  ```javascript
15
- import * as cga from "@xtor/cga.js";
15
+ import * as cga from "@xtor/cga";
16
16
  var seg0 = new cga.Segment(randomV3(), randomV3());
17
17
  var seg1 = new cga.Segment(randomV3(), randomV3());
18
18
  var result = seg0.distanceSegment(seg);
package/git.sh CHANGED
@@ -3,10 +3,10 @@
3
3
  # 确保脚本抛出遇到的错误
4
4
  set -e
5
5
 
6
- cnpm sync xtorcga
6
+ cnpm sync @xort/cga
7
7
 
8
8
  git add -A
9
9
  # git add .
10
- git commit -m 'xtorcga'
10
+ git commit -m '@xort/cga'
11
11
 
12
12
  git push origin master
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@xort/cga",
3
- "version": "0.0.71",
3
+ "version": "0.0.74",
4
4
  "description": "Xtor Compute Geometry Algorithm Libary 计算几何算法库",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
7
7
  "scripts": {
8
- "release": "tsc && git.sh",
8
+ "release": "tsc && npm publish && git.sh",
9
9
  "dev": "webpack-dev-server",
10
10
  "build:dev": "webpack --mode development",
11
11
  "build:prod": "webpack --mode production",
package/readme.md CHANGED
@@ -27,9 +27,9 @@ Computional Geometry Algorithm implement JavaScript,javascript 实现计算机
27
27
  ## 安装
28
28
 
29
29
  ```
30
- npm install xtorcga -D
30
+ npm i @xort/cga
31
31
  国内
32
- cnpm install xtorcga -D
32
+ cnpm i @xort/cga
33
33
  ```
34
34
 
35
35
  ## 使用
@@ -37,7 +37,7 @@ cnpm install xtorcga -D
37
37
  - 全部引用;:
38
38
 
39
39
  ```javascript
40
- import * as cga from "xtorcga";
40
+ import * as cga from "@xort/cga";
41
41
  function randomV3() {
42
42
  return cga.v3(
43
43
  Math.random() * 100 - 50,
@@ -54,7 +54,7 @@ var result = point.distanceSegment(seg);
54
54
  - 按需求引用:
55
55
 
56
56
  ```javascript
57
- import { v3, Point, Segment } from "xtorcga";
57
+ import { v3, Point, Segment } from "@xort/cga";
58
58
  function randomV3() {
59
59
  return v3(
60
60
  Math.random() * 100 - 50,
@@ -68,12 +68,12 @@ var seg = new Segment(randomV3(), randomV3());
68
68
  var result = point.distanceSegment(seg);
69
69
  ```
70
70
 
71
- - 网页嵌入:直接下载使用 build 目录下面的 xtorcga,包含到项目中
71
+ - 网页嵌入:直接下载使用 build 目录下面的 @xort/cga,包含到项目中
72
72
 
73
73
  ```html
74
- <script src="xtorcga" />
74
+ <script src="@xort/@xort_cga.js" />
75
75
  或者
76
- <script src="https://raw.githack.com/yszhao91/xtorcga/master/build/xtorcga" />
76
+ <script src="https://raw.githack.com/yszhao91/@xort/cga/master/build/@xort_cga.js" />
77
77
  <script>
78
78
  var point = new cga.Point(1, 2, 3);
79
79
  var line = new cga.Line(
@@ -87,7 +87,7 @@ var result = point.distanceSegment(seg);
87
87
  ## 项目编译
88
88
 
89
89
  ```shell
90
- npm run build //js 编译到build目录下生成xtorcga dist目录下生成每个文件的js和.d.ts
90
+ npm run build //js 编译到build目录下生成@xort/cga dist目录下生成每个文件的js和.d.ts
91
91
  npm run dev //运行项目,自己更改源码测试
92
92
  ```
93
93
 
package/rollup.config.js CHANGED
@@ -59,7 +59,7 @@ export default {
59
59
  external: ['lodash'],
60
60
  plugins: plugins,
61
61
  output: {
62
- file: path.join(DIST ? 'dist' : 'build', 'cga' + (MIN ? '.min' : '') + '.js'),
62
+ file: path.join(DIST ? 'dist' : 'build', '@xort_cga' + (MIN ? '.min' : '') + '.js'),
63
63
  format: 'umd',
64
64
  // format: 'umd',
65
65
  name: 'cga',
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from "./math/Mat4"
7
7
  export * from "./math/Quat"
8
8
  export * from "./math/Math"
9
9
  export * from "./math/Euler"
10
+ export * from "./math/Color"
10
11
  //common
11
12
  export * from "./math/vector"
12
13
 
@@ -36,6 +37,8 @@ export * from "./struct/3d/Sphere"
36
37
  export * from "./alg/delaunator"
37
38
  export * from "./alg/voronoi"
38
39
 
40
+ export * from "./render/eventhandler"
41
+
39
42
  export * from "./extends/geometryaid"
40
43
 
41
44
  //Geometry
@@ -0,0 +1,157 @@
1
+ import { EventHandler } from "src/render/eventhandler";
2
+ import * as THREE from "three"
3
+
4
+
5
+ export function hue2rgb(p: number, q: number, t: number) {
6
+
7
+ if (t < 0) t += 1;
8
+ if (t > 1) t -= 1;
9
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
10
+ if (t < 1 / 2) return q;
11
+ if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t);
12
+ return p;
13
+
14
+ }
15
+
16
+ export function SRGBToLinear(c: number) {
17
+
18
+ return (c < 0.04045) ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
19
+
20
+ }
21
+
22
+ export function LinearToSRGB(c: number) {
23
+
24
+ return (c < 0.0031308) ? c * 12.92 : 1.055 * (Math.pow(c, 0.41666)) - 0.055;
25
+
26
+ }
27
+
28
+ export class Color extends EventHandler {
29
+ get isColor() {
30
+ return true;
31
+ }
32
+
33
+ constructor(private _r: number = 0, private _g: number = 0, private _b: number = 0, private _a: number = 1) {
34
+ super();
35
+ }
36
+
37
+ get r() {
38
+ return this._r;
39
+ }
40
+
41
+ set r(value) {
42
+ if (this._r !== value) {
43
+ this._r = value;
44
+ this.fire('change', 'r', this._r, value)
45
+ }
46
+ }
47
+
48
+ get g() {
49
+ return this._g;
50
+ }
51
+
52
+ set g(value) {
53
+ if (this._g !== value) {
54
+ this._g = value;
55
+ this.fire('change', 'g', this._g, value)
56
+ }
57
+ }
58
+
59
+ get b() {
60
+ return this._g;
61
+ }
62
+
63
+ set b(value) {
64
+ if (this._b !== value) {
65
+ this._b = value;
66
+ this.fire('change', 'b', this._b, value)
67
+ }
68
+ THREE.Color
69
+ }
70
+
71
+ get a() {
72
+ return this._a;
73
+ }
74
+
75
+ set a(value) {
76
+ if (this._a !== value) {
77
+ this._a = value;
78
+ this.fire('change', 'a', this._a, value)
79
+ }
80
+ }
81
+
82
+
83
+ set(value: any) {
84
+
85
+ if (value && value.isColor) {
86
+ this.copy(value);
87
+ } else if (typeof value === 'number') {
88
+ this.setHex(value);
89
+ }
90
+
91
+ return this;
92
+ }
93
+
94
+ setHex(hex: number) {
95
+
96
+ hex = Math.floor(hex);
97
+ if (hex > 0xffffff) {
98
+ this._r = (hex >> 32 & 255) / 255;
99
+ this._g = (hex >> 16 & 255) / 255;
100
+ this._b = (hex >> 8 & 255) / 255;
101
+ this._a = (hex & 255) / 255;
102
+ } else {
103
+ this._r = (hex >> 16 & 255) / 255;
104
+ this._g = (hex >> 8 & 255) / 255;
105
+ this._b = (hex & 255) / 255;
106
+ }
107
+
108
+ return this;
109
+
110
+ }
111
+
112
+ setRGB(r: number, g: number, b: number, a: number = 1.0) {
113
+
114
+ this._r = r;
115
+ this._g = g;
116
+ this._b = b;
117
+ this._a = a;
118
+
119
+ return this;
120
+
121
+ }
122
+
123
+ clone() {
124
+ return new (this.constructor as any)(this.r, this.g, this.b, this.a);
125
+ }
126
+
127
+ copy(color: this) {
128
+ this._r = color.r;
129
+ this._g = color.g;
130
+ this._b = color.b;
131
+
132
+ return this;
133
+ }
134
+
135
+ equals(c: this) {
136
+ return (c.r === this.r) && (c.g === this.g) && (c.b === this.b);
137
+ }
138
+
139
+ toArray(array: number[] = [], offset = 0) {
140
+
141
+ array[offset] = this.r;
142
+ array[offset + 1] = this.g;
143
+ array[offset + 2] = this.b;
144
+ array[offset + 3] = this.a;
145
+
146
+ return array;
147
+ }
148
+
149
+ getHex() {
150
+ return (this.r * 255) << 32 ^ (this.g * 255) << 16 ^ (this.b * 255) << 8 ^ (this.a * 255) << 0;
151
+ }
152
+
153
+ toJSON() {
154
+ return this.getHex();
155
+ }
156
+
157
+ }
@@ -36,8 +36,11 @@ export class EventHandler {
36
36
  * });
37
37
  * obj.fire('test', 1, 2); // prints 3 to the console
38
38
  */
39
- on(name: string, callback: any, scope?: any) {
40
- this._addCallback(name, callback, scope, false);
39
+ on(name: string | string[], callback: any, scope?: any) {
40
+ if (Array.isArray(name))
41
+ name.forEach(v => this._addCallback(v, callback, scope, false));
42
+ else
43
+ this._addCallback(name, callback, scope, false);
41
44
 
42
45
  return this;
43
46
  }
@@ -75,7 +75,7 @@ export class BufferGeometry {
75
75
  * 转化成BufferArray来计算
76
76
  * @param geo
77
77
  */
78
- setFromGeometry(geo: IGeometry) {
78
+ setFromGeometry(geo: IGeometry | IBufferGeometry) {
79
79
  this.setAttribute('position', new Float32BufferAttribute(geo.position, 3))
80
80
  if (geo.uv)
81
81
  this.setAttribute('uv', new Float32BufferAttribute(geo.uv, 2));
@@ -932,7 +932,7 @@ export class BufferGeometry {
932
932
 
933
933
  }
934
934
 
935
- toFlat() {
935
+ toFlat() {
936
936
  var indices = this.index!.array;
937
937
  var attributes = this.attributes;
938
938
  var geometry2 = new BufferGeometry();