public TriangleLight(int tri, TriangleMeshLight meshlight) { tri3 = 3 * tri; this.meshlight = meshlight; int a = meshlight.triangles[tri3 + 0]; int b = meshlight.triangles[tri3 + 1]; int c = meshlight.triangles[tri3 + 2]; Point3 v0p = meshlight.getPoint(a); Point3 v1p = meshlight.getPoint(b); Point3 v2p = meshlight.getPoint(c); ng = Point3.normal(v0p, v1p, v2p); area = 0.5f * ng.Length(); ng.normalize(); }
public TriangleLight(int tri, TriangleMeshLight meshlight) { tri3 = 3 * tri; this.meshlight = meshlight; int a = meshlight.triangles[tri3 + 0]; int b = meshlight.triangles[tri3 + 1]; int c = meshlight.triangles[tri3 + 2]; Point3 v0p = meshlight.getPoint(a); Point3 v1p = meshlight.getPoint(b); Point3 v2p = meshlight.getPoint(c); ng = Point3.normal(v0p, v1p, v2p); area = 0.5f * ng.Length(); ng.normalize(); }
private void parseLightBlock(SunflowAPI api) { p.checkNextToken("{"); p.checkNextToken("type"); if (p.peekNextToken("mesh")) { UI.printWarning(UI.Module.API, "Deprecated light type: mesh"); p.checkNextToken("name"); string name = p.getNextToken(); UI.printInfo(UI.Module.API, "Reading light mesh: {0} ...", name); p.checkNextToken("emit"); api.parameter("radiance", parseColor()); int samples = numLightSamples; if (p.peekNextToken("samples")) samples = p.getNextInt(); else UI.printWarning(UI.Module.API, "Samples keyword not found - defaulting to {0}", samples); api.parameter("samples", samples); int numVertices = p.getNextInt(); int numTriangles = p.getNextInt(); float[] points = new float[3 * numVertices]; int[] triangles = new int[3 * numTriangles]; for (int i = 0; i < numVertices; i++) { p.checkNextToken("v"); points[3 * i + 0] = p.getNextFloat(); points[3 * i + 1] = p.getNextFloat(); points[3 * i + 2] = p.getNextFloat(); // ignored p.getNextFloat(); p.getNextFloat(); p.getNextFloat(); p.getNextFloat(); p.getNextFloat(); } for (int i = 0; i < numTriangles; i++) { p.checkNextToken("t"); triangles[3 * i + 0] = p.getNextInt(); triangles[3 * i + 1] = p.getNextInt(); triangles[3 * i + 2] = p.getNextInt(); } api.parameter("points", "point", "vertex", points); api.parameter("triangles", triangles); TriangleMeshLight mesh = new TriangleMeshLight(); mesh.init(name, api); } else if (p.peekNextToken("point")) { UI.printInfo(UI.Module.API, "Reading point light ..."); Color pow; if (p.peekNextToken("color")) { pow = parseColor(); p.checkNextToken("power"); float po = p.getNextFloat(); pow.mul(po); } else { UI.printWarning(UI.Module.API, "Deprecated color specification - please use color and power instead"); p.checkNextToken("power"); pow = parseColor(); } p.checkNextToken("p"); api.parameter("center", parsePoint()); api.parameter("power", pow); api.light(api.getUniqueName("pointlight"), new PointLight()); } else if (p.peekNextToken("spherical")) { UI.printInfo(UI.Module.API, "Reading spherical light ..."); p.checkNextToken("color"); Color pow = parseColor(); p.checkNextToken("radiance"); pow.mul(p.getNextFloat()); api.parameter("radiance", pow); p.checkNextToken("center"); api.parameter("center", parsePoint()); p.checkNextToken("radius"); api.parameter("radius", p.getNextFloat()); p.checkNextToken("samples"); api.parameter("samples", p.getNextInt()); SphereLight light = new SphereLight(); light.init(api.getUniqueName("spherelight"), api); } else if (p.peekNextToken("directional")) { UI.printInfo(UI.Module.API, "Reading directional light ..."); p.checkNextToken("source"); Point3 s = parsePoint(); api.parameter("source", s); p.checkNextToken("target"); Point3 t = parsePoint(); api.parameter("dir", Point3.sub(t, s, new Vector3())); p.checkNextToken("radius"); api.parameter("radius", p.getNextFloat()); p.checkNextToken("emit"); Color e = parseColor(); if (p.peekNextToken("intensity")) { float i = p.getNextFloat(); e.mul(i); } else UI.printWarning(UI.Module.API, "Deprecated color specification - please use emit and intensity instead"); api.parameter("radiance", e); api.light(api.getUniqueName("dirlight"), new DirectionalSpotlight()); } else if (p.peekNextToken("ibl")) { UI.printInfo(UI.Module.API, "Reading image based light ..."); p.checkNextToken("image"); api.parameter("texture", p.getNextToken()); p.checkNextToken("center"); api.parameter("center", parseVector()); p.checkNextToken("up"); api.parameter("up", parseVector()); p.checkNextToken("lock"); api.parameter("fixed", p.getNextbool()); int samples = numLightSamples; if (p.peekNextToken("samples")) samples = p.getNextInt(); else UI.printWarning(UI.Module.API, "Samples keyword not found - defaulting to {0}", samples); api.parameter("samples", samples); ImageBasedLight ibl = new ImageBasedLight(); ibl.init(api.getUniqueName("ibl"), api); } else if (p.peekNextToken("meshlight")) { p.checkNextToken("name"); string name = p.getNextToken(); UI.printInfo(UI.Module.API, "Reading meshlight: {0} ...", name); p.checkNextToken("emit"); Color e = parseColor(); if (p.peekNextToken("radiance")) { float r = p.getNextFloat(); e.mul(r); } else UI.printWarning(UI.Module.API, "Deprecated color specification - please use emit and radiance instead"); api.parameter("radiance", e); int samples = numLightSamples; if (p.peekNextToken("samples")) samples = p.getNextInt(); else UI.printWarning(UI.Module.API, "Samples keyword not found - defaulting to {0}", samples); api.parameter("samples", samples); // parse vertices p.checkNextToken("points"); int np = p.getNextInt(); api.parameter("points", "point", "vertex", parseFloatArray(np * 3)); // parse triangle indices p.checkNextToken("triangles"); int nt = p.getNextInt(); api.parameter("triangles", parseIntArray(nt * 3)); TriangleMeshLight mesh = new TriangleMeshLight(); mesh.init(name, api); } else if (p.peekNextToken("sunsky")) { p.checkNextToken("up"); api.parameter("up", parseVector()); p.checkNextToken("east"); api.parameter("east", parseVector()); p.checkNextToken("sundir"); api.parameter("sundir", parseVector()); p.checkNextToken("turbidity"); api.parameter("turbidity", p.getNextFloat()); if (p.peekNextToken("samples")) api.parameter("samples", p.getNextInt()); SunSkyLight sunsky = new SunSkyLight(); sunsky.init(api.getUniqueName("sunsky"), api); } else UI.printWarning(UI.Module.API, "Unrecognized object type: {0}", p.getNextToken()); p.checkNextToken("}"); }