@lovelace_lol/embody 0.0.8 → 0.0.9

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/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import * as THREE3 from 'three';
2
- import { NoBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NormalBlending, Vector3, Box3, Matrix4, Quaternion, MathUtils, Mesh, PlaneGeometry, ShadowMaterial, HemisphereLight, DirectionalLight, SRGBColorSpace, ACESFilmicToneMapping, WebGLRenderer, Scene, Color, PerspectiveCamera, PCFShadowMap, PCFSoftShadowMap, InterpolateDiscrete, NumberKeyframeTrack, QuaternionKeyframeTrack, VectorKeyframeTrack, AnimationClip, PMREMGenerator, FloatType, Float32BufferAttribute, Euler, PropertyBinding, BufferAttribute, WebGPUCoordinateSystem, WebGLCoordinateSystem } from 'three';
3
- import { initEmbodyCore, requireInitializedEmbodyCore } from '@lovelace_lol/embody/wasm';
2
+ import { NoBlending, MultiplyBlending, SubtractiveBlending, AdditiveBlending, NormalBlending, Vector3, Box3, Timer, Matrix4, AnimationMixer, AdditiveAnimationBlendMode, NormalAnimationBlendMode, LoopOnce, LoopRepeat, LoopPingPong, PropertyBinding, Quaternion, AnimationUtils, InterpolateDiscrete, InterpolateLinear, MathUtils, Mesh, PlaneGeometry, ShadowMaterial, HemisphereLight, DirectionalLight, SRGBColorSpace, ACESFilmicToneMapping, WebGLRenderer, Scene, Color, PerspectiveCamera, PCFShadowMap, PCFSoftShadowMap, NumberKeyframeTrack, QuaternionKeyframeTrack, VectorKeyframeTrack, AnimationClip, PMREMGenerator, FloatType, Float32BufferAttribute, Euler, BufferAttribute, WebGPUCoordinateSystem, WebGLCoordinateSystem } from 'three';
3
+ import { CC4_HUMANOID_SKELETON_TEMPLATE, HUMANOID_SKELETON_TEMPLATES, DEFAULT_HAIR_COLOR_APPEARANCE, initEmbodyCore, requireInitializedEmbodyCore } from '@lovelace_lol/embody/wasm';
4
+ export * from '@lovelace_lol/embody/wasm';
5
+ export { CC4_HUMANOID_SKELETON_TEMPLATE, DEFAULT_AXIS_TO_CHANNEL, DEFAULT_BONE_MAX_DEGREES, DEFAULT_HAIR_COLOR_APPEARANCE, HAIR_COLOR_PRESETS, HUMANOID_SKELETON_TEMPLATES, JOINT_CONTROL_SECTION, VISEME_KEYS } from '@lovelace_lol/embody/wasm';
4
6
  import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
5
7
  import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
6
8
  import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js';
@@ -449,6 +451,59 @@ function drawModelForRender(renderer, scene, camera, model) {
449
451
  if (globalShadow && renderer.shadowMap.enabled) globalShadow.needsUpdate = true;
450
452
  };
451
453
  }
454
+ var bindings = /* @__PURE__ */ new WeakMap();
455
+ function bindPlaybackRendering(model, mixer, afterFrame) {
456
+ const binding = { mixer, enabled: true, afterFrame };
457
+ const entries = bindings.get(model) ?? /* @__PURE__ */ new Set();
458
+ entries.add(binding);
459
+ bindings.set(model, entries);
460
+ return {
461
+ setEnabled(enabled) {
462
+ binding.enabled = enabled;
463
+ },
464
+ dispose() {
465
+ entries.delete(binding);
466
+ if (!entries.size) bindings.delete(model);
467
+ }
468
+ };
469
+ }
470
+ function renderScenePlayback(scene, timer) {
471
+ const mixers = /* @__PURE__ */ new Set();
472
+ const active = [];
473
+ scene.traverse((object) => {
474
+ for (const binding of bindings.get(object) ?? []) {
475
+ if (binding.enabled) {
476
+ active.push(binding);
477
+ mixers.add(binding.mixer);
478
+ }
479
+ }
480
+ });
481
+ for (const mixer of mixers) mixer.update(timer.getDelta());
482
+ for (const binding of active) binding.afterFrame();
483
+ }
484
+ function createScenePlaybackFrame(scene, document2) {
485
+ const timer = new Timer();
486
+ if (document2) timer.connect(document2);
487
+ let disposed = false;
488
+ let initialized = false;
489
+ return {
490
+ onFrame(timestamp) {
491
+ if (disposed) return;
492
+ timer.update(timestamp);
493
+ if (!initialized) {
494
+ initialized = true;
495
+ return;
496
+ }
497
+ renderScenePlayback(scene, timer);
498
+ },
499
+ dispose() {
500
+ if (!disposed) {
501
+ disposed = true;
502
+ timer.dispose();
503
+ }
504
+ }
505
+ };
506
+ }
452
507
 
453
508
  // three/annotations/DOMControls.ts
454
509
  var RUNTIME_ANNOTATION_REGION_PREFIX = "runtime:annotation:";
@@ -1111,8 +1166,8 @@ function getAnnotationRegionLabel(region) {
1111
1166
  const trimmed = label.trim();
1112
1167
  return trimmed.length > 0 ? trimmed : void 0;
1113
1168
  }
1114
- function isFiniteClipPoint(point3) {
1115
- return Number.isFinite(point3.x) && Number.isFinite(point3.y) && Number.isFinite(point3.z) && Number.isFinite(point3.w);
1169
+ function isFiniteClipPoint(point2) {
1170
+ return Number.isFinite(point2.x) && Number.isFinite(point2.y) && Number.isFinite(point2.z) && Number.isFinite(point2.w);
1116
1171
  }
1117
1172
  function resolveViewportSafeBounds(params) {
1118
1173
  return requireAnnotationCameraCore().resolveViewportSafeBounds(params);
@@ -3913,9 +3968,9 @@ function resolveRuntimeAnnotationAUBoneTargets(auId, candidates, targetSide) {
3913
3968
  const boneTargets = [];
3914
3969
  for (const candidate of candidates) {
3915
3970
  if (!isPlainRecord(candidate.auToBones)) continue;
3916
- const bindings = candidate.auToBones[auId];
3917
- if (!Array.isArray(bindings)) continue;
3918
- for (const binding of bindings) {
3971
+ const bindings2 = candidate.auToBones[auId];
3972
+ if (!Array.isArray(bindings2)) continue;
3973
+ for (const binding of bindings2) {
3919
3974
  const target = readRuntimeAnnotationBoneTarget(binding);
3920
3975
  if (!target || seen.has(target.boneName)) continue;
3921
3976
  seen.add(target.boneName);
@@ -4079,6 +4134,7 @@ var DPthreeCameraController = class {
4079
4134
  __publicField(this, "domElement");
4080
4135
  // Renderer and render loop (when controller manages the render loop)
4081
4136
  __publicField(this, "renderer", null);
4137
+ __publicField(this, "playbackTimer", new THREE3.Timer());
4082
4138
  __publicField(this, "renderFrame");
4083
4139
  __publicField(this, "resizeRenderer");
4084
4140
  __publicField(this, "onRenderError");
@@ -4189,15 +4245,25 @@ var DPthreeCameraController = class {
4189
4245
  startRenderLoop(propagateFailure = false) {
4190
4246
  if (!this.renderer) return;
4191
4247
  const renderer = this.renderer;
4248
+ this.playbackTimer.disconnect();
4249
+ const ownerDocument = renderer.domElement?.ownerDocument;
4250
+ if (ownerDocument) this.playbackTimer.connect(ownerDocument);
4251
+ this.playbackTimer.reset();
4252
+ let playbackStarted = false;
4192
4253
  try {
4193
- const started = renderer.setAnimationLoop(() => {
4194
- if (this.disposed || this.renderFailed || this.renderingSuspended || this.framePending || renderer !== this.renderer) return;
4254
+ const started = renderer.setAnimationLoop((timestamp) => {
4255
+ if (this.disposed || renderer !== this.renderer) return;
4256
+ this.playbackTimer.update(timestamp);
4257
+ const samplePlayback = playbackStarted;
4258
+ playbackStarted = true;
4259
+ if (this.renderFailed || this.renderingSuspended || this.framePending) return;
4195
4260
  try {
4196
4261
  const preparationDraw = this.modelPreparation?.draw;
4197
4262
  if (preparationDraw) {
4198
4263
  preparationDraw();
4199
4264
  return;
4200
4265
  }
4266
+ if (samplePlayback) renderScenePlayback(this.scene, this.playbackTimer);
4201
4267
  this.update();
4202
4268
  const frame = this.renderFrame ? this.renderFrame(this.renderer, this.scene, this.camera) : this.renderer.render(this.scene, this.camera);
4203
4269
  if (frame) {
@@ -4246,6 +4312,7 @@ var DPthreeCameraController = class {
4246
4312
  * Stop the render loop
4247
4313
  */
4248
4314
  stopRenderLoop() {
4315
+ this.playbackTimer.reset();
4249
4316
  try {
4250
4317
  const stopped = this.renderer?.setAnimationLoop(null);
4251
4318
  if (stopped) void stopped.catch((error) => console.error("Character camera render loop stop failed.", error));
@@ -4331,18 +4398,18 @@ var DPthreeCameraController = class {
4331
4398
  resolve = yes;
4332
4399
  reject = no;
4333
4400
  });
4334
- const request2 = {
4401
+ const request3 = {
4335
4402
  promise,
4336
4403
  draw: null,
4337
4404
  cancel: (reason) => {
4338
4405
  cancelled ?? (cancelled = reason);
4339
4406
  invalidatePreparedShadows?.();
4340
- request2.draw = null;
4407
+ request3.draw = null;
4341
4408
  rejectDraw?.(cancelled);
4342
4409
  }
4343
4410
  };
4344
- this.modelPreparation = request2;
4345
- const abort = () => request2.cancel(renderPreparationAborted());
4411
+ this.modelPreparation = request3;
4412
+ const abort = () => request3.cancel(renderPreparationAborted());
4346
4413
  options.signal?.addEventListener("abort", abort, { once: true });
4347
4414
  const checkCancelled = () => {
4348
4415
  if (cancelled) throw cancelled;
@@ -4361,8 +4428,8 @@ var DPthreeCameraController = class {
4361
4428
  checkCancelled();
4362
4429
  await new Promise((done, failed) => {
4363
4430
  rejectDraw = failed;
4364
- request2.draw = () => {
4365
- request2.draw = null;
4431
+ request3.draw = () => {
4432
+ request3.draw = null;
4366
4433
  try {
4367
4434
  checkCancelled();
4368
4435
  invalidatePreparedShadows = drawModelForRender(renderer, this.scene, this.camera, model);
@@ -4377,7 +4444,7 @@ var DPthreeCameraController = class {
4377
4444
  checkCancelled();
4378
4445
  } finally {
4379
4446
  options.signal?.removeEventListener("abort", abort);
4380
- if (this.modelPreparation === request2) this.modelPreparation = null;
4447
+ if (this.modelPreparation === request3) this.modelPreparation = null;
4381
4448
  }
4382
4449
  })().then(resolve, reject);
4383
4450
  return promise;
@@ -4416,10 +4483,10 @@ var DPthreeCameraController = class {
4416
4483
  */
4417
4484
  async loadRegions(config) {
4418
4485
  if (this.disposed) return;
4419
- const request2 = ++this.regionLoadGeneration;
4486
+ const request3 = ++this.regionLoadGeneration;
4420
4487
  const model = this.model;
4421
4488
  const runtimeConfig = await this.resolveCharacterConfig(config);
4422
- if (!this.isRegionLoadCurrent(request2, model)) return;
4489
+ if (!this.isRegionLoadCurrent(request3, model)) return;
4423
4490
  await this.prepareRegionsAndMarkersForReveal(runtimeConfig);
4424
4491
  }
4425
4492
  /**
@@ -4439,12 +4506,12 @@ var DPthreeCameraController = class {
4439
4506
  async prepareRegionsAndMarkersForReveal(config, beforeReveal) {
4440
4507
  if (this.disposed) return;
4441
4508
  this.prepareRegionState(config);
4442
- const request2 = this.regionLoadGeneration;
4509
+ const request3 = this.regionLoadGeneration;
4443
4510
  const model = this.model;
4444
4511
  await this.loadMarkersForCurrentRegions(true);
4445
- if (!this.isRegionLoadCurrent(request2, model) || this.characterConfig !== config) return;
4512
+ if (!this.isRegionLoadCurrent(request3, model) || this.characterConfig !== config) return;
4446
4513
  if (beforeReveal && !await beforeReveal()) return;
4447
- if (this.isRegionLoadCurrent(request2, model) && this.characterConfig === config) {
4514
+ if (this.isRegionLoadCurrent(request3, model) && this.characterConfig === config) {
4448
4515
  this.startPreparedCameraTransition(config);
4449
4516
  }
4450
4517
  }
@@ -4479,14 +4546,14 @@ var DPthreeCameraController = class {
4479
4546
  return;
4480
4547
  }
4481
4548
  const characterConfig = this.characterConfig;
4482
- const request2 = this.regionLoadGeneration;
4549
+ const request3 = this.regionLoadGeneration;
4483
4550
  const model = this.model;
4484
4551
  this.ensureMarkersForCurrentStyle();
4485
4552
  const markers = this.markers;
4486
4553
  if (!markers) return;
4487
4554
  markers.setVisible(this.markersVisible);
4488
4555
  await markers.loadRegions(characterConfig, { sliceSurfaceQueries });
4489
- if (!this.isRegionLoadCurrent(request2, model) || markers !== this.markers || characterConfig !== this.characterConfig) {
4556
+ if (!this.isRegionLoadCurrent(request3, model) || markers !== this.markers || characterConfig !== this.characterConfig) {
4490
4557
  return;
4491
4558
  }
4492
4559
  if (this.currentRegion) {
@@ -4656,8 +4723,8 @@ var DPthreeCameraController = class {
4656
4723
  * @param zoomDuration - Duration of the final zoom in ms (default: 1500)
4657
4724
  */
4658
4725
  async playIntroAnimation(orbitDuration = 3e3, zoomDuration = 1500) {
4659
- const request2 = await this.beginCameraRequest();
4660
- if (request2 === null) return;
4726
+ const request3 = await this.beginCameraRequest();
4727
+ if (request3 === null) return;
4661
4728
  if (!this.model) {
4662
4729
  return;
4663
4730
  }
@@ -4672,12 +4739,12 @@ var DPthreeCameraController = class {
4672
4739
  const orbitRadius = Math.max(horizontalExtent, verticalExtent) * 1.8;
4673
4740
  const orbitHeight = center.y;
4674
4741
  await this.animateOrbit(center, orbitRadius, orbitHeight, orbitDuration);
4675
- if (!this.isCameraRequestCurrent(request2)) return;
4742
+ if (!this.isCameraRequestCurrent(request3)) return;
4676
4743
  const leftEyeRegion = this.findIntroLeftEyeRegion();
4677
4744
  const leftEyeFocus = leftEyeRegion ? this.calculateIntroLeftEyeFocusPosition(leftEyeRegion) : null;
4678
4745
  if (leftEyeFocus && leftEyeRegion) {
4679
4746
  await this.animateCamera(leftEyeFocus.position, leftEyeFocus.target, zoomDuration);
4680
- if (!this.isCameraRequestCurrent(request2)) return;
4747
+ if (!this.isCameraRequestCurrent(request3)) return;
4681
4748
  this.currentRegion = leftEyeRegion.name;
4682
4749
  this.notifyRegionChange(leftEyeRegion.name);
4683
4750
  return;
@@ -4686,7 +4753,7 @@ var DPthreeCameraController = class {
4686
4753
  const fullBodyRegion = this.regions.find((region) => this.isFullBodyRegion(region));
4687
4754
  const focusPos = this.calculateFullBodyFocusPosition(fullBodyRegion?.paddingFactor, finalAngle, "world");
4688
4755
  await this.animateCamera(focusPos.position, focusPos.target, zoomDuration);
4689
- if (!this.isCameraRequestCurrent(request2)) return;
4756
+ if (!this.isCameraRequestCurrent(request3)) return;
4690
4757
  if (fullBodyRegion) {
4691
4758
  this.currentRegion = fullBodyRegion.name;
4692
4759
  this.notifyRegionChange(fullBodyRegion.name);
@@ -5390,6 +5457,7 @@ var DPthreeCameraController = class {
5390
5457
  this.regionLoadGeneration += 1;
5391
5458
  this.cameraRequestGeneration += 1;
5392
5459
  this.stopRenderLoop();
5460
+ this.playbackTimer.dispose();
5393
5461
  const renderingSettled = this.unbindRendering?.();
5394
5462
  this.unbindRendering = null;
5395
5463
  this.cleanupResizeHandling();
@@ -5703,19 +5771,19 @@ var DPthreeCameraController = class {
5703
5771
  this.laterality = detectAnnotationLaterality(this.model, this.regions, boneResolutionProfile(this.characterConfig));
5704
5772
  }
5705
5773
  /** Resolver and paint continuations belong to one model/configuration load. */
5706
- isRegionLoadCurrent(request2, model) {
5707
- return !this.disposed && request2 === this.regionLoadGeneration && model === this.model;
5774
+ isRegionLoadCurrent(request3, model) {
5775
+ return !this.disposed && request3 === this.regionLoadGeneration && model === this.model;
5708
5776
  }
5709
5777
  /** Await Wasm once per request and abandon requests superseded during initialization. */
5710
5778
  async beginCameraRequest() {
5711
- const request2 = ++this.cameraRequestGeneration;
5779
+ const request3 = ++this.cameraRequestGeneration;
5712
5780
  this.cancelCameraAnimation();
5713
5781
  if (this.disposed) return null;
5714
5782
  await getAnnotationCameraCore();
5715
- return this.isCameraRequestCurrent(request2) ? request2 : null;
5783
+ return this.isCameraRequestCurrent(request3) ? request3 : null;
5716
5784
  }
5717
- isCameraRequestCurrent(request2) {
5718
- return !this.disposed && request2 === this.cameraRequestGeneration;
5785
+ isCameraRequestCurrent(request3) {
5786
+ return !this.disposed && request3 === this.cameraRequestGeneration;
5719
5787
  }
5720
5788
  cancelCameraAnimation() {
5721
5789
  this.timerAnimationFallbackToken += 1;
@@ -6448,6 +6516,99 @@ function pickContinuumAnnotationAuId(value, negId, posId, stickyId) {
6448
6516
  if (value > 0) return posId;
6449
6517
  return negId;
6450
6518
  }
6519
+ var json = (value) => JSON.stringify(value ?? {});
6520
+ function request2(op, payload = {}) {
6521
+ return JSON.parse(requireInitializedEmbodyCore().embody_request(json({ op, payload })));
6522
+ }
6523
+ var getPreset = (id) => request2("preset.get", { id });
6524
+ var extendCharacterConfigWithPreset = (config) => request2("profile.extendConfig", { config });
6525
+ var extractProfileOverrides = (config) => request2("profile.extractOverrides", { config });
6526
+ var mergeCharacterRegionsByName = (base, override) => request2("profile.mergeRegions", { base, override });
6527
+ var getMeshNamesForAUProfile = (profile, auId) => request2("profile.getMeshNamesForAU", { profile, auId });
6528
+ var getHumanoidSpecification = () => request2("humanoid.getSpecification");
6529
+ var setAUMorphTargets = (profile, auId, side, targets) => request2("profile.setAUMorphTargets", { profile, auId, side, targets });
6530
+ var setHumanoidRoleBinding = (profile, role, boneName) => request2("profile.setHumanoidRoleBinding", { profile, role, boneName });
6531
+ var resolveHumanoidCharacterization = (profile) => request2("profile.resolveHumanoidCharacterization", { profile });
6532
+ var hasLeftRightMorphs = (profile, auId) => request2("profile.hasLeftRightMorphs", { profile, auId });
6533
+ var isMixedAU = (profile, auId) => request2("profile.isMixedAU", { profile, auId });
6534
+ var resolveVisemeProfile = (profile) => request2("profile.resolveVisemes", { profile });
6535
+ var isMaxDegreesOnlyAxisBindingUpdate = (update) => request2("bone.isMaxDegreesOnlyUpdate", { update });
6536
+ var findNodeKeyForBone = (boneName, profile) => profile ? request2("bone.findNodeKey", { profile, boneName }) : null;
6537
+ var ensureBoneNodeKey = (profile, boneName) => request2("bone.ensureNodeKey", { profile, boneName });
6538
+ var ensureBilateralBoneNodeKeys = (profile, leftBoneName, rightBoneName) => request2("bone.ensureBilateralNodeKeys", { profile, leftBoneName, rightBoneName });
6539
+ var resolveBoneNameForNodeKey = (profile, nodeKey) => request2("bone.resolveBoneName", { profile, nodeKey });
6540
+ var stripConfiguredBoneAffixes = (profile, boneName) => request2("bone.stripAffixes", { profile: profile ?? {}, boneName });
6541
+ var inferChiralBoneNamePair = (boneNames, selectedBoneName) => request2("bone.inferChiralPair", { boneNames, selectedBoneName });
6542
+ var formatAxisLabel = (axis) => request2("bone.formatAxisLabel", { axis });
6543
+ var formatAxisDirectionLabel = (axis, direction) => request2("bone.formatDirectionLabel", { axis, direction });
6544
+ var getAxisFromChannel = (channel) => channel ? request2("bone.getAxisFromChannel", { channel }) : null;
6545
+ var getBoneAxisBindingState = (profile, boneName, axis) => request2("bone.getAxisState", { profile, boneName, axis });
6546
+ var resolveBoneAxisChannel = (profile, boneName, axis) => request2("bone.resolveAxisChannel", { profile, boneName, axis });
6547
+ var getBilateralAxisBindingState = (profile, boneName, axis) => request2("bone.getBilateralAxisState", { profile, boneName, axis });
6548
+ var getAUBoneBindingState = (profile, auId) => request2("bone.getAUBindingState", { profile, auId });
6549
+ var inferEyeControlScope = (profile, binding) => request2("bone.inferEyeScope", { profile, binding });
6550
+ var inferEyeControlFamily = (binding) => request2("bone.inferEyeFamily", { binding });
6551
+ var applyBoneAxisBindingUpdate = (profile, boneName, axis, update) => request2("bone.applyAxisUpdate", { profile, boneName, axis, update });
6552
+ var applyBilateralAxisBindingUpdate = (profile, boneName, axis, scope, update) => request2("bone.applyBilateralAxisUpdate", { profile, boneName, axis, scope, update });
6553
+ var applyAUBoneBindingUpdate = (profile, auId, update) => request2("bone.applyAUBindingUpdate", { profile, auId, update });
6554
+ var createBoneAxisAu = (profile, boneName, axis, direction, options = {}) => request2("bone.createAxisAU", { profile, boneName, axis, direction, name: options.name });
6555
+ var createBilateralBoneAxisAu = (profile, boneName, axis, scope, direction, options = {}) => request2("bone.createBilateralAxisAU", { profile, boneName, axis, scope, direction, name: options.name });
6556
+ var buildBoneAuOptions = (profile) => request2("bone.buildAUOptions", { profile });
6557
+ var isJointControlAuInfo = (info) => request2("bone.isJointControlInfo", { info });
6558
+ var classifyAuAsJointControl = (profile, auId, options = {}) => request2("bone.classifyJointControl", { profile, auId, boneName: options.boneName, nodeKey: options.nodeKey });
6559
+ var resolveContinuumDisplayLabel = (profile, negativeAuId, positiveAuId) => request2("bone.resolveContinuumLabel", { profile, negativeAuId, positiveAuId }) ?? `AU ${negativeAuId} <-> AU ${positiveAuId}`;
6560
+ function inspectModel(model, meshes, profile) {
6561
+ return new ThreeModelInspector().inspectModel(model, { meshes, profile });
6562
+ }
6563
+ function getBodyControls(profile, model) {
6564
+ return request2("profile.getBodyControls", { profile, ...model ? { model: inspectModel(model, void 0, profile).descriptor } : {} });
6565
+ }
6566
+ function extractModelData(model, meshes, animations = []) {
6567
+ const inspection = inspectModel(model, meshes);
6568
+ return JSON.parse(requireInitializedEmbodyCore().extract_model_data_json(json(inspection.descriptor), json(serializeAnimationClips(model, animations, inspection))));
6569
+ }
6570
+ async function analyzeModel(options) {
6571
+ const source = options.source;
6572
+ const model = source.type === "gltf" ? source.gltf.scene ?? source.gltf.scenes[0] : source.model;
6573
+ const animations = source.type === "gltf" ? source.gltf.animations : source.animations ?? [];
6574
+ const inspection = inspectModel(model, source.type === "runtime" ? source.meshes : void 0);
6575
+ return JSON.parse(requireInitializedEmbodyCore().analyze_model_descriptor(json(inspection.descriptor), json(serializeAnimationClips(model, animations, inspection)), options.preset ? json(options.preset) : "", json({ suggestCorrections: Boolean(options.suggestCorrections) })));
6576
+ }
6577
+ function validateMappings(meshes, skeleton, profile, options = {}) {
6578
+ let nextMorphId = 1;
6579
+ const morphTargets = [];
6580
+ const descriptorMeshes = (meshes ?? []).map((value, index) => {
6581
+ const mesh = value;
6582
+ const id = index + 1;
6583
+ const morphTargetIds = Object.entries(mesh.morphTargetDictionary ?? mesh.geometry?.morphTargetDictionary ?? {}).map(([name, hostIndex]) => {
6584
+ const morphId = nextMorphId++;
6585
+ morphTargets.push({ id: morphId, meshId: id, name, hostIndex });
6586
+ return morphId;
6587
+ });
6588
+ return { id, name: mesh.name ?? "", morphTargetIds, visible: true };
6589
+ });
6590
+ const bones = (skeleton?.bones ?? []).map((bone, index) => ({ id: index + 1, name: typeof bone === "string" ? bone : bone.name ?? "" }));
6591
+ return JSON.parse(requireInitializedEmbodyCore().validate_profile_model(json(profile), json({ meshes: descriptorMeshes, morphTargets, bones, objects: [] }), json(options)));
6592
+ }
6593
+ function validateHumanoidCharacterization(model, profile) {
6594
+ return JSON.parse(requireInitializedEmbodyCore().validate_humanoid_characterization(json(profile), json(inspectModel(model, void 0, profile).descriptor)));
6595
+ }
6596
+ function normalizeHairColorAppearance(value, fallback = DEFAULT_HAIR_COLOR_APPEARANCE) {
6597
+ return JSON.parse(requireInitializedEmbodyCore().normalize_hair_color_appearance_json(json(value), json(fallback)));
6598
+ }
6599
+ var getHumanoidSkeletonTemplate = (id) => HUMANOID_SKELETON_TEMPLATES.find((template) => template.id === id) ?? null;
6600
+ function getHumanoidSkeletonTemplateBoneNames(template = CC4_HUMANOID_SKELETON_TEMPLATE) {
6601
+ return JSON.parse(requireInitializedEmbodyCore().humanoid_skeleton_template_bone_names(json(template)));
6602
+ }
6603
+ function createValidationSkeletonFromHumanoidTemplate(template = CC4_HUMANOID_SKELETON_TEMPLATE) {
6604
+ return JSON.parse(requireInitializedEmbodyCore().create_validation_skeleton_json(json(template)));
6605
+ }
6606
+ function computeHumanoidSkeletonTemplateRestBounds(template) {
6607
+ return Array.from(requireInitializedEmbodyCore().compute_humanoid_skeleton_template_rest_bounds(json(template)));
6608
+ }
6609
+ function extractHumanoidSkeletonTemplateFromModel(model, options) {
6610
+ return JSON.parse(requireInitializedEmbodyCore().extract_humanoid_skeleton_template_json(json(inspectModel(model).descriptor), json(options)));
6611
+ }
6451
6612
  var isBone = (object) => !!(object.isBone || object.type === "Bone");
6452
6613
  var finite = (values, description) => {
6453
6614
  if (!values.every(Number.isFinite)) {
@@ -6558,389 +6719,1692 @@ function extendModelReferencePose(model, previous) {
6558
6719
  }
6559
6720
  function bindModelReferencePose(model, referencePose) {
6560
6721
  if (referencePose.version !== 1) throw new Error("Unsupported model reference pose version");
6561
- const bindings = /* @__PURE__ */ new Map();
6722
+ const bindings2 = /* @__PURE__ */ new Map();
6562
6723
  let index = 0;
6563
6724
  const bind = (object, path, parentPath) => {
6564
6725
  const node = referencePose.nodes[index++];
6565
6726
  if (!matchesNode(object, node, path, parentPath) || node.childCount !== object.children.length) {
6566
6727
  throw incompatible(object, path);
6567
6728
  }
6568
- bindings.set(object, node);
6729
+ bindings2.set(object, node);
6569
6730
  object.children.forEach((child, childIndex) => bind(child, `${path}/${childIndex}`, path));
6570
6731
  };
6571
6732
  bind(model, "", null);
6572
6733
  if (index !== referencePose.nodes.length) throw new Error("Incompatible reference pose hierarchy: extra captured nodes");
6573
- return bindings;
6574
- }
6575
- var EPSILON = 1e-8;
6576
- var finite2 = (value, fallback = 0) => typeof value === "number" && Number.isFinite(value) ? value : fallback;
6577
- var bounded = (value) => Math.max(-1, Math.min(1, finite2(value)));
6578
- var contribution = (value) => Math.max(0, Math.min(1, finite2(value, 1)));
6579
- var point2 = (value) => ({ x: value.x, y: value.y, z: value.z });
6580
- var vector = (value) => new Vector3(finite2(value?.x), finite2(value?.y), finite2(value?.z));
6581
- var axisVector = (channel) => channel === "rx" ? new Vector3(1, 0, 0) : channel === "ry" ? new Vector3(0, 1, 0) : channel === "rz" ? new Vector3(0, 0, 1) : void 0;
6582
- var ThreeGazeFocus = class {
6583
- constructor(model, profile, options = {}) {
6584
- this.model = model;
6585
- this.profile = profile;
6586
- __publicField(this, "head");
6587
- __publicField(this, "eyes", []);
6588
- __publicField(this, "saved", /* @__PURE__ */ new Map());
6589
- __publicField(this, "references");
6590
- __publicField(this, "limits");
6591
- this.references = bindModelReferencePose(model, options.referencePose ?? captureModelReferencePose(model));
6592
- this.head = this.joint("HEAD", "head", [51, 52, 53, 54, 56, 55]);
6593
- this.eyes = [
6594
- this.joint("EYE_L", "leftEye", [61, 62, 63, 64]),
6595
- this.joint("EYE_R", "rightEye", [61, 62, 63, 64])
6596
- ].filter((value) => !!value);
6597
- this.limits = {
6598
- headYaw: this.capacity(51, 52),
6599
- headPitch: this.capacity(53, 54),
6600
- eyeYaw: this.capacity(61, 62),
6601
- eyePitch: this.capacity(63, 64)
6602
- };
6734
+ return bindings2;
6735
+ }
6736
+
6737
+ // three/clipBindings.ts
6738
+ function concreteTrackName(target, inspection) {
6739
+ if (!target) return void 0;
6740
+ if (target.kind === "morphTarget") {
6741
+ const binding = inspection.morphBindings.get(Number(target.morphTargetId));
6742
+ return binding && `${binding.mesh.uuid}.morphTargetInfluences[${binding.index}]`;
6743
+ }
6744
+ if (target.kind === "boneTransform" || target.kind === "objectTransform") {
6745
+ const object = target.kind === "boneTransform" ? inspection.boneBindings.get(Number(target.boneId)) : inspection.objectBindings.get(Number(target.objectId));
6746
+ const property = target.property ?? "rotation";
6747
+ if (!object) return void 0;
6748
+ if (property === "rotation" || property === "quaternion") return `${object.uuid}.quaternion`;
6749
+ if (property === "position" || property === "scale") return `${object.uuid}.${property}`;
6603
6750
  }
6604
- name(node) {
6605
- const base = this.profile.boneNodes?.[node] ?? node;
6606
- const prefix = this.profile.bonePrefix ?? "";
6607
- const suffix = this.profile.boneSuffix ?? "";
6608
- return `${base.startsWith(prefix) ? "" : prefix}${base}${base.endsWith(suffix) ? "" : suffix}`;
6609
- }
6610
- binding(node, id) {
6611
- const binding = this.profile.auToBones?.[id]?.find((candidate) => this.name(candidate.node) === this.name(node));
6612
- const axis = binding && axisVector(binding.channel);
6613
- const radians = finite2(binding?.maxDegrees) * finite2(binding?.scale, 1) * Math.PI / 180;
6614
- return axis && Math.abs(radians) > EPSILON ? { axis, radians } : void 0;
6615
- }
6616
- capacity(positive, negative) {
6617
- const magnitude = (id) => {
6618
- const seen = /* @__PURE__ */ new Set();
6619
- const values = [];
6620
- for (const row of this.profile.auToBones?.[id] ?? []) {
6621
- const name = this.name(row.node);
6622
- if (!axisVector(row.channel) || seen.has(name)) continue;
6623
- seen.add(name);
6624
- values.push(Math.abs(finite2(row.maxDegrees) * finite2(row.scale, 1)));
6751
+ if (target.kind === "meshVisibility") {
6752
+ const mesh = inspection.meshBindings.get(Number(target.meshId));
6753
+ return mesh && `${mesh.uuid}.visible`;
6754
+ }
6755
+ return void 0;
6756
+ }
6757
+ function cloneWithConcreteTrackNames(clip, tracks, inspection) {
6758
+ const native = clip.clone();
6759
+ for (let index = 0; index < tracks.length; index += 1) {
6760
+ const name = concreteTrackName(tracks[index].target, inspection);
6761
+ if (!name) throw new Error("Every native playback track must resolve on the bound model.");
6762
+ native.tracks[index].name = name;
6763
+ }
6764
+ return native;
6765
+ }
6766
+
6767
+ // three/nativePlayback.ts
6768
+ var sampleSize = (track) => track.getValueSize() / (track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ? 3 : 1);
6769
+ var asError = (error) => error instanceof Error ? error : new Error(String(error));
6770
+ var blendMode = (mode) => mode === "additive" ? AdditiveAnimationBlendMode : NormalAnimationBlendMode;
6771
+ var loopMode = (mode) => mode === "once" ? LoopOnce : mode === "repeat" ? LoopRepeat : LoopPingPong;
6772
+ function validateBinding(binding) {
6773
+ if (!binding.model?.isObject3D || binding.mixer && binding.mixer.getRoot() !== binding.model) {
6774
+ throw new Error("Native playback requires a Three model and its render integration mixer.");
6775
+ }
6776
+ const objects = /* @__PURE__ */ new Set();
6777
+ binding.model.traverse((object) => objects.add(object));
6778
+ const { inspection } = binding;
6779
+ for (const object of [
6780
+ ...inspection.meshBindings.values(),
6781
+ ...inspection.boneBindings.values(),
6782
+ ...inspection.objectBindings.values(),
6783
+ ...Array.from(inspection.morphBindings.values(), (entry) => entry.mesh)
6784
+ ]) {
6785
+ if (!objects.has(object)) throw new Error("Native playback inspection contains an object outside the bound model.");
6786
+ }
6787
+ }
6788
+ var ThreeNativePlaybackConnector = class {
6789
+ constructor(session, binding) {
6790
+ this.session = session;
6791
+ __publicField(this, "binding");
6792
+ __publicField(this, "rendering");
6793
+ __publicField(this, "renderingEnabled", true);
6794
+ __publicField(this, "resources", /* @__PURE__ */ new Map());
6795
+ __publicField(this, "actionHandles", /* @__PURE__ */ new Map());
6796
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
6797
+ __publicField(this, "pending", []);
6798
+ __publicField(this, "notifications", []);
6799
+ __publicField(this, "depth", 0);
6800
+ __publicField(this, "flushingNotifications", false);
6801
+ __publicField(this, "notificationScheduled", false);
6802
+ __publicField(this, "sessionDisposed", false);
6803
+ __publicField(this, "disposed", false);
6804
+ __publicField(this, "onError");
6805
+ __publicField(this, "onRelease");
6806
+ __publicField(this, "finished", (event) => {
6807
+ const handle = this.actionHandles.get(event.action);
6808
+ if (!handle || this.disposed) return;
6809
+ this.notifications.push({ type: this.resources.get(handle)?.fadingOut ? "cancelled" : "completed", handle });
6810
+ if (this.notificationScheduled) return;
6811
+ this.notificationScheduled = true;
6812
+ queueMicrotask(() => {
6813
+ this.notificationScheduled = false;
6814
+ if (this.disposed) return;
6815
+ try {
6816
+ this.flushNotifications();
6817
+ } catch (error) {
6818
+ const failure = asError(error);
6819
+ if (this.onError) this.onError(failure);
6820
+ else throw failure;
6821
+ }
6822
+ });
6823
+ });
6824
+ validateBinding(binding);
6825
+ this.binding = { ...binding, mixer: binding.mixer ?? new AnimationMixer(binding.model) };
6826
+ this.onError = binding.onError;
6827
+ this.onRelease = binding.onRelease;
6828
+ this.binding.mixer.addEventListener("finished", this.finished);
6829
+ this.rendering = bindPlaybackRendering(binding.model, this.binding.mixer, () => this.flushEvents());
6830
+ }
6831
+ /** Prepare bindings first; old actions are released before the new binding is exposed. */
6832
+ rebind(modelKey, profileKey, binding = this.binding) {
6833
+ validateBinding(binding);
6834
+ this.beforeOperation();
6835
+ this.dispatch(this.session.rebind(modelKey, profileKey), void 0, () => {
6836
+ this.binding.mixer.removeEventListener("finished", this.finished);
6837
+ this.rendering.dispose();
6838
+ this.binding = { ...binding, mixer: binding.mixer ?? new AnimationMixer(binding.model) };
6839
+ this.binding.mixer.addEventListener("finished", this.finished);
6840
+ this.rendering = bindPlaybackRendering(binding.model, this.binding.mixer, () => this.flushEvents());
6841
+ this.rendering.setEnabled(this.renderingEnabled);
6842
+ });
6843
+ }
6844
+ play(clip, options = {}) {
6845
+ this.beforeOperation();
6846
+ const native = createAnimationClipFromClipIR(clip, this.binding.inspection);
6847
+ if (native.tracks.length !== clip.tracks.length) {
6848
+ throw new Error("Every playback track must resolve on the bound model.");
6849
+ }
6850
+ return this.dispatch(this.session.play(JSON.stringify(clip), JSON.stringify(options)), native).handle;
6851
+ }
6852
+ /**
6853
+ * Validate native track bindings through the existing serializer, then retain
6854
+ * the native clone's interpolants and authored/additive sample values. Concrete
6855
+ * binding names match compiled tracks so Three shares their PropertyMixer.
6856
+ */
6857
+ playNativeClip(clip, options = {}) {
6858
+ this.beforeOperation();
6859
+ const [ir] = serializeAnimationClips(this.binding.model, [clip], this.binding.inspection);
6860
+ if (ir.tracks.length !== clip.tracks.length) {
6861
+ throw new Error("Every native playback track must serialize against the bound model.");
6862
+ }
6863
+ const native = cloneWithConcreteTrackNames(clip, ir.tracks, this.binding.inspection);
6864
+ const settings = {
6865
+ ...options,
6866
+ blendMode: options.blendMode ?? (clip.blendMode === AdditiveAnimationBlendMode ? "additive" : "normal")
6867
+ };
6868
+ return this.dispatch(this.session.play(JSON.stringify(ir), JSON.stringify(settings)), native).handle;
6869
+ }
6870
+ control(handle, control) {
6871
+ this.beforeOperation();
6872
+ this.dispatch(this.session.control(handle, JSON.stringify(control)));
6873
+ }
6874
+ setRendering(enabled) {
6875
+ this.beforeOperation();
6876
+ if (enabled === this.renderingEnabled) return;
6877
+ this.renderingEnabled = enabled;
6878
+ this.rendering.setEnabled(enabled);
6879
+ for (const resource of this.resources.values()) {
6880
+ if (!resource.action) continue;
6881
+ if (!enabled) {
6882
+ resource.suspendedPaused = resource.action.paused;
6883
+ this.pauseFade(resource);
6884
+ resource.action.paused = true;
6885
+ } else if (resource.suspendedPaused !== void 0) {
6886
+ resource.action.paused = resource.suspendedPaused;
6887
+ if (!resource.explicitlyPaused) this.resumeFade(resource);
6888
+ resource.suspendedPaused = void 0;
6889
+ }
6890
+ }
6891
+ }
6892
+ setTimeScale(value) {
6893
+ this.beforeOperation();
6894
+ if (!Number.isFinite(value)) throw new Error("Native mixer speed must be finite.");
6895
+ this.binding.mixer.timeScale = value;
6896
+ }
6897
+ fadeIn(handle, seconds) {
6898
+ this.control(handle, { type: "fadeIn", seconds });
6899
+ }
6900
+ fadeOut(handle, seconds) {
6901
+ this.control(handle, { type: "fadeOut", seconds });
6902
+ }
6903
+ /** Edit authored samples, retaining the native action and its loop/fade progress. */
6904
+ replaceClip(handle, clip) {
6905
+ this.beforeOperation();
6906
+ const resource = this.resources.get(handle);
6907
+ if (!resource) throw new Error("Unknown, foreign or stale playback handle.");
6908
+ const [ir] = serializeAnimationClips(this.binding.model, [clip], this.binding.inspection);
6909
+ if (ir.tracks.length !== clip.tracks.length) throw new Error("Every edited track must resolve on the bound model.");
6910
+ const native = cloneWithConcreteTrackNames(clip, ir.tracks, this.binding.inspection);
6911
+ if (native.tracks.length !== resource.clip.tracks.length || native.tracks.some((track, index) => {
6912
+ const old = resource.clip.tracks[index];
6913
+ return track.name !== old.name || track.ValueTypeName !== old.ValueTypeName || sampleSize(track) !== sampleSize(old);
6914
+ })) throw new Error("Editing samples must preserve track bindings; play a new clip to change its bindings.");
6915
+ const editable = resource.action;
6916
+ if (!editable || !Array.isArray(editable._interpolants) || editable._interpolants.length !== native.tracks.length) {
6917
+ throw new Error("This Three version does not support editing native action samples.");
6918
+ }
6919
+ this.dispatch(this.session.replace_clip(handle, JSON.stringify(ir)), native);
6920
+ }
6921
+ /** Native state for the owning adapter; never exposed through Polymer. */
6922
+ getAction(handle) {
6923
+ return this.resources.get(handle)?.action;
6924
+ }
6925
+ /** Deliver native completion after the borrowed mixer has finished sampling. */
6926
+ flushEvents() {
6927
+ if (this.disposed) return;
6928
+ this.notificationScheduled = false;
6929
+ for (const [handle, resource] of this.resources) {
6930
+ if (resource.fadingOut && resource.action?.getEffectiveWeight() === 0) {
6931
+ resource.fadingOut = false;
6932
+ this.notifications.push({ type: "cancelled", handle });
6625
6933
  }
6626
- return values.length ? Math.min(...values) : 0;
6934
+ }
6935
+ this.flushNotifications();
6936
+ }
6937
+ subscribe(listener) {
6938
+ if (this.disposed) throw new Error("Native playback connector is disposed.");
6939
+ this.listeners.add(listener);
6940
+ return () => {
6941
+ this.listeners.delete(listener);
6627
6942
  };
6628
- return { positive: magnitude(positive), negative: magnitude(negative) };
6629
6943
  }
6630
- joint(node, calibration, ids) {
6631
- const object = this.model.getObjectByName(this.name(node));
6632
- if (!object) return void 0;
6633
- const yaw = { positive: this.binding(node, ids[0]), negative: this.binding(node, ids[1]) };
6634
- const pitch = { positive: this.binding(node, ids[2]), negative: this.binding(node, ids[3]) };
6635
- const roll = { positive: this.binding(node, ids[4]), negative: this.binding(node, ids[5]) };
6636
- const explicit = this.profile.gazeCalibration?.[calibration]?.opticalAxis;
6637
- let optical = explicit ? vector(explicit) : new Vector3();
6638
- if (optical.lengthSq() < EPSILON) {
6639
- const positiveAxis = (axis) => axis.positive ? axis.positive.axis.clone().multiplyScalar(Math.sign(axis.positive.radians)) : axis.negative?.axis.clone().multiplyScalar(-Math.sign(axis.negative.radians));
6640
- const yawAxis = positiveAxis(yaw);
6641
- const pitchAxis = positiveAxis(pitch);
6642
- if (yawAxis && pitchAxis) optical.crossVectors(yawAxis, pitchAxis);
6643
- }
6644
- if (optical.lengthSq() < EPSILON) return void 0;
6645
- const reference = this.references.get(object);
6646
- const ancestors = [];
6647
- for (let parent = object.parent; parent && parent !== this.model; parent = parent.parent) ancestors.push(parent);
6648
- const referenceParent = new Matrix4();
6649
- for (const parent of ancestors.reverse()) referenceParent.multiply(new Matrix4().fromArray(this.references.get(parent).localMatrix));
6650
- const rotation = reference.transform.rotation;
6651
- return {
6652
- object,
6653
- optical: optical.normalize(),
6654
- yaw,
6655
- pitch,
6656
- roll,
6657
- reference: new Quaternion(rotation.x, rotation.y, rotation.z, rotation.w),
6658
- referenceParent,
6659
- referenceScale: vector(reference.transform.scale)
6944
+ dispose() {
6945
+ if (this.disposed) return;
6946
+ this.retryPending();
6947
+ if (!this.sessionDisposed) {
6948
+ const batch = this.session.dispose();
6949
+ this.sessionDisposed = true;
6950
+ this.dispatch(batch);
6951
+ }
6952
+ this.binding.mixer.removeEventListener("finished", this.finished);
6953
+ this.rendering.dispose();
6954
+ this.notifications.length = 0;
6955
+ this.listeners.clear();
6956
+ this.session.free();
6957
+ this.disposed = true;
6958
+ }
6959
+ pauseFade(resource) {
6960
+ const action = resource.action;
6961
+ const fade = action?._weightInterpolant;
6962
+ if (!action || !fade) return;
6963
+ resource.pausedFade = {
6964
+ seconds: Math.max(0, fade.parameterPositions[1] - resource.binding.mixer.time),
6965
+ from: fade.evaluate(resource.binding.mixer.time)[0],
6966
+ to: fade.sampleValues[1],
6967
+ weight: action.weight
6660
6968
  };
6969
+ action.stopFading();
6970
+ action.setEffectiveWeight(resource.pausedFade.weight * resource.pausedFade.from);
6971
+ }
6972
+ resumeFade(resource) {
6973
+ const action = resource.action;
6974
+ const fade = resource.pausedFade;
6975
+ if (!action || !fade) return;
6976
+ resource.pausedFade = void 0;
6977
+ action.setEffectiveWeight(fade.weight);
6978
+ action.fadeIn(fade.seconds);
6979
+ const interpolant = action._weightInterpolant;
6980
+ interpolant.sampleValues[0] = fade.from;
6981
+ interpolant.sampleValues[1] = fade.to;
6982
+ }
6983
+ beforeOperation() {
6984
+ if (this.disposed || this.sessionDisposed) throw new Error("Native playback connector is disposed.");
6985
+ this.retryPending();
6986
+ }
6987
+ retryPending() {
6988
+ if (this.pending.length) this.drain();
6989
+ }
6990
+ dispatch(serialized, clip, afterCommands) {
6991
+ const batch = JSON.parse(serialized);
6992
+ this.pending.push({ batch, nextCommand: 0, clip, afterCommands });
6993
+ this.drain();
6994
+ return batch;
6995
+ }
6996
+ drain() {
6997
+ const errors = [];
6998
+ this.depth += 1;
6999
+ try {
7000
+ while (this.pending.length) {
7001
+ const pending = this.pending[0];
7002
+ while (pending.nextCommand < pending.batch.commands.length) {
7003
+ const command = pending.batch.commands[pending.nextCommand];
7004
+ try {
7005
+ this.execute(command, pending.clip);
7006
+ } catch (error) {
7007
+ if (command.type === "release") throw asError(error);
7008
+ const failure = asError(error);
7009
+ errors.push(failure);
7010
+ this.notifications.push({ type: "error", handle: command.handle, message: failure.message || "Native operation failed." });
7011
+ }
7012
+ pending.nextCommand += 1;
7013
+ }
7014
+ pending.afterCommands?.();
7015
+ this.pending.shift();
7016
+ for (const event of pending.batch.events) {
7017
+ for (const listener of [...this.listeners]) {
7018
+ try {
7019
+ listener(event);
7020
+ } catch (error) {
7021
+ const failure = asError(error);
7022
+ queueMicrotask(() => {
7023
+ if (this.onError) this.onError(failure);
7024
+ else throw failure;
7025
+ });
7026
+ }
7027
+ }
7028
+ }
7029
+ }
7030
+ } finally {
7031
+ this.depth -= 1;
7032
+ }
7033
+ if (this.depth === 0 && !this.flushingNotifications) this.flushNotifications();
7034
+ if (errors.length) throw errors[0];
7035
+ }
7036
+ execute(command, preparedClip) {
7037
+ if (command.type === "release") {
7038
+ const resource2 = this.resources.get(command.handle);
7039
+ if (!resource2) return;
7040
+ resource2.action?.stop();
7041
+ resource2.binding.mixer.uncacheAction(resource2.clip, resource2.binding.model);
7042
+ resource2.binding.mixer.uncacheClip(resource2.clip);
7043
+ if (resource2.action) this.actionHandles.delete(resource2.action);
7044
+ this.resources.delete(command.handle);
7045
+ try {
7046
+ this.onRelease?.(command.handle);
7047
+ } catch (error) {
7048
+ const failure = asError(error);
7049
+ queueMicrotask(() => {
7050
+ if (this.onError) this.onError(failure);
7051
+ else throw failure;
7052
+ });
7053
+ }
7054
+ return;
7055
+ }
7056
+ if (command.type === "replaceClip") {
7057
+ const resource2 = this.resources.get(command.handle);
7058
+ if (!resource2 || !preparedClip) throw new Error("Native clip edit has no owned resource.");
7059
+ const action2 = resource2.action;
7060
+ const tracks = preparedClip.tracks.map((track) => track.clone());
7061
+ const interpolants = tracks.map((track, index) => {
7062
+ const interpolant = track.createInterpolant(action2._interpolants[index].resultBuffer);
7063
+ if (interpolant.settings) Object.assign(action2._interpolantSettings, interpolant.settings);
7064
+ interpolant.settings = action2._interpolantSettings;
7065
+ return interpolant;
7066
+ });
7067
+ resource2.clip.tracks = tracks;
7068
+ action2._interpolants = interpolants;
7069
+ return;
7070
+ }
7071
+ if (command.type === "play") {
7072
+ if (!preparedClip) throw new Error("Native playback has no prepared clip.");
7073
+ const resource2 = { clip: preparedClip, binding: this.binding };
7074
+ this.resources.set(command.handle, resource2);
7075
+ const settings = command.settings;
7076
+ const action2 = this.binding.mixer.clipAction(preparedClip, this.binding.model, blendMode(settings.blendMode));
7077
+ resource2.action = action2;
7078
+ this.actionHandles.set(action2, command.handle);
7079
+ action2.setLoop(loopMode(settings.loop.mode), settings.loop.count ?? Infinity);
7080
+ action2.clampWhenFinished = settings.finalPose === "hold";
7081
+ action2.setEffectiveTimeScale(settings.speed);
7082
+ action2.setEffectiveWeight(settings.weight);
7083
+ action2.time = settings.startSeconds;
7084
+ if (!this.renderingEnabled) {
7085
+ resource2.suspendedPaused = false;
7086
+ action2.paused = true;
7087
+ }
7088
+ action2.play();
7089
+ return;
7090
+ }
7091
+ const resource = this.resources.get(command.handle);
7092
+ const action = resource?.action;
7093
+ if (!resource || !action) throw new Error("Native playback action is unavailable.");
7094
+ const control = command.control;
7095
+ switch (control.type) {
7096
+ case "pause":
7097
+ resource.explicitlyPaused = true;
7098
+ this.pauseFade(resource);
7099
+ action.paused = true;
7100
+ if (!this.renderingEnabled) this.resources.get(command.handle).suspendedPaused = true;
7101
+ break;
7102
+ case "resume":
7103
+ resource.explicitlyPaused = false;
7104
+ if (this.renderingEnabled) {
7105
+ action.paused = false;
7106
+ this.resumeFade(resource);
7107
+ } else this.resources.get(command.handle).suspendedPaused = false;
7108
+ break;
7109
+ case "seek":
7110
+ action.time = control.seconds;
7111
+ break;
7112
+ case "setSpeed":
7113
+ action.setEffectiveTimeScale(control.speed);
7114
+ break;
7115
+ case "setWeight":
7116
+ resource.pausedFade = void 0;
7117
+ action.setEffectiveWeight(control.weight);
7118
+ this.resources.get(command.handle).fadingOut = false;
7119
+ break;
7120
+ case "setBlendMode":
7121
+ action.blendMode = blendMode(control.blendMode);
7122
+ break;
7123
+ case "setLoop":
7124
+ action.setLoop(loopMode(control.loop.mode), control.loop.count ?? Infinity);
7125
+ break;
7126
+ case "setFinalPose":
7127
+ action.clampWhenFinished = control.finalPose === "hold";
7128
+ break;
7129
+ case "fadeIn":
7130
+ resource.pausedFade = void 0;
7131
+ action.fadeIn(control.seconds);
7132
+ resource.fadingOut = false;
7133
+ if (resource.explicitlyPaused || !this.renderingEnabled) this.pauseFade(resource);
7134
+ break;
7135
+ case "fadeOut":
7136
+ resource.pausedFade = void 0;
7137
+ if (control.seconds === 0) this.notifications.push({ type: "cancelled", handle: command.handle });
7138
+ else {
7139
+ action.fadeOut(control.seconds);
7140
+ resource.fadingOut = true;
7141
+ if (resource.explicitlyPaused || !this.renderingEnabled) this.pauseFade(resource);
7142
+ }
7143
+ break;
7144
+ case "stop":
7145
+ throw new Error("Rust must translate stop into a resource release.");
7146
+ }
6661
7147
  }
6662
- restore() {
6663
- for (const [object, value] of this.saved) {
6664
- const current = object.quaternion;
6665
- const norm = Math.sqrt(current.lengthSq() * value.applied.lengthSq());
6666
- if (norm > 0 && Number.isFinite(norm) && Math.abs(current.dot(value.applied)) / norm > 1 - 1e-12) {
6667
- current.copy(value.base);
7148
+ flushNotifications() {
7149
+ if (this.flushingNotifications || this.depth > 0 || this.disposed || this.notificationScheduled) return;
7150
+ this.flushingNotifications = true;
7151
+ try {
7152
+ while (this.notifications.length) {
7153
+ const event = this.notifications.shift();
7154
+ this.dispatch(this.session.notify(JSON.stringify(event)));
6668
7155
  }
7156
+ } finally {
7157
+ this.flushingNotifications = false;
6669
7158
  }
6670
- this.saved.clear();
6671
- this.model.updateMatrixWorld(true);
6672
7159
  }
6673
- controlLimits() {
6674
- const combine = (head, eye) => ({
6675
- negative: head.negative + eye.negative,
6676
- positive: head.positive + eye.positive
7160
+ };
7161
+
7162
+ // three/character.ts
7163
+ var json2 = (value) => JSON.stringify(value ?? {});
7164
+ var targetKey = (target) => JSON.stringify([target.kind, target.meshId, target.morphTargetId, target.boneId, target.objectId, target.property]);
7165
+ var copy = (value) => JSON.parse(JSON.stringify(value));
7166
+ var parse = (value) => JSON.parse(value);
7167
+ var finite2 = (value) => typeof value === "number" && Number.isFinite(value);
7168
+ var intensity = (options, fallback = 1) => {
7169
+ const value = options.intensityScale ?? options.intensity ?? options.weight;
7170
+ return finite2(value) ? Math.max(0, Math.min(2, value)) : fallback;
7171
+ };
7172
+ var presetId = (value) => value?.trim().toLowerCase() || "cc4";
7173
+ function supportsRustEmbodyPreset(value) {
7174
+ return requireInitializedEmbodyCore().has_preset(presetId(value));
7175
+ }
7176
+ var Embody = class _Embody {
7177
+ constructor(config = {}) {
7178
+ this.config = config;
7179
+ __publicField(this, "meshes", []);
7180
+ __publicField(this, "meshByName", /* @__PURE__ */ new Map());
7181
+ __publicField(this, "bones", {});
7182
+ __publicField(this, "wasm", requireInitializedEmbodyCore());
7183
+ __publicField(this, "core");
7184
+ __publicField(this, "inspector", new ThreeModelInspector());
7185
+ __publicField(this, "applier", new ThreeFrameApplier());
7186
+ __publicField(this, "references", /* @__PURE__ */ new WeakMap());
7187
+ __publicField(this, "referenceBindings", /* @__PURE__ */ new Map());
7188
+ __publicField(this, "boundModel");
7189
+ __publicField(this, "inspection");
7190
+ __publicField(this, "connector");
7191
+ __publicField(this, "profile");
7192
+ __publicField(this, "profileSource");
7193
+ __publicField(this, "profileMode");
7194
+ __publicField(this, "preset");
7195
+ __publicField(this, "sources", /* @__PURE__ */ new Map());
7196
+ __publicField(this, "playbacks", /* @__PURE__ */ new Map());
7197
+ __publicField(this, "current", /* @__PURE__ */ new Map());
7198
+ __publicField(this, "playDepth", 0);
7199
+ __publicField(this, "pendingEvents", []);
7200
+ __publicField(this, "bindingGeneration", 0);
7201
+ __publicField(this, "disposed", false);
7202
+ __publicField(this, "rendering", true);
7203
+ __publicField(this, "timeScale", 1);
7204
+ __publicField(this, "nextLiveTarget", 0);
7205
+ __publicField(this, "liveTargets", /* @__PURE__ */ new Map());
7206
+ __publicField(this, "hairObjects", /* @__PURE__ */ new Map());
7207
+ __publicField(this, "hairConfig", {});
7208
+ __publicField(this, "hairAppearance", {
7209
+ hairColor: copy(DEFAULT_HAIR_COLOR_APPEARANCE),
7210
+ eyebrowColor: copy(DEFAULT_HAIR_COLOR_APPEARANCE),
7211
+ showOutline: false,
7212
+ outlineColor: "#000000",
7213
+ outlineOpacity: 1
6677
7214
  });
6678
- return { yaw: combine(this.limits.headYaw, this.limits.eyeYaw), pitch: combine(this.limits.headPitch, this.limits.eyePitch) };
6679
- }
6680
- angles(direction) {
6681
- const local = direction.clone().applyQuaternion(this.model.getWorldQuaternion(new Quaternion()).invert());
6682
- return {
6683
- yaw: Math.atan2(local.x, local.z) * 180 / Math.PI,
6684
- pitch: Math.atan2(local.y, Math.hypot(local.x, local.z)) * 180 / Math.PI
7215
+ const mode = config.profileMode ?? "preset";
7216
+ if (mode !== "profile" && mode !== "preset") throw new Error(`Unknown profile mode: ${mode}`);
7217
+ if (mode === "profile" && !config.profile) throw new Error("Resolved profile mode requires a profile object.");
7218
+ this.profileMode = mode;
7219
+ this.preset = presetId(config.presetId ?? config.presetType);
7220
+ if (mode === "preset" && !this.wasm.has_preset(this.preset)) throw new Error(`Unknown Embody preset: ${this.preset}`);
7221
+ this.profileSource = this.validateProfile(config.profile ?? {});
7222
+ this.profile = this.resolveProfile(this.profileSource);
7223
+ this.core = new this.wasm.RuntimeCore(0);
7224
+ }
7225
+ get model() {
7226
+ return this.boundModel;
7227
+ }
7228
+ static async create(config = {}) {
7229
+ await initEmbodyCore();
7230
+ return new _Embody(config);
7231
+ }
7232
+ assertAlive() {
7233
+ if (this.disposed) throw new Error("Character is disposed.");
7234
+ }
7235
+ requireModel() {
7236
+ this.assertAlive();
7237
+ if (!this.boundModel) throw new Error("Bind a character model with onReady before using this operation.");
7238
+ return this.boundModel;
7239
+ }
7240
+ requireConnector() {
7241
+ this.requireModel();
7242
+ if (!this.connector) throw new Error("Character playback is not bound.");
7243
+ return this.connector;
7244
+ }
7245
+ validateProfile(value) {
7246
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Embody profile must be a JSON object.");
7247
+ return copy(value);
7248
+ }
7249
+ resolveProfile(value) {
7250
+ return this.profileMode === "profile" ? copy(value) : parse(this.wasm.merge_embedded_preset(this.preset, json2(value)));
7251
+ }
7252
+ onReady(options) {
7253
+ this.assertAlive();
7254
+ const model = options.model;
7255
+ if (!model?.isObject3D) throw new Error("onReady requires a Three Object3D model.");
7256
+ const reference = this.references.get(model) ?? options.referencePose ?? (!this.boundModel ? this.config.referencePose : void 0) ?? captureModelReferencePose(model);
7257
+ const inspection = this.inspector.inspectModel(model, { meshes: options.meshes, profile: this.profile, referencePose: reference });
7258
+ this.bind(model, reference, inspection, this.profileSource, this.profile);
7259
+ if (options.animations) this.loadAnimationClips(options.animations);
7260
+ }
7261
+ bind(model, reference, inspection, source, profile, preserveLiveState = true) {
7262
+ const referenceBindings = bindModelReferencePose(model, reference);
7263
+ const runtimeDescriptor = {
7264
+ ...inspection.descriptor,
7265
+ morphTargets: inspection.descriptor.morphTargets.map((morph) => {
7266
+ const binding = inspection.morphBindings.get(morph.id);
7267
+ const baseline = binding && referenceBindings.get(binding.mesh)?.morphInfluences?.[binding.index];
7268
+ return { ...morph, initialValue: baseline ?? morph.initialValue };
7269
+ })
6685
7270
  };
7271
+ const replacingModel = !!this.boundModel && this.boundModel !== model;
7272
+ const core2 = new this.wasm.RuntimeCore(0);
7273
+ try {
7274
+ if (this.profileMode === "profile") core2.configure_with_profile(json2(source), json2(runtimeDescriptor));
7275
+ else core2.configure_with_preset(this.preset, json2(source), json2(runtimeDescriptor));
7276
+ if (preserveLiveState && this.boundModel) core2.copy_live_state_from(this.core);
7277
+ for (const registered of replacingModel ? [] : this.sources.values()) {
7278
+ if (registered.kind === "native") {
7279
+ const [clip] = serializeAnimationClips(model, [registered.clip], inspection);
7280
+ core2.register_animation_clip(json2(clip), "baked");
7281
+ }
7282
+ }
7283
+ } catch (error) {
7284
+ core2.free();
7285
+ throw error;
7286
+ }
7287
+ try {
7288
+ this.connector?.dispose();
7289
+ } catch (error) {
7290
+ core2.free();
7291
+ throw error;
7292
+ }
7293
+ this.core.free();
7294
+ this.core = core2;
7295
+ if (replacingModel) this.sources.clear();
7296
+ this.boundModel = model;
7297
+ this.inspection = inspection;
7298
+ this.referenceBindings = referenceBindings;
7299
+ this.references.set(model, reference);
7300
+ this.profileSource = source;
7301
+ this.profile = profile;
7302
+ this.bindingGeneration += 1;
7303
+ this.playbacks.clear();
7304
+ this.current.clear();
7305
+ this.liveTargets.clear();
7306
+ this.meshes.splice(0, this.meshes.length, ...inspection.morphMeshes.length ? inspection.morphMeshes : inspection.allMeshes);
7307
+ this.meshByName = inspection.meshByName;
7308
+ this.bones = inspection.bones;
7309
+ this.applier.setBindings(inspection);
7310
+ this.applier.applyMeshMaterialConfigs(model, profile.meshes ?? {});
7311
+ const session = new this.wasm.NativePlaybackSession();
7312
+ try {
7313
+ this.connector = new ThreeNativePlaybackConnector(session, {
7314
+ model,
7315
+ inspection,
7316
+ onRelease: (id) => {
7317
+ const playback = this.playbacks.get(id);
7318
+ if (playback?.terminal) this.forget(playback);
7319
+ }
7320
+ });
7321
+ } catch (error) {
7322
+ session.free();
7323
+ throw error;
7324
+ }
7325
+ this.connector.rebind(model.uuid, String(this.bindingGeneration));
7326
+ this.connector.setRendering(this.rendering);
7327
+ this.connector.setTimeScale(this.timeScale);
7328
+ this.connector.subscribe((event) => this.onPlaybackEvent(event));
7329
+ this.hairConfig = parse(this.core.get_hair_config_json());
7330
+ this.registerHairObjects(inspection.allMeshes.filter((mesh) => ["hair", "eyebrow"].includes(this.meshCategory(mesh))));
7331
+ if (preserveLiveState) this.commitLive();
7332
+ }
7333
+ bindModel(meshes) {
7334
+ const model = this.requireModel();
7335
+ const reference = this.references.get(model);
7336
+ const inspection = this.inspector.inspectModel(model, { meshes, profile: this.profile, referencePose: reference });
7337
+ this.bind(model, reference, inspection, this.profileSource, this.profile);
7338
+ }
7339
+ extendReferencePose() {
7340
+ const model = this.requireModel();
7341
+ const reference = extendModelReferencePose(model, this.references.get(model));
7342
+ const inspection = this.inspector.inspectModel(model, { profile: this.profile, referencePose: reference });
7343
+ this.bind(model, reference, inspection, this.profileSource, this.profile);
7344
+ return reference;
7345
+ }
7346
+ setProfile(value) {
7347
+ this.assertAlive();
7348
+ const source = this.validateProfile(value);
7349
+ const profile = this.resolveProfile(source);
7350
+ if (!this.boundModel) {
7351
+ this.profileSource = source;
7352
+ this.profile = profile;
7353
+ return;
7354
+ }
7355
+ const reference = this.references.get(this.boundModel);
7356
+ const inspection = this.inspector.inspectModel(this.boundModel, { profile, referencePose: reference });
7357
+ this.bind(this.boundModel, reference, inspection, source, profile, false);
6686
7358
  }
6687
- ratio(degrees, limits) {
6688
- const capacity = degrees < 0 ? limits.negative : limits.positive;
6689
- return capacity > EPSILON ? bounded(degrees / capacity) : 0;
7359
+ getProfile() {
7360
+ return this.profile;
6690
7361
  }
6691
- degrees(control, limits) {
6692
- return bounded(control) * (control < 0 ? limits.negative : limits.positive);
7362
+ getProfileMode() {
7363
+ return this.profileMode;
6693
7364
  }
6694
- direction(yawDegrees, pitchDegrees) {
6695
- const yaw = yawDegrees * Math.PI / 180;
6696
- const pitch = pitchDegrees * Math.PI / 180;
6697
- return new Vector3(Math.sin(yaw) * Math.cos(pitch), Math.sin(pitch), Math.cos(yaw) * Math.cos(pitch)).applyQuaternion(this.model.getWorldQuaternion(new Quaternion())).normalize();
7365
+ getPresetId() {
7366
+ return this.profileMode === "preset" ? this.preset : null;
6698
7367
  }
6699
- ray(joint) {
6700
- return joint.optical.clone().transformDirection(joint.object.matrixWorld);
7368
+ supportsPreset(value) {
7369
+ return supportsRustEmbodyPreset(value);
6701
7370
  }
6702
- /** Seed motor clips from the rendered bearing when enabling pose constraints. */
6703
- readControlState(options = {}) {
6704
- this.model.updateMatrixWorld(true);
6705
- const active = this.controlLimits();
6706
- const gaze = new Vector3();
6707
- const eyeBases = /* @__PURE__ */ new Map();
6708
- const eyeGain = contribution(options.eyeIntensity);
6709
- for (const eye of this.eyes) {
6710
- const value = options.eyeBaseQuaternions?.[eye.object.name];
6711
- const base = value ? new Quaternion(finite2(value.x), finite2(value.y), finite2(value.z), finite2(value.w, 1)).normalize() : (this.saved.get(eye.object)?.base ?? eye.object.quaternion).clone();
6712
- const actual = this.ray(eye);
6713
- const excursion = this.solveJoint(eye, actual, 0, base);
6714
- gaze.add(this.jointPose(
6715
- eye,
6716
- base,
6717
- eyeGain > EPSILON ? bounded(excursion.yaw / eyeGain) : 0,
6718
- eyeGain > EPSILON ? bounded(excursion.pitch / eyeGain) : 0
6719
- ).direction);
6720
- eyeBases.set(eye, { base, actual });
6721
- }
6722
- if (gaze.lengthSq() < EPSILON) gaze.copy(this.head ? this.ray(this.head) : this.direction(0, 0));
6723
- const eyes = this.angles(gaze.normalize());
6724
- let head = this.angles(this.direction(0, 0));
6725
- let headSeedLimited = false;
6726
- if (this.head) {
6727
- const value = options.headBaseQuaternion;
6728
- const base = value ? new Quaternion(finite2(value.x), finite2(value.y), finite2(value.z), finite2(value.w, 1)).normalize() : (this.saved.get(this.head.object)?.base ?? this.head.object.quaternion).clone();
6729
- const actual = this.ray(this.head);
6730
- const excursion = this.solveJoint(this.head, actual, 0, base);
6731
- const gain = contribution(options.headIntensity);
6732
- const yaw = gain > EPSILON ? bounded(excursion.yaw / gain) : 0;
6733
- const pitch = gain > EPSILON ? bounded(excursion.pitch / gain) : 0;
6734
- const preferred = this.jointPose(
6735
- this.head,
6736
- this.head.reference,
6737
- yaw,
6738
- pitch,
6739
- 0,
6740
- this.referenceParent(this.head),
6741
- this.head.referenceScale
6742
- );
6743
- head = this.angles(preferred.direction);
6744
- const represented = this.direction(
6745
- this.degrees(this.ratio(head.yaw, this.limits.headYaw), this.limits.headYaw),
6746
- this.degrees(this.ratio(head.pitch, this.limits.headPitch), this.limits.headPitch)
6747
- );
6748
- headSeedLimited = this.contributedPose(this.head, represented, 0, gain, true, base).direction.angleTo(actual) > 1e-3;
6749
- }
6750
- const destination = options.worldTarget ? this.angles(vector(options.worldTarget).sub(this.origin())) : void 0;
6751
- const eyeTarget = { x: -this.ratio(eyes.yaw, active.yaw), y: this.ratio(eyes.pitch, active.pitch), z: 0 };
6752
- const origin = this.origin();
6753
- const distance = options.worldTarget ? Math.max(EPSILON, vector(options.worldTarget).distanceTo(origin)) : 1;
6754
- const representedTarget = origin.clone().addScaledVector(this.direction(
6755
- this.degrees(-eyeTarget.x, active.yaw),
6756
- this.degrees(eyeTarget.y, active.pitch)
6757
- ), distance);
6758
- const eyeSeedLimited = this.eyes.some((eye) => {
6759
- const { base, actual } = eyeBases.get(eye);
6760
- const desired = representedTarget.clone().sub(eye.object.getWorldPosition(new Vector3())).normalize();
6761
- return this.contributedPose(eye, desired, 0, eyeGain, false, base).direction.angleTo(actual) > 1e-3;
6762
- });
6763
- return {
6764
- target: destination ? { x: -this.ratio(destination.yaw, active.yaw), y: this.ratio(destination.pitch, active.pitch), z: 0 } : void 0,
6765
- eyeTarget,
6766
- headTarget: { x: -this.ratio(head.yaw, this.limits.headYaw), y: this.ratio(head.pitch, this.limits.headPitch), z: 0 },
6767
- headRoll: 0,
6768
- headSeedLimited,
6769
- eyeSeedLimited
7371
+ onPlaybackEvent(event) {
7372
+ if (this.playDepth) {
7373
+ this.pendingEvents.push(event);
7374
+ return;
7375
+ }
7376
+ const playback = this.playbacks.get(event.handle);
7377
+ if (!playback) return;
7378
+ playback.terminal = true;
7379
+ if (!playback.connector.getAction(playback.id)) {
7380
+ this.playbacks.delete(playback.id);
7381
+ if (this.current.get(playback.source.name) === playback) this.current.delete(playback.source.name);
7382
+ }
7383
+ playback.notify({ ...event, actionId: event.handle, clipName: playback.source.name });
7384
+ }
7385
+ compile(source, options) {
7386
+ const buildOptions = { ..."options" in source ? source.options : {}, ...options, intensityScale: intensity(options) };
7387
+ switch (source.kind) {
7388
+ case "curves":
7389
+ return parse(this.core.build_clip(source.name, json2(source.input), json2(buildOptions)));
7390
+ case "typed":
7391
+ return parse(this.core.build_typed_clip(source.name, json2(source.input), json2(buildOptions)));
7392
+ case "semantic":
7393
+ return parse(this.core.build_semantic_clip(source.name, json2(source.input), json2(buildOptions)));
7394
+ case "compiled":
7395
+ return source.clip;
7396
+ case "native":
7397
+ throw new Error("Native animation sources do not require semantic compilation.");
7398
+ }
7399
+ }
7400
+ restValues(track) {
7401
+ const model = this.requireModel();
7402
+ const parsed = PropertyBinding.parseTrackName(track.name);
7403
+ let object = PropertyBinding.findNode(model, parsed.nodeName);
7404
+ if (parsed.objectName === "bones" && object) {
7405
+ const skeleton = object.skeleton;
7406
+ object = skeleton?.bones.find((bone) => bone.name === String(parsed.objectIndex)) ?? skeleton?.bones[Number(parsed.objectIndex)];
7407
+ }
7408
+ if (!object) return void 0;
7409
+ const reference = this.referenceBindings.get(object);
7410
+ if (!reference) return void 0;
7411
+ switch (parsed.propertyName) {
7412
+ case "quaternion":
7413
+ return Object.values(reference.transform.rotation);
7414
+ case "position":
7415
+ return Object.values(reference.transform.position);
7416
+ case "scale":
7417
+ return Object.values(reference.transform.scale);
7418
+ case "morphTargetInfluences": {
7419
+ const mesh = object;
7420
+ const index = typeof parsed.propertyIndex === "string" && !/^\d+$/.test(parsed.propertyIndex) ? mesh.morphTargetDictionary?.[parsed.propertyIndex] : Number(parsed.propertyIndex);
7421
+ return [reference.morphInfluences?.[index ?? -1] ?? 0];
7422
+ }
7423
+ default:
7424
+ return void 0;
7425
+ }
7426
+ }
7427
+ materialize(source, options, inheritedStarts = /* @__PURE__ */ new Map()) {
7428
+ if (!this.inspection) throw new Error("Character has no model inspection.");
7429
+ const nativeSource = source.kind === "native";
7430
+ let ir;
7431
+ if (!nativeSource) {
7432
+ ir = this.compile(source, options);
7433
+ }
7434
+ const clip = nativeSource ? source.clip.clone() : createAnimationClipFromClipIR(ir, this.inspection);
7435
+ if (ir) {
7436
+ const predecessor = this.current.get(source.name);
7437
+ const outgoing = predecessor?.connector.getAction(predecessor.id);
7438
+ for (let index = 0; index < ir.tracks.length; index += 1) {
7439
+ if (!ir.tracks[index].inheritStart) continue;
7440
+ const track = clip.tracks[index];
7441
+ if (!track) throw new Error("Every inherited track must bind to the character.");
7442
+ const startKey = `${index}:${track.name}`;
7443
+ let previous = inheritedStarts.get(startKey);
7444
+ if (!previous && options.blendMode === "additive") {
7445
+ const rest = this.restValues(track);
7446
+ const candidates = outgoing?.getClip().tracks;
7447
+ const oldTrack = candidates?.[index]?.name === track.name ? candidates[index] : candidates?.find((candidate) => candidate.name === track.name);
7448
+ if (oldTrack && outgoing) {
7449
+ previous = Array.from(oldTrack.createInterpolant().evaluate(outgoing.time));
7450
+ if (outgoing.blendMode === AdditiveAnimationBlendMode && rest) {
7451
+ previous = track.ValueTypeName === "quaternion" ? new Quaternion().fromArray(rest).multiply(new Quaternion().fromArray(previous)).toArray() : previous.map((value, axis) => value + rest[axis]);
7452
+ }
7453
+ } else if (rest) previous = rest;
7454
+ }
7455
+ if (previous) track.values.set(previous, 0);
7456
+ inheritedStarts.set(startKey, previous ?? Array.from(track.values.subarray(0, track.getValueSize())));
7457
+ }
7458
+ }
7459
+ const authoredAdditive = clip.blendMode === AdditiveAnimationBlendMode;
7460
+ const scale = intensity(options);
7461
+ const additive = options.blendMode === "additive" || options.blendMode === void 0 && authoredAdditive;
7462
+ this.applyEasing(clip, options.easing ?? "linear", nativeSource && (scale !== 1 || additive !== authoredAdditive));
7463
+ if (nativeSource && scale !== 1) {
7464
+ for (const track of clip.tracks) {
7465
+ const rest = authoredAdditive ? track.ValueTypeName === "quaternion" ? [0, 0, 0, 1] : Array(track.getValueSize()).fill(0) : this.restValues(track);
7466
+ if (!rest) continue;
7467
+ const stride = track.getValueSize();
7468
+ const cubic = track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true;
7469
+ const width = cubic ? stride / 3 : stride;
7470
+ for (let offset = 0; offset < track.values.length; offset += stride) {
7471
+ const sample = offset + (cubic ? width : 0);
7472
+ if (track.ValueTypeName === "quaternion") {
7473
+ const neutral = new Quaternion().fromArray(rest);
7474
+ const value = new Quaternion().fromArray(track.values, sample);
7475
+ neutral.slerp(value, scale).toArray(track.values, sample);
7476
+ } else {
7477
+ for (let axis = 0; axis < width; axis += 1) {
7478
+ track.values[sample + axis] = rest[axis] + (track.values[sample + axis] - rest[axis]) * scale;
7479
+ if (cubic) {
7480
+ track.values[offset + axis] *= scale;
7481
+ track.values[offset + 2 * width + axis] *= scale;
7482
+ }
7483
+ }
7484
+ }
7485
+ }
7486
+ }
7487
+ }
7488
+ if (additive && !authoredAdditive) {
7489
+ const reference = clip.clone();
7490
+ for (const track of reference.tracks) {
7491
+ const rest = this.restValues(track);
7492
+ if (!rest) continue;
7493
+ const width = track.getValueSize();
7494
+ for (let offset = 0; offset < track.values.length; offset += width) track.values.set(rest, offset);
7495
+ }
7496
+ const explicitReference = options.additiveReferenceTimeSec;
7497
+ if (finite2(explicitReference)) AnimationUtils.makeClipAdditive(clip, explicitReference * 30, clip.clone(), 30);
7498
+ else AnimationUtils.makeClipAdditive(clip, 0, reference, 30);
7499
+ }
7500
+ if (!additive && authoredAdditive) {
7501
+ for (const track of clip.tracks) {
7502
+ const rest = this.restValues(track);
7503
+ if (!rest) continue;
7504
+ const width = track.getValueSize();
7505
+ for (let offset = 0; offset < track.values.length; offset += width) {
7506
+ if (track.ValueTypeName === "quaternion") new Quaternion().fromArray(rest).multiply(new Quaternion().fromArray(track.values, offset)).toArray(track.values, offset);
7507
+ else for (let axis = 0; axis < width; axis += 1) track.values[offset + axis] += rest[axis];
7508
+ }
7509
+ }
7510
+ }
7511
+ clip.blendMode = additive ? AdditiveAnimationBlendMode : NormalAnimationBlendMode;
7512
+ return clip;
7513
+ }
7514
+ applyEasing(clip, easing, resampleCustom = false) {
7515
+ if (easing === "linear" && !resampleCustom) return;
7516
+ const curve = (progress2) => {
7517
+ switch (easing) {
7518
+ case "easeIn":
7519
+ return progress2 * progress2;
7520
+ case "easeOut":
7521
+ return 1 - (1 - progress2) ** 2;
7522
+ case "easeInOut":
7523
+ return progress2 < 0.5 ? 2 * progress2 * progress2 : 1 - (-2 * progress2 + 2) ** 2 / 2;
7524
+ case "easeInOutCubic":
7525
+ return progress2 < 0.5 ? 4 * progress2 ** 3 : 1 - (-2 * progress2 + 2) ** 3 / 2;
7526
+ default:
7527
+ return progress2;
7528
+ }
6770
7529
  };
6771
- }
6772
- origin() {
6773
- const origin = new Vector3();
6774
- for (const eye of this.eyes) origin.add(eye.object.getWorldPosition(new Vector3()));
6775
- if (this.eyes.length) origin.divideScalar(this.eyes.length);
6776
- else if (this.head) origin.copy(this.head.object.getWorldPosition(new Vector3()));
6777
- else origin.copy(this.model.getWorldPosition(new Vector3()));
6778
- return origin;
6779
- }
6780
- rotation(axis, value) {
6781
- const binding = value < 0 ? axis.negative : axis.positive;
6782
- return binding ? new Quaternion().setFromAxisAngle(binding.axis, Math.abs(bounded(value)) * binding.radians) : new Quaternion();
6783
- }
6784
- referenceParent(joint) {
6785
- return new Matrix4().multiplyMatrices(this.model.matrixWorld, joint.referenceParent);
6786
- }
6787
- jointPose(joint, base, yaw, pitch, roll = 0, parent = joint.object.parent?.matrixWorld ?? new Matrix4(), scale = joint.object.scale) {
6788
- const object = joint.object;
6789
- const quaternion = base.clone().multiply(this.rotation(joint.yaw, yaw)).multiply(this.rotation(joint.pitch, pitch)).multiply(this.rotation(joint.roll, roll));
6790
- const matrix = new Matrix4().multiplyMatrices(parent, new Matrix4().compose(object.position, quaternion, scale));
6791
- return { quaternion, direction: joint.optical.clone().transformDirection(matrix) };
6792
- }
6793
- solveJoint(joint, desired, roll = 0, base = joint.object.quaternion.clone(), parent = joint.object.parent?.matrixWorld ?? new Matrix4(), scale = joint.object.scale) {
6794
- const evaluate = (yaw2, pitch2) => this.jointPose(joint, base, yaw2, pitch2, roll, parent, scale);
6795
- let yaw = 0;
6796
- let pitch = 0;
6797
- let best = evaluate(yaw, pitch);
6798
- for (let iteration = 0; iteration < 24; iteration += 1) {
6799
- const error = desired.clone().sub(best.direction);
6800
- if (error.lengthSq() < 1e-14) break;
6801
- const derivative = (axis) => {
6802
- const value = axis === 0 ? yaw : pitch;
6803
- const lo = Math.max(-1, value - 1e-4);
6804
- const hi = Math.min(1, value + 1e-4);
6805
- return evaluate(axis === 0 ? hi : yaw, axis === 1 ? hi : pitch).direction.sub(evaluate(axis === 0 ? lo : yaw, axis === 1 ? lo : pitch).direction).divideScalar(hi - lo);
7530
+ for (const track of clip.tracks) {
7531
+ if (track.getInterpolation() === InterpolateDiscrete || track.times.length === 0) continue;
7532
+ const customInterpolant = track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true;
7533
+ if (track.times.length === 1) {
7534
+ if (customInterpolant && resampleCustom) {
7535
+ track.values = new Float32Array(track.createInterpolant().evaluate(track.times[0]));
7536
+ track.setInterpolation(InterpolateLinear);
7537
+ }
7538
+ continue;
7539
+ }
7540
+ if ((customInterpolant || track.getInterpolation() !== InterpolateLinear) && easing === "linear" && !resampleCustom) continue;
7541
+ const stride = track.getValueSize();
7542
+ const width = customInterpolant ? stride / 3 : stride;
7543
+ const interpolant = track.createInterpolant();
7544
+ const times = [];
7545
+ const values = [];
7546
+ const append = (time, value) => {
7547
+ times.push(time);
7548
+ for (let axis = 0; axis < width; axis += 1) values.push(value[axis]);
6806
7549
  };
6807
- const a = derivative(0);
6808
- const b = derivative(1);
6809
- const aa = a.dot(a) + 1e-7;
6810
- const ab = a.dot(b);
6811
- const bb = b.dot(b) + 1e-7;
6812
- const determinant = aa * bb - ab * ab;
6813
- if (determinant < 1e-14) break;
6814
- const ay = a.dot(error);
6815
- const by = b.dot(error);
6816
- const dy = Math.max(-0.5, Math.min(0.5, (ay * bb - by * ab) / determinant));
6817
- const dp = Math.max(-0.5, Math.min(0.5, (by * aa - ay * ab) / determinant));
6818
- let improved = false;
6819
- for (const step of [1, 0.5, 0.25, 0.125]) {
6820
- const nextYaw = bounded(yaw + dy * step);
6821
- const nextPitch = bounded(pitch + dp * step);
6822
- const next = evaluate(nextYaw, nextPitch);
6823
- if (next.direction.distanceToSquared(desired) < error.lengthSq()) {
6824
- yaw = nextYaw;
6825
- pitch = nextPitch;
6826
- best = next;
6827
- improved = true;
6828
- break;
7550
+ for (let index = 0; index < track.times.length - 1; index += 1) {
7551
+ const start = track.times[index];
7552
+ const end = track.times[index + 1];
7553
+ const offset = index * stride + (customInterpolant ? width : 0);
7554
+ append(start, track.values.subarray(offset, offset + width));
7555
+ if (end <= start) continue;
7556
+ for (let part = 1; part < 16; part += 1) {
7557
+ const progress2 = part / 16;
7558
+ append(start + (end - start) * progress2, interpolant.evaluate(start + (end - start) * curve(progress2)));
6829
7559
  }
6830
7560
  }
6831
- if (!improved) break;
7561
+ const lastOffset = (track.times.length - 1) * stride + (customInterpolant ? width : 0);
7562
+ append(track.times[track.times.length - 1], track.values.subarray(lastOffset, lastOffset + width));
7563
+ track.times = new Float32Array(times);
7564
+ track.values = new Float32Array(values);
7565
+ if (customInterpolant || track.getInterpolation() !== InterpolateLinear) track.setInterpolation(InterpolateLinear);
6832
7566
  }
6833
- return { ...best, limited: best.direction.angleTo(desired) > 1e-3, yaw, pitch };
6834
7567
  }
6835
- contributedPose(joint, desired, roll, intensity, fromReference, base = joint.object.quaternion.clone()) {
6836
- const full = fromReference ? this.solveJoint(joint, desired, roll, joint.reference, this.referenceParent(joint), joint.referenceScale) : this.solveJoint(joint, desired, roll, base);
6837
- const gain = contribution(intensity);
6838
- const result = this.jointPose(joint, base, full.yaw * gain, full.pitch * gain, bounded(roll) * gain);
6839
- return { ...result, limited: result.direction.angleTo(desired) > 1e-3 };
7568
+ nativeOptions(options, clip) {
7569
+ const mode = clip.duration === 0 ? "once" : options.loopMode ?? (options.loop === true ? "repeat" : "once");
7570
+ const count = finite2(options.repeatCount) && options.repeatCount > 0 ? options.repeatCount : null;
7571
+ let speed = options.speed ?? options.playbackRate ?? options.rate ?? options.timeScale ?? 1;
7572
+ if (options.reverse === true) speed = -Math.abs(speed);
7573
+ return {
7574
+ startSeconds: finite2(options.time) ? options.time : finite2(options.offsetSec) ? options.offsetSec : speed < 0 ? clip.duration : 0,
7575
+ speed,
7576
+ weight: finite2(options.mixerWeight) ? options.mixerWeight : 1,
7577
+ blendMode: clip.blendMode === AdditiveAnimationBlendMode ? "additive" : "normal",
7578
+ loop: { mode: mode === "once" ? "once" : mode === "pingpong" || mode === "pingPong" ? "pingPong" : "repeat", count: mode === "once" ? 1 : count },
7579
+ finalPose: options.finalPose === "release" || options.clampWhenFinished === false ? "release" : "hold"
7580
+ };
6840
7581
  }
6841
- solve(joint, desired, roll = 0, intensity = 1, fromReference = false) {
6842
- const result = this.contributedPose(joint, desired, roll, intensity, fromReference);
6843
- this.saved.set(joint.object, { base: joint.object.quaternion.clone(), applied: result.quaternion.clone() });
6844
- joint.object.quaternion.copy(result.quaternion);
6845
- joint.object.updateMatrixWorld(true);
6846
- return result;
7582
+ validateEasing(options) {
7583
+ if (options.easing !== void 0 && !["linear", "easeIn", "easeOut", "easeInOut", "easeInOutCubic"].includes(options.easing)) throw new Error(`Unknown playback easing: ${options.easing}`);
6847
7584
  }
6848
- apply(request2, controls) {
6849
- this.restore();
6850
- const active = this.controlLimits();
6851
- const intendedWorldTarget = vector(request2.worldTarget);
6852
- const origin = this.origin();
6853
- const intendedOffset = intendedWorldTarget.clone().sub(origin);
6854
- const intendedBearing = this.angles(intendedOffset);
6855
- const remainingYaw = this.degrees(-finite2(controls.eyeYaw), active.yaw) - this.degrees(-finite2(request2.target?.x), active.yaw);
6856
- const remainingPitch = this.degrees(finite2(controls.eyePitch), active.pitch) - this.degrees(finite2(request2.target?.y), active.pitch);
6857
- const target = origin.clone().addScaledVector(
6858
- this.direction(intendedBearing.yaw + remainingYaw, intendedBearing.pitch + remainingPitch),
6859
- intendedOffset.length()
6860
- );
6861
- let headLimited = false;
6862
- const headControlsPresent = controls.headYaw !== void 0 || controls.headPitch !== void 0 || controls.headRoll !== void 0;
6863
- const eyeControlsPresent = controls.eyeYaw !== void 0 || controls.eyePitch !== void 0;
6864
- if (request2.headEnabled !== false && headControlsPresent && this.head) {
6865
- headLimited = this.solve(this.head, this.direction(
6866
- this.degrees(-finite2(controls.headYaw), this.limits.headYaw),
6867
- this.degrees(finite2(controls.headPitch), this.limits.headPitch)
6868
- ), finite2(controls.headRoll), contribution(controls.headIntensity ?? request2.headIntensity), true).limited;
6869
- }
6870
- const eyes = [];
6871
- for (const eye of this.eyes) {
6872
- const eyeOrigin = eye.object.getWorldPosition(new Vector3());
6873
- const desired = target.clone().sub(eyeOrigin).normalize();
6874
- const solved = request2.eyesEnabled !== false && eyeControlsPresent ? this.solve(eye, desired, 0, contribution(controls.eyeIntensity ?? request2.eyeIntensity)) : { limited: false };
6875
- const direction = this.ray(eye);
6876
- eyes.push({
6877
- name: eye.object.name,
6878
- origin: point2(eyeOrigin),
6879
- direction: point2(direction),
6880
- errorDegrees: direction.angleTo(desired) * 180 / Math.PI,
6881
- limited: solved.limited
7585
+ handle(source, options, autoPlay) {
7586
+ options = { ..."options" in source ? source.options : {}, ...options };
7587
+ const listeners = /* @__PURE__ */ new Set();
7588
+ const generation = this.bindingGeneration;
7589
+ let current;
7590
+ let resolvePromise = () => {
7591
+ };
7592
+ const result = { name: source.name };
7593
+ Object.defineProperty(result, "finished", { get: () => result.promise, enumerable: true });
7594
+ const newPromise = () => {
7595
+ result.promise = new Promise((resolve) => {
7596
+ resolvePromise = resolve;
6882
7597
  });
7598
+ };
7599
+ newPromise();
7600
+ result.subscribe = (listener) => {
7601
+ const callback = typeof listener === "function" ? listener : (event) => listener.next(event);
7602
+ listeners.add(callback);
7603
+ return () => {
7604
+ listeners.delete(callback);
7605
+ };
7606
+ };
7607
+ const start = () => {
7608
+ if (generation !== this.bindingGeneration) throw new Error("Playback handle belongs to an obsolete model binding.");
7609
+ this.validateEasing(options);
7610
+ const connector = this.requireConnector();
7611
+ const inheritedStarts = /* @__PURE__ */ new Map();
7612
+ const clip = this.materialize(source, options, inheritedStarts);
7613
+ const hairMotion = this.authoredHeadMotion(clip);
7614
+ const previous = this.current.get(source.name);
7615
+ const settings = this.nativeOptions(options, clip);
7616
+ if (previous && connector.getAction(previous.id)) settings.replace = previous.id;
7617
+ if (current) newPromise();
7618
+ const resolve = resolvePromise;
7619
+ let settled = false;
7620
+ this.playDepth += 1;
7621
+ let id;
7622
+ try {
7623
+ id = connector.playNativeClip(clip, settings);
7624
+ } catch (error) {
7625
+ this.playDepth -= 1;
7626
+ while (!this.playDepth && this.pendingEvents.length) this.onPlaybackEvent(this.pendingEvents.shift());
7627
+ throw error;
7628
+ }
7629
+ const playback = {
7630
+ id,
7631
+ source,
7632
+ options: { ...options, intensityScale: intensity(options) },
7633
+ connector,
7634
+ terminal: false,
7635
+ inheritedStarts,
7636
+ replay: (next) => {
7637
+ options = next;
7638
+ return start();
7639
+ },
7640
+ notify: (event) => {
7641
+ if (settled) return;
7642
+ settled = true;
7643
+ resolve(event);
7644
+ for (const listener of [...listeners]) {
7645
+ try {
7646
+ listener(event);
7647
+ } catch (error) {
7648
+ queueMicrotask(() => {
7649
+ throw error;
7650
+ });
7651
+ }
7652
+ }
7653
+ }
7654
+ };
7655
+ current = playback;
7656
+ result.actionId = id;
7657
+ this.playbacks.set(id, playback);
7658
+ this.current.set(source.name, playback);
7659
+ const ensure = () => {
7660
+ this.assertAlive();
7661
+ if (this.connector !== connector || !connector.getAction(id)) throw new Error("Unknown, released or obsolete playback handle.");
7662
+ };
7663
+ const control = (command) => {
7664
+ ensure();
7665
+ connector.control(id, command);
7666
+ if (command.type === "stop") this.forget(playback);
7667
+ return result;
7668
+ };
7669
+ result.stop = result.cancel = () => {
7670
+ if (this.connector !== connector || !connector.getAction(id)) return result;
7671
+ ensure();
7672
+ const seconds = finite2(playback.options.fadeOutSec) ? playback.options.fadeOutSec : 0;
7673
+ if (seconds > 0 && !playback.terminal) connector.fadeOut(id, seconds);
7674
+ else control({ type: "stop" });
7675
+ return result;
7676
+ };
7677
+ result.pause = () => control({ type: "pause" });
7678
+ result.resume = () => {
7679
+ ensure();
7680
+ if (playback.terminal) {
7681
+ options = { ...playback.options, time: connector.getAction(id).time };
7682
+ return start();
7683
+ }
7684
+ return control({ type: "resume" });
7685
+ };
7686
+ result.setSpeed = result.setPlaybackRate = (speed) => {
7687
+ ensure();
7688
+ this.updatePlayback(playback, { speed });
7689
+ return result;
7690
+ };
7691
+ result.setTime = result.seek = (seconds) => control({ type: "seek", seconds });
7692
+ result.setWeight = result.setIntensity = (value) => {
7693
+ ensure();
7694
+ this.updatePlayback(playback, { intensityScale: value });
7695
+ return result;
7696
+ };
7697
+ result.updateParams = result.setParams = (value) => {
7698
+ ensure();
7699
+ this.updatePlayback(playback, value);
7700
+ return result;
7701
+ };
7702
+ try {
7703
+ const fade = options.fadeInSec ?? options.crossfadeDuration;
7704
+ if (finite2(fade) && fade > 0) connector.fadeIn(id, fade);
7705
+ } finally {
7706
+ this.playDepth -= 1;
7707
+ while (!this.playDepth && this.pendingEvents.length) this.onPlaybackEvent(this.pendingEvents.shift());
7708
+ }
7709
+ if (hairMotion && connector.getAction(id)) {
7710
+ this.playHairImpulse(hairMotion.horizontal, hairMotion.vertical);
7711
+ this.setHairGravity(hairMotion.pitch, clip.duration);
7712
+ }
7713
+ return result;
7714
+ };
7715
+ result.play = () => {
7716
+ if (current) options = { ...current.options };
7717
+ return start();
7718
+ };
7719
+ const beforePlay = () => {
7720
+ throw new Error("Play this compiled clip before changing playback.");
7721
+ };
7722
+ result.stop = result.cancel = () => result;
7723
+ result.pause = result.resume = beforePlay;
7724
+ result.updateParams = result.setParams = (patch) => {
7725
+ this.assertAlive();
7726
+ this.validateEasing(patch);
7727
+ options = { ...options, ...patch };
7728
+ if ("finalPose" in patch && !("clampWhenFinished" in patch)) options.clampWhenFinished = patch.finalPose !== "release";
7729
+ if ("clampWhenFinished" in patch && !("finalPose" in patch)) options.finalPose = patch.clampWhenFinished === false ? "release" : "hold";
7730
+ if ("loop" in patch && !("loopMode" in patch)) options.loopMode = patch.loop ? "repeat" : "once";
7731
+ if ("loopMode" in patch && !("repeatCount" in patch)) delete options.repeatCount;
7732
+ if ("weight" in patch || "intensity" in patch || "intensityScale" in patch) options.intensityScale = intensity(patch);
7733
+ if ("time" in patch || "offsetSec" in patch) options.time = patch.time ?? patch.offsetSec;
7734
+ if ("speed" in patch || "playbackRate" in patch || "rate" in patch || "timeScale" in patch || "reverse" in patch) {
7735
+ let speed = patch.speed ?? patch.playbackRate ?? patch.rate ?? patch.timeScale ?? options.speed ?? options.playbackRate ?? options.rate ?? options.timeScale ?? 1;
7736
+ if ("reverse" in patch) speed = Math.abs(speed) * (patch.reverse ? -1 : 1);
7737
+ options.speed = speed;
7738
+ delete options.reverse;
7739
+ }
7740
+ return result;
7741
+ };
7742
+ result.setWeight = result.setIntensity = (value) => result.updateParams({ intensityScale: value });
7743
+ result.setSpeed = result.setPlaybackRate = (speed) => result.updateParams({ speed });
7744
+ result.setTime = result.seek = (time) => result.updateParams({ time });
7745
+ return autoPlay ? start() : result;
7746
+ }
7747
+ forget(playback) {
7748
+ this.playbacks.delete(playback.id);
7749
+ if (this.current.get(playback.source.name) === playback) this.current.delete(playback.source.name);
7750
+ }
7751
+ updatePlayback(playback, patch) {
7752
+ this.validateEasing(patch);
7753
+ const connector = playback.connector;
7754
+ const action = connector.getAction(playback.id);
7755
+ if (connector !== this.connector || !action) throw new Error("Unknown, released or obsolete playback handle.");
7756
+ const options = { ...playback.options, ...patch };
7757
+ if ("finalPose" in patch && !("clampWhenFinished" in patch)) options.clampWhenFinished = patch.finalPose !== "release";
7758
+ if ("clampWhenFinished" in patch && !("finalPose" in patch)) options.finalPose = patch.clampWhenFinished === false ? "release" : "hold";
7759
+ if ("loop" in patch && !("loopMode" in patch)) options.loopMode = patch.loop ? "repeat" : "once";
7760
+ if ("loopMode" in patch && !("repeatCount" in patch)) delete options.repeatCount;
7761
+ if ("weight" in patch || "intensity" in patch || "intensityScale" in patch) options.intensityScale = intensity(patch);
7762
+ if (["weight", "intensity", "intensityScale", "blendMode", "easing", "balance", "balanceMap", "mixWeights"].some((key) => key in patch)) {
7763
+ const clip = this.materialize(playback.source, options, playback.inheritedStarts);
7764
+ connector.replaceClip(playback.id, clip);
7765
+ if ("blendMode" in patch) connector.control(playback.id, { type: "setBlendMode", blendMode: clip.blendMode === AdditiveAnimationBlendMode ? "additive" : "normal" });
7766
+ }
7767
+ if ("mixerWeight" in patch) connector.control(playback.id, { type: "setWeight", weight: patch.mixerWeight });
7768
+ if ("speed" in patch || "playbackRate" in patch || "rate" in patch || "timeScale" in patch || "reverse" in patch) {
7769
+ let speed = patch.speed ?? patch.playbackRate ?? patch.rate ?? patch.timeScale ?? action.timeScale;
7770
+ if ("reverse" in patch) speed = Math.abs(speed) * (patch.reverse ? -1 : 1);
7771
+ connector.control(playback.id, { type: "setSpeed", speed });
7772
+ options.speed = speed;
7773
+ delete options.reverse;
7774
+ }
7775
+ if ("time" in patch || "offsetSec" in patch) {
7776
+ options.time = patch.time ?? patch.offsetSec;
7777
+ connector.control(playback.id, { type: "seek", seconds: options.time });
7778
+ }
7779
+ if ("loopMode" in patch || "loop" in patch || "repeatCount" in patch) {
7780
+ if (playback.terminal) {
7781
+ playback.replay({ ...options, time: action.time });
7782
+ return;
7783
+ }
7784
+ connector.control(playback.id, { type: "setLoop", loop: this.nativeOptions(options, action.getClip()).loop });
6883
7785
  }
6884
- return { target: point2(target), eyes, headLimited, missingHead: !this.head, missingEyes: this.eyes.length < 2 };
7786
+ if ("clampWhenFinished" in patch || "finalPose" in patch) connector.control(playback.id, { type: "setFinalPose", finalPose: this.nativeOptions(options, action.getClip()).finalPose });
7787
+ playback.options = options;
7788
+ if (!connector.getAction(playback.id)) this.forget(playback);
6885
7789
  }
6886
- };
6887
- var draco = null;
6888
- var dracoPath = "";
6889
- var gltfLoader = null;
6890
- var gltfLoaderUsesDraco = false;
6891
- var fbxLoader = null;
6892
- var getGltfLoader = (dracoDecoderPath) => {
6893
- const wantsDraco = typeof dracoDecoderPath === "string" && dracoDecoderPath.length > 0;
6894
- const normalizedPath = wantsDraco ? dracoDecoderPath.endsWith("/") ? dracoDecoderPath : `${dracoDecoderPath}/` : "";
6895
- if (!gltfLoader || gltfLoaderUsesDraco !== wantsDraco || wantsDraco && normalizedPath !== dracoPath) {
6896
- draco?.dispose();
6897
- draco = null;
6898
- dracoPath = normalizedPath;
6899
- gltfLoaderUsesDraco = wantsDraco;
6900
- gltfLoader = new GLTFLoader();
6901
- if (wantsDraco) {
6902
- draco = new DRACOLoader().setDecoderPath(normalizedPath).setDecoderConfig({ type: "wasm" });
6903
- gltfLoader.setDRACOLoader(draco);
7790
+ registerAnimationClips(clips) {
7791
+ const model = this.requireModel();
7792
+ for (const clip of clips) {
7793
+ if (this.sources.get(clip.name)?.kind === "native" && this.sources.get(clip.name).clip === clip) continue;
7794
+ const [ir] = serializeAnimationClips(model, [clip], this.inspection);
7795
+ this.core.register_animation_clip(json2(ir), "baked");
7796
+ this.sources.set(clip.name, { name: clip.name, kind: "native", clip });
6904
7797
  }
6905
7798
  }
6906
- return gltfLoader;
6907
- };
6908
- var prepare = (model, castShadows = true) => {
6909
- const meshes = [];
6910
- model.traverse((object) => {
6911
- if (!object.isMesh) return;
6912
- if (castShadows) object.castShadow = true;
6913
- if (object.morphTargetInfluences?.length) meshes.push(object);
6914
- });
6915
- return meshes;
6916
- };
6917
- var progress = (listener) => {
6918
- let last = -1;
6919
- return (event) => {
6920
- if (!listener || !event.lengthComputable) return;
6921
- const next = Math.min(100, Math.max(0, Math.round(event.loaded / event.total * 100)));
6922
- if (next !== last) {
6923
- last = next;
6924
- listener(next);
7799
+ loadAnimationClips(clips) {
7800
+ this.stopAllAnimations();
7801
+ for (const source of [...this.sources.values()]) if (source.kind === "native") {
7802
+ this.sources.delete(source.name);
7803
+ this.core.remove_animation_clip(source.name);
6925
7804
  }
6926
- };
6927
- };
6928
- function applyCharacterModelTransform(model, value = {}) {
6929
- if (value.modelOffset) model.position.set(value.modelOffset.x ?? 0, value.modelOffset.y ?? 0, value.modelOffset.z ?? 0);
6930
- if (value.modelRotation) model.rotation.set(...["x", "y", "z"].map((axis) => (value.modelRotation?.[axis] ?? 0) * Math.PI / 180));
6931
- if (Number.isFinite(value.modelScale) && (value.modelScale ?? 0) > 0) model.scale.setScalar(value.modelScale);
6932
- if (Number.isFinite(value.modelGroundClearance)) {
6933
- model.updateMatrixWorld(true);
6934
- const min = new Box3().setFromObject(model).min.y;
6935
- if (Number.isFinite(min) && min < value.modelGroundClearance) model.position.y += value.modelGroundClearance - min;
7805
+ this.registerAnimationClips(clips ?? []);
7806
+ this.restartHair();
6936
7807
  }
6937
- }
6938
- function disposeCharacterModel(scene, model) {
6939
- scene?.remove(model);
6940
- model.traverse((object) => {
6941
- object.geometry?.dispose?.();
6942
- for (const material of object.material ? Array.isArray(object.material) ? object.material : [object.material] : []) {
6943
- for (const value of Object.values(material)) if (value?.isTexture) value.dispose?.();
7808
+ removeAnimationClip(name) {
7809
+ this.stopAnimation(name);
7810
+ this.sources.delete(name);
7811
+ return this.core.remove_animation_clip(name);
7812
+ }
7813
+ getAnimationClips() {
7814
+ return parse(this.core.get_animation_clips());
7815
+ }
7816
+ playAnimation(name, options = {}) {
7817
+ const source = this.sources.get(name);
7818
+ if (!source) throw new Error(`Unknown animation clip: ${name}`);
7819
+ return this.handle(source, options, true);
7820
+ }
7821
+ build(source, options, play) {
7822
+ this.requireModel();
7823
+ this.validateEasing(options);
7824
+ this.compile(source, options);
7825
+ this.sources.set(source.name, source);
7826
+ return this.handle(source, options, play);
7827
+ }
7828
+ buildClip(name, curves, options = {}) {
7829
+ return options.semanticAnimation ? this.semanticAnimationToClip(name, options.semanticAnimation, { ...options, faceCurves: curves }) : this.build({ name, kind: "curves", input: copy(curves), options: copy(options) }, options, false);
7830
+ }
7831
+ snippetToClip(name, curves, options = {}) {
7832
+ return this.buildClip(name, curves, options);
7833
+ }
7834
+ buildTypedClip(name, channels, options = {}) {
7835
+ return this.build({ name, kind: "typed", input: copy(channels), options: copy(options) }, options, false);
7836
+ }
7837
+ typedSnippetToClip(name, channels, options = {}) {
7838
+ return this.buildTypedClip(name, channels, options);
7839
+ }
7840
+ semanticAnimationToClip(name, animation, options = {}) {
7841
+ return this.build({ name, kind: "semantic", input: copy(animation), options: copy(options) }, options, false);
7842
+ }
7843
+ playSnippet(snippet, curvesOrOptions = {}, options = {}) {
7844
+ return typeof snippet === "string" ? this.buildClip(snippet, curvesOrOptions, options).play() : this.buildClip(snippet.name, snippet.curves, curvesOrOptions).play();
7845
+ }
7846
+ playTypedSnippet(snippet, options = {}) {
7847
+ return this.buildTypedClip(snippet.name, snippet.channels, options).play();
7848
+ }
7849
+ playClip(value) {
7850
+ return typeof value === "string" ? this.playAnimation(value) : value.play();
7851
+ }
7852
+ supportsClipCurves() {
7853
+ return true;
7854
+ }
7855
+ cleanupSnippet(name) {
7856
+ this.stopAnimation(name);
7857
+ this.sources.delete(name);
7858
+ this.core.cleanup_snippet(name);
7859
+ }
7860
+ crossfadeTo(name, seconds, options = {}) {
7861
+ const outgoing = [...this.current.values()].filter((playback) => !playback.source.name.startsWith("__embody_"));
7862
+ const handle = this.playAnimation(name, { ...options, fadeInSec: seconds });
7863
+ for (const playback of outgoing) if (playback.connector.getAction(playback.id)) playback.connector.fadeOut(playback.id, seconds);
7864
+ return handle;
7865
+ }
7866
+ stopAnimation(name) {
7867
+ const playback = this.current.get(name);
7868
+ if (!playback) return;
7869
+ if (playback.connector.getAction(playback.id)) playback.connector.control(playback.id, { type: "stop" });
7870
+ this.forget(playback);
7871
+ }
7872
+ stopAllAnimations() {
7873
+ for (const playback of [...this.playbacks.values()]) {
7874
+ if (playback.source.kind === "compiled") continue;
7875
+ if (playback.connector.getAction(playback.id)) playback.connector.control(playback.id, { type: "stop" });
7876
+ this.forget(playback);
7877
+ }
7878
+ }
7879
+ pauseAnimation(name) {
7880
+ const p = this.current.get(name);
7881
+ if (p) p.connector.control(p.id, { type: "pause" });
7882
+ }
7883
+ resumeAnimation(name) {
7884
+ const p = this.current.get(name);
7885
+ if (!p) return;
7886
+ if (p.terminal) p.replay({ ...p.options, time: p.connector.getAction(p.id)?.time ?? 0 });
7887
+ else p.connector.control(p.id, { type: "resume" });
7888
+ }
7889
+ pauseAllAnimations() {
7890
+ for (const p of this.playbacks.values()) if (!p.terminal) p.connector.control(p.id, { type: "pause" });
7891
+ }
7892
+ resumeAllAnimations() {
7893
+ for (const name of [...this.current.keys()]) this.resumeAnimation(name);
7894
+ }
7895
+ updateClipParams(name, options) {
7896
+ const p = this.current.get(name);
7897
+ if (p) this.updatePlayback(p, options);
7898
+ }
7899
+ setAnimationSpeed(name, value) {
7900
+ this.updateClipParams(name, { speed: value });
7901
+ }
7902
+ setAnimationIntensity(name, value) {
7903
+ this.updateClipParams(name, { intensityScale: value });
7904
+ }
7905
+ setAnimationLoop(name, value) {
7906
+ this.updateClipParams(name, { loopMode: value ? "repeat" : "once" });
7907
+ }
7908
+ setAnimationLoopMode(name, value) {
7909
+ this.updateClipParams(name, { loopMode: value });
7910
+ }
7911
+ setAnimationRepeatCount(name, value) {
7912
+ this.updateClipParams(name, { loopMode: "repeat", repeatCount: value });
7913
+ }
7914
+ setAnimationReverse(name, value) {
7915
+ this.updateClipParams(name, { reverse: value });
7916
+ }
7917
+ setAnimationBlendMode(name, value) {
7918
+ this.updateClipParams(name, { blendMode: value });
7919
+ }
7920
+ setAnimationEasing(name, value) {
7921
+ this.validateEasing({ easing: value });
7922
+ this.updateClipParams(name, { easing: value });
7923
+ }
7924
+ seekAnimation(name, value) {
7925
+ this.updateClipParams(name, { time: value });
7926
+ }
7927
+ setAnimationTime(name, value) {
7928
+ this.seekAnimation(name, value);
7929
+ }
7930
+ setSnippetTime(name, value) {
7931
+ this.seekAnimation(name, value);
7932
+ }
7933
+ seekSnippet(name, value) {
7934
+ this.seekAnimation(name, value);
7935
+ }
7936
+ seek(name, value) {
7937
+ this.seekAnimation(name, value);
7938
+ }
7939
+ setAnimationTimeScale(value) {
7940
+ this.requireConnector().setTimeScale(value);
7941
+ this.timeScale = value;
7942
+ }
7943
+ getAnimationState(name) {
7944
+ const p = this.current.get(name);
7945
+ const action = p?.connector.getAction(p.id);
7946
+ if (!action || !p) {
7947
+ if (p) this.forget(p);
7948
+ return { name, playing: false, isPlaying: false };
7949
+ }
7950
+ const playing = action.isRunning();
7951
+ return {
7952
+ name,
7953
+ actionId: p.id,
7954
+ playing,
7955
+ isPlaying: playing,
7956
+ paused: action.paused,
7957
+ completed: p.terminal,
7958
+ time: action.time,
7959
+ duration: action.getClip().duration,
7960
+ speed: action.timeScale,
7961
+ intensityScale: intensity(p.options),
7962
+ mixerWeight: action.getEffectiveWeight(),
7963
+ loopMode: action.loop === LoopOnce ? "once" : action.loop === LoopPingPong ? "pingpong" : "repeat",
7964
+ repeatCount: Number.isFinite(action.repetitions) ? action.repetitions : null,
7965
+ blendMode: action.blendMode === AdditiveAnimationBlendMode ? "additive" : "replace"
7966
+ };
7967
+ }
7968
+ getPlayingAnimations() {
7969
+ return [...this.current.keys()].filter((name) => this.getAnimationState(name).playing);
7970
+ }
7971
+ commitLive(durationMs = 0) {
7972
+ const connector = this.requireConnector();
7973
+ const duration = Math.max(0, durationMs) / 1e3;
7974
+ const clip = parse(this.core.build_live_clip("__embody_live", duration));
7975
+ const touched = new Set(parse(this.core.live_command_targets_json()).map(targetKey));
7976
+ const tracks = new Map(clip.tracks.map((track) => [targetKey(track.target), track]));
7977
+ const handles = [];
7978
+ for (const [key, previous] of this.liveTargets) {
7979
+ if (tracks.has(key)) continue;
7980
+ if (previous.releasing && !touched.has(key)) continue;
7981
+ const action = previous.handle.actionId && connector.getAction(previous.handle.actionId);
7982
+ if (!action || duration === 0) {
7983
+ previous.handle.stop();
7984
+ this.liveTargets.delete(key);
7985
+ continue;
7986
+ }
7987
+ const nativeTrack = action.getClip().tracks[0];
7988
+ const sample = Array.from(nativeTrack.createInterpolant().evaluate(action.time));
7989
+ const released = { ...previous.track, times: [0, duration], values: [...sample, ...sample], inheritStart: false };
7990
+ const releaseClip = { ...clip, name: previous.handle.name, tracks: [released] };
7991
+ const handle = this.handle(
7992
+ { name: releaseClip.name, kind: "compiled", clip: releaseClip },
7993
+ { loopMode: "once", finalPose: "release", mixerWeight: action.getEffectiveWeight() },
7994
+ true
7995
+ );
7996
+ connector.fadeOut(handle.actionId, duration);
7997
+ const record = { track: released, handle, releasing: true };
7998
+ this.liveTargets.set(key, record);
7999
+ void handle.promise.then(() => {
8000
+ if (this.liveTargets.get(key) === record) this.liveTargets.delete(key);
8001
+ });
8002
+ handles.push(handle);
8003
+ }
8004
+ for (const [key, track] of tracks) {
8005
+ const previous = this.liveTargets.get(key);
8006
+ const endpoint = (value) => value.values.slice(value.values.length / value.times.length * (value.times.length - 1));
8007
+ if (previous && !previous.releasing && !touched.has(key) && json2(endpoint(previous.track)) === json2(endpoint(track))) continue;
8008
+ const name = previous?.handle.name ?? `__embody_live_${this.nextLiveTarget++}`;
8009
+ const outgoing = previous?.handle.actionId && connector.getAction(previous.handle.actionId);
8010
+ let nativeTrack = track;
8011
+ if (duration > 0 && outgoing) {
8012
+ const start = Array.from(outgoing.getClip().tracks[0].createInterpolant().evaluate(outgoing.time));
8013
+ nativeTrack = { ...track, values: [...start, ...endpoint(track)], inheritStart: false };
8014
+ }
8015
+ const targetClip = { ...clip, name, tracks: [nativeTrack] };
8016
+ const handle = this.handle({ name, kind: "compiled", clip: targetClip }, { loopMode: "once", finalPose: "hold" }, true);
8017
+ this.liveTargets.set(key, { track, handle, releasing: false });
8018
+ handles.push(handle);
8019
+ }
8020
+ return handles;
8021
+ }
8022
+ mutateLive(mutate, durationMs = 0) {
8023
+ this.requireModel();
8024
+ this.core.begin_live_command();
8025
+ mutate();
8026
+ return this.commitLive(durationMs);
8027
+ }
8028
+ transition(handles) {
8029
+ let settled = handles.length === 0;
8030
+ const promise = Promise.all(handles.map((handle) => handle.promise)).then(() => {
8031
+ settled = true;
8032
+ });
8033
+ const control = (command) => {
8034
+ if (settled) return;
8035
+ for (const handle of handles) {
8036
+ const playback = handle.actionId && this.playbacks.get(handle.actionId);
8037
+ if (!playback || !playback.connector.getAction(playback.id)) continue;
8038
+ if (command === "cancel" || !playback.terminal) handle[command]();
8039
+ }
8040
+ };
8041
+ return { promise, pause: () => control("pause"), resume: () => control("resume"), cancel: () => control("cancel") };
8042
+ }
8043
+ setAU(id, value, balance = this.core.get_au_balance(id)) {
8044
+ this.mutateLive(() => this.core.set_au_signed(id, value, balance));
8045
+ }
8046
+ getAU(id) {
8047
+ return this.core.get_au(id);
8048
+ }
8049
+ getAUBalance(id) {
8050
+ return this.core.get_au_balance(id);
8051
+ }
8052
+ getBodyControls() {
8053
+ return parse(this.core.get_body_controls_json());
8054
+ }
8055
+ getSemanticPoseCatalog() {
8056
+ return parse(this.core.get_semantic_pose_catalog_json());
8057
+ }
8058
+ captureSemanticPose() {
8059
+ return parse(this.core.capture_semantic_pose_json());
8060
+ }
8061
+ validateSemanticPose(pose) {
8062
+ return parse(this.core.validate_semantic_pose_json(json2(pose)));
8063
+ }
8064
+ applySemanticPose(pose) {
8065
+ this.mutateLive(() => this.core.apply_semantic_pose_json(json2(pose)));
8066
+ }
8067
+ validateSemanticAnimation(animation, options = {}) {
8068
+ this.core.validate_semantic_animation_json(json2(animation), json2(options));
8069
+ }
8070
+ resetBodyControls() {
8071
+ this.mutateLive(() => this.core.reset_body_controls());
8072
+ }
8073
+ setContinuum(negative, positive, value, balance = NaN) {
8074
+ this.mutateLive(() => this.core.set_continuum(negative, positive, value, balance));
8075
+ }
8076
+ getContinuum(negative, positive) {
8077
+ return this.core.get_continuum(negative, positive);
8078
+ }
8079
+ transitionAU(id, value, durationMs = 200, balance = this.core.get_au_balance(id)) {
8080
+ return this.transition(this.mutateLive(() => this.core.set_au_signed(id, value, balance), durationMs));
8081
+ }
8082
+ setViseme(index, value, jawScale = 1) {
8083
+ this.mutateLive(() => {
8084
+ this.core.set_viseme(index, value);
8085
+ this.core.set_viseme_jaw_scale(index, jawScale);
8086
+ });
8087
+ }
8088
+ getViseme(index) {
8089
+ return this.core.get_viseme(index);
8090
+ }
8091
+ getVisemeJawScale(index) {
8092
+ return this.core.get_viseme_jaw_scale(index);
8093
+ }
8094
+ setVisemeById(id, value, jawScale = 1) {
8095
+ const index = this.core.viseme_slot_index(id);
8096
+ if (index < 0) throw new Error(`Unknown viseme: ${id}`);
8097
+ this.setViseme(index, value, jawScale);
8098
+ }
8099
+ transitionViseme(index, value, durationMs = 80, jawScale = 1) {
8100
+ return this.transition(this.mutateLive(() => {
8101
+ this.core.set_viseme(index, value);
8102
+ this.core.set_viseme_jaw_scale(index, jawScale);
8103
+ }, durationMs));
8104
+ }
8105
+ transitionVisemeById(id, value, durationMs = 80, jawScale = 1) {
8106
+ const index = this.core.viseme_slot_index(id);
8107
+ if (index < 0) return this.transition([]);
8108
+ return this.transitionViseme(index, value, durationMs, jawScale);
8109
+ }
8110
+ setAUMixWeight(id, value) {
8111
+ var _a, _b;
8112
+ const weight = Math.max(0, Math.min(1, value));
8113
+ this.mutateLive(() => this.core.set_au_mix_weight(id, weight));
8114
+ ((_a = this.profile).auMixDefaults ?? (_a.auMixDefaults = {}))[id] = weight;
8115
+ ((_b = this.profileSource).auMixDefaults ?? (_b.auMixDefaults = {}))[id] = weight;
8116
+ }
8117
+ getAUMixWeight(id) {
8118
+ return this.core.get_au_mix_weight(id);
8119
+ }
8120
+ hasLeftRightBones(id) {
8121
+ return this.core.has_left_right_bones(id);
8122
+ }
8123
+ setMorph(key, value, meshNames = []) {
8124
+ this.mutateLive(() => {
8125
+ if (typeof key === "number") this.core.set_morph_index(key, value, json2(meshNames));
8126
+ else this.core.set_morph(key, value, json2(meshNames));
8127
+ });
8128
+ }
8129
+ setMorphOnMeshes(meshNames, key, value) {
8130
+ this.setMorph(key, value, meshNames);
8131
+ }
8132
+ releaseMorph(key, meshNames = []) {
8133
+ this.mutateLive(() => {
8134
+ if (typeof key === "number") this.core.release_morph_index(key, json2(meshNames));
8135
+ else this.core.release_morph(key, json2(meshNames));
8136
+ });
8137
+ }
8138
+ transitionMorph(key, value, durationMs = 120, meshNames = []) {
8139
+ return this.transition(this.mutateLive(() => {
8140
+ if (typeof key === "number") this.core.set_morph_index(key, value, json2(meshNames));
8141
+ else this.core.set_morph(key, value, json2(meshNames));
8142
+ }, durationMs));
8143
+ }
8144
+ getMorphTargets() {
8145
+ return Object.fromEntries(this.meshes.map((mesh) => [mesh.name, Object.keys(mesh.morphTargetDictionary ?? {}).sort()]));
8146
+ }
8147
+ getMorphTargetIndices() {
8148
+ return Object.fromEntries(this.meshes.map((mesh) => [mesh.name, Object.entries(mesh.morphTargetDictionary ?? {}).map(([name, index]) => ({ name, index })).sort((a, b) => a.index - b.index)]));
8149
+ }
8150
+ addMorphTarget(target, options) {
8151
+ const index = this.applier.addMorphTarget(this.requireModel(), target, options);
8152
+ this.bindModel();
8153
+ return index;
8154
+ }
8155
+ addMorphTargets(targets, options) {
8156
+ const result = this.applier.addMorphTargets(this.requireModel(), targets, options);
8157
+ this.bindModel();
8158
+ return result;
8159
+ }
8160
+ meshCategory(mesh) {
8161
+ return this.profile.meshes?.[mesh.name]?.category ?? "other";
8162
+ }
8163
+ getMeshList() {
8164
+ return (this.inspection?.allMeshes ?? []).map((mesh) => ({ name: mesh.name, visible: mesh.visible, morphCount: mesh.morphTargetInfluences?.length ?? 0, category: this.meshCategory(mesh) }));
8165
+ }
8166
+ getBones() {
8167
+ return this.bones;
8168
+ }
8169
+ meshProfile(name) {
8170
+ var _a, _b;
8171
+ return (_b = (_a = this.profile).meshes ?? (_a.meshes = {}))[name] ?? (_b[name] = { category: "other" });
8172
+ }
8173
+ setMeshVisible(name, visible) {
8174
+ this.applier.setMeshVisible(this.requireModel(), name, visible);
8175
+ this.meshProfile(name).visible = visible;
8176
+ }
8177
+ highlightMesh(name, color, value) {
8178
+ this.applier.highlightMesh(this.requireModel(), name, color, value);
8179
+ }
8180
+ getMeshMaterialConfig(name) {
8181
+ return this.applier.getMeshMaterialConfig(this.requireModel(), name);
8182
+ }
8183
+ setMeshMaterialConfig(name, value) {
8184
+ this.applier.setMeshMaterialConfig(this.requireModel(), name, value);
8185
+ const entry = this.meshProfile(name);
8186
+ entry.material = { ...entry.material, ...value };
8187
+ }
8188
+ registerHairObjects(objects) {
8189
+ this.hairObjects.clear();
8190
+ for (const object of objects) if (object.isMesh) this.hairObjects.set(object.name, object);
8191
+ for (const category of ["hair", "eyebrow"]) {
8192
+ const mesh = [...this.hairObjects.values()].find((object) => this.meshCategory(object) === category);
8193
+ const material = mesh && (Array.isArray(mesh.material) ? mesh.material[0] : mesh.material);
8194
+ if (material) this.hairAppearance[`${category}Color`] = { ...this.hairAppearance[`${category}Color`], baseColor: material.color ? `#${material.color.getHexString()}` : "#000000", emissive: material.emissive ? `#${material.emissive.getHexString()}` : "#000000", emissiveIntensity: material.emissiveIntensity ?? 0 };
8195
+ }
8196
+ this.restartHair();
8197
+ return [...this.hairObjects.values()].map((mesh) => ({ name: mesh.name, isMesh: true, isEyebrow: this.meshCategory(mesh) === "eyebrow" }));
8198
+ }
8199
+ getRegisteredHairObjects() {
8200
+ return [...this.hairObjects.values()];
8201
+ }
8202
+ getHairMorphTargets(name) {
8203
+ const meshes = name ? [this.hairObjects.get(name)] : [...this.hairObjects.values()];
8204
+ return [...new Set(meshes.flatMap((mesh) => Object.keys(mesh?.morphTargetDictionary ?? {})))].sort();
8205
+ }
8206
+ getHairAppearance() {
8207
+ return copy(this.hairAppearance);
8208
+ }
8209
+ setHairAppearance(category, value) {
8210
+ const key = `${category}Color`;
8211
+ const next = parse(this.wasm.normalize_hair_color_appearance_json(json2(value), json2(this.hairAppearance[key])));
8212
+ this.hairAppearance[key] = next;
8213
+ this.applier.applyHairAppearance([...this.hairObjects.values()].filter((mesh) => this.meshCategory(mesh) === category), next);
8214
+ }
8215
+ setHairColor(value) {
8216
+ this.setHairAppearance("hair", value);
8217
+ }
8218
+ setEyebrowColor(value) {
8219
+ this.setHairAppearance("eyebrow", value);
8220
+ }
8221
+ setHairBaseColor(value) {
8222
+ this.setHairColor({ baseColor: value });
8223
+ }
8224
+ setEyebrowBaseColor(value) {
8225
+ this.setEyebrowColor({ baseColor: value });
8226
+ }
8227
+ setHairGlow(color, value) {
8228
+ this.setHairColor({ emissive: color, emissiveIntensity: value });
8229
+ }
8230
+ setEyebrowGlow(color, value) {
8231
+ this.setEyebrowColor({ emissive: color, emissiveIntensity: value });
8232
+ }
8233
+ setHairOutline(value) {
8234
+ Object.assign(this.hairAppearance, { showOutline: value.show }, value.color ? { outlineColor: value.color } : {}, value.opacity !== void 0 ? { outlineOpacity: value.opacity } : {});
8235
+ }
8236
+ restartHair() {
8237
+ for (const name of [...this.current.keys()]) if (name.startsWith("__embody_hair")) this.stopAnimation(name);
8238
+ if (!this.hairConfig.enabled || !this.hairObjects.size || !this.connector) return;
8239
+ if (this.hairConfig.idleSwayAmount > 0 || this.hairConfig.windStrength > 0) {
8240
+ const curves = parse(this.wasm.build_hair_idle_curves(json2(this.hairConfig), this.hairConfig.idleClipDuration));
8241
+ if (Object.keys(curves).length) this.playSnippet("__embody_hair_idle", curves, { loopMode: "repeat", meshNames: [...this.hairObjects.keys()], source: "hair", blendMode: "additive" });
8242
+ }
8243
+ }
8244
+ setHairPhysicsEnabled(value) {
8245
+ this.setHairPhysicsConfig({ enabled: value });
8246
+ }
8247
+ isHairPhysicsEnabled() {
8248
+ return !!this.hairConfig.enabled;
8249
+ }
8250
+ setHairPhysicsConfig(value) {
8251
+ this.hairConfig = parse(this.core.set_hair_config_json(json2(value)));
8252
+ this.restartHair();
8253
+ }
8254
+ getHairPhysicsConfig() {
8255
+ return copy(this.hairConfig);
8256
+ }
8257
+ validateHairMorphTargets() {
8258
+ return parse(this.core.get_missing_hair_morph_targets_json(json2(this.getHairMorphTargets())));
8259
+ }
8260
+ applyHairStateToObject(name, state) {
8261
+ const mesh = this.hairObjects.get(name);
8262
+ if (!mesh) return;
8263
+ if (state.visible !== void 0) mesh.visible = state.visible;
8264
+ if (state.scale) mesh.scale.set(state.scale.x, state.scale.y, state.scale.z);
8265
+ if (state.position) mesh.position.set(state.position.x, state.position.y, state.position.z);
8266
+ if (state.color) this.applier.applyHairAppearance([mesh], state.color);
8267
+ }
8268
+ authoredHeadMotion(clip) {
8269
+ if (!this.hairConfig.enabled || clip.name.startsWith("__embody_hair") || !this.hairObjects.size) return void 0;
8270
+ const tracks = [];
8271
+ for (const track of clip.tracks) {
8272
+ if (track.ValueTypeName !== "quaternion") continue;
8273
+ const parsed = PropertyBinding.parseTrackName(track.name);
8274
+ let object = PropertyBinding.findNode(this.requireModel(), parsed.nodeName);
8275
+ if (parsed.objectName === "bones" && object) {
8276
+ const skeleton = object.skeleton;
8277
+ object = skeleton?.bones.find((bone) => bone.name === String(parsed.objectIndex)) ?? skeleton?.bones[Number(parsed.objectIndex)];
8278
+ }
8279
+ if (!object) continue;
8280
+ const cubic = track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline === true;
8281
+ const stride = track.getValueSize();
8282
+ const reference = this.restValues(track);
8283
+ if (!reference) continue;
8284
+ const samples = [];
8285
+ for (let index = 0; index < track.times.length; index += 1) {
8286
+ const offset = index * stride + (cubic ? 4 : 0);
8287
+ samples.push(Array.from(track.values.subarray(offset, offset + 4)));
8288
+ }
8289
+ tracks.push({ boneName: object.name, current: object.quaternion.toArray(), reference, samples });
8290
+ }
8291
+ return parse(this.core.resolve_hair_motion_json(json2(tracks), clip.blendMode === AdditiveAnimationBlendMode)) ?? void 0;
8292
+ }
8293
+ setHairGravity(pitch, durationSeconds) {
8294
+ const clip = parse(this.core.build_hair_gravity_clip("__embody_hair_gravity", pitch, durationSeconds, json2({ meshNames: [...this.hairObjects.keys()], source: "hair" })));
8295
+ if (!clip.tracks.length) return;
8296
+ this.handle({ name: clip.name, kind: "compiled", clip }, { loopMode: "once", finalPose: "hold", blendMode: "additive" }, true);
8297
+ }
8298
+ playHairImpulse(horizontal, vertical) {
8299
+ if (!this.hairConfig.enabled || !this.hairObjects.size) return void 0;
8300
+ const curves = parse(this.wasm.build_hair_impulse_curves(json2(this.hairConfig), this.hairConfig.impulseClipDuration, horizontal, vertical));
8301
+ if (!Object.keys(curves).length) return void 0;
8302
+ return this.playSnippet("__embody_hair_impulse", curves, { loopMode: "once", finalPose: "release", meshNames: [...this.hairObjects.keys()], source: "hair", blendMode: "additive" });
8303
+ }
8304
+ start() {
8305
+ this.assertAlive();
8306
+ this.rendering = true;
8307
+ this.connector?.setRendering(true);
8308
+ }
8309
+ stop() {
8310
+ this.assertAlive();
8311
+ this.rendering = false;
8312
+ this.connector?.setRendering(false);
8313
+ }
8314
+ clear() {
8315
+ this.mutateLive(() => this.core.clear());
8316
+ }
8317
+ resetToNeutral() {
8318
+ this.clear();
8319
+ }
8320
+ dispose() {
8321
+ if (this.disposed) return;
8322
+ this.connector?.dispose();
8323
+ this.core.free();
8324
+ this.playbacks.clear();
8325
+ this.current.clear();
8326
+ this.sources.clear();
8327
+ this.hairObjects.clear();
8328
+ this.meshes.length = 0;
8329
+ this.meshByName.clear();
8330
+ this.bones = {};
8331
+ this.liveTargets.clear();
8332
+ this.connector = void 0;
8333
+ this.inspection = void 0;
8334
+ this.boundModel = void 0;
8335
+ this.disposed = true;
8336
+ }
8337
+ };
8338
+ function createRustEmbodyHostUnbound(config = {}) {
8339
+ return new Embody(config);
8340
+ }
8341
+ async function createRustEmbodyHost(model, config = {}) {
8342
+ const character = await Embody.create(config);
8343
+ try {
8344
+ character.onReady({ model, meshes: config.meshes, referencePose: config.referencePose });
8345
+ return character;
8346
+ } catch (error) {
8347
+ character.dispose();
8348
+ throw error;
8349
+ }
8350
+ }
8351
+ var draco = null;
8352
+ var dracoPath = "";
8353
+ var gltfLoader = null;
8354
+ var gltfLoaderUsesDraco = false;
8355
+ var fbxLoader = null;
8356
+ var getGltfLoader = (dracoDecoderPath) => {
8357
+ const wantsDraco = typeof dracoDecoderPath === "string" && dracoDecoderPath.length > 0;
8358
+ const normalizedPath = wantsDraco ? dracoDecoderPath.endsWith("/") ? dracoDecoderPath : `${dracoDecoderPath}/` : "";
8359
+ if (!gltfLoader || gltfLoaderUsesDraco !== wantsDraco || wantsDraco && normalizedPath !== dracoPath) {
8360
+ draco?.dispose();
8361
+ draco = null;
8362
+ dracoPath = normalizedPath;
8363
+ gltfLoaderUsesDraco = wantsDraco;
8364
+ gltfLoader = new GLTFLoader();
8365
+ if (wantsDraco) {
8366
+ draco = new DRACOLoader().setDecoderPath(normalizedPath).setDecoderConfig({ type: "wasm" });
8367
+ gltfLoader.setDRACOLoader(draco);
8368
+ }
8369
+ }
8370
+ return gltfLoader;
8371
+ };
8372
+ var prepare = (model, castShadows = true) => {
8373
+ const meshes = [];
8374
+ model.traverse((object) => {
8375
+ if (!object.isMesh) return;
8376
+ if (castShadows) object.castShadow = true;
8377
+ if (object.morphTargetInfluences?.length) meshes.push(object);
8378
+ });
8379
+ return meshes;
8380
+ };
8381
+ var progress = (listener) => {
8382
+ let last = -1;
8383
+ return (event) => {
8384
+ if (!listener || !event.lengthComputable) return;
8385
+ const next = Math.min(100, Math.max(0, Math.round(event.loaded / event.total * 100)));
8386
+ if (next !== last) {
8387
+ last = next;
8388
+ listener(next);
8389
+ }
8390
+ };
8391
+ };
8392
+ function applyCharacterModelTransform(model, value = {}) {
8393
+ if (value.modelOffset) model.position.set(value.modelOffset.x ?? 0, value.modelOffset.y ?? 0, value.modelOffset.z ?? 0);
8394
+ if (value.modelRotation) model.rotation.set(...["x", "y", "z"].map((axis) => (value.modelRotation?.[axis] ?? 0) * Math.PI / 180));
8395
+ if (Number.isFinite(value.modelScale) && (value.modelScale ?? 0) > 0) model.scale.setScalar(value.modelScale);
8396
+ if (Number.isFinite(value.modelGroundClearance)) {
8397
+ model.updateMatrixWorld(true);
8398
+ const min = new Box3().setFromObject(model).min.y;
8399
+ if (Number.isFinite(min) && min < value.modelGroundClearance) model.position.y += value.modelGroundClearance - min;
8400
+ }
8401
+ }
8402
+ function disposeCharacterModel(scene, model) {
8403
+ scene?.remove(model);
8404
+ model.traverse((object) => {
8405
+ object.geometry?.dispose?.();
8406
+ for (const material of object.material ? Array.isArray(object.material) ? object.material : [object.material] : []) {
8407
+ for (const value of Object.values(material)) if (value?.isTexture) value.dispose?.();
6944
8408
  material.dispose?.();
6945
8409
  }
6946
8410
  });
@@ -7375,7 +8839,7 @@ function createDefaultCharacterSceneRuntime(container, options = {}) {
7375
8839
  let disposed = false;
7376
8840
  let disposal = null;
7377
8841
  let generation = 0;
7378
- let pending2 = null;
8842
+ let pending = null;
7379
8843
  let pendingRendererChange = null;
7380
8844
  let leaseCount = 0;
7381
8845
  let pendingResourceReleases = 0;
@@ -7437,8 +8901,8 @@ function createDefaultCharacterSceneRuntime(container, options = {}) {
7437
8901
  if (pendingRendererChange && preference === settings.preference && (status === "initializing" || status === "switching")) return pendingRendererChange;
7438
8902
  if (status === "ready" && preference === settings.preference) return Promise.resolve(getSnapshot());
7439
8903
  settings = { preference };
7440
- const request2 = ++generation;
7441
- const previous = pending2;
8904
+ const request3 = ++generation;
8905
+ const previous = pending;
7442
8906
  status = active ? "switching" : "initializing";
7443
8907
  error = null;
7444
8908
  const execute = async () => {
@@ -7451,7 +8915,7 @@ function createDefaultCharacterSceneRuntime(container, options = {}) {
7451
8915
  let restoreModelSkinning = () => {
7452
8916
  };
7453
8917
  const check = () => {
7454
- if (disposed || generation !== request2) throw renderingAborted();
8918
+ if (disposed || generation !== request3) throw renderingAborted();
7455
8919
  if (!active) throwIfAborted(options.signal);
7456
8920
  if (candidate?.lost) throw candidate.lost;
7457
8921
  };
@@ -7534,7 +8998,7 @@ function createDefaultCharacterSceneRuntime(container, options = {}) {
7534
8998
  if (attached && candidate?.renderer.domElement.parentElement === container) container.removeChild(candidate.renderer.domElement);
7535
8999
  rollback(() => environment?.dispose());
7536
9000
  rollback(() => candidate?.dispose());
7537
- const canceled = disposed || generation !== request2 || !active && options.signal?.aborted;
9001
+ const canceled = disposed || generation !== request3 || !active && options.signal?.aborted;
7538
9002
  if (!disposed) {
7539
9003
  rollback(restoreModelSkinning);
7540
9004
  rollback(restoreCameraCoordinates);
@@ -7546,7 +9010,7 @@ function createDefaultCharacterSceneRuntime(container, options = {}) {
7546
9010
  owner.reportFailure(resumeError, active.renderer);
7547
9011
  }
7548
9012
  }
7549
- if (generation === request2) {
9013
+ if (generation === request3) {
7550
9014
  status = active?.lost ? "lost" : "error";
7551
9015
  error = failure instanceof Error ? failure : new Error(String(failure));
7552
9016
  notify();
@@ -7559,11 +9023,11 @@ function createDefaultCharacterSceneRuntime(container, options = {}) {
7559
9023
  }
7560
9024
  };
7561
9025
  const operation = previous ? previous.catch(() => void 0).then(execute) : Promise.resolve().then(execute);
7562
- pending2 = operation;
9026
+ pending = operation;
7563
9027
  pendingRendererChange = operation;
7564
9028
  notify();
7565
9029
  const settled = () => {
7566
- if (pending2 === operation) pending2 = null;
9030
+ if (pending === operation) pending = null;
7567
9031
  if (pendingRendererChange === operation) pendingRendererChange = null;
7568
9032
  };
7569
9033
  void operation.then(settled, settled);
@@ -7603,7 +9067,7 @@ function createDefaultCharacterSceneRuntime(container, options = {}) {
7603
9067
  },
7604
9068
  releaseSceneResources: (release) => {
7605
9069
  if (disposal) return disposal.then(release, release);
7606
- const previous = pending2;
9070
+ const previous = pending;
7607
9071
  pendingResourceReleases++;
7608
9072
  const operation = Promise.resolve(previous).catch(() => void 0).then(async () => {
7609
9073
  if (leaseCount) await leaseBarrier;
@@ -7622,16 +9086,16 @@ function createDefaultCharacterSceneRuntime(container, options = {}) {
7622
9086
  }).finally(() => {
7623
9087
  pendingResourceReleases--;
7624
9088
  });
7625
- pending2 = operation;
9089
+ pending = operation;
7626
9090
  void operation.then(() => {
7627
- if (pending2 === operation) pending2 = null;
9091
+ if (pending === operation) pending = null;
7628
9092
  }, () => {
7629
- if (pending2 === operation) pending2 = null;
9093
+ if (pending === operation) pending = null;
7630
9094
  });
7631
9095
  return operation.then(() => void 0);
7632
9096
  }
7633
9097
  };
7634
- const owner = registerSceneRendering(rendering, scene, camera, () => pending2, (failure, renderer) => {
9098
+ const owner = registerSceneRendering(rendering, scene, camera, () => pending, (failure, renderer) => {
7635
9099
  if (disposed) return;
7636
9100
  const problem = failure instanceof Error ? failure : new Error(String(failure));
7637
9101
  if (candidateInUse && renderer === candidateInUse.renderer && renderer !== active?.renderer) {
@@ -7674,7 +9138,7 @@ function createDefaultCharacterSceneRuntime(container, options = {}) {
7674
9138
  reject(failure);
7675
9139
  }
7676
9140
  };
7677
- if (pending2 || leaseCount || drain) void Promise.allSettled([pending2, drain, leaseBarrier]).then(cleanup);
9141
+ if (pending || leaseCount || drain) void Promise.allSettled([pending, drain, leaseBarrier]).then(cleanup);
7678
9142
  else cleanup();
7679
9143
  return disposal;
7680
9144
  };
@@ -7723,6 +9187,184 @@ async function createDefaultCharacterSceneAsync(container, options = {}) {
7723
9187
  }
7724
9188
  }
7725
9189
 
9190
+ // three/characterHost.ts
9191
+ async function createCharacterHost(options) {
9192
+ if (!options.container) throw new Error("createCharacterHost requires a container HTMLElement");
9193
+ if (!options.character?.modelUrl) throw new Error("createCharacterHost requires character.modelUrl");
9194
+ let loaded;
9195
+ let state;
9196
+ let engine;
9197
+ let controller;
9198
+ let disposed = false;
9199
+ let disposal;
9200
+ let switching = Promise.resolve();
9201
+ let mountedCanvas;
9202
+ const aborted = () => new DOMException("Character host creation was aborted", "AbortError");
9203
+ const checkCreation = () => {
9204
+ if (options.signal?.aborted) throw aborted();
9205
+ };
9206
+ const releaseModel = async (value) => {
9207
+ const release = () => disposeCharacterModel(state?.scene ?? null, value.model);
9208
+ if (state?.rendering) await state.rendering.releaseSceneResources(release);
9209
+ else release();
9210
+ };
9211
+ const makeEngine = (value, character) => {
9212
+ const next = new Embody({ ...options.embody, presetType: character.presetType ?? options.embody?.presetType, profile: character.profile ?? options.embody?.profile });
9213
+ try {
9214
+ next.onReady(value);
9215
+ return next;
9216
+ } catch (error) {
9217
+ try {
9218
+ next.dispose();
9219
+ } catch {
9220
+ }
9221
+ throw error;
9222
+ }
9223
+ };
9224
+ const dispose = () => {
9225
+ if (disposal) return disposal;
9226
+ disposed = true;
9227
+ disposal = (async () => {
9228
+ let failure;
9229
+ const attempt = async (release) => {
9230
+ try {
9231
+ await release();
9232
+ } catch (error) {
9233
+ failure ?? (failure = error);
9234
+ }
9235
+ };
9236
+ await attempt(() => controller?.dispose());
9237
+ await switching.catch(() => {
9238
+ });
9239
+ await attempt(() => engine?.dispose());
9240
+ const ownedScene = !options.external && state && "dispose" in state ? state : void 0;
9241
+ if (ownedScene) await attempt(() => ownedScene.dispose());
9242
+ const lastModel = loaded;
9243
+ if (lastModel) await attempt(() => releaseModel(lastModel));
9244
+ mountedCanvas?.remove();
9245
+ if (failure !== void 0) throw failure;
9246
+ })();
9247
+ return disposal;
9248
+ };
9249
+ try {
9250
+ checkCreation();
9251
+ loaded = await loadCharacterModel(options.character.modelUrl, options.loader);
9252
+ checkCreation();
9253
+ state = options.external ?? await createDefaultCharacterSceneAsync(options.container, { ...options.scene, signal: options.signal });
9254
+ checkCreation();
9255
+ await initEmbodyCore();
9256
+ checkCreation();
9257
+ applyCharacterModelTransform(loaded.model, options.character);
9258
+ state.scene.add(loaded.model);
9259
+ engine = makeEngine(loaded, options.character);
9260
+ if (options.external?.mountCanvas && !state.renderer.domElement.parentElement) {
9261
+ mountedCanvas = state.renderer.domElement;
9262
+ options.container.appendChild(mountedCanvas);
9263
+ }
9264
+ if (options.renderLoop ?? !options.external) {
9265
+ if (!(state.camera instanceof PerspectiveCamera)) throw new Error("Character host rendering requires a PerspectiveCamera");
9266
+ controller = new DPthreeCameraController({
9267
+ scene: state.scene,
9268
+ camera: state.camera,
9269
+ domElement: state.renderer.domElement,
9270
+ ...state.rendering ? { rendering: state.rendering } : { renderer: state.renderer },
9271
+ showDOMControls: false
9272
+ });
9273
+ controller.setModel(loaded.model);
9274
+ await controller.prepareModelForRender(loaded.model, { signal: options.signal });
9275
+ if (options.autoFrame !== false) await controller.focusFullBody(0);
9276
+ }
9277
+ checkCreation();
9278
+ if (options.autoStart === false) engine.stop();
9279
+ else engine.start();
9280
+ const sceneState = state;
9281
+ const rendering = state.rendering ?? null;
9282
+ const host = {
9283
+ engine,
9284
+ scene: state.scene,
9285
+ camera: state.camera,
9286
+ get renderer() {
9287
+ return rendering ? rendering.getSnapshot().renderer : sceneState.renderer;
9288
+ },
9289
+ get backend() {
9290
+ return rendering ? rendering.getSnapshot().backend : sceneState.backend ?? null;
9291
+ },
9292
+ rendering,
9293
+ model: loaded.model,
9294
+ meshes: loaded.meshes,
9295
+ animations: loaded.animations,
9296
+ lighting: "lighting" in state ? state.lighting : null,
9297
+ ownsScene: !options.external,
9298
+ container: options.container,
9299
+ resize() {
9300
+ if ("resize" in sceneState) sceneState.resize();
9301
+ },
9302
+ setCharacter(character, loader = options.loader) {
9303
+ if (disposed) return Promise.reject(new Error("Character host is disposed"));
9304
+ const change = switching.catch(() => {
9305
+ }).then(async () => {
9306
+ if (disposed) throw new Error("Character host is disposed");
9307
+ const next = await loadCharacterModel(character.modelUrl, loader);
9308
+ let nextEngine;
9309
+ try {
9310
+ if (disposed) throw new Error("Character host is disposed");
9311
+ applyCharacterModelTransform(next.model, character);
9312
+ nextEngine = makeEngine(next, character);
9313
+ nextEngine.stop();
9314
+ sceneState.scene.add(next.model);
9315
+ if (controller) await controller.prepareModelForRender(next.model);
9316
+ if (disposed) throw new Error("Character host is disposed");
9317
+ } catch (error) {
9318
+ try {
9319
+ nextEngine?.dispose();
9320
+ } catch {
9321
+ }
9322
+ try {
9323
+ await releaseModel(next);
9324
+ } catch {
9325
+ }
9326
+ throw error;
9327
+ }
9328
+ const previous = loaded;
9329
+ try {
9330
+ engine.dispose();
9331
+ } catch (error) {
9332
+ try {
9333
+ nextEngine?.dispose();
9334
+ } catch {
9335
+ }
9336
+ try {
9337
+ await releaseModel(next);
9338
+ } catch {
9339
+ }
9340
+ throw error;
9341
+ }
9342
+ engine = nextEngine;
9343
+ loaded = next;
9344
+ host.engine = engine;
9345
+ host.model = next.model;
9346
+ host.meshes = next.meshes;
9347
+ host.animations = next.animations;
9348
+ controller?.setModel(next.model);
9349
+ if (options.autoStart !== false) engine.start();
9350
+ await releaseModel(previous);
9351
+ if (controller && options.autoFrame !== false) await controller.focusFullBody(0);
9352
+ });
9353
+ switching = change;
9354
+ return change;
9355
+ },
9356
+ dispose
9357
+ };
9358
+ return host;
9359
+ } catch (error) {
9360
+ try {
9361
+ await dispose();
9362
+ } catch {
9363
+ }
9364
+ throw error;
9365
+ }
9366
+ }
9367
+
7726
9368
  // three/index.ts
7727
9369
  var THREE_BLENDING_MODES = {
7728
9370
  Normal: NormalBlending,
@@ -7731,6 +9373,7 @@ var THREE_BLENDING_MODES = {
7731
9373
  Multiply: MultiplyBlending,
7732
9374
  None: NoBlending
7733
9375
  };
9376
+ var BLENDING_MODES = THREE_BLENDING_MODES;
7734
9377
  var MORPH_ATTRIBUTE_SEMANTICS = ["position", "normal", "tangent", "color"];
7735
9378
  var createNeutralMorphAttribute = (geometry, semantic, name) => {
7736
9379
  const base = geometry.getAttribute(semantic);
@@ -7925,6 +9568,8 @@ function createAnimationClipFromClipIR(clip, inspection) {
7925
9568
  const tracks = [];
7926
9569
  for (const track of clip.tracks ?? []) {
7927
9570
  const kind = track.target?.kind;
9571
+ const trackName = concreteTrackName(track.target, inspection);
9572
+ if (!trackName) continue;
7928
9573
  const times = Array.from(track.times ?? []);
7929
9574
  const values = Array.from(track.values ?? []);
7930
9575
  if (!times.length || !values.length) continue;
@@ -7932,7 +9577,6 @@ function createAnimationClipFromClipIR(clip, inspection) {
7932
9577
  if (kind === "morphTarget") {
7933
9578
  const binding = inspection.morphBindings.get(Number(track.target.morphTargetId));
7934
9579
  if (!binding?.mesh) continue;
7935
- const trackName = `${binding.mesh.uuid}.morphTargetInfluences[${binding.index}]`;
7936
9580
  if (track.inheritStart) {
7937
9581
  values[0] = binding.mesh.morphTargetInfluences?.[binding.index] ?? 0;
7938
9582
  }
@@ -7945,13 +9589,13 @@ function createAnimationClipFromClipIR(clip, inspection) {
7945
9589
  const property = track.target.property ?? "rotation";
7946
9590
  if (property === "rotation" || property === "quaternion") {
7947
9591
  if (track.inheritStart) object.quaternion.toArray(values, 0);
7948
- tracks.push(new QuaternionKeyframeTrack(`${object.uuid}.quaternion`, times, values, interpolation));
9592
+ tracks.push(new QuaternionKeyframeTrack(trackName, times, values, interpolation));
7949
9593
  } else if (property === "position") {
7950
9594
  if (track.inheritStart) object.position.toArray(values, 0);
7951
- tracks.push(new VectorKeyframeTrack(`${object.uuid}.position`, times, values, interpolation));
9595
+ tracks.push(new VectorKeyframeTrack(trackName, times, values, interpolation));
7952
9596
  } else if (property === "scale") {
7953
9597
  if (track.inheritStart) object.scale.toArray(values, 0);
7954
- tracks.push(new VectorKeyframeTrack(`${object.uuid}.scale`, times, values, interpolation));
9598
+ tracks.push(new VectorKeyframeTrack(trackName, times, values, interpolation));
7955
9599
  }
7956
9600
  continue;
7957
9601
  }
@@ -7959,7 +9603,7 @@ function createAnimationClipFromClipIR(clip, inspection) {
7959
9603
  const mesh = inspection.meshBindings.get(Number(track.target.meshId));
7960
9604
  if (!mesh) continue;
7961
9605
  if (track.inheritStart) values[0] = Number(mesh.visible);
7962
- tracks.push(new NumberKeyframeTrack(`${mesh.uuid}.visible`, times, values, interpolation));
9606
+ tracks.push(new NumberKeyframeTrack(trackName, times, values, interpolation));
7963
9607
  }
7964
9608
  }
7965
9609
  const duration = Number.isFinite(clip.durationSeconds) ? Number(clip.durationSeconds) : -1;
@@ -8002,14 +9646,19 @@ function serializeAnimationClips(model, clips, inspection) {
8002
9646
  }
8003
9647
  if (!target) return;
8004
9648
  const kind = target.kind === "morphTarget" ? "face" : target.kind === "boneTransform" ? "body" : "scene";
8005
- const size = track.getValueSize();
9649
+ const cubic = !!track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline;
9650
+ const size = track.getValueSize() / (cubic ? 3 : 1);
9651
+ if (!Array.from(track.values).every(Number.isFinite)) {
9652
+ throw new Error(`Animation track ${JSON.stringify(track.name)} contains non-finite samples.`);
9653
+ }
9654
+ const values = cubic ? Array.from(track.times).flatMap((_, key) => Array.from(track.values.slice((key * 3 + 1) * size, (key * 3 + 2) * size))) : Array.from(track.values);
8006
9655
  tracks.push({
8007
9656
  id: index + 1,
8008
9657
  channelId: channelId(kind),
8009
9658
  target,
8010
9659
  valueType: size === 4 ? "quat" : size === 3 ? "vec3" : "scalar",
8011
9660
  times: Array.from(track.times),
8012
- values: Array.from(track.values),
9661
+ values,
8013
9662
  interpolation: track.getInterpolation() === InterpolateDiscrete ? "step" : "linear",
8014
9663
  sourceName: track.name
8015
9664
  });
@@ -8098,7 +9747,7 @@ var ThreeFrameApplier = class {
8098
9747
  mesh.visible = visible;
8099
9748
  });
8100
9749
  }
8101
- highlightMesh(root, name, color = 65535, intensity = 0.5) {
9750
+ highlightMesh(root, name, color = 65535, intensity2 = 0.5) {
8102
9751
  root.traverse((object) => {
8103
9752
  if (!object.isMesh) return;
8104
9753
  for (const material of materials(object.material)) {
@@ -8107,7 +9756,7 @@ var ThreeFrameApplier = class {
8107
9756
  if (name === object.name) {
8108
9757
  if (!this.originalEmissive.has(key)) this.originalEmissive.set(key, { color: material.emissive.getHex(), intensity: material.emissiveIntensity ?? 0 });
8109
9758
  material.emissive.setHex(color);
8110
- material.emissiveIntensity = intensity;
9759
+ material.emissiveIntensity = intensity2;
8111
9760
  } else {
8112
9761
  const original = this.originalEmissive.get(key);
8113
9762
  if (original) {
@@ -8276,1072 +9925,6 @@ var collectMorphMeshes = (root) => {
8276
9925
  return meshes;
8277
9926
  };
8278
9927
 
8279
- // assets/presets/cc4.json
8280
- var cc4_default = {
8281
- hairColorPresets: {
8282
- natural_black: {
8283
- name: "Natural Black",
8284
- baseColor: "#1a1a1a",
8285
- emissive: "#000000",
8286
- emissiveIntensity: 0
8287
- },
8288
- natural_brown: {
8289
- name: "Natural Brown",
8290
- baseColor: "#4a3728",
8291
- emissive: "#000000",
8292
- emissiveIntensity: 0
8293
- },
8294
- natural_blonde: {
8295
- name: "Natural Blonde",
8296
- baseColor: "#e6c78a",
8297
- emissive: "#000000",
8298
- emissiveIntensity: 0
8299
- },
8300
- natural_red: {
8301
- name: "Natural Red",
8302
- baseColor: "#8b3a3a",
8303
- emissive: "#000000",
8304
- emissiveIntensity: 0
8305
- },
8306
- natural_gray: {
8307
- name: "Natural Gray",
8308
- baseColor: "#9e9e9e",
8309
- emissive: "#000000",
8310
- emissiveIntensity: 0
8311
- },
8312
- natural_white: {
8313
- name: "Natural White",
8314
- baseColor: "#f5f5f5",
8315
- emissive: "#000000",
8316
- emissiveIntensity: 0
8317
- },
8318
- neon_blue: {
8319
- name: "Neon Blue",
8320
- baseColor: "#00ffff",
8321
- emissive: "#0000ff",
8322
- emissiveIntensity: 0.8
8323
- },
8324
- neon_pink: {
8325
- name: "Neon Pink",
8326
- baseColor: "#ff00ff",
8327
- emissive: "#ff1493",
8328
- emissiveIntensity: 0.8
8329
- },
8330
- neon_green: {
8331
- name: "Neon Green",
8332
- baseColor: "#00ff00",
8333
- emissive: "#00ff00",
8334
- emissiveIntensity: 0.8
8335
- },
8336
- electric_purple: {
8337
- name: "Electric Purple",
8338
- baseColor: "#9d00ff",
8339
- emissive: "#9d00ff",
8340
- emissiveIntensity: 0.6
8341
- },
8342
- fire_orange: {
8343
- name: "Fire Orange",
8344
- baseColor: "#ff6600",
8345
- emissive: "#ff3300",
8346
- emissiveIntensity: 0.7
8347
- }
8348
- }
8349
- };
8350
-
8351
- // assets/templates/cc4-humanoid.json
8352
- var cc4_humanoid_default = {
8353
- id: "cc4-humanoid",
8354
- sourceCharacterId: "cc4",
8355
- sourceAsset: "assets/presets/cc4.json",
8356
- sourceSkinName: "Armature",
8357
- bones: [
8358
- {
8359
- name: "CC_Base_BoneRoot",
8360
- parent: null,
8361
- translation: [
8362
- 0,
8363
- 0,
8364
- 0
8365
- ]
8366
- },
8367
- {
8368
- name: "CC_Base_Hip",
8369
- parent: "CC_Base_BoneRoot",
8370
- translation: [
8371
- 0,
8372
- 0,
8373
- 102.33650207519531
8374
- ]
8375
- },
8376
- {
8377
- name: "CC_Base_Pelvis",
8378
- parent: "CC_Base_Hip",
8379
- translation: [
8380
- -3790411029074318e-30,
8381
- 30517578125e-15,
8382
- -7.908884072094224e-7
8383
- ]
8384
- },
8385
- {
8386
- name: "CC_Base_L_Thigh",
8387
- parent: "CC_Base_Pelvis",
8388
- translation: [
8389
- 9.953155517578125,
8390
- -1.789858102798462,
8391
- -1.3750107288360596
8392
- ]
8393
- },
8394
- {
8395
- name: "CC_Base_L_Calf",
8396
- parent: "CC_Base_L_Thigh",
8397
- translation: [
8398
- 0.0010912826983258128,
8399
- 47.572593688964844,
8400
- -25631440803408623e-20
8401
- ]
8402
- },
8403
- {
8404
- name: "CC_Base_L_Foot",
8405
- parent: "CC_Base_L_Calf",
8406
- translation: [
8407
- 0.012946736067533493,
8408
- 47.30466842651367,
8409
- 0.0028991601429879665
8410
- ]
8411
- },
8412
- {
8413
- name: "CC_Base_L_ToeBaseShareBone",
8414
- parent: "CC_Base_L_Foot",
8415
- translation: [
8416
- -15205750241875648e-20,
8417
- 15.384612083435059,
8418
- 8890032768249512e-20
8419
- ]
8420
- },
8421
- {
8422
- name: "CC_Base_L_ToeBase",
8423
- parent: "CC_Base_L_Foot",
8424
- translation: [
8425
- -15205750241875648e-20,
8426
- 15.384612083435059,
8427
- 8890032768249512e-20
8428
- ]
8429
- },
8430
- {
8431
- name: "CC_Base_L_PinkyToe1",
8432
- parent: "CC_Base_L_ToeBase",
8433
- translation: [
8434
- -2.8338863849639893,
8435
- 0.00474335253238678,
8436
- -0.449185848236084
8437
- ]
8438
- },
8439
- {
8440
- name: "CC_Base_L_RingToe1",
8441
- parent: "CC_Base_L_ToeBase",
8442
- translation: [
8443
- -1.4594630002975464,
8444
- 1.165667176246643,
8445
- -0.024081647396087646
8446
- ]
8447
- },
8448
- {
8449
- name: "CC_Base_L_MidToe1",
8450
- parent: "CC_Base_L_ToeBase",
8451
- translation: [
8452
- -5848705768585205e-21,
8453
- 2.3142271041870117,
8454
- 5245208740234375e-20
8455
- ]
8456
- },
8457
- {
8458
- name: "CC_Base_L_IndexToe1",
8459
- parent: "CC_Base_L_ToeBase",
8460
- translation: [
8461
- 1.5948846340179443,
8462
- 2.64426851272583,
8463
- 0.3221862316131592
8464
- ]
8465
- },
8466
- {
8467
- name: "CC_Base_L_BigToe1",
8468
- parent: "CC_Base_L_ToeBase",
8469
- translation: [
8470
- 3.8480422496795654,
8471
- 2.5877017974853516,
8472
- 0.018612831830978394
8473
- ]
8474
- },
8475
- {
8476
- name: "CC_Base_L_CalfTwist01",
8477
- parent: "CC_Base_L_Calf",
8478
- translation: [
8479
- -9258394129574299e-21,
8480
- 4678964614868164e-21,
8481
- -3.073364496231079e-8
8482
- ]
8483
- },
8484
- {
8485
- name: "CC_Base_L_CalfTwist02",
8486
- parent: "CC_Base_L_CalfTwist01",
8487
- translation: [
8488
- 0.008389605209231377,
8489
- 23.652305603027344,
8490
- 0.0010145818814635277
8491
- ]
8492
- },
8493
- {
8494
- name: "CC_Base_L_KneeShareBone",
8495
- parent: "CC_Base_L_Calf",
8496
- translation: [
8497
- -9258394129574299e-21,
8498
- 4678964614868164e-21,
8499
- -3.073364496231079e-8
8500
- ]
8501
- },
8502
- {
8503
- name: "CC_Base_L_ThighTwist01",
8504
- parent: "CC_Base_L_Thigh",
8505
- translation: [
8506
- -5.249967216514051e-8,
8507
- -446811318397522e-19,
8508
- 7050111889839172e-22
8509
- ]
8510
- },
8511
- {
8512
- name: "CC_Base_L_ThighTwist02",
8513
- parent: "CC_Base_L_ThighTwist01",
8514
- translation: [
8515
- 5524034495465457e-19,
8516
- 23.786300659179688,
8517
- 3187847323715687e-20
8518
- ]
8519
- },
8520
- {
8521
- name: "CC_Base_R_Thigh",
8522
- parent: "CC_Base_Pelvis",
8523
- translation: [
8524
- -9.953006744384766,
8525
- -1.7889251708984375,
8526
- -1.3763487339019775
8527
- ]
8528
- },
8529
- {
8530
- name: "CC_Base_R_Calf",
8531
- parent: "CC_Base_R_Thigh",
8532
- translation: [
8533
- -0.001107644522562623,
8534
- 47.52029800415039,
8535
- 4845880903303623e-20
8536
- ]
8537
- },
8538
- {
8539
- name: "CC_Base_R_KneeShareBone",
8540
- parent: "CC_Base_R_Calf",
8541
- translation: [
8542
- -7073394954204559e-21,
8543
- -2518296241760254e-21,
8544
- 19818544387817383e-22
8545
- ]
8546
- },
8547
- {
8548
- name: "CC_Base_R_Foot",
8549
- parent: "CC_Base_R_Calf",
8550
- translation: [
8551
- -0.011737369000911713,
8552
- 47.35129928588867,
8553
- -0.0035943761467933655
8554
- ]
8555
- },
8556
- {
8557
- name: "CC_Base_R_ToeBase",
8558
- parent: "CC_Base_R_Foot",
8559
- translation: [
8560
- 23105042055249214e-20,
8561
- 15.38337230682373,
8562
- 45359134674072266e-20
8563
- ]
8564
- },
8565
- {
8566
- name: "CC_Base_R_BigToe1",
8567
- parent: "CC_Base_R_ToeBase",
8568
- translation: [
8569
- -3.848090648651123,
8570
- 2.587796926498413,
8571
- 0.018401414155960083
8572
- ]
8573
- },
8574
- {
8575
- name: "CC_Base_R_PinkyToe1",
8576
- parent: "CC_Base_R_ToeBase",
8577
- translation: [
8578
- 2.8339407444000244,
8579
- 0.005379915237426758,
8580
- -0.4495028853416443
8581
- ]
8582
- },
8583
- {
8584
- name: "CC_Base_R_RingToe1",
8585
- parent: "CC_Base_R_ToeBase",
8586
- translation: [
8587
- 1.4595259428024292,
8588
- 1.1659480333328247,
8589
- -0.02425825595855713
8590
- ]
8591
- },
8592
- {
8593
- name: "CC_Base_R_IndexToe1",
8594
- parent: "CC_Base_R_ToeBase",
8595
- translation: [
8596
- -1.59493887424469,
8597
- 2.64436674118042,
8598
- 0.32200416922569275
8599
- ]
8600
- },
8601
- {
8602
- name: "CC_Base_R_MidToe1",
8603
- parent: "CC_Base_R_ToeBase",
8604
- translation: [
8605
- -912696123123169e-20,
8606
- 2.3142714500427246,
8607
- 1671910285949707e-20
8608
- ]
8609
- },
8610
- {
8611
- name: "CC_Base_R_ToeBaseShareBone",
8612
- parent: "CC_Base_R_Foot",
8613
- translation: [
8614
- 23105042055249214e-20,
8615
- 15.38337230682373,
8616
- 45359134674072266e-20
8617
- ]
8618
- },
8619
- {
8620
- name: "CC_Base_R_CalfTwist01",
8621
- parent: "CC_Base_R_Calf",
8622
- translation: [
8623
- -7073394954204559e-21,
8624
- -2518296241760254e-21,
8625
- 19818544387817383e-22
8626
- ]
8627
- },
8628
- {
8629
- name: "CC_Base_R_CalfTwist02",
8630
- parent: "CC_Base_R_CalfTwist01",
8631
- translation: [
8632
- -0.005310218781232834,
8633
- 23.675636291503906,
8634
- -0.0015991628170013428
8635
- ]
8636
- },
8637
- {
8638
- name: "CC_Base_R_ThighTwist01",
8639
- parent: "CC_Base_R_Thigh",
8640
- translation: [
8641
- 30152787076076493e-22,
8642
- -12714415788650513e-21,
8643
- -5.024485290050507e-7
8644
- ]
8645
- },
8646
- {
8647
- name: "CC_Base_R_ThighTwist02",
8648
- parent: "CC_Base_R_ThighTwist01",
8649
- translation: [
8650
- -532150617800653e-18,
8651
- 23.760181427001953,
8652
- -5566661711782217e-19
8653
- ]
8654
- },
8655
- {
8656
- name: "CC_Base_Waist",
8657
- parent: "CC_Base_Hip",
8658
- translation: [
8659
- 0,
8660
- 7.9917144775390625,
8661
- 1.035797119140625
8662
- ]
8663
- },
8664
- {
8665
- name: "CC_Base_Spine01",
8666
- parent: "CC_Base_Waist",
8667
- translation: [
8668
- 12880583372901905e-29,
8669
- 4.44435453414917,
8670
- 36954879760742188e-22
8671
- ]
8672
- },
8673
- {
8674
- name: "CC_Base_Spine02",
8675
- parent: "CC_Base_Spine01",
8676
- translation: [
8677
- 13552527156068805e-36,
8678
- 14.241397857666016,
8679
- -852346420288086e-20
8680
- ]
8681
- },
8682
- {
8683
- name: "CC_Base_NeckTwist01",
8684
- parent: "CC_Base_Spine02",
8685
- translation: [
8686
- -1075023646990303e-21,
8687
- 29.157955169677734,
8688
- 44345855712890625e-21
8689
- ]
8690
- },
8691
- {
8692
- name: "CC_Base_NeckTwist02",
8693
- parent: "CC_Base_NeckTwist01",
8694
- translation: [
8695
- 8672486728755757e-24,
8696
- 3.354764223098755,
8697
- 13446807861328125e-20
8698
- ]
8699
- },
8700
- {
8701
- name: "CC_Base_Head",
8702
- parent: "CC_Base_NeckTwist02",
8703
- translation: [
8704
- 41776246507652104e-20,
8705
- 3.995985746383667,
8706
- -1358989356958773e-20
8707
- ]
8708
- },
8709
- {
8710
- name: "CC_Base_FacialBone",
8711
- parent: "CC_Base_Head",
8712
- translation: [
8713
- 5114753065527111e-26,
8714
- 15347271983046085e-21,
8715
- -7390974587906385e-21
8716
- ]
8717
- },
8718
- {
8719
- name: "CC_Base_JawRoot",
8720
- parent: "CC_Base_FacialBone",
8721
- translation: [
8722
- 1.856170654296875,
8723
- 2.3725814819335938,
8724
- -0.026499934494495392
8725
- ]
8726
- },
8727
- {
8728
- name: "CC_Base_Tongue01",
8729
- parent: "CC_Base_JawRoot",
8730
- translation: [
8731
- 3.4788222312927246,
8732
- 1.3013767004013062,
8733
- 0.001722173416055739
8734
- ]
8735
- },
8736
- {
8737
- name: "CC_Base_Tongue02",
8738
- parent: "CC_Base_Tongue01",
8739
- translation: [
8740
- 1.211624026298523,
8741
- 7291115616681054e-20,
8742
- 23348256945610046e-22
8743
- ]
8744
- },
8745
- {
8746
- name: "CC_Base_Tongue03",
8747
- parent: "CC_Base_Tongue02",
8748
- translation: [
8749
- 1.8075196743011475,
8750
- 4838673339691013e-19,
8751
- 1673889346420765e-20
8752
- ]
8753
- },
8754
- {
8755
- name: "CC_Base_Teeth02",
8756
- parent: "CC_Base_JawRoot",
8757
- translation: [
8758
- 3.509425640106201,
8759
- 1.6364113092422485,
8760
- 0.025405975058674812
8761
- ]
8762
- },
8763
- {
8764
- name: "CC_Base_R_Eye",
8765
- parent: "CC_Base_FacialBone",
8766
- translation: [
8767
- 7.916625499725342,
8768
- 8.004108428955078,
8769
- -3.399050235748291
8770
- ]
8771
- },
8772
- {
8773
- name: "CC_Base_L_Eye",
8774
- parent: "CC_Base_FacialBone",
8775
- translation: [
8776
- 7.864105701446533,
8777
- 7.835659027099609,
8778
- 3.473083019256592
8779
- ]
8780
- },
8781
- {
8782
- name: "CC_Base_UpperJaw",
8783
- parent: "CC_Base_FacialBone",
8784
- translation: [
8785
- 3.261932373046875,
8786
- 6.942871570587158,
8787
- -0.02468101494014263
8788
- ]
8789
- },
8790
- {
8791
- name: "CC_Base_Teeth01",
8792
- parent: "CC_Base_UpperJaw",
8793
- translation: [
8794
- 0.09780752658843994,
8795
- 0.021660717204213142,
8796
- 0.023386476561427116
8797
- ]
8798
- },
8799
- {
8800
- name: "CC_Base_L_Clavicle",
8801
- parent: "CC_Base_Spine02",
8802
- translation: [
8803
- 5.846743106842041,
8804
- 22.913326263427734,
8805
- 0.15851521492004395
8806
- ]
8807
- },
8808
- {
8809
- name: "CC_Base_L_Upperarm",
8810
- parent: "CC_Base_L_Clavicle",
8811
- translation: [
8812
- 6332993507385254e-20,
8813
- 13.675213813781738,
8814
- 40340423583984375e-20
8815
- ]
8816
- },
8817
- {
8818
- name: "CC_Base_L_Forearm",
8819
- parent: "CC_Base_L_Upperarm",
8820
- translation: [
8821
- -0.0021000131964683533,
8822
- 29.648496627807617,
8823
- 5214959383010864e-19
8824
- ]
8825
- },
8826
- {
8827
- name: "CC_Base_L_ForearmTwist01",
8828
- parent: "CC_Base_L_Forearm",
8829
- translation: [
8830
- -2450495958328247e-20,
8831
- -63749030232429504e-22,
8832
- 5811452865600586e-21
8833
- ]
8834
- },
8835
- {
8836
- name: "CC_Base_L_ForearmTwist02",
8837
- parent: "CC_Base_L_ForearmTwist01",
8838
- translation: [
8839
- -0.0017938688397407532,
8840
- 12.154339790344238,
8841
- -0.0031246542930603027
8842
- ]
8843
- },
8844
- {
8845
- name: "CC_Base_L_ElbowShareBone",
8846
- parent: "CC_Base_L_Forearm",
8847
- translation: [
8848
- -2450495958328247e-20,
8849
- -63749030232429504e-22,
8850
- 5811452865600586e-21
8851
- ]
8852
- },
8853
- {
8854
- name: "CC_Base_L_Hand",
8855
- parent: "CC_Base_L_Forearm",
8856
- translation: [
8857
- -0.0032659247517585754,
8858
- 24.308786392211914,
8859
- -0.0040430426597595215
8860
- ]
8861
- },
8862
- {
8863
- name: "CC_Base_L_Pinky1",
8864
- parent: "CC_Base_L_Hand",
8865
- translation: [
8866
- 0.8387796878814697,
8867
- 9.643739700317383,
8868
- -1.8876361846923828
8869
- ]
8870
- },
8871
- {
8872
- name: "CC_Base_L_Pinky2",
8873
- parent: "CC_Base_L_Pinky1",
8874
- translation: [
8875
- 396043062210083e-18,
8876
- 3.0504348278045654,
8877
- -1811981201171875e-19
8878
- ]
8879
- },
8880
- {
8881
- name: "CC_Base_L_Pinky3",
8882
- parent: "CC_Base_L_Pinky2",
8883
- translation: [
8884
- 38370490074157715e-21,
8885
- 1.9355652332305908,
8886
- -3510713577270508e-20
8887
- ]
8888
- },
8889
- {
8890
- name: "CC_Base_L_Ring1",
8891
- parent: "CC_Base_L_Hand",
8892
- translation: [
8893
- 0.0010117590427398682,
8894
- 9.706981658935547,
8895
- 0.0030269622802734375
8896
- ]
8897
- },
8898
- {
8899
- name: "CC_Base_L_Ring2",
8900
- parent: "CC_Base_L_Ring1",
8901
- translation: [
8902
- -1965165138244629e-19,
8903
- 4.398406982421875,
8904
- -5393028259277344e-19
8905
- ]
8906
- },
8907
- {
8908
- name: "CC_Base_L_Ring3",
8909
- parent: "CC_Base_L_Ring2",
8910
- translation: [
8911
- -8174926042556763e-19,
8912
- 3.074361801147461,
8913
- 6477683782577515e-19
8914
- ]
8915
- },
8916
- {
8917
- name: "CC_Base_L_Mid1",
8918
- parent: "CC_Base_L_Hand",
8919
- translation: [
8920
- -0.6153436303138733,
8921
- 9.996679306030273,
8922
- 1.9597835540771484
8923
- ]
8924
- },
8925
- {
8926
- name: "CC_Base_L_Mid2",
8927
- parent: "CC_Base_L_Mid1",
8928
- translation: [
8929
- -2244412899017334e-19,
8930
- 4.767321586608887,
8931
- -41157007217407227e-21
8932
- ]
8933
- },
8934
- {
8935
- name: "CC_Base_L_Mid3",
8936
- parent: "CC_Base_L_Mid2",
8937
- translation: [
8938
- -0.0010398924350738525,
8939
- 3.306338310241699,
8940
- -8061528205871582e-19
8941
- ]
8942
- },
8943
- {
8944
- name: "CC_Base_L_Index1",
8945
- parent: "CC_Base_L_Hand",
8946
- translation: [
8947
- -0.4277152717113495,
8948
- 9.799840927124023,
8949
- 4.421895980834961
8950
- ]
8951
- },
8952
- {
8953
- name: "CC_Base_L_Index2",
8954
- parent: "CC_Base_L_Index1",
8955
- translation: [
8956
- -0.001440480351448059,
8957
- 4.649103164672852,
8958
- 0.001256398856639862
8959
- ]
8960
- },
8961
- {
8962
- name: "CC_Base_L_Index3",
8963
- parent: "CC_Base_L_Index2",
8964
- translation: [
8965
- -5395412445068359e-19,
8966
- 2.933397054672241,
8967
- 52034854888916016e-21
8968
- ]
8969
- },
8970
- {
8971
- name: "CC_Base_L_Thumb1",
8972
- parent: "CC_Base_L_Hand",
8973
- translation: [
8974
- 0.4729442000389099,
8975
- 1.4073847532272339,
8976
- 2.9682064056396484
8977
- ]
8978
- },
8979
- {
8980
- name: "CC_Base_L_Thumb2",
8981
- parent: "CC_Base_L_Thumb1",
8982
- translation: [
8983
- -3701448440551758e-20,
8984
- 7.252772331237793,
8985
- -34561753273010254e-20
8986
- ]
8987
- },
8988
- {
8989
- name: "CC_Base_L_Thumb3",
8990
- parent: "CC_Base_L_Thumb2",
8991
- translation: [
8992
- -9371936321258545e-19,
8993
- 3.2246363162994385,
8994
- -3355741500854492e-19
8995
- ]
8996
- },
8997
- {
8998
- name: "CC_Base_L_UpperarmTwist01",
8999
- parent: "CC_Base_L_Upperarm",
9000
- translation: [
9001
- -24765729904174805e-21,
9002
- -8791685104370117e-21,
9003
- -4850327968597412e-21
9004
- ]
9005
- },
9006
- {
9007
- name: "CC_Base_L_UpperarmTwist02",
9008
- parent: "CC_Base_L_UpperarmTwist01",
9009
- translation: [
9010
- -5109608173370361e-20,
9011
- 14.824237823486328,
9012
- -4093348979949951e-20
9013
- ]
9014
- },
9015
- {
9016
- name: "CC_Base_L_RibsTwist",
9017
- parent: "CC_Base_Spine02",
9018
- translation: [
9019
- 12.37477970123291,
9020
- 4.240516662597656,
9021
- 11.340028762817383
9022
- ]
9023
- },
9024
- {
9025
- name: "CC_Base_L_Breast",
9026
- parent: "CC_Base_L_RibsTwist",
9027
- translation: [
9028
- 15254845493473113e-21,
9029
- 1.999998688697815,
9030
- 8869566954672337e-20
9031
- ]
9032
- },
9033
- {
9034
- name: "CC_Base_R_RibsTwist",
9035
- parent: "CC_Base_Spine02",
9036
- translation: [
9037
- -12.366527557373047,
9038
- 4.255687236785889,
9039
- 11.342021942138672
9040
- ]
9041
- },
9042
- {
9043
- name: "CC_Base_R_Breast",
9044
- parent: "CC_Base_R_RibsTwist",
9045
- translation: [
9046
- -14992387150414288e-21,
9047
- 1.9999765157699585,
9048
- 698570511303842e-19
9049
- ]
9050
- },
9051
- {
9052
- name: "CC_Base_R_Clavicle",
9053
- parent: "CC_Base_Spine02",
9054
- translation: [
9055
- -5.847836017608643,
9056
- 22.913354873657227,
9057
- 0.158738374710083
9058
- ]
9059
- },
9060
- {
9061
- name: "CC_Base_R_Upperarm",
9062
- parent: "CC_Base_R_Clavicle",
9063
- translation: [
9064
- -38962066173553467e-20,
9065
- 13.675079345703125,
9066
- 13494491577148438e-20
9067
- ]
9068
- },
9069
- {
9070
- name: "CC_Base_R_Forearm",
9071
- parent: "CC_Base_R_Upperarm",
9072
- translation: [
9073
- 0.0014372840523719788,
9074
- 29.647546768188477,
9075
- -34911930561065674e-20
9076
- ]
9077
- },
9078
- {
9079
- name: "CC_Base_R_ElbowShareBone",
9080
- parent: "CC_Base_R_Forearm",
9081
- translation: [
9082
- 4427880048751831e-20,
9083
- -5062669515609741e-21,
9084
- 19073486328125e-19
9085
- ]
9086
- },
9087
- {
9088
- name: "CC_Base_R_ForearmTwist01",
9089
- parent: "CC_Base_R_Forearm",
9090
- translation: [
9091
- 4427880048751831e-20,
9092
- -5062669515609741e-21,
9093
- 19073486328125e-19
9094
- ]
9095
- },
9096
- {
9097
- name: "CC_Base_R_ForearmTwist02",
9098
- parent: "CC_Base_R_ForearmTwist01",
9099
- translation: [
9100
- 0.0017296746373176575,
9101
- 12.154948234558105,
9102
- -0.0021570324897766113
9103
- ]
9104
- },
9105
- {
9106
- name: "CC_Base_R_Hand",
9107
- parent: "CC_Base_R_Forearm",
9108
- translation: [
9109
- 0.0013648197054862976,
9110
- 24.31002426147461,
9111
- -3132820129394531e-19
9112
- ]
9113
- },
9114
- {
9115
- name: "CC_Base_R_Ring1",
9116
- parent: "CC_Base_R_Hand",
9117
- translation: [
9118
- 73462724685668945e-22,
9119
- 9.707071304321289,
9120
- -7748603820800781e-19
9121
- ]
9122
- },
9123
- {
9124
- name: "CC_Base_R_Ring2",
9125
- parent: "CC_Base_R_Ring1",
9126
- translation: [
9127
- 15947222709655762e-20,
9128
- 4.398307800292969,
9129
- -6395876407623291e-19
9130
- ]
9131
- },
9132
- {
9133
- name: "CC_Base_R_Ring3",
9134
- parent: "CC_Base_R_Ring2",
9135
- translation: [
9136
- -0.0010596513748168945,
9137
- 3.074486494064331,
9138
- -25691837072372437e-20
9139
- ]
9140
- },
9141
- {
9142
- name: "CC_Base_R_Mid1",
9143
- parent: "CC_Base_R_Hand",
9144
- translation: [
9145
- 0.6159845590591431,
9146
- 9.997448921203613,
9147
- 1.9559621810913086
9148
- ]
9149
- },
9150
- {
9151
- name: "CC_Base_R_Mid2",
9152
- parent: "CC_Base_R_Mid1",
9153
- translation: [
9154
- 445440411567688e-18,
9155
- 4.767148494720459,
9156
- -16441941261291504e-20
9157
- ]
9158
- },
9159
- {
9160
- name: "CC_Base_R_Mid3",
9161
- parent: "CC_Base_R_Mid2",
9162
- translation: [
9163
- 12923777103424072e-20,
9164
- 3.306414842605591,
9165
- 5930662155151367e-20
9166
- ]
9167
- },
9168
- {
9169
- name: "CC_Base_R_Thumb1",
9170
- parent: "CC_Base_R_Hand",
9171
- translation: [
9172
- -0.4736732244491577,
9173
- 1.408708095550537,
9174
- 2.9675445556640625
9175
- ]
9176
- },
9177
- {
9178
- name: "CC_Base_R_Thumb2",
9179
- parent: "CC_Base_R_Thumb1",
9180
- translation: [
9181
- 3608446568250656e-19,
9182
- 7.252943515777588,
9183
- -981692224740982e-18
9184
- ]
9185
- },
9186
- {
9187
- name: "CC_Base_R_Thumb3",
9188
- parent: "CC_Base_R_Thumb2",
9189
- translation: [
9190
- -9268522262573242e-21,
9191
- 3.2248055934906006,
9192
- 4887580871582031e-20
9193
- ]
9194
- },
9195
- {
9196
- name: "CC_Base_R_Index1",
9197
- parent: "CC_Base_R_Hand",
9198
- translation: [
9199
- 0.4276627004146576,
9200
- 9.801568984985352,
9201
- 4.418048858642578
9202
- ]
9203
- },
9204
- {
9205
- name: "CC_Base_R_Index2",
9206
- parent: "CC_Base_R_Index1",
9207
- translation: [
9208
- 0.001061864197254181,
9209
- 4.648791790008545,
9210
- 6793588399887085e-19
9211
- ]
9212
- },
9213
- {
9214
- name: "CC_Base_R_Index3",
9215
- parent: "CC_Base_R_Index2",
9216
- translation: [
9217
- -6211921572685242e-19,
9218
- 2.9368622303009033,
9219
- -16835331916809082e-20
9220
- ]
9221
- },
9222
- {
9223
- name: "CC_Base_R_Pinky1",
9224
- parent: "CC_Base_R_Hand",
9225
- translation: [
9226
- -0.837287962436676,
9227
- 9.643238067626953,
9228
- -1.891557216644287
9229
- ]
9230
- },
9231
- {
9232
- name: "CC_Base_R_Pinky2",
9233
- parent: "CC_Base_R_Pinky1",
9234
- translation: [
9235
- -3053247928619385e-19,
9236
- 3.050346851348877,
9237
- -22897124290466309e-20
9238
- ]
9239
- },
9240
- {
9241
- name: "CC_Base_R_Pinky3",
9242
- parent: "CC_Base_R_Pinky2",
9243
- translation: [
9244
- -6973743438720703e-21,
9245
- 1.9355270862579346,
9246
- 15944242477416992e-22
9247
- ]
9248
- },
9249
- {
9250
- name: "CC_Base_R_UpperarmTwist01",
9251
- parent: "CC_Base_R_Upperarm",
9252
- translation: [
9253
- 4403293132781982e-21,
9254
- 33676624298095703e-22,
9255
- -2473592758178711e-21
9256
- ]
9257
- },
9258
- {
9259
- name: "CC_Base_R_UpperarmTwist02",
9260
- parent: "CC_Base_R_UpperarmTwist01",
9261
- translation: [
9262
- -0.0015784502029418945,
9263
- 14.823780059814453,
9264
- -3107339143753052e-19
9265
- ]
9266
- }
9267
- ]
9268
- };
9269
-
9270
- // wasm/index.ts
9271
- var EMBODY_CORE_ABI_VERSION = 1;
9272
- var PACKED_MORPH_FRAME_DELTA_STRIDE = 4;
9273
- var PACKED_BONE_FRAME_DELTA_STRIDE = 9;
9274
- var HAIR_CONFIG_STRIDE = 11;
9275
- var HAIR_STATE_STRIDE = 4;
9276
- var HAIR_HEAD_STATE_STRIDE = 5;
9277
- var HAIR_MORPH_OUTPUT_STRIDE = 6;
9278
- var MESH_PROPORTIONS_STRIDE = 16;
9279
- var TEMPLATE_SKELETON_FIT_SOLUTION_STRIDE = 10;
9280
- var TEMPLATE_SKELETON_FIT_TRANSFORM_STRIDE = 4;
9281
- var ANNOTATION_CAMERA_FRAMING_STRIDE = 7;
9282
- var CAMERA_FLIGHT_SAMPLE_STRIDE = 7;
9283
- var MARKER_VISIBILITY_FACTORS_STRIDE = 3;
9284
- var MARKER_ENDPOINT_STRIDE = 3;
9285
- var SCREEN_SPACE_GAZE_SOLUTION_STRIDE = 14;
9286
- var HAIR_COLOR_PRESETS = cc4_default.hairColorPresets;
9287
- var DEFAULT_HAIR_COLOR_APPEARANCE = HAIR_COLOR_PRESETS.natural_brown;
9288
- var CC4_HUMANOID_SKELETON_TEMPLATE = cc4_humanoid_default;
9289
- var HUMANOID_SKELETON_TEMPLATES = [CC4_HUMANOID_SKELETON_TEMPLATE];
9290
- var pending = null;
9291
- var loaded = null;
9292
- async function initEmbodyCore3() {
9293
- if (!pending) {
9294
- pending = load().catch((error) => {
9295
- pending = null;
9296
- loaded = null;
9297
- throw error;
9298
- });
9299
- }
9300
- return pending;
9301
- }
9302
- var getEmbodyCore = initEmbodyCore3;
9303
- function requireInitializedEmbodyCore2() {
9304
- if (!loaded) throw new Error("Embody Wasm core is not initialized. Await initEmbodyCore() first.");
9305
- return loaded;
9306
- }
9307
- function resetEmbodyCoreForTests() {
9308
- pending = null;
9309
- loaded = null;
9310
- }
9311
- async function load() {
9312
- const resolveAsset = (path) => new URL(path, import.meta.url);
9313
- const moduleUrl = resolveAsset("./wasm/embody_wasm.js").href;
9314
- const binaryUrl = resolveAsset("./wasm/embody_wasm_bg.wasm");
9315
- const core2 = await import(
9316
- /* @vite-ignore */
9317
- moduleUrl
9318
- );
9319
- if (typeof core2.default === "function") {
9320
- let input = binaryUrl;
9321
- if (globalThis.process?.versions?.node && binaryUrl.protocol === "file:") {
9322
- const fsSpecifier = "node:fs/promises";
9323
- const urlSpecifier = "node:url";
9324
- const [{ readFile }, { fileURLToPath }] = await Promise.all([
9325
- import(
9326
- /* @vite-ignore */
9327
- fsSpecifier
9328
- ),
9329
- import(
9330
- /* @vite-ignore */
9331
- urlSpecifier
9332
- )
9333
- ]);
9334
- input = await readFile(fileURLToPath(binaryUrl));
9335
- }
9336
- await core2.default({ module_or_path: input });
9337
- }
9338
- if (core2.core_abi_version() !== EMBODY_CORE_ABI_VERSION) {
9339
- throw new Error(`Unsupported Embody Wasm ABI version ${core2.core_abi_version()}.`);
9340
- }
9341
- loaded = core2;
9342
- return core2;
9343
- }
9344
-
9345
- export { ANNOTATION_CAMERA_FRAMING_STRIDE, CAMERA_FLIGHT_SAMPLE_STRIDE, CC4_HUMANOID_SKELETON_TEMPLATE, CHARACTER_SCENE_TYPES, CHARACTER_SCENE_TYPE_IDS, DPthreeCameraController as CameraController, CameraDOMControls, CameraDOMControls as Controls, DEFAULT_CHARACTER_LIGHTING_PRESETS, DEFAULT_CHARACTER_LIGHTING_PRESET_ID, DEFAULT_CHARACTER_LIGHTING_PRESET_IDS, DEFAULT_CHARACTER_LIGHTING_SETTINGS, DEFAULT_CHARACTER_SCENE_TYPE_ID, DEFAULT_HAIR_COLOR_APPEARANCE, DEFAULT_MARKER_AUTO_HIDE_MS, DEFAULT_PREVIEW_AUTO_CLEAR_MS, DPthree, DPthree3DMarkers, DPthreeCameraController, DPthreeHTMLMarkers, DPthreeMarkers, EMBODY_CORE_ABI_VERSION, HAIR_COLOR_PRESETS, HAIR_CONFIG_STRIDE, HAIR_HEAD_STATE_STRIDE, HAIR_MORPH_OUTPUT_STRIDE, HAIR_STATE_STRIDE, HUMANOID_SKELETON_TEMPLATES, MARKER_ENDPOINT_STRIDE, MARKER_VISIBILITY_FACTORS_STRIDE, MESH_PROPORTIONS_STRIDE, DPthree3DMarkers as Markers3D, DPthreeHTMLMarkers as MarkersHTML, PACKED_BONE_FRAME_DELTA_STRIDE, PACKED_MORPH_FRAME_DELTA_STRIDE, RUNTIME_ANNOTATION_REGION_PREFIX, RustAnnotationCameraCore, SCREEN_SPACE_GAZE_SOLUTION_STRIDE, TEMPLATE_SKELETON_FIT_SOLUTION_STRIDE, TEMPLATE_SKELETON_FIT_TRANSFORM_STRIDE, THREE_BLENDING_MODES, ThreeFrameApplier, ThreeGazeFocus, ThreeModelInspector, applyCharacterModelTransform, bindModelReferencePose, boneResolutionProfile, buildRegionDisplayOptions, captureModelReferencePose, collectMorphMeshes, createAnimationClipFromClipIR, createDefaultCharacterLighting, createDefaultCharacterScene, createDefaultCharacterSceneAsync, createDefaultCharacterSceneRuntime, createMarkerLifecycleRevealOptions, createMarkerVisibilityLifecycle, createRuntimeAnnotationPreviewLifecycle, createRustAnnotationCameraCore, createShadowPlane, detectAnnotationLaterality, disposeCharacterModel, extendModelReferencePose, filterCameraViewRegions, getDefaultAnnotationLaterality, getEmbodyCore, getModelLocalOrbitAngle, getRuntimeAUMeshSideOffset, getRuntimeAUMorphAnchorPoint, getRuntimeAnnotationSide, getSemanticHorizontalSign, getSemanticHorizontalSignForSide, getWorldDirectionForCameraAngle, inferRuntimeAnnotationPreviewSide, initEmbodyCore3 as initEmbodyCore, isRuntimeAnnotationRegionName, loadCharacterModel, normalizeDefaultCharacterLightingSettings, parseCharacterModel, passesMarkerCameraAngleGate, pickContinuumAnnotationAuId, requireInitializedEmbodyCore2 as requireInitializedEmbodyCore, resetEmbodyCoreForTests, resolveAnnotationCharacterConfig, resolveFaceCenter, resolveMarkerAnchorRegion, resolveRegionCameraAngle, resolveRegionVisibilityCameraAngle, serializeAnimationClips, shouldProjectMarkerAnchorToSurface, shouldUseFaceCenterForMarkerAnchor, toWorldDirection };
9928
+ export { BLENDING_MODES, CHARACTER_SCENE_TYPES, CHARACTER_SCENE_TYPE_IDS, DPthreeCameraController as CameraController, CameraDOMControls, CameraDOMControls as Controls, DEFAULT_CHARACTER_LIGHTING_PRESETS, DEFAULT_CHARACTER_LIGHTING_PRESET_ID, DEFAULT_CHARACTER_LIGHTING_PRESET_IDS, DEFAULT_CHARACTER_LIGHTING_SETTINGS, DEFAULT_CHARACTER_SCENE_TYPE_ID, DEFAULT_MARKER_AUTO_HIDE_MS, DEFAULT_PREVIEW_AUTO_CLEAR_MS, DPthree, DPthree3DMarkers, DPthreeCameraController, DPthreeHTMLMarkers, DPthreeMarkers, Embody, DPthree3DMarkers as Markers3D, DPthreeHTMLMarkers as MarkersHTML, RUNTIME_ANNOTATION_REGION_PREFIX, RustAnnotationCameraCore, THREE_BLENDING_MODES, ThreeFrameApplier, ThreeModelInspector, ThreeNativePlaybackConnector, analyzeModel, applyAUBoneBindingUpdate, applyBilateralAxisBindingUpdate, applyBoneAxisBindingUpdate, applyCharacterModelTransform, bindModelReferencePose, boneResolutionProfile, buildBoneAuOptions, buildRegionDisplayOptions, captureModelReferencePose, classifyAuAsJointControl, collectMorphMeshes, computeHumanoidSkeletonTemplateRestBounds, createAnimationClipFromClipIR, createBilateralBoneAxisAu, createBoneAxisAu, createCharacterHost, createDefaultCharacterLighting, createDefaultCharacterScene, createDefaultCharacterSceneAsync, createDefaultCharacterSceneRuntime, createMarkerLifecycleRevealOptions, createMarkerVisibilityLifecycle, createRuntimeAnnotationPreviewLifecycle, createRustAnnotationCameraCore, createRustEmbodyHost, createRustEmbodyHostUnbound, createScenePlaybackFrame, createShadowPlane, createValidationSkeletonFromHumanoidTemplate, detectAnnotationLaterality, disposeCharacterModel, ensureBilateralBoneNodeKeys, ensureBoneNodeKey, extendCharacterConfigWithPreset, extendModelReferencePose, extractHumanoidSkeletonTemplateFromModel, extractModelData, extractProfileOverrides, filterCameraViewRegions, findNodeKeyForBone, formatAxisDirectionLabel, formatAxisLabel, fuzzyNameMatch, getAUBoneBindingState, getAxisFromChannel, getBilateralAxisBindingState, getBodyControls, getBoneAxisBindingState, getDefaultAnnotationLaterality, getHumanoidSkeletonTemplate, getHumanoidSkeletonTemplateBoneNames, getHumanoidSpecification, getMeshNamesForAUProfile, getModelLocalOrbitAngle, getPreset, getRuntimeAUMeshSideOffset, getRuntimeAUMorphAnchorPoint, getRuntimeAnnotationSide, getSemanticHorizontalSign, getSemanticHorizontalSignForSide, getWorldDirectionForCameraAngle, hasLeftRightMorphs, inferChiralBoneNamePair, inferEyeControlFamily, inferEyeControlScope, inferRuntimeAnnotationPreviewSide, isJointControlAuInfo, isMaxDegreesOnlyAxisBindingUpdate, isMixedAU, isRuntimeAnnotationRegionName, loadCharacterModel, mergeCharacterRegionsByName, normalizeDefaultCharacterLightingSettings, normalizeHairColorAppearance, parseCharacterModel, passesMarkerCameraAngleGate, pickContinuumAnnotationAuId, renderScenePlayback, resolveAnnotationCharacterConfig, resolveBoneAxisChannel, resolveBoneNameForNodeKey, resolveBoneNames, resolveContinuumDisplayLabel, resolveFaceCenter, resolveHumanoidCharacterization, resolveMarkerAnchorRegion, resolveRegionCameraAngle, resolveRegionVisibilityCameraAngle, resolveVisemeProfile, serializeAnimationClips, setAUMorphTargets, setHumanoidRoleBinding, shouldProjectMarkerAnchorToSurface, shouldUseFaceCenterForMarkerAnchor, stripConfiguredBoneAffixes, supportsRustEmbodyPreset, toWorldDirection, validateHumanoidCharacterization, validateMappings };
9346
9929
  //# sourceMappingURL=index.js.map
9347
9930
  //# sourceMappingURL=index.js.map