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 color)
21 #:use-module (assimp low-level material)
22 #:use-module (assimp low-level mesh)
23 #:use-module (assimp low-level scene)
24 #:use-module (assimp low-level vector)
25 #:use-module (system foreign))
27 (define libassimp (dynamic-link "libassimp"))
30 (pointer->procedure '*
31 (dynamic-func "aiImportFile" libassimp)
32 (list '* unsigned-int)))
37 (define-conversion-type parse-aiScene -> scene
38 (flags (field 'mFlags))
39 (root-node (wrap (field 'mRootNode) wrap-node))
40 (meshes (wrap (array (field 'mNumMeshes) (field 'mMeshes)) wrap-mesh))
41 (materials (wrap (array (field 'mNumMaterials) (field 'mMaterials)) wrap-material))
42 (animations (array (field 'mNumAnimations) (field 'mAnimations)))
43 (textures (array (field 'mNumTextures) (field 'mTextures)))
44 (lights (array (field 'mNumLights) (field 'mLights)))
45 (cameras (array (field 'mNumCameras) (field 'mCameras))))
47 (define (load-scene filename flags)
49 (aiImportFile (string->pointer filename)
67 (define-conversion-type parse-aiNode -> node
68 (name (sized-string (field 'mName)))
69 (transformation (field 'mTransformation))
70 (parent (wrap (field 'mParent) wrap-node))
71 (children (wrap (array (field 'mNumChildren) (field 'mChildren)) wrap-node))
72 (meshes (array (field 'mNumMeshes) (field 'mMeshes))))
85 (define-conversion-type parse-aiMesh -> mesh
86 (name (sized-string (field 'mName)))
87 (primitive-types (field 'mPrimitiveTypes))
89 (array (field 'mNumVertices) (field 'mVertices) #:element-proc get-element-address)
92 (array (field 'mNumFaces) (field 'mFaces) #:element-size 8 #:element-proc get-element-address)
95 (array (field 'mNumVertices) (field 'mNormals) #:element-size 12 #:element-proc get-element-address)
98 (array (field 'mNumVertices) (field 'mTangents) #:element-size 12 #:element-proc get-element-address)
101 (array (field 'mNumVertices) (field 'mBitangents) #:element-size 12 #:element-proc get-element-address)
106 (array (field 'mNumVertices) c #:element-size 16 #:element-proc get-element-address)
112 (array (field 'mNumVertices) tc #:element-size 12 #:element-proc get-element-address)
114 (field 'mTextureCoords)))
115 (num-uv-components (field 'mNumUVComponents))
116 (bones (wrap (array (field 'mNumBones) (field 'mBones)) wrap-bone))
117 (material-index (field 'mMaterialIndex)))
130 mesh-num-uv-components
137 (define-conversion-type parse-aiMaterial -> material
138 (properties (array (field 'mNumProperties) (field 'mProperties)))
139 (num-allocated (field 'mNumAllocated)))
144 material-num-allocated)
149 (define-conversion-type parse-aiFace -> face
150 (indices (array (field 'mNumIndices) (field 'mIndices))))
159 (define-conversion-type parse-aiVector2D -> vector2d
168 (define-conversion-type parse-aiVector3D -> vector3d
182 (define-conversion-type parse-aiColor4D -> color4d
198 (define-conversion-type parse-aiBone -> bone
199 (name (sized-string (field 'mName)))
201 (array (field 'mNumWeights) (field 'mWeights) #:element-size 8 #:element-proc get-element-address)
203 (offset-matrix (field 'mOffsetMatrix)))
214 (define-conversion-type parse-aiVertexWeight -> vertex-weight
215 (vertex-id (field 'mVertexId))
216 (weight (field 'mWeight)))
218 (export vertex-weight?
219 vertex-weight-contents
220 vertex-weight-vertex-id
221 vertex-weight-weight)