haggi
December 30th, 2008, 13:50
I try to evaluate the color from a struct array and I'm failing.
My struct looks like this:
declare shader
color "megaTex" (
integer "randomSeed" default 1234, #:shortname randomseed
#array color "cols", #:shortname cols
array struct "Textures" {
integer "count" default 10, #:shortname count
color "color" default .0 .5 1.0 1.0, #:shortname color
scalar "minScale" default 0.5, #:shortname minscale
scalar "maxScale" default 2.0, #:shortname maxscale
scalar "maxRot" default 180.0 #:shortname maxrot
}
)
version 1
apply texture
end declare
Now I try to evaluate the color in the "Textures" struct as follows:
int i_obj = *mi_eval_integer(¶s->i_obj);
int n_obj = *mi_eval_integer(¶s->n_obj);
texStruct *ts = (texStruct *)mi_eval(state, ¶s->texStructures) + i_obj;
for( int i = 0; i < n_obj; i++)
{
texStruct tStruct = ts[i];
mi_info("struct %d tcount %d scalemin %f scalemax %f", i, tStruct.count, tStruct.minScale, tStruct.maxScale ); //<- this is printed correct so I suppose I access the structure correctly
miColor micol = *mi_eval_color( &tStruct.color );
*result = micol;
mi_info("Eval col %f %f %f", micol.r, micol.g, micol.b);
}
return miTRUE;
This works if I use only a color. But as soon as I try to connect a texture to the "color" entry, I get a black color only.
If I use a simple color array instead of a structure array, the texture is evaluated without any problems.
I suppose there is something wrong in my code.
Would be great if anyone has an idea how I can solve the problem.
Update:
After a suggestion of bart, I tried the following:
for( int i = 0; i < n_obj; i++)
{
texStruct tStruct = paras->texStructures[ i + i_obj ];
miColor micol = *mi_eval_color( &tStruct.color );
}
This leads to an error:
DB 0.2 fatal 041052: accessing unknown tag 0x1
An access like this:
for( int i = 0; i < n_obj; i++)
{
texStruct tStruct = paras->texStructures[ i + i_obj ];
miColor micol = *mi_eval_color( ¶s->texStructures[ i + i_obj ].color );
}
does not produce an error but the result is always black (0,0,0).
This only happens for the evaluation of the color. I can access the other values without problems, well... I dont evaluate them with a mi_eval.. command, this may be the reason why it works.
edit: I tried to evaluate the other struct values and they work without problems in any case.
My struct looks like this:
declare shader
color "megaTex" (
integer "randomSeed" default 1234, #:shortname randomseed
#array color "cols", #:shortname cols
array struct "Textures" {
integer "count" default 10, #:shortname count
color "color" default .0 .5 1.0 1.0, #:shortname color
scalar "minScale" default 0.5, #:shortname minscale
scalar "maxScale" default 2.0, #:shortname maxscale
scalar "maxRot" default 180.0 #:shortname maxrot
}
)
version 1
apply texture
end declare
Now I try to evaluate the color in the "Textures" struct as follows:
int i_obj = *mi_eval_integer(¶s->i_obj);
int n_obj = *mi_eval_integer(¶s->n_obj);
texStruct *ts = (texStruct *)mi_eval(state, ¶s->texStructures) + i_obj;
for( int i = 0; i < n_obj; i++)
{
texStruct tStruct = ts[i];
mi_info("struct %d tcount %d scalemin %f scalemax %f", i, tStruct.count, tStruct.minScale, tStruct.maxScale ); //<- this is printed correct so I suppose I access the structure correctly
miColor micol = *mi_eval_color( &tStruct.color );
*result = micol;
mi_info("Eval col %f %f %f", micol.r, micol.g, micol.b);
}
return miTRUE;
This works if I use only a color. But as soon as I try to connect a texture to the "color" entry, I get a black color only.
If I use a simple color array instead of a structure array, the texture is evaluated without any problems.
I suppose there is something wrong in my code.
Would be great if anyone has an idea how I can solve the problem.
Update:
After a suggestion of bart, I tried the following:
for( int i = 0; i < n_obj; i++)
{
texStruct tStruct = paras->texStructures[ i + i_obj ];
miColor micol = *mi_eval_color( &tStruct.color );
}
This leads to an error:
DB 0.2 fatal 041052: accessing unknown tag 0x1
An access like this:
for( int i = 0; i < n_obj; i++)
{
texStruct tStruct = paras->texStructures[ i + i_obj ];
miColor micol = *mi_eval_color( ¶s->texStructures[ i + i_obj ].color );
}
does not produce an error but the result is always black (0,0,0).
This only happens for the evaluation of the color. I can access the other values without problems, well... I dont evaluate them with a mi_eval.. command, this may be the reason why it works.
edit: I tried to evaluate the other struct values and they work without problems in any case.