private final void computeArray( final double[] vd, final int[] vertices, final double[] nd, final int[] normals) { if (2 * vertices.length + 6 >= (vertexData.length - vertexCount) / Polygon.VERTEX_LENGTH) increaseVertexCapacity(vertices.length / 3); int vc = vertexCount; for (int i = 0; i < vertices.length; i++) { int vi = vertices[i]; VecMat.transform(matrix, vd[vi++], vd[vi++], vd[vi], vertexData, vc + Polygon.SX); vertexData[vc + Polygon.SW] = 1; int ni = normals[i]; VecMat.transformNormal( inverseTransposeMatrix, nd[ni++], nd[ni++], nd[ni], vertexData, vc + Polygon.NX); vc += Polygon.VERTEX_LENGTH; if (vertexColors) { DoubleArray color = vertexColor.item(vi / 3).toDoubleArray(); vertexData[vc + Polygon.R] = color.getValueAt(0); vertexData[vc + Polygon.G] = color.getValueAt(1); vertexData[vc + Polygon.B] = color.getValueAt(2); vertexData[vc + Polygon.A] = (vertexColorLength == 4 || (vertexColorLength == -1 && color.getLength() > 3)) ? color.getValueAt(3) : 1.; } } compute(vertices.length); }
private final void unionVectors(DataList dl) { double[][] data = dl.toDoubleArrayArray(null); double[][] tmpVec = new double[2][3]; int length = data.length; if (length == 0) return; int vectorLength = data[0].length; if (vectorLength < 3 || vectorLength > 4) return; Rn.matrixTimesVector(data, currentTrafo, data); try { if (vectorLength == 4) { Pn.calculateBounds(tmpVec, data); } else if (vectorLength == 3) { Rn.calculateBounds(tmpVec, data); } } catch (IllegalStateException e) { e.printStackTrace(); } if (Rn.isNan(tmpVec[0]) || Rn.isNan(tmpVec[1])) return; bound.xmin = Math.min(bound.xmin, tmpVec[0][0]); bound.xmax = Math.max(bound.xmax, tmpVec[1][0]); bound.ymin = Math.min(bound.ymin, tmpVec[0][1]); bound.ymax = Math.max(bound.ymax, tmpVec[1][1]); bound.zmin = Math.min(bound.zmin, tmpVec[0][2]); bound.zmax = Math.max(bound.zmax, tmpVec[1][2]); }
final void startGeometry(Geometry geom) { if (lineShader != null) lineShader.startGeometry(geom); if (faceShader != null) faceShader.startGeometry(geom); if (pointShader != null) pointShader.startGeometry(geom); if (geom instanceof PointSet) { vertexColor = ((PointSet) geom).getVertexAttributes(Attribute.COLORS); vertexColors = vertexColor != null; if (vertexColors) vertexColorLength = vertexColor.getStorageModel().getDimensions()[1]; // System.out.println("PolygonPipeline.startGeometry("+geom.getName() // +"): colors: "+vertexColors); } else { vertexColor = null; vertexColors = false; } }
public final void processPoint(final DoubleArrayArray data, int index) { DoubleArray da = data.item(index).toDoubleArray(); double w = 1; if (da.size() == 4) w = da.getValueAt(3); if (vertexColors) { DoubleArray color = vertexColor.item(index).toDoubleArray(); for (int i = 0; i < 16; i++) { pointColors[i][0] = color.getValueAt(0); pointColors[i][1] = color.getValueAt(1); pointColors[i][2] = color.getValueAt(2); pointColors[i][3] = (vertexColorLength == 4 || (vertexColorLength == -1 && color.getLength() > 3)) ? color.getValueAt(3) : 1.; } vertexColor = pointColorDataList; } processPoint(da.getValueAt(0), da.getValueAt(1), da.getValueAt(2), w); }
private final void computeArray( final DoubleArrayArray vd, final IntArray vertices, final DoubleArrayArray nd, final IntArray normals, DataList texCoords) { if (2 * vertices.getLength() + 6 >= (vertexData.length - vertexCount) / Polygon.VERTEX_LENGTH) increaseVertexCapacity(vertices.getLength() / 3); int vc = vertexCount; if (vd.getLengthAt(0) == 3) for (int i = 0; i < vertices.getLength(); i++) { int vi = vertices.getValueAt(i); DoubleArray vertex = vd.item(vi).toDoubleArray(); VecMat.transform( matrix, vertex.getValueAt(0), vertex.getValueAt(1), vertex.getValueAt(2), vertexData, vc + Polygon.SX); vertexData[vc + Polygon.SW] = 1; int ni = normals.getValueAt(i); DoubleArray normal = nd.item(ni).toDoubleArray(); VecMat.transformNormal( inverseTransposeMatrix, normal.getValueAt(0), normal.getValueAt(1), normal.getValueAt(2), vertexData, vc + Polygon.NX); if (vertexColors) { DoubleArray color = vertexColor.item(vi).toDoubleArray(); vertexData[vc + Polygon.R] = color.getValueAt(0); vertexData[vc + Polygon.G] = color.getValueAt(1); vertexData[vc + Polygon.B] = color.getValueAt(2); vertexData[vc + Polygon.A] = (vertexColorLength == 4 || (vertexColorLength == -1 && color.getLength() > 3)) ? color.getValueAt(3) : 1.; } if (useTexCoords && texCoords != null) { DoubleArray tc = texCoords.item(vi).toDoubleArray(); vertexData[vc + Polygon.U] = tc.getValueAt(0); vertexData[vc + Polygon.V] = tc.getValueAt(1); } vc += Polygon.VERTEX_LENGTH; } else // vertices are 4 tupel for (int i = 0; i < vertices.getLength(); i++) { int vi = vertices.getValueAt(i); DoubleArray vertex = vd.item(vi).toDoubleArray(); VecMat.transform( matrix, vertex.getValueAt(0), vertex.getValueAt(1), vertex.getValueAt(2), vertex.getValueAt(3), vertexData, vc + Polygon.SX); if (vertexData[vc + Polygon.SW] != 0) { final double d = vertexData[vc + Polygon.SW]; vertexData[vc + Polygon.SX] /= d; vertexData[vc + Polygon.SY] /= d; vertexData[vc + Polygon.SZ] /= d; vertexData[vc + Polygon.SW] = 1; } int ni = normals.getValueAt(i); DoubleArray normal = nd.item(ni).toDoubleArray(); VecMat.transformNormal( inverseTransposeMatrix, normal.getValueAt(0), normal.getValueAt(1), normal.getValueAt(2), // normal.getValueAt(3), vertexData, vc + Polygon.NX); if (vertexColors) { DoubleArray color = vertexColor.item(vi).toDoubleArray(); vertexData[vc + Polygon.R] = color.getValueAt(0); vertexData[vc + Polygon.G] = color.getValueAt(1); vertexData[vc + Polygon.B] = color.getValueAt(2); vertexData[vc + Polygon.A] = (vertexColorLength == 4 || (vertexColorLength == -1 && color.getLength() > 3)) ? color.getValueAt(3) : 1.; } if (useTexCoords && texCoords != null) { DoubleArray tc = texCoords.item(vi).toDoubleArray(); vertexData[vc + Polygon.U] = tc.getValueAt(0); vertexData[vc + Polygon.V] = tc.getValueAt(1); } vc += Polygon.VERTEX_LENGTH; } compute(vertices.getLength()); }