Add ability to exclude SubMesh from EdgeList

What it says on the tin: a place to discuss proposed new features.
Post Reply
User avatar
DimA
Halfling
Posts: 59
Joined: Tue Jan 10, 2006 12:52 pm
Location: Ukraine
x 6
Contact:

Add ability to exclude SubMesh from EdgeList

Post by DimA »

Hi,

I think it would be very useful to add 'mBuildEdgesEnabled' flag into the SubMesh. This feature will allow us to include or exclude SubMesh from EdgeList during generation in the 'void Mesh::buildEdgeList(void)' method.
See the code bellow how it might be done:

OgreSubMesh.h:

Code: Select all

    class _OgreExport SubMesh
    {
.....................

		bool isBuildEdgesEnabled(void) const { return mBuildEdgesEnabled; }
		void setBuildEdgesEnabled(bool b);
		
    protected:

		/// Is Build Edges Enabled
		bool mBuildEdgesEnabled;
......................
    }; 
OgreSubMesh.cpp:

Code: Select all

	void SubMesh::setBuildEdgesEnabled(bool b)
	{
		mBuildEdgesEnabled = b;
		if(parent)
		{
			parent->freeEdgeList();
			parent->setAutoBuildEdgeLists(true);
		}
	}
OgreMesh.cpp:

Code: Select all

    void Mesh::buildEdgeList(void)
    {
....................

                // Prepare the builder using the submesh information
                SubMeshList::iterator i, iend;
                iend = mSubMeshList.end();
                for (i = mSubMeshList.begin(); i != iend; ++i)
                {
                    SubMesh* s = *i;
					if (s->operationType != RenderOperation::OT_TRIANGLE_FAN && 
						s->operationType != RenderOperation::OT_TRIANGLE_LIST && 
						s->operationType != RenderOperation::OT_TRIANGLE_STRIP)
					{
						// Skip this submesh
						continue;
					}
                    if (s->useSharedVertices)
                    {
                        // Use shared vertex data, index as set 0
                        if (lodIndex == 0)
                        {
                            eb.addIndexData(s->indexData, 0, s->operationType);
                        }
                        else
                        {
                            eb.addIndexData(s->mLodFaceList[lodIndex-1], 0,
                                s->operationType);
                        }
                    }
                    else  if(s->isBuildEdgesEnabled()) //can include/exclude for non shared vertices only
                    {
                        // own vertex data, add it and reference it directly
                        eb.addVertexData(s->vertexData);
                        if (lodIndex == 0)
                        {
                            // Base index data
                            eb.addIndexData(s->indexData, vertexSetCount++,
                                s->operationType);
                        }
                        else
                        {
                            // LOD index data
                            eb.addIndexData(s->mLodFaceList[lodIndex-1],
                                vertexSetCount++, s->operationType);
                        }

                    }
					atLeastOneIndexSet = true;
                }

....................
    }
So, now we can exclude, for example, submeshes with glass material in windows or other objects and get really nice stencil shadows :)
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Patches welcome :)
User avatar
DimA
Halfling
Posts: 59
Joined: Tue Jan 10, 2006 12:52 pm
Location: Ukraine
x 6
Contact:

Post by DimA »

Ok, here it is:

Code: Select all

Index: OgreMain/include/OgreSubMesh.h
===================================================================
RCS file: /cvsroot/ogre/ogrenew/OgreMain/include/OgreSubMesh.h,v
retrieving revision 1.27
diff -u -r1.27 OgreSubMesh.h
--- OgreMain/include/OgreSubMesh.h	3 Jan 2007 18:23:59 -0000	1.27
+++ OgreMain/include/OgreSubMesh.h	15 Aug 2007 14:54:20 -0000
@@ -234,6 +234,11 @@
         */
         void generateExtremes(size_t count);
 
+		/** Returns true(by default) if the submesh should be included in the mesh EdgeList, otherwise returns false.
+        */		
+		bool isBuildEdgesEnabled(void) const { return mBuildEdgesEnabled; }
+		void setBuildEdgesEnabled(bool b);
+
     protected:
 
         /// Name of the material this SubMesh uses.
@@ -253,12 +258,13 @@
 		/// Type of vertex animation for dedicated vertex data (populated by Mesh)
 		mutable VertexAnimationType mVertexAnimationType;
 
+		/// Is Build Edges Enabled
+		bool mBuildEdgesEnabled;
 
         /// Internal method for removing LOD data
         void removeLodLevels(void);
 
 
-
     };
 
 } // namespace
Index: OgreMain/src/OgreMesh.cpp
===================================================================
RCS file: /cvsroot/ogre/ogrenew/OgreMain/src/OgreMesh.cpp,v
retrieving revision 1.129.2.1
diff -u -r1.129.2.1 OgreMesh.cpp
--- OgreMain/src/OgreMesh.cpp	28 Apr 2007 15:04:06 -0000	1.129.2.1
+++ OgreMain/src/OgreMesh.cpp	15 Aug 2007 14:54:22 -0000
@@ -1583,7 +1583,7 @@
                                 s->operationType);
                         }
                     }
-                    else
+                    else if(s->isBuildEdgesEnabled())
                     {
                         // own vertex data, add it and reference it directly
                         eb.addVertexData(s->vertexData);
Index: OgreMain/src/OgreSubMesh.cpp
===================================================================
RCS file: /cvsroot/ogre/ogrenew/OgreMain/src/OgreSubMesh.cpp,v
retrieving revision 1.39
diff -u -r1.39 OgreSubMesh.cpp
--- OgreMain/src/OgreSubMesh.cpp	15 Jan 2007 13:00:35 -0000	1.39
+++ OgreMain/src/OgreSubMesh.cpp	15 Aug 2007 14:54:22 -0000
@@ -44,6 +44,7 @@
         , mMatInitialised(false)
         , mBoneAssignmentsOutOfDate(false)
 		, mVertexAnimationType(VAT_NONE)
+		, mBuildEdgesEnabled(true)
     {
 		indexData = new IndexData();
     }
@@ -410,5 +411,15 @@
         vbuf->unlock ();
         indexData->indexBuffer->unlock ();
     }
+	 //---------------------------------------------------------------------
+	void SubMesh::setBuildEdgesEnabled(bool b)
+	{
+		mBuildEdgesEnabled = b;
+		if(parent)
+		{
+			parent->freeEdgeList();
+			parent->setAutoBuildEdgeLists(true);
+		}
+	}
 }
 
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Sorry, here is the patch submission procedure

We need the contributor license agreement and patches will just get buried here on the forum.
User avatar
DimA
Halfling
Posts: 59
Joined: Tue Jan 10, 2006 12:52 pm
Location: Ukraine
x 6
Contact:

Post by DimA »

Ok, I've just submited by e-mail the contributor license agreement. I'll follow through the procedure...
User avatar
DimA
Halfling
Posts: 59
Joined: Tue Jan 10, 2006 12:52 pm
Location: Ukraine
x 6
Contact:

Post by DimA »

I've done patch submission.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Thanks.
Post Reply