protected int replaceNaN(FloatBuffer floatBuffer, float value) { int length = floatBuffer.remaining(); int numValues = 0; if (this.tmpBuffer == null || this.tmpBuffer.length < floatBuffer.remaining()) { this.tmpBuffer = new float[length]; } floatBuffer.get(this.tmpBuffer, 0, length); floatBuffer.flip(); for (int i = 0; i < length; i++) { if (isNoValueFloat(this.tmpBuffer[i])) { this.tmpBuffer[i] = value; } else { numValues++; } } floatBuffer.put(this.tmpBuffer, 0, length); floatBuffer.flip(); return(numValues); }
/** * Compute the intersections of a line with a triangle fan. * * @param line the line to intersect. * @param vertices the tri-fan vertices. * @param indices the indices forming the tri-fan. * * @return the list of intersections with the line and the triangle fan, or null if there are no intersections. * * @throws ArgumentException if the line, vertex buffer or index buffer is null. */ public static List <Intersection> intersectTriFan(Line line, FloatBuffer vertices, IntBuffer indices) { if (line == null) { string msg = Logging.getMessage("nullValue.LineIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (vertices == null || indices == null) { string msg = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } List <Intersection> intersections = null; // Get the index and then the values of the constant vertex. int k = indices.get(); // note that this increments the index buffer position float v0x = vertices.get(k * 3); float v0y = vertices.get(k * 3 + 1); float v0z = vertices.get(k * 3 + 2); // Starting with the second position in the index buffer, get subsequent indices and vertices. for (int n = indices.position(); n < indices.limit() - 1; n++) { Intersection intersection; int i = indices.get(n) * 3; int j = indices.get(n + 1) * 3; // The triangle intersect method detects front and back face intersections so there's no reason to // order the vertices. intersection = intersect(line, v0x, v0y, v0z, vertices.get(i), vertices.get(i + 1), vertices.get(i + 2), vertices.get(j), vertices.get(j + 1), vertices.get(j + 2)); if (intersection != null) { if (intersections == null) { intersections = new List <Intersection>(); } intersections.Add(intersection); } } return(intersections); }
/** * Compute the intersections of a line with a triangle strip. * * @param line the line to intersect. * @param vertices the tri-strip vertices. * @param indices the indices forming the tri-strip. * * @return the list of intersections with the line and the tri-strip, or null if there are no intersections. * * @throws ArgumentException if the line, vertex buffer or index buffer is null. */ public static List <Intersection> intersectTriStrip(Line line, FloatBuffer vertices, IntBuffer indices) { if (line == null) { string msg = Logging.getMessage("nullValue.LineIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (vertices == null || indices == null) { string msg = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } List <Intersection> intersections = null; for (int n = indices.position(); n < indices.limit() - 2; n++) { Intersection intersection; int i = indices.get(n) * 3; int j = indices.get(n + 1) * 3; int k = indices.get(n + 2) * 3; // The triangle intersect method detects front and back face intersections so there's no reason to // order the vertices. intersection = intersect(line, vertices.get(i), vertices.get(i + 1), vertices.get(i + 2), vertices.get(j), vertices.get(j + 1), vertices.get(j + 2), vertices.get(k), vertices.get(k + 1), vertices.get(k + 2)); if (intersection != null) { if (intersections == null) { intersections = new List <Intersection>(); } intersections.Add(intersection); } } return(intersections); }
/** * Compute the intersections of a line with a collection of triangles. * * @param line the line to intersect. * @param vertices the triangles, arranged in a buffer as GL_TRIANGLES (9 floats per triangle). * @param indices the indices forming the triangles. * * @return the list of intersections with the line and the triangle fan, or null if there are no intersections. * * @throws ArgumentException if the line, vertex buffer or index buffer is null. */ public static List <Intersection> intersectTriangles(Line line, FloatBuffer vertices, IntBuffer indices) { if (line == null) { string msg = Logging.getMessage("nullValue.LineIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (vertices == null || indices == null) { string msg = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } List <Intersection> intersections = null; for (int n = indices.position(); n < indices.limit(); n += 3) { Intersection intersection; int i = indices.get(n) * 3; int j = indices.get(n + 1) * 3; int k = indices.get(n + 2) * 3; intersection = intersect(line, vertices.get(i), vertices.get(i + 1), vertices.get(i + 2), vertices.get(j), vertices.get(j + 1), vertices.get(j + 2), vertices.get(k), vertices.get(k + 1), vertices.get(k + 2)); if (intersection != null) { if (intersections == null) { intersections = new List <Intersection>(); } intersections.Add(intersection); } } return(intersections); }
/** * Expands a buffer of indexed triangle fan vertices to a buffer of non-indexed general-triangle vertices. * * @param indices the triangle indices. * @param inBuf the vertex buffer the indices refer to, in the order x, y, z, x, y, z, ... * @param outBuf the buffer in which to place the expanded triangle vertices. The buffer must have a limit * sufficient to hold the output vertices. * * @throws ArgumentException if the index list or the input or output buffer is null, or if the output buffer * size is insufficient. */ public static void expandTriangleFan(List <int> indices, FloatBuffer inBuf, FloatBuffer outBuf) { if (indices == null) { string msg = Logging.getMessage("nullValue.ListIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (inBuf == null || outBuf == null) { string msg = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } int nunTriangles = indices.Count - 2; if (nunTriangles * 3 * 3 > outBuf.limit() - outBuf.position()) { string msg = Logging.getMessage("generic.BufferSize", outBuf.limit() - outBuf.position()); Logging.logger().severe(msg); throw new ArgumentException(msg); } int k = indices[0] * 3; float v0x = inBuf.get(k); float v0y = inBuf.get(k + 1); float v0z = inBuf.get(k + 2); for (int i = 1; i < indices.Count - 1; i++) { outBuf.put(v0x).put(v0y).put(v0z); k = indices[i] * 3; outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2)); k = indices[i + 1] * 3; outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2)); } }
private float readFloat(ComponentInfo componentInfo, int index, int n) { if (componentInfo.buffer is FloatBuffer) { FloatBuffer floatBuffer = (FloatBuffer)componentInfo.buffer; return(floatBuffer.get(getPosition(componentInfo, index, n))); } else if (componentInfo.buffer is ByteBuffer) { ByteBuffer byteBuffer = (ByteBuffer)componentInfo.buffer; FloatBuffer floatBuffer = byteBuffer.asFloatBuffer(); return(floatBuffer.get(getPosition(componentInfo, index, n))); } return(0.0f); }
/** * Expands a buffer of indexed triangle strip vertices to a buffer of non-indexed general-triangle vertices. * * @param indices the triangle indices. * @param inBuf the vertex buffer the indices refer to, in the order x, y, z, x, y, z, ... * @param outBuf the buffer in which to place the expanded triangle vertices. The buffer must have a limit * sufficient to hold the output vertices. * * @throws ArgumentException if the index list or the input or output buffer is null, or if the output buffer * size is insufficient. */ public static void expandTriangleStrip(List <int> indices, FloatBuffer inBuf, FloatBuffer outBuf) { if (indices == null) { string msg = Logging.getMessage("nullValue.ListIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (inBuf == null || outBuf == null) { string msg = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } int nunTriangles = indices.Count - 2; if (nunTriangles * 3 * 3 > outBuf.limit() - outBuf.position()) { string msg = Logging.getMessage("generic.BufferSize", outBuf.limit() - outBuf.position()); Logging.logger().severe(msg); throw new ArgumentException(msg); } for (int i = 2; i < indices.Count; i++) { int k = indices[i - 2] * 3; outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2)); k = indices[i % 2 == 0 ? i : i - 1] * 3; outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2)); k = indices[i % 2 == 0 ? i - 1 : i] * 3; outBuf.put(inBuf.get(k)).put(inBuf.get(k + 1)).put(inBuf.get(k + 2)); } }
public virtual J3DBuffer getSelectedColorBuffer(Color paramColor) { if (this.selectedColorBuffer == null) { FloatBuffer floatBuffer1 = (FloatBuffer)ColorBuffer.Buffer; float[] arrayOfFloat = new float[this.triangleGeometry.VertexCount * 4]; for (sbyte b = 0; b < this.triangleGeometry.VertexCount; b++) { sbyte b1 = b * 4; arrayOfFloat[b1] = (paramColor.Red / 255); arrayOfFloat[b1 + 1] = (paramColor.Green / 255); arrayOfFloat[b1 + 2] = (paramColor.Blue / 255); arrayOfFloat[b1 + 3] = floatBuffer1.get(b1 + 3); } FloatBuffer floatBuffer2 = ByteBuffer.allocateDirect(32 * arrayOfFloat.Length).order(ByteOrder.nativeOrder()).asFloatBuffer(); floatBuffer2.put(arrayOfFloat, 0, arrayOfFloat.Length); this.selectedColorBuffer = new J3DBuffer(floatBuffer2); } return(this.selectedColorBuffer); }
/** * Compute the intersections of a line with a collection of triangles. * * @param line the line to intersect. * @param vertices the triangles, arranged in a buffer as GL_TRIANGLES (9 floats per triangle). * * @return the list of intersections with the line and the triangles, or null if there are no intersections. * * @throws ArgumentException if the line or vertex buffer is null. */ public static List <Intersection> intersectTriangles(Line line, FloatBuffer vertices) { if (line == null) { string msg = Logging.getMessage("nullValue.LineIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (vertices == null) { string msg = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } List <Intersection> intersections = null; vertices.rewind(); while (vertices.limit() - vertices.position() >= 9) { Intersection intersection = intersect(line, vertices.get(), vertices.get(), vertices.get(), vertices.get(), vertices.get(), vertices.get(), vertices.get(), vertices.get(), vertices.get()); if (intersection != null) { if (intersections == null) { intersections = new List <Intersection>(); } intersections.Add(intersection); } } return(intersections); }