Skip to content
Permalink
Browse files

Create tangent vectors for assimp models

  • Loading branch information...
Shinmera committed Mar 21, 2019
1 parent 5124da1 commit 0b94f1f488b8d8ec717be35171a4b4997d49419d
Showing with 26 additions and 4 deletions.
  1. +8 −4 formats/assimp.lisp
  2. +18 −0 geometry.lisp
@@ -7,16 +7,19 @@
(in-package #:org.shirakumo.fraf.trial)

(defmethod classimp->mesh (source)
(let* ((mesh (make-instance 'vertex-mesh :vertex-type 'basic-vertex
(let* ((mesh (make-instance 'vertex-mesh :vertex-type 'basic+-vertex
:face-length (classimp:primitive-types source)))
(verts (vertices mesh))
(faces (faces mesh)))
(loop for location across (classimp:vertices source)
for normal across (classimp:normals source)
for uv across (aref (classimp:texture-coords source) 0)
for vertex = (make-instance 'basic-vertex :location (vec-from-vector location)
:normal (vec-from-vector normal)
:uv (vec2 (aref uv 0) (aref uv 1)))
for tangent across (classimp:tangents source)
for vertex = (make-instance 'basic+-vertex
:location (vec-from-vector location)
:normal (vec-from-vector normal)
:uv (vec2 (aref uv 0) (aref uv 1))
:tangent (vec-from-vector tangent))
do (vector-push-extend vertex verts))
(loop for face across (classimp:faces source)
do (loop for index across face
@@ -28,6 +31,7 @@
(scene (classimp:import-into-lisp file :processing-flags '(:ai-process-triangulate
:ai-process-flip-u-vs
:ai-process-fix-infacing-normals
:ai-process-calc-tangent-space
;; FIXME: should scene-graph sometime
:ai-process-pre-transform-vertices)))
(meshes (map 'vector #'classimp->mesh (classimp:meshes scene))))
@@ -165,9 +165,27 @@
(defmethod fill-vertex-attribute ((vertex colored-vertex) (attribute (eql 'color)) data offset)
(fill-vector-data (color vertex) 'vec4 data offset))

(defclass tangent-vertex (vertex)
((tangent :initform (vec 0 0 0) :initarg :tangent :accessor tangent :type vec3)))

(defmethod vertex= and ((a tangent-vertex) (b tangent-vertex))
(v= (tangent a) (tangent b)))

(defmethod vertex-attribute-size ((vertex tangent-vertex) (attribute (eql 'tangent)))
3)

(defmethod vertex-attributes append ((vertex tangent-vertex))
'(tangent))

(defmethod fill-vertex-attribute ((vertex tangent-vertex) (attribute (eql 'tangent)) data offset)
(fill-vector-data (tangent vertex) 'vec3 data offset))

(defclass basic-vertex (normal-vertex textured-vertex)
())

(defclass basic+-vertex (tangent-vertex normal-vertex textured-vertex)
())

;;;; Translation

(defmethod update-instance-for-different-class ((mesh vertex-mesh) (array vertex-array) &key (data-usage :static-draw) (attributes T))

0 comments on commit 0b94f1f

Please sign in to comment.
You can’t perform that action at this time.