@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/dist/math/Vec4.js
CHANGED
|
@@ -1,34 +1,17 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
3
|
exports.v4 = exports.Vec4 = void 0;
|
|
17
|
-
var
|
|
18
|
-
var Vec4 = /** @class */ (function (_super) {
|
|
19
|
-
__extends(Vec4, _super);
|
|
4
|
+
var Vec4 = /** @class */ (function () {
|
|
20
5
|
function Vec4(_x, _y, _z, _w) {
|
|
21
6
|
if (_x === void 0) { _x = 0; }
|
|
22
7
|
if (_y === void 0) { _y = 0; }
|
|
23
8
|
if (_z === void 0) { _z = 0; }
|
|
24
9
|
if (_w === void 0) { _w = 1; }
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
_this.isVec4 = true;
|
|
31
|
-
return _this;
|
|
10
|
+
this._x = _x;
|
|
11
|
+
this._y = _y;
|
|
12
|
+
this._z = _z;
|
|
13
|
+
this._w = _w;
|
|
14
|
+
this.isVec4 = true;
|
|
32
15
|
}
|
|
33
16
|
Object.defineProperty(Vec4.prototype, "x", {
|
|
34
17
|
get: function () {
|
|
@@ -37,7 +20,7 @@ var Vec4 = /** @class */ (function (_super) {
|
|
|
37
20
|
set: function (value) {
|
|
38
21
|
if (this._x !== value) {
|
|
39
22
|
this._x = value;
|
|
40
|
-
this.fire('change', 'x', this._x, value)
|
|
23
|
+
// this.fire('change', 'x', this._x, value)
|
|
41
24
|
}
|
|
42
25
|
},
|
|
43
26
|
enumerable: false,
|
|
@@ -50,7 +33,7 @@ var Vec4 = /** @class */ (function (_super) {
|
|
|
50
33
|
set: function (value) {
|
|
51
34
|
if (this._y !== value) {
|
|
52
35
|
this._y = value;
|
|
53
|
-
this.fire('change', 'y', this._y, value)
|
|
36
|
+
// this.fire('change', 'y', this._y, value)
|
|
54
37
|
}
|
|
55
38
|
},
|
|
56
39
|
enumerable: false,
|
|
@@ -63,7 +46,7 @@ var Vec4 = /** @class */ (function (_super) {
|
|
|
63
46
|
set: function (value) {
|
|
64
47
|
if (this._z !== value) {
|
|
65
48
|
this._z = value;
|
|
66
|
-
this.fire('change', 'z', this._z, value)
|
|
49
|
+
// this.fire('change', 'z', this._z, value)
|
|
67
50
|
}
|
|
68
51
|
},
|
|
69
52
|
enumerable: false,
|
|
@@ -76,7 +59,7 @@ var Vec4 = /** @class */ (function (_super) {
|
|
|
76
59
|
set: function (value) {
|
|
77
60
|
if (this._w !== value) {
|
|
78
61
|
this._w = value;
|
|
79
|
-
this.fire('change', 'w', this._w, value)
|
|
62
|
+
// this.fire('change', 'w', this._w, value)
|
|
80
63
|
}
|
|
81
64
|
},
|
|
82
65
|
enumerable: false,
|
|
@@ -484,7 +467,7 @@ var Vec4 = /** @class */ (function (_super) {
|
|
|
484
467
|
return this;
|
|
485
468
|
};
|
|
486
469
|
return Vec4;
|
|
487
|
-
}(
|
|
470
|
+
}());
|
|
488
471
|
exports.Vec4 = Vec4;
|
|
489
472
|
function v4(x, y, z, w) {
|
|
490
473
|
return new Vec4(x, y, z, w);
|
package/dist/math/vecs.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ import { Vec2 } from './Vec2';
|
|
|
11
11
|
import { Vec3 } from './Vec3';
|
|
12
12
|
import { ArrayList } from '../struct/data/ArrayList';
|
|
13
13
|
import { Vec4 } from './Vec4';
|
|
14
|
+
import { Mat4 } from "./Mat4";
|
|
15
|
+
import { Quat } from "./Quat";
|
|
16
|
+
import { TypedArrayLike } from "../render/types";
|
|
14
17
|
/**
|
|
15
18
|
* 矢量几何操作,数字数组/矢量数组,常用工具集合
|
|
16
19
|
*/
|
|
@@ -22,6 +25,18 @@ export declare class vecs {
|
|
|
22
25
|
* @returns
|
|
23
26
|
*/
|
|
24
27
|
static uniqueNeighborVecs(vs: Array<Vec3>, delta?: number): Vec3[];
|
|
28
|
+
/**
|
|
29
|
+
* 找到最大值
|
|
30
|
+
* @param array
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
static max(array: ArrayLike<number>): number;
|
|
34
|
+
/**
|
|
35
|
+
* 找到最小值
|
|
36
|
+
* @param array
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
static min(array: ArrayLike<number>): number;
|
|
25
40
|
/**
|
|
26
41
|
* 去除相邻没有重复点
|
|
27
42
|
*/
|
|
@@ -110,5 +125,10 @@ export declare class vecs {
|
|
|
110
125
|
* @param component 矢量维度,默认为3
|
|
111
126
|
* @returns
|
|
112
127
|
*/
|
|
113
|
-
static numbersToVecs(vss:
|
|
128
|
+
static numbersToVecs(vss: TypedArrayLike, component?: number): Vec2[] | Vec3[] | Vec4[];
|
|
129
|
+
static applyQuat(vss: TypedArrayLike, quat: Quat, component?: number): void;
|
|
130
|
+
static applyMat4(vss: TypedArrayLike, mat: Mat4, component?: number): void;
|
|
131
|
+
static translate(vss: TypedArrayLike, distance: number[], component?: number): void;
|
|
132
|
+
static rotate(vss: TypedArrayLike, axis: Vec3, angle: number): void;
|
|
133
|
+
static scale(vss: TypedArrayLike, _scale: number[], component?: number): void;
|
|
114
134
|
}
|
package/dist/math/vecs.js
CHANGED
|
@@ -23,6 +23,10 @@ var Vec2_1 = require("./Vec2");
|
|
|
23
23
|
var Vec3_1 = require("./Vec3");
|
|
24
24
|
var Vec4_1 = require("./Vec4");
|
|
25
25
|
var Math_1 = require("./Math");
|
|
26
|
+
var Quat_1 = require("./Quat");
|
|
27
|
+
var _vec21 = new Vec2_1.Vec2();
|
|
28
|
+
var _vec31 = new Vec3_1.Vec3();
|
|
29
|
+
var _vec41 = new Vec4_1.Vec4();
|
|
26
30
|
var ckeckVec = function (vs, component) {
|
|
27
31
|
if (vs.length % component !== 0)
|
|
28
32
|
throw ("向量组件数量不一样");
|
|
@@ -48,6 +52,36 @@ var vecs = /** @class */ (function () {
|
|
|
48
52
|
}
|
|
49
53
|
return vs;
|
|
50
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* 找到最大值
|
|
57
|
+
* @param array
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
vecs.max = function (array) {
|
|
61
|
+
if (array.length === 0)
|
|
62
|
+
return -Infinity;
|
|
63
|
+
var max = array[0];
|
|
64
|
+
for (var i = 1, l = array.length; i < l; ++i) {
|
|
65
|
+
if (array[i] > max)
|
|
66
|
+
max = array[i];
|
|
67
|
+
}
|
|
68
|
+
return max;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* 找到最小值
|
|
72
|
+
* @param array
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
vecs.min = function (array) {
|
|
76
|
+
if (array.length === 0)
|
|
77
|
+
return -Infinity;
|
|
78
|
+
var min = array[0];
|
|
79
|
+
for (var i = 1, l = array.length; i < l; ++i) {
|
|
80
|
+
if (array[i] < min)
|
|
81
|
+
min = array[i];
|
|
82
|
+
}
|
|
83
|
+
return min;
|
|
84
|
+
};
|
|
51
85
|
/**
|
|
52
86
|
* 去除相邻没有重复点
|
|
53
87
|
*/
|
|
@@ -359,14 +393,62 @@ var vecs = /** @class */ (function () {
|
|
|
359
393
|
vecs.numbersToVecs = function (vss, component) {
|
|
360
394
|
if (component === void 0) { component = 3; }
|
|
361
395
|
var result = [];
|
|
362
|
-
var
|
|
363
|
-
for (var i = 0; i < length; i += component) {
|
|
396
|
+
for (var i = 0, length_1 = vss.length; i < length_1; i += component) {
|
|
364
397
|
var vec = vecs.vec(component);
|
|
365
|
-
vec.fromArray(vss
|
|
398
|
+
vec.fromArray(vss, i);
|
|
366
399
|
result.push(vec);
|
|
367
400
|
}
|
|
368
401
|
return result;
|
|
369
402
|
};
|
|
403
|
+
vecs.applyQuat = function (vss, quat, component) {
|
|
404
|
+
if (component === void 0) { component = 3; }
|
|
405
|
+
var vec;
|
|
406
|
+
if (component === 3)
|
|
407
|
+
vec = _vec31;
|
|
408
|
+
else if (component === 2)
|
|
409
|
+
vec = _vec21;
|
|
410
|
+
else if (component === 4)
|
|
411
|
+
vec = _vec41;
|
|
412
|
+
for (var i = 0; i < vss.length; i += component) {
|
|
413
|
+
vec.fromArray(vss, i)
|
|
414
|
+
.applyQuat(quat)
|
|
415
|
+
.toArray(vss, i);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
vecs.applyMat4 = function (vss, mat, component) {
|
|
419
|
+
if (component === void 0) { component = 3; }
|
|
420
|
+
var vec;
|
|
421
|
+
if (component === 3)
|
|
422
|
+
vec = _vec31;
|
|
423
|
+
else if (component === 2)
|
|
424
|
+
vec = _vec21;
|
|
425
|
+
else if (component === 4)
|
|
426
|
+
vec = _vec41;
|
|
427
|
+
for (var i = 0; i < vss.length; i += component) {
|
|
428
|
+
vec.fromArray(vss, i)
|
|
429
|
+
.applyMat4(mat)
|
|
430
|
+
.toArray(vss, i);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
vecs.translate = function (vss, distance, component) {
|
|
434
|
+
if (component === void 0) { component = 3; }
|
|
435
|
+
for (var i = 0; i < vss.length; i += component) {
|
|
436
|
+
for (var j = 0; j < component; j++) {
|
|
437
|
+
vss[i + j] += distance[j];
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
vecs.rotate = function (vss, axis, angle) {
|
|
442
|
+
vecs.applyQuat(vss, new Quat_1.Quat().setFromAxisAngle(axis, angle));
|
|
443
|
+
};
|
|
444
|
+
vecs.scale = function (vss, _scale, component) {
|
|
445
|
+
if (component === void 0) { component = 3; }
|
|
446
|
+
for (var i = 0; i < vss.length; i += component) {
|
|
447
|
+
for (var j = 0; j < component; j++) {
|
|
448
|
+
vss[i + j] *= _scale[j];
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
};
|
|
370
452
|
return vecs;
|
|
371
453
|
}());
|
|
372
454
|
exports.vecs = vecs;
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { Mat3 } from "../math/Mat3";
|
|
2
2
|
import { Mat4 } from "../math/Mat4";
|
|
3
3
|
import { TypedArray } from "./types";
|
|
4
|
+
/**
|
|
5
|
+
* 几何体buffer属性
|
|
6
|
+
* 记录每个几何数据属性的细节
|
|
7
|
+
*/
|
|
4
8
|
export declare class BufferAttribute {
|
|
5
9
|
name: string;
|
|
6
|
-
array: TypedArray;
|
|
7
10
|
itemSize: number;
|
|
11
|
+
array: TypedArray;
|
|
12
|
+
version: number;
|
|
13
|
+
normalized: boolean;
|
|
14
|
+
count: number;
|
|
8
15
|
updateRange: {
|
|
9
16
|
offset: number;
|
|
10
17
|
count: number;
|
|
11
18
|
};
|
|
12
|
-
version: number;
|
|
13
|
-
normalized: boolean;
|
|
14
|
-
count: number;
|
|
15
19
|
readonly isBufferAttribute: true;
|
|
16
20
|
/**
|
|
17
21
|
*
|
|
@@ -18,6 +18,10 @@ var Vec2_1 = require("../math/Vec2");
|
|
|
18
18
|
var Vec3_1 = require("../math/Vec3");
|
|
19
19
|
var Vec4_1 = require("../math/Vec4");
|
|
20
20
|
var _vector = new Vec3_1.Vec3();
|
|
21
|
+
/**
|
|
22
|
+
* 几何体buffer属性
|
|
23
|
+
* 记录每个几何数据属性的细节
|
|
24
|
+
*/
|
|
21
25
|
var BufferAttribute = /** @class */ (function () {
|
|
22
26
|
/**
|
|
23
27
|
*
|
|
@@ -2,7 +2,7 @@ import { Mat4 } from "../math/Mat4";
|
|
|
2
2
|
import { Vec3 } from "../math/Vec3";
|
|
3
3
|
import { Box } from "../struct/3d/Box";
|
|
4
4
|
import { Sphere } from "../struct/3d/Sphere";
|
|
5
|
-
import { BufferAttribute } from "./
|
|
5
|
+
import { BufferAttribute } from "./bufferAttribute";
|
|
6
6
|
import { TypedArray } from "./types";
|
|
7
7
|
import { Vec2 } from "../math/Vec2";
|
|
8
8
|
import { Vec4 } from "../math/Vec4";
|
|
@@ -27,27 +27,25 @@ export interface IBufferGeometry {
|
|
|
27
27
|
*/
|
|
28
28
|
export declare class BufferGeometry {
|
|
29
29
|
name: string;
|
|
30
|
-
|
|
30
|
+
boundingBox: Box | undefined;
|
|
31
|
+
boundingSphere: Sphere | undefined;
|
|
31
32
|
morphAttributes: any;
|
|
32
33
|
morphTargetsRelative: boolean;
|
|
34
|
+
index: BufferAttribute | undefined;
|
|
35
|
+
attributes: {
|
|
36
|
+
[key: string]: BufferAttribute;
|
|
37
|
+
};
|
|
33
38
|
groups: {
|
|
34
39
|
start: number;
|
|
35
40
|
count: number;
|
|
36
41
|
materialIndex?: number;
|
|
37
42
|
}[];
|
|
38
|
-
boundingBox: Box | undefined;
|
|
39
|
-
boundingSphere: Sphere | undefined;
|
|
40
43
|
drawRange: {
|
|
41
44
|
start: number;
|
|
42
45
|
count: number;
|
|
43
46
|
};
|
|
44
|
-
attributes: {
|
|
45
|
-
[key: string]: BufferAttribute;
|
|
46
|
-
};
|
|
47
47
|
parameters: any;
|
|
48
48
|
readonly isBufferGeometry: true;
|
|
49
|
-
uuid: string;
|
|
50
|
-
type: string;
|
|
51
49
|
constructor();
|
|
52
50
|
/**
|
|
53
51
|
* 转化成BufferArray来计算
|
package/dist/render/geometry.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BufferGeometry = void 0;
|
|
4
|
-
var Vec_1 = require("../math/Vec");
|
|
5
4
|
var Mat3_1 = require("../math/Mat3");
|
|
6
5
|
var Mat4_1 = require("../math/Mat4");
|
|
7
6
|
var Vec3_1 = require("../math/Vec3");
|
|
8
7
|
var Box_1 = require("../struct/3d/Box");
|
|
9
8
|
var Sphere_1 = require("../struct/3d/Sphere");
|
|
10
|
-
var
|
|
9
|
+
var bufferAttribute_1 = require("./bufferAttribute");
|
|
11
10
|
var types_1 = require("./types");
|
|
12
11
|
var Vec2_1 = require("../math/Vec2");
|
|
13
12
|
var Vec4_1 = require("../math/Vec4");
|
|
@@ -24,9 +23,7 @@ var _vector = new Vec3_1.Vec3();
|
|
|
24
23
|
var BufferGeometry = /** @class */ (function () {
|
|
25
24
|
function BufferGeometry() {
|
|
26
25
|
this.isBufferGeometry = true;
|
|
27
|
-
this
|
|
28
|
-
this.type = "BufferGeometry";
|
|
29
|
-
Object.defineProperty(this, 'id', { value: _bufferGeometryId += 2 });
|
|
26
|
+
Object.defineProperty(this, 'id', { value: _bufferGeometryId += 1 });
|
|
30
27
|
this.name = '';
|
|
31
28
|
this.attributes = {};
|
|
32
29
|
this.morphAttributes = {};
|
|
@@ -39,9 +36,9 @@ var BufferGeometry = /** @class */ (function () {
|
|
|
39
36
|
* @param geo
|
|
40
37
|
*/
|
|
41
38
|
BufferGeometry.prototype.setFromGeometry = function (geo) {
|
|
42
|
-
this.setAttribute('position', new
|
|
39
|
+
this.setAttribute('position', new bufferAttribute_1.Float32BufferAttribute(geo.position, 3));
|
|
43
40
|
if (geo.uv)
|
|
44
|
-
this.setAttribute('uv', new
|
|
41
|
+
this.setAttribute('uv', new bufferAttribute_1.Float32BufferAttribute(geo.uv, 2));
|
|
45
42
|
if (geo.index)
|
|
46
43
|
this.setIndex(geo.index);
|
|
47
44
|
return this;
|
|
@@ -51,13 +48,13 @@ var BufferGeometry = /** @class */ (function () {
|
|
|
51
48
|
};
|
|
52
49
|
BufferGeometry.prototype.setIndex = function (index) {
|
|
53
50
|
if (Array.isArray(index)) {
|
|
54
|
-
this.index = new (
|
|
51
|
+
this.index = new (vecs_1.vecs.max(index) > 65535 ? bufferAttribute_1.Uint32BufferAttribute : bufferAttribute_1.Uint16BufferAttribute)(index, 1);
|
|
55
52
|
}
|
|
56
|
-
else if (index instanceof
|
|
53
|
+
else if (index instanceof bufferAttribute_1.BufferAttribute) {
|
|
57
54
|
this.index = index;
|
|
58
55
|
}
|
|
59
56
|
else {
|
|
60
|
-
this.index = new (
|
|
57
|
+
this.index = new (vecs_1.vecs.max(index) > 65535 ? bufferAttribute_1.Uint32BufferAttribute : bufferAttribute_1.Uint16BufferAttribute)(index, 1);
|
|
61
58
|
}
|
|
62
59
|
};
|
|
63
60
|
BufferGeometry.prototype.getAttribute = function (name) {
|
|
@@ -72,28 +69,28 @@ var BufferGeometry = /** @class */ (function () {
|
|
|
72
69
|
if (Array.isArray(attribute)) {
|
|
73
70
|
if (attribute[0] instanceof Vec2_1.Vec2) {
|
|
74
71
|
var nums = vecs_1.vecs.verctorToNumbers(attribute);
|
|
75
|
-
this.setAttribute(name, new
|
|
72
|
+
this.setAttribute(name, new bufferAttribute_1.Float32BufferAttribute(nums, 2));
|
|
76
73
|
}
|
|
77
74
|
else if (attribute[0] instanceof Vec3_1.Vec3) {
|
|
78
75
|
var nums = vecs_1.vecs.verctorToNumbers(attribute);
|
|
79
|
-
this.setAttribute(name, new
|
|
76
|
+
this.setAttribute(name, new bufferAttribute_1.Float32BufferAttribute(nums, 3));
|
|
80
77
|
}
|
|
81
78
|
else if (attribute[0] instanceof Vec4_1.Vec4) {
|
|
82
79
|
var nums = vecs_1.vecs.verctorToNumbers(attribute);
|
|
83
|
-
this.setAttribute(name, new
|
|
80
|
+
this.setAttribute(name, new bufferAttribute_1.Float32BufferAttribute(nums, 4));
|
|
84
81
|
}
|
|
85
82
|
else if (!isNaN(attribute[0])) {
|
|
86
|
-
this.setAttribute(name, new
|
|
83
|
+
this.setAttribute(name, new bufferAttribute_1.Float32BufferAttribute(attribute, itemSize));
|
|
87
84
|
}
|
|
88
85
|
else {
|
|
89
86
|
console.error("类型不存在");
|
|
90
87
|
}
|
|
91
88
|
}
|
|
92
|
-
else if (attribute instanceof
|
|
89
|
+
else if (attribute instanceof bufferAttribute_1.BufferAttribute) {
|
|
93
90
|
this.attributes[name] = attribute;
|
|
94
91
|
}
|
|
95
92
|
else if (types_1.isBufferArray(attribute)) {
|
|
96
|
-
this.setAttribute(name, new
|
|
93
|
+
this.setAttribute(name, new bufferAttribute_1.BufferAttribute(attribute, itemSize));
|
|
97
94
|
}
|
|
98
95
|
return this;
|
|
99
96
|
};
|
|
@@ -185,12 +182,12 @@ var BufferGeometry = /** @class */ (function () {
|
|
|
185
182
|
// console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
|
|
186
183
|
var geometry = object.geometry;
|
|
187
184
|
if (object.isPoints || object.isLine) {
|
|
188
|
-
var positions = new
|
|
189
|
-
var colors = new
|
|
185
|
+
var positions = new bufferAttribute_1.Float32BufferAttribute(geometry.vertices.length * 3, 3);
|
|
186
|
+
var colors = new bufferAttribute_1.Float32BufferAttribute(geometry.colors.length * 3, 3);
|
|
190
187
|
this.setAttribute('position', positions.copyVec3sArray(geometry.vertices));
|
|
191
188
|
this.setAttribute('color', colors.copyColorsArray(geometry.colors));
|
|
192
189
|
if (geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length) {
|
|
193
|
-
var lineDistances = new
|
|
190
|
+
var lineDistances = new bufferAttribute_1.Float32BufferAttribute(geometry.lineDistances.length, 1);
|
|
194
191
|
this.setAttribute('lineDistance', lineDistances.copyArray(geometry.lineDistances));
|
|
195
192
|
}
|
|
196
193
|
if (geometry.boundingSphere !== null) {
|
|
@@ -213,7 +210,7 @@ var BufferGeometry = /** @class */ (function () {
|
|
|
213
210
|
var point = points[i];
|
|
214
211
|
position.push(point.x, point.y, point.z || 0);
|
|
215
212
|
}
|
|
216
|
-
this.setAttribute('position', new
|
|
213
|
+
this.setAttribute('position', new bufferAttribute_1.Float32BufferAttribute(position, 3));
|
|
217
214
|
return this;
|
|
218
215
|
};
|
|
219
216
|
BufferGeometry.prototype.updateFromObject = function (object) {
|
|
@@ -440,7 +437,7 @@ var BufferGeometry = /** @class */ (function () {
|
|
|
440
437
|
if (attributes.position) {
|
|
441
438
|
var positions = attributes.position.array;
|
|
442
439
|
if (attributes.normal === undefined) {
|
|
443
|
-
this.setAttribute('normal', new
|
|
440
|
+
this.setAttribute('normal', new bufferAttribute_1.BufferAttribute(new Float32Array(positions.length), 3));
|
|
444
441
|
}
|
|
445
442
|
else {
|
|
446
443
|
// reset existing normals to zero
|
|
@@ -552,7 +549,7 @@ var BufferGeometry = /** @class */ (function () {
|
|
|
552
549
|
array2[index2++] = array[index++];
|
|
553
550
|
}
|
|
554
551
|
}
|
|
555
|
-
return new
|
|
552
|
+
return new bufferAttribute_1.BufferAttribute(array2, itemSize);
|
|
556
553
|
}
|
|
557
554
|
for (var name in attributes) {
|
|
558
555
|
var attribute = attributes[name];
|
|
@@ -575,7 +572,7 @@ var BufferGeometry = /** @class */ (function () {
|
|
|
575
572
|
array2[index2++] = array[index++];
|
|
576
573
|
}
|
|
577
574
|
}
|
|
578
|
-
return new
|
|
575
|
+
return new bufferAttribute_1.BufferAttribute(array2, itemSize);
|
|
579
576
|
}
|
|
580
577
|
//
|
|
581
578
|
if (this.index === undefined) {
|
|
@@ -621,8 +618,8 @@ var BufferGeometry = /** @class */ (function () {
|
|
|
621
618
|
}
|
|
622
619
|
};
|
|
623
620
|
// standard BufferGeometry serialization
|
|
624
|
-
data.uuid = this.uuid;
|
|
625
|
-
data.type = this.type;
|
|
621
|
+
// data.uuid = this.uuid;
|
|
622
|
+
// data.type = this.type;
|
|
626
623
|
if (this.name !== '')
|
|
627
624
|
data.name = this.name;
|
|
628
625
|
if (Object.keys(this.userData).length > 0)
|
package/dist/render/mesh.d.ts
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
import { Vec3 } from "../math/Vec3";
|
|
2
2
|
import { Vec2 } from "../math/Vec2";
|
|
3
3
|
import { BufferGeometry } from "./geometry";
|
|
4
|
-
import { BufferAttribute } from "./
|
|
4
|
+
import { BufferAttribute } from "./bufferAttribute";
|
|
5
5
|
import { Vec4 } from "../math/Vec4";
|
|
6
6
|
import { TypedArray } from "./types";
|
|
7
|
-
export declare function indexable(obj: any[] | any, refIndexInfo?: {
|
|
8
|
-
index: number;
|
|
9
|
-
}, force?: boolean): void;
|
|
10
|
-
export declare function triangListToBuffer(vertices: Vec3[], triangleList: Vec3[]): BufferGeometry;
|
|
11
7
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @param {Array<Verctor3|Number>} vertices
|
|
14
|
-
* @param {Array<Number>} indices
|
|
15
|
-
* @param {Array<Verctor2|Number>} uvs
|
|
8
|
+
* 网格工具
|
|
16
9
|
*/
|
|
17
|
-
export declare
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
export declare class MeshTool {
|
|
11
|
+
static indexable(obj: any[] | any, refIndexInfo?: {
|
|
12
|
+
index: number;
|
|
13
|
+
}, force?: boolean): void;
|
|
14
|
+
static triangListToBuffer(vertices: Vec3[], triangleList: Vec3[]): BufferGeometry;
|
|
15
|
+
/**
|
|
16
|
+
* 顶点纹理坐标所以转化为buffer数据
|
|
17
|
+
* @param {Array<Verctor3|Number>} vertices
|
|
18
|
+
* @param {Array<Number>} indices
|
|
19
|
+
* @param {Array<Verctor2|Number>} uvs
|
|
20
|
+
*/
|
|
21
|
+
static toGeoBuffer(vertices: BufferAttribute | Array<number | Vec2 | Vec3 | Vec4> | TypedArray, indices: number[] | Uint32Array | Uint16Array, uvs?: BufferAttribute | TypedArray | Array<Vec2 | number>): BufferGeometry;
|
|
22
|
+
/**
|
|
23
|
+
* 三角剖分后转成几何体
|
|
24
|
+
* 只考虑XY平面
|
|
25
|
+
* @param {*} boundary
|
|
26
|
+
* @param {*} hole
|
|
27
|
+
* @param {*} options
|
|
28
|
+
*/
|
|
29
|
+
static trianglutionToGeometryBuffer(boundary: any, holes?: any[], options?: any): BufferGeometry;
|
|
30
|
+
}
|
package/dist/render/mesh.js
CHANGED
|
@@ -7,7 +7,7 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
|
7
7
|
return r;
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
10
|
+
exports.MeshTool = void 0;
|
|
11
11
|
/*
|
|
12
12
|
* @Description :
|
|
13
13
|
* @Author : 赵耀圣
|
|
@@ -20,61 +20,66 @@ var Vec3_1 = require("../math/Vec3");
|
|
|
20
20
|
var array_1 = require("../utils/array");
|
|
21
21
|
var geometry_1 = require("./geometry");
|
|
22
22
|
var trianglution_1 = require("../alg/trianglution");
|
|
23
|
-
function indexable(obj, refIndexInfo, force) {
|
|
24
|
-
if (refIndexInfo === void 0) { refIndexInfo = { index: 0 }; }
|
|
25
|
-
if (force === void 0) { force = false; }
|
|
26
|
-
if (obj instanceof Array) {
|
|
27
|
-
for (var i = 0; i < obj.length; i++)
|
|
28
|
-
indexable(obj[i], refIndexInfo);
|
|
29
|
-
}
|
|
30
|
-
else if (obj instanceof Object) {
|
|
31
|
-
if (obj.index === undefined)
|
|
32
|
-
obj.index = refIndexInfo.index++;
|
|
33
|
-
else if (force)
|
|
34
|
-
obj.index = refIndexInfo.index++;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.indexable = indexable;
|
|
38
|
-
function triangListToBuffer(vertices, triangleList) {
|
|
39
|
-
indexable(triangleList);
|
|
40
|
-
var indices = [];
|
|
41
|
-
array_1.forall(triangleList, function (v) {
|
|
42
|
-
indices.push(v.index);
|
|
43
|
-
});
|
|
44
|
-
return toGeoBuffer(vertices, indices);
|
|
45
|
-
}
|
|
46
|
-
exports.triangListToBuffer = triangListToBuffer;
|
|
47
23
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @param {Array<Verctor3|Number>} vertices
|
|
50
|
-
* @param {Array<Number>} indices
|
|
51
|
-
* @param {Array<Verctor2|Number>} uvs
|
|
24
|
+
* 网格工具
|
|
52
25
|
*/
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
26
|
+
var MeshTool = /** @class */ (function () {
|
|
27
|
+
function MeshTool() {
|
|
28
|
+
}
|
|
29
|
+
MeshTool.indexable = function (obj, refIndexInfo, force) {
|
|
30
|
+
if (refIndexInfo === void 0) { refIndexInfo = { index: 0 }; }
|
|
31
|
+
if (force === void 0) { force = false; }
|
|
32
|
+
if (obj instanceof Array) {
|
|
33
|
+
for (var i = 0; i < obj.length; i++)
|
|
34
|
+
MeshTool.indexable(obj[i], refIndexInfo);
|
|
35
|
+
}
|
|
36
|
+
else if (obj instanceof Object) {
|
|
37
|
+
if (obj.index === undefined)
|
|
38
|
+
obj.index = refIndexInfo.index++;
|
|
39
|
+
else if (force)
|
|
40
|
+
obj.index = refIndexInfo.index++;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
MeshTool.triangListToBuffer = function (vertices, triangleList) {
|
|
44
|
+
MeshTool.indexable(triangleList);
|
|
45
|
+
var indices = [];
|
|
46
|
+
array_1.forall(triangleList, function (v) {
|
|
47
|
+
indices.push(v.index);
|
|
48
|
+
});
|
|
49
|
+
return MeshTool.toGeoBuffer(vertices, indices);
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* 顶点纹理坐标所以转化为buffer数据
|
|
53
|
+
* @param {Array<Verctor3|Number>} vertices
|
|
54
|
+
* @param {Array<Number>} indices
|
|
55
|
+
* @param {Array<Verctor2|Number>} uvs
|
|
56
|
+
*/
|
|
57
|
+
MeshTool.toGeoBuffer = function (vertices, indices, uvs) {
|
|
58
|
+
var geometry = new geometry_1.BufferGeometry();
|
|
59
|
+
geometry.addAttribute('position', vertices, 3);
|
|
60
|
+
geometry.addAttribute('uv', uvs || new Float32Array(geometry.getAttribute('position').array.length / 3 * 2), 2);
|
|
61
|
+
geometry.setIndex(indices);
|
|
62
|
+
return geometry;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* 三角剖分后转成几何体
|
|
66
|
+
* 只考虑XY平面
|
|
67
|
+
* @param {*} boundary
|
|
68
|
+
* @param {*} hole
|
|
69
|
+
* @param {*} options
|
|
70
|
+
*/
|
|
71
|
+
MeshTool.trianglutionToGeometryBuffer = function (boundary, holes, options) {
|
|
72
|
+
if (holes === void 0) { holes = []; }
|
|
73
|
+
if (options === void 0) { options = { normal: Vec3_1.Vec3.UnitZ }; }
|
|
74
|
+
var triangles = trianglution_1.triangulation(boundary, holes, options);
|
|
75
|
+
var vertices = __spreadArrays(boundary, array_1.flat(holes));
|
|
76
|
+
var uvs = [];
|
|
77
|
+
vertices.forEach(function (v) {
|
|
78
|
+
uvs.push(v.x, v.z);
|
|
79
|
+
});
|
|
80
|
+
var geometry = MeshTool.toGeoBuffer(vertices, triangles, uvs);
|
|
81
|
+
return geometry;
|
|
82
|
+
};
|
|
83
|
+
return MeshTool;
|
|
84
|
+
}());
|
|
85
|
+
exports.MeshTool = MeshTool;
|
package/dist/render/types.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
|
|
2
2
|
export declare const isBufferArray: (obj: any) => boolean;
|
|
3
|
+
export declare type TypedArrayLike = number[] | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
|
package/dist/struct/3d/Box.d.ts
CHANGED