Skip to content

Commit

Permalink
fix: scale before to-world
Browse files Browse the repository at this point in the history
  • Loading branch information
azimut committed Nov 12, 2024
1 parent f90b36f commit 2c40f7b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/actors/actor.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"c-array of mat4s, of transforms for each bone in the whole scene")
(bones-unique :reader bones-unique)
(bones-transforms :reader bones-transforms)
(scene-offset :reader scene-offset)
(duration :initform 0f0 :initarg :duration)))

(defmethod print-object ((obj actor) stream)
Expand Down
9 changes: 6 additions & 3 deletions src/actors/assimp/bones-helpers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@
(setf (gethash name nodes-transforms) new-transform)
(loop :for children :across childrens :do
(walk-node children new-transform))))))
(walk-node (ai:root-node scene) (m4:identity)))))
(walk-node
(ai:root-node scene)
(m4:identity)))))

(s:-> get-animated-bone-transforms (ai:scene number fixnum) hash-table)
(defun get-animated-bone-transforms (scene time nth-animation)
Expand All @@ -159,8 +161,9 @@

(loop :for children :across childrens :do
(walk-node children new-transform))))))
(walk-node (ai:root-node scene)
(m4:identity))))))
(walk-node
(ai:root-node scene)
(m4:identity))))))

(s:-> get-bones-transforms (ai:scene number) simple-vector)
(defun get-bones-transforms (scene time)
Expand Down
5 changes: 2 additions & 3 deletions src/actors/assimp/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
))

(defmethod initialize-instance :after ((obj assimp-thing-with-bones) &key scene)
(with-slots (scene-offset bones-unique bones-transforms) obj
(setf scene-offset (serapeum:~> scene (ai:root-node) (ai:transform)))
(with-slots (bones-unique bones-transforms) obj
(setf bones-unique (list-bones-unique scene))
(setf bones-transforms (make-array (length bones-unique)))))

Expand Down Expand Up @@ -80,7 +79,7 @@
;; Loaders
;;--------------------------------------------------

(defmethod free ((actor assimp-thing-with-bones))
(defmethod free :AFTER ((actor assimp-thing-with-bones))
(with-slots (bones) actor
(free bones)))

Expand Down
20 changes: 11 additions & 9 deletions src/lights/directional.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,18 @@
(world-view :mat4)
(view-clip :mat4)
(scale :float))
(let* ((pos (pos vert))
(let* ((bone-transform
(with-slots (weights ids) bones
(+ (* (x weights) (aref offsets (int (x ids))))
(* (y weights) (aref offsets (int (y ids))))
(* (z weights) (aref offsets (int (z ids))))
(* (w weights) (aref offsets (int (w ids)))))))
(model-pos (pos vert))
(world-pos
(* (m4:scale (v3! scale)) ;; FIXME
model-world
(with-slots (weights ids) bones
(+ (* (x weights) (aref offsets (int (x ids))))
(* (y weights) (aref offsets (int (y ids))))
(* (z weights) (aref offsets (int (z ids))))
(* (w weights) (aref offsets (int (w ids))))))
(v! pos 1)))
(* model-world
(m4:scale (v3! scale))
bone-transform
(v! model-pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos))
(tex (tex vert))
Expand Down
4 changes: 2 additions & 2 deletions src/render.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
(* (w weights) (aref offsets (int (w ids)))))))
(model-pos (pos vert))
(world-pos
(* (m4:scale (v3! scale)) ;; FIXME
model-world
(* model-world
(m4:scale (v3! scale))
bone-transform
(v! model-pos 1)))
;; Normal
Expand Down

0 comments on commit 2c40f7b

Please sign in to comment.