From 0f5922af37242ffe33f1b83f5bdfff79639b5d5a Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Tue, 26 Nov 2019 18:06:09 +0100 Subject: [PATCH] Custom scene node --- Makefile.am | 3 + include/ICustomSceneNode.h | 27 +++++++++ include/ISceneManager.h | 15 +++++ include/SMaterial.h | 31 +++++++++++ include/aabbox3d.h | 28 ++++++++++ include/cirrlicht.h | 3 + src/ISceneManager.cpp | 111 +++++++++++++++++++++++++++++++++++++ 7 files changed, 218 insertions(+) create mode 100644 include/ICustomSceneNode.h create mode 100644 include/SMaterial.h create mode 100644 include/aabbox3d.h diff --git a/Makefile.am b/Makefile.am index 771cf4e..b8dce54 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,6 +13,7 @@ libCIrrlicht_la_SOURCES = \ libCIrrlicht_la_CPPFLAGS = -I$(top_srcdir)/include libCIrrlicht_la_LDFLAGS = -version-info 0:1 pkginclude_HEADERS = \ + include/aabbox3d.h \ include/cirrlicht.h \ include/dimension2d.h \ include/EDriverTypes.h \ @@ -22,6 +23,7 @@ pkginclude_HEADERS = \ include/IAnimatedMeshSceneNode.h \ include/ICameraSceneNode.h \ include/ICursorControl.h \ + include/ICustomSceneNode.h \ include/IFileArchive.h \ include/IFileSystem.h \ include/IGUIElement.h \ @@ -38,4 +40,5 @@ pkginclude_HEADERS = \ include/SColor.h \ include/SExposedVideoData.h \ include/SKeyMap.h \ + include/SMaterial.h \ include/vector3d.h diff --git a/include/ICustomSceneNode.h b/include/ICustomSceneNode.h new file mode 100644 index 0000000..17dbeac --- /dev/null +++ b/include/ICustomSceneNode.h @@ -0,0 +1,27 @@ +/* c-irrlicht --- C bindings for Irrlicht Engine + + Copyright (C) 2019 Javier Sancho + + This file is part of c-irrlicht. + + c-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. + + c-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 __C_I_CUSTOM_SCENE_NODE_H_INCLUDED__ +#define __C_I_CUSTOM_SCENE_NODE_H_INCLUDED__ + +typedef void irr_scene_ICustomSceneNode; + +#endif diff --git a/include/ISceneManager.h b/include/ISceneManager.h index 5700bb0..ff1ed12 100644 --- a/include/ISceneManager.h +++ b/include/ISceneManager.h @@ -22,12 +22,15 @@ #ifndef __C_I_SCENE_MANAGER_H_INCLUDED__ #define __C_I_SCENE_MANAGER_H_INCLUDED__ +#include "aabbox3d.h" #include "IAnimatedMesh.h" #include "IAnimatedMeshSceneNode.h" #include "ICameraSceneNode.h" +#include "ICustomSceneNode.h" #include "IMeshSceneNode.h" #include "ISceneNode.h" #include "SKeyMap.h" +#include "SMaterial.h" #include "vector3d.h" typedef void irr_scene_ISceneManager; @@ -67,6 +70,18 @@ extern "C" { int invertMouse, int makeActive); + irr_scene_ICustomSceneNode* + irr_scene_addCustomSceneNode(irr_scene_ISceneManager* smgr, + irr_scene_ISceneNode* parent, + int id, + irr_core_vector3df* position, + irr_core_vector3df* rotation, + irr_core_vector3df* scale, + void (*render)(), + irr_core_aabbox3d_f32* (*getBoundingBox)(), + int (*getMaterialCount)(), + irr_video_SMaterial* (*getMaterial)(unsigned int i)); + irr_scene_IMeshSceneNode* irr_scene_addOctreeSceneNodeAM(irr_scene_ISceneManager* smgr, irr_scene_IAnimatedMesh* mesh, diff --git a/include/SMaterial.h b/include/SMaterial.h new file mode 100644 index 0000000..6004657 --- /dev/null +++ b/include/SMaterial.h @@ -0,0 +1,31 @@ +/* c-irrlicht --- C bindings for Irrlicht Engine + + Copyright (C) 2019 Javier Sancho + + This file is part of c-irrlicht. + + c-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. + + c-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 __C_IRR_S_MATERIAL_H_INCLUDED__ +#define __C_IRR_S_MATERIAL_H_INCLUDED__ + +typedef struct +{ + int wireframe; + int lighting; +} irr_video_SMaterial; + +#endif diff --git a/include/aabbox3d.h b/include/aabbox3d.h new file mode 100644 index 0000000..f31fadb --- /dev/null +++ b/include/aabbox3d.h @@ -0,0 +1,28 @@ +/* c-irrlicht --- C bindings for Irrlicht Engine + + Copyright (C) 2019 Javier Sancho + + This file is part of c-irrlicht. + + c-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. + + c-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 __C_IRR_AABBOX_3D_H_INCLUDED__ +#define __C_IRR_AABBOX_3D_H_INCLUDED__ + +typedef struct{ +} irr_core_aabbox3d_f32; + +#endif diff --git a/include/cirrlicht.h b/include/cirrlicht.h index 48d96f2..f00e28c 100644 --- a/include/cirrlicht.h +++ b/include/cirrlicht.h @@ -22,6 +22,7 @@ #ifndef __C_IRRLICHT_H_INCLUDED__ #define __C_IRRLICHT_H_INCLUDED__ +#include "aabbox3d.h" #include "dimension2d.h" #include "EDriverTypes.h" #include "EMaterialFlags.h" @@ -29,6 +30,7 @@ #include "IAnimatedMeshSceneNode.h" #include "ICameraSceneNode.h" #include "ICursorControl.h" +#include "ICustomSceneNode.h" #include "IFileArchive.h" #include "IFileSystem.h" #include "IGUIEnvironment.h" @@ -45,6 +47,7 @@ #include "SColor.h" #include "SExposedVideoData.h" #include "SKeyMap.h" +#include "SMaterial.h" #include "vector3d.h" #ifdef __cplusplus diff --git a/src/ISceneManager.cpp b/src/ISceneManager.cpp index b682499..905ad49 100644 --- a/src/ISceneManager.cpp +++ b/src/ISceneManager.cpp @@ -22,6 +22,68 @@ #include #include "ISceneManager.h" +class CustomSceneNode : public irr::scene::ISceneNode +{ + void (*Render)(); + irr_core_aabbox3d_f32* (*GetBoundingBox)(); + int (*GetMaterialCount)(); + irr_video_SMaterial* (*GetMaterial)(unsigned int i); + +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, + void (*render)(), + irr_core_aabbox3d_f32* (*getBoundingBox)(), + int (*getMaterialCount)(), + irr_video_SMaterial* (*getMaterial)(unsigned int i)) + : irr::scene::ISceneNode(parent, smgr, id, position, rotation, scale) + { + Render = render; + GetBoundingBox = getBoundingBox; + GetMaterialCount = getMaterialCount; + GetMaterial = getMaterial; + } + + virtual void OnRegisterSceneNode() + { + if (IsVisible) { + SceneManager->registerNodeForRendering(this); + } + + ISceneNode::OnRegisterSceneNode(); + } + + virtual void render() + { + Render(); + } + + virtual const irr::core::aabbox3d& getBoundingBox() const + { + irr_core_aabbox3d_f32* box = GetBoundingBox(); + irr::core::aabbox3d* irrBox = new irr::core::aabbox3d(); + return *irrBox; + } + + virtual irr::u32 getMaterialCount() const + { + return GetMaterialCount(); + } + + virtual irr::video::SMaterial& getMaterial(irr::u32 i) + { + irr_video_SMaterial* material = GetMaterial(i); + irr::video::SMaterial* irrMaterial = new irr::video::SMaterial(); + irrMaterial->Wireframe = material->wireframe; + irrMaterial->Lighting = material->lighting; + return *irrMaterial; + } +}; + extern "C" { irr_scene_IAnimatedMeshSceneNode* irr_scene_addAnimatedMeshSceneNode(irr_scene_ISceneManager* smgr, @@ -112,6 +174,55 @@ extern "C" { makeActive); } + irr_scene_ICustomSceneNode* + irr_scene_addCustomSceneNode(irr_scene_ISceneManager* smgr, + irr_scene_ISceneNode* parent, + int id, + irr_core_vector3df* position, + irr_core_vector3df* rotation, + irr_core_vector3df* scale, + void (*render)(), + irr_core_aabbox3d_f32* (*getBoundingBox)(), + int (*getMaterialCount)(), + irr_video_SMaterial* (*getMaterial)(unsigned int i)) + { + if (parent == NULL) + { + parent = irr_scene_getRootSceneNode(smgr); + } + + const irr::core::vector3df iPosition = + position ? + irr::core::vector3df(position->x, position->y, position->z) : + irr::core::vector3df(0, 0, 0); + + const irr::core::vector3df iRotation = + rotation ? + irr::core::vector3df(rotation->x, rotation->y, rotation->z) : + irr::core::vector3df(0, 0, 0); + + const irr::core::vector3df& iScale = + scale ? + irr::core::vector3df(scale->x, scale->y, scale->z) : + irr::core::vector3df(1, 1, 1); + + CustomSceneNode *node = + new CustomSceneNode((irr::scene::ISceneNode*)parent, + (irr::scene::ISceneManager*)smgr, + id, + iPosition, + iRotation, + iScale, + render, + getBoundingBox, + getMaterialCount, + getMaterial); + node->drop(); + node = 0; + return NULL; + //return node; + } + irr_scene_IMeshSceneNode* irr_scene_addOctreeSceneNodeAM(irr_scene_ISceneManager* smgr, irr_scene_IAnimatedMesh* mesh, -- 2.39.5