1 ;;; guile-irrlicht --- FFI bindings for Irrlicht Engine
2 ;;; Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
4 ;;; This file is part of guile-irrlicht.
6 ;;; Guile-irrlicht is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU Lesser General Public License as
8 ;;; published by the Free Software Foundation; either version 3 of the
9 ;;; License, or (at your option) any later version.
11 ;;; Guile-irrlicht is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;; General Public License for more details.
16 ;;; You should have received a copy of the GNU Lesser General Public
17 ;;; License along with guile-irrlicht. If not, see
18 ;;; <http://www.gnu.org/licenses/>.
21 (define-module (irrlicht scene)
22 #:use-module (oop goops)
23 #:use-module (ice-9 optargs)
24 #:use-module (irrlicht base)
25 #:use-module (irrlicht foreign)
26 #:use-module (irrlicht io)
27 #:use-module (irrlicht irr)
28 #:use-module (irrlicht video))
32 (define-class <mesh> (<reference-counted>)
33 (irr-class #:init-value "IMesh"))
39 (define-class <animated-mesh> (<mesh>)
40 (irr-class #:init-value "IAnimatedMesh"))
42 (export <animated-mesh>)
46 (define-class <scene-manager> (<reference-counted>)
47 (irr-class #:init-value "ISceneManager"))
49 (define-method (add-animated-mesh-scene-node! (scene-manager <scene-manager>)
50 (mesh <animated-mesh>)
53 ((parent (make <scene-node>))
58 (also-add-if-mesh-pointer-zero #f))
59 (make <animated-mesh-scene-node>
61 ((get-irrlicht-proc "addAnimatedMeshSceneNode" scene-manager parent)
69 also-add-if-mesh-pointer-zero))))
71 (define-method (add-camera-scene-node! (scene-manager <scene-manager>) . rest)
73 ((parent (make <scene-node>))
78 (make <camera-scene-node>
80 ((get-irrlicht-proc "addCameraSceneNode" scene-manager parent)
88 (define-method (add-octree-scene-node! (scene-manager <scene-manager>)
89 (mesh <animated-mesh>)
92 ((parent (make <scene-node>))
94 (minimal-polys-per-node 512)
95 (also-add-if-mesh-pointer-zero #f))
96 (let ((addOctreeSceneNode (get-irrlicht-proc "addOctreeSceneNode" scene-manager parent mesh)))
97 (make <mesh-scene-node>
99 (addOctreeSceneNode scene-manager mesh parent id minimal-polys-per-node
100 also-add-if-mesh-pointer-zero)))))
102 (define-method (add-octree-scene-node! (scene-manager <scene-manager>)
105 (let-keywords rest #f
106 ((parent (make <scene-node>))
108 (minimal-polys-per-node 256)
109 (also-add-if-mesh-pointer-zero #f))
110 (let ((addOctreeSceneNode (get-irrlicht-proc "addOctreeSceneNode" scene-manager parent mesh)))
111 (make <mesh-scene-node>
113 (addOctreeSceneNode scene-manager mesh parent id minimal-polys-per-node
114 also-add-if-mesh-pointer-zero)))))
116 (define-method (draw-all (scene-manager <scene-manager>))
117 ((get-irrlicht-proc "drawAll" scene-manager)
120 (define-method (get-mesh (scene-manager <scene-manager>) filename)
121 (make <animated-mesh>
123 ((get-irrlicht-proc "getMesh" scene-manager)
127 (export <scene-manager> add-animated-mesh-scene-node! add-camera-scene-node! add-octree-scene-node!
132 (define-class <scene-node> (<attribute-exchanging-object>)
133 (irr-class #:init-value "ISceneNode"))
135 (define-method (set-material-flag! (node <scene-node>) flag new-value)
136 ((get-irrlicht-proc "setMaterialFlag" node)
141 (define-method (set-material-texture! (node <scene-node>) texture-layer (texture <texture>))
142 ((get-irrlicht-proc "setMaterialTexture" node)
147 (export <scene-node> set-material-flag! set-material-texture!)
150 ;; IAnimatedMeshSceneNode
151 (define-class <animated-mesh-scene-node> (<scene-node>)
152 (irr-class #:init-value "IAnimatedMeshSceneNode"))
154 (define-method (set-md2-animation! (node <animated-mesh-scene-node>) anim)
155 ((get-irrlicht-proc "setMD2Animation" node)
159 (export <animated-mesh-scene-node> set-md2-animation!)
163 (define-class <camera-scene-node> (<scene-node>)
164 (irr-class #:init-value "ICameraSceneNode"))
166 (export <camera-scene-node>)
170 (define-class <mesh-scene-node> (<scene-node>)
171 (irr-class #:init-value "IMeshSceneNode"))
173 (export <mesh-scene-node>)