three-base 2.0.24 → 2.0.26
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 +13 -7
- package/InstancedGroupMesh.js +48 -5
- package/InstancedGroupMesh.ts +70 -17
- 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/ThreeMouse.d.ts +1 -1
- package/ThreeMouse.js +2 -2
- package/ThreeMouse.ts +2 -2
- package/Transition.js +3 -1
- package/Transition.ts +3 -1
- package/package.json +1 -1
- package/threeLoader.d.ts +3 -1
- package/threeLoader.js +32 -1
- package/threeLoader.ts +33 -1
package/InstancedGroupMesh.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default class InstancedGroupMesh extends
|
|
1
|
+
import { Color, Group, InstancedMesh, Matrix4, Mesh } from 'three';
|
|
2
|
+
export default class InstancedGroupMesh extends Mesh {
|
|
3
|
+
children: InstancedMesh[];
|
|
3
4
|
isInstancedGroupMesh: boolean;
|
|
4
5
|
count: number;
|
|
5
|
-
meshCollect: Record<string,
|
|
6
|
-
instanceCollect: Record<string,
|
|
7
|
-
static matrix:
|
|
8
|
-
constructor(group:
|
|
9
|
-
|
|
6
|
+
meshCollect: Record<string, Mesh[]>;
|
|
7
|
+
instanceCollect: Record<string, InstancedMesh>;
|
|
8
|
+
static matrix: Matrix4;
|
|
9
|
+
constructor(group: Group, count: number);
|
|
10
|
+
computeBoundingSphere: import("lodash").DebouncedFunc<() => void>;
|
|
11
|
+
setMatrixAt(index: number, matrix: Matrix4): void;
|
|
12
|
+
setColorAt(index: number, color: (instancedMesh: InstancedMesh) => Color | undefined): void;
|
|
13
|
+
updateMatrixWorld(force?: boolean): void;
|
|
14
|
+
addEventListener(name: string, callback: (e: any) => void): void;
|
|
15
|
+
removeEventListener(name: string, callback: (e: any) => void): void;
|
|
10
16
|
}
|
package/InstancedGroupMesh.js
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
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-27 17:41:26
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
7
|
+
import { throttle } from 'lodash';
|
|
8
|
+
import { InstancedMesh, Matrix4, Mesh } from 'three';
|
|
8
9
|
// 模型组转成 实例对象
|
|
9
|
-
export default class InstancedGroupMesh extends
|
|
10
|
+
export default class InstancedGroupMesh extends Mesh {
|
|
10
11
|
isInstancedGroupMesh = true;
|
|
11
12
|
count = 0;
|
|
12
13
|
meshCollect = {};
|
|
13
14
|
instanceCollect = {};
|
|
14
|
-
static matrix = new
|
|
15
|
+
static matrix = new Matrix4();
|
|
15
16
|
constructor(group, count) {
|
|
16
17
|
super();
|
|
17
18
|
this.count = count;
|
|
@@ -20,6 +21,7 @@ export default class InstancedGroupMesh extends THREE.Mesh {
|
|
|
20
21
|
// collect all mesh counts, in case there are more than one copy of the same mesh in this group
|
|
21
22
|
group.traverse((obj) => {
|
|
22
23
|
const mesh = obj;
|
|
24
|
+
obj.userData = this.userData;
|
|
23
25
|
if (mesh.isMesh) {
|
|
24
26
|
mesh.matrixWorld.decompose(mesh.position, mesh.quaternion, mesh.scale);
|
|
25
27
|
mesh.rotation.setFromQuaternion(mesh.quaternion);
|
|
@@ -43,11 +45,17 @@ export default class InstancedGroupMesh extends THREE.Mesh {
|
|
|
43
45
|
Object.keys(meshCollect).forEach(uuid => {
|
|
44
46
|
const meshes = meshCollect[uuid];
|
|
45
47
|
const mesh = meshes[0];
|
|
46
|
-
const instancedMesh = new
|
|
48
|
+
const instancedMesh = new InstancedMesh(mesh.geometry, mesh.material, meshes.length * count);
|
|
47
49
|
instanceCollect[uuid] = instancedMesh;
|
|
48
50
|
this.add(instancedMesh);
|
|
49
51
|
});
|
|
50
52
|
}
|
|
53
|
+
// 更新包围盒
|
|
54
|
+
computeBoundingSphere = throttle(() => {
|
|
55
|
+
this.traverse(m => {
|
|
56
|
+
m.computeBoundingSphere();
|
|
57
|
+
});
|
|
58
|
+
}, 1000);
|
|
51
59
|
setMatrixAt(index, matrix) {
|
|
52
60
|
Object.keys(this.meshCollect).forEach(uuid => {
|
|
53
61
|
const instancedMesh = this.instanceCollect[uuid];
|
|
@@ -59,5 +67,40 @@ export default class InstancedGroupMesh extends THREE.Mesh {
|
|
|
59
67
|
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
60
68
|
});
|
|
61
69
|
});
|
|
70
|
+
this.computeBoundingSphere();
|
|
71
|
+
}
|
|
72
|
+
// 设置颜色
|
|
73
|
+
setColorAt(index, color) {
|
|
74
|
+
Object.keys(this.meshCollect).forEach(uuid => {
|
|
75
|
+
const instancedMesh = this.instanceCollect[uuid];
|
|
76
|
+
const collect = this.meshCollect[uuid];
|
|
77
|
+
collect.forEach((mesh, i) => {
|
|
78
|
+
const c = color(instancedMesh);
|
|
79
|
+
if (c) {
|
|
80
|
+
instancedMesh.setColorAt(collect.length * index + i, c);
|
|
81
|
+
instancedMesh.instanceColor.needsUpdate = true;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
// 同步属性
|
|
87
|
+
updateMatrixWorld(force) {
|
|
88
|
+
super.updateMatrixWorld(force);
|
|
89
|
+
const { cursor, enableEvent } = this.userData;
|
|
90
|
+
this.traverse(obj => {
|
|
91
|
+
Object.assign(obj.userData, { cursor, enableEvent });
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// 事件监听
|
|
95
|
+
addEventListener(name, callback) {
|
|
96
|
+
this.children.map(mesh => {
|
|
97
|
+
mesh.addEventListener(name, callback);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// 取消事件的监听
|
|
101
|
+
removeEventListener(name, callback) {
|
|
102
|
+
this.children.map(mesh => {
|
|
103
|
+
mesh.removeEventListener(name, callback);
|
|
104
|
+
});
|
|
62
105
|
}
|
|
63
106
|
}
|
package/InstancedGroupMesh.ts
CHANGED
|
@@ -2,26 +2,29 @@
|
|
|
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-27 17:41:26
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import { throttle } from 'lodash';
|
|
9
|
+
import { Color, Group, InstancedMesh, Material, Matrix4, Mesh } from 'three';
|
|
9
10
|
|
|
10
11
|
// 模型组转成 实例对象
|
|
11
|
-
export default class InstancedGroupMesh extends
|
|
12
|
+
export default class InstancedGroupMesh extends Mesh {
|
|
13
|
+
|
|
14
|
+
declare children: InstancedMesh[];
|
|
15
|
+
|
|
12
16
|
isInstancedGroupMesh = true
|
|
13
17
|
|
|
14
|
-
count: number = 0
|
|
18
|
+
count: number = 0;
|
|
15
19
|
|
|
16
|
-
meshCollect: Record<string,
|
|
20
|
+
meshCollect: Record<string, Mesh[]> = {}
|
|
17
21
|
|
|
18
|
-
instanceCollect: Record<string,
|
|
22
|
+
instanceCollect: Record<string, InstancedMesh> = {}
|
|
19
23
|
|
|
20
|
-
static matrix = new
|
|
24
|
+
static matrix = new Matrix4()
|
|
21
25
|
|
|
22
|
-
constructor(group:
|
|
26
|
+
constructor(group: Group, count: number) {
|
|
23
27
|
super()
|
|
24
|
-
|
|
25
28
|
this.count = count
|
|
26
29
|
|
|
27
30
|
const { meshCollect, instanceCollect } = this
|
|
@@ -30,7 +33,10 @@ export default class InstancedGroupMesh extends THREE.Mesh {
|
|
|
30
33
|
|
|
31
34
|
// collect all mesh counts, in case there are more than one copy of the same mesh in this group
|
|
32
35
|
group.traverse((obj) => {
|
|
33
|
-
const mesh = obj as
|
|
36
|
+
const mesh = obj as Mesh;
|
|
37
|
+
|
|
38
|
+
obj.userData = this.userData;
|
|
39
|
+
|
|
34
40
|
if (mesh.isMesh) {
|
|
35
41
|
|
|
36
42
|
mesh.matrixWorld.decompose(mesh.position, mesh.quaternion, mesh.scale);
|
|
@@ -38,7 +44,7 @@ export default class InstancedGroupMesh extends THREE.Mesh {
|
|
|
38
44
|
mesh.updateMatrix();
|
|
39
45
|
|
|
40
46
|
// same geometry and same material consider as the same mesh
|
|
41
|
-
const uuid = mesh.geometry.uuid + '/' + (mesh.material as
|
|
47
|
+
const uuid = mesh.geometry.uuid + '/' + (mesh.material as Material).uuid
|
|
42
48
|
|
|
43
49
|
if (meshCollect[uuid]) {
|
|
44
50
|
meshCollect[uuid].push(mesh)
|
|
@@ -58,23 +64,70 @@ export default class InstancedGroupMesh extends THREE.Mesh {
|
|
|
58
64
|
const meshes = meshCollect[uuid]
|
|
59
65
|
const mesh = meshes[0]
|
|
60
66
|
|
|
61
|
-
const instancedMesh = new
|
|
62
|
-
instanceCollect[uuid] = instancedMesh
|
|
67
|
+
const instancedMesh = new InstancedMesh(mesh.geometry, mesh.material, meshes.length * count)
|
|
68
|
+
instanceCollect[uuid] = instancedMesh;
|
|
63
69
|
this.add(instancedMesh)
|
|
64
70
|
})
|
|
65
71
|
}
|
|
66
72
|
|
|
67
|
-
|
|
73
|
+
// 更新包围盒
|
|
74
|
+
computeBoundingSphere = throttle(() => {
|
|
75
|
+
this.traverse(m => {
|
|
76
|
+
(m as InstancedMesh).computeBoundingSphere();
|
|
77
|
+
})
|
|
78
|
+
}, 1000)
|
|
79
|
+
|
|
80
|
+
setMatrixAt(index: number, matrix: Matrix4) {
|
|
68
81
|
Object.keys(this.meshCollect).forEach(uuid => {
|
|
69
82
|
const instancedMesh = this.instanceCollect[uuid]
|
|
70
83
|
const collect = this.meshCollect[uuid]
|
|
71
|
-
collect.forEach((mesh:
|
|
84
|
+
collect.forEach((mesh: Mesh, i: number) => {
|
|
72
85
|
InstancedGroupMesh.matrix.copy(mesh.matrix)
|
|
73
86
|
InstancedGroupMesh.matrix.premultiply(matrix)
|
|
74
|
-
|
|
75
87
|
instancedMesh.setMatrixAt(collect.length * index + i, InstancedGroupMesh.matrix);
|
|
76
88
|
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
77
89
|
})
|
|
78
90
|
})
|
|
91
|
+
this.computeBoundingSphere();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 设置颜色
|
|
95
|
+
setColorAt(index: number, color: (instancedMesh: InstancedMesh) => Color | undefined) {
|
|
96
|
+
Object.keys(this.meshCollect).forEach(uuid => {
|
|
97
|
+
const instancedMesh = this.instanceCollect[uuid]
|
|
98
|
+
const collect = this.meshCollect[uuid]
|
|
99
|
+
collect.forEach((mesh: Mesh, i: number) => {
|
|
100
|
+
const c = color(instancedMesh);
|
|
101
|
+
if (c) {
|
|
102
|
+
instancedMesh.setColorAt(collect.length * index + i, c);
|
|
103
|
+
instancedMesh.instanceColor!.needsUpdate = true;
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// 同步属性
|
|
110
|
+
updateMatrixWorld(force?: boolean): void {
|
|
111
|
+
super.updateMatrixWorld(force);
|
|
112
|
+
const { cursor, enableEvent } = this.userData;
|
|
113
|
+
this.traverse(obj => {
|
|
114
|
+
Object.assign(obj.userData, { cursor, enableEvent });
|
|
115
|
+
});
|
|
79
116
|
}
|
|
80
|
-
|
|
117
|
+
|
|
118
|
+
// 事件监听
|
|
119
|
+
addEventListener(name: string, callback: (e: any) => void) {
|
|
120
|
+
this.children.map(mesh => {
|
|
121
|
+
mesh.addEventListener(name, callback);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 取消事件的监听
|
|
126
|
+
removeEventListener(name: string, callback: (e: any) => void) {
|
|
127
|
+
this.children.map(mesh => {
|
|
128
|
+
mesh.removeEventListener(name, callback);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
}
|
|
133
|
+
|
|
@@ -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)) {
|
package/ThreeMouse.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface ThreeMouseEvent extends Intersection {
|
|
|
11
11
|
y: number;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* three.js 专用的鼠标拾取模型对象
|
|
15
15
|
*/
|
|
16
16
|
export default class ThreeMouse {
|
|
17
17
|
constructor(renderer: THREE.WebGLRenderer, camera: THREE.Camera, scene: THREE.Scene);
|
package/ThreeMouse.js
CHANGED
|
@@ -8,7 +8,7 @@ import * as THREE from "three";
|
|
|
8
8
|
import { Raycaster } from "three";
|
|
9
9
|
import { debounce } from "lodash";
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* three.js 专用的鼠标拾取模型对象
|
|
12
12
|
*/
|
|
13
13
|
export default class ThreeMouse {
|
|
14
14
|
constructor(renderer, camera, scene) {
|
|
@@ -108,7 +108,7 @@ export default class ThreeMouse {
|
|
|
108
108
|
let intersection = this._getSelected(meshs);
|
|
109
109
|
if (intersection) {
|
|
110
110
|
const { face, object } = intersection;
|
|
111
|
-
face && face.normal.applyMatrix4(object.matrixWorld);
|
|
111
|
+
// face && face.normal.applyMatrix4(object.matrixWorld);
|
|
112
112
|
const MouseEvent = Object.assign(intersection, {
|
|
113
113
|
renderer: this._renderer,
|
|
114
114
|
camera: this._camera,
|
package/ThreeMouse.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface ThreeMouseEvent extends Intersection {
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* three.js 专用的鼠标拾取模型对象
|
|
25
25
|
*/
|
|
26
26
|
export default class ThreeMouse {
|
|
27
27
|
|
|
@@ -152,7 +152,7 @@ export default class ThreeMouse {
|
|
|
152
152
|
|
|
153
153
|
if (intersection) {
|
|
154
154
|
const { face, object } = intersection;
|
|
155
|
-
face && face.normal.applyMatrix4(object.matrixWorld);
|
|
155
|
+
// face && face.normal.applyMatrix4(object.matrixWorld);
|
|
156
156
|
const MouseEvent: ThreeMouseEvent = Object.assign(intersection, { // 将来可能用到的对象
|
|
157
157
|
renderer: this._renderer,
|
|
158
158
|
camera: this._camera,
|
package/Transition.js
CHANGED
package/Transition.ts
CHANGED
package/package.json
CHANGED
package/threeLoader.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventDispatcher, Texture, TextureLoader } from "three";
|
|
1
|
+
import { EventDispatcher, Object3D, Texture, TextureLoader } from "three";
|
|
2
2
|
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
|
|
3
3
|
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
|
4
4
|
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
|
|
@@ -16,6 +16,8 @@ declare class ThreeLoader extends EventDispatcher {
|
|
|
16
16
|
stlLoader: STLLoader;
|
|
17
17
|
mtlLoader: MTLLoader;
|
|
18
18
|
gltfLoader: GLTFLoader;
|
|
19
|
+
/** 加载模型支持glb,fbx,stl,obj */
|
|
20
|
+
loadModal(url: string): Promise<Object3D<import("three").Object3DEventMap>>;
|
|
19
21
|
onload: boolean;
|
|
20
22
|
}
|
|
21
23
|
declare const threeLoader: ThreeLoader;
|
package/threeLoader.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @Last Modified by: xiaosihan
|
|
5
5
|
* @Last Modified time: 2023-02-07 11:11:48
|
|
6
6
|
*/
|
|
7
|
-
import { CanvasTexture, DefaultLoadingManager, EventDispatcher, RepeatWrapping, TextureLoader, VideoTexture } from "three";
|
|
7
|
+
import { CanvasTexture, DefaultLoadingManager, EventDispatcher, Mesh, MeshLambertMaterial, Object3D, RepeatWrapping, TextureLoader, VideoTexture } from "three";
|
|
8
8
|
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
|
|
9
9
|
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
|
10
10
|
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
|
|
@@ -114,6 +114,37 @@ class ThreeLoader extends EventDispatcher {
|
|
|
114
114
|
loader.setDRACOLoader(dracoLoader);
|
|
115
115
|
return loader;
|
|
116
116
|
})();
|
|
117
|
+
/** 加载模型支持glb,fbx,stl,obj */
|
|
118
|
+
async loadModal(url) {
|
|
119
|
+
let Object3d = new Object3D();
|
|
120
|
+
if (/\.fbx$/i.test(url)) {
|
|
121
|
+
await threeLoader.fbxLoader.loadAsync(url).then(res => {
|
|
122
|
+
Object3d = res;
|
|
123
|
+
}).catch(() => {
|
|
124
|
+
console.error(`${url},加载失败`);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
else if (/\.(gltf|glb)$/i.test(url)) {
|
|
128
|
+
await threeLoader.gltfLoader.loadAsync(url).then(res => {
|
|
129
|
+
Object3d = res.scene;
|
|
130
|
+
Object3d.animations = res.animations;
|
|
131
|
+
}).catch(() => {
|
|
132
|
+
console.error(`${url},加载失败`);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
else if (/\.stl$/i.test(url)) {
|
|
136
|
+
await threeLoader.stlLoader.loadAsync(url).then(geometry => {
|
|
137
|
+
const material = new MeshLambertMaterial();
|
|
138
|
+
Object3d = new Mesh(geometry, material);
|
|
139
|
+
}).catch(() => {
|
|
140
|
+
console.error(`${url},加载失败`);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
throw new Error(`${url},不支持的格式`);
|
|
145
|
+
}
|
|
146
|
+
return Object3d;
|
|
147
|
+
}
|
|
117
148
|
// 是否加载完成
|
|
118
149
|
onload = true;
|
|
119
150
|
}
|
package/threeLoader.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @Last Modified time: 2023-02-07 11:11:48
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { CanvasTexture, DefaultLoadingManager, EventDispatcher, RepeatWrapping, SRGBColorSpace, Texture, TextureLoader, VideoTexture } from "three";
|
|
8
|
+
import { CanvasTexture, DefaultLoadingManager, EventDispatcher, Mesh, MeshLambertMaterial, Object3D, RepeatWrapping, SRGBColorSpace, Texture, TextureLoader, VideoTexture } from "three";
|
|
9
9
|
import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader";
|
|
10
10
|
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
|
11
11
|
import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader";
|
|
@@ -141,6 +141,38 @@ class ThreeLoader extends EventDispatcher {
|
|
|
141
141
|
return loader;
|
|
142
142
|
})()
|
|
143
143
|
|
|
144
|
+
|
|
145
|
+
/** 加载模型支持glb,fbx,stl,obj */
|
|
146
|
+
async loadModal(url: string) {
|
|
147
|
+
let Object3d = new Object3D();
|
|
148
|
+
|
|
149
|
+
if (/\.fbx$/i.test(url)) {
|
|
150
|
+
await threeLoader.fbxLoader.loadAsync(url).then(res => {
|
|
151
|
+
Object3d = res;
|
|
152
|
+
}).catch(() => {
|
|
153
|
+
console.error(`${url},加载失败`);
|
|
154
|
+
})
|
|
155
|
+
} else if (/\.(gltf|glb)$/i.test(url)) {
|
|
156
|
+
await threeLoader.gltfLoader.loadAsync(url).then(res => {
|
|
157
|
+
Object3d = res.scene;
|
|
158
|
+
Object3d.animations = res.animations;
|
|
159
|
+
}).catch(() => {
|
|
160
|
+
console.error(`${url},加载失败`);
|
|
161
|
+
})
|
|
162
|
+
} else if (/\.stl$/i.test(url)) {
|
|
163
|
+
await threeLoader.stlLoader.loadAsync(url).then(geometry => {
|
|
164
|
+
const material = new MeshLambertMaterial();
|
|
165
|
+
Object3d = new Mesh(geometry, material);
|
|
166
|
+
}).catch(() => {
|
|
167
|
+
console.error(`${url},加载失败`);
|
|
168
|
+
})
|
|
169
|
+
} else {
|
|
170
|
+
throw new Error(`${url},不支持的格式`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return Object3d;
|
|
174
|
+
}
|
|
175
|
+
|
|
144
176
|
// 是否加载完成
|
|
145
177
|
onload = true;
|
|
146
178
|
|