@xort/cga 0.0.82 → 0.0.84
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.
- package/build/@xort_cga.js +639 -314
- package/deploy.sh +13 -1
- package/dist/IKanimation/Bone.d.ts +1 -3
- package/dist/IKanimation/Bone.js +4 -22
- package/dist/alg/common.d.ts +2 -2
- package/dist/alg/common.js +4 -4
- package/dist/alg/extrude.js +4 -4
- package/dist/extends/geometryaid.js +7 -15
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/math/Color.d.ts +1 -2
- package/dist/math/Color.js +14 -31
- package/dist/math/Euler.d.ts +4 -5
- package/dist/math/Euler.js +16 -34
- package/dist/math/HVec3.d.ts +1 -2
- package/dist/math/HVec3.js +13 -30
- package/dist/math/Quat.d.ts +1 -2
- package/dist/math/Quat.js +23 -43
- package/dist/math/Vec2.d.ts +4 -4
- package/dist/math/Vec2.js +7 -24
- package/dist/math/Vec3.d.ts +5 -9
- package/dist/math/Vec3.js +35 -52
- package/dist/math/Vec4.d.ts +4 -4
- package/dist/math/Vec4.js +11 -28
- package/dist/math/vecs.d.ts +21 -1
- package/dist/math/vecs.js +85 -3
- package/dist/render/{buffer-attribute.d.ts → bufferAttribute.d.ts} +8 -4
- package/dist/render/{buffer-attribute.js → bufferAttribute.js} +4 -0
- package/dist/render/geometry.d.ts +7 -9
- package/dist/render/geometry.js +22 -25
- package/dist/render/mesh.d.ts +23 -18
- package/dist/render/mesh.js +62 -57
- package/dist/render/types.d.ts +1 -0
- package/dist/struct/3d/Box.d.ts +1 -1
- package/dist/struct/3d/Plane.js +1 -1
- package/package.json +73 -73
- package/rollup.config.js +1 -1
- package/src/IKanimation/Bone.ts +1 -5
- package/src/alg/common.ts +4 -4
- package/src/alg/extrude.ts +6 -6
- package/src/app.ts +2 -10
- package/src/extends/geometryaid.ts +10 -13
- package/src/index.ts +2 -4
- package/src/math/Color.ts +6 -8
- package/src/math/Euler.ts +11 -12
- package/src/math/HVec3.ts +3 -5
- package/src/math/Quat.ts +18 -23
- package/src/math/Vec2.ts +7 -7
- package/src/math/Vec3.ts +37 -36
- package/src/math/Vec4.ts +9 -9
- package/src/math/vecs.ts +104 -4
- package/src/render/{buffer-attribute.ts → bufferAttribute.ts} +11 -4
- package/src/render/geometry.ts +18 -15
- package/src/render/mesh.ts +56 -54
- package/src/render/types.ts +2 -0
- package/src/struct/3d/Box.ts +1 -1
- package/src/struct/3d/Plane.ts +2 -4
- package/dist/math/Vec.d.ts +0 -7
- package/dist/math/Vec.js +0 -41
- package/dist/math/vector.d.ts +0 -114
- package/dist/math/vector.js +0 -371
- package/dist/render/eventhandler.d.ts +0 -78
- package/dist/render/eventhandler.js +0 -191
- package/dist/render/thing.d.ts +0 -34
- package/dist/render/thing.js +0 -194
- package/src/math/Vec.ts +0 -26
- package/src/render/eventhandler.ts +0 -196
- package/src/render/thing.ts +0 -204
package/src/math/vecs.ts
CHANGED
|
@@ -15,9 +15,16 @@ import { Vec3 } from './Vec3';
|
|
|
15
15
|
import { ArrayList } from '../struct/data/ArrayList';
|
|
16
16
|
import { Vec4 } from './Vec4';
|
|
17
17
|
import { delta4 } from './Math';
|
|
18
|
+
import { Mat4 } from "./Mat4";
|
|
19
|
+
import { Quat } from "./Quat";
|
|
20
|
+
import { TypedArrayLike } from "../render/types";
|
|
18
21
|
|
|
19
22
|
|
|
20
23
|
|
|
24
|
+
const _vec21 = new Vec2();
|
|
25
|
+
const _vec31 = new Vec3();
|
|
26
|
+
const _vec41 = new Vec4();
|
|
27
|
+
|
|
21
28
|
const ckeckVec = (vs: any, component: number) => {
|
|
22
29
|
if (vs.length % component !== 0)
|
|
23
30
|
throw ("向量组件数量不一样")
|
|
@@ -42,6 +49,47 @@ export class vecs {
|
|
|
42
49
|
|
|
43
50
|
return vs;
|
|
44
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 找到最大值
|
|
55
|
+
* @param array
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
static max(array: ArrayLike<number>) {
|
|
59
|
+
|
|
60
|
+
if (array.length === 0) return - Infinity;
|
|
61
|
+
|
|
62
|
+
var max = array[0];
|
|
63
|
+
|
|
64
|
+
for (var i = 1, l = array.length; i < l; ++i) {
|
|
65
|
+
|
|
66
|
+
if (array[i] > max) max = array[i];
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return max;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 找到最小值
|
|
75
|
+
* @param array
|
|
76
|
+
* @returns
|
|
77
|
+
*/
|
|
78
|
+
static min(array: ArrayLike<number>) {
|
|
79
|
+
|
|
80
|
+
if (array.length === 0) return - Infinity;
|
|
81
|
+
|
|
82
|
+
var min = array[0];
|
|
83
|
+
|
|
84
|
+
for (var i = 1, l = array.length; i < l; ++i) {
|
|
85
|
+
|
|
86
|
+
if (array[i] < min) min = array[i];
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return min;
|
|
91
|
+
}
|
|
92
|
+
|
|
45
93
|
/**
|
|
46
94
|
* 去除相邻没有重复点
|
|
47
95
|
*/
|
|
@@ -363,16 +411,68 @@ export class vecs {
|
|
|
363
411
|
* @param component 矢量维度,默认为3
|
|
364
412
|
* @returns
|
|
365
413
|
*/
|
|
366
|
-
static numbersToVecs(vss:
|
|
414
|
+
static numbersToVecs(vss: TypedArrayLike, component: number = 3): Vec2[] | Vec3[] | Vec4[] {
|
|
367
415
|
const result: any = []
|
|
368
|
-
const length = vss.length;
|
|
369
416
|
|
|
370
|
-
for (let i = 0; i < length; i += component) {
|
|
417
|
+
for (let i = 0, length = vss.length; i < length; i += component) {
|
|
371
418
|
const vec = vecs.vec(component);
|
|
372
|
-
vec.fromArray(vss
|
|
419
|
+
vec.fromArray(vss, i);
|
|
373
420
|
result.push(vec);
|
|
374
421
|
}
|
|
375
422
|
|
|
376
423
|
return result;
|
|
377
424
|
}
|
|
425
|
+
|
|
426
|
+
static applyQuat(vss: TypedArrayLike, quat: Quat, component: number = 3) {
|
|
427
|
+
let vec;
|
|
428
|
+
if (component === 3)
|
|
429
|
+
vec = _vec31;
|
|
430
|
+
else if (component === 2)
|
|
431
|
+
vec = _vec21
|
|
432
|
+
else if (component === 4)
|
|
433
|
+
vec = _vec41;
|
|
434
|
+
|
|
435
|
+
for (let i = 0; i < vss.length; i += component) {
|
|
436
|
+
(vec as any).fromArray(vss, i)
|
|
437
|
+
.applyQuat(quat)
|
|
438
|
+
.toArray(vss, i);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
static applyMat4(vss: TypedArrayLike, mat: Mat4, component: number = 3) {
|
|
443
|
+
let vec;
|
|
444
|
+
if (component === 3)
|
|
445
|
+
vec = _vec31;
|
|
446
|
+
else if (component === 2)
|
|
447
|
+
vec = _vec21
|
|
448
|
+
else if (component === 4)
|
|
449
|
+
vec = _vec41;
|
|
450
|
+
|
|
451
|
+
for (let i = 0; i < vss.length; i += component) {
|
|
452
|
+
(vec as Vec3).fromArray(vss, i)
|
|
453
|
+
.applyMat4(mat)
|
|
454
|
+
.toArray(vss, i);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
static translate(vss: TypedArrayLike, distance: number[], component = 3) {
|
|
459
|
+
for (let i = 0; i < vss.length; i += component) {
|
|
460
|
+
for (let j = 0; j < component; j++) {
|
|
461
|
+
vss[i + j] += distance[j];
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
static rotate(vss: TypedArrayLike, axis: Vec3, angle: number) {
|
|
467
|
+
vecs.applyQuat(vss, new Quat().setFromAxisAngle(axis, angle))
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
static scale(vss: TypedArrayLike, _scale: number[], component = 3) {
|
|
472
|
+
for (let i = 0; i < vss.length; i += component) {
|
|
473
|
+
for (let j = 0; j < component; j++) {
|
|
474
|
+
vss[i + j] *= _scale[j];
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
378
478
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import { Mat3 } from "../math/Mat3";
|
|
3
2
|
import { Mat4 } from "../math/Mat4";
|
|
4
3
|
import { Vec2 } from "../math/Vec2";
|
|
@@ -9,16 +8,23 @@ import { TypedArray } from "./types";
|
|
|
9
8
|
|
|
10
9
|
var _vector = new Vec3();
|
|
11
10
|
|
|
11
|
+
/**
|
|
12
|
+
* 几何体buffer属性
|
|
13
|
+
* 记录每个几何数据属性的细节
|
|
14
|
+
*/
|
|
12
15
|
export class BufferAttribute {
|
|
13
16
|
name: string;
|
|
14
|
-
|
|
17
|
+
|
|
15
18
|
itemSize: number;
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
array: TypedArray;
|
|
20
|
+
|
|
18
21
|
version: number;
|
|
19
22
|
normalized: boolean;
|
|
23
|
+
|
|
20
24
|
count: number;
|
|
21
25
|
|
|
26
|
+
updateRange: { offset: number; count: number };
|
|
27
|
+
|
|
22
28
|
readonly isBufferAttribute: true = true;
|
|
23
29
|
/**
|
|
24
30
|
*
|
|
@@ -52,6 +58,7 @@ export class BufferAttribute {
|
|
|
52
58
|
|
|
53
59
|
return this;
|
|
54
60
|
}
|
|
61
|
+
|
|
55
62
|
setUsage(usage: any): this {
|
|
56
63
|
return this
|
|
57
64
|
}
|
package/src/render/geometry.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Mat3 } from "../math/Mat3";
|
|
1
|
+
import { Mat3 } from "../math/Mat3";
|
|
3
2
|
import { Mat4 } from "../math/Mat4";
|
|
4
3
|
import { v3, Vec3 } from "../math/Vec3";
|
|
5
4
|
import { Box } from "../struct/3d/Box";
|
|
6
5
|
import { Sphere } from "../struct/3d/Sphere";
|
|
7
|
-
import { BufferAttribute, Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from "./
|
|
6
|
+
import { BufferAttribute, Float32BufferAttribute, Uint16BufferAttribute, Uint32BufferAttribute } from "./bufferAttribute";
|
|
8
7
|
import { isBufferArray, TypedArray } from "./types";
|
|
9
8
|
import { Vec2 } from "../math/Vec2";
|
|
10
9
|
import { Vec4 } from "../math/Vec4";
|
|
@@ -43,21 +42,25 @@ var _vector = new Vec3();
|
|
|
43
42
|
*/
|
|
44
43
|
export class BufferGeometry {
|
|
45
44
|
name: string;
|
|
46
|
-
|
|
45
|
+
|
|
46
|
+
boundingBox: Box | undefined;
|
|
47
|
+
boundingSphere: Sphere | undefined;
|
|
48
|
+
|
|
47
49
|
morphAttributes: any;
|
|
48
50
|
morphTargetsRelative: boolean;
|
|
51
|
+
|
|
52
|
+
index: BufferAttribute | undefined;
|
|
53
|
+
attributes: { [key: string]: BufferAttribute };
|
|
49
54
|
groups: { start: number; count: number; materialIndex?: number }[];
|
|
50
|
-
boundingBox: Box | undefined;
|
|
51
|
-
boundingSphere: Sphere | undefined;
|
|
52
55
|
drawRange: { start: number; count: number; };
|
|
53
|
-
|
|
54
|
-
parameters: any;
|
|
56
|
+
|
|
57
|
+
parameters: any;
|
|
58
|
+
|
|
55
59
|
readonly isBufferGeometry: true = true;
|
|
56
|
-
|
|
57
|
-
type: string = "BufferGeometry";
|
|
60
|
+
|
|
58
61
|
constructor() {
|
|
59
62
|
|
|
60
|
-
Object.defineProperty(this, 'id', { value: _bufferGeometryId +=
|
|
63
|
+
Object.defineProperty(this, 'id', { value: _bufferGeometryId += 1 });
|
|
61
64
|
|
|
62
65
|
this.name = '';
|
|
63
66
|
|
|
@@ -94,11 +97,11 @@ export class BufferGeometry {
|
|
|
94
97
|
|
|
95
98
|
setIndex(index: BufferAttribute | TypedArray | number[]) {
|
|
96
99
|
if (Array.isArray(index)) {
|
|
97
|
-
this.index = new (
|
|
100
|
+
this.index = new (vecs.max(index as any) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1);
|
|
98
101
|
} else if (index instanceof BufferAttribute) {
|
|
99
102
|
this.index = index;
|
|
100
103
|
} else {
|
|
101
|
-
this.index = new (
|
|
104
|
+
this.index = new (vecs.max(index as any) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute)(index, 1)
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
}
|
|
@@ -1083,8 +1086,8 @@ export class BufferGeometry {
|
|
|
1083
1086
|
|
|
1084
1087
|
// standard BufferGeometry serialization
|
|
1085
1088
|
|
|
1086
|
-
data.uuid = this.uuid;
|
|
1087
|
-
data.type = this.type;
|
|
1089
|
+
// data.uuid = this.uuid;
|
|
1090
|
+
// data.type = this.type;
|
|
1088
1091
|
if (this.name !== '') data.name = this.name;
|
|
1089
1092
|
if (Object.keys(this.userData).length > 0) data.userData = this.userData;
|
|
1090
1093
|
|
package/src/render/mesh.ts
CHANGED
|
@@ -10,71 +10,73 @@ import { Vec3 } from "../math/Vec3";
|
|
|
10
10
|
import { Vec2 } from "../math/Vec2";
|
|
11
11
|
import { flat, forall } from '../utils/array';
|
|
12
12
|
import { BufferGeometry } from "./geometry";
|
|
13
|
-
import { BufferAttribute } from "./
|
|
13
|
+
import { BufferAttribute } from "./bufferAttribute";
|
|
14
14
|
import { Vec4 } from "../math/Vec4";
|
|
15
15
|
import { TypedArray } from "./types";
|
|
16
16
|
import { triangulation } from "../alg/trianglution";
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* 网格工具
|
|
20
|
+
*/
|
|
21
|
+
export class MeshTool {
|
|
18
22
|
|
|
23
|
+
static indexable(obj: any[] | any, refIndexInfo = { index: 0 }, force = false) {
|
|
24
|
+
if (obj instanceof Array) {
|
|
25
|
+
for (var i = 0; i < obj.length; i++)
|
|
26
|
+
MeshTool.indexable(obj[i], refIndexInfo);
|
|
27
|
+
}
|
|
28
|
+
else if (obj instanceof Object) {
|
|
29
|
+
if (obj.index === undefined)
|
|
30
|
+
obj.index = refIndexInfo.index++;
|
|
31
|
+
else if (force)
|
|
32
|
+
obj.index = refIndexInfo.index++;
|
|
33
|
+
}
|
|
19
34
|
|
|
20
|
-
export function indexable(obj: any[] | any, refIndexInfo = { index: 0 }, force = false) {
|
|
21
|
-
if (obj instanceof Array) {
|
|
22
|
-
for (var i = 0; i < obj.length; i++)
|
|
23
|
-
indexable(obj[i], refIndexInfo);
|
|
24
35
|
}
|
|
25
|
-
else if (obj instanceof Object) {
|
|
26
|
-
if (obj.index === undefined)
|
|
27
|
-
obj.index = refIndexInfo.index++;
|
|
28
|
-
else if (force)
|
|
29
|
-
obj.index = refIndexInfo.index++;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function triangListToBuffer(vertices: Vec3[], triangleList: Vec3[]) {
|
|
35
|
-
indexable(triangleList);
|
|
36
|
-
const indices: number[] = [];
|
|
37
|
-
forall(triangleList, (v: Vec3 | any) => {
|
|
38
|
-
indices.push(v.index);
|
|
39
|
-
})
|
|
40
|
-
return toGeoBuffer(vertices, indices);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 顶点纹理坐标所以转化为buffer数据
|
|
46
|
-
* @param {Array<Verctor3|Number>} vertices
|
|
47
|
-
* @param {Array<Number>} indices
|
|
48
|
-
* @param {Array<Verctor2|Number>} uvs
|
|
49
|
-
*/
|
|
50
|
-
export function toGeoBuffer(vertices: BufferAttribute | Array<number | Vec2 | Vec3 | Vec4> | TypedArray, indices: number[] | Uint32Array | Uint16Array, uvs?: BufferAttribute | TypedArray | Array<Vec2 | number>): BufferGeometry {
|
|
51
|
-
const geometry = new BufferGeometry();
|
|
52
|
-
geometry.addAttribute('position', vertices, 3)
|
|
53
|
-
geometry.addAttribute('uv', uvs || new Float32Array(geometry.getAttribute('position').array.length / 3 * 2), 2)
|
|
54
|
-
geometry.setIndex(indices)
|
|
55
|
-
return geometry;
|
|
56
|
-
}
|
|
57
36
|
|
|
37
|
+
static triangListToBuffer(vertices: Vec3[], triangleList: Vec3[]) {
|
|
38
|
+
MeshTool.indexable(triangleList);
|
|
39
|
+
const indices: number[] = [];
|
|
40
|
+
forall(triangleList, (v: Vec3 | any) => {
|
|
41
|
+
indices.push(v.index);
|
|
42
|
+
})
|
|
43
|
+
return MeshTool.toGeoBuffer(vertices, indices);
|
|
44
|
+
}
|
|
58
45
|
|
|
59
46
|
|
|
47
|
+
/**
|
|
48
|
+
* 顶点纹理坐标所以转化为buffer数据
|
|
49
|
+
* @param {Array<Verctor3|Number>} vertices
|
|
50
|
+
* @param {Array<Number>} indices
|
|
51
|
+
* @param {Array<Verctor2|Number>} uvs
|
|
52
|
+
*/
|
|
53
|
+
static toGeoBuffer(vertices: BufferAttribute | Array<number | Vec2 | Vec3 | Vec4> | TypedArray, indices: number[] | Uint32Array | Uint16Array, uvs?: BufferAttribute | TypedArray | Array<Vec2 | number>): BufferGeometry {
|
|
54
|
+
const geometry = new BufferGeometry();
|
|
55
|
+
geometry.addAttribute('position', vertices, 3)
|
|
56
|
+
geometry.addAttribute('uv', uvs || new Float32Array(geometry.getAttribute('position').array.length / 3 * 2), 2)
|
|
57
|
+
geometry.setIndex(indices)
|
|
58
|
+
return geometry;
|
|
59
|
+
}
|
|
60
60
|
|
|
61
|
+
|
|
61
62
|
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
/**
|
|
64
|
+
* 三角剖分后转成几何体
|
|
65
|
+
* 只考虑XY平面
|
|
66
|
+
* @param {*} boundary
|
|
67
|
+
* @param {*} hole
|
|
68
|
+
* @param {*} options
|
|
69
|
+
*/
|
|
70
|
+
static trianglutionToGeometryBuffer(boundary: any, holes: any[] = [], options: any = { normal: Vec3.UnitZ }): BufferGeometry {
|
|
71
|
+
var triangles = triangulation(boundary, holes, options)
|
|
72
|
+
var vertices = [...boundary, ...flat(holes)]
|
|
73
|
+
var uvs: any = [];
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
vertices.forEach(v => {
|
|
76
|
+
uvs.push(v.x, v.z);
|
|
77
|
+
})
|
|
78
|
+
var geometry = MeshTool.toGeoBuffer(vertices, triangles, uvs);
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
}
|
|
80
|
+
return geometry;
|
|
81
|
+
}
|
|
82
|
+
}
|
package/src/render/types.ts
CHANGED
|
@@ -13,3 +13,5 @@ export const isBufferArray = (obj: any) => {
|
|
|
13
13
|
var types = ['Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array']
|
|
14
14
|
return types.indexOf(obj.constructor.name) > -1;
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
export type TypedArrayLike = number[] | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array
|
package/src/struct/3d/Box.ts
CHANGED
package/src/struct/3d/Plane.ts
CHANGED
|
@@ -14,9 +14,7 @@ import { Triangle } from './Triangle';
|
|
|
14
14
|
import { IGeometry } from '../../render/geometry';
|
|
15
15
|
import { ISplitResult } from '../../alg/split';
|
|
16
16
|
import { Line } from './Line';
|
|
17
|
-
import {
|
|
18
|
-
import { Path } from './Path';
|
|
19
|
-
import { indexable } from '../../render/mesh';
|
|
17
|
+
import { MeshTool } from '../../render/mesh';
|
|
20
18
|
|
|
21
19
|
class Plane {
|
|
22
20
|
|
|
@@ -259,7 +257,7 @@ class Plane {
|
|
|
259
257
|
*/
|
|
260
258
|
splitPolyVS(polyVS: Vec3[]) {
|
|
261
259
|
polyVS = [...polyVS];
|
|
262
|
-
indexable(polyVS);
|
|
260
|
+
MeshTool.indexable(polyVS);
|
|
263
261
|
|
|
264
262
|
let jd0 = -1;//找出第一个交点
|
|
265
263
|
let jdp0: any;//找出第一个交点
|
package/dist/math/Vec.d.ts
DELETED
package/dist/math/Vec.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
extendStatics(d, b);
|
|
11
|
-
function __() { this.constructor = d; }
|
|
12
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.Vec = void 0;
|
|
17
|
-
/**
|
|
18
|
-
* 暂不使用
|
|
19
|
-
*/
|
|
20
|
-
var Vec = /** @class */ (function (_super) {
|
|
21
|
-
__extends(Vec, _super);
|
|
22
|
-
function Vec(n) {
|
|
23
|
-
var _this = _super.call(this) || this;
|
|
24
|
-
while (n-- > 0) {
|
|
25
|
-
_this[_this.length] = 0;
|
|
26
|
-
}
|
|
27
|
-
return _this;
|
|
28
|
-
}
|
|
29
|
-
Vec.max = function (array) {
|
|
30
|
-
if (array.length === 0)
|
|
31
|
-
return -Infinity;
|
|
32
|
-
var max = array[0];
|
|
33
|
-
for (var i = 1, l = array.length; i < l; ++i) {
|
|
34
|
-
if (array[i] > max)
|
|
35
|
-
max = array[i];
|
|
36
|
-
}
|
|
37
|
-
return max;
|
|
38
|
-
};
|
|
39
|
-
return Vec;
|
|
40
|
-
}(Array));
|
|
41
|
-
exports.Vec = Vec;
|
package/dist/math/vector.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 当向量以数组的方式出现,一个计算单元库
|
|
3
|
-
* @Description : 向量数组
|
|
4
|
-
* @Author : 赵耀圣
|
|
5
|
-
* @QQ : 549184003
|
|
6
|
-
* @Date : 2021-08-02 15:09:33
|
|
7
|
-
* @LastEditTime : 2021-08-02 15:50:16
|
|
8
|
-
* @FilePath : \cga.js\src\math\VecArray.ts
|
|
9
|
-
*/
|
|
10
|
-
import { Vec2 } from './Vec2';
|
|
11
|
-
import { Vec3 } from './Vec3';
|
|
12
|
-
import { ArrayList } from '../struct/data/ArrayList';
|
|
13
|
-
import { Vec4 } from './Vec4';
|
|
14
|
-
/**
|
|
15
|
-
* 矢量几何操作,数字数组/矢量数组,常用工具集合
|
|
16
|
-
*/
|
|
17
|
-
export default class vector {
|
|
18
|
-
/**
|
|
19
|
-
* 去除相邻的重复向量
|
|
20
|
-
* @param vs 矢量集合
|
|
21
|
-
* @param delta 误差
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
static uniqueNeighborVecs(vs: Array<Vec3>, delta?: number): Vec3[];
|
|
25
|
-
/**
|
|
26
|
-
* 去除相邻没有重复点
|
|
27
|
-
*/
|
|
28
|
-
static uniqueNeighbor(vs: number[], component?: number, delta?: number): number[];
|
|
29
|
-
/**
|
|
30
|
-
* 去除任意重复点
|
|
31
|
-
* @param vs 向量数组
|
|
32
|
-
* @param component 向量组件数量
|
|
33
|
-
* @returns 无重复向量数组
|
|
34
|
-
*/
|
|
35
|
-
static unique(vs: number[], component?: number): number[];
|
|
36
|
-
/**
|
|
37
|
-
* 翻转向量数组
|
|
38
|
-
* @param vecs 向量数组
|
|
39
|
-
* @param component 组件数量
|
|
40
|
-
* @returns
|
|
41
|
-
*/
|
|
42
|
-
static reverse(vecs: number[], component?: number): number[];
|
|
43
|
-
/**
|
|
44
|
-
* 点积
|
|
45
|
-
* @param vecs
|
|
46
|
-
* @returns
|
|
47
|
-
*/
|
|
48
|
-
static dot(...vecs: number[]): number;
|
|
49
|
-
/**
|
|
50
|
-
* 长度平方
|
|
51
|
-
* @param vecs
|
|
52
|
-
* @returns
|
|
53
|
-
*/
|
|
54
|
-
static distanceSq(...vecs: number[]): number;
|
|
55
|
-
/**
|
|
56
|
-
* 长度
|
|
57
|
-
* @param vecs
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
60
|
-
static distance(...vecs: number[]): number;
|
|
61
|
-
/**
|
|
62
|
-
* 相加
|
|
63
|
-
* @param vecs
|
|
64
|
-
* @returns
|
|
65
|
-
*/
|
|
66
|
-
static add(...vecs: number[]): number[] | (number & any[]);
|
|
67
|
-
/**
|
|
68
|
-
* 相减
|
|
69
|
-
* @param vecs
|
|
70
|
-
* @returns
|
|
71
|
-
*/
|
|
72
|
-
static sub(...vecs: number[]): number[];
|
|
73
|
-
/**
|
|
74
|
-
* 相乘
|
|
75
|
-
* @param vecs
|
|
76
|
-
* @returns
|
|
77
|
-
*/
|
|
78
|
-
static mul(...vecs: number[]): number[] | (number & any[]);
|
|
79
|
-
/**
|
|
80
|
-
* 获取矢量数组的i个矢量
|
|
81
|
-
* @param vecs
|
|
82
|
-
* @param i
|
|
83
|
-
* @param component
|
|
84
|
-
* @returns
|
|
85
|
-
*/
|
|
86
|
-
static getVecAt(vecs: number[], i: number, component?: number): number[];
|
|
87
|
-
/**
|
|
88
|
-
* 在第 i 个位置插入一个向量
|
|
89
|
-
* @param vecs
|
|
90
|
-
* @param i
|
|
91
|
-
* @param vec
|
|
92
|
-
*/
|
|
93
|
-
static insertAt(vecs: number[], i: number, ...vec: number[]): void;
|
|
94
|
-
/**
|
|
95
|
-
* 是否逆时针
|
|
96
|
-
* counterclockwise
|
|
97
|
-
*/
|
|
98
|
-
static isCCW<T>(shape: Array<T> | ArrayList<T>, component?: number): boolean;
|
|
99
|
-
/**
|
|
100
|
-
* 将向量深度拆解为数字
|
|
101
|
-
* @param {Array} Array<Vec4 | Vec3 | Vec2 | any> | any
|
|
102
|
-
* @param {String} comSort 'x','y','z','w' 按顺序选取后自由组合
|
|
103
|
-
* @returns {Array<Number>} 数字数组
|
|
104
|
-
*/
|
|
105
|
-
static verctorToNumbers(vecs: Array<Vec4 | Vec3 | Vec2 | any> | any, comSort?: string): number[];
|
|
106
|
-
static vec(component?: number): Vec3 | Vec4 | Vec2;
|
|
107
|
-
/**
|
|
108
|
-
* 数字数组 转 适量数组
|
|
109
|
-
* @param vss 数字数组
|
|
110
|
-
* @param component 矢量维度,默认为3
|
|
111
|
-
* @returns
|
|
112
|
-
*/
|
|
113
|
-
static numbersToVecs(vss: number[], component?: number): Vec2[] | Vec3[] | Vec4[];
|
|
114
|
-
}
|