Need Help,Saving Mesh to File

Acnirak

27-09-2010 16:01:07

Hi All;
i am creating a mesh by using manual object but i have serious problems when i try to save it to a .mesh file;

Target is my manualobject and the code below is giving me a mesh which is working without a problem;(Target have indexes too)
Target.ConvertToMesh(MeshName);

it is ok till now
but after this
MeshSerializer SerializeMesh = new MeshSerializer();
MeshManager meshmanage = new MeshManager();
meshmanage.BoundsPaddingFactor = 1f;
Mesh ISSF = new Mesh(meshmanage, "Deneme", resourceno, "Deneme");
ISSF._setBounds(AAB);
SerializeMesh.ExportMesh(ISSF, "Ucgen.mesh");
it says thay converting mesh is ok and i am finding the file but it is only 72 bytes and i dont think it writes it something actually because file size doesnt change even with bigger manualobjects and
i cant load mesh from file.

an example code is like that:

ManualObject Target = mSceneMgr.CreateManualObject(MeshName);
//DrawTarget(mSceneMgr, Target, 9, 20, 5, 20);
Target.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
Target.Position(0, 0, 0);
Target.Position(50, 0, 0);
Target.Position(0, 75, 0);
Target.Triangle(0, 1, 2);
Target.End();
AxisAlignedBox AAB = new AxisAlignedBox(-10f, -10f, -10f, 100, 100, 100);
Target.BoundingBox = AAB;
AAB.Volume();
Target.ConvertToMesh(MeshName);
it works til now;

but after this serialize doesnt work properly;
MeshSerializer SerializeMesh = new MeshSerializer();
MeshManager meshmanage = new MeshManager();
meshmanage.BoundsPaddingFactor = 1f;
Mesh ISSF = new Mesh(meshmanage, "Deneme", resourceno, "Deneme");
ISSF._setBounds(AAB);
SerializeMesh.ExportMesh(ISSF, "Ucgen.mesh");

smiley80

27-09-2010 16:20:35

Mesh ISSF = new Mesh(meshmanage, "Deneme", resourceno, "Deneme");
creates a new mesh.

Just export the return value of ConvertToMesh:

ManualObject Target = mSceneMgr.CreateManualObject(MeshName);
Target.Begin("BaseWhiteNoLighting", RenderOperation.OperationTypes.OT_TRIANGLE_LIST);
Target.Position(0, 0, 0);
Target.Position(50, 0, 0);
Target.Position(0, 75, 0);
Target.Triangle(0, 1, 2);
Target.End();
MeshSerializer serializer = new MeshSerializer();
serializer.ExportMesh(Target.ConvertToMesh(MeshName), "Ucgen.mesh");

Acnirak

29-09-2010 11:08:33

Hi again i couldnt look forms yesterday but thank you very much it has worked when i tried your solution;
now i can save these meshes to files and load from files later;
but i had a new problem when i am testing these meshes.
This time the problem is about materials; i cant load any materials on the meshes which i have saved;

i am using this code to set material:
Entity ent = mSceneMgr.CreateEntity("Head1", "prefix.mesh");
Entity ent2 = mSceneMgr.CreateEntity("ISSF.mesh");
Entity ent3 = mSceneMgr.CreateEntity("ucc.mesh");
Mogre.MaterialPtr matptr = Mogre.MaterialManager.Singleton.GetByName("prefix/mat1");
ent.SetMaterial(matptr);
ent2.SetMaterial(matptr);
ent3.SetMaterial(matptr);

But although material can cover other meshes(which came from external third party programs like blender), it can't cover its own meshes; you can check it from picture,
this triangle is a basic 2d triangle(its same basic triangle code above) mesh but it couldnt cover any 3d mesh too;

i thought that maybe it suffers from bounding boxes but it seems bounding boxes are ok too:


it is like it reads only first pixel of material and giving it to all mesh because these meshes are taking the color inside the material(this green arent their native color it comes from the material somehow) but not all the material.

mstoyke

29-09-2010 11:25:29

You also need to generate UV coordinates.

Acnirak

29-09-2010 15:31:36

Thank you very much guys i have learned and implemented UV map;
my project is about to create meshes from pictures
i am using edgedetection then polynamial triuangulation and converting to mesh;
it is like:

and mesh:

or;

and mesh:


now my project is working and i will optimize my code with better edge detection and something like this;
so i wanted to say something about it ;
first of all i want to ask a question: i am drawing a lot of triangles but although i am using same points a lot of time over and over again i am giving new indexes whenever i use this point; should i optimise it by giving a point only one index or it isnt so important?

second there is some programs to do it but i didnt see it an open source program for this, if you want after i complete my project and my code becomes in a good OO style code(i will rewrite somewhere) i may send you its code and you can publish it to use for mogre community if you think it is useful.
Thanks again.