/** Returns the function's value at the given point. */ public static float getValueAt(Vector3f p, ArrayList<Primitive> primitives) { float bestValue = Float.MAX_VALUE; // Find the primitive which surface is the closest to the isosurface. for (Primitive primitive : primitives) { bestValue = Math.min(primitive.getPointValue(p), bestValue); } return bestValue; }
/** Returns the function's normal at the given point. */ public static Vector3f getNormalAt(Vector3f p, ArrayList<Primitive> primitives) { float bestValue = Float.MAX_VALUE; Primitive bestPrimitive = null; // Find the primitive which surface is the closest to the isosurface. for (Primitive primitive : primitives) { float newValue = Math.abs(primitive.getPointValue(p)); if (newValue < bestValue) { bestValue = newValue; bestPrimitive = primitive; } } // Get the normal from that primitive. Vector3f result = bestPrimitive.getPointNormal(p); return result; }
public void generateMesh() { if (!primitives.isEmpty()) { // Save local rotation Quaternion q1 = getParent().getLocalRotation().clone(); Quaternion q2 = getParent().getParent().getLocalRotation().clone(); // Align to Zero rotation. getParent().setLocalRotation(Quaternion.IDENTITY); getParent().getParent().setLocalRotation(Quaternion.IDENTITY); setLocalRotation(Quaternion.IDENTITY); // Discard previous mesh then reload it if (meshGeometry != null) { detachChild(meshGeometry); } // Build the hull again. Mesh mesh = buildPreviewMesh(); // Re-attach the hull meshGeometry = new Geometry("OurMesh", mesh); // meshGeometry.setMaterial(Primitive.showNormalsWireframeMaterial); // meshGeometry.setMaterial(Primitive.showNormalsMaterial); meshGeometry.setMaterial(Primitive.simpleLightMaterial); // meshGeometry.setMaterial(Primitive.simpleLightWireframeMaterial); attachChild(meshGeometry); meshGeometry.setShadowMode(ShadowMode.CastAndReceive); // Restore rotation getParent().setLocalRotation(q1); getParent().getParent().setLocalRotation(q2); // Hide all frames. for (Primitive a : primitives) { a.setCullHint(CullHint.Always); } } }