Changing a material's color
5 posters
Changing a material's color
Hi all,
I am having trouble figuring out the correct way to change the color properties of an object's material.
This is the code I am using currently. It sets the wrong colors and the object is not shaded at all:
//the color_arr is mine
my_material->diffuse->x = obj->color_arr[0];
my_material->diffuse->y = obj->color_arr[1];
my_material->diffuse->z = obj->color_arr[2];
my_material->diffuse->w = obj->color_arr[3];
//render the material
sio2MaterialRender(my_material);
//render the object
sio2ObjectRender(my_object, sio2->_SIO2camera, 0);
sio2ObjectReset();
sio2MaterialReset();
Can someone please tell me the correct way to re-set a material's color, and render the object properly?
Thank you!! Kind regards,
-joshua
I am having trouble figuring out the correct way to change the color properties of an object's material.
This is the code I am using currently. It sets the wrong colors and the object is not shaded at all:
//the color_arr is mine
my_material->diffuse->x = obj->color_arr[0];
my_material->diffuse->y = obj->color_arr[1];
my_material->diffuse->z = obj->color_arr[2];
my_material->diffuse->w = obj->color_arr[3];
//render the material
sio2MaterialRender(my_material);
//render the object
sio2ObjectRender(my_object, sio2->_SIO2camera, 0);
sio2ObjectReset();
sio2MaterialReset();
Can someone please tell me the correct way to re-set a material's color, and render the object properly?
Thank you!! Kind regards,
-joshua
meteors- Posts : 241
Join date : 2008-11-08
Location : Sunny Florida
Re: Changing a material's color
Ok, sio2interactive helped me. All I was trying to do was alter the RGB of an existing material exported from Blender.
This works:
SIO2material *_SIO2material = ( SIO2material * ) sio2ResourceGet( sio2->_SIO2resource, SIO2_MATERIAL, "material/myMaterial" );
_SIO2material->diffuse->x = 0;
_SIO2material->diffuse->y = 1;
_SIO2material->diffuse->z = 0;
// Render all the resources.
sio2ResourceRender( sio2->_SIO2resource,
sio2->_SIO2window,
_SIO2camera );
Thanks again!
-j
This works:
SIO2material *_SIO2material = ( SIO2material * ) sio2ResourceGet( sio2->_SIO2resource, SIO2_MATERIAL, "material/myMaterial" );
_SIO2material->diffuse->x = 0;
_SIO2material->diffuse->y = 1;
_SIO2material->diffuse->z = 0;
// Render all the resources.
sio2ResourceRender( sio2->_SIO2resource,
sio2->_SIO2window,
_SIO2camera );
Thanks again!
-j
meteors- Posts : 241
Join date : 2008-11-08
Location : Sunny Florida
Re: Changing a material's color
I used this method to change the material color for an object, and I used sio2LampEnableLight when render the object and material; the problem is that the object/material is not shaded. Why?
Another question (and more important): is it possible to link other material to an object in runtime mode?
Thank you
Another question (and more important): is it possible to link other material to an object in runtime mode?
Thank you
andreassilva- Posts : 22
Join date : 2009-02-19
Re: Changing a material's color
To change the material, you need to set:
my_object->_SIO2vertexgroup[0]->_SIO2material
...where _SIO2material is your custom material.
Regarding the shading, are you passing SIO2_RENDER_SOLID_OBJECT to sio2ResourceRender?
Best,
-j
my_object->_SIO2vertexgroup[0]->_SIO2material
...where _SIO2material is your custom material.
Regarding the shading, are you passing SIO2_RENDER_SOLID_OBJECT to sio2ResourceRender?
Best,
-j
meteors- Posts : 241
Join date : 2008-11-08
Location : Sunny Florida
Re: Changing a material's color
Did you mean: my_object->_SIO2vertexgroup[0]->_SIO2material = my_material ?
I'm getting a bad access error.
what I need is duplicate an object ("loading time") an then set different materials for the duplicated at "runtime".
Thank you for reply, really appreciate it
I'm getting a bad access error.
what I need is duplicate an object ("loading time") an then set different materials for the duplicated at "runtime".
Thank you for reply, really appreciate it
andreassilva- Posts : 22
Join date : 2009-02-19
Re: Changing a material's color
Check out Tutorial 06_1 some more (I've been re-reading and working with this one for a while now, heh)... in there the comments mention that SIO2 remembers the last used material, so if you're changing your material using diffuse->x or whatever, then use the sio2RenderMaterial() function.
Then you can use renderObject() which is also used in Tutorial 06_1 (used for drawing the selected object, the duplicated object and any instances of the selected object).
Hope that helps.
Then you can use renderObject() which is also used in Tutorial 06_1 (used for drawing the selected object, the duplicated object and any instances of the selected object).
Hope that helps.
Re: Changing a material's color
If you are changing some material value, you need to call sio2MaterialReset() if you want to make the change, as SIO2 try as much is it can (while not beeing too paranoid) to avoid changing values that have already been set.
Re: Changing a material's color
Well, I don't want to change the material value. I just want to link other material (created on blender) to the duplicated objects when I load/create/duplicate them (before the render routine occurs), so that when I render all resources (including the duplicated), the duplicate objects are rendered with the material that I linked to them before.
Can I do this?
Thank you
Can I do this?
Thank you
andreassilva- Posts : 22
Join date : 2009-02-19
Re: Changing a material's color
I would think that you could create an SIO2material instance and assign it to your other material - do this in your templateLoading function, and then you could assign the material to the material property in the render section?
Or is that what you've already tried?
Or is that what you've already tried?
Re: Changing a material's color
When you duplicate objects in run-time you are creating an instance (sio2ObjectDuplicate). If you want to have an independent object you need to do a hard copy, but this will require more memory. What type of material you need to render? like a simple color or another material with different textures etc...?
Re: Changing a material's color
-----------------------------------
Exactly, the problem is that when I try to assign the materials to my duplicated objects it gives me a bad access error.
It seems the duplicated objects doesn't own a _SIO2vertexgroup[0]->_SIO2material but uses the material of the original object.
Am I right?
If yes, How can I init a vertexgroup and a material to the object?
Thanks for your effort Jawdy
-----------------------------------
sio2 have just answer my question,
for now is a simple color. My goal here is to separate the things: object and materials (blender) and logic.
You could think that I could make all my objects with different materials in blender, but what if I really wanted to do a hard copy or just give the duplicated a vertex group and material?
Exactly, the problem is that when I try to assign the materials to my duplicated objects it gives me a bad access error.
It seems the duplicated objects doesn't own a _SIO2vertexgroup[0]->_SIO2material but uses the material of the original object.
Am I right?
If yes, How can I init a vertexgroup and a material to the object?
Thanks for your effort Jawdy
-----------------------------------
sio2 have just answer my question,
for now is a simple color. My goal here is to separate the things: object and materials (blender) and logic.
You could think that I could make all my objects with different materials in blender, but what if I really wanted to do a hard copy or just give the duplicated a vertex group and material?
andreassilva- Posts : 22
Join date : 2009-02-19
Re: Changing a material's color
andreassilva wrote:-----------------------------------
Exactly, the problem is that when I try to assign the materials to my duplicated objects it gives me a bad access error.
It seems the duplicated objects doesn't own a _SIO2vertexgroup[0]->_SIO2material but uses the material of the original object.
Am I right?
If yes, How can I init a vertexgroup and a material to the object?
Thanks for your effort Jawdy
-----------------------------------
sio2 have just answer my question,
for now is a simple color. My goal here is to separate the things: object and materials (blender) and logic.
You could think that I could make all my objects with different materials in blender, but what if I really wanted to do a hard copy or just give the duplicated a vertex group and material?
No problem
I'm still a complete newb when it comes to SIO2, but trying to learn and if I can help, then great - but the man who knows all the answers is sio2
Re: Changing a material's color
I'm a newb too
I hope he can help with me with this.
Can you sio2? :p
I hope he can help with me with this.
Can you sio2? :p
andreassilva- Posts : 22
Join date : 2009-02-19
Re: Changing a material's color
Solved by linking the materials to objects in blender...
andreassilva- Posts : 22
Join date : 2009-02-19
Re: Changing a material's color
sio2interactive wrote:If you want to have an independent object you need to do a hard copy
Can you give a code sample for hard-copying an object? I'm trying to procedurally-generate the ground and would like to apply light transformations (slight shading, maybe some vertex transformations) to my ground tiles.
compaqdrew- Posts : 4
Join date : 2009-05-07
Re: Changing a material's color
Do you really have to? the process will be slow on the device and not really practical... and since some GL calls are necessary you need to do the operation within the main thread... What exactly are you trying to achieve...
Re: Changing a material's color
I'm trying to procedurally generate an infinite world--as you walk forward, tiles in the far distance are generated, and tiles behind you are destroyed. Currently i'm using sio2ObjectDuplicate to take a single cube, duplicate it, and tile it about 300 times to cover the visible area. As you walk forward, tiles distantly behind you are relocated such that they are distantly in front of you. This happens just outside the clipping plane, creating the illusion of infinite space. That's all working rather well.
Of course, using the same ground tile everywhere is rather boring. I could just blender up a palette of ground tiles, but I'd prefer to manage my tiles procedurally. For instance: as you walk forward, tiles become darker, and in the other direction, they become lighter. Or: As you walk in one direction, the tiles increase in alpha. Of course, I would do this on a row-by-row basis so that I would only have to load 30-40 materials in memory at any one time.
Of course, using the same ground tile everywhere is rather boring. I could just blender up a palette of ground tiles, but I'd prefer to manage my tiles procedurally. For instance: as you walk forward, tiles become darker, and in the other direction, they become lighter. Or: As you walk in one direction, the tiles increase in alpha. Of course, I would do this on a row-by-row basis so that I would only have to load 30-40 materials in memory at any one time.
compaqdrew- Posts : 4
Join date : 2009-05-07
Re: Changing a material's color
What I would do in your case is create another thread with a shared another GL context... all the loading / unloading should be done there...
Re: Changing a material's color
sio2interactive wrote:What I would do in your case is create another thread with a shared another GL context... all the loading / unloading should be done there...
Fair enough. But as to my original question--how would you go about hard cloning an object?
compaqdrew- Posts : 4
Join date : 2009-05-07
Re: Changing a material's color
I don't think you should hard-copy them... I think you should stream your world from the SIO2 file...
Similar topics
» erratic problem exporting and rendering
» How to rotate a object without changing the axis by SIO2?
» Materials, materials, materials, ...
» Object with two materials
» Multi-Materials for one object
» How to rotate a object without changing the axis by SIO2?
» Materials, materials, materials, ...
» Object with two materials
» Multi-Materials for one object
Permissions in this forum:
You cannot reply to topics in this forum