three-base 1.0.14 → 1.0.16

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/index.ts CHANGED
@@ -14,6 +14,9 @@ export { default as KeyFrameAnimation } from "./lib/KeyFrameAnimation";
14
14
  export type { KeyframeAnimationProps } from "./lib/KeyFrameAnimation";
15
15
  export type { Keyframe } from "./lib/KeyFrameAnimation";
16
16
 
17
+ //实例模型组对象
18
+ export { default as InstancedGroupMesh } from "./lib/InstancedGroupMesh";
19
+
17
20
  //点光源
18
21
  export { default as PointLight } from "./lib/PointLight";
19
22
 
@@ -0,0 +1,71 @@
1
+ /*
2
+ * @Author: xiaosihan
3
+ * @Date: 2023-02-21 09:55:52
4
+ * @Last Modified by: xiaosihan
5
+ * @Last Modified time: 2023-02-21 10:12:33
6
+ */
7
+
8
+ import * as THREE from 'three'
9
+
10
+ // 模型组转成 实例对象
11
+ export default class InstancedGroupMesh extends THREE.Mesh {
12
+ isInstancedGroupMesh = true
13
+
14
+ count: number = 0
15
+
16
+ meshCollect: Record<string, THREE.Mesh[]> = {}
17
+
18
+ instanceCollect: Record<string, THREE.InstancedMesh> = {}
19
+
20
+ static matrix = new THREE.Matrix4()
21
+
22
+ constructor(group: THREE.Group, count: number) {
23
+ super()
24
+
25
+ this.count = count
26
+
27
+ const { meshCollect, instanceCollect } = this
28
+
29
+ // collect all mesh counts, in case there are more than one copy of the same mesh in this group
30
+ group.traverse((obj) => {
31
+ if (obj.type !== 'Mesh') return
32
+ const mesh = obj as THREE.Mesh
33
+
34
+ // this is important
35
+ mesh.updateMatrix()
36
+
37
+ // same geometry and same material consider as the same mesh
38
+ const uuid = mesh.geometry.uuid + '/' + (mesh.material as THREE.Material).uuid
39
+
40
+ if (meshCollect[uuid]) {
41
+ meshCollect[uuid].push(mesh)
42
+ } else {
43
+ meshCollect[uuid] = [mesh]
44
+ }
45
+ })
46
+
47
+ // create all instances
48
+ Object.keys(meshCollect).forEach(uuid => {
49
+ const meshes = meshCollect[uuid]
50
+ const mesh = meshes[0]
51
+
52
+ const instancedMesh = new THREE.InstancedMesh(mesh.geometry, mesh.material, meshes.length * count)
53
+ instanceCollect[uuid] = instancedMesh
54
+ this.add(instancedMesh)
55
+ })
56
+ }
57
+
58
+ setMatrixAt(index: number, matrix: THREE.Matrix4) {
59
+ Object.keys(this.meshCollect).forEach(uuid => {
60
+ const instancedMesh = this.instanceCollect[uuid]
61
+ const collect = this.meshCollect[uuid]
62
+ collect.forEach((mesh: THREE.Mesh, i: number) => {
63
+ InstancedGroupMesh.matrix.copy(mesh.matrix)
64
+ InstancedGroupMesh.matrix.premultiply(matrix)
65
+
66
+ instancedMesh.setMatrixAt(collect.length * index + i, InstancedGroupMesh.matrix);
67
+ instancedMesh.instanceMatrix.needsUpdate = true;
68
+ })
69
+ })
70
+ }
71
+ }
package/lib/Transition.ts CHANGED
@@ -92,6 +92,7 @@ export default class Transition {
92
92
  } else {
93
93
  this.onChangeCall(this.getJson());
94
94
  }
95
+ return this;
95
96
  }
96
97
 
97
98
  runbindThis = this.run.bind(this);
@@ -144,7 +145,7 @@ export default class Transition {
144
145
  return 0;
145
146
  }
146
147
 
147
- set(param: TParam): this {
148
+ async set(param: TParam): Promise<this> {
148
149
 
149
150
  let timetemp = performance.now() + this._delay;;
150
151
 
@@ -184,6 +185,11 @@ export default class Transition {
184
185
 
185
186
  }
186
187
  threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
188
+
189
+ while (!this._isDone) {
190
+ await new Promise(resolve => setTimeout(resolve, 50));
191
+ }
192
+
187
193
  return this;
188
194
  }
189
195
  // 重置起始和终止位置
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-base",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "three 3d three-base",
5
5
  "keywords": [
6
6
  "three",