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 material)
21 #:use-module (assimp low-level mesh)
22 #:use-module (assimp low-level scene)
23 #:use-module (system foreign))
25 (define libassimp (dynamic-link "libassimp"))
28 (pointer->procedure '*
29 (dynamic-func "aiImportFile" libassimp)
30 (list '* unsigned-int)))
35 (define-conversion-type parse-aiScene -> scene
36 (flags (field 'mFlags))
37 (root-node (wrap (field 'mRootNode) wrap-node))
38 (meshes (wrap (array (field 'mNumMeshes) (field 'mMeshes)) wrap-mesh))
39 (materials (wrap (array (field 'mNumMaterials) (field 'mMaterials)) wrap-material))
40 (animations (array (field 'mNumAnimations) (field 'mAnimations)))
41 (textures (array (field 'mNumTextures) (field 'mTextures)))
42 (lights (array (field 'mNumLights) (field 'mLights)))
43 (cameras (array (field 'mNumCameras) (field 'mCameras))))
45 (define (load-scene filename flags)
47 (aiImportFile (string->pointer filename)
65 (define-conversion-type parse-aiNode -> node
66 (name (sized-string (field 'mName)))
67 (transformation (field 'mTransformation))
68 (parent (wrap (field 'mParent) wrap-node))
69 (children (wrap (array (field 'mNumChildren) (field 'mChildren)) wrap-node))
70 (meshes (array (field 'mNumMeshes) (field 'mMeshes))))
83 (define-conversion-type parse-aiMesh -> mesh
84 (name (sized-string (field 'mName)))
85 (primitive-types (field 'mPrimitiveTypes))
86 (vertices (array (field 'mNumVertices) (field 'mVertices) #:element-proc get-element-address))
87 (faces (wrap (array (field 'mNumFaces) (field 'mFaces) #:element-size 8 #:element-proc get-element-address) wrap-face))
88 (normals (array (field 'mNumVertices) (field 'mNormals) #:element-size 12 #:element-proc get-element-address))
89 (tangents (array (field 'mNumVertices) (field 'mTangents) #:element-size 12 #:element-proc get-element-address))
90 (bitangents (array (field 'mNumVertices) (field 'mBitangents) #:element-size 12 #:element-proc get-element-address))
91 (colors (field 'mColors))
92 (texture-coords (field 'mTextureCoords))
93 (num-uv-components (field 'mNumUVComponents))
94 (bones (array (field 'mNumBones) (field 'mBones)))
95 (material-index (field 'mMaterialIndex)))
108 mesh-num-uv-components
115 (define-conversion-type parse-aiMaterial -> material
116 (properties (array (field 'mNumProperties) (field 'mProperties)))
117 (num-allocated (field 'mNumAllocated)))
122 material-num-allocated)
127 (define-conversion-type parse-aiFace -> face
128 (indices (array (field 'mNumIndices) (field 'mIndices))))