IMeshBuffer
IMeshBuffer
Hello,
i have to add Newton physics into my game. I need the IMeshBuffer class
in Irrlicht.NET but it doesn't exist !
Please tell me what i can do now !
Bye.
i have to add Newton physics into my game. I need the IMeshBuffer class
in Irrlicht.NET but it doesn't exist !
Please tell me what i can do now !
Bye.
Hello,
i added IMeshBuffer myself so here it is:
http://rapidshare.de/files/17278514/IMe ... T.rar.html
Bye !
i added IMeshBuffer myself so here it is:
http://rapidshare.de/files/17278514/IMe ... T.rar.html
Bye !
I try to convert Irrlicht Mesh to ODE TriMesh...
The problem is: my item fall trough the ODE Plane.... why?
Code: Select all
private void createTriMesh()
{
int i,j,ci,cif,cv;
int indexcount=0;
int vertexcount=0;
IMesh omesh = mesh.GetMesh(0);
// count vertices and indices
for(i=0;i < omesh.MeshBufferCount;i++)
{
IMeshBuffer mb=omesh.GetMeshBuffer(i);
indexcount+=mb.IndexCount;
vertexcount+=mb.VertexCount;
}
// build structure for ode trimesh geom
Vector3[] vertices =new Vector3[vertexcount];
int[] indices= new int[indexcount];
// fill trimesh geom
ci=0; // current index in the indices array
cif=0; // offset of the irrlicht-vertex-index in the vetices array
cv=0; // current index in the vertices array
for(i=0;i<omesh.MeshBufferCount;i++)
{
IMeshBuffer mb=omesh.GetMeshBuffer(i);
// fill indices
ushort* mb_indices=mb.Indices;
for(j=0;j < mb.IndexCount;j++)
{
// scale the indices from multiple meshbuffers to single index array
indices[ci]=cif+mb_indices[j];
ci++;
}
// update the offset for the next meshbuffer
cif=cif+mb.VertexCount;
// fill vertices
if(mb.VertexType==VertexType.STANDARD)
{
Vertex3D* mb_vertices= (Vertex3D*)mb.Vertices;
for(j=0;j<mb.VertexCount;j++)
{
vertices[cv].X=mb_vertices[j].Pos.X;
vertices[cv].Y=mb_vertices[j].Pos.Y;
vertices[cv].Z=mb_vertices[j].Pos.Z;
cv++;
}
}
else if(mb.VertexType==VertexType.TWOTCOORDS)
{
Vertex3D2Tex* mb_vertices= (Vertex3D2Tex*)mb.Vertices;
for(j=0;j<mb.VertexCount;j++)
{
vertices[cv].X=mb_vertices[j].Pos.X;
vertices[cv].Y=mb_vertices[j].Pos.Y;
vertices[cv].Z=mb_vertices[j].Pos.Z;
cv++;
}
}
}
Vector3D pos=m_terrain.Position;
// build the trimesh data
if(geom != null)
geom.Destroy();
geom = new ODE.Geoms.TriMesh(vertices,indices);
geom.Position = toODE(pos);
body.Position = toODE(pos);
geom.RigidBody = body;
}
THANKS!!
I'd just like to say, that this is pretty awesome. I think if I just rewrite my old C++ meshbuffer crawling routine I can have physics in .NET.
Heh now if somebody will make a .NET newton wrapper....lol
Heh now if somebody will make a .NET newton wrapper....lol
My irrlicht-based projects have gone underground for now, but if you want, check out my webcomic instead! http://brokenboomerang.net
Heres Nezumi's great little Ode trimesh method in C# for anyone that needs it.
I am using this code for my 'Ground' and it works fine ( just remember that once you have created the geom to add it to the Ode Space.
Code: Select all
protected ODE.Geoms.TriMesh createTriMesh(IAnimatedMesh mesh)
{
int i, j, ci, cif, cv;
int indexcount = 0;
int vertexcount = 0;
IMesh omesh = mesh.GetMesh(0);
// count vertices and indices
for (i = 0; i < omesh.MeshBufferCount; i++)
{
IMeshBuffer mb = omesh.GetMeshBuffer(i);
indexcount += mb.IndexCount;
vertexcount += mb.VertexCount;
}
// build structure for ode trimesh geom
ODE.NoMDX.Vector3[] vertices = new ODE.NoMDX.Vector3[vertexcount];
int[] indices = new int[indexcount];
// fill trimesh geom
ci = 0; // current index in the indices array
cif = 0; // offset of the irrlicht-vertex-index in the vetices array
cv = 0; // current index in the vertices array
for (i = 0; i < omesh.MeshBufferCount; i++)
{
IMeshBuffer mb = omesh.GetMeshBuffer(i);
// fill indices
for (j = 0; j < mb.IndexCount; j++)
{
// scale the indices from multiple meshbuffers to single index array
indices[ci] = cif + mb.GetIndex(j);
ci++;
}
// update the offset for the next meshbuffer
cif = cif + mb.VertexCount;
// fill vertices
if (mb.VertexType == VertexType.STANDARD)
{
//Vertex3D* mb_vertices = (Vertex3D*)mb.Vertices;
for (j = 0; j < mb.VertexCount; j++)
{
vertices[cv].X = mb.GetVertex(j).Pos.X;
vertices[cv].Y = mb.GetVertex(j).Pos.Y;
vertices[cv].Z = mb.GetVertex(j).Pos.Z;
cv++;
}
}
else if (mb.VertexType == VertexType.TWOTCOORDS)
{
for (j = 0; j < mb.VertexCount; j++)
{
vertices[cv].X = mb.GetVertex2Tex(j).Pos.X;
vertices[cv].Y = mb.GetVertex2Tex(j).Pos.Y;
vertices[cv].Z = mb.GetVertex2Tex(j).Pos.Z;
cv++;
}
}
}
I can't download the file. Could you send it on cyr1988pro_left@front.ru
I can't download the file. Could you send it on cyr1988pro_left@front.ru
what do i do wrong
i 'd like to transform the irr terrain to ode trimesh using this syntax and the new Irrlicht.NET CP.., and add it to my car game..
but my car doesnt collide with the terrain/trimesh..
just falls down
but my car doesnt collide with the terrain/trimesh..
Code: Select all
public void LoadTerrain()
{
if (device == null)
{
MessageBox.Show("Couldn't load terrain because device was null.", "Terrain");
return;
}
VideoDriver driver = device.VideoDriver;
SceneManager smgr = device.SceneManager;
TerrainSceneNode terrain = smgr.AddTerrainSceneNode(
mediapath + @"terrain\terrain-heightmap.bmp", null, -1,
new Vector3D(), new Vector3D(), new Vector3D(40, 4.4f, 40), new Color(255, 255, 255, 255), 100, TerrainPatchSize.TPS33);
terrain.SetMaterialFlag(MaterialFlag.Lighting, false);
terrain.SetMaterialType(MaterialType.DetailMap);
terrain.SetMaterialTexture(0, driver.GetTexture(mediapath + @"terrain\terrain-texture.jpg"));
terrain.SetMaterialTexture(1, driver.GetTexture(mediapath + @"terrain\detailmap3.jpg"));
terrain.ScaleTexture(1.0f, 20.0f);
TriangleSelector selector =
smgr.CreateTerrainTriangleSelector(terrain, 0);
driver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, false);
createTriMesh(terrain);
}
Code: Select all
private void createTriMesh(TerrainSceneNode mesh)
{
int i, j, ci, cif, cv;
int indexcount = 0;
int vertexcount = 0;
Mesh omesh = mesh.Mesh;
// count vertices and indices
for (i = 0; i < omesh.MeshBufferCount; i++)
{
MeshBuffer mb = omesh.GetMeshBuffer(i);
indexcount += mb.IndexCount;
vertexcount += mb.VertexCount;
}
// build structure for ode trimesh geom
Vector3[] vertices = new Vector3[vertexcount];
int[] indices = new int[indexcount];
// fill trimesh geom
ci = 0; // current index in the indices array
cif = 0; // offset of the irrlicht-vertex-index in the vetices array
cv = 0; // current index in the vertices array
for (i = 0; i < omesh.MeshBufferCount; i++)
{
MeshBuffer mb = omesh.GetMeshBuffer(i);
// fill indices
for (j = 0; j < mb.IndexCount; j++)
{
// scale the indices from multiple meshbuffers to single index array
indices[ci] = cif + mb.GetIndex(j);
ci++;
}
// update the offset for the next meshbuffer
cif = cif + mb.VertexCount;
// fill vertices
//Vertex3D* mb_vertices = (Vertex3D*)mb.Vertices;
for (j = 0; j < mb.VertexCount; j++)
{
vertices[cv].X = mb.GetVertex(j).Position.X;
vertices[cv].Y = mb.GetVertex(j).Position.Y;
vertices[cv].Z = mb.GetVertex(j).Position.Z;
cv++;
}
}
Vector3D pos = mesh.Position;
ODE.Geoms.TriMesh terra = new ODE.Geoms.TriMesh(vertices, indices);
space.Add(terra);
terra.Position = new Vector3(pos.X, pos.Y, pos.Z);
return;
}