Skip to main content

Rendering faces out of order...?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
16 replies [Last post]
ACher91
Offline
Joined: 2013-05-08

So, I am making a card game. I have a consistent problem where no matter what I try, java3d renders my objects wrong. Here is what I'm talking about:

When the camera is looking at them from the back, they are all in order as they should be.

But when you rotate around to the other side...

The cards that are actually supposed to be in the back render on top.

I know it's not a normals problem because I checked them in Blender (where I made them as x3ds), and they all point outwards. Furthermore, if I flip the cards over (so that in the first picture, the front sides are facing the camera), I get the same problem but in reverse; the cards render and cover each other up correctly when looked at from the face side, and mess up when looked at from the back side.

This is an absolutely catastrophic problem for my game, because I need to lay the cards in a pile, face up, and they need to be shown in the right order (Egyptian Ratscrew).

So... has anybody seen anything like this before or have any ideas on what's causing this?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
interactivemesh
Offline
Joined: 2006-06-07

This visual effect might be caused by a depth-buffer conflict. You will find several posts related to this subject in the forum.

It would be helpful to get following state informations:

- View: front and back clip policies and distances
- TransformGroup: rotation and translation used to position the cards
- Appearance: polygon and rendering attributes
- Geometry: bounding box size of a card

Could you provide the x3d-file of a card?
What is your system and graphics card?

August

ACher91
Offline
Joined: 2013-05-08

I am having a rather hard time replying with all of this information because every time I try my post gets blocked by their spam filter -.-

For my View object, in my code I do

View theView = univ.getViewer().getView();
theView.setFrontClipDistance(0.01);
theView.setMinimumFrameCycleTime(5);
theView.setSceneAntialiasingEnable(false);

This is actually in here from example code that was left over from a previous project. I don't actually know what any of this does. =S These are all the changes made to the View object.

ACher91
Offline
Joined: 2013-05-08

Oh, nevermind. I was going to post it piece by piece, but apparently, my full message came through somehow. Just read this last one:

ACher91
Offline
Joined: 2013-05-08

Yeah... sorry, I'm a bit of a noob when it comes to java3d. I thought it might have something to do with the cards being very thin, so I tried making one bigger by 5 times, and then by 10 times, to no avail. It's quite a hassle because I have to open up Blender every time, modify it, and export it back out. Anyway, having the cards be that thick is not desirable either, so meh...

Anyway!

So yes, for my View object, in my code I do

View theView = univ.getViewer().getView();
theView.setFrontClipDistance(0.01);
theView.setMinimumFrameCycleTime(5);
theView.setSceneAntialiasingEnable(false);

This is actually in here from example code that was left over from a previous project. I don't actually know what any of this does. =S These are all the changes made to the View object.

Here's a snippet of the code from my Card class:

public static final float cardHeight = .006f;

private int value; //2-10, 1 = ace, 11 = jack, 12 = queen, 13 = king
private Suit suit;

private BranchGroup bg;
public TransformGroup obj_Init = new TransformGroup();
public TransformGroup obj_Rotate = new TransformGroup();

public Card(int v, Suit s)
{
setValue(v);
setSuit(s);
bg = ModelLoader.load(suit.toString() + value + ".x3d");
obj_Rotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
obj_Init.addChild(obj_Rotate);
obj_Rotate.addChild(bg);
}

In Blender, I moved every card to the origin before exporting. So, to position them I just do...

Transform3D cardTransform = new Transform3D();
cardTransform.setTranslation(new Vector3f(0, 6.125f + deckSize*Card.cardHeight, 0));
placed.obj_Rotate.setTransform(cardTransform);

cardHeight is that static variable inside my Card class. It was experimentally determined for how thick a card is, and thus how far apart they should be if they're all stacked together. (For my example screenshots I augmented that value). deckSize is just how many there are.

I have no clue about Appearance or Geometry - I don't touch either of those things.

My system is Windows 7 Home Premium, 64bit, 2 2.9GHz processors, 4GB RAM. The graphics card is ATI Radeon HD 4200.

Lastly, here's an x3d for the ace of clubs:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd">
<X3D version="3.0" profile="Immersive" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.0.xsd">
<head>
<meta name="filename" content="clubs1.x3d" />
<meta name="generator" content="Blender 2.66 (sub 1)" />
</head>
<Scene>
<NavigationInfo headlight="false"
                visibilityLimit="0.0"
                type='"EXAMINE", "ANY"'
                avatarSize="0.25, 1.75, 0.75"
                />
<Background DEF="WO_World"
            groundColor="0.051 0.051 0.051"
            skyColor="0.051 0.051 0.051"
            />
<Transform DEF="OB_ShapeIndexedFaceSet_050_ifs_TRANSFORM"
           translation="0.000000 0.000000 0.000000"
           scale="0.769580 0.769580 0.153916"
           rotation="0.000000 0.707107 0.707107 3.141593"
           >
<Group DEF="group_ME_ShapeIndexedFaceSet_051">
<Shape>
<Appearance>
<ImageTexture DEF="IM_cardz_png_052"
              url='"cardz.png"'
              />
<TextureTransform
                  translation="0.000000 0.000000"
                  scale="1.000000 1.000000"
                  rotation="0.000000"
                  />
<Material DEF="MA_Shape_050"
          diffuseColor="1.000 1.000 1.000"
          specularColor="0.001 0.001 0.001"
          emissiveColor="0.000 0.000 0.000"
          ambientIntensity="0.111"
          shininess="0.098"
          transparency="0.0"
          />
</Appearance>
<IndexedFaceSet solid="true"
                normalPerVertex="true"
                texCoordIndex="0 1 2 3 -1 4 5 6 7 -1 8 9 10 11 -1 12 13 14 15 -1 16 17 18 19 -1 20 21 22 23 -1 24 25 26 27 -1 28 29 30 31 -1 32 33 34 35 -1 36 37 38 39 -1 40 41 42 43 -1 44 45 46 47 -1 48 49 50 51 -1 52 53 54 55 -1 56 57 58 59 -1 60 61 62 63 -1 64 65 66 -1 67 68 69 -1 70 71 72 -1 73 74 75 -1 76 77 78 -1 79 80 81 -1 82 83 84 -1 85 86 87 -1 88 89 90 -1 91 92 93 -1 94 95 96 -1 97 98 99 -1 100 101 102 -1 103 104 105 -1 106 107 108 -1 109 110 111 -1 112 113 114 -1 115 116 117 -1 118 119 120 -1 121 122 123 -1 124 125 126 -1 127 128 129 -1 130 131 132 -1 133 134 135 -1 136 137 138 -1 139 140 141 -1 142 143 144 -1 145 146 147 -1 148 149 150 -1 151 152 153 -1 154 155 156 -1 157 158 159 -1 160 161 162 -1 163 164 165 -1 166 167 168 -1 169 170 171 -1 172 173 174 175 -1 176 177 178 179 -1 180 181 182 183 -1 184 185 186 187 -1 "
                coordIndex="1 21 33 13 -1 27 7 6 26 -1 16 36 26 6 -1 39 19 10 30 -1 17 37 28 8 -1 35 15 4 24 -1 21 1 12 32 -1 18 38 29 9 -1 13 33 22 2 -1 3 23 24 4 -1 19 39 31 11 -1 14 34 23 3 -1 37 17 7 27 -1 30 10 9 29 -1 20 40 32 12 -1 15 35 25 5 -1 3 4 15 -1 3 15 14 -1 15 5 14 -1 5 2 14 -1 5 16 2 -1 16 13 2 -1 16 6 13 -1 6 1 13 -1 7 1 6 -1 12 1 7 -1 7 17 12 -1 17 20 12 -1 17 8 20 -1 8 11 20 -1 8 18 11 -1 18 19 11 -1 18 9 19 -1 9 10 19 -1 23 35 24 -1 23 34 35 -1 34 25 35 -1 34 22 25 -1 22 36 25 -1 22 33 36 -1 33 26 36 -1 33 21 26 -1 21 27 26 -1 21 32 27 -1 32 37 27 -1 32 40 37 -1 40 28 37 -1 40 31 28 -1 31 38 28 -1 31 39 38 -1 39 29 38 -1 39 30 29 -1 34 14 2 22 -1 40 20 11 31 -1 36 16 5 25 -1 38 18 8 28 -1 "
                >
<Coordinate DEF="coords_ME_ShapeIndexedFaceSet_051"
            point="0.000000 0.000000 0.000000 1.000001 1.364643 0.025000 0.975001 1.424999 0.025000 0.914645 1.449999 0.025000 -0.914644 1.450000 0.025000 -0.975000 1.424999 0.025000 -1.000000 1.364644 0.025000 -1.000000 -1.364644 0.025000 -0.975000 -1.424999 0.025000 -0.914645 -1.450000 0.025000 0.914644 -1.450001 0.025000 0.974999 -1.425001 0.025000 0.999999 -1.364646 0.025000 0.990814 1.399501 0.025000 0.947993 1.442322 0.025000 -0.947992 1.442323 0.025000 -0.990813 1.399502 0.025000 -0.990813 -1.399502 0.025000 -0.947993 -1.442323 0.025000 0.947992 -1.442324 0.025000 0.990813 -1.399503 0.025000 1.000001 1.364643 -0.025000 0.975001 1.424999 -0.025000 0.914645 1.449999 -0.025000 -0.914644 1.450000 -0.025000 -0.975000 1.424999 -0.025000 -1.000000 1.364644 -0.025000 -1.000000 -1.364644 -0.025000 -0.975000 -1.424999 -0.025000 -0.914645 -1.450000 -0.025000 0.914644 -1.450001 -0.025000 0.974999 -1.425001 -0.025000 0.999999 -1.364646 -0.025000 0.990814 1.399501 -0.025000 0.947993 1.442322 -0.025000 -0.947992 1.442323 -0.025000 -0.990813 1.399502 -0.025000 -0.990813 -1.399502 -0.025000 -0.947993 -1.442323 -0.025000 0.947992 -1.442324 -0.025000 0.990813 -1.399503 -0.025000 "
            />
<Normal DEF="normals_ME_ShapeIndexedFaceSet_051"
        vector="0.000000 0.000000 0.000000 0.727775 0.094272 0.679281 0.534837 0.526780 0.660604 0.082492 0.726157 0.682546 -0.082492 0.726157 0.682546 -0.534837 0.526780 0.660604 -0.727775 0.094272 0.679281 -0.727775 -0.094272 0.679281 -0.534837 -0.526780 0.660604 -0.082492 -0.726157 0.682546 0.082492 -0.726157 0.682546 0.534837 -0.526780 0.660604 0.727775 -0.094272 0.679281 0.677511 0.291574 0.675222 0.287729 0.683798 0.670522 -0.287729 0.683798 0.670522 -0.677511 0.291574 0.675222 -0.677511 -0.291574 0.675222 -0.287729 -0.683798 0.670522 0.287729 -0.683798 0.670522 0.677511 -0.291574 0.675222 0.727775 0.094272 -0.679281 0.534837 0.526780 -0.660604 0.082492 0.726157 -0.682546 -0.082492 0.726157 -0.682546 -0.534837 0.526780 -0.660604 -0.727775 0.094272 -0.679281 -0.727775 -0.094272 -0.679281 -0.534837 -0.526780 -0.660604 -0.082492 -0.726157 -0.682546 0.082492 -0.726157 -0.682546 0.534837 -0.526780 -0.660604 0.727775 -0.094272 -0.679281 0.677511 0.291574 -0.675222 0.287729 0.683798 -0.670522 -0.287729 0.683798 -0.670522 -0.677511 0.291574 -0.675222 -0.677511 -0.291574 -0.675222 -0.287729 -0.683798 -0.670522 0.287729 -0.683798 -0.670522 0.677511 -0.291574 -0.675222 "
        />
<TextureCoordinate point="0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0735 0.9995 0.0032 0.9995 0.0019 0.9990 0.0735 0.9995 0.0019 0.9990 0.0748 0.9990 0.0019 0.9990 0.0009 0.9978 0.0748 0.9990 0.0009 0.9978 0.0758 0.9978 0.0748 0.9990 0.0009 0.9978 0.0003 0.9960 0.0758 0.9978 0.0003 0.9960 0.0764 0.9960 0.0758 0.9978 0.0003 0.9960 -0.0001 0.9936 0.0764 0.9960 -0.0001 0.9936 0.0768 0.9936 0.0764 0.9960 -0.0001 0.8054 0.0768 0.9936 -0.0001 0.9936 0.0768 0.8054 0.0768 0.9936 -0.0001 0.8054 -0.0001 0.8054 0.0003 0.8030 0.0768 0.8054 0.0003 0.8030 0.0764 0.8030 0.0768 0.8054 0.0003 0.8030 0.0009 0.8012 0.0764 0.8030 0.0009 0.8012 0.0758 0.8012 0.0764 0.8030 0.0009 0.8012 0.0019 0.8000 0.0758 0.8012 0.0019 0.8000 0.0748 0.8000 0.0758 0.8012 0.0019 0.8000 0.0032 0.7995 0.0748 0.8000 0.0032 0.7995 0.0735 0.7995 0.0748 0.8000 0.2273 0.0001 0.1557 0.0007 0.1570 0.0001 0.2273 0.0001 0.2286 0.0006 0.1557 0.0007 0.2286 0.0006 0.1547 0.0018 0.1557 0.0007 0.2286 0.0006 0.2297 0.0018 0.1547 0.0018 0.2297 0.0018 0.1541 0.0036 0.1547 0.0018 0.2297 0.0018 0.2303 0.0036 0.1541 0.0036 0.2303 0.0036 0.1537 0.0060 0.1541 0.0036 0.2303 0.0036 0.2306 0.0060 0.1537 0.0060 0.2306 0.0060 0.1537 0.1941 0.1537 0.0060 0.2306 0.0060 0.2306 0.1941 0.1537 0.1941 0.2306 0.1941 0.1541 0.1965 0.1537 0.1941 0.2306 0.1941 0.2303 0.1965 0.1541 0.1965 0.2303 0.1965 0.1547 0.1983 0.1541 0.1965 0.2303 0.1965 0.2297 0.1983 0.1547 0.1983 0.2297 0.1983 0.1557 0.1995 0.1547 0.1983 0.2297 0.1983 0.2286 0.1995 0.1557 0.1995 0.2286 0.1995 0.1570 0.2000 0.1557 0.1995 0.2286 0.1995 0.2273 0.2000 0.1570 0.2000 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 0.0206 0.8850 " />
</IndexedFaceSet>
</Shape>
</Group>
</Transform>
</Scene>
</X3D>
interactivemesh
Offline
Joined: 2006-06-07

Thanks for providing your code and x3d file.

I wasn't successful in reproducing your visual effect on my Win 7-64/GeForce GTX 560 Ti system.

The polygon and rendering attributes of the loaded Appearance are both 'null'. So the default values will be applied and these can't/shouldn't cause any problems.

The default front/back distances ( = visual depth range in front of the 'camera') are 0.1/10.0. Your choice of front distance 0.01 should neither cause a problem. Try 0.1/20.0 as front/back distances for your scene and check if all cards are rendered.

Your x3d file includes a Transform node with a rotation and a non-uniform scale of "0.769580 0.769580 0.153916". This scaling might be a problem.

I applied this Transform to the coordinates and exported a new x3d file 'CardTransformed'. Please create a copy for each of your images and give these files a try. Or create the cards in Blender without scaling (if possible).

CardTransformed.x3d

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.2//EN" "http://www.web3d.org/specifications/x3d-3.2.dtd">
<X3D version="3.2" profile="Interchange"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.2.xsd">
  <head>
    <meta name="date" content="2013/05/10"/>
    <meta name="title" content="CardTransformed.x3d"/>
  </head>
  <Scene>
    <Shape>
      <Appearance>
        <ImageTexture url='"cardz.png"'/>
        <Material
          ambientIntensity="0.0"
          diffuseColor="1.0 1.0 1.0"
          emissiveColor="0.0 0.0 0.0"
          specularColor="0.001 0.001 0.001"
          shininess="0.098"
        />
      </Appearance>
      <IndexedFaceSet ccw="true" colorPerVertex="true" convex="true" creaseAngle="1.797689" normalPerVertex="true" solid="true"
         coordIndex="1 33 13 -1 1 21 33 -1 27 6 26 -1 27 7 6 -1 16 26 6 -1 16 36 26 -1 39 10 30 -1 39 19 10 -1 17 28 8 -1 17 37 28 -1 35 4 24 -1 35 15 4 -1 21 12 32 -1 21 1 12 -1 18 29 9 -1 18 38 29 -1 13 22 2 -1 13 33 22 -1 3 24 4 -1 3 23 24 -1 19 31 11 -1 19 39 31 -1 14 23 3 -1 14 34 23 -1 37 7 27 -1 37 17 7 -1 30 9 29 -1 30 10 9 -1 20 32 12 -1 20 40 32 -1 15 25 5 -1 15 35 25 -1 3 4 15 -1 3 15 14 -1 15 5 14 -1 5 2 14 -1 5 16 2 -1 16 13 2 -1 16 6 13 -1 6 1 13 -1 7 1 6 -1 12 1 7 -1 7 17 12 -1 17 20 12 -1 17 8 20 -1 8 11 20 -1 8 18 11 -1 18 19 11 -1 18 9 19 -1 9 10 19 -1 23 35 24 -1 23 34 35 -1 34 25 35 -1 34 22 25 -1 22 36 25 -1 22 33 36 -1 33 26 36 -1 33 21 26 -1 21 27 26 -1 21 32 27 -1 32 37 27 -1 32 40 37 -1 40 28 37 -1 40 31 28 -1 31 38 28 -1 31 39 38 -1 39 29 38 -1 39 30 29 -1 34 2 22 -1 34 14 2 -1 40 11 31 -1 40 20 11 -1 36 5 25 -1 36 16 5 -1 38 8 28 -1 38 18 8 -1"
         normalIndex="0 1 2 -1 0 3 1 -1 4 5 6 -1 4 7 5 -1 8 6 5 -1 8 9 6 -1 10 11 12 -1 10 13 11 -1 14 15 16 -1 14 17 15 -1 18 19 20 -1 18 21 19 -1 3 22 23 -1 3 0 22 -1 24 25 26 -1 24 27 25 -1 2 28 29 -1 2 1 28 -1 30 20 19 -1 30 31 20 -1 13 32 33 -1 13 10 32 -1 34 31 30 -1 34 35 31 -1 17 7 4 -1 17 14 7 -1 12 26 25 -1 12 11 26 -1 36 23 22 -1 36 37 23 -1 21 38 39 -1 21 18 38 -1 30 19 21 -1 30 21 34 -1 21 39 34 -1 39 29 34 -1 39 8 29 -1 8 2 29 -1 8 5 2 -1 5 0 2 -1 7 0 5 -1 22 0 7 -1 7 14 22 -1 14 36 22 -1 14 16 36 -1 16 33 36 -1 16 24 33 -1 24 13 33 -1 24 26 13 -1 26 11 13 -1 31 18 20 -1 31 35 18 -1 35 38 18 -1 35 28 38 -1 28 9 38 -1 28 1 9 -1 1 6 9 -1 1 3 6 -1 3 4 6 -1 3 23 4 -1 23 17 4 -1 23 37 17 -1 37 15 17 -1 37 32 15 -1 32 27 15 -1 32 10 27 -1 10 25 27 -1 10 12 25 -1 35 29 28 -1 35 34 29 -1 37 33 32 -1 37 36 33 -1 9 39 38 -1 9 8 39 -1 27 16 15 -1 27 24 16 -1"
         texCoordIndex="0 2 3 -1 0 1 2 -1 4 6 7 -1 4 5 6 -1 8 10 11 -1 8 9 10 -1 12 14 15 -1 12 13 14 -1 16 18 19 -1 16 17 18 -1 20 22 23 -1 20 21 22 -1 24 26 27 -1 24 25 26 -1 28 30 31 -1 28 29 30 -1 32 34 35 -1 32 33 34 -1 36 38 39 -1 36 37 38 -1 40 42 43 -1 40 41 42 -1 44 46 47 -1 44 45 46 -1 48 50 51 -1 48 49 50 -1 52 54 55 -1 52 53 54 -1 56 58 59 -1 56 57 58 -1 60 62 63 -1 60 61 62 -1 64 65 66 -1 67 68 69 -1 70 71 72 -1 73 74 75 -1 76 77 78 -1 79 80 81 -1 82 83 84 -1 85 86 87 -1 88 89 90 -1 91 92 93 -1 94 95 96 -1 97 98 99 -1 100 101 102 -1 103 104 105 -1 106 107 108 -1 109 110 111 -1 112 113 114 -1 115 116 117 -1 118 119 120 -1 121 122 123 -1 124 125 126 -1 127 128 129 -1 130 131 132 -1 133 134 135 -1 136 137 138 -1 139 140 141 -1 142 143 144 -1 145 146 147 -1 148 149 150 -1 151 152 153 -1 154 155 156 -1 157 158 159 -1 160 161 162 -1 163 164 165 -1 166 167 168 -1 169 170 171 -1 172 174 175 -1 172 173 174 -1 176 178 179 -1 176 177 178 -1 180 182 183 -1 180 181 182 -1 184 186 187 -1 184 185 186 -1"
        >
        <Coordinate point="0.0 0.0 0.0 -0.769581 0.003848 1.050202 -0.750341 0.003848 1.096651 -0.703893 0.003848 1.11589 0.703892 0.003848 1.115891 0.750341 0.003848 1.096651 0.76958 0.003848 1.050203 0.76958 0.003848 -1.050203 0.750341 0.003848 -1.096651 0.703893 0.003848 -1.115891 -0.703892 0.003848 -1.115892 -0.75034 0.003848 -1.096652 -0.769579 0.003848 -1.050204 -0.762511 0.003848 1.077028 -0.729556 0.003848 1.109982 0.729556 0.003848 1.109983 0.76251 0.003848 1.077029 0.76251 0.003848 -1.077029 0.729556 0.003848 -1.109983 -0.729556 0.003848 -1.109984 -0.76251 0.003848 -1.077029 -0.769581 -0.003848 1.050202 -0.750341 -0.003848 1.096651 -0.703893 -0.003848 1.11589 0.703892 -0.003848 1.115891 0.750341 -0.003848 1.096651 0.76958 -0.003848 1.050203 0.76958 -0.003848 -1.050203 0.750341 -0.003848 -1.096651 0.703893 -0.003848 -1.115891 -0.703892 -0.003848 -1.115892 -0.75034 -0.003848 -1.096652 -0.769579 -0.003848 -1.050204 -0.762511 -0.003848 1.077028 -0.729556 -0.003848 1.109982 0.729556 -0.003848 1.109983 0.76251 -0.003848 1.077029 0.76251 -0.003848 -1.077029 0.729556 -0.003848 -1.109983 -0.729556 -0.003848 -1.109984 -0.76251 -0.003848 -1.077029" />
        <Normal vector="-0.694092 0.709715 0.120581 -0.659372 -0.710582 0.245564 -0.631626 0.710582 0.310035 -0.701904 -0.709715 0.06029 0.701904 -0.709715 -0.060291 0.701904 0.709715 0.060291 0.694092 -0.709715 0.120582 0.694092 0.709715 -0.120582 0.65937 0.710582 0.245568 0.631622 -0.710582 0.310043 -0.234544 -0.711757 -0.662111 -0.142614 0.317852 -0.937353 -0.071307 -0.317852 -0.945455 -0.309413 0.711757 -0.630608 0.631622 0.710582 -0.310043 0.53369 -0.714896 -0.451773 0.45984 0.714896 -0.526755 0.65937 -0.710582 -0.245568 0.234547 -0.711757 0.66211 0.142616 0.317852 0.937353 0.071308 -0.317852 0.945455 0.309417 0.711757 0.630605 -0.701905 0.709715 -0.060286 -0.694094 -0.709715 -0.120572 0.234551 0.711757 -0.662108 0.124934 -0.556888 -0.821137 0.062467 0.556888 -0.828235 0.309424 -0.711757 -0.630602 -0.533688 -0.714898 0.451772 -0.459828 0.714898 0.526763 -0.062466 0.556888 0.828235 -0.124932 -0.556888 0.821138 -0.45983 -0.714896 -0.526763 -0.533683 0.714896 -0.45178 -0.234541 0.711756 0.662113 -0.309406 -0.711756 0.630612 -0.659372 0.710583 -0.245561 -0.631622 -0.710583 -0.310042 0.459834 -0.714896 0.526759 0.533687 0.714896 0.451775" />
        <TextureCoordinate point="0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0735 0.9995 0.0032 0.9995 0.0019 0.999 0.0735 0.9995 0.0019 0.999 0.0748 0.999 0.0019 0.999 9.0E-4 0.9978 0.0748 0.999 9.0E-4 0.9978 0.0758 0.9978 0.0748 0.999 9.0E-4 0.9978 3.0E-4 0.996 0.0758 0.9978 3.0E-4 0.996 0.0764 0.996 0.0758 0.9978 3.0E-4 0.996 -1.0E-4 0.9936 0.0764 0.996 -1.0E-4 0.9936 0.0768 0.9936 0.0764 0.996 -1.0E-4 0.8054 0.0768 0.9936 -1.0E-4 0.9936 0.0768 0.8054 0.0768 0.9936 -1.0E-4 0.8054 -1.0E-4 0.8054 3.0E-4 0.803 0.0768 0.8054 3.0E-4 0.803 0.0764 0.803 0.0768 0.8054 3.0E-4 0.803 9.0E-4 0.8012 0.0764 0.803 9.0E-4 0.8012 0.0758 0.8012 0.0764 0.803 9.0E-4 0.8012 0.0019 0.8 0.0758 0.8012 0.0019 0.8 0.0748 0.8 0.0758 0.8012 0.0019 0.8 0.0032 0.7995 0.0748 0.8 0.0032 0.7995 0.0735 0.7995 0.0748 0.8 0.2273 1.0E-4 0.1557 7.0E-4 0.157 1.0E-4 0.2273 1.0E-4 0.2286 6.0E-4 0.1557 7.0E-4 0.2286 6.0E-4 0.1547 0.0018 0.1557 7.0E-4 0.2286 6.0E-4 0.2297 0.0018 0.1547 0.0018 0.2297 0.0018 0.1541 0.0036 0.1547 0.0018 0.2297 0.0018 0.2303 0.0036 0.1541 0.0036 0.2303 0.0036 0.1537 0.006 0.1541 0.0036 0.2303 0.0036 0.2306 0.006 0.1537 0.006 0.2306 0.006 0.1537 0.1941 0.1537 0.006 0.2306 0.006 0.2306 0.1941 0.1537 0.1941 0.2306 0.1941 0.1541 0.1965 0.1537 0.1941 0.2306 0.1941 0.2303 0.1965 0.1541 0.1965 0.2303 0.1965 0.1547 0.1983 0.1541 0.1965 0.2303 0.1965 0.2297 0.1983 0.1547 0.1983 0.2297 0.1983 0.1557 0.1995 0.1547 0.1983 0.2297 0.1983 0.2286 0.1995 0.1557 0.1995 0.2286 0.1995 0.157 0.2 0.1557 0.1995 0.2286 0.1995 0.2273 0.2 0.157 0.2 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885 0.0206 0.885" />
      </IndexedFaceSet>
    </Shape>
  </Scene>
</X3D>

Good luck, August

ACher91
Offline
Joined: 2013-05-08

interactivemesh wrote:

I wasn't successful in reproducing your visual effect on my Win 7-64/GeForce GTX 560 Ti system.

...Seriously? So they just show up normally from both sides for you?

interactivemesh wrote:

The default front/back distances ( = visual depth range in front of the 'camera') are 0.1/10.0. Your choice of front distance 0.01 should neither cause a problem. Try 0.1/20.0 as front/back distances for your scene and check if all cards are rendered.

Tried this. Still no difference.

interactivemesh wrote:

I applied this Transform to the coordinates and exported a new x3d file 'CardTransformed'. Please create a copy for each of your images and give these files a try. Or create the cards in Blender without scaling (if possible).

Well, I took the "new" x3d you made. I temporarily set all cards to use that same file, so they all showed up as aces of clubs, and STILL no difference! They still randomly show through each other from the front side. ...Gee, this is some "visual effect", huh?

...Any more ideas? :/

ACher91
Offline
Joined: 2013-05-08

...Okay, wow, you know what.

theView.setDepthBufferFreezeTransparent(false);

Stackoverflow tipped me off about this one method call. Adding this one simple line solved what was a monstrous, legendary monument of a problem that I thought I was never going to solve.

Like, seriously.... wow.

Ha. Well, I guess my problem is solved!

interactivemesh
Offline
Joined: 2006-06-07

Good news!

But why does calling 'theView.setDepthBufferFreezeTransparent(false)' solve the problem?

Are the images/textures transparent? In this case XModelLoader adds a TransparencyAttributes to the Appearance and the objects will be rendered in the transparent rendering pass with disabled depth buffer writes.

Could you provide one of the images?

August

ACher91
Offline
Joined: 2013-05-08

I have no idea why, but I'm just happy it does. Hah.. XD

And um... How would they be transparent? If that was the case, you wouldn't even be able to see them, right...? In my giant cardz.png, they're all there. Also, in the x3d, the transparency value is set to "0.0"...

What do you mean provide one of the images? I thought I already did when I posted the ace of clubs' x3d. If you mean the picture file where the textures are coming from, I suppose I could attach that...

interactivemesh
Offline
Joined: 2006-06-07

Yes, I'm interested in the image/picture png-file(s) which are used for the textures. I would like to check if my XModelLoader works correctly.

Unfortunately, the provided link 'cardz.png' failes (0 KB). Does the download work for you? If you don't mind, send them to info [at] interactivemesh [dot] com.

Thanks a lot, August

ACher91
Offline
Joined: 2013-05-08

Mmkay, sent.

interactivemesh
Offline
Joined: 2006-06-07

The texture image 'cardz.png' includes besides the r, g, and b values also an alpha value per pixel. But all alphas are equal to 1! There is no transparency or translucence in the file.

If the XModelLoader detects an alpha channel an image with at least one alpha value less then 1 is assumed and a TransparencyAttributes is added to the Appearance. In consequence the objects will be rendered in the transparent rendering pass with disabled depth buffer writes. This leads to the reported issue.

If the image 'cardz.png' could be converted to a png-file without an alpha channel then no TransparencyAttributes will be created and the smaller file will be read faster.

August

ACher91
Offline
Joined: 2013-05-08

Hm... would you happen to know how I could possibly extract the Appearance objects out of my cards' BranchGroups? I am quite frustrated with how stupid this whole process is because of how inaccessible everything is. Apparently to even be able to get at a BranchGroup's Appearance object, I have to loop through its children and try to get it from there? And even then, there's like 10 classes that the children could possibly be, and some of them have an Appearance and some don't. -.-

I eventually just tried using reflection to look for a "getAppearance" method in any children. None were found. ...what does this mean? Does this mean that there are no Appearances set on it anyway and that the model loader is indeed working fine?

...Also, I tried getting rid of the transparency values in the png via saving it through ms paint. Still, even when I use that file and take out the line setting the freeze buffer transparent thingy to false, it goes back to doing the messed up visual effect. It seems like it always needs the setDepthBufferFreezeTransparent(false); to work correctly...

interactivemesh
Offline
Joined: 2006-06-07

The Appearance component is only an attribute of a Shape3D, so you have to traverse the loaded BranchGroup for Shape3D nodes. Alternatively you can name the X3D-Appearance nodes with the help of the DEF attribute:

<Appearance> -> <Appearance DEF="myUniqueAppearName">

Now you can retrieve the named objects from the loaded Scene by calling:

java.util.Hashtable namedObjects = Scene.getNamedObjects();

Appearance myAppear = (Appearance)namedObjects.get("myUniqueAppearName");

MS Paint seems to export png images always with alpha values even if there is no transparency.

I used GIMP 2.8 and
- exported your file as bmp (24 bit R8G8B8)
- opened this bmp file
- exported it as png file.

The result is a png image without alpha values. Probably there might exist a more straightforward process. I'm going to mail 'cardz-rgb.png' to you.

August

ACher91
Offline
Joined: 2013-05-08

Huh... interesting. This new png file is able to work without calling setDepthBufferFreezeTransparent(false);

So... this means... that the XModelLoader wrongfully inserts transparency values where they shouldn't be?

Ehh. My problem has been solved already, so all things considered, I'm not too worried about all this. Still, I'd like to know what exactly that setDepthBufferFreezeTransparent method does. Is it particularly bad setting it to false? Does it mean that I can't have transparency anywhere in my scene, even if I wanted to? (I got the impression that you seemed rather opposed to me using that as a solution.)

interactivemesh
Offline
Joined: 2006-06-07

I.

XModelLoader only checks by default if a loaded image (= java.awt.image.BufferedImage) has an alpha-channel assuming that this implies a non-fully-opaque image. This check is for 'free' but testing each pixel's alpha-value is time consuming.

XModelLoader's "Java 3D Extensions for X3D files" (see javadoc) allows to determine exactly the Java 3D's image and texture types.

Replacing the original ImageTexture element

<ImageTexture DEF="IM_cardz_png_052" url='"cardz.png"' />

in your card.x3d file with
<ImageTexture DEF="IM_cardz_png_052" url='"cardz.png"' >
  <MetadataSet name='SceneGraphObject'>;
    <MetadataString name='TextureFormat' value='RGB' />   
    <MetadataSet name='ImageComponent'>
      <MetadataString name='ImageFormat' value='FORMAT_RGB' />
    </MetadataSet>                     
  </MetadataSet>
</ImageTexture>

forces the XModelLoader to convert the loaded image according to the required format types. In this case the alpha-channel of the BufferedImage will be removed. Calling 'View.setDepthBufferFreezeTransparent(false) should now be
unnecessary.

II.

Use as much transparency ojects as you like in your scene, but don't add a TransparencyAttributes component to an Appearance if not needed.

Several strategies exist for rendering transparent 3D objects. None of these solves all requirements (search the web). Choosing the right one for a concrete scene is the developer's task.

Java 3D's transparency capabilities are limited. Java 3D assumes a mixed scene of opaque and depth-sorted transparent objects (see View.setTransparencySortingPolicy()). The rendering strategy is to render first the opaque objects. Before the transparent objects are rendered subsequently the depth-buffer is frozen. In consequence the transparent objects don't write their depth-value into the depth-buffer. This often leads to well rendered mixed scenes.

Your scene exists of (pseudo-) transparent objects only. In this case freezing the depth-buffer isn't helpful. Calling 'View.setDepthBufferFreezeTransparent(false)' simply switches off the Java 3D default state.

August