@realsee/dnalogel 3.77.4 → 3.77.5

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.
@@ -9,23 +9,30 @@ export declare class DigitalHuman {
9
9
  items: DigitalModelPlayerItem[];
10
10
  effects: DigitalModelPlayerEffect[];
11
11
  digitalPlayground: any;
12
- private mixer;
13
- private action;
14
12
  state: {
15
13
  currentTime: number;
16
14
  currentAnimation: THREE.AnimationClip | null;
15
+ currentAnimationRepeat: boolean;
17
16
  playing: boolean;
18
17
  };
19
18
  animationFrameId: number | null;
20
- private itemMatrixMap;
21
- private trace;
22
19
  curveLine: THREE.Line;
23
20
  effectsGroup: THREE.Group;
24
21
  effectObjects: Map<string, THREE.Mesh>;
25
22
  container: THREE.Group;
23
+ private mixer;
24
+ private action;
25
+ private itemMatrixMap;
26
+ private trace;
26
27
  private processedNeedRenderKeyframeIndices;
28
+ private attachedItems;
29
+ private rightHandBone;
27
30
  constructor(model: GLTFObject, digitalPlayground: any);
28
- playAnimation(animation: THREE.AnimationClip, repeat: boolean, switchDuration: number): void;
31
+ playAnimation({ animation, repeat, switchDuration }: {
32
+ animation: THREE.AnimationClip;
33
+ repeat: boolean;
34
+ switchDuration: number;
35
+ }): void;
29
36
  pauseAnimation(): void;
30
37
  stopAnimation(): void;
31
38
  continueAnimation(): void;
@@ -39,7 +46,10 @@ export declare class DigitalHuman {
39
46
  }): Promise<boolean>;
40
47
  traceUpDate(): void;
41
48
  clearTrace(): void;
49
+ clearProcessedNeedRenderKeyframeIndices(): void;
42
50
  private hasProcessedNeedRenderForTimestamp;
43
51
  private markNeedRenderProcessedForTimestamp;
44
- clearProcessedNeedRenderKeyframeIndices(): void;
52
+ private getRightHandBone;
53
+ private updateKeyframeItems;
54
+ private detachAllKeyframeItems;
45
55
  }
@@ -1,57 +1,62 @@
1
- var x = Object.defineProperty;
2
- var R = (u, e, s) => e in u ? x(u, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : u[e] = s;
3
- var n = (u, e, s) => (R(u, typeof e != "symbol" ? e + "" : e, s), s);
4
- var M = (u, e, s) => new Promise((y, h) => {
5
- var r = (l) => {
1
+ var B = Object.defineProperty;
2
+ var x = (p, e, t) => e in p ? B(p, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : p[e] = t;
3
+ var n = (p, e, t) => (x(p, typeof e != "symbol" ? e + "" : e, t), t);
4
+ var M = (p, e, t) => new Promise((l, o) => {
5
+ var s = (d) => {
6
6
  try {
7
- p(s.next(l));
7
+ y(t.next(d));
8
8
  } catch (F) {
9
- h(F);
9
+ o(F);
10
10
  }
11
- }, k = (l) => {
11
+ }, I = (d) => {
12
12
  try {
13
- p(s.throw(l));
13
+ y(t.throw(d));
14
14
  } catch (F) {
15
- h(F);
15
+ o(F);
16
16
  }
17
- }, p = (l) => l.done ? y(l.value) : Promise.resolve(l.value).then(r, k);
18
- p((s = s.apply(u, e)).next());
17
+ }, y = (d) => d.done ? l(d.value) : Promise.resolve(d.value).then(s, I);
18
+ y((t = t.apply(p, e)).next());
19
19
  });
20
- import * as t from "three";
21
- import { DigitalStateMachine as S } from "./DigitalStateMachine.js";
22
- import { Trace as L } from "./Trace.js";
23
- const B = 300;
24
- class O {
25
- constructor(e, s) {
20
+ import * as i from "three";
21
+ import { DigitalStateMachine as L } from "./DigitalStateMachine.js";
22
+ import { Trace as S } from "./Trace.js";
23
+ const q = 300;
24
+ class D {
25
+ constructor(e, t) {
26
26
  n(this, "model");
27
27
  n(this, "keyframesManager");
28
28
  n(this, "keyframes");
29
29
  n(this, "items");
30
30
  n(this, "effects");
31
31
  n(this, "digitalPlayground");
32
- n(this, "mixer");
33
- n(this, "action");
34
32
  n(this, "state");
35
33
  n(this, "animationFrameId");
36
- n(this, "itemMatrixMap");
37
- n(this, "trace");
38
34
  n(this, "curveLine");
39
35
  n(this, "effectsGroup");
40
36
  n(this, "effectObjects");
41
37
  n(this, "container");
38
+ n(this, "mixer");
39
+ n(this, "action");
40
+ n(this, "itemMatrixMap");
41
+ n(this, "trace");
42
42
  // 用于跟踪已处理的needRender keyframeIndex
43
43
  n(this, "processedNeedRenderKeyframeIndices", /* @__PURE__ */ new Set());
44
- this.model = e, this.model.visible = !1, this.model.mixer = null, this.mixer = new t.AnimationMixer(this.model), this.action = null, this.keyframesManager = new S(), this.keyframes = [], this.items = [], this.effects = [], this.digitalPlayground = s, this.state = {
44
+ // 跟踪已绑定到骨骼的 keyframe 道具(key: itemKey, value: item object)
45
+ n(this, "attachedItems", /* @__PURE__ */ new Map());
46
+ // 缓存 RightHand 骨骼
47
+ n(this, "rightHandBone", null);
48
+ this.model = e, this.model.visible = !1, this.model.mixer = null, this.mixer = new i.AnimationMixer(this.model), this.action = null, this.keyframesManager = new L(), this.keyframes = [], this.items = [], this.effects = [], this.digitalPlayground = t, this.state = {
45
49
  currentTime: 0,
46
50
  currentAnimation: null,
51
+ currentAnimationRepeat: !1,
47
52
  playing: !1
48
- }, this.animationFrameId = null, this.itemMatrixMap = /* @__PURE__ */ new Map(), this.trace = new L(), this.curveLine = new t.Line(), this.curveLine.material = new t.LineBasicMaterial({ color: 14467195, linewidth: 5 }), this.effectsGroup = new t.Group(), this.effectObjects = /* @__PURE__ */ new Map(), this.container = new t.Group(), this.container.add(this.model), this.container.add(this.curveLine), this.container.add(this.effectsGroup);
53
+ }, this.animationFrameId = null, this.itemMatrixMap = /* @__PURE__ */ new Map(), this.trace = new S(), this.curveLine = new i.Line(), this.curveLine.material = new i.LineBasicMaterial({ color: 14467195, linewidth: 5 }), this.effectsGroup = new i.Group(), this.effectObjects = /* @__PURE__ */ new Map(), this.container = new i.Group(), this.container.add(this.model), this.container.add(this.curveLine), this.container.add(this.effectsGroup);
49
54
  }
50
- playAnimation(e, s, y) {
51
- const h = this.action, r = this.mixer.clipAction(e);
52
- r.reset(), s || (r.setLoop(t.LoopOnce, 1), r.clampWhenFinished = !0), h && (r.enabled = !0, r.setEffectiveTimeScale(1), r.crossFadeFrom(h, y / 1e3, !0)), r.play(), h && h !== r && setTimeout(() => {
53
- h.stop();
54
- }, y), this.action = r;
55
+ playAnimation({ animation: e, repeat: t, switchDuration: l }) {
56
+ const o = this.action, s = this.mixer.clipAction(e);
57
+ s.reset(), t ? (s.setLoop(i.LoopRepeat, 1 / 0), s.clampWhenFinished = !1) : (s.setLoop(i.LoopOnce, 1), s.clampWhenFinished = !0), o && (s.enabled = !0, s.setEffectiveTimeScale(1), s.crossFadeFrom(o, l / 1e3, !0)), s.play(), o && o !== s && setTimeout(() => {
58
+ o.stop();
59
+ }, l), this.action = s;
55
60
  }
56
61
  pauseAnimation() {
57
62
  this.action && (this.action.paused = !0), this.animationFrameId && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null), this.state.playing = !1;
@@ -65,93 +70,86 @@ class O {
65
70
  attachItem() {
66
71
  }
67
72
  init() {
68
- this.state.currentTime = 0, this.model.position.copy(new t.Vector3().fromArray(this.keyframes[0].position)), this.model.quaternion.copy(new t.Quaternion().fromArray(this.keyframes[0].quaternion)), this.model.visible = this.keyframes[0].visible;
73
+ this.state.currentTime = 0, this.model.position.copy(new i.Vector3().fromArray(this.keyframes[0].position)), this.model.quaternion.copy(new i.Quaternion().fromArray(this.keyframes[0].quaternion)), this.model.visible = this.keyframes[0].visible;
69
74
  }
70
75
  reset() {
71
- this.state.currentTime = 0, this.keyframes && this.keyframes.length > 0 && (this.model.position.copy(new t.Vector3().fromArray(this.keyframes[0].position)), this.model.quaternion.copy(new t.Quaternion().fromArray(this.keyframes[0].quaternion))), this.model.visible = !1, this.container.visible = !1, this.animationFrameId && cancelAnimationFrame(this.animationFrameId), this.stopAnimation(), this.clearTrace(), this.state.playing = !1;
76
+ this.state.currentTime = 0, this.keyframes && this.keyframes.length > 0 && (this.model.position.copy(new i.Vector3().fromArray(this.keyframes[0].position)), this.model.quaternion.copy(new i.Quaternion().fromArray(this.keyframes[0].quaternion))), this.model.visible = !1, this.container.visible = !1, this.animationFrameId && cancelAnimationFrame(this.animationFrameId), this.stopAnimation(), this.clearTrace(), this.detachAllKeyframeItems(), this.state.playing = !1;
72
77
  }
73
78
  play(e) {
74
79
  return M(this, null, function* () {
75
80
  this.clearProcessedNeedRenderKeyframeIndices();
76
- const { keyframes: s, items: y, effects: h } = e || {};
77
- return this.keyframes = s || this.keyframes, this.items = y || this.items, this.effects = h || this.effects, this.state.currentAnimation = null, this.state.playing = !0, new Promise((r, k) => {
81
+ const { keyframes: t, items: l, effects: o } = e || {};
82
+ return this.keyframes = t || this.keyframes, this.items = l || this.items, this.effects = o || this.effects, this.state.currentAnimation = null, this.state.currentAnimationRepeat = !1, this.state.playing = !0, new Promise((s, I) => {
78
83
  this.state.currentTime || this.init();
79
- let p = null;
80
- for (let m = 0; m < this.items.length; m++) {
81
- const c = this.digitalPlayground.getDigitalItem(this.items[m].model);
82
- if (c) {
83
- let i = null;
84
- const d = this.model.children[0].children.find((f) => f instanceof t.Bone), A = this.model.children[0].children.find((f) => f instanceof t.SkinnedMesh);
85
- if (!d || !A)
84
+ let y = null;
85
+ for (let c = 0; c < this.items.length; c++) {
86
+ const h = this.digitalPlayground.getDigitalItem(this.items[c].model);
87
+ if (h) {
88
+ let a = null;
89
+ const u = this.model.children[0].children.find((f) => f instanceof i.Bone), g = this.model.children[0].children.find((f) => f instanceof i.SkinnedMesh);
90
+ if (!u || !g)
86
91
  throw new Error("模型骨骼缺失");
87
92
  if (this.model.children[0].children[2].traverse((f) => {
88
- f instanceof t.Bone && f.name === "RightHand" && (i = f);
89
- }), !i)
93
+ f instanceof i.Bone && f.name === "RightHand" && (a = f);
94
+ }), !a)
90
95
  throw new Error("没有找到绑定的骨骼");
91
- i.add(c);
92
- const a = new t.Vector3(), o = new t.Quaternion(), g = new t.Vector3();
93
- new t.Matrix4().fromArray(this.items[m].initialMatrix).decompose(a, o, g), c.position.copy(a), c.quaternion.copy(o), c.scale.copy(g), c.updateMatrixWorld(!0);
96
+ a.add(h);
97
+ const w = new i.Vector3(), r = new i.Quaternion(), m = new i.Vector3();
98
+ new i.Matrix4().fromArray(this.items[c].initialMatrix).decompose(w, r, m), h.position.copy(w), h.quaternion.copy(r), h.scale.copy(m), h.updateMatrixWorld(!0);
94
99
  }
95
100
  }
96
- const l = /* @__PURE__ */ new Map(), F = new t.TextureLoader();
97
- for (let m = 0; m < this.effects.length; m++) {
98
- const c = this.effects[m];
99
- if (c.type === "frameSequence") {
100
- const i = c.keyframes;
101
- for (let d = 0; d < i.length; d++)
102
- F.load(i[d].image, (A) => {
103
- A.name = i[d].image, l.set(i[d].image, A);
101
+ const d = /* @__PURE__ */ new Map(), F = new i.TextureLoader();
102
+ for (let c = 0; c < this.effects.length; c++) {
103
+ const h = this.effects[c];
104
+ if (h.type === "frameSequence") {
105
+ const a = h.keyframes;
106
+ for (let u = 0; u < a.length; u++)
107
+ F.load(a[u].image, (g) => {
108
+ g.name = a[u].image, d.set(a[u].image, g);
104
109
  });
105
110
  }
106
111
  }
107
- const T = (m) => {
108
- var A;
109
- p === null && (p = m);
110
- const c = m - p;
111
- p = m, this.state.currentTime += c;
112
- const i = this.keyframesManager.getStateByTime(this.state.currentTime, this.keyframes, "model");
113
- this.trace.addPoint(i.translation);
114
- const d = new t.BufferGeometry().setFromPoints(this.trace.tracePoints);
115
- if (this.curveLine.geometry = d, this.model.position.copy(i.translation), this.model.quaternion.copy(i.quaternion), this.model.scale.copy(i.scale), this.model.visible = i.visible, i.isFinal) {
116
- this.model.visible = !1, this.container.visible = !1, this.stopAnimation(), this.model.needsRender = !0, r(!0), this.animationFrameId !== null && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null);
112
+ const v = (c) => {
113
+ var g, w;
114
+ y === null && (y = c);
115
+ const h = c - y;
116
+ y = c, this.state.currentTime += h;
117
+ const a = this.keyframesManager.getStateByTime(this.state.currentTime, this.keyframes, "model");
118
+ this.trace.addPoint(a.translation);
119
+ const u = new i.BufferGeometry().setFromPoints(this.trace.tracePoints);
120
+ if (this.curveLine.geometry = u, this.model.position.copy(a.translation), this.model.quaternion.copy(a.quaternion), this.model.scale.copy(a.scale), this.model.visible = a.visible, a.isFinal) {
121
+ this.model.visible = !1, this.container.visible = !1, this.stopAnimation(), this.model.needsRender = !0, s(!0), this.animationFrameId !== null && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null);
117
122
  return;
118
- } else if (i.animation) {
119
- const a = this.digitalPlayground.getAnimation(i.animation.url), o = i.animation.needRender;
120
- (a !== this.state.currentAnimation || o && !this.hasProcessedNeedRenderForTimestamp(i.keyframeIndex)) && (o && a === this.state.currentAnimation && this.markNeedRenderProcessedForTimestamp(i.keyframeIndex), this.state.currentAnimation = a, this.playAnimation(
121
- a,
122
- i.animation.repeat,
123
- (A = i.animation.switchDuration) != null ? A : B
124
- )), this.mixer.update(c / 1e3), i.animation.isOver === !0 && (this.action.paused = !0, this.action.time = this.state.currentAnimation.duration, this.mixer.update(0));
123
+ } else if (a.animation) {
124
+ const r = this.digitalPlayground.getAnimation(a.animation.url), m = a.animation.needRender, A = a.animation.repeat !== this.state.currentAnimationRepeat;
125
+ (r !== this.state.currentAnimation || A || m && !this.hasProcessedNeedRenderForTimestamp(a.keyframeIndex)) && (m && r === this.state.currentAnimation && this.markNeedRenderProcessedForTimestamp(a.keyframeIndex), this.state.currentAnimation = r, this.state.currentAnimationRepeat = a.animation.repeat, this.playAnimation({
126
+ animation: r,
127
+ repeat: a.animation.repeat,
128
+ switchDuration: (g = a.animation.switchDuration) != null ? g : q
129
+ })), this.mixer.update(h / 1e3), a.animation.isOver === !0 && (this.action.paused = !0, this.action.time = this.state.currentAnimation.duration, this.mixer.update(0));
125
130
  }
126
- for (let a = 0; a < this.items.length; a++) {
127
- const o = this.digitalPlayground.getDigitalItem(this.items[a].model);
128
- o && (this.keyframesManager.getStateByTime(
129
- this.state.currentTime,
130
- this.items[a].keyframes,
131
- "item"
132
- ).visible === !0 ? o.visible = !0 : o.visible = !1);
131
+ this.updateKeyframeItems((w = a.animation) == null ? void 0 : w.item);
132
+ for (let r = 0; r < this.items.length; r++) {
133
+ const m = this.digitalPlayground.getDigitalItem(this.items[r].model);
134
+ m && (this.keyframesManager.getStateByTime(this.state.currentTime, this.items[r].keyframes, "item").visible === !0 ? m.visible = !0 : m.visible = !1);
133
135
  }
134
- for (let a = 0; a < this.effects.length; a++) {
135
- const o = this.effects[a];
136
- if (o.type === "frameSequence") {
137
- const g = o.type + a;
138
- if (!this.effectObjects.has(g)) {
139
- const P = new t.PlaneGeometry(1, 1), b = new t.MeshBasicMaterial({
136
+ for (let r = 0; r < this.effects.length; r++) {
137
+ const m = this.effects[r];
138
+ if (m.type === "frameSequence") {
139
+ const A = m.type + r;
140
+ if (!this.effectObjects.has(A)) {
141
+ const R = new i.PlaneGeometry(1, 1), b = new i.MeshBasicMaterial({
140
142
  transparent: !0
141
- }), w = new t.Mesh(P, b);
142
- w.rotateX(-Math.PI / 2), w.position.copy(new t.Vector3().fromArray(o.position)), this.effectObjects.set(g, w), this.effectsGroup.add(w);
143
+ }), k = new i.Mesh(R, b);
144
+ k.rotateX(-Math.PI / 2), k.position.copy(new i.Vector3().fromArray(m.position)), this.effectObjects.set(A, k), this.effectsGroup.add(k);
143
145
  }
144
- const I = this.effectObjects.get(g), f = this.keyframesManager.getStateByTime(
145
- this.state.currentTime,
146
- this.effects[a].keyframes,
147
- "effect"
148
- ), v = l.get(f.image);
149
- I.material.map = v, I.visible = f.visible;
146
+ const f = this.effectObjects.get(A), T = this.keyframesManager.getStateByTime(this.state.currentTime, this.effects[r].keyframes, "effect"), P = d.get(T.image);
147
+ f.material.map = P, f.visible = T.visible;
150
148
  }
151
149
  }
152
- this.model.needsRender = !0, this.animationFrameId = requestAnimationFrame(T);
150
+ this.model.needsRender = !0, this.animationFrameId = requestAnimationFrame(v);
153
151
  };
154
- this.animationFrameId && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null), this.animationFrameId = requestAnimationFrame(T);
152
+ this.animationFrameId && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null), this.animationFrameId = requestAnimationFrame(v);
155
153
  });
156
154
  });
157
155
  }
@@ -159,18 +157,22 @@ class O {
159
157
  traceUpDate() {
160
158
  this.trace.clear();
161
159
  for (let e = 0; e <= this.state.currentTime; e += 100) {
162
- const s = this.keyframesManager.getStateByTime(e, this.keyframes, "model");
163
- this.trace.addPoint(s.translation);
164
- const y = new t.BufferGeometry().setFromPoints(this.trace.tracePoints);
165
- this.curveLine.geometry = y;
160
+ const t = this.keyframesManager.getStateByTime(e, this.keyframes, "model");
161
+ this.trace.addPoint(t.translation);
162
+ const l = new i.BufferGeometry().setFromPoints(this.trace.tracePoints);
163
+ this.curveLine.geometry = l;
166
164
  }
167
165
  }
168
166
  // 清楚轨迹
169
167
  clearTrace() {
170
168
  this.trace.clear();
171
- const e = new t.BufferGeometry().setFromPoints(this.trace.tracePoints);
169
+ const e = new i.BufferGeometry().setFromPoints(this.trace.tracePoints);
172
170
  this.curveLine.geometry = e;
173
171
  }
172
+ // 清理已处理的keyframeIndex记录(可选,在适当的时候调用)
173
+ clearProcessedNeedRenderKeyframeIndices() {
174
+ this.processedNeedRenderKeyframeIndices.clear();
175
+ }
174
176
  // 检查指定keyframeIndex的needRender是否已经处理过
175
177
  hasProcessedNeedRenderForTimestamp(e) {
176
178
  return this.processedNeedRenderKeyframeIndices.has(e);
@@ -179,11 +181,35 @@ class O {
179
181
  markNeedRenderProcessedForTimestamp(e) {
180
182
  this.processedNeedRenderKeyframeIndices.add(e);
181
183
  }
182
- // 清理已处理的keyframeIndex记录(可选,在适当的时候调用)
183
- clearProcessedNeedRenderKeyframeIndices() {
184
- this.processedNeedRenderKeyframeIndices.clear();
184
+ // 获取并缓存 RightHand 骨骼
185
+ getRightHandBone() {
186
+ var e;
187
+ return this.rightHandBone ? this.rightHandBone : ((e = this.model.children[0].children.find((t) => t instanceof i.Bone)) == null || e.traverse((t) => {
188
+ t instanceof i.Bone && t.name === "RightHand" && (this.rightHandBone = t);
189
+ }), this.rightHandBone);
190
+ }
191
+ // 根据当前帧的 items 动态绑定/解绑道具
192
+ updateKeyframeItems(e) {
193
+ var o;
194
+ const t = (e == null ? void 0 : e.url) || null;
195
+ for (const [s, I] of this.attachedItems)
196
+ t !== s && ((o = I.parent) == null || o.remove(I), this.attachedItems.delete(s));
197
+ if (!t)
198
+ return;
199
+ const l = this.getRightHandBone();
200
+ if (l && !this.attachedItems.has(t)) {
201
+ const s = this.digitalPlayground.getDigitalItem(t);
202
+ s && (l.add(s), this.attachedItems.set(t, s));
203
+ }
204
+ }
205
+ // 解绑所有 keyframe 道具
206
+ detachAllKeyframeItems() {
207
+ var e;
208
+ for (const [, t] of this.attachedItems)
209
+ (e = t.parent) == null || e.remove(t);
210
+ this.attachedItems.clear();
185
211
  }
186
212
  }
187
213
  export {
188
- O as DigitalHuman
214
+ D as DigitalHuman
189
215
  };
@@ -4,14 +4,13 @@ import { DigitalHuman } from './DigitalHuman';
4
4
  import type { DigitalScript, DigitalChapter } from './DigitalStateMachine';
5
5
  export declare class DigitalPlayground {
6
6
  gltfLoader: GLTFLoader;
7
+ script: DigitalScript | null;
8
+ currentChapter: DigitalChapter | null;
7
9
  private digitalHumanMap;
8
10
  private digitalItemMap;
9
11
  private skeletalAnimationMap;
10
- script: DigitalScript | null;
11
- currentChapter: DigitalChapter | null;
12
12
  private debugMode;
13
13
  constructor(debugMode?: boolean);
14
- private loadGLTF;
15
14
  setScript(script: DigitalScript): void;
16
15
  loadModel(url: string, id?: string): Promise<DigitalHuman>;
17
16
  loadModels(urls: string[], ids?: string[]): Promise<DigitalHuman[]>;
@@ -20,8 +19,14 @@ export declare class DigitalPlayground {
20
19
  getAnimation(url: string): THREE.AnimationClip | null;
21
20
  getDigitalHuman(url: string, id?: string): DigitalHuman | null;
22
21
  playByChapter(chapter: DigitalChapter): Promise<any[]>;
23
- loadItems(urls: string[]): Promise<any[]>;
24
- loadItem(url: string): Promise<any>;
22
+ loadItems(urls: string[], offsets?: Map<string, {
23
+ position: number[];
24
+ rotation: number[];
25
+ }>): Promise<any[]>;
26
+ loadItem(url: string, offset?: {
27
+ position: number[];
28
+ rotation: number[];
29
+ }): Promise<any>;
25
30
  getDigitalItem(url: string): any | null;
26
31
  pause(): void;
27
32
  continue(): void;
@@ -31,4 +36,5 @@ export declare class DigitalPlayground {
31
36
  * 销毁 playground
32
37
  */
33
38
  dispose(): void;
39
+ private loadGLTF;
34
40
  }
@@ -1,127 +1,131 @@
1
- var d = Object.defineProperty;
2
- var c = (o, t, e) => t in o ? d(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e;
3
- var m = (o, t, e) => (c(o, typeof t != "symbol" ? t + "" : t, e), e);
4
- var h = (o, t, e) => new Promise((a, i) => {
5
- var s = (l) => {
1
+ var g = Object.defineProperty;
2
+ var u = (o, t, i) => t in o ? g(o, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : o[t] = i;
3
+ var m = (o, t, i) => (u(o, typeof t != "symbol" ? t + "" : t, i), i);
4
+ var p = (o, t, i) => new Promise((e, a) => {
5
+ var r = (l) => {
6
6
  try {
7
- n(e.next(l));
8
- } catch (p) {
9
- i(p);
7
+ s(i.next(l));
8
+ } catch (h) {
9
+ a(h);
10
10
  }
11
- }, r = (l) => {
11
+ }, n = (l) => {
12
12
  try {
13
- n(e.throw(l));
14
- } catch (p) {
15
- i(p);
13
+ s(i.throw(l));
14
+ } catch (h) {
15
+ a(h);
16
16
  }
17
- }, n = (l) => l.done ? a(l.value) : Promise.resolve(l.value).then(s, r);
18
- n((e = e.apply(o, t)).next());
17
+ }, s = (l) => l.done ? e(l.value) : Promise.resolve(l.value).then(r, n);
18
+ s((i = i.apply(o, t)).next());
19
19
  });
20
- import { GLTFLoader as g } from "@realsee/five/gltf-loader";
21
- import { DigitalHuman as u } from "./DigitalHuman.js";
22
- import { loadGltf as M } from "@realsee/five";
23
- import "three";
20
+ import * as d from "three";
21
+ import { GLTFLoader as M } from "@realsee/five/gltf-loader";
22
+ import { DigitalHuman as y } from "./DigitalHuman.js";
23
+ import { loadGltf as A } from "@realsee/five";
24
24
  import "./DigitalStateMachine.js";
25
25
  import "./Trace.js";
26
- class w {
26
+ class T {
27
27
  constructor(t = !1) {
28
28
  m(this, "gltfLoader");
29
+ m(this, "script");
30
+ m(this, "currentChapter");
29
31
  m(this, "digitalHumanMap");
30
32
  m(this, "digitalItemMap");
31
33
  m(this, "skeletalAnimationMap");
32
- m(this, "script");
33
- m(this, "currentChapter");
34
34
  m(this, "debugMode");
35
- this.gltfLoader = new g(), this.digitalHumanMap = /* @__PURE__ */ new Map(), this.digitalItemMap = /* @__PURE__ */ new Map(), this.skeletalAnimationMap = /* @__PURE__ */ new Map(), this.script = null, this.currentChapter = null, this.debugMode = t;
36
- }
37
- loadGLTF(t) {
38
- return M(t).then((e) => {
39
- const a = e == null ? void 0 : e.upAxis;
40
- return e && a === "Z" && e.scene && (e.scene.rotateX(-Math.PI / 2), e.scene.updateMatrixWorld(!0)), e;
41
- });
35
+ this.gltfLoader = new M(), this.digitalHumanMap = /* @__PURE__ */ new Map(), this.digitalItemMap = /* @__PURE__ */ new Map(), this.skeletalAnimationMap = /* @__PURE__ */ new Map(), this.script = null, this.currentChapter = null, this.debugMode = t;
42
36
  }
43
37
  setScript(t) {
44
38
  this.script = t;
45
39
  }
46
- loadModel(t, e) {
47
- return h(this, null, function* () {
48
- const a = e ? `${t}_${e}` : t;
49
- if (this.digitalHumanMap.has(a)) {
50
- const i = this.digitalHumanMap.get(a);
51
- return Promise.resolve(i);
40
+ loadModel(t, i) {
41
+ return p(this, null, function* () {
42
+ const e = i ? `${t}_${i}` : t;
43
+ if (this.digitalHumanMap.has(e)) {
44
+ const a = this.digitalHumanMap.get(e);
45
+ return Promise.resolve(a);
52
46
  } else
53
- return new Promise((i, s) => {
54
- t.endsWith(".gltf") || t.endsWith(".glb") ? this.loadGLTF(t).then((r) => {
55
- const n = r.scene, l = new u(n, this);
56
- this.digitalHumanMap.set(a, l), i(l);
57
- }) : s(new Error("不支持的模型格式"));
47
+ return new Promise((a, r) => {
48
+ t.endsWith(".gltf") || t.endsWith(".glb") ? this.loadGLTF(t).then((n) => {
49
+ const s = n.scene, l = new y(s, this);
50
+ this.digitalHumanMap.set(e, l), a(l);
51
+ }) : r(new Error("不支持的模型格式"));
58
52
  });
59
53
  });
60
54
  }
61
- loadModels(t, e) {
62
- return h(this, null, function* () {
63
- return e && e.length === t.length ? Promise.all(t.map((a, i) => this.loadModel(a, e[i]))) : Promise.all(t.map((a) => this.loadModel(a)));
55
+ loadModels(t, i) {
56
+ return p(this, null, function* () {
57
+ return i && i.length === t.length ? Promise.all(t.map((e, a) => this.loadModel(e, i[a]))) : Promise.all(t.map((e) => this.loadModel(e)));
64
58
  });
65
59
  }
66
60
  // 加载骨骼动画,暂且认为一个glb只包含一个骨骼动画
67
61
  loadAnimation(t) {
68
- return h(this, null, function* () {
62
+ return p(this, null, function* () {
69
63
  if (this.skeletalAnimationMap.has(t)) {
70
- const e = this.skeletalAnimationMap.get(t);
71
- return Promise.resolve(e);
64
+ const i = this.skeletalAnimationMap.get(t);
65
+ return Promise.resolve(i);
72
66
  } else
73
- return new Promise((e, a) => {
74
- this.loadGLTF(t).then((i) => {
75
- const r = i.animations[0];
76
- this.skeletalAnimationMap.set(t, r), e(r);
67
+ return new Promise((i, e) => {
68
+ this.loadGLTF(t).then((a) => {
69
+ const n = a.animations[0];
70
+ this.skeletalAnimationMap.set(t, n), i(n);
77
71
  });
78
72
  });
79
73
  });
80
74
  }
81
75
  loadAnimations(t) {
82
- return h(this, null, function* () {
83
- return Promise.all(t.map((e) => this.loadAnimation(e)));
76
+ return p(this, null, function* () {
77
+ return Promise.all(t.map((i) => this.loadAnimation(i)));
84
78
  });
85
79
  }
86
80
  getAnimation(t) {
87
81
  return this.skeletalAnimationMap.get(t) || null;
88
82
  }
89
- getDigitalHuman(t, e) {
90
- const a = e ? `${t}_${e}` : t;
91
- return this.digitalHumanMap.get(a) || null;
83
+ getDigitalHuman(t, i) {
84
+ const e = i ? `${t}_${i}` : t;
85
+ return this.digitalHumanMap.get(e) || null;
92
86
  }
93
87
  playByChapter(t) {
94
- return h(this, null, function* () {
88
+ return p(this, null, function* () {
95
89
  if (!t || !Array.isArray(t.players))
96
90
  throw new Error("Invalid chapter: chapter or chapter.players is undefined");
97
91
  this.currentChapter = t;
98
- const e = t.players.filter((i) => i.type === "model");
99
- this.digitalHumanMap.forEach((i) => {
100
- i.model.visible = !1, i.container.visible = !1;
92
+ const i = t.players.filter((a) => a.type === "model");
93
+ this.digitalHumanMap.forEach((a) => {
94
+ a.model.visible = !1, a.container.visible = !1;
101
95
  });
102
- const a = [];
103
- for (let i = 0; i < e.length; i++) {
104
- const s = e[i], r = `${s.model}_${s.id}`, n = this.digitalHumanMap.get(r);
105
- n && (n.model.visible = !0, n.container.visible = !0, a.push(n.play({ keyframes: s.keyframes, items: [], effects: [] })));
96
+ const e = [];
97
+ for (let a = 0; a < i.length; a++) {
98
+ const r = i[a], n = `${r.model}_${r.id}`, s = this.digitalHumanMap.get(n);
99
+ s && (s.model.visible = !0, s.container.visible = !0, e.push(s.play({ keyframes: r.keyframes, items: [], effects: [] })));
106
100
  }
107
- return Promise.all(a);
101
+ return Promise.all(e);
108
102
  });
109
103
  }
110
- loadItems(t) {
111
- return h(this, null, function* () {
112
- return Promise.all(t.map((e) => this.loadItem(e)));
104
+ loadItems(t, i) {
105
+ return p(this, null, function* () {
106
+ return Promise.all(t.map((e) => this.loadItem(e, i == null ? void 0 : i.get(e))));
113
107
  });
114
108
  }
115
- loadItem(t) {
116
- return h(this, null, function* () {
109
+ loadItem(t, i) {
110
+ return p(this, null, function* () {
117
111
  if (this.digitalItemMap.has(t)) {
118
112
  const e = this.digitalItemMap.get(t);
119
113
  return Promise.resolve(e);
120
114
  } else
121
115
  return new Promise((e, a) => {
122
- t.endsWith(".gltf") || t.endsWith(".glb") ? this.loadGLTF(t).then((i) => {
123
- const s = i.scene;
124
- this.digitalItemMap.set(t, s), e(s);
116
+ t.endsWith(".gltf") || t.endsWith(".glb") ? this.loadGLTF(t).then((r) => {
117
+ const n = r.scene;
118
+ if (i && (i != null && i.position) && (i != null && i.rotation)) {
119
+ const [s, l, h] = i.position;
120
+ n.position.set(s * 0.01, -l * 0.01, -h * 0.01);
121
+ const c = new d.Euler(
122
+ d.MathUtils.degToRad(i.rotation[0]),
123
+ d.MathUtils.degToRad(i.rotation[1]),
124
+ d.MathUtils.degToRad(i.rotation[2])
125
+ );
126
+ n.quaternion.setFromEuler(c);
127
+ }
128
+ this.digitalItemMap.set(t, n), e(n);
125
129
  }) : a(new Error("不支持的模型格式"));
126
130
  });
127
131
  });
@@ -145,8 +149,8 @@ class w {
145
149
  });
146
150
  }
147
151
  setTimelineTo(t) {
148
- this.digitalHumanMap.forEach((e) => {
149
- e.state.currentTime = t;
152
+ this.digitalHumanMap.forEach((i) => {
153
+ i.state.currentTime = t;
150
154
  });
151
155
  }
152
156
  /**
@@ -157,7 +161,13 @@ class w {
157
161
  t.reset();
158
162
  }), this.digitalHumanMap.clear(), this.digitalItemMap.clear(), this.skeletalAnimationMap.clear();
159
163
  }
164
+ loadGLTF(t) {
165
+ return A(t).then((i) => {
166
+ const e = i == null ? void 0 : i.upAxis;
167
+ return i && e === "Z" && i.scene && (i.scene.rotateX(-Math.PI / 2), i.scene.updateMatrixWorld(!0)), i;
168
+ });
169
+ }
160
170
  }
161
171
  export {
162
- w as DigitalPlayground
172
+ T as DigitalPlayground
163
173
  };