@lovelace_lol/polymer 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +434 -12
  2. package/dist/index.d.ts +1945 -244
  3. package/dist/index.js +1686 -1017
  4. package/dist/vision/face-worker.js +296 -0
  5. package/dist/vision/face_landmarker.task +0 -0
  6. package/dist/vision/manifest.edn +1 -0
  7. package/dist/vision/vision_bundle.js +2 -0
  8. package/dist/vision/wasm/vision_wasm_internal.js +8841 -0
  9. package/dist/vision/wasm/vision_wasm_internal.wasm +0 -0
  10. package/dist/vision/wasm/vision_wasm_module_internal.js +8837 -0
  11. package/dist/vision/wasm/vision_wasm_module_internal.wasm +0 -0
  12. package/dist/vision/wasm/vision_wasm_nosimd_internal.js +8832 -0
  13. package/dist/vision/wasm/vision_wasm_nosimd_internal.wasm +0 -0
  14. package/dist/worker/agency-worker.js +1276 -962
  15. package/dist/worker/manifest.edn +1 -1
  16. package/package.json +33 -20
  17. package/dist/test.cjs +0 -1519
  18. package/shadow-cljs.edn +0 -173
  19. package/src/polymer/animation/agency.cljs +0 -84
  20. package/src/polymer/animation/domain.cljs +0 -110
  21. package/src/polymer/animation/planner.cljs +0 -88
  22. package/src/polymer/animation/runtime.cljs +0 -137
  23. package/src/polymer/animation/scheduler.cljs +0 -178
  24. package/src/polymer/animation/service.cljs +0 -981
  25. package/src/polymer/animation/state.cljs +0 -112
  26. package/src/polymer/blink/agency.cljs +0 -131
  27. package/src/polymer/blink/planner.cljs +0 -115
  28. package/src/polymer/blink/scheduler.cljs +0 -90
  29. package/src/polymer/blink/snippet.cljs +0 -50
  30. package/src/polymer/blink/state.cljs +0 -102
  31. package/src/polymer/camera_context/agency.cljs +0 -132
  32. package/src/polymer/camera_context/domain.cljs +0 -186
  33. package/src/polymer/camera_context/planner.cljs +0 -50
  34. package/src/polymer/camera_context/scheduler.cljs +0 -113
  35. package/src/polymer/camera_context/state.cljs +0 -121
  36. package/src/polymer/character.cljs +0 -403
  37. package/src/polymer/conversation/agency.cljs +0 -83
  38. package/src/polymer/conversation/domain.cljs +0 -35
  39. package/src/polymer/conversation/effector.cljs +0 -130
  40. package/src/polymer/conversation/planner.cljs +0 -178
  41. package/src/polymer/conversation/scheduler.cljs +0 -202
  42. package/src/polymer/conversation/service.cljs +0 -329
  43. package/src/polymer/conversation/state.cljs +0 -186
  44. package/src/polymer/core.cljs +0 -172
  45. package/src/polymer/eye_head/agency.cljs +0 -75
  46. package/src/polymer/eye_head/domain.cljs +0 -133
  47. package/src/polymer/eye_head/goap.cljs +0 -106
  48. package/src/polymer/eye_head/scheduler.cljs +0 -176
  49. package/src/polymer/eye_head/service.cljs +0 -259
  50. package/src/polymer/eye_head/snippet.cljs +0 -92
  51. package/src/polymer/eye_head/state.cljs +0 -167
  52. package/src/polymer/gaze/agency.cljs +0 -85
  53. package/src/polymer/gaze/domain.cljs +0 -211
  54. package/src/polymer/gaze/goap.cljs +0 -208
  55. package/src/polymer/gaze/scheduler.cljs +0 -184
  56. package/src/polymer/gaze/state.cljs +0 -202
  57. package/src/polymer/gesture/agency.cljs +0 -185
  58. package/src/polymer/gesture/goap.cljs +0 -461
  59. package/src/polymer/gesture/scheduler.cljs +0 -122
  60. package/src/polymer/gesture/snippet.cljs +0 -198
  61. package/src/polymer/gesture/state.cljs +0 -273
  62. package/src/polymer/lipsync/agency.cljs +0 -593
  63. package/src/polymer/lipsync/articulation/jaw.cljs +0 -258
  64. package/src/polymer/lipsync/articulation/snippet.cljs +0 -605
  65. package/src/polymer/lipsync/articulation/tongue.cljs +0 -418
  66. package/src/polymer/lipsync/articulation/visemes.cljs +0 -429
  67. package/src/polymer/lipsync/goap.cljs +0 -132
  68. package/src/polymer/lipsync/pronunciation/effector.cljs +0 -51
  69. package/src/polymer/lipsync/scheduler.cljs +0 -302
  70. package/src/polymer/lipsync/state.cljs +0 -202
  71. package/src/polymer/nlp/phonemes.cljs +0 -164
  72. package/src/polymer/prosodic/agency.cljs +0 -196
  73. package/src/polymer/prosodic/goap.cljs +0 -122
  74. package/src/polymer/prosodic/scheduler.cljs +0 -99
  75. package/src/polymer/prosodic/snippet.cljs +0 -106
  76. package/src/polymer/prosodic/state.cljs +0 -139
  77. package/src/polymer/runtime/embody.cljs +0 -117
  78. package/src/polymer/runtime/embody_wasm.cljs +0 -177
  79. package/src/polymer/runtime/rust_embody_host.cljs +0 -647
  80. package/src/polymer/society.cljs +0 -253
  81. package/src/polymer/stream.cljs +0 -130
  82. package/src/polymer/transcription/agency.cljs +0 -69
  83. package/src/polymer/transcription/domain.cljs +0 -68
  84. package/src/polymer/transcription/effector.cljs +0 -611
  85. package/src/polymer/transcription/planner.cljs +0 -203
  86. package/src/polymer/transcription/scheduler.cljs +0 -225
  87. package/src/polymer/transcription/service.cljs +0 -209
  88. package/src/polymer/transcription/state.cljs +0 -239
  89. package/src/polymer/tts/agency.cljs +0 -503
  90. package/src/polymer/tts/azure.cljs +0 -290
  91. package/src/polymer/tts/planner.cljs +0 -178
  92. package/src/polymer/tts/runtime.cljs +0 -624
  93. package/src/polymer/tts/scheduler.cljs +0 -162
  94. package/src/polymer/tts/state.cljs +0 -191
  95. package/src/polymer/worker.cljs +0 -81
@@ -1,647 +0,0 @@
1
- (ns polymer.runtime.rust-embody-host
2
- "Polymer-owned CLJS host for Embody's Rust/Wasm RuntimeCore.
3
-
4
- Rust owns profile/preset intake, binding compilation, control state, and
5
- packed frame evaluation. This namespace owns the JavaScript object exposed to
6
- hosts and the narrow Three.js inspection/application boundary."
7
- (:require ["@lovelace_lol/embody" :as embody]
8
- [polymer.runtime.embody-wasm :as embody-wasm]))
9
-
10
- (def ThreeModelInspector (aget embody "ThreeModelInspector"))
11
- (def ThreeFrameApplier (aget embody "ThreeFrameApplier"))
12
- (def ThreeAnimationRuntime (aget embody "ThreeAnimationRuntime"))
13
- (def ThreeAnimationSystem (aget embody "ThreeAnimationSystem"))
14
- (def HairPhysicsController (aget embody "HairPhysicsController"))
15
- (def build-frame-applier-bindings (aget embody "buildFrameApplierBindings"))
16
- (def get-mesh-names-for-au-profile (aget embody "getMeshNamesForAUProfile"))
17
- (def get-mesh-names-for-viseme-profile (aget embody "getMeshNamesForVisemeProfile"))
18
-
19
- (defn- js-call
20
- [target method & args]
21
- (let [f (when target (aget target method))]
22
- (when-not (fn? f)
23
- (throw (js/Error. (str "Character host is missing method: " method))))
24
- (.apply f target (to-array args))))
25
-
26
- (defn- js-new
27
- [ctor & args]
28
- (when-not ctor
29
- (throw (js/Error. "The installed Embody package is missing a required Three.js adapter export.")))
30
- (.construct js/Reflect ctor (to-array args)))
31
-
32
- (defn- js-values
33
- [value]
34
- (if (array? value) (array-seq value) ()))
35
-
36
- (defn- clamp01
37
- [value]
38
- (max 0 (min 1 (if (and (number? value) (js/isFinite value)) value 0))))
39
-
40
- (defn- normalize-preset-id
41
- [preset-id]
42
- (let [normalized (when (string? preset-id) (.toLowerCase (.trim preset-id)))]
43
- (if (or (nil? normalized) (= "" normalized))
44
- "cc4"
45
- normalized)))
46
-
47
- (defn- normalize-profile-mode
48
- [profile-mode]
49
- (let [normalized (when (string? profile-mode)
50
- (.toLowerCase (.trim profile-mode)))]
51
- (case normalized
52
- (nil "" "preset" "embedded-preset") "preset"
53
- ("profile" "resolved-profile" "exact" "exact-profile") "profile"
54
- (throw (js/Error.
55
- (str "Unknown Rust Embody profileMode \"" profile-mode
56
- "\". Expected \"preset\" or \"profile\"."))))))
57
-
58
- (defn- profile-json
59
- [profile required?]
60
- (cond
61
- (nil? profile)
62
- (if required?
63
- (throw (js/Error. "Rust Embody profile mode requires a resolved profile object."))
64
- "")
65
-
66
- (or (array? profile) (not= "object" (goog/typeOf profile)))
67
- (throw (js/Error. "Rust Embody profile must be a JSON object."))
68
-
69
- :else
70
- (.stringify js/JSON profile)))
71
-
72
- (defn supports-preset?
73
- "True when the initialized Rust/Wasm registry contains the requested preset."
74
- [preset-id]
75
- (let [wasm (embody-wasm/get-core)]
76
- (boolean (js-call wasm "has_preset" (normalize-preset-id preset-id)))))
77
-
78
- (def supportsRustEmbodyPreset supports-preset?)
79
-
80
- (defn- profile-map
81
- [profile key]
82
- (or (when profile (aget profile key)) #js {}))
83
-
84
- (defn- profile-array
85
- [profile key]
86
- (let [value (when profile (aget profile key))]
87
- (if (array? value) value #js [])))
88
-
89
- (defn- resolved-meshes
90
- [meshes mesh-by-name profile mesh-names]
91
- (let [requested (if (and (array? mesh-names) (pos? (.-length mesh-names)))
92
- mesh-names
93
- (let [face (aget (profile-map profile "morphToMesh") "face")]
94
- (if (and (array? face) (pos? (.-length face)))
95
- face
96
- (.map meshes (fn [mesh] (.-name mesh))))))]
97
- (keep (fn [name] (.get mesh-by-name name)) (js-values requested))))
98
-
99
- (defn- resolve-morph-targets
100
- [meshes mesh-by-name profile morph-key mesh-names]
101
- (reduce
102
- (fn [targets mesh]
103
- (let [dictionary (aget mesh "morphTargetDictionary")
104
- influences (aget mesh "morphTargetInfluences")
105
- index (cond
106
- (number? morph-key) morph-key
107
- dictionary (aget dictionary morph-key)
108
- :else nil)]
109
- (if (and influences (number? index) (<= 0 index) (< index (.-length influences)))
110
- (conj targets #js {:infl influences :idx index})
111
- targets)))
112
- []
113
- (resolved-meshes meshes mesh-by-name profile mesh-names)))
114
-
115
- (defn- current-morph-value
116
- [meshes mesh-by-name profile morph-key mesh-names]
117
- (reduce
118
- (fn [current target]
119
- (max current (or (aget (aget target "infl") (aget target "idx")) 0)))
120
- 0
121
- (resolve-morph-targets meshes mesh-by-name profile morph-key mesh-names)))
122
-
123
- (defn- mixed-au?
124
- [profile au-id]
125
- (let [morphs (aget (profile-map profile "auToMorphs") (str au-id))
126
- bones (aget (profile-map profile "auToBones") (str au-id))
127
- has-morphs (and morphs
128
- (some #(pos? (.-length (or (aget morphs %) #js [])))
129
- ["left" "right" "center"]))]
130
- (boolean (and has-morphs (array? bones) (pos? (.-length bones))))))
131
-
132
- (defn- animation-method!
133
- [host animation-system method]
134
- (aset host method
135
- (fn [& args]
136
- (apply js-call @animation-system method args))))
137
-
138
- (def animation-methods
139
- ["loadAnimationClips"
140
- "getAnimationClips"
141
- "removeAnimationClip"
142
- "playAnimation"
143
- "stopAnimation"
144
- "stopAllAnimations"
145
- "pauseAnimation"
146
- "resumeAnimation"
147
- "pauseAllAnimations"
148
- "resumeAllAnimations"
149
- "setAnimationSpeed"
150
- "setAnimationIntensity"
151
- "setAnimationLoopMode"
152
- "setAnimationRepeatCount"
153
- "setAnimationReverse"
154
- "setAnimationBlendMode"
155
- "seekAnimation"
156
- "setAnimationTimeScale"
157
- "getAnimationState"
158
- "getPlayingAnimations"
159
- "crossfadeTo"
160
- "snippetToClip"
161
- "playClip"
162
- "playSnippet"
163
- "typedSnippetToClip"
164
- "playTypedSnippet"
165
- "buildClip"
166
- "buildTypedClip"
167
- "updateClipParams"
168
- "cleanupSnippet"
169
- "supportsClipCurves"])
170
-
171
- (defn create-rust-embody-host-unbound
172
- "Create Polymer's synchronous CLJS host after initEmbodyCore has completed."
173
- ([]
174
- (create-rust-embody-host-unbound #js {}))
175
- ([config]
176
- (let [config (or config #js {})
177
- wasm (embody-wasm/get-core)
178
- profile-mode (normalize-profile-mode (aget config "profileMode"))
179
- resolved-profile? (= profile-mode "profile")
180
- preset-id (normalize-preset-id
181
- (or (aget config "presetId") (aget config "presetType")))
182
- _ (when (and (not resolved-profile?)
183
- (not (js-call wasm "has_preset" preset-id)))
184
- (throw (js/Error.
185
- (str "Rust Embody preset \"" preset-id
186
- "\" is not embedded. Known presets: "
187
- (.join (js-call wasm "list_presets") ", ") "."))))
188
- profile-source-json (atom (profile-json (aget config "profile") resolved-profile?))
189
- profile (atom (if resolved-profile?
190
- (.parse js/JSON @profile-source-json)
191
- (.parse js/JSON
192
- (js-call wasm
193
- "merge_embedded_preset"
194
- preset-id
195
- @profile-source-json))))
196
- RuntimeCore (aget wasm "RuntimeCore")
197
- core (js-new RuntimeCore 0)
198
- inspector (js-new ThreeModelInspector)
199
- applier (js-new ThreeFrameApplier)
200
- morph-transitions (js-new ThreeAnimationRuntime)
201
- model (atom nil)
202
- meshes (atom #js [])
203
- all-meshes (atom #js [])
204
- mesh-by-name (atom (js/Map.))
205
- bones (atom #js {})
206
- inspection (atom nil)
207
- animation-system (atom nil)
208
- hair-runtime (atom nil)
209
- viseme-values (atom #js [])
210
- mix-weights (atom {})
211
- running? (atom false)
212
- raf-id (atom nil)
213
- last-frame-ms (atom nil)
214
- host (js-obj)]
215
- (letfn [(apply-frame! []
216
- (let [morph-frame (js-call core "evaluate_morph_frame_delta")
217
- bone-frame (js-call core "evaluate_bone_frame_delta")]
218
- (when (pos? (.-length morph-frame))
219
- (js-call applier "applyPackedMorphFrameDelta" morph-frame))
220
- (when (pos? (.-length bone-frame))
221
- (js-call applier "applyPackedBoneFrameDelta" bone-frame)
222
- (when @model
223
- (js-call @model "updateMatrixWorld" true)))))
224
-
225
- (bind-model! [mesh-overrides]
226
- (when @model
227
- (let [options (if mesh-overrides
228
- #js {:profile @profile :meshes mesh-overrides}
229
- #js {:profile @profile})
230
- result (js-call inspector "inspectModel" @model options)
231
- model-meshes (aget result "allMeshes")
232
- runtime-meshes (let [morph-meshes (aget result "morphMeshes")]
233
- (if (and morph-meshes (pos? (.-length morph-meshes)))
234
- morph-meshes
235
- model-meshes))]
236
- (reset! inspection result)
237
- (reset! meshes runtime-meshes)
238
- (reset! all-meshes model-meshes)
239
- (reset! mesh-by-name (aget result "meshByName"))
240
- (reset! bones (aget result "bones"))
241
- (aset host "meshes" runtime-meshes)
242
- (aset host "meshByName" @mesh-by-name)
243
- (aset host "bones" @bones)
244
- (js-call applier "setBindings" (build-frame-applier-bindings result))
245
- (js-call applier
246
- "applyMeshMaterialConfigs"
247
- @model
248
- (profile-map @profile "meshes"))
249
- (when @hair-runtime
250
- (js-call @hair-runtime "registerHairObjects" (to-array (hair-meshes)))
251
- (js-call @hair-runtime
252
- "setHairPhysicsProfileConfig"
253
- (aget @profile "hairPhysics")))
254
- (let [descriptor-json (.stringify js/JSON (aget result "descriptor"))]
255
- (if resolved-profile?
256
- (js-call core
257
- "configure_with_profile"
258
- @profile-source-json
259
- descriptor-json)
260
- (js-call core
261
- "configure_with_preset"
262
- preset-id
263
- @profile-source-json
264
- descriptor-json)))
265
- (apply-frame!))))
266
-
267
- (set-profile! [next-profile]
268
- (js-call core "clear")
269
- (js-call morph-transitions "clearTransitions")
270
- (apply-frame!)
271
- (reset! viseme-values #js [])
272
- (reset! mix-weights {})
273
- (reset! profile-source-json (profile-json next-profile resolved-profile?))
274
- (reset! profile
275
- (if resolved-profile?
276
- (.parse js/JSON @profile-source-json)
277
- (.parse js/JSON
278
- (js-call wasm
279
- "merge_embedded_preset"
280
- preset-id
281
- @profile-source-json))))
282
- (bind-model! @meshes))
283
-
284
- (get-au-mix-weight [au-id]
285
- (or (get @mix-weights au-id)
286
- (aget (profile-map @profile "auMixDefaults") (str au-id))
287
- 1))
288
-
289
- (set-morph! [morph-key value mesh-names]
290
- (let [targets (resolve-morph-targets
291
- @meshes @mesh-by-name @profile morph-key mesh-names)
292
- normalized (clamp01 value)]
293
- (doseq [target targets]
294
- (aset (aget target "infl") (aget target "idx") normalized))))
295
-
296
- (transition-morph! [morph-key value duration-ms mesh-names]
297
- (let [targets (resolve-morph-targets
298
- @meshes @mesh-by-name @profile morph-key mesh-names)
299
- from (reduce
300
- (fn [current target]
301
- (max current
302
- (or (aget (aget target "infl") (aget target "idx")) 0)))
303
- 0
304
- targets)
305
- target (clamp01 value)
306
- mesh-key (if (and (array? mesh-names) (pos? (.-length mesh-names)))
307
- (.join mesh-names ",")
308
- "*")]
309
- (js-call morph-transitions
310
- "addTransition"
311
- (str "morph:" mesh-key ":" morph-key)
312
- from
313
- target
314
- (or duration-ms 120)
315
- (fn [next-value]
316
- (doseq [resolved targets]
317
- (aset (aget resolved "infl")
318
- (aget resolved "idx")
319
- (clamp01 next-value)))))))
320
-
321
- (update! [dt-seconds]
322
- (let [dt (max 0 (if (and (number? dt-seconds) (js/isFinite dt-seconds))
323
- dt-seconds
324
- 0))]
325
- (when (pos? dt)
326
- (let [active-before (js-call core "active_transition_count")
327
- active-after (js-call core "update" dt)]
328
- (js-call morph-transitions "tick" dt)
329
- (when (or (pos? active-before) (pos? active-after))
330
- (apply-frame!))
331
- (when @animation-system
332
- (js-call @animation-system "update" dt))
333
- (when @hair-runtime
334
- (js-call @hair-runtime "update" dt))))))
335
-
336
- (request-next-frame! []
337
- (when @running?
338
- (when-let [request-frame (aget js/globalThis "requestAnimationFrame")]
339
- (reset! raf-id
340
- (.call request-frame
341
- js/globalThis
342
- (fn [now-ms]
343
- (let [previous @last-frame-ms
344
- dt (if previous
345
- (/ (max 0 (- now-ms previous)) 1000)
346
- 0)]
347
- (reset! last-frame-ms now-ms)
348
- (update! dt)
349
- (request-next-frame!))))))))
350
-
351
- (stop! []
352
- (reset! running? false)
353
- (reset! last-frame-ms nil)
354
- (when (some? @raf-id)
355
- (when-let [cancel-frame (aget js/globalThis "cancelAnimationFrame")]
356
- (.call cancel-frame js/globalThis @raf-id))
357
- (reset! raf-id nil)))
358
-
359
- (hair-meshes []
360
- (filter
361
- (fn [mesh]
362
- (let [info (aget (profile-map @profile "meshes") (.-name mesh))
363
- category (when info (aget info "category"))]
364
- (or (= category "hair") (= category "eyebrow"))))
365
- (js-values @all-meshes)))]
366
- (let [animation-host
367
- #js {:getModel (fn [] @model)
368
- :getMeshes (fn [] @meshes)
369
- :getMeshByName (fn [name] (.get @mesh-by-name name))
370
- :getMeshNamesForAU
371
- (fn [au-id] (get-mesh-names-for-au-profile @profile au-id))
372
- :getMeshNamesForViseme
373
- (fn [] (get-mesh-names-for-viseme-profile @profile))
374
- :getCurrentAUValue (fn [au-id] (js-call core "get_au" au-id))
375
- :getCurrentVisemeValue
376
- (fn [index] (or (aget @viseme-values index) 0))
377
- :getCurrentMorphValue
378
- (fn [morph-key mesh-names]
379
- (current-morph-value
380
- @meshes @mesh-by-name @profile morph-key mesh-names))
381
- :getCurrentMorphIndexValue
382
- (fn [morph-index mesh-names]
383
- (current-morph-value
384
- @meshes @mesh-by-name @profile morph-index mesh-names))
385
- :getCurrentBoneQuaternion
386
- (fn [node-key]
387
- (some-> (aget @bones node-key) (aget "obj") (aget "quaternion") (.clone)))
388
- :getCurrentBonePositionValue
389
- (fn [node-key axis]
390
- (some-> (aget @bones node-key) (aget "obj") (aget "position") (aget axis)))
391
- :getBones (fn [] @bones)
392
- :getConfig (fn [] @profile)
393
- :getCompositeRotations
394
- (fn [] (profile-array @profile "compositeRotations"))
395
- :computeSideValues
396
- (fn [base balance]
397
- (let [packed (embody-wasm/solve-bilateral-values base (or balance 0))]
398
- #js {:left (aget packed 0) :right (aget packed 1)}))
399
- :getAUMixWeight get-au-mix-weight
400
- :isMixedAU (fn [au-id] (mixed-au? @profile au-id))
401
- :reapplyProceduralState apply-frame!}]
402
- (reset! animation-system (js-new ThreeAnimationSystem animation-host)))
403
-
404
- (let [hair-host
405
- #js {:getMeshByName (fn [name] (.get @mesh-by-name name))
406
- :getSelectedHairMeshNames
407
- (fn []
408
- (to-array
409
- (map #(aget % "name")
410
- (filter
411
- (fn [mesh]
412
- (= "hair"
413
- (some-> (aget (profile-map @profile "meshes")
414
- (aget mesh "name"))
415
- (aget "category"))))
416
- (js-values @all-meshes)))))
417
- :buildClip
418
- (fn [clip-name curves options]
419
- (js-call @animation-system "buildClip" clip-name curves options))
420
- :cleanupSnippet
421
- (fn [clip-name]
422
- (js-call @animation-system "cleanupSnippet" clip-name))}
423
- controller (js-new HairPhysicsController hair-host)]
424
- (js-call controller "setCore" wasm)
425
- (reset! hair-runtime controller))
426
-
427
- (aset host "onReady"
428
- (fn [options]
429
- (reset! model (aget options "model"))
430
- (bind-model! (aget options "meshes"))))
431
- (aset host "bindModel" bind-model!)
432
- (aset host "setProfile" set-profile!)
433
- (aset host "getProfile" (fn [] @profile))
434
- (aset host "getProfileMode" (fn [] profile-mode))
435
- (aset host "getPresetId" (fn [] (when-not resolved-profile? preset-id)))
436
- (aset host "supportsPreset" (fn [id] (supports-preset? id)))
437
- (aset host "setAU"
438
- (fn [id value balance]
439
- (js-call core "set_au_signed" id value (if (number? balance) balance js/NaN))
440
- (apply-frame!)))
441
- (aset host "getAU" (fn [id] (js-call core "get_au" id)))
442
- (aset host "setContinuum"
443
- (fn [negative-au positive-au value balance]
444
- (js-call core
445
- "set_continuum"
446
- negative-au
447
- positive-au
448
- value
449
- (if (number? balance) balance js/NaN))
450
- (apply-frame!)))
451
- (aset host "getContinuum"
452
- (fn [negative-au positive-au]
453
- (js-call core "get_continuum" negative-au positive-au)))
454
- (aset host "transitionAU"
455
- (fn [id value duration-ms balance]
456
- (js-call core
457
- "transition_au"
458
- id
459
- value
460
- (or duration-ms 200)
461
- (if (number? balance) balance js/NaN))))
462
- (aset host "transitionViseme"
463
- (fn [index value duration-ms jaw-scale]
464
- (js-call core
465
- "transition_viseme"
466
- index
467
- value
468
- (or duration-ms 80)
469
- (or jaw-scale 1))))
470
- (aset host "setViseme"
471
- (fn [index value jaw-scale]
472
- (js-call core "set_viseme" index value)
473
- (js-call core "set_viseme_jaw_scale" index (or jaw-scale 1))
474
- (aset @viseme-values index value)
475
- (apply-frame!)))
476
- (aset host "setVisemeById"
477
- (fn [slot-id value jaw-scale]
478
- (let [index (js-call core "viseme_slot_index" slot-id)]
479
- (when (<= 0 index)
480
- (js-call host "setViseme" index value (or jaw-scale 1))))))
481
- (aset host "transitionVisemeById"
482
- (fn [slot-id value duration-ms jaw-scale]
483
- (let [index (js-call core "viseme_slot_index" slot-id)]
484
- (when (<= 0 index)
485
- (js-call host
486
- "transitionViseme"
487
- index
488
- value
489
- (or duration-ms 80)
490
- (or jaw-scale 1))))))
491
- (aset host "setAUMixWeight"
492
- (fn [id weight]
493
- (swap! mix-weights assoc id weight)
494
- (js-call core "set_au_mix_weight" id weight)
495
- (apply-frame!)))
496
- (aset host "getAUMixWeight" get-au-mix-weight)
497
- (aset host "hasLeftRightBones"
498
- (fn [au-id]
499
- (let [bindings (aget (profile-map @profile "auToBones") (str au-id))
500
- sides (set (map #(aget % "side") (js-values bindings)))]
501
- (and (contains? sides "left") (contains? sides "right")))))
502
- (aset host "setMorph"
503
- (fn
504
- ([morph-key value] (set-morph! morph-key value nil))
505
- ([morph-key value mesh-names] (set-morph! morph-key value mesh-names))))
506
- (aset host "setMorphOnMeshes"
507
- (fn [mesh-names morph-key value]
508
- (set-morph! morph-key value mesh-names)))
509
- (aset host "transitionMorph"
510
- (fn
511
- ([morph-key value] (transition-morph! morph-key value 120 nil))
512
- ([morph-key value duration-ms]
513
- (transition-morph! morph-key value duration-ms nil))
514
- ([morph-key value duration-ms mesh-names]
515
- (transition-morph! morph-key value duration-ms mesh-names))))
516
- (aset host "getMorphTargets"
517
- (fn []
518
- (let [result (js-obj)]
519
- (doseq [mesh (js-values @meshes)]
520
- (when-let [dictionary (aget mesh "morphTargetDictionary")]
521
- (aset result
522
- (aget mesh "name")
523
- (.sort (.keys js/Object dictionary)))))
524
- result)))
525
- (aset host "getMorphTargetIndices"
526
- (fn []
527
- (let [result (js-obj)]
528
- (doseq [mesh (js-values @meshes)]
529
- (when-let [dictionary (aget mesh "morphTargetDictionary")]
530
- (let [entries (.map
531
- (.entries js/Object dictionary)
532
- (fn [entry]
533
- #js {:name (aget entry 0) :index (aget entry 1)}))]
534
- (.sort entries (fn [a b] (- (.-index a) (.-index b))))
535
- (aset result (aget mesh "name") entries))))
536
- result)))
537
- (aset host "getHairMorphTargets"
538
- (fn
539
- ([] (js-call @hair-runtime "getHairMorphTargets"))
540
- ([mesh-name] (js-call @hair-runtime "getHairMorphTargets" mesh-name))))
541
- (aset host "getMeshList"
542
- (fn []
543
- (.map
544
- @all-meshes
545
- (fn [mesh]
546
- (let [mesh-name (aget mesh "name")
547
- info (aget (profile-map @profile "meshes") mesh-name)]
548
- #js {:name mesh-name
549
- :visible (aget mesh "visible")
550
- :morphCount (.-length (or (aget mesh "morphTargetInfluences") #js []))
551
- :category (or (when info (aget info "category")) "other")})))))
552
- (aset host "getBones" (fn [] @bones))
553
- (aset host "setMeshVisible"
554
- (fn [mesh-name visible]
555
- (when @model
556
- (js-call applier "setMeshVisible" @model mesh-name visible))))
557
- (aset host "highlightMesh"
558
- (fn
559
- ([mesh-name]
560
- (when @model (js-call applier "highlightMesh" @model mesh-name)))
561
- ([mesh-name color]
562
- (when @model (js-call applier "highlightMesh" @model mesh-name color)))
563
- ([mesh-name color intensity]
564
- (when @model
565
- (js-call applier "highlightMesh" @model mesh-name color intensity)))))
566
- (aset host "getMeshMaterialConfig"
567
- (fn [mesh-name]
568
- (when @model
569
- (js-call applier "getMeshMaterialConfig" @model mesh-name))))
570
- (aset host "setMeshMaterialConfig"
571
- (fn [mesh-name material-config]
572
- (when @model
573
- (js-call applier
574
- "setMeshMaterialConfig"
575
- @model
576
- mesh-name
577
- material-config))))
578
- (doseq [method ["registerHairObjects"
579
- "getRegisteredHairObjects"
580
- "getHairAppearance"
581
- "setHairColor"
582
- "setEyebrowColor"
583
- "setHairBaseColor"
584
- "setEyebrowBaseColor"
585
- "setHairGlow"
586
- "setEyebrowGlow"
587
- "setHairOutline"
588
- "setHairPhysicsEnabled"
589
- "isHairPhysicsEnabled"
590
- "setHairPhysicsConfig"
591
- "getHairPhysicsConfig"
592
- "validateHairMorphTargets"
593
- "applyHairStateToObject"]]
594
- (aset host method
595
- (fn [& args]
596
- (apply js-call @hair-runtime method args))))
597
- (aset host "updateHairPhysics"
598
- (fn [dt-seconds]
599
- (js-call @hair-runtime "update" dt-seconds)))
600
- (aset host "update" update!)
601
- (aset host "start"
602
- (fn []
603
- (when-not @running?
604
- (reset! running? true)
605
- (reset! last-frame-ms nil)
606
- (request-next-frame!))))
607
- (aset host "stop" stop!)
608
- (aset host "clear"
609
- (fn []
610
- (js-call core "clear")
611
- (js-call morph-transitions "clearTransitions")
612
- (apply-frame!)))
613
- (aset host "resetToNeutral" (aget host "clear"))
614
- (aset host "dispose"
615
- (fn []
616
- (stop!)
617
- (when @animation-system
618
- (js-call @animation-system "dispose"))
619
- (when @hair-runtime
620
- (js-call @hair-runtime "clearRegisteredHairObjects"))
621
- (when-let [free (aget core "free")]
622
- (.call free core))
623
- (reset! model nil)
624
- (reset! meshes #js [])
625
- (reset! all-meshes #js [])
626
- (reset! mesh-by-name (js/Map.))
627
- (reset! bones #js {})))
628
-
629
- (doseq [method animation-methods]
630
- (animation-method! host animation-system method))
631
- host))))
632
-
633
- (def createRustEmbodyHostUnbound create-rust-embody-host-unbound)
634
-
635
- (defn create-rust-embody-host
636
- "Create a Polymer CLJS host and bind an already-loaded Three.js model."
637
- ([model]
638
- (create-rust-embody-host model #js {}))
639
- ([model config]
640
- (-> (embody-wasm/init-core!)
641
- (.then
642
- (fn [_]
643
- (let [host (create-rust-embody-host-unbound config)]
644
- (js-call host "onReady" #js {:model model :meshes (aget config "meshes")})
645
- host))))))
646
-
647
- (def createRustEmbodyHost create-rust-embody-host)