Skinning individual faces on a cube - need advice
by Alviss · in Torque 3D Professional · 10/15/2012 (9:04 pm) · 7 replies
Hi
As the title suggests im trying to figure out the best way to create a new engine function, like
Famous example of what happens now
I'd like it to go something like this.
What i am thinking is making a collada using 6 separate meshes as faces of one cube. The faces all have different materials, so they can be changed individually. A single face on the cube can be skinned, and all the other faces will remain the same.
Now, what im asking is, is there a better way to do this? Can the individual meshes or nodes that make up a shape be referenced in the engine, and then painted individually? Or, how would you go about accomplishing this?
Thanks you for any advice.
As the title suggests im trying to figure out the best way to create a new engine function, like
TSShapeInstance::reSkin( String newBaseName, String oldBaseName ). Except instead of changing all materials based on a common string, a material is changed based on an index, or some other indicator, that is then NOT renamed to the material name.
Famous example of what happens now
blue_body blue_head facereSkin to red, they become
red_body red_head face
I'd like it to go something like this.
blue_body blue_head faceTo reskin to red, indicate the mesh/index/etc, (head), and the new colour (red)
blue_body red_head face
What i am thinking is making a collada using 6 separate meshes as faces of one cube. The faces all have different materials, so they can be changed individually. A single face on the cube can be skinned, and all the other faces will remain the same.
Now, what im asking is, is there a better way to do this? Can the individual meshes or nodes that make up a shape be referenced in the engine, and then painted individually? Or, how would you go about accomplishing this?
Thanks you for any advice.
#2
Thank you kindly, Richard.
10/16/2012 (9:27 pm)
Yeah, i've also heard about those issues. I'll make up the code and see how she works. If it works well, i'll resource it.Thank you kindly, Richard.
#3
I've created a a new function
But i've hit a bit of a wall, brought about by my own lack of Torque engine know-how.
Is there at all a way to get the material used by just one mesh, like, how i have above? Instead of using the Shape method and getting all the individual mesh's materials culminated into one material list? Because once it's in that list, it's impossible (as far as i know) to decifer which one came from which mesh. Like in the below...
10/17/2012 (9:30 pm)
Im slowly starting to figure out what im doing. I've assembled my cube, 6 separate meshes, with 6 separate materials.I've created a a new function
void TSShapeInstance::reSkinById( String newMatName, String targetMesh )
{
targetMesh = "Soldier"; // for testing the soldier collada
if( newMatName.isEmpty() )
newMatName = "Grey";
if( targetMesh.isEmpty() )
return;
TSMesh* meshObj;
meshObj = mShape->findMesh(targetMesh);
if (meshObj == 0)
return;
TSMaterialList* matList = meshObj->giveMeTheFreakinMaterial() // :p(Yes i know it's flow doesnt make much sense, it's just a quick mockup)But i've hit a bit of a wall, brought about by my own lack of Torque engine know-how.
Is there at all a way to get the material used by just one mesh, like, how i have above? Instead of using the Shape method and getting all the individual mesh's materials culminated into one material list? Because once it's in that list, it's impossible (as far as i know) to decifer which one came from which mesh. Like in the below...
(class is TsShapeInstance) TSMaterialList* pMatList = getMaterialList();
#4
It seems like it would be sensible for them to come back in the order that the meshes are defined. Not that it means anything, really - but it might be a place to start....
It isn't entirely relevant since the skins map to specific base materials anyway - unless you need to check the state of a face's material. However, if that is the case and there is no discernible order that the materials come back in you might just want to do the book keeping yourself.
10/18/2012 (4:57 pm)
Doesn't it come back in the same order every time?It seems like it would be sensible for them to come back in the order that the meshes are defined. Not that it means anything, really - but it might be a place to start....
It isn't entirely relevant since the skins map to specific base materials anyway - unless you need to check the state of a face's material. However, if that is the case and there is no discernible order that the materials come back in you might just want to do the book keeping yourself.
#5
edit: look for SubMaterialSelector in tools/materialeditor files it lists all the meshes in the model.
10/18/2012 (5:08 pm)
There must be a way since when you use the material editor with a model selected the dropdown of all materials/meshes is populated. So i assume that if you slecet your cube all 6 faces/materials will be listed in the dropdown.edit: look for SubMaterialSelector in tools/materialeditor files it lists all the meshes in the model.
#6
@Bloodknight
Yeah, i can get a list of all meshes and materials, but other than what Richard has said, there is no discernible way to find out who belongs to what.
10/18/2012 (6:34 pm)
Thank you Richard, It would seem logical to have materials added in the order meshes are added, i'll check that out.@Bloodknight
Yeah, i can get a list of all meshes and materials, but other than what Richard has said, there is no discernible way to find out who belongs to what.
#7
TSMaterialList* pMatList = getMaterialList();
Any idea what the error could be? getMaterialList() is only called by reSkin() in tsShapeInstance.cpp and that works fine. getMaterialList() is used a lot in the engine on the whole, so i dont understand why it's not working in my function.
10/21/2012 (12:08 am)
Im getting a strange crash when i call: TSMaterialList* pMatList = getMaterialList();
Any idea what the error could be? getMaterialList() is only called by reSkin() in tsShapeInstance.cpp and that works fine. getMaterialList() is used a lot in the engine on the whole, so i dont understand why it's not working in my function.
void TSShapeInstance::reSkinById( String newMatName, String targetMesh )
{
if( newMatName.isEmpty() )
newMatName = "Grey";
if( targetMesh.isEmpty() )
return;
const U32 meshLength = targetMesh.length();
for ( U32 m = 0; m < mMeshObjects.size(); m++ )
{
//const MeshObjectInstance &mesh = mMeshObjects[m];
const String &meshName = mShape->getMeshName(m).c_str();
if ( meshName.compare( targetMesh, meshLength, String::NoCase ) == 0 )
{
Con::warnf( "test-1" );
TSMaterialList* MaterialList = getMaterialList();
Con::warnf( "test0" );
}
}
}
Torque Owner Richard Ranft
Roostertail Games
Additionally, some people have indicated a problem changing a mesh's skin after creation though I've never run into it myself.