Hi,
I want to render an OBJ object3d.
Part of the initialization code is:
GroupOfModels3D = Loader.loadOBJ(objStream, mtlStream, scale);
object3D = Object3D.mergeAll(GroupOfModels3D);
object3D.build();//<----- removing this line fixes the issue
GLSLShader blendingShader = new GLSLShader( Loader.loadTextFile(res.openRawResource(R.raw.vertexshader)),Loader.loadTextFile(res.openRawResource(R.raw.fragmentshader)));
//assign vertex colors
int numberOfVertices = object3D.getMesh().getUniqueVertexCount();
float[] offScreenColorArray = new float[numberOfVertices * 4];
for (int i = 0; i < offScreenColorArray.length; i++) {
offScreenColorArray[i] = 0.0f;
if (i > 0) {
if (i % 4 == 0)
offScreenColorArray[i] = 0; //red color
if (i % 4 == 1)
offScreenColorArray[i] = 0;//green color
if (i % 4 == 2)
offScreenColorArray[i] = 1;//blue color
if (i % 4 == 3)
offScreenColorArray[i] = 1; //transparency
// 1-> opaque 0-> total
// transparent
}
}
vattrs = new VertexAttributes("colorinfo",offScreenColorArray,VertexAttributes.TYPE_FOUR_FLOATS);
vattrs.setDynamic(true);
object3D.getMesh().addVertexAttributes(vattrs);
At the beginning the object is rendered without using the blendingShader GLSLShader with no problem.
But later on run time i want to use the blendingShader with a different array of color (red ) like this one:
int numberOfVertices = object3D.getMesh().getUniqueVertexCount();
for(int i = 0; i < fixedColor.length; i++){
fixedColor[i] = 0.0f;
if(i>0){
if(i%4 == 0)
fixedColor[i] = 1;//red color
if(i%4 == 1)
fixedColor[i] = 0; //green color
if(i%4 == 2)
fixedColor[i] = 0; //blue color
if(i%4 == 3)
fixedColor[i] = 1; //transparency
}
}
After i assign the new color i call the following lines:
vattrs.update(fixedColor, 0);
object3D.setShader(blendingShader);
But in this case the object3D is rendered with blue color (offScreenColorArray) instead of red color (fixedColor)
After a lot of hours i found out that if i remove the call of object3D.build() at the beginning, the object3d is rendered with red color (fixedcolor array)
The used shaders are:
//------------------------------- vertexshader -------------------------
attribute vec4 colorinfo;
uniform mat4 modelViewProjectionMatrix;
attribute vec4 position;
varying vec4 vertexColor;
void main(void)
{
vertexColor = colorinfo;
gl_Position = modelViewProjectionMatrix * position;
}
//-------------------------------- fragmentshader -------------------
varying vec4 theColor;
varying vec4 vertexColor;
void main(void)
{
gl_FragColor = vertexColor;
}
What is the problem?
Thanks in Advance