Access to triangle data in Irrlicht.NET

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
buhatkj
Posts: 444
Joined: Fri Dec 12, 2003 4:53 am
Contact:

Access to triangle data in Irrlicht.NET

Post by buhatkj »

So, I am trying to write a quick function to give us access to raw triangle data from an IMesh object in Irrlicht.NET
Here is my code so far for this function:

Code: Select all

System::Collections::ArrayList* IMesh::get_Triangles(){
		irr::scene::IMesh* tmp;
		
		System::Collections::ArrayList* triangles = new System::Collections::ArrayList();
		tmp = get_NativeMesh();
        //hahahah
		int cMeshBuffer, j;
		int v1i, v2i, v3i;
		irr::scene::IMeshBuffer *mb;
		float vArray[9]; // vertex array (3*3 floats)
		int tmpCount = 0;
		for (cMeshBuffer=0; cMeshBuffer < tmp->getMeshBufferCount(); cMeshBuffer++){	
			mb = tmp->getMeshBuffer(cMeshBuffer);
			irr::video::S3DVertex* mb_vertices = (irr::video::S3DVertex*)mb->getVertices();
			irr::u16* mb_indices  = mb->getIndices();
			// add each triangle from the mesh
			for (j=0; j<mb->getIndexCount(); j+=3){
				v1i = mb_indices[j];
				v2i = mb_indices[j+1];
				v3i = mb_indices[j+2];
			
				Irrlicht::Core::Vector3D a;
				Irrlicht::Core::Vector3D b;
				Irrlicht::Core::Vector3D c;
				
				a.X = mb_vertices[v1i].Pos.X;
				a.Y = mb_vertices[v1i].Pos.Y;
				a.Z = mb_vertices[v1i].Pos.Z;
				b.X = mb_vertices[v2i].Pos.X;
				b.Y = mb_vertices[v2i].Pos.Y;
				b.Z = mb_vertices[v2i].Pos.Z;
				c.X = mb_vertices[v3i].Pos.X;
				c.Y = mb_vertices[v3i].Pos.Y;
				c.Z = mb_vertices[v3i].Pos.Z;
				
				Irrlicht::Core::Triangle3D* t;
				t->Set(a,b,c);
				
				(*triangles).Add(t);
			}
		}
        return triangles;
	}
Unfortunately, this doesn't quite work. What I was trying to do was adapt the meshbuffer crawling routine from Mercior's Newton physics tutorial to instead give me a .NET ArrayList of Irrlicht.NET Triangle objects. Seems like a good idea eh? but I'm getting a compile error:

Code: Select all

c:\Documents and Settings\tkoenig\Desktop\Code\irrlicht-1.0\source\Irrlicht.NET\IMesh.cpp(92): error C2664: 'System::Collections::ArrayList::Add' : cannot convert parameter 1 from 'Irrlicht::Core::Triangle3D __gc *' to 'System::Object __gc *'
Which as I read it is telling me that the Irrlicht .NET Triangle type is not a valid .NET object.

Any suggestions? Is this something other folks want to do also? The reason I want to do it is so I can try to implement some sort of physics library binding with Irrlicht.NET, maybe using the ODE.NET DLL from TAO.

Thanks!
My irrlicht-based projects have gone underground for now, but if you want, check out my webcomic instead! http://brokenboomerang.net
DeusXL
Posts: 114
Joined: Sun Mar 14, 2004 9:37 am
Contact:

Post by DeusXL »

I'm not very familiar with C++ managed but a correct function should be like that (don't know if it can work but you can still try :roll:)

Code: Select all

Core::Triangle3D IMesh::get_Triangles()[]
	{
      irr::scene::IMesh* tmp;      
      tmp = get_NativeMesh();
	  Core::Triangle3D triangles[] = new Core::Triangle3D[tmp->getMeshBufferCount()];
        //hahahah
      int cMeshBuffer, j;
      int v1i, v2i, v3i;
      irr::scene::IMeshBuffer *mb;
      int tmpCount = 0;
      for (cMeshBuffer=0; cMeshBuffer < tmp->getMeshBufferCount(); cMeshBuffer++)
	  {   
         mb = tmp->getMeshBuffer(cMeshBuffer);
         irr::video::S3DVertex* mb_vertices = (irr::video::S3DVertex*)mb->getVertices();
         irr::u16* mb_indices  = mb->getIndices();
         // add each triangle from the mesh
         for (j=0; j<mb->getIndexCount(); j+=3){
            v1i = mb_indices[j];
            v2i = mb_indices[j+1];
            v3i = mb_indices[j+2];
         
            Irrlicht::Core::Vector3D a;
            Irrlicht::Core::Vector3D b;
            Irrlicht::Core::Vector3D c;
            
            a.X = mb_vertices[v1i].Pos.X;
            a.Y = mb_vertices[v1i].Pos.Y;
            a.Z = mb_vertices[v1i].Pos.Z;
            b.X = mb_vertices[v2i].Pos.X;
            b.Y = mb_vertices[v2i].Pos.Y;
            b.Z = mb_vertices[v2i].Pos.Z;
            c.X = mb_vertices[v3i].Pos.X;
            c.Y = mb_vertices[v3i].Pos.Y;
            c.Z = mb_vertices[v3i].Pos.Z;
            
            Irrlicht::Core::Triangle3D t;
            t.Set(a,b,c);
            
            triangles[cMeshBuffer] = (t);
         }
      }
        return triangles;
   } 
In dotNET, only classes (wich all heritates from System::Object) can be boxed in Objects (wich is the type for ArrayList). The Triangle3D class is not created with __gc attribute but with __value, I guess it means it's not a real class :roll:
The only problem is that when you use Irrlicht.NET (with C# for instance), Triangle3D inherits from Object and can be boxed... One more proof that C++.NET is incomprehensible for me :lol:
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
buhatkj
Posts: 444
Joined: Fri Dec 12, 2003 4:53 am
Contact:

returning a c++ array?

Post by buhatkj »

can I return a c++ array to C# ? I didn't think I could, that's why i was trying to use the arraylist. I guess it's worth a try....
all the same I'd rather have the arraylist if possible.
The other thing that's annoying is I dont think I can make instance of the native irrlicht collections in .NET
Anyone else have any ideas?
My irrlicht-based projects have gone underground for now, but if you want, check out my webcomic instead! http://brokenboomerang.net
Locked