Author Topic: Object3D's transparency issue  (Read 7173 times)

Offline AeroShark333

  • long
  • ***
  • Posts: 149
    • View Profile
Object3D's transparency issue
« on: December 06, 2014, 12:07:56 pm »
Hey everyone,

I had a hard time trying to register to this forums, so I used my schoolemail...  :o
Anyway, I have an issue with 2 Object3D's...
Both objects are cubed. They have individual textures on each face.
Both objects have this transparency value:
Code: [Select]
this.setTransparency(300);
Box1 is in box2. (their center point is equal)
Box1's dimensions: 2f * 2f * 2f
Box2's dimensions: 2.2f * 2.2f * 2.2f
Box2 has more transparent area's than box1.
However, box2's non-transparent textures don't seem to be visible...
When I remove
Code: [Select]
this.setTransparency(300); from box1, then those non-transparent textures do show up... (but then I get black-ish areas on the box1 texture...)

How can I solve this problem?

Cheers,
Abiram

PS: This library is AWESOME   ;D

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Object3D's transparency issue
« Reply #1 on: December 06, 2014, 03:07:46 pm »
That's most likely caused by render order. Transparent objects are sorted by depth, but that happens on a per object base. If you put one object into another one, there's no correct ordering. Your case is a quite special one. It might be sufficient to force an order between the two cubes. Try something like box1.setSortOffset(10) and see if that helps.

Offline AeroShark333

  • long
  • ***
  • Posts: 149
    • View Profile
Re: Object3D's transparency issue
« Reply #2 on: December 06, 2014, 05:28:34 pm »
Thanks for the quick reply and it worked! :D

However, I have another issue now...
I have a box3 and a box4 next to each other (touched).
Both faces that touch each othe, do intersect each other on the whole face.
And I get something like in the picture... (both have transparency set to 300)

Picture: Left one is what I got. Right one is what I want.
« Last Edit: December 06, 2014, 05:30:27 pm by AeroShark333 »

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Object3D's transparency issue
« Reply #3 on: December 06, 2014, 11:11:10 pm »
That's basically the same issue. Transparent have to be sorted and that happen per object (it has to). This sorting isn't perfect in cases where object intersect or a close to one another. Sorting issues with transparent objects can only be avoided by not using them in the first place. Or by tweaking the sort order like you did in the former case, but for the general case, this isn't possible. I'm not sure if it is in your case. What's the actual idea behind what you are doing? What are these boxes, in which ways are then moving and why do they touch?

Offline AeroShark333

  • long
  • ***
  • Posts: 149
    • View Profile
Re: Object3D's transparency issue
« Reply #4 on: December 06, 2014, 11:31:42 pm »
Well here is the idea:
The app I am working on is a skinviewer for Minecraft and Minebuilder.
The user selects a .png file skin and the app will 'visualise' a 3D version of it.
Since skin files usually contain transparent areas, I have decided to enable transparency on every object.
The objects do not move (yet), but the camera rotates around the objects/skin. (I will add user input and animation-ish movements later)

I released the app today:
https://play.google.com/store/apps/details?id=com.aeroshark333.skinviewer (this version has box1's transparency disabled though, the next update will include the sorting order)

I am not a really good developer, neither am I very good with Java and OpenGL. But this is some kind of hobby :)

The transparency issue with the objects next to each other depends on the device too I guess

« Last Edit: December 06, 2014, 11:33:48 pm by AeroShark333 »

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Object3D's transparency issue
« Reply #5 on: December 07, 2014, 03:20:58 pm »
No, they have nothing to do with the device. Not even with the engine. They are a common problem whenever transparent objects intersect. The only option would be use alpha testing instead of alpha blending. But jPCT-AE doesn't support this out of the box. You would have to use the OpenGL ES 2.0 pipeline and write an alpha testing shader.
If you can provide a simplified test case that shows the issue, i'll have a look and provide you with something to get you started.

Offline AeroShark333

  • long
  • ***
  • Posts: 149
    • View Profile
Re: Object3D's transparency issue
« Reply #6 on: December 08, 2014, 04:40:24 pm »
The 'issue' is very small though, but noticable. (see screenshot in attachment)
Since the camera rotates around the 'center', the 'issue' moves from the left leg to the right leg and visa versa.

Well this is my code:

SkinActivity.class (the GameRenderer class in this class only)
Code: [Select]
class GameRenderer implements GLSurfaceView.Renderer {
final World mainWorld;
final Camera mainCamera;
FrameBuffer frameBuffer;

public GameRenderer(World world) {
this.mainWorld = world;
this.mainCamera = this.mainWorld.getCamera();
}


@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {

}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
this.frameBuffer = new FrameBuffer(width, height);

totalSkin.hasAlpha();
InnerHead iH = new InnerHead();
OuterHead oH = new OuterHead();
Body b = new Body();
RightArm rA = new RightArm();
LeftArm lA = new LeftArm();
RightLeg rL = new RightLeg();
LeftLeg lL = new LeftLeg();

mainWorld.addObject(iH);
mainWorld.addObject(oH);
mainWorld.addObject(b);
mainWorld.addObject(rA);
mainWorld.addObject(lA);
mainWorld.addObject(rL);
mainWorld.addObject(lL);

this.mainWorld.setAmbientLight(255, 255, 255);

final float dScreen = (float) height/(float)width;

this.mainCamera.setPosition(0, 0.25f, (-9 / dScreen));
this.mainCamera.lookAt(b.getCenter());

iH.translate(0, -2.51f, 0);
oH.translate(0, -2.605f, 0);
rA.translate(-1.5f, 0, 0);
lA.translate(1.5f, 0, 0);
rL.translate(-0.5f, 3f, 0);
lL.translate(0.5f, 3f, 0);


System.runFinalization();
System.gc();
MemoryHelper.compact();
}

@Override
public void onDrawFrame(GL10 gl) {
frameBuffer.clear(new RGBColor(132, 189, 240));

SimpleVector moveLine = new SimpleVector(0.333f, 0, 0.333f);
com.threed.jpct.Matrix m = moveLine.normalize().getRotationMatrix();
m.rotateAxis(m.getYAxis(), (float) -Math.PI / 2f);
mainCamera.moveCamera(Camera.CAMERA_MOVEIN, 10);
mainCamera.rotateAxis(m.invert3x3().getYAxis(),
moveLine.length() / 30f);
mainCamera.moveCamera(Camera.CAMERA_MOVEOUT, 10);
mainCamera.lookAt(mainWorld.getObjectByName("body").getCenter());

final Texture t1 = TextureManager.getInstance().getTexture("bg");
frameBuffer.blit(t1, 0, t1.getHeight(), 0, 0, t1.getWidth(),
-t1.getHeight(), frameBuffer.getWidth(),
frameBuffer.getHeight(), -1, false);
mainWorld.renderScene(frameBuffer);
mainWorld.draw(frameBuffer);
frameBuffer.display();
}

}

Body:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

public class Body extends Object3D {

private static final long serialVersionUID = 8216608860877707087L;

public Body() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-1, -1.5f, -0.5f);
SimpleVector upperRightFront = new SimpleVector(1, -1.5f, -0.5f);
SimpleVector lowerLeftFront = new SimpleVector(-1, 1.5f, -0.5f);
SimpleVector lowerRightFront = new SimpleVector(1, 1.5f, -0.5f);

SimpleVector upperLeftBack = new SimpleVector(-1, -1.5f, 0.5f);
SimpleVector upperRightBack = new SimpleVector(1, -1.5f, 0.5f);
SimpleVector lowerLeftBack = new SimpleVector(-1, 1.5f, 0.5f);
SimpleVector lowerRightBack = new SimpleVector(1, 1.5f, 0.5f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("bodyfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("bodyfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("bodyback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("bodyback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("bodytop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("bodytop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("bodybottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("bodybottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("bodyright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("bodyright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("bodyleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("bodyleft"));

this.setTransparency(300);

box.setName("body");

box.build();
}
}


Innerhead:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

public class InnerHead extends Object3D {

private static final long serialVersionUID = 4848178494608221837L;

public InnerHead() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-1, -1, -1);
SimpleVector upperRightFront = new SimpleVector(1, -1, -1);
SimpleVector lowerLeftFront = new SimpleVector(-1, 1, -1);
SimpleVector lowerRightFront = new SimpleVector(1, 1, -1);

SimpleVector upperLeftBack = new SimpleVector(-1, -1, 1);
SimpleVector upperRightBack = new SimpleVector(1, -1, 1);
SimpleVector lowerLeftBack = new SimpleVector(-1, 1, 1);
SimpleVector lowerRightBack = new SimpleVector(1, 1, 1);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("headfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("headfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("headback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("headback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("headtop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("headtop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("headbottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("headbottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("headright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("headright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("headleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("headleft"));

this.setTransparency(300);

box.setName("head");

box.setSortOffset(9);

box.build();
}
}

Leftarm:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

//biological left :p
public class LeftArm extends Object3D{

/**
*
*/
private static final long serialVersionUID = -5036321054138114930L;

public LeftArm() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-0.5f, -1.5f, -0.5f);
SimpleVector upperRightFront = new SimpleVector(0.5f, -1.5f, -0.5f);
SimpleVector lowerLeftFront = new SimpleVector(-0.5f, 1.5f, -0.5f);
SimpleVector lowerRightFront = new SimpleVector(0.5f, 1.5f, -0.5f);

SimpleVector upperLeftBack = new SimpleVector(-0.5f, -1.5f, 0.5f);
SimpleVector upperRightBack = new SimpleVector(0.5f, -1.5f, 0.5f);
SimpleVector lowerLeftBack = new SimpleVector(-0.5f, 1.5f, 0.5f);
SimpleVector lowerRightBack = new SimpleVector(0.5f, 1.5f, 0.5f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("armfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("armfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("armback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("armback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("armtop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("armtop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armbottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armbottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("armleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("armleft"));

this.setTransparency(300);

box.setName("leftarm");


box.build();
}
}

Leftleg:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

//biological left
public class LeftLeg extends Object3D{
/**
*
*/
private static final long serialVersionUID = 4705719438846904180L;

public LeftLeg() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-0.5f, -1.5f, -0.5f);
SimpleVector upperRightFront = new SimpleVector(0.5f, -1.5f, -0.5f);
SimpleVector lowerLeftFront = new SimpleVector(-0.5f, 1.5f, -0.5f);
SimpleVector lowerRightFront = new SimpleVector(0.5f, 1.5f, -0.5f);

SimpleVector upperLeftBack = new SimpleVector(-0.5f, -1.5f, 0.5f);
SimpleVector upperRightBack = new SimpleVector(0.5f, -1.5f, 0.5f);
SimpleVector lowerLeftBack = new SimpleVector(-0.5f, 1.5f, 0.5f);
SimpleVector lowerRightBack = new SimpleVector(0.5f, 1.5f, 0.5f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("legfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("legfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("legback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("legback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("legtop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("legtop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legbottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legbottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("legleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("legleft"));

this.setTransparency(300);

box.setName("leftleg");


box.build();
}
}

Outerhead:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

public class OuterHead extends Object3D{

private static final long serialVersionUID = 3950765561884516490L;

public OuterHead() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-1.1f, -1.1f, -1.1f);
SimpleVector upperRightFront = new SimpleVector(1.1f, -1.1f, -1.1f);
SimpleVector lowerLeftFront = new SimpleVector(-1.1f, 1.1f, -1.1f);
SimpleVector lowerRightFront = new SimpleVector(1.1f, 1.1f, -1.1f);

SimpleVector upperLeftBack = new SimpleVector(-1.1f, -1.1f, 1.1f);
SimpleVector upperRightBack = new SimpleVector(1.1f, -1.1f, 1.1f);
SimpleVector lowerLeftBack = new SimpleVector(-1.1f, 1.1f, 1.1f);
SimpleVector lowerRightBack = new SimpleVector(1.1f, 1.1f, 1.1f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("hatfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("hatfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("hatback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("hatback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("hattop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("hattop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("hatbottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("hatbottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("hatright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("hatright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("hatleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("hatleft"));

this.setTransparency(300);


box.setName("hat");

box.build();
}
}

Rightarm:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

//biological right
public class RightArm extends Object3D{

/**
*
*/
private static final long serialVersionUID = -5257845406283197478L;

public RightArm() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-0.5f, -1.5f, -0.5f);
SimpleVector upperRightFront = new SimpleVector(0.5f, -1.5f, -0.5f);
SimpleVector lowerLeftFront = new SimpleVector(-0.5f, 1.5f, -0.5f);
SimpleVector lowerRightFront = new SimpleVector(0.5f, 1.5f, -0.5f);

SimpleVector upperLeftBack = new SimpleVector(-0.5f, -1.5f, 0.5f);
SimpleVector upperRightBack = new SimpleVector(0.5f, -1.5f, 0.5f);
SimpleVector lowerLeftBack = new SimpleVector(-0.5f, 1.5f, 0.5f);
SimpleVector lowerRightBack = new SimpleVector(0.5f, 1.5f, 0.5f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("armfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("armfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("armback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("armback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("armtop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("armtop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armbottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armbottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("armright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("armleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("armleft"));

this.setTransparency(300);

box.setName("rightarm");


box.build();
}
}

Rightleg:
Code: [Select]
package com.aeroshark333.skinviewer.skinparts;

import com.threed.jpct.Object3D;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.TextureManager;

//biological right
public class RightLeg extends Object3D {

/**
*
*/
private static final long serialVersionUID = 8223363127837467932L;

public RightLeg() {

super(12);

final Object3D box = this;

SimpleVector upperLeftFront = new SimpleVector(-0.5f, -1.5f, -0.5f);
SimpleVector upperRightFront = new SimpleVector(0.5f, -1.5f, -0.5f);
SimpleVector lowerLeftFront = new SimpleVector(-0.5f, 1.5f, -0.5f);
SimpleVector lowerRightFront = new SimpleVector(0.5f, 1.5f, -0.5f);

SimpleVector upperLeftBack = new SimpleVector(-0.5f, -1.5f, 0.5f);
SimpleVector upperRightBack = new SimpleVector(0.5f, -1.5f, 0.5f);
SimpleVector lowerLeftBack = new SimpleVector(-0.5f, 1.5f, 0.5f);
SimpleVector lowerRightBack = new SimpleVector(0.5f, 1.5f, 0.5f);

// Front
box.addTriangle(upperLeftFront, 0, 0, lowerLeftFront, 0, 1,
upperRightFront, 1, 0, TextureManager.getInstance()
.getTextureID("legfront"));
box.addTriangle(upperRightFront, 1, 0, lowerLeftFront, 0, 1,
lowerRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("legfront"));
// Back
box.addTriangle(upperLeftBack, 0, 0, upperRightBack, 1, 0,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("legback"));
box.addTriangle(upperRightBack, 1, 0, lowerRightBack, 1, 1,
lowerLeftBack, 0, 1,
TextureManager.getInstance().getTextureID("legback"));
// Top
box.addTriangle(upperLeftBack, 0, 0, upperLeftFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("legtop"));
box.addTriangle(upperRightBack, 1, 0, upperLeftFront, 0, 1,
upperRightFront, 1, 1, TextureManager.getInstance()
.getTextureID("legtop"));
// Bottom
box.addTriangle(lowerLeftBack, 0, 0, lowerRightBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legbottom"));
box.addTriangle(lowerRightBack, 1, 0, lowerRightFront, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legbottom"));
// Right
box.addTriangle(upperLeftFront, 0, 0, upperLeftBack, 1, 0,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legright"));
box.addTriangle(upperLeftBack, 1, 0, lowerLeftBack, 1, 1,
lowerLeftFront, 0, 1, TextureManager.getInstance()
.getTextureID("legright"));
// Left
box.addTriangle(upperRightFront, 0, 0, lowerRightFront, 0, 1,
upperRightBack, 1, 0, TextureManager.getInstance()
.getTextureID("legleft"));
box.addTriangle(upperRightBack, 1, 0, lowerRightFront, 0, 1,
lowerRightBack, 1, 1, TextureManager.getInstance()
.getTextureID("legleft"));

this.setTransparency(300);

box.setName("rightleg");


box.build();
}
}
« Last Edit: December 08, 2014, 04:53:26 pm by AeroShark333 »

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Object3D's transparency issue
« Reply #7 on: December 08, 2014, 05:23:59 pm »
An example in form of a zipped project would help. I can't be bithered to create one out of individual sources.

Offline Lobby

  • int
  • **
  • Posts: 66
    • View Profile
    • flowersoft
Re: Object3D's transparency issue
« Reply #8 on: December 08, 2014, 05:38:28 pm »
As already suggested, a fragment shader using alpha testing would be the best solution. Except if you want semi transparent textures...

Here a little sample how this works: https://dl.dropboxusercontent.com/u/1618711/web/software/AlphaTest.zip

Offline AeroShark333

  • long
  • ***
  • Posts: 149
    • View Profile
Re: Object3D's transparency issue
« Reply #9 on: December 09, 2014, 05:45:14 pm »
Thanks for the replies!

I kind of solved my problem already.
I added
Code: [Select]
box.setSortOffset(9); to both RightLeg.java and LeftLeg.java (which seemed to work)
I think this fix was a bit logical (now that I think about it... :|)

Thanks a lot for the support! (I have no idea what alpha testing is, so I guess it is better I don't have to use that difficult stuff xD)

My final question: Is my app project-worthy? (for this page: http://www.jpct.net/projects.html)

Offline AeroShark333

  • long
  • ***
  • Posts: 149
    • View Profile
Re: Object3D's transparency issue
« Reply #10 on: December 29, 2014, 04:15:39 pm »
The issue in post #2 does not happen on all devices for some reason...
But it does on a few...
Is there an easier solution?

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Object3D's transparency issue
« Reply #11 on: December 29, 2014, 05:24:26 pm »
Can you provide a more detailed screen shot? If it's a transparency issue, it has to appear on all devices. There's no way that the device has any influence on it...unless it's another issue, but i can't tell it from the shots.

Offline AeroShark333

  • long
  • ***
  • Posts: 149
    • View Profile
Re: Object3D's transparency issue
« Reply #12 on: December 31, 2014, 01:25:45 pm »
On tablet the issue is visible, on phones it isn't (I suppose the width of the screen does have an effect on the bug's visibility)

Anyway, here is a screenshot: https://dl.dropboxusercontent.com/u/47988037/Android/Skin%20Viewer%203D/Screenshot/bug.png
(Look at the right arm (biological left arm))

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Object3D's transparency issue
« Reply #13 on: January 01, 2015, 08:06:28 pm »
Looks just like the usual sorting issues that we already described. I don't see any way in which these can depend on the device. On randoness maybe, but not on the device. Given that textures, why are you using transparency anyway? I don't see any transparent parts on them... ???

Offline AeroShark333

  • long
  • ***
  • Posts: 149
    • View Profile
Re: Object3D's transparency issue
« Reply #14 on: January 01, 2015, 08:59:37 pm »
It is possible to use transparent skins in Minecraft.
A skin is a 64x32 png file.
Since every bodypart can have transparent elements, I decided to enable transparency for every part.
Is 'alpha testing' easy to do?
Or are there other solutions?

I tried to make the parts not touch each other using about 0.03f space between the parts. But it did not help at all...
Is it possible to have more drawing/sorting precision? Using the Config perhaps?

What will happen in I enlarge the parts a lot and zoom out the camera? The same?