]> git.jsancho.org Git - guile-irrlicht.git/commitdiff
add-custom-scene-node!
authorJavier Sancho <jsf@jsancho.org>
Sat, 28 Mar 2020 11:53:04 +0000 (12:53 +0100)
committerJavier Sancho <jsf@jsancho.org>
Sat, 28 Mar 2020 11:53:04 +0000 (12:53 +0100)
src/scene-manager.cpp
src/scene-manager.h

index eb7a3780ab6361e2afd0c72fcf3d70ed3041b7ab..ed2ab6871fc29cfeb38ece8ff86b51c27ba8c44e 100644 (file)
 
 #include "animated-mesh.h"
 #include "animated-mesh-scene-node.h"
+#include "box3d.h"
 #include "camera-scene-node.h"
 #include "device.h"
 #include "keymap.h"
+#include "material.h"
 #include "mesh.h"
 #include "mesh-scene-node.h"
 #include "scene-manager.h"
@@ -46,13 +48,15 @@ extern "C" {
                         (scm_t_subr)irr_scene_addCameraSceneNode);
     scm_c_define_gsubr ("add-camera-scene-node-fps!", 1, 0, 1,
                         (scm_t_subr)irr_scene_addCameraSceneNodeFPS);
+    scm_c_define_gsubr ("add-custom-scene-node!", 5, 0, 1,
+                        (scm_t_subr)irr_scene_addCustomSceneNode);
     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!",
-                  "add-camera-scene-node-fps!", "add-octree-scene-node!",
-                  "get-mesh", "get-scene-manager", NULL);
+                  "add-camera-scene-node-fps!", "add-custom-scene-node!",
+                  "add-octree-scene-node!", "get-mesh", "get-scene-manager", NULL);
   }
 
   DEFINE_WRAPPED_TYPE (irr::scene::ISceneManager*, "scene-manager",
@@ -173,6 +177,108 @@ extern "C" {
     return wrap_camera_scene_node (camera);
   }
 
+  SCM
+  irr_scene_addCustomSceneNode (SCM wrapped_scene_manager,
+                                SCM proc_render,
+                                SCM proc_get_bounding_box,
+                                SCM proc_get_material_count,
+                                SCM proc_get_material,
+                                SCM rest)
+  {
+    irr::scene::ISceneManager* scene_manager = unwrap_scene_manager (wrapped_scene_manager);
+
+    SCM parent = wrap_scene_node (scene_manager->getRootSceneNode ());
+    SCM id = scm_from_int32 (-1);
+    SCM position = scm_list_3 (scm_from_double (0),
+                               scm_from_double (0),
+                               scm_from_double (0));
+    SCM rotation = scm_list_3 (scm_from_double (0),
+                               scm_from_double (0),
+                               scm_from_double (0));
+    SCM scale = scm_list_3 (scm_from_double (1),
+                            scm_from_double (1),
+                            scm_from_double (1));
+
+    scm_c_bind_keyword_arguments ("add-custom-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 ("position"), &position,
+                                  scm_from_utf8_keyword ("rotation"), &rotation,
+                                  scm_from_utf8_keyword ("scale"), &scale,
+                                  SCM_UNDEFINED);
+
+    class CustomSceneNode : public irr::scene::ISceneNode
+    {
+      SCM scm_render;
+      SCM scm_get_bounding_box;
+      SCM scm_get_material_count;
+      SCM scm_get_material;
+
+    public:
+      CustomSceneNode (irr::scene::ISceneNode* parent,
+                       irr::scene::ISceneManager* smgr,
+                       irr::s32 id,
+                       const irr::core::vector3df& position,
+                       const irr::core::vector3df& rotation,
+                       const irr::core::vector3df& scale,
+                       SCM render,
+                       SCM get_bounding_box,
+                       SCM get_material_count,
+                       SCM get_material)
+        : irr::scene::ISceneNode (parent, smgr, id, position, rotation, scale)
+      {
+        scm_render = render;
+        scm_get_bounding_box = get_bounding_box;
+        scm_get_material_count = get_material_count;
+        scm_get_material = get_material;
+      }
+
+      virtual void OnRegisterSceneNode ()
+      {
+        if (IsVisible)
+          {
+            SceneManager->registerNodeForRendering (this);
+          }
+        ISceneNode::OnRegisterSceneNode ();
+      }
+
+      virtual void render ()
+      {
+        scm_call_0 (scm_render);
+      }
+
+      virtual const irr::core::aabbox3d<irr::f32>& getBoundingBox () const
+      {
+        SCM box = scm_call_0 (scm_get_bounding_box);
+        return *(unwrap_box3d (box));
+      }
+
+      virtual irr::u32 getMaterialCount () const
+      {
+        return scm_to_uint32 (scm_call_0 (scm_get_material_count));
+      }
+
+      virtual irr::video::SMaterial& getMaterial (irr::u32 i)
+      {
+        SCM material = scm_call_1 (scm_get_material, scm_from_uint32 (i));
+        return *(unwrap_material (material));
+      }
+    };
+
+    CustomSceneNode* node =
+      new CustomSceneNode (unwrap_scene_node (parent),
+                           scene_manager,
+                           scm_to_int32 (id),
+                           scm_to_vector3df (position),
+                           scm_to_vector3df (rotation),
+                           scm_to_vector3df (scale),
+                           proc_render,
+                           proc_get_bounding_box,
+                           proc_get_material_count,
+                           proc_get_material);
+    return wrap_scene_node (node);
+  }
+
   SCM
   irr_scene_addOctreeSceneNode (SCM wrapped_scene_manager,
                                 SCM wrapped_mesh,
index 41af5579fd2cc14119e77f077997d473d6a4a2ee..44e414511650d27b51806dabd0985e6d5a03b2fd 100644 (file)
@@ -47,6 +47,14 @@ extern "C" {
   irr_scene_addCameraSceneNodeFPS (SCM wrapped_scene_manager,
                                    SCM rest);
 
+  SCM
+  irr_scene_addCustomSceneNode (SCM wrapped_scene_manager,
+                                SCM proc_render,
+                                SCM proc_get_bounding_box,
+                                SCM proc_get_material_count,
+                                SCM proc_get_material,
+                                SCM rest);
+
   SCM
   irr_scene_addOctreeSceneNode (SCM wrapped_scene_manager,
                                 SCM wrapped_mesh,