Skip to content

Commit

Permalink
Fix pivot point related issues (defold#9711)
Browse files Browse the repository at this point in the history
* fix frame and manual size mode

* fix aabb

* fix issue
  • Loading branch information
AGulev authored Nov 8, 2024
1 parent 7403aa9 commit 26c326f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
19 changes: 15 additions & 4 deletions editor/src/clj/editor/sprite.clj
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,24 @@

(input copied-nodes g/Any :array :cascade-delete)

(output aabb AABB (g/fnk [size]
(output aabb AABB (g/fnk [size ^:try scene-infos]
(let [[^double width ^double height ^double depth] size
first-animation (when-not (g/error-value? scene-infos)
(:animation (first scene-infos)))
anim-pivot (when first-animation
(get-in first-animation [:frames 0 :pivot]))
[pivot-x pivot-y] (if anim-pivot
anim-pivot
[0.0 0.0])
half-width (* 0.5 width)
half-height (* 0.5 height)
half-depth (* 0.5 depth)]
(geom/make-aabb (Point3d. (- half-width) (- half-height) (- half-depth))
(Point3d. half-width half-height half-depth)))))
half-depth (* 0.5 depth)

; Adjusted calculations for min-x and min-y
min-x (- (* (- width) pivot-x) half-width)
min-y (- (* (- height) pivot-y) half-height)]
(geom/make-aabb (Point3d. min-x min-y (- half-depth))
(Point3d. (+ min-x width) (+ min-y height) half-depth)))))
(output save-value g/Any produce-save-value)
(output scene g/Any :cached produce-scene)
(output build-targets g/Any :cached produce-build-targets)
Expand Down
11 changes: 7 additions & 4 deletions editor/src/clj/editor/texture_set.clj
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,15 @@

; Pivot point comes from the SpriteGeometry, where (0,0) is center of the image and +Y is up.
[^double image-pivot-x ^double image-pivot-y] (or (:pivot animation-frame) [0.0 0.0])
image-pivot-x (* (or (:width animation-frame) 0.0) image-pivot-x)
image-pivot-y (* (or (:height animation-frame) 0.0) image-pivot-y)
[width height] (if (or (and (= :size-mode-manual size-mode)) (nil? animation-frame)) size [(:width animation-frame) (:height animation-frame)])
image-pivot-x (* width image-pivot-x)
image-pivot-y (* height image-pivot-y)

position-data (:position-data out)
offset-positions (offset-vertices image-pivot-x image-pivot-y position-data)]
(assoc out :position-data offset-positions)))
line-data (:line-data out)
offset-positions (offset-vertices image-pivot-x image-pivot-y position-data)
offset-lines (offset-vertices image-pivot-x image-pivot-y line-data)]
(assoc out :position-data offset-positions :line-data offset-lines)))


;; animation
Expand Down

0 comments on commit 26c326f

Please sign in to comment.