Commit 8a9d6361 authored by hybrid's avatar hybrid

Add triangle selector methods to get back single selectors from meta triangle...

Add triangle selector methods to get back single selectors from meta triangle selector. Submitted by LexManos

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3707 dfc29bdd-3216-0410-991c-e03cc46cb475
parent e13d17c2
...@@ -29,10 +29,7 @@ class ITriangleSelector : public virtual IReferenceCounted ...@@ -29,10 +29,7 @@ class ITriangleSelector : public virtual IReferenceCounted
{ {
public: public:
//! Destructor //! Get amount of all available triangles in this selector
virtual ~ITriangleSelector() {}
//! Returns amount of all available triangles in this selector
virtual s32 getTriangleCount() const = 0; virtual s32 getTriangleCount() const = 0;
//! Gets the triangles for one associated node. //! Gets the triangles for one associated node.
...@@ -41,19 +38,19 @@ public: ...@@ -41,19 +38,19 @@ public:
selector. If there is more than one scene node associated (e.g. for selector. If there is more than one scene node associated (e.g. for
an IMetaTriangleSelector) this this function may be called multiple an IMetaTriangleSelector) this this function may be called multiple
times to retrieve all triangles. times to retrieve all triangles.
\param triangles: Array where the resulting triangles will be \param triangles Array where the resulting triangles will be
written to. written to.
\param arraySize: Size of the target array. \param arraySize Size of the target array.
\param outTriangleCount: Amount of triangles which have been written \param outTriangleCount: Amount of triangles which have been written
into the array. into the array.
\param transform: Pointer to matrix for transforming the triangles \param transform Pointer to matrix for transforming the triangles
before they are returned. Useful for example to scale all triangles before they are returned. Useful for example to scale all triangles
down into an ellipsoid space. If this pointer is null, no down into an ellipsoid space. If this pointer is null, no
transformation will be done. */ transformation will be done. */
virtual void getTriangles(core::triangle3df* triangles, s32 arraySize, virtual void getTriangles(core::triangle3df* triangles, s32 arraySize,
s32& outTriangleCount, const core::matrix4* transform=0) const = 0; s32& outTriangleCount, const core::matrix4* transform=0) const = 0;
//! Gets the triangles for one associated node which lie or may lie within a specific bounding box. //! Gets the triangles for one associated node which may lie within a specific bounding box.
/** /**
This returns all triangles for one scene node associated with this This returns all triangles for one scene node associated with this
selector. If there is more than one scene node associated (e.g. for selector. If there is more than one scene node associated (e.g. for
...@@ -62,14 +59,14 @@ public: ...@@ -62,14 +59,14 @@ public:
This method will return at least the triangles that intersect the box, This method will return at least the triangles that intersect the box,
but may return other triangles as well. but may return other triangles as well.
\param triangles: Array where the resulting triangles will be written \param triangles Array where the resulting triangles will be written
to. to.
\param arraySize: Size of the target array. \param arraySize Size of the target array.
\param outTriangleCount: Amount of triangles which have been written \param outTriangleCount Amount of triangles which have been written
into the array. into the array.
\param box: Only triangles which are in this axis aligned bounding box \param box Only triangles which are in this axis aligned bounding box
will be written into the array. will be written into the array.
\param transform: Pointer to matrix for transforming the triangles \param transform Pointer to matrix for transforming the triangles
before they are returned. Useful for example to scale all triangles before they are returned. Useful for example to scale all triangles
down into an ellipsoid space. If this pointer is null, no down into an ellipsoid space. If this pointer is null, no
transformation will be done. */ transformation will be done. */
...@@ -86,14 +83,14 @@ public: ...@@ -86,14 +83,14 @@ public:
Please note that unoptimized triangle selectors also may return Please note that unoptimized triangle selectors also may return
triangles which are not in contact at all with the 3d line. triangles which are not in contact at all with the 3d line.
\param triangles: Array where the resulting triangles will be written \param triangles Array where the resulting triangles will be written
to. to.
\param arraySize: Size of the target array. \param arraySize Size of the target array.
\param outTriangleCount: Amount of triangles which have been written \param outTriangleCount Amount of triangles which have been written
into the array. into the array.
\param line: Only triangles which may be in contact with this 3d line \param line Only triangles which may be in contact with this 3d line
will be written into the array. will be written into the array.
\param transform: Pointer to matrix for transforming the triangles \param transform Pointer to matrix for transforming the triangles
before they are returned. Useful for example to scale all triangles before they are returned. Useful for example to scale all triangles
down into an ellipsoid space. If this pointer is null, no down into an ellipsoid space. If this pointer is null, no
transformation will be done. */ transformation will be done. */
...@@ -101,9 +98,9 @@ public: ...@@ -101,9 +98,9 @@ public:
s32& outTriangleCount, const core::line3d<f32>& line, s32& outTriangleCount, const core::line3d<f32>& line,
const core::matrix4* transform=0) const = 0; const core::matrix4* transform=0) const = 0;
//! Return the scene node associated with a given triangle. //! Get scene node associated with a given triangle.
/** /**
This allows you to find which scene node (potentially of several) is This allows to find which scene node (potentially of several) is
associated with a specific triangle. associated with a specific triangle.
\param triangleIndex: the index of the triangle for which you want to find \param triangleIndex: the index of the triangle for which you want to find
...@@ -112,11 +109,18 @@ public: ...@@ -112,11 +109,18 @@ public:
*/ */
virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const = 0; virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const = 0;
//! Get number of TriangleSelectors that are part of this one
/** Only useful for MetaTriangleSelector, others return 1
*/
virtual const u32 getSelectorCount() const = 0;
//! Get TriangleSelector based on index based on getSelectorCount
/** Only useful for MetaTriangleSelector, others return 'this' or 0
*/
virtual const ITriangleSelector* getSelector(u32 index) const = 0;
}; };
} // end namespace scene } // end namespace scene
} // end namespace irr } // end namespace irr
#endif #endif
...@@ -152,6 +152,26 @@ ISceneNode* CMetaTriangleSelector::getSceneNodeForTriangle(u32 triangleIndex) co ...@@ -152,6 +152,26 @@ ISceneNode* CMetaTriangleSelector::getSceneNodeForTriangle(u32 triangleIndex) co
} }
/* Return the number of TriangleSelectors that are inside this one,
Only useful for MetaTriangleSelector others return 1
*/
const u32 CMetaTriangleSelector::getSelectorCount() const
{
return TriangleSelectors.size();
}
/* Returns the TriangleSelector based on index based on getSelectorCount
Only useful for MetaTriangleSelector others return 'this'
*/
const ITriangleSelector* CMetaTriangleSelector::getSelector(u32 index) const
{
if(index >= TriangleSelectors.size())
return 0;
return TriangleSelectors[index];
}
} // end namespace scene } // end namespace scene
} // end namespace irr } // end namespace irr
...@@ -24,7 +24,7 @@ public: ...@@ -24,7 +24,7 @@ public:
//! destructor //! destructor
virtual ~CMetaTriangleSelector(); virtual ~CMetaTriangleSelector();
//! Returns amount of all available triangles in this selector //! Get amount of all available triangles in this selector
virtual s32 getTriangleCount() const; virtual s32 getTriangleCount() const;
//! Gets all triangles. //! Gets all triangles.
...@@ -51,9 +51,15 @@ public: ...@@ -51,9 +51,15 @@ public:
//! Removes all triangle selectors from the collection. //! Removes all triangle selectors from the collection.
virtual void removeAllTriangleSelectors(); virtual void removeAllTriangleSelectors();
//! Return the scene node associated with a given triangle. //! Get the scene node associated with a given triangle.
virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const; virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const;
// Get the number of TriangleSelectors that are part of this one
virtual const u32 getSelectorCount() const;
// Get the TriangleSelector based on index based on getSelectorCount
virtual const ITriangleSelector* getSelector(u32 index) const;
private: private:
core::array<ITriangleSelector*> TriangleSelectors; core::array<ITriangleSelector*> TriangleSelectors;
......
...@@ -34,11 +34,8 @@ CTerrainTriangleSelector::~CTerrainTriangleSelector() ...@@ -34,11 +34,8 @@ CTerrainTriangleSelector::~CTerrainTriangleSelector()
//! Clears and sets triangle data //! Clears and sets triangle data
void CTerrainTriangleSelector::setTriangleData(ITerrainSceneNode* node, s32 LOD) void CTerrainTriangleSelector::setTriangleData(ITerrainSceneNode* node, s32 LOD)
{ {
core::triangle3df tri;
core::array<u32> indices;
// Get pointer to the GeoMipMaps vertices // Get pointer to the GeoMipMaps vertices
video::S3DVertex2TCoords* vertices = static_cast<video::S3DVertex2TCoords*>(node->getRenderBuffer()->getVertices()); const video::S3DVertex2TCoords* vertices = static_cast<const video::S3DVertex2TCoords*>(node->getRenderBuffer()->getVertices());
// Clear current data // Clear current data
const s32 count = (static_cast<CTerrainSceneNode*>(node))->TerrainData.PatchCount; const s32 count = (static_cast<CTerrainSceneNode*>(node))->TerrainData.PatchCount;
...@@ -49,6 +46,8 @@ void CTerrainTriangleSelector::setTriangleData(ITerrainSceneNode* node, s32 LOD) ...@@ -49,6 +46,8 @@ void CTerrainTriangleSelector::setTriangleData(ITerrainSceneNode* node, s32 LOD)
for (s32 o=0; o<TrianglePatches.NumPatches; ++o) for (s32 o=0; o<TrianglePatches.NumPatches; ++o)
TrianglePatches.TrianglePatchArray.push_back(SGeoMipMapTrianglePatch()); TrianglePatches.TrianglePatchArray.push_back(SGeoMipMapTrianglePatch());
core::triangle3df tri;
core::array<u32> indices;
s32 tIndex = 0; s32 tIndex = 0;
for(s32 x = 0; x < count; ++x ) for(s32 x = 0; x < count; ++x )
{ {
...@@ -74,9 +73,11 @@ void CTerrainTriangleSelector::setTriangleData(ITerrainSceneNode* node, s32 LOD) ...@@ -74,9 +73,11 @@ void CTerrainTriangleSelector::setTriangleData(ITerrainSceneNode* node, s32 LOD)
} }
} }
//! Gets all triangles. //! Gets all triangles.
void CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32 arraySize, void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles,
s32& outTriangleCount, const core::matrix4* transform) const s32 arraySize, s32& outTriangleCount,
const core::matrix4* transform) const
{ {
s32 count = TrianglePatches.TotalTriangles; s32 count = TrianglePatches.TotalTriangles;
...@@ -110,9 +111,9 @@ void CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32 ...@@ -110,9 +111,9 @@ void CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32
//! Gets all triangles which lie within a specific bounding box. //! Gets all triangles which lie within a specific bounding box.
void CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32 arraySize, void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles,
s32& outTriangleCount, const core::aabbox3d<f32>& box, s32 arraySize, s32& outTriangleCount,
const core::matrix4* transform) const const core::aabbox3d<f32>& box, const core::matrix4* transform) const
{ {
s32 count = TrianglePatches.TotalTriangles; s32 count = TrianglePatches.TotalTriangles;
...@@ -145,10 +146,11 @@ void CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32 ...@@ -145,10 +146,11 @@ void CTerrainTriangleSelector::getTriangles ( core::triangle3df* triangles, s32
outTriangleCount = tIndex; outTriangleCount = tIndex;
} }
//! Gets all triangles which have or may have contact with a 3d line. //! Gets all triangles which have or may have contact with a 3d line.
void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles, s32 arraySize, void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles,
s32& outTriangleCount, const core::line3d<f32>& line, s32 arraySize, s32& outTriangleCount, const core::line3d<f32>& line,
const core::matrix4* transform) const const core::matrix4* transform) const
{ {
const s32 count = core::min_((s32)TrianglePatches.TotalTriangles, arraySize); const s32 count = core::min_((s32)TrianglePatches.TotalTriangles, arraySize);
...@@ -180,17 +182,41 @@ void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles, s32 ar ...@@ -180,17 +182,41 @@ void CTerrainTriangleSelector::getTriangles(core::triangle3df* triangles, s32 ar
outTriangleCount = tIndex; outTriangleCount = tIndex;
} }
//! Returns amount of all available triangles in this selector //! Returns amount of all available triangles in this selector
s32 CTerrainTriangleSelector::getTriangleCount() const s32 CTerrainTriangleSelector::getTriangleCount() const
{ {
return TrianglePatches.TotalTriangles; return TrianglePatches.TotalTriangles;
} }
ISceneNode* CTerrainTriangleSelector::getSceneNodeForTriangle(u32 triangleIndex) const
ISceneNode* CTerrainTriangleSelector::getSceneNodeForTriangle(
u32 triangleIndex) const
{ {
return SceneNode; return SceneNode;
} }
/* Get the number of TriangleSelectors that are part of this one.
Only useful for MetaTriangleSelector others return 1
*/
const u32 CTerrainTriangleSelector::getSelectorCount() const
{
return 1;
}
/* Get the TriangleSelector based on index based on getSelectorCount.
Only useful for MetaTriangleSelector others return 'this' or 0
*/
const ITriangleSelector* CTerrainTriangleSelector::getSelector(u32 index) const
{
if (index)
return 0;
else
return this;
}
} // end namespace scene } // end namespace scene
} // end namespace irr } // end namespace irr
...@@ -20,14 +20,16 @@ namespace scene ...@@ -20,14 +20,16 @@ namespace scene
class ITerrainSceneNode; class ITerrainSceneNode;
//! Triangle Selector for the TerrainSceneNode //! Triangle Selector for the TerrainSceneNode
//! The code for the TerrainTriangleSelector is based on the GeoMipMapSelector /** The code for the TerrainTriangleSelector is based on the GeoMipMapSelector
//! developed by Spintz. He made it available for Irrlicht and allowed it to be developed by Spintz. He made it available for Irrlicht and allowed it to be
//! distributed under this licence. I only modified some parts. A lot of thanks go to him. distributed under this licence. I only modified some parts. A lot of thanks go
to him.
*/
class CTerrainTriangleSelector : public ITriangleSelector class CTerrainTriangleSelector : public ITriangleSelector
{ {
public: public:
//! Constructs a selector based on an IGeoMipMapSceneNode //! Constructs a selector based on an ITerrainSceneNode
CTerrainTriangleSelector(ITerrainSceneNode* node, s32 LOD); CTerrainTriangleSelector(ITerrainSceneNode* node, s32 LOD);
//! Destructor //! Destructor
...@@ -55,15 +57,21 @@ public: ...@@ -55,15 +57,21 @@ public:
//! Return the scene node associated with a given triangle. //! Return the scene node associated with a given triangle.
virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const; virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const;
// Get the number of TriangleSelectors that are part of this one
virtual const u32 getSelectorCount() const;
// Get the TriangleSelector based on index based on getSelectorCount
virtual const ITriangleSelector* getSelector(u32 index) const;
private: private:
friend class CTerrainSceneNode; friend class CTerrainSceneNode;
struct SGeoMipMapTrianglePatch struct SGeoMipMapTrianglePatch
{ {
core::array<core::triangle3df> Triangles; core::array<core::triangle3df> Triangles;
s32 NumTriangles; s32 NumTriangles;
core::aabbox3df Box; core::aabbox3df Box;
}; };
struct SGeoMipMapTrianglePatches struct SGeoMipMapTrianglePatches
...@@ -73,13 +81,13 @@ private: ...@@ -73,13 +81,13 @@ private:
{ {
} }
core::array<SGeoMipMapTrianglePatch> TrianglePatchArray; core::array<SGeoMipMapTrianglePatch> TrianglePatchArray;
s32 NumPatches; s32 NumPatches;
u32 TotalTriangles; u32 TotalTriangles;
}; };
ITerrainSceneNode* SceneNode; ITerrainSceneNode* SceneNode;
SGeoMipMapTrianglePatches TrianglePatches; SGeoMipMapTrianglePatches TrianglePatches;
}; };
} // end namespace scene } // end namespace scene
...@@ -87,4 +95,3 @@ private: ...@@ -87,4 +95,3 @@ private:
#endif // __C_TERRAIN_TRIANGLE_SELECTOR_H__ #endif // __C_TERRAIN_TRIANGLE_SELECTOR_H__
...@@ -231,6 +231,26 @@ s32 CTriangleSelector::getTriangleCount() const ...@@ -231,6 +231,26 @@ s32 CTriangleSelector::getTriangleCount() const
} }
/* Get the number of TriangleSelectors that are part of this one.
Only useful for MetaTriangleSelector others return 1
*/
const u32 CTriangleSelector::getSelectorCount() const
{
return 1;
}
/* Get the TriangleSelector based on index based on getSelectorCount.
Only useful for MetaTriangleSelector others return 'this' or 0
*/
const ITriangleSelector* CTriangleSelector::getSelector(u32 index) const
{
if (index)
return 0;
else
return this;
}
} // end namespace scene } // end namespace scene
} // end namespace irr } // end namespace irr
......
...@@ -54,6 +54,12 @@ public: ...@@ -54,6 +54,12 @@ public:
//! Return the scene node associated with a given triangle. //! Return the scene node associated with a given triangle.
virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const { return SceneNode; } virtual ISceneNode* getSceneNodeForTriangle(u32 triangleIndex) const { return SceneNode; }
// Get the number of TriangleSelectors that are part of this one
virtual const u32 getSelectorCount() const;
// Get the TriangleSelector based on index based on getSelectorCount
virtual const ITriangleSelector* getSelector(u32 index) const;
protected: protected:
//! Create from a mesh //! Create from a mesh
virtual void createFromMesh(const IMesh* mesh); virtual void createFromMesh(const IMesh* mesh);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment