minerender 2.1.0-alpha.139 → 2.1.0-alpha.140

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.
@@ -3493,8 +3493,17 @@ interface SceneEntityDefinition extends SceneObjectDefinitionBase {
3493
3493
  wireframe?: boolean;
3494
3494
  tints?: Record<string, string | number>;
3495
3495
  };
3496
- animation?: {
3496
+ /** Plays one named clip or blends clips with weights defaulting to 1, without normalization. */
3497
+ animation?: ({
3497
3498
  name: string;
3499
+ clips?: never;
3500
+ } | {
3501
+ name?: never;
3502
+ clips: {
3503
+ name: string;
3504
+ weight?: number;
3505
+ }[];
3506
+ }) & {
3498
3507
  loop?: boolean;
3499
3508
  speed?: number;
3500
3509
  time?: number;
@@ -3493,8 +3493,17 @@ interface SceneEntityDefinition extends SceneObjectDefinitionBase {
3493
3493
  wireframe?: boolean;
3494
3494
  tints?: Record<string, string | number>;
3495
3495
  };
3496
- animation?: {
3496
+ /** Plays one named clip or blends clips with weights defaulting to 1, without normalization. */
3497
+ animation?: ({
3497
3498
  name: string;
3499
+ clips?: never;
3500
+ } | {
3501
+ name?: never;
3502
+ clips: {
3503
+ name: string;
3504
+ weight?: number;
3505
+ }[];
3506
+ }) & {
3498
3507
  loop?: boolean;
3499
3508
  speed?: number;
3500
3509
  time?: number;
@@ -16766,6 +16766,23 @@ var itemContext = (withDisplayContext) => (value, path) => {
16766
16766
  }
16767
16767
  });
16768
16768
  };
16769
+ function entityAnimation(value, path) {
16770
+ const animation = object3(value, path);
16771
+ if (["name", "clips"].filter((key) => animation[key] !== void 0).length !== 1) {
16772
+ fail(path, "expected exactly one of name or clips");
16773
+ }
16774
+ fields(value, path, { name: text, clips: (value2, path2) => {
16775
+ list((value3, path3) => {
16776
+ fields(value3, path3, { name: text, weight: nonnegative }, ["name"]);
16777
+ })(value2, path2);
16778
+ if (!value2.length) fail(path2, "expected at least one clip");
16779
+ const names = /* @__PURE__ */ new Set();
16780
+ for (const [index, clip] of value2.entries()) {
16781
+ if (names.has(clip.name)) fail(`${path2}[${index}].name`, `duplicate clip "${clip.name}"`);
16782
+ names.add(clip.name);
16783
+ }
16784
+ }, loop: boolean, speed: nonnegative, time: nonnegative, paused: boolean });
16785
+ }
16769
16786
  function guiLayer(value, path) {
16770
16787
  const layer = object3(value, path);
16771
16788
  if (["texture", "item", "text"].filter((key) => layer[key] !== void 0).length !== 1) {
@@ -16868,9 +16885,7 @@ function validateObject(value, path) {
16868
16885
  })
16869
16886
  });
16870
16887
  },
16871
- animation: (value2, path2) => {
16872
- fields(value2, path2, { name: text, loop: boolean, speed: nonnegative, time: nonnegative, paused: boolean }, ["name"]);
16873
- }
16888
+ animation: entityAnimation
16874
16889
  }, [...required, "asset"]);
16875
16890
  if (Array.isArray(input.layers) && !input.layers.length) fail(`${path}.layers`, "expected at least one layer");
16876
16891
  break;
@@ -17137,10 +17152,20 @@ var SceneDocumentLoader = class {
17137
17152
  const entity = await content.addEntity(model, { ...definition.options, instanceMeshes: false });
17138
17153
  object4 = entity;
17139
17154
  if (definition.animation) {
17155
+ const animation = definition.animation;
17140
17156
  const animations = await Entities.getAnimations(key);
17141
- const clip = animations?.[definition.animation.name];
17142
- if (!clip) throw new Error(`Entity ${definition.asset} has no animation "${definition.animation.name}"`);
17143
- entity.playAnimation(clip, definition.animation);
17157
+ if (animation.name !== void 0) {
17158
+ const clip = animations && Object.prototype.hasOwnProperty.call(animations, animation.name) ? animations[animation.name] : void 0;
17159
+ if (!clip) throw new Error(`Entity ${definition.asset} has no animation "${animation.name}"`);
17160
+ entity.playAnimation(clip, animation);
17161
+ } else {
17162
+ const clips = animation.clips.map(({ name }) => {
17163
+ const clip = animations && Object.prototype.hasOwnProperty.call(animations, name) ? animations[name] : void 0;
17164
+ if (!clip) throw new Error(`Entity ${definition.asset} has no animation "${name}"`);
17165
+ return clip;
17166
+ });
17167
+ entity.playAnimations(clips, { ...animation, weights: animation.clips.map((clip) => clip.weight ?? 1) });
17168
+ }
17144
17169
  }
17145
17170
  break;
17146
17171
  }