three-base 2.0.24 → 2.0.25
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/InstancedGroupMesh.d.ts +12 -7
- package/InstancedGroupMesh.js +33 -5
- package/InstancedGroupMesh.ts +51 -13
- package/InstancedMeshBase/InstancedMeshBase.d.ts +4 -0
- package/InstancedMeshBase/InstancedMeshBase.js +13 -0
- package/InstancedMeshBase/InstancedMeshBase.ts +18 -0
- package/MeshBase.d.ts +4 -0
- package/MeshBase.js +13 -0
- package/MeshBase.ts +19 -0
- package/PlaneText.d.ts +2 -2
- package/ThreeBase.js +1 -1
- package/ThreeBase.ts +1 -1
- package/package.json +1 -1
package/InstancedGroupMesh.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default class InstancedGroupMesh extends
|
|
1
|
+
import { Group, InstancedMesh, Matrix4, Mesh, Vector3, Color } from 'three';
|
|
2
|
+
export default class InstancedGroupMesh extends Mesh {
|
|
3
|
+
url: string;
|
|
3
4
|
isInstancedGroupMesh: boolean;
|
|
4
5
|
count: number;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
size: Vector3;
|
|
7
|
+
meshCollect: Record<string, Mesh[]>;
|
|
8
|
+
instanceCollect: Record<string, InstancedMesh>;
|
|
9
|
+
children: InstancedMesh[];
|
|
10
|
+
static matrix: Matrix4;
|
|
11
|
+
constructor(group: Group, count: number);
|
|
12
|
+
computeBoundingSphere: import("lodash").DebouncedFunc<() => void>;
|
|
13
|
+
setMatrixAt(index: number, matrix: Matrix4): void;
|
|
14
|
+
setColorAt(index: number, color: (instancedMesh: InstancedMesh) => Color | undefined): void;
|
|
10
15
|
}
|
package/InstancedGroupMesh.js
CHANGED
|
@@ -2,18 +2,23 @@
|
|
|
2
2
|
* @Author: xiaosihan
|
|
3
3
|
* @Date: 2023-02-21 09:55:52
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time:
|
|
5
|
+
* @Last Modified time: 2024-01-20 21:58:20
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
7
|
+
import { throttle } from 'lodash';
|
|
8
|
+
import { InstancedMesh, Matrix4, Mesh, Vector3 } from 'three';
|
|
9
|
+
import threeUtils from './threeUtils';
|
|
8
10
|
// 模型组转成 实例对象
|
|
9
|
-
export default class InstancedGroupMesh extends
|
|
11
|
+
export default class InstancedGroupMesh extends Mesh {
|
|
12
|
+
url = "";
|
|
10
13
|
isInstancedGroupMesh = true;
|
|
11
14
|
count = 0;
|
|
15
|
+
size = new Vector3(1, 1, 1);
|
|
12
16
|
meshCollect = {};
|
|
13
17
|
instanceCollect = {};
|
|
14
|
-
static matrix = new
|
|
18
|
+
static matrix = new Matrix4();
|
|
15
19
|
constructor(group, count) {
|
|
16
20
|
super();
|
|
21
|
+
this.size.copy(threeUtils.getSize(group));
|
|
17
22
|
this.count = count;
|
|
18
23
|
const { meshCollect, instanceCollect } = this;
|
|
19
24
|
group.updateMatrixWorld(true);
|
|
@@ -43,11 +48,19 @@ export default class InstancedGroupMesh extends THREE.Mesh {
|
|
|
43
48
|
Object.keys(meshCollect).forEach(uuid => {
|
|
44
49
|
const meshes = meshCollect[uuid];
|
|
45
50
|
const mesh = meshes[0];
|
|
46
|
-
const instancedMesh = new
|
|
51
|
+
const instancedMesh = new InstancedMesh(mesh.geometry, mesh.material, meshes.length * count);
|
|
52
|
+
instancedMesh.name = mesh.name;
|
|
53
|
+
instancedMesh.frustumCulled = false;
|
|
47
54
|
instanceCollect[uuid] = instancedMesh;
|
|
48
55
|
this.add(instancedMesh);
|
|
49
56
|
});
|
|
50
57
|
}
|
|
58
|
+
// 更新包围盒
|
|
59
|
+
computeBoundingSphere = throttle(() => {
|
|
60
|
+
this.traverse(m => {
|
|
61
|
+
m.computeBoundingSphere();
|
|
62
|
+
});
|
|
63
|
+
}, 1000);
|
|
51
64
|
setMatrixAt(index, matrix) {
|
|
52
65
|
Object.keys(this.meshCollect).forEach(uuid => {
|
|
53
66
|
const instancedMesh = this.instanceCollect[uuid];
|
|
@@ -59,5 +72,20 @@ export default class InstancedGroupMesh extends THREE.Mesh {
|
|
|
59
72
|
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
60
73
|
});
|
|
61
74
|
});
|
|
75
|
+
this.computeBoundingSphere();
|
|
76
|
+
}
|
|
77
|
+
// 设置颜色
|
|
78
|
+
setColorAt(index, color) {
|
|
79
|
+
Object.keys(this.meshCollect).forEach(uuid => {
|
|
80
|
+
const instancedMesh = this.instanceCollect[uuid];
|
|
81
|
+
const collect = this.meshCollect[uuid];
|
|
82
|
+
collect.forEach((mesh, i) => {
|
|
83
|
+
const c = color(instancedMesh);
|
|
84
|
+
if (c) {
|
|
85
|
+
instancedMesh.setColorAt(collect.length * index + i, c);
|
|
86
|
+
instancedMesh.instanceColor.needsUpdate = true;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
62
90
|
}
|
|
63
91
|
}
|
package/InstancedGroupMesh.ts
CHANGED
|
@@ -2,26 +2,37 @@
|
|
|
2
2
|
* @Author: xiaosihan
|
|
3
3
|
* @Date: 2023-02-21 09:55:52
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time:
|
|
5
|
+
* @Last Modified time: 2024-01-20 21:58:20
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import { throttle } from 'lodash';
|
|
9
|
+
import { Group, InstancedMesh, Material, Matrix4, Mesh, Vector3, Color } from 'three'
|
|
10
|
+
import threeUtils from './threeUtils';
|
|
9
11
|
|
|
10
12
|
// 模型组转成 实例对象
|
|
11
|
-
export default class InstancedGroupMesh extends
|
|
13
|
+
export default class InstancedGroupMesh extends Mesh {
|
|
14
|
+
|
|
15
|
+
url = "";
|
|
16
|
+
|
|
12
17
|
isInstancedGroupMesh = true
|
|
13
18
|
|
|
14
19
|
count: number = 0
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
size = new Vector3(1, 1, 1);
|
|
22
|
+
|
|
23
|
+
meshCollect: Record<string, Mesh[]> = {}
|
|
17
24
|
|
|
18
|
-
instanceCollect: Record<string,
|
|
25
|
+
instanceCollect: Record<string, InstancedMesh> = {}
|
|
19
26
|
|
|
20
|
-
|
|
27
|
+
declare children: InstancedMesh[];
|
|
21
28
|
|
|
22
|
-
|
|
29
|
+
static matrix = new Matrix4()
|
|
30
|
+
|
|
31
|
+
constructor(group: Group, count: number) {
|
|
23
32
|
super()
|
|
24
33
|
|
|
34
|
+
this.size.copy(threeUtils.getSize(group));
|
|
35
|
+
|
|
25
36
|
this.count = count
|
|
26
37
|
|
|
27
38
|
const { meshCollect, instanceCollect } = this
|
|
@@ -30,7 +41,7 @@ export default class InstancedGroupMesh extends THREE.Mesh {
|
|
|
30
41
|
|
|
31
42
|
// collect all mesh counts, in case there are more than one copy of the same mesh in this group
|
|
32
43
|
group.traverse((obj) => {
|
|
33
|
-
const mesh = obj as
|
|
44
|
+
const mesh = obj as Mesh
|
|
34
45
|
if (mesh.isMesh) {
|
|
35
46
|
|
|
36
47
|
mesh.matrixWorld.decompose(mesh.position, mesh.quaternion, mesh.scale);
|
|
@@ -38,7 +49,7 @@ export default class InstancedGroupMesh extends THREE.Mesh {
|
|
|
38
49
|
mesh.updateMatrix();
|
|
39
50
|
|
|
40
51
|
// same geometry and same material consider as the same mesh
|
|
41
|
-
const uuid = mesh.geometry.uuid + '/' + (mesh.material as
|
|
52
|
+
const uuid = mesh.geometry.uuid + '/' + (mesh.material as Material).uuid
|
|
42
53
|
|
|
43
54
|
if (meshCollect[uuid]) {
|
|
44
55
|
meshCollect[uuid].push(mesh)
|
|
@@ -57,18 +68,27 @@ export default class InstancedGroupMesh extends THREE.Mesh {
|
|
|
57
68
|
Object.keys(meshCollect).forEach(uuid => {
|
|
58
69
|
const meshes = meshCollect[uuid]
|
|
59
70
|
const mesh = meshes[0]
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
const instancedMesh = new InstancedMesh(mesh.geometry, mesh.material, meshes.length * count)
|
|
72
|
+
instancedMesh.name = mesh.name;
|
|
73
|
+
instancedMesh.frustumCulled = false;
|
|
62
74
|
instanceCollect[uuid] = instancedMesh
|
|
63
75
|
this.add(instancedMesh)
|
|
64
76
|
})
|
|
65
77
|
}
|
|
66
78
|
|
|
67
|
-
|
|
79
|
+
|
|
80
|
+
// 更新包围盒
|
|
81
|
+
computeBoundingSphere = throttle(() => {
|
|
82
|
+
this.traverse(m => {
|
|
83
|
+
(m as InstancedMesh).computeBoundingSphere();
|
|
84
|
+
})
|
|
85
|
+
}, 1000)
|
|
86
|
+
|
|
87
|
+
setMatrixAt(index: number, matrix: Matrix4) {
|
|
68
88
|
Object.keys(this.meshCollect).forEach(uuid => {
|
|
69
89
|
const instancedMesh = this.instanceCollect[uuid]
|
|
70
90
|
const collect = this.meshCollect[uuid]
|
|
71
|
-
collect.forEach((mesh:
|
|
91
|
+
collect.forEach((mesh: Mesh, i: number) => {
|
|
72
92
|
InstancedGroupMesh.matrix.copy(mesh.matrix)
|
|
73
93
|
InstancedGroupMesh.matrix.premultiply(matrix)
|
|
74
94
|
|
|
@@ -76,5 +96,23 @@ export default class InstancedGroupMesh extends THREE.Mesh {
|
|
|
76
96
|
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
77
97
|
})
|
|
78
98
|
})
|
|
99
|
+
|
|
100
|
+
this.computeBoundingSphere();
|
|
79
101
|
}
|
|
102
|
+
|
|
103
|
+
// 设置颜色
|
|
104
|
+
setColorAt(index: number, color: (instancedMesh: InstancedMesh) => Color | undefined) {
|
|
105
|
+
Object.keys(this.meshCollect).forEach(uuid => {
|
|
106
|
+
const instancedMesh = this.instanceCollect[uuid]
|
|
107
|
+
const collect = this.meshCollect[uuid]
|
|
108
|
+
collect.forEach((mesh: Mesh, i: number) => {
|
|
109
|
+
const c = color(instancedMesh);
|
|
110
|
+
if (c) {
|
|
111
|
+
instancedMesh.setColorAt(collect.length * index + i, c);
|
|
112
|
+
instancedMesh.instanceColor!.needsUpdate = true;
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
80
118
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2024-02-05 09:31:57
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2024-02-05 09:40:12
|
|
6
|
+
*/
|
|
7
|
+
import { Group } from "three";
|
|
8
|
+
// 数组实例模型
|
|
9
|
+
export default class InstancedMeshBase extends Group {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2024-02-05 09:31:57
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2024-02-05 09:40:12
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Group } from "three";
|
|
9
|
+
|
|
10
|
+
// 数组实例模型
|
|
11
|
+
export default class InstancedMeshBase extends Group {
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
}
|
package/MeshBase.d.ts
ADDED
package/MeshBase.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2024-01-29 10:08:40
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2024-02-05 09:40:17
|
|
6
|
+
*/
|
|
7
|
+
import { Group } from "three";
|
|
8
|
+
// 基础模型加载对象
|
|
9
|
+
export default class MeshBase extends Group {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
}
|
|
13
|
+
}
|
package/MeshBase.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2024-01-29 10:08:40
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2024-02-05 09:40:17
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Group } from "three";
|
|
9
|
+
|
|
10
|
+
// 基础模型加载对象
|
|
11
|
+
export default class MeshBase extends Group {
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
}
|
package/PlaneText.d.ts
CHANGED
|
@@ -22,10 +22,10 @@ export default class PlaneText extends Mesh {
|
|
|
22
22
|
spriteText: SpriteText;
|
|
23
23
|
material: MeshBasicMaterial;
|
|
24
24
|
set(parame: Props): void;
|
|
25
|
-
get(prop: keyof SpriteText): string | number | boolean | Vector3 | import("three").Object3D<import("three").Object3DEventMap> | import("three").BufferGeometry<import("three").NormalBufferAttributes> | ((force?: boolean) => void) | import("three").Object3D<import("three").Object3DEventMap>[] | HTMLCanvasElement | import("three").Vector2 | import("three").Material | Record<string, any> | import("three").Matrix4 | import("three").Quaternion | (<T extends keyof import("three").Object3DEventMap>(event: import("three").BaseEvent<T> & import("three").Object3DEventMap[T]) => void) | import("three").Euler |
|
|
25
|
+
get(prop: keyof SpriteText): string | number | boolean | Vector3 | import("three").Object3D<import("three").Object3DEventMap> | import("three").BufferGeometry<import("three").NormalBufferAttributes> | ((force?: boolean) => void) | import("three").Object3D<import("three").Object3DEventMap>[] | HTMLCanvasElement | import("three").Vector2 | import("three").Material | Record<string, any> | import("three").Matrix4 | import("three").Quaternion | (<T extends keyof import("three").Object3DEventMap>(event: import("three").BaseEvent<T> & import("three").Object3DEventMap[T]) => void) | import("three").Euler | import("three").Matrix3 | import("three").Layers | import("three").AnimationClip[] | ((renderer: import("three").WebGLRenderer, scene: import("three").Scene, shadowCamera: import("three").Camera, geometry: import("three").BufferGeometry<import("three").NormalBufferAttributes>, depthMaterial: import("three").Material, group: import("three").Group<import("three").Object3DEventMap>) => void) | ((renderer: import("three").WebGLRenderer, scene: import("three").Scene, shadowCamera: import("three").Camera, geometry: import("three").BufferGeometry<import("three").NormalBufferAttributes>, depthMaterial: import("three").Material, group: import("three").Group<import("three").Object3DEventMap>) => void) | ((renderer: import("three").WebGLRenderer, scene: import("three").Scene, camera: import("three").Camera, geometry: import("three").BufferGeometry<import("three").NormalBufferAttributes>, material: import("three").Material, group: import("three").Group<import("three").Object3DEventMap>) => void) | ((renderer: import("three").WebGLRenderer, scene: import("three").Scene, camera: import("three").Camera, geometry: import("three").BufferGeometry<import("three").NormalBufferAttributes>, material: import("three").Material, group: import("three").Group<import("three").Object3DEventMap>) => void) | ((matrix: import("three").Matrix4) => void) | ((axis: Vector3, angle: number) => void) | ((euler: import("three").Euler) => void) | ((m: import("three").Matrix4) => void) | ((q: import("three").Quaternion) => void) | ((vector: Vector3) => Vector3) | ((vector: Vector3) => Vector3) | {
|
|
26
26
|
(vector: Vector3): void;
|
|
27
27
|
(x: number, y: number, z: number): void;
|
|
28
|
-
} | ((id: number) => import("three").Object3D<import("three").Object3DEventMap>) | ((name: string) => import("three").Object3D<import("three").Object3DEventMap>) | ((name: string, value: any) => import("three").Object3D<import("three").Object3DEventMap>) | ((name: string, value: any, optionalTarget?: import("three").Object3D<import("three").Object3DEventMap>[]) => import("three").Object3D<import("three").Object3DEventMap>[]) | ((target: Vector3) => Vector3) | ((target: import("three").Quaternion) => import("three").Quaternion) | ((target: Vector3) => Vector3) | ((target: Vector3) => Vector3) | ((raycaster: import("three").Raycaster, intersects: import("three").Intersection<import("three").Object3D<import("three").Object3DEventMap>>[]) => void) | ((callback: (object: import("three").Object3D<import("three").Object3DEventMap>) => any) => void) | ((callback: (object: import("three").Object3D<import("three").Object3DEventMap>) => any) => void) | (() => void) | ((updateParents: boolean, updateChildren: boolean) => void) | ((meta?: {
|
|
28
|
+
} | ((id: number) => import("three").Object3D<import("three").Object3DEventMap>) | ((name: string) => import("three").Object3D<import("three").Object3DEventMap>) | ((name: string, value: any) => import("three").Object3D<import("three").Object3DEventMap>) | ((name: string, value: any, optionalTarget?: import("three").Object3D<import("three").Object3DEventMap>[]) => import("three").Object3D<import("three").Object3DEventMap>[]) | ((target: Vector3) => Vector3) | ((target: import("three").Quaternion) => import("three").Quaternion) | ((target: Vector3) => Vector3) | ((target: Vector3) => Vector3) | ((raycaster: import("three").Raycaster, intersects: import("three").Intersection<import("three").Object3D<import("three").Object3DEventMap>>[]) => void) | ((callback: (object: import("three").Object3D<import("three").Object3DEventMap>) => any) => void) | ((callback: (object: import("three").Object3D<import("three").Object3DEventMap>) => any) => void) | ((callback: (object: import("three").Object3D<import("three").Object3DEventMap>) => any) => void) | (() => void) | ((updateParents: boolean, updateChildren: boolean) => void) | ((meta?: {
|
|
29
29
|
geometries: any;
|
|
30
30
|
materials: any;
|
|
31
31
|
textures: any;
|
package/ThreeBase.js
CHANGED
|
@@ -295,7 +295,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
295
295
|
// 渲染场景
|
|
296
296
|
render() {
|
|
297
297
|
// 控制器在移动时鼠标不能操作
|
|
298
|
-
this.renderer.domElement.style.pointerEvents = (!this.controlsPosition.isDone() || !this.controlsCenter.isDone()) ? "none" : "all";
|
|
298
|
+
// this.renderer.domElement.style.pointerEvents = (!this.controlsPosition.isDone() || !this.controlsCenter.isDone()) ? "none" : "all";
|
|
299
299
|
// canvas 没有在页面上面的话 就跳过渲染
|
|
300
300
|
if (!threeUtils.inDocument(this.renderer.domElement)) {
|
|
301
301
|
this.stopRender();
|
package/ThreeBase.ts
CHANGED
|
@@ -364,7 +364,7 @@ export default class ThreeBase extends EventDispatcher {
|
|
|
364
364
|
// 渲染场景
|
|
365
365
|
render() {
|
|
366
366
|
// 控制器在移动时鼠标不能操作
|
|
367
|
-
this.renderer.domElement.style.pointerEvents = (!this.controlsPosition.isDone() || !this.controlsCenter.isDone()) ? "none" : "all";
|
|
367
|
+
// this.renderer.domElement.style.pointerEvents = (!this.controlsPosition.isDone() || !this.controlsCenter.isDone()) ? "none" : "all";
|
|
368
368
|
|
|
369
369
|
// canvas 没有在页面上面的话 就跳过渲染
|
|
370
370
|
if (!threeUtils.inDocument(this.renderer.domElement)) {
|