@lovelace_lol/embody 0.0.3 → 0.0.4

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/three.js CHANGED
@@ -3920,14 +3920,6 @@ var PACKED_BONE_FLAG_HAS_POSITION = 1;
3920
3920
  var PACKED_BONE_FLAG_HAS_ROTATION = 2;
3921
3921
 
3922
3922
  // src/core/WasmRuntimeCore.ts
3923
- var AXIS_GROUP_NEGATIVE = 0;
3924
- var AXIS_GROUP_POSITIVE = 1;
3925
- var AXIS_GROUP_PLAIN = 2;
3926
- var BONE_SIDE_NONE = 0;
3927
- var BONE_SIDE_LEFT = 1;
3928
- var BONE_SIDE_RIGHT = 2;
3929
- var ROTATION_CHANNELS = { rx: 0, ry: 1, rz: 2 };
3930
- var TRANSLATION_CHANNELS = { tx: 0, ty: 1, tz: 2 };
3931
3923
  var WasmRuntimeCore = class {
3932
3924
  constructor(options) {
3933
3925
  __publicField(this, "wasm");
@@ -3941,12 +3933,11 @@ var WasmRuntimeCore = class {
3941
3933
  if (!RuntimeCtor) {
3942
3934
  throw new Error("Embody Wasm module does not export RuntimeCore");
3943
3935
  }
3944
- this.core = new RuntimeCtor(getProfileVisemeSlots(options.profile).length);
3936
+ this.core = new RuntimeCtor(0);
3945
3937
  this.reloadBindings();
3946
3938
  }
3947
3939
  setProfile(profile) {
3948
3940
  this.profile = profile;
3949
- this.core.set_viseme_slot_count(getProfileVisemeSlots(profile).length);
3950
3941
  this.reloadBindings();
3951
3942
  }
3952
3943
  setModelDescriptor(model) {
@@ -3991,191 +3982,9 @@ var WasmRuntimeCore = class {
3991
3982
  };
3992
3983
  }
3993
3984
  reloadBindings() {
3994
- const { auBindings, mixedAus, visemeBindings } = compileMorphBindings(this.profile, this.model);
3995
- this.core.load_au_morph_bindings(auBindings);
3996
- this.core.load_viseme_morph_bindings(visemeBindings);
3997
- this.core.set_mixed_aus(mixedAus);
3998
- const boneBindings = compileBoneBindings(this.profile, this.model);
3999
- this.core.load_bone_rest_transforms(boneBindings.restTransforms);
4000
- this.core.load_composite_axes(boneBindings.compositeAxes);
4001
- this.core.load_bone_translations(boneBindings.translations);
4002
- this.core.load_jaw_binding(boneBindings.jawBinding);
4003
- this.core.load_viseme_jaw_amounts(boneBindings.visemeJawAmounts);
3985
+ this.core.configure_with_profile(JSON.stringify(this.profile), JSON.stringify(this.model));
4004
3986
  }
4005
3987
  };
4006
- function compileMorphBindings(profile, model) {
4007
- const auRows = [];
4008
- const mixed = [];
4009
- for (const [auIdText, entry] of Object.entries(profile.auToMorphs || {})) {
4010
- const auId = Number(auIdText);
4011
- if (Number.isNaN(auId) || !entry) continue;
4012
- const meshNames = getMeshNamesForAUProfile(profile, auId);
4013
- const hasMorphs = !!(entry.left?.length || entry.right?.length || entry.center?.length);
4014
- if (hasMorphs && profile.auToBones?.[auId]?.length) {
4015
- mixed.push(auId);
4016
- }
4017
- pushAuSide(auRows, auId, 0, entry.left || [], meshNames, model, profile);
4018
- pushAuSide(auRows, auId, 1, entry.right || [], meshNames, model, profile);
4019
- pushAuSide(auRows, auId, 2, entry.center || [], meshNames, model, profile);
4020
- }
4021
- const visemeRows = [];
4022
- const visemeMeshNames = getMeshNamesForVisemeProfile(profile);
4023
- const slotCount = getProfileVisemeSlots(profile).length;
4024
- for (let index = 0; index < slotCount; index += 1) {
4025
- for (const bindingTarget of getVisemeBindingTargets(profile, index)) {
4026
- for (const resolved of resolveMorphTargets(model, profile, bindingTarget.morph, visemeMeshNames)) {
4027
- visemeRows.push(
4028
- index,
4029
- Number(resolved.mesh.id),
4030
- Number(resolved.morphTarget.id),
4031
- bindingTarget.weight
4032
- );
4033
- }
4034
- }
4035
- }
4036
- return {
4037
- auBindings: Float32Array.from(auRows),
4038
- visemeBindings: Float32Array.from(visemeRows),
4039
- mixedAus: Uint32Array.from(mixed)
4040
- };
4041
- }
4042
- function compileBoneBindings(profile, model) {
4043
- const referencedBones = /* @__PURE__ */ new Map();
4044
- const findBone = (nodeKey) => {
4045
- const bone = findBoneDescriptor(profile, model, nodeKey);
4046
- if (bone) referencedBones.set(bone.id, bone);
4047
- return bone;
4048
- };
4049
- const boneSideForAU = (auId, nodeKey) => {
4050
- const side = profile.auToBones?.[auId]?.find((candidate) => candidate.node === nodeKey)?.side;
4051
- if (side === "left") return BONE_SIDE_LEFT;
4052
- if (side === "right") return BONE_SIDE_RIGHT;
4053
- return BONE_SIDE_NONE;
4054
- };
4055
- const compositeRows = [];
4056
- for (const composite of profile.compositeRotations || []) {
4057
- const bone = findBone(composite.node);
4058
- if (!bone) continue;
4059
- const axes = [
4060
- { axis: 1, config: composite.yaw },
4061
- { axis: 0, config: composite.pitch },
4062
- { axis: 2, config: composite.roll }
4063
- ];
4064
- for (const { axis, config } of axes) {
4065
- if (!config) continue;
4066
- const negativeAUs = toAUList(config.negative);
4067
- const positiveAUs = toAUList(config.positive);
4068
- const hasDirectional = negativeAUs.length > 0 && positiveAUs.length > 0;
4069
- const valueRows = [];
4070
- if (hasDirectional) {
4071
- for (const auId of negativeAUs) {
4072
- valueRows.push([auId, AXIS_GROUP_NEGATIVE, boneSideForAU(auId, composite.node)]);
4073
- }
4074
- for (const auId of positiveAUs) {
4075
- valueRows.push([auId, AXIS_GROUP_POSITIVE, boneSideForAU(auId, composite.node)]);
4076
- }
4077
- } else {
4078
- for (const auId of config.aus) {
4079
- valueRows.push([auId, AXIS_GROUP_PLAIN, boneSideForAU(auId, composite.node)]);
4080
- }
4081
- }
4082
- const bindingRows = [];
4083
- const pushBindingRows = (auIds, group) => {
4084
- for (const auId of auIds) {
4085
- const binding = profile.auToBones?.[auId]?.find(
4086
- (candidate) => candidate.node === composite.node
4087
- );
4088
- if (!binding?.maxDegrees) continue;
4089
- const channel = ROTATION_CHANNELS[binding.channel];
4090
- if (channel === void 0) continue;
4091
- bindingRows.push([
4092
- auId,
4093
- group,
4094
- boneSideForAU(auId, composite.node),
4095
- channel,
4096
- binding.scale,
4097
- binding.maxDegrees
4098
- ]);
4099
- }
4100
- };
4101
- pushBindingRows(negativeAUs, AXIS_GROUP_NEGATIVE);
4102
- pushBindingRows(positiveAUs, AXIS_GROUP_POSITIVE);
4103
- pushBindingRows(config.aus, AXIS_GROUP_PLAIN);
4104
- compositeRows.push(
4105
- Number(bone.id),
4106
- axis,
4107
- hasDirectional ? 1 : 0,
4108
- valueRows.length,
4109
- bindingRows.length,
4110
- 0,
4111
- 0,
4112
- 0
4113
- );
4114
- for (const row of valueRows) compositeRows.push(...row);
4115
- for (const row of bindingRows) compositeRows.push(...row);
4116
- }
4117
- }
4118
- const translationRows = [];
4119
- for (const [auIdText, bindings] of Object.entries(profile.auToBones || {})) {
4120
- const auId = Number(auIdText);
4121
- if (Number.isNaN(auId)) continue;
4122
- for (const binding of bindings || []) {
4123
- const channel = TRANSLATION_CHANNELS[binding.channel];
4124
- if (channel === void 0 || binding.maxUnits === void 0) continue;
4125
- const bone = findBone(binding.node);
4126
- if (!bone) continue;
4127
- translationRows.push(auId, Number(bone.id), channel, binding.scale, binding.maxUnits);
4128
- }
4129
- }
4130
- const jawRow = [];
4131
- const jawBinding = findAutoVisemeJawBinding(profile, model);
4132
- if (jawBinding?.maxDegrees) {
4133
- const bone = findBone(jawBinding.node);
4134
- const channel = ROTATION_CHANNELS[jawBinding.channel];
4135
- if (bone && channel !== void 0) {
4136
- jawRow.push(Number(bone.id), channel, jawBinding.scale, jawBinding.maxDegrees);
4137
- }
4138
- }
4139
- const restRows = [];
4140
- for (const bone of referencedBones.values()) {
4141
- const position = bone.restTransform?.position;
4142
- const rotation = bone.restTransform?.rotation;
4143
- restRows.push(
4144
- Number(bone.id),
4145
- position?.x ?? 0,
4146
- position?.y ?? 0,
4147
- position?.z ?? 0,
4148
- rotation?.x ?? 0,
4149
- rotation?.y ?? 0,
4150
- rotation?.z ?? 0,
4151
- rotation?.w ?? 1
4152
- );
4153
- }
4154
- return {
4155
- restTransforms: Float32Array.from(restRows),
4156
- compositeAxes: Float32Array.from(compositeRows),
4157
- translations: Float32Array.from(translationRows),
4158
- jawBinding: Float32Array.from(jawRow),
4159
- visemeJawAmounts: Float32Array.from(getVisemeJawAmounts(profile) ?? [])
4160
- };
4161
- }
4162
- function findBoneDescriptor(profile, model, nodeKey) {
4163
- const configuredName = profile.boneNodes?.[nodeKey] || nodeKey;
4164
- const prefix = profile.bonePrefix ?? "";
4165
- const suffix = profile.boneSuffix ?? "";
4166
- const prefixedName = prefix && !configuredName.startsWith(prefix) ? `${prefix}${configuredName}` : configuredName;
4167
- const fullName = suffix && !prefixedName.endsWith(suffix) ? `${prefixedName}${suffix}` : prefixedName;
4168
- const candidates = /* @__PURE__ */ new Set([nodeKey, configuredName, fullName]);
4169
- return model.bones.find((bone) => candidates.has(bone.name));
4170
- }
4171
- function findAutoVisemeJawBinding(profile, model) {
4172
- const isRotation = (binding) => binding?.channel === "rx" || binding?.channel === "ry" || binding?.channel === "rz";
4173
- const candidates = [
4174
- profile.auToBones?.[103]?.find(isRotation),
4175
- profile.auToBones?.[26]?.find(isRotation)
4176
- ].filter((binding) => !!binding);
4177
- return candidates.find((binding) => !!findBoneDescriptor(profile, model, binding.node)) ?? candidates[0] ?? null;
4178
- }
4179
3988
  function unpackBoneFrameDelta(values) {
4180
3989
  const stride = PACKED_BONE_FRAME_DELTA_STRIDE;
4181
3990
  const writes = [];
@@ -4216,46 +4025,6 @@ function unpackMorphFrameDelta(values) {
4216
4025
  }
4217
4026
  return writes;
4218
4027
  }
4219
- function pushAuSide(rows, auId, side, morphs, meshNames, model, profile) {
4220
- for (const morph of morphs) {
4221
- for (const resolved of resolveMorphTargets(model, profile, morph, meshNames)) {
4222
- rows.push(
4223
- auId,
4224
- side,
4225
- Number(resolved.mesh.id),
4226
- Number(resolved.morphTarget.id),
4227
- 1
4228
- );
4229
- }
4230
- }
4231
- }
4232
- function resolveMorphTargets(model, profile, morph, meshNames) {
4233
- const result = [];
4234
- for (const meshName of meshNames) {
4235
- const mesh = model.meshes.find((candidate) => candidate.name === meshName);
4236
- if (!mesh) continue;
4237
- const morphTargets = mesh.morphTargetIds.map((id) => model.morphTargets.find((candidate) => candidate.id === id)).filter((target2) => !!target2);
4238
- const target = typeof morph === "number" ? morphTargets.find((candidate) => candidate.hostIndex === morph) : resolveMorphTargetByName2(morphTargets, morph, profile);
4239
- if (target) {
4240
- result.push({ mesh, morphTarget: target });
4241
- }
4242
- }
4243
- return result;
4244
- }
4245
- function resolveMorphTargetByName2(targets, key, profile) {
4246
- const prefix = profile.morphPrefix || "";
4247
- const suffix = profile.morphSuffix || "";
4248
- const fullName = prefix + key + suffix;
4249
- const exact = targets.find((target) => target.name === fullName);
4250
- if (exact) return exact;
4251
- const suffixRegex = profile.suffixPattern ? new RegExp(profile.suffixPattern) : null;
4252
- if (!suffixRegex) return void 0;
4253
- return targets.find((target) => {
4254
- if (!target.name.startsWith(fullName)) return false;
4255
- const candidateSuffix = target.name.slice(fullName.length);
4256
- return candidateSuffix === "" || suffixRegex.test(candidateSuffix);
4257
- });
4258
- }
4259
4028
 
4260
4029
  // src/hair/appearance.ts
4261
4030
  var HAIR_COLOR_PRESETS = {