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);
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
}
}
vattrs.update(fixedColor, 0);
object3D.setShader(blendingShader);
//------------------------------- 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;
}