From 917fd378fcc23c07d14442e0ccabcce90f8c9fcc Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Mon, 14 Jul 2014 14:54:13 +0200 Subject: [PATCH] Add new types and structs parsers * src/assimp.scm: New types vector2d, vector3d, color4d, bone and vertex-weight. * src/low-level/color.scm: New parser for aiColor4D. * src/low-level/mesh.scm: New parsers for aiVertexWeight and aiBone. * src/low-level/vector.scm: New parsers for aiVector2D and aiVector3D. --- src/assimp.scm | 105 ++++++++++++++++++++++++++++++++++++--- src/low-level/color.scm | 29 +++++++++++ src/low-level/mesh.scm | 16 ++++++ src/low-level/vector.scm | 33 ++++++++++++ 4 files changed, 175 insertions(+), 8 deletions(-) create mode 100644 src/low-level/color.scm create mode 100644 src/low-level/vector.scm diff --git a/src/assimp.scm b/src/assimp.scm index 9f6bfc2..81329da 100644 --- a/src/assimp.scm +++ b/src/assimp.scm @@ -17,9 +17,11 @@ (define-module (assimp assimp) #:use-module (assimp low-level) + #:use-module (assimp low-level color) #:use-module (assimp low-level material) #:use-module (assimp low-level mesh) #:use-module (assimp low-level scene) + #:use-module (assimp low-level vector) #:use-module (system foreign)) (define libassimp (dynamic-link "libassimp")) @@ -83,15 +85,35 @@ (define-conversion-type parse-aiMesh -> mesh (name (sized-string (field 'mName))) (primitive-types (field 'mPrimitiveTypes)) - (vertices (array (field 'mNumVertices) (field 'mVertices) #:element-proc get-element-address)) - (faces (wrap (array (field 'mNumFaces) (field 'mFaces) #:element-size 8 #:element-proc get-element-address) wrap-face)) - (normals (array (field 'mNumVertices) (field 'mNormals) #:element-size 12 #:element-proc get-element-address)) - (tangents (array (field 'mNumVertices) (field 'mTangents) #:element-size 12 #:element-proc get-element-address)) - (bitangents (array (field 'mNumVertices) (field 'mBitangents) #:element-size 12 #:element-proc get-element-address)) - (colors (field 'mColors)) - (texture-coords (field 'mTextureCoords)) + (vertices (wrap + (array (field 'mNumVertices) (field 'mVertices) #:element-proc get-element-address) + wrap-vector3d)) + (faces (wrap + (array (field 'mNumFaces) (field 'mFaces) #:element-size 8 #:element-proc get-element-address) + wrap-face)) + (normals (wrap + (array (field 'mNumVertices) (field 'mNormals) #:element-size 12 #:element-proc get-element-address) + wrap-vector3d)) + (tangents (wrap + (array (field 'mNumVertices) (field 'mTangents) #:element-size 12 #:element-proc get-element-address) + wrap-vector3d)) + (bitangents (wrap + (array (field 'mNumVertices) (field 'mBitangents) #:element-size 12 #:element-proc get-element-address) + wrap-vector3d)) + (colors (map + (lambda (c) + (wrap + (array (field 'mNumVertices) c #:element-size 16 #:element-proc get-element-address) + wrap-color4d)) + (field 'mColors))) + (texture-coords (map + (lambda (tc) + (wrap + (array (field 'mNumVertices) tc #:element-size 12 #:element-proc get-element-address) + wrap-vector3d)) + (field 'mTextureCoords))) (num-uv-components (field 'mNumUVComponents)) - (bones (array (field 'mNumBones) (field 'mBones))) + (bones (wrap (array (field 'mNumBones) (field 'mBones)) wrap-bone)) (material-index (field 'mMaterialIndex))) (export mesh? @@ -130,3 +152,70 @@ (export face? face-contents face-indices) + + +;;; Vectors + +(define-conversion-type parse-aiVector2D -> vector2d + (x (field 'x)) + (y (field 'y))) + +(export vector2d? + vector2d-contents + vector2d-x + vector2d-y) + +(define-conversion-type parse-aiVector3D -> vector3d + (x (field 'x)) + (y (field 'y)) + (z (field 'z))) + +(export vector3d? + vector3d-contents + vector3d-x + vector3d-y + vector3d-z) + + +;;; Colors + +(define-conversion-type parse-aiColor4D -> color4d + (r (field 'r)) + (g (field 'g)) + (b (field 'b)) + (a (field 'a))) + +(export color4d? + color4d-contents + color4d-r + color4d-g + color4d-b + color4d-a) + + +;;; Bones + +(define-conversion-type parse-aiBone -> bone + (name (sized-string (field 'mName))) + (weights (wrap + (array (field 'mNumWeights) (field 'mWeights) #:element-size 8 #:element-proc get-element-address) + wrap-vertex-weight)) + (offset-matrix (field 'mOffsetMatrix))) + +(export bone? + bone-contents + bone-name + bone-weights + bone-offset-matrix) + + +;;; Weights + +(define-conversion-type parse-aiVertexWeight -> vertex-weight + (vertex-id (field 'mVertexId)) + (weight (field 'mWeight))) + +(export vertex-weight? + vertex-weight-contents + vertex-weight-vertex-id + vertex-weight-weight) diff --git a/src/low-level/color.scm b/src/low-level/color.scm new file mode 100644 index 0000000..bc13274 --- /dev/null +++ b/src/low-level/color.scm @@ -0,0 +1,29 @@ +;;; guile-assimp, foreign interface to libassimp +;;; Copyright (C) 2014 by Javier Sancho Fernandez +;;; +;;; This program is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see . + + +(define-module (assimp low-level color) + #:use-module (assimp low-level) + #:use-module (system foreign)) + + +(define-struct-parser parse-aiColor4D + (r float) + (g float) + (b float) + (a float)) + +(export parse-aiColor4D) diff --git a/src/low-level/mesh.scm b/src/low-level/mesh.scm index e151045..50d0bb8 100644 --- a/src/low-level/mesh.scm +++ b/src/low-level/mesh.scm @@ -28,6 +28,22 @@ (export parse-aiFace) +(define-struct-parser parser-aiVertexWeight + (mVertexId unsigned-int) + (mWeight float)) + +(export parse-aiVertexWeight) + + +(define-struct-parser parse-aiBone + (mName aiString-type) + (mNumWeights unsigned-int) + (mWeights '*) + (mOffsetMatrix aiMatrix4x4-type)) + +(export parse-aiBone) + + (define AI_MAX_NUMBER_OF_COLOR_SETS #x8) (define AI_MAX_NUMBER_OF_TEXTURECOORDS #x8) diff --git a/src/low-level/vector.scm b/src/low-level/vector.scm new file mode 100644 index 0000000..49b9916 --- /dev/null +++ b/src/low-level/vector.scm @@ -0,0 +1,33 @@ +;;; guile-assimp, foreign interface to libassimp +;;; Copyright (C) 2014 by Javier Sancho Fernandez +;;; +;;; This program is free software: you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation, either version 3 of the License, or +;;; (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program. If not, see . + + +(define-module (assimp low-level vector) + #:use-module (assimp low-level) + #:use-module (system foreign)) + + +(define-struct-parser parse-aiVector2D + (x float) + (y float)) + +(define-struct-parser parse-aiVector3D + (x float) + (y float) + (z float)) + +(export parse-aiVector2D + parse-aiVector3D) -- 2.39.5