About Store Forum Documentation Contact



Post Reply 
Yet another MaterialLock question
Author Message
Turnstile Offline
Member

Post: #1
Yet another MaterialLock question
I have read all posts in this forum about MaterialLock, but I'm still confused how I should apply it. This is my scenario:

bool Init()
{
...
obj=UID(3699598399, 1199629675, 410681482, 1937165676); // get tank object parameters
tankMesh1 = obj->mesh();
tankMeshMaterial1 = obj->material();
obj2=UID(3211065273, 1093528304, 3438213763, 2556400651); // get tank 2 object parameters(which has parameters almost identical to tank 1)
tankMesh2 = obj2->mesh();
tankMeshMaterial2 = obj2->material();
...
}

void Render()
{
switch(Renderer())
{
case RM_PREPARE:
{
MaterialLock = tankMeshMaterial1();
tankMesh2->draw(MatrixIdentity);
MaterialLock = NULL;
}break;
case RM_BLEND:
{
}break;
}
}

So I'm trying to switch tankMesh2's materials (each tank is made up of 4 parts) with the materials from tankMesh1. But when rendered it is still using it's original materials.
The only difference between the two tank materials is that one of the tank parts has a different color (no changes in Technique (they are all set to default)).
As I mentione, the tank mesh has 4 parts. Doesn't MaterialLock lock all the parts' materials?

I noticed, that if I do it like this:
case RM_PREPARE:
{
MaterialLock = tankMesh->parts[0].material();
tankMesh2->draw(MatrixIdentity);
MaterialLock = NULL;
}break;

it will actually render all parts of tankMesh2 with the ONE texture that I locked.

So how does this work? Sorry for being so confused.
01-26-2014 10:24 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #2
RE: Yet another MaterialLock question
I could be way off here, but where you have
MaterialLock = tankMeshMaterial1();
did you try without the ()?
MaterialLock = tankMeshMaterial1;
01-27-2014 12:21 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: Yet another MaterialLock question
You should set 'MaterialLock' only before calling mesh.draw, and then reset it back after the 'draw' call
01-27-2014 06:56 AM
Find all posts by this user Quote this message in a reply
Turnstile Offline
Member

Post: #4
RE: Yet another MaterialLock question
Rubeus,
tankMeshMaterial1 is a MaterialPtr, and so I need to use ()
These are the rest of the variables for the above code snippet:
Game.ObjParamsPtr obj;
Game.ObjParamsPtr obj2;
MeshPtr pTankMesh1;
MeshPtr pTankMesh2;
Mesh tankMesh;
MaterialPtr tankMeshMaterial1;
MaterialPtr tankMeshMaterial2;
MaterialPtr boxMaterial1;
MaterialPtr boxMaterial2;

Esenthel:
>>You should set 'MaterialLock' only before calling mesh.draw, and then reset it back after the 'draw' call

Aren't these lines doing just that?
case RM_PREPARE:
{
MaterialLock = tankMeshMaterial1();
tankMesh2->draw(MatrixIdentity);
MaterialLock = NULL;
}break;
Or what are they locking? And isn't, MaterialLock = NULL, used to reset it back?
01-27-2014 06:24 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: Yet another MaterialLock question
Hi, yes the code is correct.
If it doesn't work correctly please attach some screens with the result, or better the sample project.
Thank you
01-27-2014 11:59 PM
Find all posts by this user Quote this message in a reply
Turnstile Offline
Member

Post: #6
RE: Yet another MaterialLock question
Alright,
I have zipped my project map(not sure if that is how you wanted it.), and here is a download link:
https://dl.dropboxusercontent.com/u/11312211/Sample.zip

Thank you very much for taking the time!
01-28-2014 12:56 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: Yet another MaterialLock question
Hi,

I've checked your codes.

The problem is here:
tankMeshMaterial2 = obj2->material();
The object material in 1.0 was used to replace the material for the entire mesh.
However since it's not used in 2.0 (I'm planning a more advanced system) then the obj.material is always NULL, making the MaterialLock to be set to NULL and disabled.

What you want is to work with Mesh.parts[I].material(); instead of Obj.material();
01-29-2014 11:05 PM
Find all posts by this user Quote this message in a reply
Turnstile Offline
Member

Post: #8
RE: Yet another MaterialLock question
Thank you for your reply and for your time.
I understand your explanation, and will adjust accordingly.
Best regards,
Turnstile.
01-29-2014 11:32 PM
Find all posts by this user Quote this message in a reply
Post Reply