Best Practice for an Object with Variable Material Properties
2 posters
Best Practice for an Object with Variable Material Properties
Hi,
Here is what I am trying to accomplish: Given a game state variable (0, 1) I wish to toggle the color of the material on a 3D object. The 2 materials I want to toggle between should both be transparent by 50%, and the only difference is that one material is red, and the other is green.
1. How should I initally set up the object and it's material assignment in Blender?
2. How do I change the material attributes of the given object's material in templateRender()? Is it best practice to simply make adjustment to the material->diffuse->x,y, z and use ONE material? Or create two materials?
I am looking through tutorial06, and have tried the following code block inside of templateRender(), but the object's material stays the same (right now, initially set as a RGBA .tga texture in Blender)...
Here is what I am trying to accomplish: Given a game state variable (0, 1) I wish to toggle the color of the material on a 3D object. The 2 materials I want to toggle between should both be transparent by 50%, and the only difference is that one material is red, and the other is green.
1. How should I initally set up the object and it's material assignment in Blender?
2. How do I change the material attributes of the given object's material in templateRender()? Is it best practice to simply make adjustment to the material->diffuse->x,y, z and use ONE material? Or create two materials?
I am looking through tutorial06, and have tried the following code block inside of templateRender(), but the object's material stays the same (right now, initially set as a RGBA .tga texture in Blender)...
- Code:
/*at top: */
//SIO2material *_SIO2material_greenArrow = NULL;
/*inside templateRender() */
//set the material color of the arrow based on if aimStatus is selected.
if (readyStatus == 1) { //arrow is green
if (!_SIO2material_greenArrow) { //initialize material it if it hasn't been already
_SIO2material_greenArrow = sio2MaterialInit("greenArrow");
_SIO2material_greenArrow->diffuse->x = 0.0f;
_SIO2material_greenArrow->diffuse->y = 0.0f;
_SIO2material_greenArrow->diffuse->z = 0.0f;
_SIO2material_greenArrow->diffuse->w = 0.5f;
//change the blending mode
_SIO2material_greenArrow->blend = SIO2_MATERIAL_ALPHA;
NSLog(@"material INIT");
}
//set to green
_SIO2material_greenArrow->diffuse->x = 0.0f;
_SIO2material_greenArrow->diffuse->y = 1.0f;
//render the material
sio2MaterialRender(_SIO2material_greenArrow);
sio2ObjectRender(_readyArrow, sio2->_SIO2camera, 0);
sio2ObjectReset();
}
if (readyStatus == 0) { //arrow is red
if (!_SIO2material_greenArrow) { //initialize material it if it hasn't been already
_SIO2material_greenArrow = sio2MaterialInit("greenArrow");
_SIO2material_greenArrow->diffuse->x = 0.0f;
_SIO2material_greenArrow->diffuse->y = 0.0f;
_SIO2material_greenArrow->diffuse->z = 0.0f;
_SIO2material_greenArrow->diffuse->w = 0.5f;
//change the blending mode
_SIO2material_greenArrow->blend = SIO2_MATERIAL_ALPHA;
NSLog(@"material INIT");
}
//set to red
_SIO2material_greenArrow->diffuse->x = 1.0f;
_SIO2material_greenArrow->diffuse->y = 0.0f;
//render the material
sio2MaterialRender(_SIO2material_greenArrow);
sio2ObjectRender(_readyArrow, sio2->_SIO2camera, 0);
sio2ObjectReset();
}
}
jj- Posts : 77
Join date : 2008-09-24
Re: Best Practice for an Object with Variable Material Properties
As part of the optimization process, SIO2 remember the last material pointer that have been bind to the OpenGL context, if NO other material(s) is/are rendered after SIO2 assume that every GL_STATES are already set to render it... If you make some changes on the material properties make sure to call sio2MaterialReset() at least once after you change the values, so the changes will be applied...
In addition to tutorial06 check the font tutorial... it also uses the same technique...
Cheers,
In addition to tutorial06 check the font tutorial... it also uses the same technique...
Cheers,
Re: Best Practice for an Object with Variable Material Properties
Great! Thanks...
I was able to update the ->diffuse colors accordingly.
I was able to update the ->diffuse colors accordingly.
jj- Posts : 77
Join date : 2008-09-24
Similar topics
» Material and Texture
» Make a global variable private
» Storing additional properties
» soft bodies properties question
» Glass Material
» Make a global variable private
» Storing additional properties
» soft bodies properties question
» Glass Material
Permissions in this forum:
You cannot reply to topics in this forum