1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| static class Element extends Shape3D implements GeometryUpdater { final static Color3f WHITE = new Color3f(1, 1, 1); final static Color3f BLACK = new Color3f(0, 0, 0); final static int CAPABILITIES = GeometryArray.COORDINATES | GeometryArray.BY_REFERENCE | GeometryArray.TEXTURE_COORDINATE_2; final static TransparencyAttributes TRANSATT = TRANSATT(); final static TransparencyAttributes TRANSATT() { TransparencyAttributes transAtt = new TransparencyAttributes(); transAtt.setTransparencyMode(TransparencyAttributes.BLENDED); return transAtt; } final static TextureAttributes TEXATT = TEXATT(); final static TextureAttributes TEXATT() { TextureAttributes texAtt = new TextureAttributes(); texAtt.setTextureMode(TextureAttributes.MODULATE); texAtt.setTextureBlendColor(1, 1, 1, 1); return texAtt; } final static RenderingAttributes RENDATT = RENDATT(); final static RenderingAttributes RENDATT() { RenderingAttributes rendAtt = new RenderingAttributes(); rendAtt.setIgnoreVertexColors(true); return rendAtt; } final static PolygonAttributes POLYATT = POLYATT(); final static PolygonAttributes POLYATT() { PolygonAttributes polyatt = new PolygonAttributes(); polyatt.setCullFace(PolygonAttributes.CULL_NONE); return polyatt; } final static Material MATERIAL = new Material(BLACK, WHITE, BLACK, BLACK, 0); final static float UV[] = { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1 }; float xpos, ypos, xdim, ydim, depth; Point3f c1 = new Point3f(), c2 = new Point3f(), c3 = new Point3f(), c4 = new Point3f(), corners[] = new Point3f[6]; float coordinates[] = new float[18]; TriangleArray geometry; Appearance surface; Element(float xp, float xd, float yp, float yd, float deep, Texture texture) { depth = 0 - deep; corners[0] = c1; corners[1] = c2; corners[2] = c3; corners[3] = c2; corners[4] = c3; corners[5] = c4; surface = new Appearance(); surface.setTexture(texture); surface.setTextureAttributes(TEXATT); surface.setMaterial(MATERIAL); surface.setTransparencyAttributes(TRANSATT); surface.setRenderingAttributes(RENDATT); surface.setPolygonAttributes(POLYATT); geometry = new TriangleArray(6, CAPABILITIES); geometry.setCoordRefFloat(coordinates); geometry.setTexCoordRefFloat(0, UV); setGeometry(geometry); setAppearance(surface); geometry.setCapability(GeometryArray.ALLOW_REF_DATA_READ); geometry.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE); reset(xp, xd, yp, yd); } void position(float xp, float yp) { xpos = xp; ypos = yp; reset(); } void resize(float xd, float yd) { xdim = xd; ydim = yd; reset(); } void reset(float xp, float xd, float yp, float yd) { xpos = xp; ypos = yp; xdim = xd; ydim = yd; reset(); } void reset() { float xmax = xpos + xdim, ymax = ypos + ydim; c1.set(xpos, ypos, depth); c2.set(xpos, ymax, depth); c3.set(xmax, ypos, depth); c4.set(xmax, ymax, depth); update(); } void update() { System.out.println("updating data?"); geometry.updateData(this); System.out.println("done."); } public void updateData(Geometry data) { System.out.println("updating data!"); int entry = 0, c = 0; Point3f corner; while(c < 6) { corner = corners[c++]; coordinates[entry++] = corner.x; coordinates[entry++] = corner.y; coordinates[entry++] = corner.z; } } } |