Derive COctTreeSceneNode from IMeshSceneNode instead ISceneNode, and have it return the IMesh that was used to create its octtree.  Tested with a slightly modified example 07.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2173 dfc29bdd-3216-0410-991c-e03cc46cb475
master
Rogerborg 2009-01-31 15:58:43 +00:00
parent 0e00187fdd
commit bd192519d6
8 changed files with 59 additions and 17 deletions

View File

@ -463,6 +463,8 @@ Changes in version 1.6, TA
Changes in version 1.6 Changes in version 1.6
- Octtree scene nodes are now IMeshSceneNodes rather than ISceneNodes, and so you can call getMesh() on them.
- New scene parameter B3D_LOADER_IGNORE_MIPMAP_FLAG to ignore the often missing mipmap flag in b3d files. If this parameter is true, the old pre Irrlicht-1.5 behavior is restored. - New scene parameter B3D_LOADER_IGNORE_MIPMAP_FLAG to ignore the often missing mipmap flag in b3d files. If this parameter is true, the old pre Irrlicht-1.5 behavior is restored.
- Added Mipmap LOD Bias attribute to MaterialLayer. - Added Mipmap LOD Bias attribute to MaterialLayer.

View File

@ -59,7 +59,7 @@ int main()
device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3"); device->getFileSystem()->addZipFileArchive("../../media/map-20kdm2.pk3");
scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp"); scene::IAnimatedMesh* q3levelmesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* q3node = 0; scene::IMeshSceneNode* q3node = 0;
if (q3levelmesh) if (q3levelmesh)
q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0)); q3node = smgr->addOctTreeSceneNode(q3levelmesh->getMesh(0));
@ -88,7 +88,7 @@ int main()
q3node->setPosition(core::vector3df(-1350,-130,-1400)); q3node->setPosition(core::vector3df(-1350,-130,-1400));
selector = smgr->createOctTreeTriangleSelector( selector = smgr->createOctTreeTriangleSelector(
q3levelmesh->getMesh(0), q3node, 128); q3node->getMesh(), q3node, 128);
q3node->setTriangleSelector(selector); q3node->setTriangleSelector(selector);
} }

View File

@ -24,9 +24,9 @@ public:
/** Use setMesh() to set the mesh to display. /** Use setMesh() to set the mesh to display.
*/ */
IMeshSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id, IMeshSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation, const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale) const core::vector3df& scale = core::vector3df(1,1,1))
: ISceneNode(parent, mgr, id, position, rotation, scale) {} : ISceneNode(parent, mgr, id, position, rotation, scale) {}
//! Sets a new mesh to display //! Sets a new mesh to display

View File

@ -496,7 +496,7 @@ namespace scene
\param alsoAddIfMeshPointerZero: Add the scene node even if a 0 pointer is passed. \param alsoAddIfMeshPointerZero: Add the scene node even if a 0 pointer is passed.
\return Pointer to the OctTree if successful, otherwise 0. \return Pointer to the OctTree if successful, otherwise 0.
This pointer should not be dropped. See IReferenceCounted::drop() for more information. */ This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
virtual ISceneNode* addOctTreeSceneNode(IAnimatedMesh* mesh, ISceneNode* parent=0, virtual IMeshSceneNode* addOctTreeSceneNode(IAnimatedMesh* mesh, ISceneNode* parent=0,
s32 id=-1, s32 minimalPolysPerNode=512, bool alsoAddIfMeshPointerZero=false) = 0; s32 id=-1, s32 minimalPolysPerNode=512, bool alsoAddIfMeshPointerZero=false) = 0;
//! Adds a scene node for rendering using a octtree to the scene graph. //! Adds a scene node for rendering using a octtree to the scene graph.
@ -512,7 +512,7 @@ namespace scene
\param alsoAddIfMeshPointerZero: Add the scene node even if a 0 pointer is passed. \param alsoAddIfMeshPointerZero: Add the scene node even if a 0 pointer is passed.
\return Pointer to the octtree if successful, otherwise 0. \return Pointer to the octtree if successful, otherwise 0.
This pointer should not be dropped. See IReferenceCounted::drop() for more information. */ This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
virtual ISceneNode* addOctTreeSceneNode(IMesh* mesh, ISceneNode* parent=0, virtual IMeshSceneNode* addOctTreeSceneNode(IMesh* mesh, ISceneNode* parent=0,
s32 id=-1, s32 minimalPolysPerNode=256, bool alsoAddIfMeshPointerZero=false) = 0; s32 id=-1, s32 minimalPolysPerNode=256, bool alsoAddIfMeshPointerZero=false) = 0;
//! Adds a camera scene node to the scene graph and sets it as active camera. //! Adds a camera scene node to the scene graph and sets it as active camera.

View File

@ -22,8 +22,8 @@ namespace scene
//! constructor //! constructor
COctTreeSceneNode::COctTreeSceneNode(ISceneNode* parent, ISceneManager* mgr, COctTreeSceneNode::COctTreeSceneNode(ISceneNode* parent, ISceneManager* mgr,
s32 id, s32 minimalPolysPerNode) s32 id, s32 minimalPolysPerNode)
: ISceneNode(parent, mgr, id), StdOctTree(0), LightMapOctTree(0), TangentsOctTree(0), : IMeshSceneNode(parent, mgr, id), StdOctTree(0), LightMapOctTree(0), TangentsOctTree(0),
MinimalPolysPerNode(minimalPolysPerNode) MinimalPolysPerNode(minimalPolysPerNode), Mesh(0)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("COctTreeSceneNode"); setDebugName("COctTreeSceneNode");
@ -279,6 +279,9 @@ bool COctTreeSceneNode::createTree(IMesh* mesh)
deleteTree(); deleteTree();
Mesh = mesh;
Mesh->grab();
u32 beginTime = os::Timer::getRealTime(); u32 beginTime = os::Timer::getRealTime();
u32 nodeCount = 0; u32 nodeCount = 0;
@ -486,8 +489,32 @@ void COctTreeSceneNode::deleteTree()
TangentsMeshes.clear(); TangentsMeshes.clear();
Materials.clear(); Materials.clear();
if(Mesh)
Mesh->drop();
} }
void COctTreeSceneNode::setMesh(IMesh* mesh)
{
createTree(mesh);
}
IMesh* COctTreeSceneNode::getMesh(void)
{
return Mesh;
}
void COctTreeSceneNode::setReadOnlyMaterials(bool readonly)
{
// Do nothing
}
bool COctTreeSceneNode::isReadOnlyMaterials() const
{
return false;
}
} // end namespace scene } // end namespace scene
} // end namespace irr } // end namespace irr

View File

@ -5,8 +5,7 @@
#ifndef __C_OCT_TREE_SCENE_NODE_H_INCLUDED__ #ifndef __C_OCT_TREE_SCENE_NODE_H_INCLUDED__
#define __C_OCT_TREE_SCENE_NODE_H_INCLUDED__ #define __C_OCT_TREE_SCENE_NODE_H_INCLUDED__
#include "ISceneNode.h" #include "IMeshSceneNode.h"
#include "IMesh.h"
#include "OctTree.h" #include "OctTree.h"
namespace irr namespace irr
@ -14,7 +13,7 @@ namespace irr
namespace scene namespace scene
{ {
//! implementation of the IBspTreeSceneNode //! implementation of the IBspTreeSceneNode
class COctTreeSceneNode : public ISceneNode class COctTreeSceneNode : public IMeshSceneNode
{ {
public: public:
@ -55,6 +54,18 @@ namespace scene
//! Returns type of the scene node //! Returns type of the scene node
virtual ESCENE_NODE_TYPE getType() const { return ESNT_OCT_TREE; } virtual ESCENE_NODE_TYPE getType() const { return ESNT_OCT_TREE; }
//! Sets a new mesh to display
virtual void setMesh(IMesh* mesh);
//! Get the currently defined mesh for display.
virtual IMesh* getMesh(void);
//! Sets if the scene node should not copy the materials of the mesh but use them in a read only style.
virtual void setReadOnlyMaterials(bool readonly);
//! Check if the scene node should not copy the materials of the mesh but use them in a read only style
virtual bool isReadOnlyMaterials() const;
private: private:
void deleteTree(); void deleteTree();
@ -76,6 +87,8 @@ namespace scene
core::stringc MeshName; core::stringc MeshName;
s32 MinimalPolysPerNode; s32 MinimalPolysPerNode;
s32 PassCount; s32 PassCount;
IMesh * Mesh;
}; };
} // end namespace scene } // end namespace scene

View File

@ -589,7 +589,7 @@ IAnimatedMeshSceneNode* CSceneManager::addAnimatedMeshSceneNode(IAnimatedMesh* m
//! Adds a scene node for rendering using a octtree to the scene graph. This a good method for rendering //! Adds a scene node for rendering using a octtree to the scene graph. This a good method for rendering
//! scenes with lots of geometry. The Octree is built on the fly from the mesh, much //! scenes with lots of geometry. The Octree is built on the fly from the mesh, much
//! faster then a bsp tree. //! faster then a bsp tree.
ISceneNode* CSceneManager::addOctTreeSceneNode(IAnimatedMesh* mesh, ISceneNode* parent, IMeshSceneNode* CSceneManager::addOctTreeSceneNode(IAnimatedMesh* mesh, ISceneNode* parent,
s32 id, s32 minimalPolysPerNode, bool alsoAddIfMeshPointerZero) s32 id, s32 minimalPolysPerNode, bool alsoAddIfMeshPointerZero)
{ {
if (!alsoAddIfMeshPointerZero && (!mesh || !mesh->getFrameCount())) if (!alsoAddIfMeshPointerZero && (!mesh || !mesh->getFrameCount()))
@ -601,10 +601,10 @@ ISceneNode* CSceneManager::addOctTreeSceneNode(IAnimatedMesh* mesh, ISceneNode*
} }
//! Adss a scene node for rendering using a octtree. This a good method for rendering //! Adds a scene node for rendering using a octtree. This a good method for rendering
//! scenes with lots of geometry. The Octree is built on the fly from the mesh, much //! scenes with lots of geometry. The Octree is built on the fly from the mesh, much
//! faster then a bsp tree. //! faster then a bsp tree.
ISceneNode* CSceneManager::addOctTreeSceneNode(IMesh* mesh, ISceneNode* parent, IMeshSceneNode* CSceneManager::addOctTreeSceneNode(IMesh* mesh, ISceneNode* parent,
s32 id, s32 minimalPolysPerNode, bool alsoAddIfMeshPointerZero) s32 id, s32 minimalPolysPerNode, bool alsoAddIfMeshPointerZero)
{ {
if (!alsoAddIfMeshPointerZero && !mesh) if (!alsoAddIfMeshPointerZero && !mesh)

View File

@ -111,13 +111,13 @@ namespace scene
//! Adds a scene node for rendering using a octtree to the scene graph. This a good method for rendering //! Adds a scene node for rendering using a octtree to the scene graph. This a good method for rendering
//! scenes with lots of geometry. The Octree is built on the fly from the mesh, much //! scenes with lots of geometry. The Octree is built on the fly from the mesh, much
//! faster then a bsp tree. //! faster then a bsp tree.
virtual ISceneNode* addOctTreeSceneNode(IAnimatedMesh* mesh, ISceneNode* parent=0, virtual IMeshSceneNode* addOctTreeSceneNode(IAnimatedMesh* mesh, ISceneNode* parent=0,
s32 id=-1, s32 minimalPolysPerNode=512, bool alsoAddIfMeshPointerZero=false); s32 id=-1, s32 minimalPolysPerNode=512, bool alsoAddIfMeshPointerZero=false);
//! Adss a scene node for rendering using a octtree. This a good method for rendering //! Adss a scene node for rendering using a octtree. This a good method for rendering
//! scenes with lots of geometry. The Octree is built on the fly from the mesh, much //! scenes with lots of geometry. The Octree is built on the fly from the mesh, much
//! faster then a bsp tree. //! faster then a bsp tree.
virtual ISceneNode* addOctTreeSceneNode(IMesh* mesh, ISceneNode* parent=0, virtual IMeshSceneNode* addOctTreeSceneNode(IMesh* mesh, ISceneNode* parent=0,
s32 id=-1, s32 minimalPolysPerNode=128, bool alsoAddIfMeshPointerZero=false); s32 id=-1, s32 minimalPolysPerNode=128, bool alsoAddIfMeshPointerZero=false);
//! Adds a camera scene node to the tree and sets it as active camera. //! Adds a camera scene node to the tree and sets it as active camera.