Brainache
Member
|
Custom Meshs
Hey there,
I am trying to import my own 3d format into the engine and save out a .mesh.
My approach is to load up all vertices, faces, etc... populate a Mshb... then use the Mshb.save to put it where I want to...
( I realize I could use the mesh editor and other programs to convert.. etc.. but there are reasons why I need to do this)
Im a bit stuck at 'populate a Mshb'....
I see there are addVtx, addTri, addQuad functions...
Do I need to use a create function first?
I do not have a list of edges - only triangles, quads, vertexes, texcoords.. will I need edges or can it generate?
Can you give me a little example of where to start on this?
Thanks!
|
|
04-14-2009 05:18 PM |
|
Esenthel
Administrator
|
Re: Custom Meshs
Hi, you don't need edges,
you can set Mshb like this:
Code:
Mshb mshb;
Int vertexes=100,
edges=0,
tris=100,
quads=0;
mshb.create(vertexes,edges,tris,quads, VTX_POS|VTX_NRM|VTX_TEX0|TRI_IND);
// now depending on which flags you've enabled VTX_POS|VTX_NRM|VTX_TEX0|TRI_IND
// you should set the following data:
mshb.vtx.pos[0]=
mshb.vtx.pos[1]=
...
mshb.vtx.tex0[0]=
mshb.vtx.tex0[1]=
...
mshb.vtx.nrm[0]=..
mshb.tri.ind[0].set(a,b,c);
...
|
|
04-14-2009 05:26 PM |
|
Brainache
Member
|
Re: Custom Meshs
Perfect - just what I needed to know...
Thanks again for the fast response!
|
|
04-14-2009 07:07 PM |
|
Brainache
Member
|
Re: Custom Meshs
Hmm - Where/how do I set the material so it will be saved in the .mesh file?
( so far so good btw )
|
|
04-14-2009 07:44 PM |
|
Esenthel
Administrator
|
Re: Custom Meshs
For this you would need to use a Mesh (and then use the Mshb which is inside the Mesh)
Mesh mesh;
mesh.create(1); // create 1 part inside the mesh
MeshPart &part=mesh.part(0); // access first part
Mshb &mshb=part.base; // access the base of the part
//set mshb here
//set part properties here:
part.material[0]=Materials(..);
// finalize the mesh building
mesh.setRender().setBox();
mesh.save(..);
|
|
04-14-2009 08:00 PM |
|
Brainache
Member
|
Re: Custom Meshs
Hey there... Getting very close on this... ran into this issue tho:
Adding polys that are neither tris or quads...
I'm figuring I'll use the triangulate function, but not sure how I can add these to the existing mshb w/o causing issues with the passed vertex, tri, and quad counts
Can I bother you to point the way?
Thanks
|
|
04-15-2009 12:58 AM |
|
Esenthel
Administrator
|
Re: Custom Meshs
you can use a helper Mshb:
Mshb mshb_triangulated; // set it using Triangulate function from polys only (>=5 vertices count)
then add the 'mshb_triangulated' to the Mshb which you've already created from triangles and quads
Mshb &base=part.base;
base+=mshb_triangulated;
|
|
04-15-2009 09:35 AM |
|
Brainache
Member
|
Re: Custom Meshs
Hey there... this is working perfectly for gemotry, but it causes the texture coordinates to be lost ( since triangulate doest have those coords..)
Any way to do this while keeping texture coords?
|
|
04-15-2009 05:02 PM |
|
Esenthel
Administrator
|
Re: Custom Meshs
please use the 'Triangulate' version which uses Vtx3D instead of a single Vec position
|
|
04-15-2009 05:07 PM |
|
Brainache
Member
|
Re: Custom Meshs
Perfect. Just perfect...
Thanks!
|
|
04-15-2009 05:21 PM |
|
Brainache
Member
|
Re: Custom Meshs
Allrighty.... on to materials...
I have the materials loading, and rendering properly... however, when I save the mesh.. and load it into mesh editor.. the materials do not show.. texture coords are there..
I'm setting the material by using part.setMaterial( &mMaterials[0] )..
Any idea why they arent saving in the .mesh file?
Thanks!
|
|
04-15-2009 11:27 PM |
|
Brainache
Member
|
Re: Custom Meshs
Another material question.. might be related to the above...
When I render the mesh after importing.. the texture coords are not quite right... ( appear to be scaled in )
When I save the mesh out.. and look at it in mesh editor... the texture coords are correct...
Ideas?
|
|
04-15-2009 11:53 PM |
|
Esenthel
Administrator
|
Re: Custom Meshs
for saving the material file name you need to assign a material created from the 'Materials' cache to the mesh.
as for the second - texture scaling, I don't know
|
|
04-16-2009 12:07 AM |
|
Brainache
Member
|
Re: Custom Meshs
Wicked - Solved the textures... ( my material index was off by 1.. coords were fine!)
Now.. working on building a .phys file from the mesh...
Reading through Phys_part.h this looks like how I should be doing it.. but it is crashing...
(eMesh is a 'Mesh')
Phys phys;
phys.create(eMesh.parts());
for (int p=0;p<eMesh.parts();p++)
{
PhysPart &pp = phys.part(p);
MeshPart &part = eMesh.part(p);
Mshb &em = part.base;
pp.createMesh(em);
}
I've treid using PhysPart &pp = phys.New() w/o calling phys.create(...) also...
Where is my mistake?
(Its got something to do with the createMesh function im sure... when I use create(box).. it works)
Thanks!
|
|
04-16-2009 12:44 AM |
|
Esenthel
Administrator
|
Re: Custom Meshs
I guess you should create the Physics first at the program start
Physics.create()
|
|
04-16-2009 12:51 AM |
|