About Store Forum Documentation Contact



Post Reply 
Copy locally a mesh
Author Message
Sadahar Offline
Member

Post: #1
Copy locally a mesh
I have a problem which solution i guess its creating a copy of the mesh... but I cant find out how to do it, maybe lacking support.

I have several "actors" with the same mesh, and the mesh has several parts... the problem is that if I change one part in one actor, every actor will actually change it, and I dont what that ^^

Any suggestions? Thanks in advance smile
10-15-2011 10:07 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #2
RE: Copy locally a mesh
Sounds to me like your code is wrong. You might want to post what you have.
10-16-2011 12:46 AM
Find all posts by this user Quote this message in a reply
Sadahar Offline
Member

Post: #3
RE: Copy locally a mesh
Its not just one part of code... Ill try to post the different parts smile

This is the set part function:

Code:
void Human::setPart(int i, Game::ObjParams* o)
{
   // Get Armor item from name

   char* matNames[] = {"b", "l", "u", "g", "f", "bh"};

   // If o == null | set default armor
   if (!o) o = Game::Objs(S+"Import/Armors/Clean/"+matNames[i]+"_clean.obj");
   if (!o) return;

   // Set specific part
   {
       MeshPart &part = mesh->parts[i];
       part.create(o->mesh()->parts[0]);
       part.setMaterial(o->material()); // set material
       Set(part.name, matNames[i]); // set name
   }

   mesh->setRender().setBox(); // setup mesh rendering version and bounding box
}

I guess every object has a reference/pointer to a mesh object in cache, so if they have the same mesh, a modification in one of them will affect others... And i cant find any constructor or method to copy the mesh object (not the reference ^^)
(This post was last modified: 10-16-2011 01:00 AM by Sadahar.)
10-16-2011 12:58 AM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #4
RE: Copy locally a mesh
Can you explain what you are trying to do better? Trying to use a different material on one mesh part and the material for that part is changing on all the other mesh instances? What is mesh pointing to?
10-16-2011 05:43 PM
Find all posts by this user Quote this message in a reply
Sadahar Offline
Member

Post: #5
RE: Copy locally a mesh
Ill try to explain better...

mesh is a MeshPtr (from cache), from a Chr object.
In my case, each mesh has 7 parts, with a (sub)mesh each part. I use it to render armors.
What I want is to completly change each part at will, both (sub)mesh and material.
And, as meshes are stored in cache, and Chr base class works with cache pointers... w/e I do in a mesh, will be done in every object in the game with the same mesh (pointer).

Ive tried to manually create a new mesh but without luck, I need a chache pointer of it to work with Chr class, and those cant be created it seems... just from a file :/

Also I tried to set each part at update loop, but its not working as intended.. maybe in draw loop? I'm trying it right now.

Sorry for my english, its not pretty good and Its hard to me to explain myself :/

EDIT: Same history if I update the parts in drawSolid(), which was the mode that made sense to me :/

EDIT2: Updating the parts in drawPrepare() updates correctly the material.. but the mesh keeps chaning randomly over time ^^ (depending of which of the different chrs that share the same mesh is called last I guess)

EDIT3: A solution to my problem might be adding manually a mesh from code to cache. (EE::Meshes)... what do you think?

Thanks for answering smile
(This post was last modified: 10-16-2011 06:45 PM by Sadahar.)
10-16-2011 05:52 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #6
RE: Copy locally a mesh
Okay, I had a feeling this was about armor rendering... Have you look at the tutorial about it?

EsenthelEngineSDK\Tutorials\Source\Advanced\2 - Animation, Physics, Rendering\Rendering\27 - Armor Rendering.cpp

The tutorial uses separate meshes for each piece of armor instead of storing them all in one. Each piece is positioned in the .mesh file where they would fit on the character and then animated individually using the character's skeleton.

You can open each .mesh file in the EsenthelEngineSDK\Data\Obj\Chr\Warrior folder in Model Editor to get a better look at how it's done in the tutorial.
10-16-2011 08:02 PM
Find all posts by this user Quote this message in a reply
Sadahar Offline
Member

Post: #7
RE: Copy locally a mesh
Yes I looked at it.. but its drawing the armor meshes OVER the main mesh, and I'd need to replace completly that part... but I think I can arrange it to do what I need... thanks for lighting me up smile

But! I still have the problem of sharing the face and the hair part :/ im not quite sure if Ill be able to achieve that.

EDIT: The armor part has problems with the base part smile seems like scaling wont solve the problem :/

That's why i want to replace the mesh part completly ^^ it keeps giving problems to have the 2 meshes at the same part.. if the armor par is *small* or specially if it doesnt cover the arms, its fairly easy to fit it.. if its body + arms (the case) is a pain ^^
(This post was last modified: 10-16-2011 09:30 PM by Sadahar.)
10-16-2011 08:51 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #8
RE: Copy locally a mesh
You can hide specific mesh parts on the character mesh, render the armor pieces, and then unhide all parts so that they will still render on other characters using the same mesh. For instance:

Code:
UInt Human::drawPrepare()
{
    mesh->hide("part_name"); // hide specific mesh parts

    UInt modes = super::drawPrepare(); // draw character
    armor->draw(cskel); // render armor

    mesh->showAll(); // show all mesh parts
    return modes;
}

Regarding the face/hair, perhaps the EsenthelEngineSDK\Tutorials\Source\Advanced\2 - Animation, Physics, Rendering\Rendering\32 - Multiple Faces.cpp tutorial will help?

It is possible to use different materials on meshes using the same .mesh file, however. Works along the same way as the code above. Save the current material to a local variable, set the new material, draw the mesh, reset the material to the saved one. Here's an example:

Code:
UInt Human::drawPrepare()
{
    MatrialPtr oldMtrl = mesh->parts[0].material(); // store current material
    mesh->parts[0].setMaterial(&newMtrl); // set new material

    UInt modes = super::drawPrepare(); // draw character

    mesh->parts[0].setMaterial(oldMtrl); // reset material
    return modes;
}
10-16-2011 09:55 PM
Find all posts by this user Quote this message in a reply
Sadahar Offline
Member

Post: #9
RE: Copy locally a mesh
Humm i tried to hide the mesh part in the update loop.. my fault ^^
And yeah, the faces would just be changing material.. humm may work smile
And for the hair I can use the armor method ^^

Thank you for your help smile
10-16-2011 09:59 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #10
RE: Copy locally a mesh
Cool. Glad this is sorted out... If you have anymore troubles, feel free to ask!
10-16-2011 10:07 PM
Find all posts by this user Quote this message in a reply
Post Reply