Package javax.media.j3d

Examples of javax.media.j3d.TriangleArray


    }

    // Create a triangle array using NIO.
    // Unfortunately, Sun picking utilities don't handle NIO very well, thus
    // we need to overload a method
    TriangleArray ta = new TriangleArray(triangles.length, GeometryArray.BY_REFERENCE|GeometryArray.USE_NIO_BUFFER|GeometryArray.COORDINATES|GeometryArray.NORMALS|GeometryArray.COLOR_3) {
      public double[] getCoordRefDouble() {
        // When picking, tests have shown that NIO buffer copy has no noticeable impact
        // on performance. So, it is actually better to copy the array each time the picking is
        // done than to hog memory with a permanent copy.
        // It is also still better to copy the buffer only when picking rather than at each rendering
        double[] array = new double[getVertexCount()*3];
        DoubleBuffer db = (DoubleBuffer)super.getCoordRefBuffer().getBuffer();
        db.rewind();
        db.get(array); // optimized get
        return array;
      }
    };
      ta.setCoordRefBuffer(new J3DBuffer(nioCoords));

      // Use Java3D utilities to compute normals
    GeometryInfo gi = new GeometryInfo(GeometryInfo.TRIANGLE_ARRAY);
    double[] coords = new double[data[0].length*3];
    nioCoords.position(0);
    nioCoords.get(coords);
    gi.setCoordinates(coords);
        // generate normals
        NormalGenerator ng = new NormalGenerator();
        ng.generateNormals(gi);
        Vector3f[] n3f = gi.getNormals();
        int[] ni = gi.getNormalIndices();
        float[] tmp = new float[3];
    for (int i=0; i<ni.length; ++i) {
      n3f[ni[i]].get(tmp);
      nioNormals.put(tmp);
    }
    ta.setNormalRefBuffer(new J3DBuffer(nioNormals));
       
    // Setup color buffer
    ta.setColorRefBuffer(new J3DBuffer(nioColors));
      ta.setCapability(TriangleArray.ALLOW_COLOR_WRITE);
      ta.setCapabilityIsFrequent(TriangleArray.ALLOW_COLOR_WRITE);
     
      Shape3D shape3d = new Shape3D(ta);
     
    // The appearance of a shape has many interesting features.
      // In particular, in case one wants to display lines (edges) over the shape,
View Full Code Here


          LineArray lineArray = (LineArray)geometryArray;
          for (int i = 0, n = lineArray.getVertexCount(); i < n; i += 2) {
            writeLine(lineArray, i, i + 1, vertexIndexSubstitutes, textureCoordinatesIndexSubstitutes);
          }
        } else if (geometryArray instanceof TriangleArray) {
          TriangleArray triangleArray = (TriangleArray)geometryArray;
          for (int i = 0, n = triangleArray.getVertexCount(); i < n; i += 3) {
            writeTriangle(triangleArray, i, i + 1, i + 2,
                vertexIndexSubstitutes, normalIndexSubstitutes, oppositeSideNormalIndexSubstitutes,  
                normalsDefined, textureCoordinatesIndexSubstitutes, textureCoordinatesGenerated, cullFace);
          }
        } else if (geometryArray instanceof QuadArray) {
View Full Code Here

            }
          }
        }
      } else {
        if (geometryArray instanceof TriangleArray) {
          TriangleArray triangleArray = (TriangleArray)geometryArray;
          geometryPath = new GeneralPath(GeneralPath.WIND_NON_ZERO, 1000);
          for (int i = 0, triangleIndex = 0; i < vertexCount; i += 3) {
            addTriangleToPath(triangleArray, i, i + 1, i + 2, vertices,
                geometryPath, triangleIndex++, nodeArea);
          }
View Full Code Here

            for (int i = 0, n = lineArray.getVertexCount(); i < n; i += 2) {
              exportLine(lineArray, i, i + 1, verticesIndices, i);
            }
          } else {
            if (geometryArray instanceof TriangleArray) {
              TriangleArray triangleArray = (TriangleArray)geometryArray;
              for (int i = 0, n = triangleArray.getVertexCount(), triangleIndex = 0; i < n; i += 3) {
                triangleIndex = exportTriangle(triangleArray, i, i + 1, i + 2,
                    verticesIndices, triangleIndex, vertices, exportedTriangles);
              }
            } else if (geometryArray instanceof QuadArray) {
              QuadArray quadArray = (QuadArray)geometryArray;
View Full Code Here

        leafShape3D.setAppearance(appearance);
    }

    private void createLeafGeometry() {
        leafGeometry = new TriangleArray(3, GeometryArray.COORDINATES | GeometryArray.NORMALS);
        leafGeometry.setCapability(TriangleArray.ALLOW_COORDINATE_WRITE);
        resetGeometryPoints();
        leafShape3D.setGeometry(leafGeometry);

        Vector3f polygonNormal = NormalHelper.computeNormal(new Point3d(0, 0, 0), state.getEndPoint1().toPointValue(),
View Full Code Here

        leafShape3D.setAppearance(appearance);
    }

    private void createLeafGeometry() {
        leafGeometry = new TriangleArray(3, GeometryArray.COORDINATES | GeometryArray.NORMALS);
        leafGeometry.setCapability(TriangleArray.ALLOW_COORDINATE_WRITE);
        leafGeometry.setCoordinate(0, new Point3d(0, 0, 0));
        resetGeometryPoints();
        leafShape3D.setGeometry(leafGeometry);
View Full Code Here

        assertNotNull(leafShape3D);

        // test position and geometry
        Geometry leafGeometry = leafShape3D.getGeometry();
        assertTrue(leafGeometry instanceof TriangleArray);
        TriangleArray leafTriangle = (TriangleArray) leafGeometry;
        assertEquals(3, leafTriangle.getVertexCount());

        Point3d actualStartPoint = new Point3d();
        Point3d actualEndPoint1 = new Point3d();
        Point3d actualEndPoint2 = new Point3d();
        leafTriangle.getCoordinate(0, actualStartPoint);
        leafTriangle.getCoordinate(1, actualEndPoint1);
        leafTriangle.getCoordinate(2, actualEndPoint2);
        PointTestHelper.assertPointEquals(new Point3d(0, 0, 0), actualStartPoint);
        PointTestHelper.assertPointEquals(leaf3DState.getEndPoint1().toPointValue(), actualEndPoint1);
        PointTestHelper.assertPointEquals(leaf3DState.getEndPoint2().toPointValue(), actualEndPoint2);
    }
View Full Code Here

/*      */     }
/*      */
/* 2554 */     GeometryArray ga = null;
/* 2555 */     switch (this.prim) {
/*      */     case 1:
/* 2557 */       TriangleArray ta = new TriangleArray(vertexCount, vertexFormat, this.texCoordSetCount, this.texCoordSetMap);
/*      */
/* 2559 */       ga = ta;
/* 2560 */       break;
/*      */     case 2:
/* 2563 */       QuadArray qa = new QuadArray(vertexCount, vertexFormat, this.texCoordSetCount, this.texCoordSetMap);
View Full Code Here

/* 402 */       totalVerts += this.currPrimEndVertex[i] - this.currPrimStartVertex[i];
/*     */     }
/*     */
/* 407 */     if (((this.flags & 0x1) != 0) && ((this.flags & 0x2) != 0))
/*     */     {
/* 409 */       obj = new TriangleArray(totalVerts, 35, 1, this.texCoordSetMap);
/*     */     }
/* 416 */     else if (((this.flags & 0x1) == 0) && ((this.flags & 0x2) != 0))
/*     */     {
/* 418 */       obj = new TriangleArray(totalVerts, 33, 1, this.texCoordSetMap);
/*     */     }
/* 424 */     else if (((this.flags & 0x1) != 0) && ((this.flags & 0x2) == 0))
/*     */     {
/* 426 */       obj = new TriangleArray(totalVerts, 3);
/*     */     }
/*     */     else
/*     */     {
/* 431 */       obj = new TriangleArray(totalVerts, 1);
/*     */     }
/*     */
/* 435 */     Point3f[] newpts = new Point3f[totalVerts];
/* 436 */     Vector3f[] newnormals = new Vector3f[totalVerts];
/* 437 */     TexCoord2f[] newtcoords = new TexCoord2f[totalVerts];
View Full Code Here

/*     */     else {
/* 168 */       vertexFormat = 1;
/* 169 */       m.setLightingEnable(false);
/*     */     }
/*     */
/* 172 */     TriangleArray ta = new TriangleArray(72, vertexFormat);
/* 173 */     ta.setCoordinates(0, vertices);
/*     */
/* 175 */     if (enableLighting) {
/* 176 */       Vector3f v0 = new Vector3f();
/* 177 */       Vector3f v1 = new Vector3f();
/* 178 */       Vector3f[] normals = new Vector3f[72];
/*     */
/* 180 */       for (int i = 0; i < 72; i += 3) {
/* 181 */         v0.sub(vertices[(i + 1)], vertices[i]);
/* 182 */         v1.sub(vertices[(i + 2)], vertices[i]);
/*     */
/* 184 */         Vector3f n = new Vector3f();
/* 185 */         n.cross(v0, v1);
/* 186 */         n.normalize();
/*     */
/* 188 */         normals[i] = n;
/* 189 */         normals[(i + 1)] = n;
/* 190 */         normals[(i + 2)] = n;
/*     */       }
/* 192 */       ta.setNormals(0, normals);
/*     */     }
/*     */
/* 195 */     Appearance a = new Appearance();
/* 196 */     a.setMaterial(m);
/* 197 */     a.setCapability(0);
/* 198 */     a.setCapability(1);
/*     */
/* 200 */     TransparencyAttributes tra = new TransparencyAttributes();
/* 201 */     tra.setCapability(0);
/* 202 */     tra.setCapability(1);
/* 203 */     tra.setCapability(2);
/* 204 */     tra.setCapability(3);
/* 205 */     ta.setCapability(4);
/*     */
/* 207 */     ta.setCapability(5);
/*     */
/* 210 */     a.setTransparencyAttributes(tra);
/* 211 */     a.setCapability(10);
/* 212 */     a.setCapability(11);
/*     */
View Full Code Here

TOP

Related Classes of javax.media.j3d.TriangleArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.