From f8051b0cda2d613101577273959b60cff09eb427 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Mon, 26 May 2014 09:32:31 +0200 Subject: [PATCH] Refining node structure (name, transformation and parent fields) --- src/assimp.scm | 27 ++++++++++++++++++++++----- src/test.c | 1 + 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/assimp.scm b/src/assimp.scm index e4d8f8e..5de82f2 100644 --- a/src/assimp.scm +++ b/src/assimp.scm @@ -16,6 +16,7 @@ (define-module (assimp assimp) + #:use-module (ice-9 iconv) #:use-module (rnrs bytevectors) #:use-module (system foreign)) @@ -75,6 +76,22 @@ (native-endianness) 4)) +(define (get-aiString index) + (lambda (pointer) + (let* ((length (bv-uint-ref pointer index)) + (data (pointer->bytevector pointer length (+ index 4)))) + (bytevector->string data (fluid-ref %default-port-encoding))))) + +(define* (get-pointer index #:optional wrap-proc) + (lambda (pointer) + (let ((p (bv-uint-ref pointer index))) + (cond ((= p 0) '()) + (else + (let ((p2 (make-pointer p))) + (list + (cond (wrap-proc (wrap-proc p2)) + (else p2))))))))) + (define* (get-pointer-of-pointers-procedure num-index root-index #:optional wrap-proc) (lambda (pointer) (let* ((num (bv-uint-ref pointer num-index)) @@ -113,11 +130,11 @@ ;;; Nodes (define-type node - (name (lambda (p) (bv-uint-ref p 0))) ;check, it's a struct - (transformation (lambda (p) (bv-uint-ref p 1028))) ;check, it's a struct - (parent (lambda (p) (bv-uint-ref p 1092))) - (children (get-pointer-of-pointers-procedure 1096 1100)) - (meshes (get-pointer-of-pointers-procedure 1104 1108))) + (name (get-aiString 0)) + (transformation (lambda (p) (array->list (pointer->bytevector p 16 1028 'f32)))) + (parent (get-pointer 1092 wrap-node)) + (children (get-pointer-of-pointers-procedure 1096 1100 wrap-node)) + (meshes (get-pointer-of-pointers-procedure 1104 1108 wrap-mesh))) (export node? node-contents) diff --git a/src/test.c b/src/test.c index d93d72e..fce975a 100644 --- a/src/test.c +++ b/src/test.c @@ -15,4 +15,5 @@ int main(int argc, char **argv) scene = aiImportFile("/home/jsancho/Imágenes/fleurOptonl.blend", aiProcessPreset_TargetRealtime_MaxQuality); node = scene->mRootNode; printf("Node:\n parent: %d\n children: %d\n meshes: %d\n", node->mParent, node->mNumChildren, node->mNumMeshes); + printf(" transformation: %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n", node->mTransformation.a1, node->mTransformation.a2, node->mTransformation.a3, node->mTransformation.a4, node->mTransformation.b1, node->mTransformation.b2, node->mTransformation.b3, node->mTransformation.b4, node->mTransformation.c1, node->mTransformation.c2, node->mTransformation.c3, node->mTransformation.c4, node->mTransformation.d1, node->mTransformation.d2, node->mTransformation.d3, node->mTransformation.d4); } -- 2.39.5