Skip to content

Commit

Permalink
Merge branch 'editor-save-value' into editor-save-value-latest-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
matgis committed May 22, 2024
2 parents 87e3b8b + c9b8689 commit 8a036e8
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 120 deletions.
179 changes: 87 additions & 92 deletions defold-spine/editor/src/spineext.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,35 @@
(ns editor.spineext
(:require [clojure.java.io :as io]
[clojure.string :as str]
[editor.protobuf :as protobuf]
[dynamo.graph :as g]
[util.murmur :as murmur]
[editor.build-target :as bt]
[editor.graph-util :as gu]
[editor.defold-project :as project]
[editor.geom :as geom]
[editor.material :as material]
[editor.math :as math]
[editor.gl :as gl]
[editor.gl.pass :as pass]
[editor.gl.shader :as shader]
[editor.gl.texture :as texture]
[editor.gl.vertex :as vtx]
[editor.defold-project :as project]
[editor.graph-util :as gu]
[editor.material :as material]
[editor.math :as math]
[editor.outline :as outline]
[editor.properties :as properties]
[editor.protobuf :as protobuf]
[editor.render :as render]
[editor.resource :as resource]
[editor.resource-node :as resource-node]
[editor.scene-cache :as scene-cache] ; debug only
[editor.scene-picking :as scene-picking]
[editor.render :as render]
[editor.types :as types]
[editor.validation :as validation]
[editor.workspace :as workspace]
[editor.gl.pass :as pass]
[editor.types :as types]
[editor.outline :as outline]
[editor.properties :as properties]
[editor.rig :as rig])
[util.murmur :as murmur])
(:import [com.dynamo.bob.textureset TextureSetGenerator$UVTransform]
[com.dynamo.bob.util BezierUtil RigUtil$Transform]
[com.jogamp.opengl GL GL2]
[editor.gl.shader ShaderLifecycle]
[editor.types AABB]
[com.jogamp.opengl GL GL2 GLContext]
[org.apache.commons.io IOUtils]
[java.io IOException]
[java.util HashSet]
[java.net URL]
[javax.vecmath Matrix4d Vector3d Vector4d]))

[javax.vecmath Matrix4d Vector3d Vector4d]
[org.apache.commons.io IOUtils]))

(set! *warn-on-reflection* true)

Expand Down Expand Up @@ -187,8 +180,9 @@


(g/defnk produce-spine-scene-pb [_node-id spine-json atlas]
{:spine_json (resource/resource->proj-path spine-json)
:atlas (resource/resource->proj-path atlas)})
(protobuf/make-map-without-defaults spine-plugin-spinescene-cls
:spine-json (resource/resource->proj-path spine-json)
:atlas (resource/resource->proj-path atlas)))

;; (defn- transform-positions [^Matrix4d transform mesh]
;; (let [p (Point3d.)]
Expand Down Expand Up @@ -466,11 +460,11 @@
(inherits outline/OutlineNode)
(property name g/Str (dynamic read-only? (g/constantly true)))
(property position types/Vec3
(dynamic edit-type (g/constantly (properties/vec3->vec2 0.0)))
(dynamic edit-type (g/constantly {:type types/Vec2}))
(dynamic read-only? (g/constantly true)))
(property rotation g/Num (dynamic read-only? (g/constantly true)))
(property scale types/Vec3
(dynamic edit-type (g/constantly (properties/vec3->vec2 1.0)))
(dynamic edit-type (g/constantly {:type types/Vec2}))
(dynamic read-only? (g/constantly true)))
(property length g/Num
(dynamic read-only? (g/constantly true)))
Expand Down Expand Up @@ -509,7 +503,7 @@
scale-y (.-scaleY spine-bone)
length (.-length spine-bone)
parent-graph-id (g/node-id->graph-id parent-id)
bone-tx-data (g/make-nodes parent-graph-id [bone [SpineBone :name name :position [x y 0] :rotation rotation :scale [scale-x scale-y 1.0] :length length]]
bone-tx-data (g/make-nodes parent-graph-id [bone [SpineBone :name name :position [x y protobuf/float-zero] :rotation rotation :scale [scale-x scale-y protobuf/float-one] :length length]]
; Hook this node into the parent's lists
(g/connect bone :_node-id parent-id :nodes)
(g/connect bone :node-outline parent-id :child-outlines)
Expand Down Expand Up @@ -636,20 +630,19 @@
(handle-read-error error _node-id spine-json-resource))))

(defn- sanitize-spine-scene [spine-scene-desc]
{:pre (map? spine-scene-desc)} ; Spine$SpineSceneDesc in map format.
{:pre [(map? spine-scene-desc)]} ; Spine$SpineSceneDesc in map format.
(dissoc spine-scene-desc :sample-rate)) ; Deprecated field.

(defn- load-spine-scene [project self resource spine]
(let [spine-resource (workspace/resolve-resource resource (:spine-json spine))
atlas (workspace/resolve-resource resource (:atlas spine))
; used for previewing a .spinescene as it doesn't have a material specified
material (workspace/resolve-resource resource spine-material-path)]
(defn- load-spine-scene [project self resource spine-scene-desc]
{:pre [(map? spine-scene-desc)]} ; Spine$SpineSceneDesc in map format.
(let [resolve-resource #(workspace/resolve-resource resource %)
default-material-resource (resolve-resource spine-material-path)]
(concat
(g/connect project :default-tex-params self :default-tex-params)
(g/set-property self
:spine-json spine-resource
:atlas atlas
:material material))))
(g/connect project :default-tex-params self :default-tex-params)
(g/set-property self :material default-material-resource)
(gu/set-properties-from-pb-map self spine-plugin-spinescene-cls spine-scene-desc
spine-json (resolve-resource :spine-json)
atlas (resolve-resource :atlas)))))

;; (defn- make-spine-skeleton-scene [_node-id aabb gpu-texture scene-structure]
;; (let [scene {:node-id _node-id :aabb aabb}]
Expand Down Expand Up @@ -786,18 +779,15 @@
;;//////////////////////////////////////////////////////////////////////////////////////////////

(g/defnk produce-model-pb [spine-scene-resource blend-mode default-animation skin material-resource create-go-bones playback-rate offset]
(cond-> {:spine-scene (resource/resource->proj-path spine-scene-resource)
:default-animation default-animation
:skin skin
:material (resource/resource->proj-path material-resource)
:blend-mode blend-mode
:create-go-bones create-go-bones}

(not= 1.0 playback-rate)
(assoc :playback-rate playback-rate)

(not= 0.0 offset)
(assoc :offset offset)))
(protobuf/make-map-without-defaults spine-plugin-spinemodel-cls
:spine-scene (resource/resource->proj-path spine-scene-resource)
:default-animation default-animation
:skin skin
:material (resource/resource->proj-path material-resource)
:blend-mode blend-mode
:create-go-bones create-go-bones
:playback-rate playback-rate
:offset offset))

(defn ->skin-choicebox [spine-skins]
(properties/->choicebox (cons "" (remove (partial = "default") spine-skins))))
Expand Down Expand Up @@ -840,7 +830,7 @@
(defn- build-spine-model [resource dep-resources user-data]
(let [pb (:proto-msg user-data)
pb (reduce #(assoc %1 (first %2) (second %2)) pb (map (fn [[label res]] [label (resource/proj-path (get dep-resources res))]) (:dep-resources user-data)))]
{:resource resource :content (protobuf/map->bytes (workspace/load-class! "com.dynamo.spine.proto.Spine$SpineModelDesc") pb)}))
{:resource resource :content (protobuf/map->bytes spine-plugin-spinemodel-cls pb)}))

(g/defnk produce-model-build-targets [_node-id own-build-errors resource model-pb spine-scene-resource material-resource dep-build-targets]
(g/precluding-errors own-build-errors
Expand All @@ -856,15 +846,20 @@
:dep-resources dep-resources}
:deps dep-build-targets})])))

(defn load-spine-model [project self resource spine]
(let [resolve-fn (partial workspace/resolve-resource resource)
spine (-> spine
(update :spine-scene resolve-fn)
(update :material resolve-fn))]
(defn load-spine-model [project self resource spine-model-desc]
{:pre [(map? spine-model-desc)]} ; Spine$SpineModelDesc in map format.
(let [resolve-resource #(workspace/resolve-resource resource %)]
(concat
(g/connect project :default-tex-params self :default-tex-params)
(for [[k v] spine]
(g/set-property self k v)))))
(g/connect project :default-tex-params self :default-tex-params)
(gu/set-properties-from-pb-map self spine-plugin-spinemodel-cls spine-model-desc
spine-scene (resolve-resource :spine-scene)
default-animation :default-animation
skin :skin
blend-mode :blend-mode
material (resolve-resource (:material :or spine-material-path))
create-go-bones :create-go-bones
playback-rate :playback-rate
offset :offset))))

(defn- step-animation
[state dt spine-data-handle animation skin]
Expand Down Expand Up @@ -925,8 +920,8 @@
(validate-model-skin _node-id spine-scene skins skin)))
(dynamic edit-type (g/fnk [skins] (->skin-choicebox skins))))
(property create-go-bones g/Bool (default false))
(property playback-rate g/Num (default 1.0))
(property offset g/Num (default 0.0)
(property playback-rate g/Num (default (float 1.0)))
(property offset g/Num (default (float 0.0))
(dynamic edit-type (g/constantly {:type :slider
:min 0.0
:max 1.0
Expand Down Expand Up @@ -1000,38 +995,38 @@

(defn register-resource-types [workspace]
(concat
(resource-node/register-ddf-resource-type workspace
:ext spine-scene-ext
:label "Spine Scene"
:node-type SpineSceneNode
:ddf-type spine-plugin-spinescene-cls
:sanitize-fn sanitize-spine-scene
:load-fn load-spine-scene
:icon spine-scene-icon
:view-types [:scene :text]
:view-opts {:scene {:grid true}}
:template "/defold-spine/editor/resources/templates/template.spinescene")
(resource-node/register-ddf-resource-type workspace
:ext spine-model-ext
:label "Spine Model"
:node-type SpineModelNode
:ddf-type spine-plugin-spinemodel-cls
:load-fn load-spine-model
:icon spine-model-icon
:view-types [:scene :text]
:view-opts {:scene {:grid true}}
:tags #{:component}
:tag-opts {:component {:transform-properties #{:position :rotation :scale}}}
:template "/defold-spine/editor/resources/templates/template.spinemodel")
(workspace/register-resource-type workspace
:ext spine-json-ext
:node-type SpineSceneJson
:textual? true
:load-fn load-spine-json
:icon spine-json-icon
:view-types [:default]
:tags #{:embeddable})))

(resource-node/register-ddf-resource-type workspace
:ext spine-scene-ext
:label "Spine Scene"
:node-type SpineSceneNode
:ddf-type spine-plugin-spinescene-cls
:read-defaults false
:sanitize-fn sanitize-spine-scene
:load-fn load-spine-scene
:icon spine-scene-icon
:view-types [:scene :text]
:view-opts {:scene {:grid true}}
:template "/defold-spine/editor/resources/templates/template.spinescene")
(resource-node/register-ddf-resource-type workspace
:ext spine-model-ext
:label "Spine Model"
:node-type SpineModelNode
:ddf-type spine-plugin-spinemodel-cls
:read-defaults false
:load-fn load-spine-model
:icon spine-model-icon
:view-types [:scene :text]
:view-opts {:scene {:grid true}}
:tags #{:component}
:tag-opts {:component {:transform-properties #{:position :rotation :scale}}}
:template "/defold-spine/editor/resources/templates/template.spinemodel")
(workspace/register-resource-type workspace
:ext spine-json-ext
:node-type SpineSceneJson
:textual? true
:load-fn load-spine-json
:icon spine-json-icon
:view-types [:default])))

; The plugin
(defn load-plugin-spine [workspace]
Expand Down
56 changes: 28 additions & 28 deletions defold-spine/editor/src/spineguiext.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,25 @@
;; specific language governing permissions and limitations under the License.

(ns editor.spineguiext
(:require [schema.core :as s]
(:require [editor.protobuf :as protobuf]
[clojure.string :as str]
[dynamo.graph :as g]
[util.murmur :as murmur]
[editor.graph-util :as gu]
[editor.geom :as geom]
[editor.defold-project :as project]
[editor.resource :as resource]
[editor.scene-cache :as scene-cache] ; debug only
[editor.workspace :as workspace]
[editor.types :as types]
[editor.geom :as geom]
[editor.gl.texture]
[editor.graph-util :as gu]
[editor.gui :as gui]
[editor.outline :as outline]
[editor.properties :as properties]
[editor.gui :as gui]
[editor.spineext :as spineext])
(:import [com.dynamo.gamesys.proto Gui$NodeDesc$ClippingMode]
[editor.resource :as resource]
[editor.spineext :as spineext]
[editor.workspace :as workspace]
[schema.core :as s]
[util.murmur :as murmur])
(:import [com.dynamo.gamesys.proto Gui$NodeDesc Gui$NodeDesc$ClippingMode]
[editor.gl.texture TextureLifecycle]
[javax.vecmath Matrix4d Point3d]))


(set! *warn-on-reflection* true)

(g/deftype ^:private SpineSceneElementIds s/Any #_{s/Str {:spine-anim-ids (sorted-set s/Str)
Expand Down Expand Up @@ -98,21 +97,21 @@
vb-out))

(g/defnk produce-spine-node-msg [visual-base-node-msg spine-scene spine-default-animation spine-skin clipping-mode clipping-visible clipping-inverted]
(assoc visual-base-node-msg
:size [1.0 1.0 0.0 1.0]
:size-mode :size-mode-auto
:spine-scene spine-scene
:spine-default-animation spine-default-animation
:spine-skin spine-skin
:clipping-mode clipping-mode
:clipping-visible clipping-visible
:clipping-inverted clipping-inverted))
(merge visual-base-node-msg
(protobuf/make-map-without-defaults Gui$NodeDesc
:size-mode :size-mode-auto
:spine-scene spine-scene
:spine-default-animation spine-default-animation
:spine-skin spine-skin
:clipping-mode clipping-mode
:clipping-visible clipping-visible
:clipping-inverted clipping-inverted)))

(g/defnode SpineNode
(inherits gui/VisualNode)

(property spine-scene g/Str
(default "")
(default (protobuf/default Gui$NodeDesc :spine-scene))
(dynamic edit-type (g/fnk [spine-scene-names] (gui/required-gui-resource-choicebox spine-scene-names)))
(dynamic error (g/fnk [_node-id spine-scene spine-scene-names]
(validate-spine-scene _node-id spine-scene-names spine-scene))))
Expand All @@ -127,10 +126,10 @@
(validate-spine-skin _node-id spine-scene-names spine-skin-ids spine-skin spine-scene)))
(dynamic edit-type (g/fnk [spine-skin-ids] (spineext/->skin-choicebox spine-skin-ids))))

(property clipping-mode g/Keyword (default :clipping-mode-none)
(property clipping-mode g/Keyword (default (protobuf/default Gui$NodeDesc :clipping-mode))
(dynamic edit-type (g/constantly (properties/->pb-choicebox Gui$NodeDesc$ClippingMode))))
(property clipping-visible g/Bool (default true))
(property clipping-inverted g/Bool (default false))
(property clipping-visible g/Bool (default (protobuf/default Gui$NodeDesc :clipping-visible)))
(property clipping-inverted g/Bool (default (protobuf/default Gui$NodeDesc :clipping-inverted)))

(display-order (into gui/base-display-order
[:spine-scene :spine-default-animation :spine-skin :color :alpha :inherit-alpha :layer :blend-mode :pivot :x-anchor :y-anchor
Expand Down Expand Up @@ -350,7 +349,6 @@
(defn- fixup-spine-node [node-type-info node-desc]
(let [node-type (:type node-desc)]
(cond-> (assoc node-desc
:size [1.0 1.0 0.0 1.0]
:size-mode :size-mode-auto)

(= :type-spine node-type)
Expand All @@ -365,12 +363,14 @@
:display-name "Spine"
:custom-type (murmur/hash32 "Spine")
:icon spineext/spine-scene-icon
:convert-fn fixup-spine-node}
:convert-fn fixup-spine-node
:defaults gui/visual-base-node-defaults}
info-depr (merge info {:node-type :type-spine
:custom-type 0
:output-node-type (:node-type info)
:output-custom-type (:custom-type info)
:deprecated true})]
:deprecated true
:defaults gui/visual-base-node-defaults})]
(gui/register-node-type-info! info)
; Register :type-spine with custom type 0 in order to be able to read old files
(gui/register-node-type-info! info-depr)))
Expand Down

0 comments on commit 8a036e8

Please sign in to comment.