From 63cca7faa50c513c8aa201d15336e555438fddb5 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Wed, 11 Jun 2014 15:19:02 +0200 Subject: [PATCH] Low level support and scene.h structs parsing --- src/assimp.scm | 11 +++++++++ src/low-level.scm | 33 +++++++++++++++++++++++++ src/low-level/scene.scm | 53 +++++++++++++++++++++++++++++++++++++++++ src/low-level/types.scm | 26 ++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 src/low-level.scm create mode 100644 src/low-level/scene.scm create mode 100644 src/low-level/types.scm diff --git a/src/assimp.scm b/src/assimp.scm index f3d8893..7422b81 100644 --- a/src/assimp.scm +++ b/src/assimp.scm @@ -16,6 +16,7 @@ (define-module (assimp assimp) + #:use-module (assimp low-level scene) #:use-module (ice-9 iconv) #:use-module (rnrs bytevectors) #:use-module (system foreign)) @@ -143,6 +144,14 @@ (aiImportFile (string->pointer filename) flags))) +(define (load-scene filename flags) + (parse-aiNode + (assoc-ref + (parse-aiScene + (aiImportFile (string->pointer filename) + flags)) + 'mRootNode))) + (export load-scene unwrap-scene scene? @@ -164,6 +173,8 @@ ;;; Meshes +(define AI_MAX_NUMBER_OF_COLOR_SETS 8) + (define-type mesh (num-primitive-types (lambda (p) (bv-uint-ref p 0))) (vertices (get-pointer-of-pointers 4 12)) diff --git a/src/low-level.scm b/src/low-level.scm new file mode 100644 index 0000000..a184082 --- /dev/null +++ b/src/low-level.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) + #:use-module (system foreign)) + + +(define-syntax define-struct-parser + (lambda (x) + (syntax-case x () + ((_ name (field type) ...) + (with-syntax (((field-name ...) (map car #'((field type) ...))) + ((field-type ...) (map cadr #'((field type) ...)))) + #'(define (name pointer) + (map cons + '(field-name ...) + (parse-c-struct pointer (list field-type ...))))))))) + +(export define-struct-parser) diff --git a/src/low-level/scene.scm b/src/low-level/scene.scm new file mode 100644 index 0000000..6d67f48 --- /dev/null +++ b/src/low-level/scene.scm @@ -0,0 +1,53 @@ +;;; 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 scene) + #:use-module (assimp low-level) + #:use-module (assimp low-level types) + #:use-module (system foreign)) + + +(define-struct-parser parse-aiNode + (aiString aiString-type) + (aiMatrix4x4 aiMatrix4x4-type) + (mParent '*) + (mNumChildren unsigned-int) + (mChildren '*) + (mNumMeshes unsigned-int) + (mMeshes '*)) + +(export parse-aiNode) + + +(define-struct-parser parse-aiScene + (mFlags unsigned-int) + (mRootNode '*) + (mNumMeshes unsigned-int) + (mMeshes '*) + (mNumMaterials unsigned-int) + (mMaterials '*) + (mNumAnimations unsigned-int) + (mAnimations '*) + (mNumTextures unsigned-int) + (mTextures '*) + (mNumLights unsigned-int) + (mLights '*) + (mNumCameras unsigned-int) + (mCameras '*) + (mPrivate '*)) + +(export parse-aiScene) diff --git a/src/low-level/types.scm b/src/low-level/types.scm new file mode 100644 index 0000000..18a11d2 --- /dev/null +++ b/src/low-level/types.scm @@ -0,0 +1,26 @@ +;;; 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 types) + #:use-module (system foreign)) + + +(define-public aiString-type + (list size_t (make-list 1024 int8))) + +(define-public aiMatrix4x4-type + (make-list 16 float)) -- 2.39.5