@combeenation/3d-viewer 21.0.1 → 21.1.0-beta2

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.
Files changed (40) hide show
  1. package/dist/lib-cjs/buildinfo.json +1 -1
  2. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  3. package/dist/lib-cjs/internal/parameter/paintable-parameter-helper.d.ts +2 -2
  4. package/dist/lib-cjs/internal/parameter/paintable-parameter-helper.js +3 -2
  5. package/dist/lib-cjs/internal/parameter/paintable-parameter-helper.js.map +1 -1
  6. package/dist/lib-cjs/internal/parameter/parameter-helper.d.ts +2 -2
  7. package/dist/lib-cjs/internal/parameter/parameter-helper.js +9 -28
  8. package/dist/lib-cjs/internal/parameter/parameter-helper.js.map +1 -1
  9. package/dist/lib-cjs/internal/parameter/texture-parameter-helper.d.ts +2 -2
  10. package/dist/lib-cjs/internal/parameter/texture-parameter-helper.js +5 -5
  11. package/dist/lib-cjs/internal/parameter/texture-parameter-helper.js.map +1 -1
  12. package/dist/lib-cjs/internal/svg-helper.d.ts +5 -0
  13. package/dist/lib-cjs/internal/svg-helper.js +13 -2
  14. package/dist/lib-cjs/internal/svg-helper.js.map +1 -1
  15. package/dist/lib-cjs/manager/camera-manager.js +6 -6
  16. package/dist/lib-cjs/manager/camera-manager.js.map +1 -1
  17. package/dist/lib-cjs/manager/parameter-manager.d.ts +6 -4
  18. package/dist/lib-cjs/manager/parameter-manager.js +10 -9
  19. package/dist/lib-cjs/manager/parameter-manager.js.map +1 -1
  20. package/dist/lib-cjs/manager/scene-manager.js +8 -5
  21. package/dist/lib-cjs/manager/scene-manager.js.map +1 -1
  22. package/dist/lib-cjs/utils/viewer-utils.d.ts +24 -1
  23. package/dist/lib-cjs/utils/viewer-utils.js +63 -0
  24. package/dist/lib-cjs/utils/viewer-utils.js.map +1 -1
  25. package/dist/lib-cjs/viewer.js +1 -0
  26. package/dist/lib-cjs/viewer.js.map +1 -1
  27. package/package.json +1 -1
  28. package/src/internal/parameter/paintable-parameter-helper.ts +4 -3
  29. package/src/internal/parameter/parameter-helper.ts +15 -49
  30. package/src/internal/parameter/texture-parameter-helper.ts +7 -12
  31. package/src/internal/svg-helper.ts +13 -1
  32. package/src/manager/camera-manager.ts +3 -3
  33. package/src/manager/parameter-manager.ts +12 -12
  34. package/src/manager/scene-manager.ts +9 -5
  35. package/src/utils/viewer-utils.ts +75 -0
  36. package/src/viewer.ts +2 -0
  37. package/dist/lib-cjs/internal/animation-helper.d.ts +0 -2
  38. package/dist/lib-cjs/internal/animation-helper.js +0 -16
  39. package/dist/lib-cjs/internal/animation-helper.js.map +0 -1
  40. package/src/internal/animation-helper.ts +0 -18
@@ -1,4 +1,7 @@
1
1
  import {
2
+ Animation,
3
+ AnimationGroup,
4
+ Color3,
2
5
  FloatArray,
3
6
  Geometry,
4
7
  Mesh,
@@ -13,6 +16,8 @@ import {
13
16
  Viewer,
14
17
  } from '../index';
15
18
 
19
+ export type AnimatableProperties = 'albedoColor' | 'position' | 'rotation' | 'scaling' | 'influence';
20
+
16
21
  export type BakeGeometrySettings = {
17
22
  keepTransformation?: boolean;
18
23
  };
@@ -165,6 +170,76 @@ export class ViewerUtils {
165
170
  return this.findParentNode(parent, criteria);
166
171
  }
167
172
  }
173
+
174
+ /**
175
+ * Animates a single property of a target object from its current value to a given target value.\
176
+ * Supported property types are defined by {@link AnimatableProperties} (i.e. `number`, `Vector3`, `Color3`).
177
+ *
178
+ * @param target The object whose property should be animated
179
+ * @param property The name of the property to animate. Must be a key of `target` whose value type is supported.
180
+ * @param value The target value the property should reach at the end of the animation.
181
+ * @param animationName Name given to the internally created animation group.\
182
+ * Use a stable, unique name per animated property so that concurrent calls can be
183
+ * identified (e.g. `"$parameterAnimation.position.MyNode"`).
184
+ * @param animationTimeMs Duration of the animation in milliseconds.
185
+ */
186
+ public async animateProperty<T, K extends Extract<keyof T, AnimatableProperties>>(
187
+ target: T,
188
+ property: K,
189
+ value: T[K],
190
+ animationName: string,
191
+ animationTimeMs: number
192
+ ): Promise<void> {
193
+ const framesPerSec = 100;
194
+ // extend if further `AnimatableProperties` with different types are added
195
+ const dataType =
196
+ value instanceof Vector3
197
+ ? Animation.ANIMATIONTYPE_VECTOR3
198
+ : value instanceof Color3
199
+ ? Animation.ANIMATIONTYPE_COLOR3
200
+ : Animation.ANIMATIONTYPE_FLOAT;
201
+
202
+ const animationGroup = new AnimationGroup(animationName);
203
+
204
+ const animation = new Animation(property, property, framesPerSec, dataType);
205
+ animation.setKeys([
206
+ { frame: 0, value: target[property] },
207
+ { frame: framesPerSec, value: value },
208
+ ]);
209
+ animationGroup.addTargetedAnimation(animation, target);
210
+
211
+ await this.playAnimationGroupOnce(animationGroup, framesPerSec, Math.max(animationTimeMs, 0));
212
+ }
213
+
214
+ /**
215
+ * Plays an animation group exactly in a certain duration, then disposes it.
216
+ *
217
+ * The animation group is expected to span exactly `framesPerSec` frames (i.e. one "logical second").\
218
+ * The speed ratio is derived from that assumption: `speedRatio = 1000 / durationMs`.
219
+ *
220
+ * Due to this strict convention, the method is marked as @internal and should not be used directly by a consumer.
221
+ */
222
+ public playAnimationGroupOnce(
223
+ animationGroup: AnimationGroup,
224
+ framesPerSec: number,
225
+ durationMs: number
226
+ ): Promise<void> {
227
+ if (durationMs <= 0) {
228
+ animationGroup.dispose();
229
+ return Promise.resolve();
230
+ }
231
+
232
+ // animation is created for 1 second (100 frames), adjust speed ratio according to desired movement time
233
+ const speedRatio = 1000 / durationMs;
234
+
235
+ return new Promise<void>(resolve => {
236
+ animationGroup.onAnimationGroupEndObservable.addOnce(() => {
237
+ animationGroup.dispose();
238
+ resolve();
239
+ });
240
+ animationGroup.start(false, speedRatio, 0, framesPerSec);
241
+ });
242
+ }
168
243
  }
169
244
 
170
245
  /**
package/src/viewer.ts CHANGED
@@ -301,6 +301,8 @@ export class Viewer {
301
301
  // call would already throw
302
302
  this._sceneManager.applyDefaultSettingsToScene();
303
303
 
304
+ this._parameterManager.addBuiltInParameterObservers();
305
+
304
306
  this._debugManager.registerAutofocusStartListener();
305
307
 
306
308
  engine.runRenderLoop(() => {
@@ -1,2 +0,0 @@
1
- import { AnimationGroup } from '../index';
2
- export declare function playAnimationGroupOnce(animationGroup: AnimationGroup, framesPerSec: number, durationMs: number): Promise<void>;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.playAnimationGroupOnce = void 0;
4
- function playAnimationGroupOnce(animationGroup, framesPerSec, durationMs) {
5
- // animation is created for 1 second (100 frames), adjust speed ratio according to desired movement time
6
- const speedRatio = 1000 / durationMs;
7
- return new Promise(resolve => {
8
- animationGroup.onAnimationGroupEndObservable.addOnce(() => {
9
- animationGroup.dispose();
10
- resolve();
11
- });
12
- animationGroup.start(false, speedRatio, 0, framesPerSec);
13
- });
14
- }
15
- exports.playAnimationGroupOnce = playAnimationGroupOnce;
16
- //# sourceMappingURL=animation-helper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"animation-helper.js","sourceRoot":"","sources":["../../../src/internal/animation-helper.ts"],"names":[],"mappings":";;;AAEA,SAAgB,sBAAsB,CACpC,cAA8B,EAC9B,YAAoB,EACpB,UAAkB;IAElB,wGAAwG;IACxG,MAAM,UAAU,GAAG,IAAI,GAAG,UAAU,CAAC;IAErC,OAAO,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE;QACjC,cAAc,CAAC,6BAA6B,CAAC,OAAO,CAAC,GAAG,EAAE;YACxD,cAAc,CAAC,OAAO,EAAE,CAAC;YACzB,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;QACH,cAAc,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC;AAfD,wDAeC"}
@@ -1,18 +0,0 @@
1
- import { AnimationGroup } from '../index';
2
-
3
- export function playAnimationGroupOnce(
4
- animationGroup: AnimationGroup,
5
- framesPerSec: number,
6
- durationMs: number
7
- ): Promise<void> {
8
- // animation is created for 1 second (100 frames), adjust speed ratio according to desired movement time
9
- const speedRatio = 1000 / durationMs;
10
-
11
- return new Promise<void>(resolve => {
12
- animationGroup.onAnimationGroupEndObservable.addOnce(() => {
13
- animationGroup.dispose();
14
- resolve();
15
- });
16
- animationGroup.start(false, speedRatio, 0, framesPerSec);
17
- });
18
- }