www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: davec64 on November 26, 2013, 06:37:20 am

Title: What is the easiest way to change a color of a 3d object. (primitive cone say)
Post by: davec64 on November 26, 2013, 06:37:20 am
I had this
Code: [Select]
tm.addTexture("platform", new Texture(0, 0, 0));
TextureInfo coneTex = new TextureInfo(tm.getTextureID("platform"));
    coneTex.add(tm.getTextureID("normals"), TextureInfo.MODE_MODULATE);
    tm.unloadTexture(fb, tm.getTexture("platform"));
    tm.replaceTexture("platform", new Texture(128, 128, red));


or
Code: [Select]
    tm.unloadTexture(fb, tm.getTexture("platform"));
    tm.replaceTexture("platform", new Texture(128, 128, green));

I just want to do this if possible.

 depthColor = green;
        coneobj.setAdditionalColor(depthColor);

Dave
Title: Re: What is the easiest way to change a color of a 3d object. (primitive cone say)
Post by: EgonOlsen on November 26, 2013, 07:39:40 am
You can use setAdditionalColor if you can live with its restrictions. It's behaviour is based on how the OpenGL pipeline works and that will lead to results in a way that setAdditionalColor is actually setMultiplicativeColor (ignoring the ambient and light source color for now...). If you set green as an additional color, this should work well enough as long as the models texture has some amount of green in it. Example (only valid if no other kind of lighting is being used): If the fragment's color is (128,128,128) and you set (0,0,255) as an additional color, the result will be (0,0,128), which is somehow green. If the fragment's color is (255,255,0), the result would be (0,0,0), which is black. However, you usually don't have that kind of colors, so for the normal case, it actually works well enough.
Title: Re: What is the easiest way to change a color of a 3d object. (primitive cone say)
Post by: davec64 on November 28, 2013, 06:30:14 am
Hi I resolved this by adding 3 textures of 0,0, size with different colors really simple and quick for a single texture object.
Code: [Select]
   tm.addTexture("conered", new Texture(0, 0, red));
      tm.addTexture("conegreen", new Texture(0, 0, green));
      tm.addTexture("coneorange", new Texture(0, 0, orange));

  if (channelDepth - reallocation.y < 1) {
      coneobj.setTexture("conered");

    }
    else if (channelDepth - reallocation.y < 2) {
      coneobj.setTexture("coneorange");

    }
    else {
      if (overlayBitmap != null) {
        coneobj.setTexture("conegreen");

      }
    }