From: Javier Sancho Date: Sat, 21 Mar 2020 07:47:57 +0000 (+0100) Subject: add-octree-scene-node! X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=9eb3d3607d4468b525df34096657fd04f77724e7;p=guile-irrlicht.git add-octree-scene-node! --- diff --git a/Makefile.am b/Makefile.am index 4918fc2..6b42a54 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,6 +38,8 @@ libguile_irrlicht_la_SOURCES = \ src/gui-static-text.cpp \ src/guile-irrlicht.cpp \ src/material-flags.cpp \ + src/mesh.cpp \ + src/mesh-scene-node.cpp \ src/misc.cpp \ src/rect.cpp \ src/reference-counted.cpp \ diff --git a/examples/02.Quake3Map.scm b/examples/02.Quake3Map.scm index 1407f29..47c8125 100644 --- a/examples/02.Quake3Map.scm +++ b/examples/02.Quake3Map.scm @@ -65,7 +65,7 @@ (add-file-archive! (get-file-system device) "media/map-20kdm2.pk3") (define mesh (get-mesh scene-manager "20kdm2.bsp")) -(define node (add-octree-scene-node +(define node (add-octree-scene-node! scene-manager mesh #:minimal-polys-per-node 1024)) (set-position! node '(-1300 -144 -1249)) diff --git a/src/guile-irrlicht.cpp b/src/guile-irrlicht.cpp index daa314d..4846b69 100644 --- a/src/guile-irrlicht.cpp +++ b/src/guile-irrlicht.cpp @@ -31,6 +31,8 @@ #include "gui-environment.h" #include "gui-static-text.h" #include "material-flags.h" +#include "mesh.h" +#include "mesh-scene-node.h" #include "misc.h" #include "reference-counted.h" #include "scene-manager.h" @@ -53,6 +55,8 @@ extern "C" { init_gui_environment (); init_gui_static_text (); init_material_flag (); + init_mesh (); + init_mesh_scene_node (); init_misc (); init_reference_counted (); init_scene_manager (); diff --git a/src/mesh-scene-node.cpp b/src/mesh-scene-node.cpp new file mode 100644 index 0000000..01a2dea --- /dev/null +++ b/src/mesh-scene-node.cpp @@ -0,0 +1,39 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht 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 Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#include +#include +#include "mesh-scene-node.h" +#include "wrapped.h" + +extern "C" { + + void + init_mesh_scene_node (void) + { + init_mesh_scene_node_type (); + } + + DEFINE_WRAPPED_TYPE (irr::scene::IMeshSceneNode*, "mesh-scene-node", + init_mesh_scene_node_type, mesh_scene_node_p, + wrap_mesh_scene_node, unwrap_mesh_scene_node); + +} diff --git a/src/mesh-scene-node.h b/src/mesh-scene-node.h new file mode 100644 index 0000000..ba1477c --- /dev/null +++ b/src/mesh-scene-node.h @@ -0,0 +1,39 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht 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 Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#ifndef __GUILE_IRRLICHT_MESH_SCENE_NODE_H_INCLUDED__ +#define __GUILE_IRRLICHT_MESH_SCENE_NODE_H_INCLUDED__ + +#include +#include +#include "wrapped.h" + +extern "C" { + + void + init_mesh_scene_node (void); + + DECLARE_WRAPPED_TYPE (irr::scene::IMeshSceneNode*, init_mesh_scene_node_type, + mesh_scene_node_p, wrap_mesh_scene_node, unwrap_mesh_scene_node); + +} + +#endif diff --git a/src/mesh.cpp b/src/mesh.cpp new file mode 100644 index 0000000..e95b81a --- /dev/null +++ b/src/mesh.cpp @@ -0,0 +1,39 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht 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 Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#include +#include +#include "mesh.h" +#include "wrapped.h" + +extern "C" { + + void + init_mesh (void) + { + init_mesh_type (); + } + + DEFINE_WRAPPED_TYPE (irr::scene::IMesh*, "mesh", + init_mesh_type, mesh_p, + wrap_mesh, unwrap_mesh); + +} diff --git a/src/mesh.h b/src/mesh.h new file mode 100644 index 0000000..895a216 --- /dev/null +++ b/src/mesh.h @@ -0,0 +1,39 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + This file is part of guile-irrlicht. + + guile-irrlicht is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + guile-irrlicht 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 Lesser General Public + License along with guile-irrlicht. If not, see + . +*/ + +#ifndef __GUILE_IRRLICHT_MESH_H_INCLUDED__ +#define __GUILE_IRRLICHT_MESH_H_INCLUDED__ + +#include +#include +#include "wrapped.h" + +extern "C" { + + void + init_mesh (void); + + DECLARE_WRAPPED_TYPE (irr::scene::IMesh*, init_mesh_type, + mesh_p, wrap_mesh, unwrap_mesh); + +} + +#endif diff --git a/src/scene-manager.cpp b/src/scene-manager.cpp index cb7f80c..0f3e54c 100644 --- a/src/scene-manager.cpp +++ b/src/scene-manager.cpp @@ -26,6 +26,8 @@ #include "animated-mesh-scene-node.h" #include "camera-scene-node.h" #include "device.h" +#include "mesh.h" +#include "mesh-scene-node.h" #include "scene-manager.h" #include "scene-node.h" #include "vector3d.h" @@ -41,10 +43,12 @@ extern "C" { (scm_t_subr)irr_scene_addAnimatedMeshSceneNode); scm_c_define_gsubr ("add-camera-scene-node!", 1, 0, 1, (scm_t_subr)irr_scene_addCameraSceneNode); + scm_c_define_gsubr ("add-octree-scene-node!", 2, 0, 1, + (scm_t_subr)irr_scene_addOctreeSceneNode); scm_c_define_gsubr ("get-mesh", 2, 0, 0, (scm_t_subr)irr_scene_getMesh); scm_c_define_gsubr ("get-scene-manager", 1, 0, 0, (scm_t_subr)irr_getSceneManager); scm_c_export ("add-animated-mesh-scene-node!", "add-camera-scene-node!", - "get-mesh", "get-scene-manager", NULL); + "add-octree-scene-node!", "get-mesh", "get-scene-manager", NULL); } DEFINE_WRAPPED_TYPE (irr::scene::ISceneManager*, "scene-manager", @@ -122,6 +126,44 @@ extern "C" { return wrap_camera_scene_node (camera); } + SCM + irr_scene_addOctreeSceneNode (SCM wrapped_scene_manager, + SCM wrapped_mesh, + SCM rest) + { + SCM parent = scm_from_bool (0); + SCM id = scm_from_int32 (-1); + SCM minimal_polys_per_node = scm_from_int32 (256); + SCM also_add_if_mesh_pointer_zero = scm_from_bool (0); + + scm_c_bind_keyword_arguments ("add-octree-scene-node!", rest, (scm_t_keyword_arguments_flags)0, + scm_from_utf8_keyword ("parent"), &parent, + scm_from_utf8_keyword ("id"), &id, + scm_from_utf8_keyword ("minimal-polys-per-node"), &minimal_polys_per_node, + scm_from_utf8_keyword ("also-add-if-mesh-pointer-zero"), &also_add_if_mesh_pointer_zero, + SCM_UNDEFINED); + + irr::scene::ISceneManager* smgr = unwrap_scene_manager (wrapped_scene_manager); + irr::scene::IMeshSceneNode* node; + if (animated_mesh_p (wrapped_mesh)) + { + node = smgr->addOctreeSceneNode (unwrap_animated_mesh (wrapped_mesh), + scm_is_false (parent) ? 0 : unwrap_scene_node (parent), + scm_to_int32 (id), + scm_to_int32 (minimal_polys_per_node), + scm_to_bool (also_add_if_mesh_pointer_zero)); + } + else + { + node = smgr->addOctreeSceneNode (unwrap_mesh (wrapped_mesh), + scm_is_false (parent) ? 0 : unwrap_scene_node (parent), + scm_to_int32 (id), + scm_to_int32 (minimal_polys_per_node), + scm_to_bool (also_add_if_mesh_pointer_zero)); + } + return wrap_mesh_scene_node (node); + } + SCM irr_scene_getMesh (SCM wrapped_scene_manager, SCM filename) diff --git a/src/scene-manager.h b/src/scene-manager.h index f65548e..39f020d 100644 --- a/src/scene-manager.h +++ b/src/scene-manager.h @@ -43,6 +43,11 @@ extern "C" { irr_scene_addCameraSceneNode (SCM wrapped_scene_manager, SCM rest); + SCM + irr_scene_addOctreeSceneNode (SCM wrapped_scene_manager, + SCM wrapped_mesh, + SCM rest); + SCM irr_scene_getMesh (SCM wrapped_scene_manager, SCM filename);