/** * Create geometry for vertices. * * @param offset Should we offset vertically * @param offsetField A full SFVec3f that we only use the height off for offset */ private X3DNode[] createVertexGeom( X3DExecutionContext mainScene, X3DNode appearance, MFInt32 geomIndicesField, MFNode geometryField, MFVec3f sizeField, MFVec3f startField, MFVec3f endField, boolean offset, MFVec3f offsetField, int shapesToCreate, int verticesPerShape) { // System.out.println("**** Creating vertex geom: " + geomIndicesField.getSize() + " // shapesToCreate: " + shapesToCreate + " verticesPerShape: " + verticesPerShape); int coord_size = 0; int index_size = 0; int texCoord_size = 0; int normal_size = 0; int num = 0; X3DNode[] ret_val = new X3DNode[shapesToCreate]; int shape_idx = 0; // System.out.println("Vertex Geoms to add: " + shapesToCreate); for (int n = 0; n < shapesToCreate; n++) { coord_size = 0; index_size = 0; texCoord_size = 0; normal_size = 0; int numVerticesInShape = verticesPerShape; if (n == shapesToCreate - 1) { numVerticesInShape++; } // System.out.println("NumVertices in Shape: " + numVerticesInShape); for (int i = 0; i < numVerticesInShape; i++) { int idx = geomIndicesField.get1Value(i); if (idx > geometryField.getSize() - 1) { System.out.println("Invalid geometry index for vertex"); continue; } X3DNode geom_node = geometryField.get1Value(idx); MField coord_field = (MField) geom_node.getField("coord"); coord_size += coord_field.getSize() * 3; MField index_field = (MField) geom_node.getField("index"); index_size += index_field.getSize(); MField texCoord_field = (MField) geom_node.getField("texCoord"); texCoord_size += texCoord_field.getSize() * 2; MField normal_field = (MField) geom_node.getField("normal"); normal_size += texCoord_field.getSize() * 3; } // System.out.println("Coord size: " + coord_size); // System.out.println("Handling vertex shape: " + n); // int[] index = new int[index_size / shapesToCreate]; // float[] point = new float[coord_size / shapesToCreate]; // float[] tc = new float[texCoord_size / shapesToCreate]; int[] index = new int[index_size]; float[] point = new float[coord_size]; float[] tc = new float[texCoord_size]; int iidx = 0; int pidx = 0; int tidx = 0; iidx = 0; pidx = 0; tidx = 0; // Post Shape X3DNode shape = mainScene.createNode("Shape"); SFNode shape_appearance = (SFNode) (shape.getField("appearance")); shape_appearance.setValue(appearance); SFNode shape_geometry = (SFNode) (shape.getField("geometry")); X3DNode its = mainScene.createNode("IndexedTriangleSet"); // SFBool its_solid = (SFBool) its.getField("solid"); // its_solid.setValue(false); X3DNode coord = mainScene.createNode("Coordinate"); SFNode its_coord = (SFNode) (its.getField("coord")); MFVec3f point_field = (MFVec3f) coord.getField("point"); X3DNode normal = mainScene.createNode("Normal"); SFNode its_normal = (SFNode) (its.getField("normal")); MFVec3f vector_field = (MFVec3f) normal.getField("vector"); X3DNode texcoord = mainScene.createNode("TextureCoordinate"); SFNode its_texcoord = (SFNode) (its.getField("texCoord")); MFVec2f tcpoint_field = (MFVec2f) texcoord.getField("point"); MFInt32 its_index = (MFInt32) (its.getField("index")); float[] size = new float[3]; int[] indexes = null; float[] coords = null; float[] texCoords = null; float[] normals = null; int currPost = -1; int post; int lastIdx = 0; float[] start = new float[3]; float[] end = new float[3]; float[] tmp = new float[3]; // System.out.println("Vertices to add: " + verticesPerShape); // Handle all but the end vertices for (int i = 0; i < verticesPerShape; i++) { post = geomIndicesField.get1Value(num); // System.out.println("Getting start: " + num); startField.get1Value(num, start); // System.out.println("translate post: " + java.util.Arrays.toString(start)); if (post != currPost) { X3DNode geom_node = geometryField.get1Value(post); MFVec3f coord_field = (MFVec3f) geom_node.getField("coord"); MFInt32 index_field = (MFInt32) geom_node.getField("index"); MFVec2f texCoord_field = (MFVec2f) geom_node.getField("texCoord"); MFVec3f normal_field = (MFVec3f) geom_node.getField("normal"); indexes = new int[index_field.getSize()]; index_field.getValue(indexes); coords = new float[coord_field.getSize() * 3]; coord_field.getValue(coords); // System.out.println("coords: " + coords.length); texCoords = new float[texCoord_field.getSize() * 2]; texCoord_field.getValue(texCoords); normals = new float[normal_field.getSize() * 3]; normal_field.getValue(normals); currPost = post; } sizeField.get1Value(num, size); int highest_idx = -1; int val; for (int j = 0; j < indexes.length; j++) { val = indexes[j] + lastIdx; index[iidx++] = val; if (val > highest_idx) highest_idx = val; } lastIdx = highest_idx + 1; float offsetVal = 0; for (int j = 0; j < coords.length / 3; j++) { point[pidx++] = (coords[j * 3] * size[0]) + start[0]; if (offset) { offsetField.get1Value(num, tmp); offsetVal = tmp[1]; } point[pidx++] = ((coords[j * 3 + 1] + 0.5f) * size[1]) + start[1] + offsetVal; point[pidx++] = (coords[j * 3 + 2] * size[2]) + start[2]; } num++; } // System.out.println("pidx: " + pidx); // System.out.println("indexes: " + java.util.Arrays.toString(index)); // System.out.println("Points1: " + java.util.Arrays.toString(point)); if (n == shapesToCreate - 1) { // System.out.println("Handling end vertices"); // Handle the end post if (num > geomIndicesField.getSize() - 1) { System.out.println("Error indexing geometry. Num: " + num); } post = geomIndicesField.get1Value(num); endField.get1Value(endField.getSize() - 1, end); if (post != currPost) { X3DNode geom_node = geometryField.get1Value(post); MFVec3f coord_field = (MFVec3f) geom_node.getField("coord"); MFInt32 index_field = (MFInt32) geom_node.getField("index"); MFVec2f texCoord_field = (MFVec2f) geom_node.getField("texCoord"); MFVec3f normal_field = (MFVec3f) geom_node.getField("normal"); indexes = new int[index_field.getSize()]; index_field.getValue(indexes); coords = new float[coord_field.getSize() * 3]; coord_field.getValue(coords); texCoords = new float[texCoord_field.getSize() * 2]; texCoord_field.getValue(texCoords); normals = new float[normal_field.getSize() * 3]; normal_field.getValue(normals); currPost = post; } sizeField.get1Value(num, size); int highest_idx = -1; int val; float offsetVal = 0; for (int j = 0; j < indexes.length; j++) { val = indexes[j] + lastIdx; index[iidx++] = val; if (val > highest_idx) highest_idx = val; } lastIdx = highest_idx + 1; for (int j = 0; j < coords.length / 3; j++) { point[pidx++] = (coords[j * 3] * size[0]) + end[0]; if (offset) { offsetField.get1Value(num, tmp); offsetVal = tmp[1]; } point[pidx++] = ((coords[j * 3 + 1] + 0.5f) * size[1]) + end[1] + offsetVal; point[pidx++] = (coords[j * 3 + 2] * size[2]) + end[2]; } // System.out.println("pidx: " + pidx); // System.out.println("Points2: " + java.util.Arrays.toString(point)); // System.out.println("Index: " + java.util.Arrays.toString(index)); } // System.out.println("TexCoord: " + java.util.Arrays.toString(tc)); if (CREATE_POSTS) { point_field.setValue(point.length / 3, point); tcpoint_field.setValue(texCoords.length / 2, texCoords); vector_field.setValue(normals.length / 3, normals); its_coord.setValue(coord); its_texcoord.setValue(texcoord); its_index.setValue(index.length, index); shape_geometry.setValue(its); } // System.out.println("Add vertex shape to: " + (shape_idx) + " size: " + ret_val.length); ret_val[shape_idx++] = shape; } return ret_val; }