@adatechnology/game-vfx-three 0.8.1 → 0.9.1

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.
@@ -5043,9 +5043,17 @@ var GameVfxThree = (() => {
5043
5043
  });
5044
5044
  }
5045
5045
  function placementOf(entry) {
5046
+ const carrier = entry.carrier;
5047
+ if (carrier) return { origin: carrier.origin, anchor: entry.anchor, yaw: entry.yaw, carrier, ...carrier.orientation ? { orientation: carrier.orientation } : {} };
5046
5048
  const origin = entry.follow ? [entry.origin[0] + positionOf2(entry.follow)[0], entry.origin[1] + positionOf2(entry.follow)[1], entry.origin[2] + positionOf2(entry.follow)[2]] : entry.origin;
5047
5049
  return { origin, anchor: entry.anchor, yaw: entry.yaw, ...entry.orientation ? { orientation: entry.orientation } : {} };
5048
5050
  }
5051
+ function moveCarrier(entry) {
5052
+ const pose = entry.track?.();
5053
+ if (!pose || !entry.carrier) return;
5054
+ entry.carrier.origin = [pose.point[0], pose.point[1], pose.point[2]];
5055
+ if (pose.orientation) entry.carrier.orientation = pose.orientation;
5056
+ }
5049
5057
  function drawing(entry, action) {
5050
5058
  const context = engine.context;
5051
5059
  const shared = context.random;
@@ -5071,7 +5079,9 @@ var GameVfxThree = (() => {
5071
5079
  anchor: def.anchor ?? ORIGIN5,
5072
5080
  yaw: yawOf(heading, playOptions.direction),
5073
5081
  orientation: playOptions.orientation,
5074
- seconds: playOptions.seconds ?? (def.loop && def.loop > 0 ? def.loop : ENDLESS_SECONDS)
5082
+ seconds: playOptions.seconds ?? (def.loop && def.loop > 0 ? def.loop : ENDLESS_SECONDS),
5083
+ track: playOptions.track,
5084
+ carrier: playOptions.track ? { origin: point, orientation: playOptions.orientation } : void 0
5075
5085
  };
5076
5086
  playing.push(entry);
5077
5087
  drawing(
@@ -5093,11 +5103,21 @@ var GameVfxThree = (() => {
5093
5103
  for (let index = playing.length - 1; index >= 0; index--) {
5094
5104
  const entry = playing[index];
5095
5105
  const instance = entry.instance;
5106
+ moveCarrier(entry);
5096
5107
  instance.setup = { ...instance.setup, placement: placementOf(entry) };
5097
5108
  drawing(entry, () => instance.step(dt));
5098
5109
  if (instance.time >= entry.seconds) playing.splice(index, 1);
5099
5110
  }
5100
5111
  },
5112
+ retrack() {
5113
+ let tracked = false;
5114
+ for (const entry of playing) {
5115
+ if (!entry.carrier) continue;
5116
+ moveCarrier(entry);
5117
+ tracked = true;
5118
+ }
5119
+ return tracked;
5120
+ },
5101
5121
  clear() {
5102
5122
  playing.length = 0;
5103
5123
  },
@@ -6709,6 +6729,19 @@ var GameVfxThree = (() => {
6709
6729
  }
6710
6730
  }
6711
6731
  };
6732
+ function rotate(q, v) {
6733
+ const [qx, qy, qz, qw] = q;
6734
+ const ix = qw * v[0] + qy * v[2] - qz * v[1];
6735
+ const iy = qw * v[1] + qz * v[0] - qx * v[2];
6736
+ const iz = qw * v[2] + qx * v[1] - qy * v[0];
6737
+ const iw = -qx * v[0] - qy * v[1] - qz * v[2];
6738
+ return [ix * qw + iw * -qx + iy * -qz - iz * -qy, iy * qw + iw * -qy + iz * -qx - ix * -qz, iz * qw + iw * -qz + ix * -qy - iy * -qx];
6739
+ }
6740
+ function carriedPoint(carried) {
6741
+ const { carrier, local: local2 } = carried;
6742
+ const turned = carrier.orientation ? rotate(carrier.orientation, local2) : local2;
6743
+ return [carrier.origin[0] + turned[0], carrier.origin[1] + turned[1], carrier.origin[2] + turned[2]];
6744
+ }
6712
6745
  var CAPACITY3 = 400;
6713
6746
  var IDENTITY = [0, 0, 0, 1];
6714
6747
  function multiply(a, b) {
@@ -6726,7 +6759,7 @@ var GameVfxThree = (() => {
6726
6759
  get count() {
6727
6760
  return this.particles.length;
6728
6761
  }
6729
- spawn(options, frame = IDENTITY) {
6762
+ spawn(options, frame = IDENTITY, carried) {
6730
6763
  const velocity = options.v ?? [0, 0, 0];
6731
6764
  const world = options.wv ?? [0, 0, 0];
6732
6765
  const particle = {
@@ -6743,6 +6776,9 @@ var GameVfxThree = (() => {
6743
6776
  y: options.p[1],
6744
6777
  z: options.p[2],
6745
6778
  frame: options.roll ? multiply(frame, aboutX(options.roll)) : frame,
6779
+ roll: options.roll ? aboutX(options.roll) : void 0,
6780
+ carried,
6781
+ drift: [0, 0, 0],
6746
6782
  at: options.at ?? [0, 0, 0],
6747
6783
  rx: options.rot?.[0] ?? 0,
6748
6784
  ry: options.rot?.[1] ?? 0,
@@ -6783,9 +6819,12 @@ var GameVfxThree = (() => {
6783
6819
  particle.vy *= keep;
6784
6820
  particle.vz *= keep;
6785
6821
  }
6786
- particle.x += particle.vx * dt;
6787
- particle.y += particle.vy * dt;
6788
- particle.z += particle.vz * dt;
6822
+ if (particle.carried) this.ride(particle, dt);
6823
+ else {
6824
+ particle.x += particle.vx * dt;
6825
+ particle.y += particle.vy * dt;
6826
+ particle.z += particle.vz * dt;
6827
+ }
6789
6828
  particle.rx += particle.spin[0] * dt;
6790
6829
  particle.ry += particle.spin[1] * dt;
6791
6830
  particle.rz += particle.spin[2] * dt;
@@ -6796,6 +6835,30 @@ var GameVfxThree = (() => {
6796
6835
  clear() {
6797
6836
  this.particles.length = 0;
6798
6837
  }
6838
+ /** Puts every carried piece where its carrier is now (after the frame moved the thing it belongs to). */
6839
+ follow() {
6840
+ for (const particle of this.particles) if (particle.carried) this.place(particle);
6841
+ }
6842
+ /** A carried piece: how far its own velocity took it, then its place on the carrier. */
6843
+ ride(particle, dt) {
6844
+ const drift = particle.drift;
6845
+ drift[0] += particle.vx * dt;
6846
+ drift[1] += particle.vy * dt;
6847
+ drift[2] += particle.vz * dt;
6848
+ this.place(particle);
6849
+ }
6850
+ /** A carried piece's place on the carrier now plus its drift, turned with the carrier. */
6851
+ place(particle) {
6852
+ const carried = particle.carried;
6853
+ if (!carried) return;
6854
+ const drift = particle.drift;
6855
+ const [x, y, z] = carriedPoint(carried);
6856
+ particle.x = x + drift[0];
6857
+ particle.y = y + drift[1];
6858
+ particle.z = z + drift[2];
6859
+ const turn = carried.carrier.orientation;
6860
+ if (turn) particle.frame = particle.roll ? multiply(turn, particle.roll) : turn;
6861
+ }
6799
6862
  };
6800
6863
  var DEFAULT_FADE_IN = 0.1;
6801
6864
  var FLOATS_PER_VECTOR = 3;
@@ -7156,8 +7219,8 @@ var GameVfxThree = (() => {
7156
7219
  }
7157
7220
  flash(point, color, intensity, duration, distance, force, steady) {
7158
7221
  const { level } = this.context.quality;
7159
- if (level >= 1 && !force) return;
7160
- if (level >= 2 && force !== "boom") return;
7222
+ if (level >= 1 && !force) return void 0;
7223
+ if (level >= 2 && force !== "boom") return void 0;
7161
7224
  const light = this.lights[this.next++ % LIGHT_CAPACITY];
7162
7225
  light.x = point[0];
7163
7226
  light.y = point[1];
@@ -7169,17 +7232,24 @@ var GameVfxThree = (() => {
7169
7232
  light.t = 0;
7170
7233
  light.steady = steady === true;
7171
7234
  light.intensity = intensity;
7235
+ light.carried = void 0;
7236
+ return light;
7172
7237
  }
7173
7238
  clear() {
7174
7239
  for (const light of this.lights) light.intensity = 0;
7175
7240
  for (const light of this.fire) light.intensity = 0;
7176
7241
  }
7242
+ /** Puts every carried light that burns where its carrier is now. */
7243
+ follow() {
7244
+ for (const light of this.lights) if (light.intensity > 0 && light.carried) [light.x, light.y, light.z] = carriedPoint(light.carried);
7245
+ }
7177
7246
  update(dt) {
7178
7247
  for (const light of this.lights) {
7179
7248
  if (light.intensity <= 0) continue;
7180
7249
  light.t += dt;
7181
7250
  const age = light.t / light.duration;
7182
7251
  light.intensity = age >= 1 ? 0 : light.steady ? light.peak : light.peak * (1 - age) * (1 - age);
7252
+ if (light.carried) [light.x, light.y, light.z] = carriedPoint(light.carried);
7183
7253
  }
7184
7254
  }
7185
7255
  };
@@ -7187,7 +7257,7 @@ var GameVfxThree = (() => {
7187
7257
  var FIRE_FLICKER_SWAY = 0.25;
7188
7258
  var FIRE_FLICKER_JITTER = 0.08;
7189
7259
  var LENS_FADE = 0.16;
7190
- function rotate(q, v) {
7260
+ function rotate2(q, v) {
7191
7261
  const [qx, qy, qz, qw] = q;
7192
7262
  const ix = qw * v[0] + qy * v[2] - qz * v[1];
7193
7263
  const iy = qw * v[1] + qz * v[0] - qx * v[2];
@@ -7244,7 +7314,7 @@ var GameVfxThree = (() => {
7244
7314
  if (!placement) return point;
7245
7315
  const { anchor, origin, yaw, orientation } = placement;
7246
7316
  if (orientation) {
7247
- const turned = rotate(orientation, [point[0] - anchor[0], point[1] - anchor[1], point[2] - anchor[2]]);
7317
+ const turned = rotate2(orientation, [point[0] - anchor[0], point[1] - anchor[1], point[2] - anchor[2]]);
7248
7318
  return [origin[0] + turned[0], origin[1] + turned[1], origin[2] + turned[2]];
7249
7319
  }
7250
7320
  const x = point[0] - anchor[0];
@@ -7253,11 +7323,20 @@ var GameVfxThree = (() => {
7253
7323
  const sin2 = Math.sin(yaw);
7254
7324
  return [origin[0] + cos2 * x + sin2 * z, origin[1] + point[1] - anchor[1], origin[2] - sin2 * x + cos2 * z];
7255
7325
  }
7326
+ /** A point of the recipe's space from the anchor, turned by the placement's yaw when it has no orientation (the carrier turns the rest). */
7327
+ local(point) {
7328
+ const placement = this.placement;
7329
+ if (!placement) return point;
7330
+ const offset = [point[0] - placement.anchor[0], point[1] - placement.anchor[1], point[2] - placement.anchor[2]];
7331
+ if (placement.carrier?.orientation) return offset;
7332
+ const turned = this.place(point);
7333
+ return [turned[0] - placement.origin[0], turned[1] - placement.origin[1], turned[2] - placement.origin[2]];
7334
+ }
7256
7335
  /** A direction or velocity of the recipe's space in the world. */
7257
7336
  turn(vector2) {
7258
7337
  const placement = this.placement;
7259
7338
  if (!placement) return vector2;
7260
- if (placement.orientation) return rotate(placement.orientation, vector2);
7339
+ if (placement.orientation) return rotate2(placement.orientation, vector2);
7261
7340
  const cos2 = Math.cos(placement.yaw);
7262
7341
  const sin2 = Math.sin(placement.yaw);
7263
7342
  return [cos2 * vector2[0] + sin2 * vector2[2], vector2[1], -sin2 * vector2[0] + cos2 * vector2[2]];
@@ -7292,7 +7371,8 @@ var GameVfxThree = (() => {
7292
7371
  const options = placement ? { ...recipe, p: this.place(recipe.p), ...recipe.v ? { v: this.turn(recipe.v) } : {} } : recipe;
7293
7372
  this.context.trace?.("mesh", [options]);
7294
7373
  const grouped = recipe.at !== void 0 || recipe.roll !== void 0;
7295
- return this.meshes.spawn(options, placement && grouped ? placement.orientation ?? [0, Math.sin(placement.yaw / 2), 0, Math.cos(placement.yaw / 2)] : void 0);
7374
+ const carried = placement?.carrier && grouped ? { carrier: placement.carrier, local: this.local(recipe.p) } : void 0;
7375
+ return this.meshes.spawn(options, placement && grouped ? placement.orientation ?? [0, Math.sin(placement.yaw / 2), 0, Math.cos(placement.yaw / 2)] : void 0, carried);
7296
7376
  }
7297
7377
  debrisPiece(recipe) {
7298
7378
  const options = this.placed(recipe);
@@ -7316,9 +7396,11 @@ var GameVfxThree = (() => {
7316
7396
  }
7317
7397
  /** `steady` (a seventh number): the light holds its intensity for its duration and goes out, where the Workshop's fades with the square of its age. */
7318
7398
  flash(recipe) {
7319
- const args = this.placement ? [this.place(recipe[0]), recipe[1], recipe[2], recipe[3], recipe[4], recipe[5], recipe[6]] : recipe;
7399
+ const placement = this.placement;
7400
+ const args = placement ? [this.place(recipe[0]), recipe[1], recipe[2], recipe[3], recipe[4], recipe[5], recipe[6]] : recipe;
7320
7401
  this.context.trace?.("flash", args.slice(0, 6));
7321
- this.lights.flash(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
7402
+ const light = this.lights.flash(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
7403
+ if (light && placement?.carrier) light.carried = { carrier: placement.carrier, local: this.local(recipe[0]) };
7322
7404
  }
7323
7405
  /** `fireLight` (W400): sways with the clock and flickers with one draw. */
7324
7406
  fireLight(slot, recipe, intensity, time) {
@@ -7477,6 +7559,12 @@ var GameVfxThree = (() => {
7477
7559
  const seed = playOptions.seed ?? (randomMode === "shared" ? void 0 : Math.imul(++handles.events, AUTO_SEED) + (options.seed ?? 0));
7478
7560
  return effectPlayer().play(id, [point[0], point[1], point[2]], { ...playOptions, ...seed !== void 0 ? { seed } : {} });
7479
7561
  },
7562
+ follow() {
7563
+ if (!engine || !player?.retrack()) return false;
7564
+ engine.meshes.follow();
7565
+ engine.lights.follow();
7566
+ return true;
7567
+ },
7480
7568
  burst: (kind, point, normal, count, speed, spriteOptions) => spriteSystem.burst(kind, point, normal, count, speed, spriteOptions),
7481
7569
  spawn: (kind, point, velocity, spriteOptions) => spriteSystem.spawn(kind, point, velocity, spriteOptions),
7482
7570
  onLand: (owner, listener) => spriteSystem.onLand(owner, listener),
@@ -9919,7 +10007,8 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9919
10007
  ...request.orientation ? { orientation: request.orientation } : {},
9920
10008
  ...request.seed !== void 0 ? { seed: request.seed } : {},
9921
10009
  ...request.param !== void 0 ? { param: request.param } : {},
9922
- ...request.values ? { values: request.values } : {}
10010
+ ...request.values ? { values: request.values } : {},
10011
+ ...request.track ? { track: request.track } : {}
9923
10012
  });
9924
10013
  },
9925
10014
  stop: (handle) => world.stop(handle),
@@ -9948,6 +10037,11 @@ void main(){vec2 d=gl_PointCoord-.5;float r=length(d)*2.;if(r>1.)discard;float a
9948
10037
  syncAll();
9949
10038
  overlay?.update(screenNow());
9950
10039
  },
10040
+ present() {
10041
+ if (!world.follow()) return;
10042
+ lights.sync();
10043
+ workshopLayers?.sync();
10044
+ },
9951
10045
  warmUpProbes() {
9952
10046
  releaseAnchors();
9953
10047
  marks.prepare();