-(define-type mesh
- (num-primitive-types (lambda (p) (bv-uint-ref p 0)))
- (vertices (get-pointer-of-pointers-procedure 4 12))
- (faces (get-pointer-of-pointers-procedure 8 124))
- (normals (lambda (p) (bv-uint-ref p 16)))
- (tangents (lambda (p) (bv-uint-ref p 20)))
- (bitangents (lambda (p) (bv-uint-ref p 24)))
- (colors (lambda (p) (bv-uint-ref p 28))) ;AI_MAX_NUMBER_OF_COLOR_SETS
- (texture-coords (lambda (p) (bv-uint-ref p 60))) ;AI_MAX_NUMBER_OF_TEXTURECOORDS
- (num-uv-components (lambda (p) (bv-uint-ref p 92))) ;AI_MAX_NUMBER_OF_TEXTURECOORDS
- (bones (get-pointer-of-pointers-procedure 128 132))
- (material-index (lambda (p) (bv-uint-ref p 136))))
-
-(export mesh?
- mesh-contents)
+(define-conversion-type parse-aiMesh -> ai-mesh
+ (name (sized-string (field 'mName)))
+ (primitive-types (field 'mPrimitiveTypes))
+ (vertices (wrap
+ (array (field 'mNumVertices) (field 'mVertices) #:element-proc get-element-address)
+ wrap-ai-vector3d))
+ (faces (wrap
+ (array (field 'mNumFaces) (field 'mFaces) #:element-size 8 #:element-proc get-element-address)
+ wrap-ai-face))
+ (normals (wrap
+ (array (field 'mNumVertices) (field 'mNormals) #:element-size 12 #:element-proc get-element-address)
+ wrap-ai-vector3d))
+ (tangents (wrap
+ (array (field 'mNumVertices) (field 'mTangents) #:element-size 12 #:element-proc get-element-address)
+ wrap-ai-vector3d))
+ (bitangents (wrap
+ (array (field 'mNumVertices) (field 'mBitangents) #:element-size 12 #:element-proc get-element-address)
+ wrap-ai-vector3d))
+ (colors (map
+ (lambda (c)
+ (wrap
+ (array (field 'mNumVertices) c #:element-size 16 #:element-proc get-element-address)
+ wrap-ai-color4d))
+ (field 'mColors)))
+ (texture-coords (map
+ (lambda (tc)
+ (wrap
+ (array (field 'mNumVertices) tc #:element-size 12 #:element-proc get-element-address)
+ wrap-ai-vector3d))
+ (field 'mTextureCoords)))
+ (num-uv-components (field 'mNumUVComponents))
+ (bones (wrap (array (field 'mNumBones) (field 'mBones)) wrap-ai-bone))
+ (material-index (field 'mMaterialIndex)))
+
+(export ai-mesh?
+ ai-mesh-contents
+ ai-mesh-name
+ ai-mesh-primitive-types
+ ai-mesh-vertices
+ ai-mesh-faces
+ ai-mesh-normals
+ ai-mesh-tangents
+ ai-mesh-bitangents
+ ai-mesh-colors
+ ai-mesh-texture-coords
+ ai-mesh-num-uv-components
+ ai-mesh-bones
+ ai-mesh-material-index)
+
+
+;;; Materials
+
+(define-conversion-type parse-aiMaterial -> ai-material
+ (properties (array (field 'mNumProperties) (field 'mProperties)))
+ (num-allocated (field 'mNumAllocated)))
+
+(export ai-material?
+ ai-material-contents
+ ai-material-properties
+ ai-material-num-allocated)
+
+
+;;; Faces
+
+(define-conversion-type parse-aiFace -> ai-face
+ (indices (array (field 'mNumIndices) (field 'mIndices))))
+
+(export ai-face?
+ ai-face-contents
+ ai-face-indices)
+
+
+;;; Vectors
+
+(define-conversion-type parse-aiVector2D -> ai-vector2d
+ (x (field 'x))
+ (y (field 'y)))
+
+(export ai-vector2d?
+ ai-vector2d-contents
+ ai-vector2d-x
+ ai-vector2d-y)
+
+(define-conversion-type parse-aiVector3D -> ai-vector3d
+ (x (field 'x))
+ (y (field 'y))
+ (z (field 'z)))
+
+(export ai-vector3d?
+ ai-vector3d-contents
+ ai-vector3d-x
+ ai-vector3d-y
+ ai-vector3d-z)
+
+
+;;; Matrixes
+
+(define-conversion-type parse-aiMatrix3x3 -> ai-matrix3x3
+ (a1 (field 'a1))
+ (a2 (field 'a2))
+ (a3 (field 'a3))
+ (b1 (field 'b1))
+ (b2 (field 'b2))
+ (b3 (field 'b3))
+ (c1 (field 'c1))
+ (c2 (field 'c2))
+ (c3 (field 'c3)))
+
+(export ai-matrix3x3?
+ ai-matrix3x3-contents
+ ai-matrix3x3-a1
+ ai-matrix3x3-a2
+ ai-matrix3x3-a3
+ ai-matrix3x3-b1
+ ai-matrix3x3-b2
+ ai-matrix3x3-b3
+ ai-matrix3x3-c1
+ ai-matrix3x3-c2
+ ai-matrix3x3-c3)
+
+(define-conversion-type parse-aiMatrix4x4 -> ai-matrix4x4
+ (a1 (field 'a1))
+ (a2 (field 'a2))
+ (a3 (field 'a3))
+ (a4 (field 'a4))
+ (b1 (field 'b1))
+ (b2 (field 'b2))
+ (b3 (field 'b3))
+ (b4 (field 'b4))
+ (c1 (field 'c1))
+ (c2 (field 'c2))
+ (c3 (field 'c3))
+ (c4 (field 'c4))
+ (d1 (field 'd1))
+ (d2 (field 'd2))
+ (d3 (field 'd3))
+ (d4 (field 'd4)))
+
+(export ai-matrix4x4?
+ ai-matrix4x4-contents
+ ai-matrix4x4-a1
+ ai-matrix4x4-a2
+ ai-matrix4x4-a3
+ ai-matrix4x4-a4
+ ai-matrix4x4-b1
+ ai-matrix4x4-b2
+ ai-matrix4x4-b3
+ ai-matrix4x4-b4
+ ai-matrix4x4-c1
+ ai-matrix4x4-c2
+ ai-matrix4x4-c3
+ ai-matrix4x4-c4
+ ai-matrix4x4-d1
+ ai-matrix4x4-d2
+ ai-matrix4x4-d3
+ ai-matrix4x4-d4)
+
+
+;;; Colors
+
+(define-conversion-type parse-aiColor4D -> ai-color4d
+ (r (field 'r))
+ (g (field 'g))
+ (b (field 'b))
+ (a (field 'a)))
+
+(export ai-color4d?
+ ai-color4d-contents
+ ai-color4d-r
+ ai-color4d-g
+ ai-color4d-b
+ ai-color4d-a)
+
+
+;;; Bones
+
+(define-conversion-type parse-aiBone -> ai-bone
+ (name (sized-string (field 'mName)))
+ (weights (wrap
+ (array (field 'mNumWeights) (field 'mWeights) #:element-size 8 #:element-proc get-element-address)
+ wrap-ai-vertex-weight))
+ (offset-matrix (wrap (parse-aiMatrix4x4 (field 'mOffsetMatrix) #:reverse #t) wrap-ai-matrix4x4)))
+
+(export ai-bone?
+ ai-bone-contents
+ ai-bone-name
+ ai-bone-weights
+ ai-bone-offset-matrix)
+
+
+;;; Weights
+
+(define-conversion-type parse-aiVertexWeight -> ai-vertex-weight
+ (vertex-id (field 'mVertexId))
+ (weight (field 'mWeight)))
+
+(export ai-vertex-weight?
+ ai-vertex-weight-contents
+ ai-vertex-weight-vertex-id
+ ai-vertex-weight-weight)
+
+
+;;; Functions
+
+(define-public (ai-import-file filename flags)
+ (wrap-ai-scene
+ (aiImportFile (string->pointer filename)
+ flags)))
+
+(define-public (ai-transform-vec-by-matrix4 vec mat)
+ (let ((cvec (parse-aiVector3D (map cdr (ai-vector3d-contents vec)) #:reverse #t))
+ (cmat (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents mat)) #:reverse #t)))
+ (aiTransformVecByMatrix4 cvec cmat)
+ (wrap-ai-vector3d cvec)))
+
+(define-public (ai-multiply-matrix4 m1 m2)
+ (let ((cm1 (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents m1)) #:reverse #t))
+ (cm2 (parse-aiMatrix4x4 (map cdr (ai-matrix4x4-contents m2)) #:reverse #t)))
+ (aiMultiplyMatrix4 cm1 cm2)
+ (wrap-ai-matrix4x4 cm1)))