Skip to content

Commit

Permalink
assimp: remove everything that refered to a "frame"
Browse files Browse the repository at this point in the history
logic was all bad thought out, animation node can have different
number of members so we cannot index through it blindly
  • Loading branch information
azimut committed Nov 6, 2024
1 parent 0eb2407 commit d5c5ca7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 37 deletions.
49 changes: 13 additions & 36 deletions src/actors/assimp/bones-helpers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,6 @@
(qinterp (q:lerp start end (coerce factor 'single-float))))
(q:normalize qinterp)))))))

(s:-> get-frame-transform (ai::node-animation fixnum) rtg-math.types:mat4)
(defun get-frame-transform (node-animation frame)
"returns a matrix"
(with-slots ((pos-keys ai::position-keys)
(rot-keys ai::rotation-keys)
(sca-keys ai::scaling-keys))
node-animation
(let ((mod-frame (mod frame (length rot-keys))))
;; Calculate transform matrix based on time
(m4-n:*
(m4:translation (ai:value (aref pos-keys mod-frame)))
(q:to-mat4 (ai:value (aref rot-keys mod-frame)))
;;(m4:scale (ai:value (aref sca-keys 0))) ;; No scaling. Here is a vec3. And we use a single float.
))))

(s:-> get-time-transform (ai::node-animation number) rtg-math.types:mat4)
(defun get-time-transform (node-animation time)
"calculate the tansform matrix based on time returns a matrix"
Expand All @@ -119,11 +104,12 @@
;;(m4:scale (ai:value (aref sca-keys 0))) ;; No scaling. Here is a vec3. And we use a single float.
))))

(defgeneric get-nodes-transforms (scene node-type &key frame time nth-animation)
(defgeneric get-nodes-transforms (scene node-type &key time nth-animation)
(:documentation "returns a hash of mat4's with each node transform
for value and node name for the key")
(:method ((scene ai:scene) (node-type (eql :static)) &key frame time nth-animation)
(let ((nodes-transforms (make-hash-table :test #'equal)))
(:method ((scene ai:scene) (node-type (eql :static)) &key time nth-animation)
(declare (ignore time nth-animation))
(s:lret ((nodes-transforms (make-hash-table :test #'equal)))
(labels ((walk-node (node parent-transform)
(declare (type ai:node node)
(type vector parent-transform))
Expand All @@ -137,9 +123,8 @@
(map 'vector
(lambda (c) (walk-node c global))
children)))))
(walk-node (ai:root-node scene) (m4:identity)))
nodes-transforms))
(:method ((scene ai:scene) (node-type (eql :animated)) &key frame time (nth-animation 0))
(walk-node (ai:root-node scene) (m4:identity)))))
(:method ((scene ai:scene) (node-type (eql :animated)) &key time (nth-animation 0))
(let* ((animation (aref (ai:animations scene) nth-animation))
(duration (ai:duration animation))
;; NOTE: animation-index is a hash lookup table for BONE>NODE-ANIMATION
Expand All @@ -159,9 +144,7 @@
(gethash name animation-index))
(time-transform
(when node-anim
(if frame
(get-frame-transform node-anim frame)
(get-time-transform node-anim (mod time duration)))))
(get-time-transform node-anim (mod time duration))))
(final-transform
(or time-transform (m4:transpose transform)))
(global
Expand All @@ -175,26 +158,20 @@
(m4:identity)))
nodes-transforms)))

(defun get-bones-tranforms (scene &key (frame 0 frame-p) (time 0 time-p))
(declare (ai:scene scene))
(s:-> get-bones-transforms (ai:scene number) t)
(defun get-bones-transforms (scene time)
(let* ((root-offset
(-> scene
(ai:root-node)
(ai:transform)
(m4:transpose)
(m4:inverse)))
(node-type
(cond ((and frame-p time-p)
(error "provide EITHER time or frame offset"))
((emptyp (ai:animations scene))
:static)
((not (emptyp (ai:animations scene)))
:animated)
(t (error "cannot figure out boned mesh type"))))
(if (emptyp (ai:animations scene))
:static
:animated))
(nodes-transforms
(if frame-p
(get-nodes-transforms scene node-type :frame frame)
(get-nodes-transforms scene node-type :time time)))
(get-nodes-transforms scene node-type :time time))
(unique-bones
(list-bones-unique scene)))
(declare (type hash-table nodes-transforms))
Expand Down
2 changes: 1 addition & 1 deletion src/actors/assimp/main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@
(coerce
;; NOTE: init using the first transform in the animation, for those that only have 1
;; frame of "animation"
(get-bones-tranforms scene :frame 0)
(get-bones-transforms scene 25f0);; !!!!!!!!!!!!!!!!
'list) :element-type :mat4))
:duration (when (eq type :bones)
(if (not (emptyp (ai:animations scene)))
Expand Down

0 comments on commit d5c5ca7

Please sign in to comment.