Static Geometry LOD Mesh Problem

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
User avatar
Marc
Gremlin
Posts: 182
Joined: Tue Jan 25, 2005 7:56 am
Location: Germany

Static Geometry LOD Mesh Problem

Post by Marc »

Hi !

I have a problem building a static geometery consisting of meshes with LOD. I have a scene with about 1000 objects inside, each
a different mesh. Each mesh has about 1000 triangles. They all only have 1 submesh and all use the same material.
When I create the .mesh-files from the .mesh.xml-files without generation of LOD, I can load and bake them
in a StaticGeometry without any problems. When I create LOD with "-l 2 -d 50 -p 50" or "-l 5 -d 50 -p 50", I get an Access Violation
in StaticGeometry::build() :

Code: Select all

>	msvcr71d.dll!memcpy(unsigned char * dst=0x02a24878, unsigned char * src=0x0274fff8, unsigned long count=12)  Line 305	Asm
 	OgreMain_d.dll!Ogre::StaticGeometry::GeometryBucket::build(bool stencilShadows=false)  Line 1541 + 0x28	C++
 	OgreMain_d.dll!Ogre::StaticGeometry::MaterialBucket::build(bool stencilShadows=false)  Line 1198	C++
 	OgreMain_d.dll!Ogre::StaticGeometry::LODBucket::build(bool stencilShadows=false)  Line 1094	C++
 	OgreMain_d.dll!Ogre::StaticGeometry::Region::build(bool stencilShadows=false)  Line 713	C++
 	OgreMain_d.dll!Ogre::StaticGeometry::build()  Line 535	C++
 	TestApp.exe!Visualization::CreateStaticGeomFromSceneFile(char * filename=0x0044d21c)  Line 266 + 0xd	C++
 	TestApp.exe!Visualization::Init()  Line 173	C++
 	TestApp.exe!Application::go()  Line 19	C++
 	TestApp.exe!main(int argc=1, char * * argv=0x00cc1ee0)  Line 26	C++
 	TestApp.exe!mainCRTStartup()  Line 259 + 0x19	C
 	kernel32.dll!7c816d4f() 	
 	kernel32.dll!7c8399f3() 	
However, if I only load 8 of the LOD meshes, it works, but already 16 is too much. I didn't try to figure out the magic number exactly.

First I thought that it is some vertexbuffer overflow problem, I experienced these before, but in a scene with even more objects in it. But in this case, it already doesn't work for 2 LOD levels of 16 objects while it works for 1000 objects with no LOD.

I'm not using latest CVS but 1.0 with the Zero-Volume-StaticGeometry-Patch applied.

Here is the code I use to create the Static Geometry from a .scene file

Code: Select all

bool CreateStaticGeomFromSceneFile(char *filename)
{
	// only supports flat hierarchy for now, and lights get ignored
	const float scale=1.0f;

	TiXmlDocument doc(filename);
	if (!doc.LoadFile())
	{
		return false;
	}

	StaticGeometry* s = mSceneMgr->createStaticGeometry("bing");
	s->setRegionDimensions(Vector3(16,16,1024));
	// Set the region origin so the centre is at 0 world
	s->setOrigin(Vector3(-500, 500, -50));

	TiXmlElement *scene,*nodes,*node,*entity,*light,*elem;
	scene=doc.FirstChildElement("scene");

	// body
	nodes=scene->FirstChildElement("nodes");

	// nodes
	node=nodes->FirstChildElement();
	unsigned int i=0;
	while (node!=0)
	{
		if (strcmp(node->Value(),"node")==0)
		{
			char nodename[1024],entityname[1024],meshfile[1024],materialfile[1024];
			int nodeid,entityid;
			double x,y,z, qx,qy,qz,qw, sx,sy,sz;

			strcpy(nodename,node->Attribute("name"));
			node->QueryIntAttribute("id",&nodeid);

			elem=node->FirstChildElement("position");
			elem->QueryDoubleAttribute("x",&x);
			elem->QueryDoubleAttribute("y",&y);
			elem->QueryDoubleAttribute("z",&z);

			elem=node->FirstChildElement("rotation");
			elem->QueryDoubleAttribute("qx",&qx);
			elem->QueryDoubleAttribute("qy",&qy);
			elem->QueryDoubleAttribute("qz",&qz);
			elem->QueryDoubleAttribute("qw",&qw);

			elem=node->FirstChildElement("scale");
			elem->QueryDoubleAttribute("x",&sx);
			elem->QueryDoubleAttribute("y",&sy);
			elem->QueryDoubleAttribute("z",&sz);

			
			entity=node->FirstChildElement("entity");
			if (entity!=0)
			{
				strcpy(entityname,entity->Attribute("name"));
				entity->QueryIntAttribute("id",&entityid);
				strcpy(meshfile,entity->Attribute("meshFile"));
				strcpy(materialfile,entity->Attribute("materialFile"));

				char t[1024];

				// add that mesh to the static geom
				sprintf(t,"%s_%u",entityname,i);
				i++;
				Entity *ent=mSceneMgr->createEntity(t, meshfile);
				s->addEntity(ent,Vector3(x*scale,y*scale,z*scale),Quaternion(qw,qx,qy,qz),Vector3(sx*scale,sy*scale,sz*scale));
			}
		}


		node=node->NextSiblingElement();
	}

	s->build();
	return 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

Post by sinbad »

Are you using the 1.0 Final, not the RC1? A LOD overrun problem was fixed in between 1.0 RC1 and 1.0 Final, and I've had no problems since with LODed meshes.
User avatar
Marc
Gremlin
Posts: 182
Joined: Tue Jan 25, 2005 7:56 am
Location: Germany

Post by Marc »

1.0 RC1, so that could be the reason. I'll try upgrading then.

[edit]Yes, it worked with 1.0 Final (and after applying the zero volume fix).[/edit]