|
170 | 170 |
|
171 | 171 | (property content g/Any)
|
172 | 172 | (property rive-handle g/Any) ; The cpp pointer
|
173 |
| - (property animations g/Any) |
174 |
| - (property state-machine-ids g/Any) |
| 173 | + (property artboard-id-list g/Any) |
175 | 174 | (property aabb g/Any)
|
176 | 175 | (property vertices g/Any)
|
177 | 176 | (property bones g/Any)
|
|
220 | 219 | ; bones is a list of root Rive$Bone (Rive.java)
|
221 | 220 | (mapcat (fn [bone] (create-bone-hierarchy parent-id bone)) bones))
|
222 | 221 |
|
| 222 | +;; Converts a list of java objects into a clojure map where we can get |
| 223 | +;; all the animations and state machines based on an artboard name. |
| 224 | +(defn- to-artboard-id-list [artboard-id-list-from-java] |
| 225 | + (into {} |
| 226 | + (map (fn [id-list] |
| 227 | + [(.-artboardId id-list) |
| 228 | + {:animation-ids (into [] (.-animations id-list)) |
| 229 | + :state-machine-ids (mapv (fn [sm] (.-name sm)) (.-stateMachines id-list))}]) |
| 230 | + artboard-id-list-from-java))) |
| 231 | + |
223 | 232 | ; Loads the .riv file
|
224 | 233 | (defn- load-rive-file
|
225 | 234 | [project node-id resource]
|
226 | 235 | (let [content (resource->bytes resource)
|
227 | 236 | rive-handle (plugin-load-file content (resource/resource->proj-path resource))
|
228 |
| - animations (.-animations rive-handle) |
| 237 | + artboard-id-list-from-java (.-artboardId rive-handle) |
| 238 | + artboard-id-list (to-artboard-id-list artboard-id-list-from-java) |
229 | 239 | artboards (.-artboards rive-handle)
|
230 |
| - state-machines (.-stateMachines rive-handle) |
231 |
| - state-machine-ids (map (fn [state-machine] (.-name state-machine)) state-machines) |
| 240 | + |
232 | 241 | _ (.Update rive-handle 0.0)
|
233 | 242 | aabb (convert-aabb (.-aabb rive-handle))
|
234 | 243 | bones (.-bones rive-handle)
|
|
237 | 246 | (g/set-property node-id :content content)
|
238 | 247 | (g/set-property node-id :rive-handle rive-handle)
|
239 | 248 | (g/set-property node-id :artboards artboards)
|
240 |
| - (g/set-property node-id :animations animations) |
241 |
| - (g/set-property node-id :state-machine-ids state-machine-ids) |
| 249 | + (g/set-property node-id :artboard-id-list artboard-id-list) |
242 | 250 | (g/set-property node-id :aabb aabb)
|
243 | 251 | (g/set-property node-id :bones bones))
|
244 | 252 |
|
|
542 | 550 | (assert (= (:pass render-args) pass/outline))
|
543 | 551 | (render/render-aabb-outline gl render-args ::rive-outline renderables rcount))
|
544 | 552 |
|
545 |
| -(g/defnk produce-main-scene [_node-id material-shader rive-file-handle rive-anim-ids aabb gpu-texture default-tex-params rive-scene-pb scene-structure texture-set-pb] |
| 553 | +(g/defnk produce-main-scene [_node-id material-shader rive-file-handle aabb gpu-texture default-tex-params rive-scene-pb scene-structure texture-set-pb] |
546 | 554 | (when rive-file-handle
|
547 | 555 | (let [blend-mode :blend-mode-alpha]
|
548 | 556 | (assoc {:node-id _node-id :aabb aabb}
|
|
590 | 598 | [:rive-handle :rive-file-handle]
|
591 | 599 | [:structure :scene-structure]
|
592 | 600 | [:artboards :rive-artboards]
|
593 |
| - [:animations :rive-anim-ids] |
594 |
| - [:state-machine-ids :rive-state-machine-ids] |
| 601 | + [:artboard-id-list :rive-artboard-id-list] |
595 | 602 | [:aabb :aabb]
|
596 | 603 | [:node-outline :source-outline]
|
597 | 604 | [:build-targets :dep-build-targets])))
|
|
628 | 635 | (input rive-file-resource resource/Resource)
|
629 | 636 | (input rive-file-handle g/Any)
|
630 | 637 | (input rive-artboards g/Any)
|
631 |
| - (input rive-anim-ids g/Any) |
632 |
| - (input rive-state-machine-ids g/Any) |
| 638 | + (input rive-artboard-id-list g/Any) |
633 | 639 | (input aabb g/Any)
|
634 | 640 | (input atlas-resource resource/Resource)
|
635 | 641 |
|
|
653 | 659 | (output material-shader ShaderLifecycle (gu/passthrough material-shader))
|
654 | 660 | (output rive-file-handle g/Any :cached (gu/passthrough rive-file-handle))
|
655 | 661 | (output rive-artboards g/Any :cached (gu/passthrough rive-artboards))
|
656 |
| - (output rive-anim-ids g/Any :cached (gu/passthrough rive-anim-ids)) |
657 |
| - (output rive-state-machine-ids g/Any :cached (gu/passthrough rive-state-machine-ids)) |
| 662 | + (output rive-artboard-id-list g/Any :cached (gu/passthrough rive-artboard-id-list)) |
658 | 663 | (output aabb g/Any :cached (gu/passthrough aabb)))
|
659 | 664 |
|
660 | 665 | ; .rivescene
|
|
695 | 700 | artboard
|
696 | 701 | (set rive-artboards))))
|
697 | 702 |
|
698 |
| -(defn- validate-model-default-animation [node-id rive-scene rive-anim-ids default-animation] |
| 703 | +(defn- validate-model-default-animation [node-id rive-scene animation-ids default-animation] |
699 | 704 | (when (and rive-scene (not-empty default-animation))
|
700 | 705 | (validation/prop-error :fatal node-id :default-animation
|
701 | 706 | (fn [anim ids]
|
702 | 707 | (when-not (contains? ids anim)
|
703 | 708 | (format "animation '%s' could not be found in the specified rive scene" anim)))
|
704 | 709 | default-animation
|
705 |
| - (set rive-anim-ids)))) |
| 710 | + (set animation-ids)))) |
706 | 711 |
|
707 |
| -(defn- validate-model-default-state-machine [node-id rive-scene rive-state-machine-ids default-state-machine] |
| 712 | +(defn- validate-model-default-state-machine [node-id rive-scene state-machine-ids default-state-machine] |
708 | 713 | (when (and rive-scene (not-empty default-state-machine))
|
709 | 714 | (validation/prop-error :fatal node-id :default-state-machine
|
710 | 715 | (fn [anim ids]
|
711 | 716 | (when-not (contains? ids anim)
|
712 |
| - (format "state machine '%s' could not be found in the specified rive scene" anim))) |
| 717 | + (format "state machine '%s' could not be found in the specified artboard or rive scene" anim))) |
713 | 718 | default-state-machine
|
714 |
| - (set rive-state-machine-ids)))) |
| 719 | + (set state-machine-ids)))) |
715 | 720 |
|
716 | 721 | (defn- validate-model-material [node-id material]
|
717 | 722 | (prop-resource-error node-id :material material "Material"))
|
718 | 723 |
|
719 | 724 | (defn- validate-model-rive-scene [node-id rive-scene]
|
720 | 725 | (prop-resource-error node-id :scene rive-scene "Rive Scene"))
|
721 | 726 |
|
722 |
| -(g/defnk produce-model-own-build-errors [_node-id artboard default-animation default-state-machine material rive-artboards rive-anim-ids rive-state-machine-ids rive-scene scene-structure] |
723 |
| - (g/package-errors _node-id |
| 727 | +(g/defnk produce-model-own-build-errors [_node-id artboard default-animation default-state-machine material rive-artboards rive-artboard-id-list rive-scene scene-structure] |
| 728 | + (let [state-machine-ids (:state-machine-ids (get rive-artboard-id-list artboard)) |
| 729 | + animation-ids (:animation-ids (get rive-artboard-id-list artboard))] |
| 730 | + (g/package-errors _node-id |
724 | 731 | (validate-model-material _node-id material)
|
725 | 732 | (validate-model-rive-scene _node-id rive-scene)
|
726 | 733 | (validate-model-artboard _node-id rive-scene rive-artboards artboard)
|
727 |
| - (validate-model-default-animation _node-id rive-scene rive-anim-ids default-animation) |
728 |
| - (validate-model-default-state-machine _node-id rive-scene rive-state-machine-ids default-state-machine))) |
| 734 | + (validate-model-default-animation _node-id rive-scene animation-ids default-animation) |
| 735 | + (validate-model-default-state-machine _node-id rive-scene state-machine-ids default-state-machine)))) |
729 | 736 |
|
730 | 737 | (defn- build-rive-model [resource dep-resources user-data]
|
731 | 738 | (let [pb (:proto-msg user-data)
|
|
759 | 766 | [:main-scene :rive-main-scene]
|
760 | 767 | [:rive-file-handle :rive-file-handle]
|
761 | 768 | [:rive-artboards :rive-artboards]
|
762 |
| - [:rive-anim-ids :rive-anim-ids] |
763 |
| - [:rive-state-machine-ids :rive-state-machine-ids] |
| 769 | + [:rive-artboard-id-list :rive-artboard-id-list] |
764 | 770 | [:build-targets :dep-build-targets]
|
765 | 771 | [:anim-data :anim-data]
|
766 | 772 | [:scene-structure :scene-structure])))
|
|
781 | 787 | (dynamic edit-type (g/constantly {:type resource/Resource :ext "material"}))
|
782 | 788 | (dynamic error (g/fnk [_node-id material]
|
783 | 789 | (validate-model-material _node-id material))))
|
| 790 | + |
784 | 791 | (property default-state-machine g/Str (default (protobuf/default rive-model-pb-class :default-state-machine))
|
785 |
| - (dynamic error (g/fnk [_node-id rive-state-machine-ids default-state-machine rive-scene] |
786 |
| - (validate-model-default-state-machine _node-id rive-scene rive-state-machine-ids default-state-machine))) |
787 |
| - (dynamic edit-type (g/fnk [rive-state-machine-ids] (properties/->choicebox (cons "" rive-state-machine-ids))))) |
| 792 | + (dynamic error (g/fnk [_node-id artboard rive-artboard-id-list default-state-machine rive-scene] |
| 793 | + (validate-model-default-state-machine _node-id rive-scene (:state-machine-ids (get rive-artboard-id-list artboard)) default-state-machine))) |
| 794 | + (dynamic edit-type (g/fnk [artboard rive-artboard-id-list] |
| 795 | + (properties/->choicebox (cons "" (:state-machine-ids (get rive-artboard-id-list artboard))))))) |
| 796 | + |
| 797 | + (property default-animation g/Str |
| 798 | + (dynamic error (g/fnk [_node-id artboard rive-artboard-id-list default-animation rive-scene] |
| 799 | + (validate-model-default-animation _node-id rive-scene (:animation-ids (get rive-artboard-id-list artboard)) default-animation))) |
| 800 | + (dynamic edit-type (g/fnk [artboard rive-artboard-id-list] |
| 801 | + (properties/->choicebox (cons "" (:animation-ids (get rive-artboard-id-list artboard))))))) |
788 | 802 |
|
789 | 803 | (property artboard g/Str (default (protobuf/default rive-model-pb-class :artboard))
|
790 | 804 | (dynamic error (g/fnk [_node-id rive-artboards artboard rive-scene]
|
791 | 805 | (validate-model-artboard _node-id rive-scene rive-artboards artboard)))
|
792 | 806 | (dynamic edit-type (g/fnk [rive-artboards] (properties/->choicebox (cons "" rive-artboards)))))
|
793 | 807 |
|
794 |
| - (property default-animation g/Str ; Required protobuf field. |
795 |
| - (dynamic error (g/fnk [_node-id rive-anim-ids default-animation rive-scene] |
796 |
| - (validate-model-default-animation _node-id rive-scene rive-anim-ids default-animation))) |
797 |
| - (dynamic edit-type (g/fnk [rive-anim-ids] (properties/->choicebox (cons "" rive-anim-ids))))) |
798 | 808 | (property create-go-bones g/Bool (default (protobuf/default rive-model-pb-class :create-go-bones)))
|
799 | 809 |
|
800 | 810 | (property coordinate-system g/Any (default (protobuf/default rive-model-pb-class :coordinate-system))
|
|
812 | 822 | (input rive-main-scene g/Any)
|
813 | 823 | (input scene-structure g/Any)
|
814 | 824 | (input rive-artboards g/Any)
|
815 |
| - (input rive-anim-ids g/Any) |
816 |
| - (input rive-state-machine-ids g/Any) |
| 825 | + (input rive-artboard-id-list g/Any) |
817 | 826 | (input texture-set-pb g/Any)
|
818 | 827 | (input atlas-resource resource/Resource)
|
819 | 828 | (input material-resource resource/Resource)
|
|
0 commit comments