1 ;;; guile-assimp, foreign interface to libassimp
2 ;;; Copyright (C) 2014 by Javier Sancho Fernandez <jsf at jsancho dot org>
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation, either version 3 of the License, or
7 ;;; (at your option) any later version.
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;; GNU General Public License for more details.
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 (define-module (assimp assimp)
19 #:use-module (assimp low-level)
20 #:use-module (assimp low-level cimport)
21 #:use-module (assimp low-level color)
22 #:use-module (assimp low-level material)
23 #:use-module (assimp low-level mesh)
24 #:use-module (assimp low-level scene)
25 #:use-module (assimp low-level types)
26 #:use-module (assimp low-level vector)
27 #:use-module (system foreign))
32 (define-conversion-type parse-aiScene -> ai-scene
33 (flags (field 'mFlags))
34 (root-node (wrap (field 'mRootNode) wrap-ai-node))
35 (meshes (wrap (array (field 'mNumMeshes) (field 'mMeshes)) wrap-ai-mesh))
36 (materials (wrap (array (field 'mNumMaterials) (field 'mMaterials)) wrap-ai-material))
37 (animations (array (field 'mNumAnimations) (field 'mAnimations)))
38 (textures (array (field 'mNumTextures) (field 'mTextures)))
39 (lights (array (field 'mNumLights) (field 'mLights)))
40 (cameras (array (field 'mNumCameras) (field 'mCameras))))
56 (define-conversion-type parse-aiNode -> ai-node
57 (name (sized-string (field 'mName)))
58 (transformation (field 'mTransformation))
59 (parent (wrap (field 'mParent) wrap-ai-node))
60 (children (wrap (array (field 'mNumChildren) (field 'mChildren)) wrap-ai-node))
61 (meshes (array (field 'mNumMeshes) (field 'mMeshes))))
66 ai-node-transformation
74 (define-conversion-type parse-aiMesh -> ai-mesh
75 (name (sized-string (field 'mName)))
76 (primitive-types (field 'mPrimitiveTypes))
78 (array (field 'mNumVertices) (field 'mVertices) #:element-proc get-element-address)
81 (array (field 'mNumFaces) (field 'mFaces) #:element-size 8 #:element-proc get-element-address)
84 (array (field 'mNumVertices) (field 'mNormals) #:element-size 12 #:element-proc get-element-address)
87 (array (field 'mNumVertices) (field 'mTangents) #:element-size 12 #:element-proc get-element-address)
90 (array (field 'mNumVertices) (field 'mBitangents) #:element-size 12 #:element-proc get-element-address)
95 (array (field 'mNumVertices) c #:element-size 16 #:element-proc get-element-address)
101 (array (field 'mNumVertices) tc #:element-size 12 #:element-proc get-element-address)
103 (field 'mTextureCoords)))
104 (num-uv-components (field 'mNumUVComponents))
105 (bones (wrap (array (field 'mNumBones) (field 'mBones)) wrap-ai-bone))
106 (material-index (field 'mMaterialIndex)))
111 ai-mesh-primitive-types
118 ai-mesh-texture-coords
119 ai-mesh-num-uv-components
121 ai-mesh-material-index)
126 (define-conversion-type parse-aiMaterial -> ai-material
127 (properties (array (field 'mNumProperties) (field 'mProperties)))
128 (num-allocated (field 'mNumAllocated)))
132 ai-material-properties
133 ai-material-num-allocated)
138 (define-conversion-type parse-aiFace -> ai-face
139 (indices (array (field 'mNumIndices) (field 'mIndices))))
148 (define-conversion-type parse-aiVector2D -> ai-vector2d
157 (define-conversion-type parse-aiVector3D -> ai-vector3d
171 (define-conversion-type parse-aiColor4D -> ai-color4d
187 (define-conversion-type parse-aiBone -> ai-bone
188 (name (sized-string (field 'mName)))
190 (array (field 'mNumWeights) (field 'mWeights) #:element-size 8 #:element-proc get-element-address)
191 wrap-ai-vertex-weight))
192 (offset-matrix (field 'mOffsetMatrix)))
198 ai-bone-offset-matrix)
203 (define-conversion-type parse-aiVertexWeight -> ai-vertex-weight
204 (vertex-id (field 'mVertexId))
205 (weight (field 'mWeight)))
207 (export ai-vertex-weight?
208 ai-vertex-weight-contents
209 ai-vertex-weight-vertex-id
210 ai-vertex-weight-weight)
215 (define-public (ai-import-file filename flags)
217 (aiImportFile (string->pointer filename)
220 (define-public (ai-multiply-matrix4 m1 m2)
221 (let ((cm1 (make-c-struct aiMatrix4x4-type m1))
222 (cm2 (make-c-struct aiMatrix4x4-type m2)))
223 (aiMultiplyMatrix4 cm1 cm2)
224 (parse-c-struct cm1 aiMatrix4x4-type)))