diff --git a/src/actors/actor.lisp b/src/actors/actor.lisp index 7a12448..f72021b 100644 --- a/src/actors/actor.lisp +++ b/src/actors/actor.lisp @@ -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) diff --git a/src/actors/assimp/bones-helpers.lisp b/src/actors/assimp/bones-helpers.lisp index 3c377f0..b2272a3 100644 --- a/src/actors/assimp/bones-helpers.lisp +++ b/src/actors/assimp/bones-helpers.lisp @@ -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) @@ -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) diff --git a/src/actors/assimp/main.lisp b/src/actors/assimp/main.lisp index 344f067..ada95ff 100644 --- a/src/actors/assimp/main.lisp +++ b/src/actors/assimp/main.lisp @@ -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))))) @@ -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))) diff --git a/src/lights/directional.lisp b/src/lights/directional.lisp index c25bd7a..59f09f2 100644 --- a/src/lights/directional.lisp +++ b/src/lights/directional.lisp @@ -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)) diff --git a/src/render.lisp b/src/render.lisp index 8dc1eea..fca513d 100644 --- a/src/render.lisp +++ b/src/render.lisp @@ -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