Example #1
0
 public bool Update(ParameterList pl, SunflowAPI api)
 {
     function = pl.getInt("function", function);
     size = pl.getFloat("size", size);
     scale = pl.getFloat("scale", scale);
     return true;
 }
Example #2
0
 public override bool Update(ParameterList pl, SunflowAPI api)
 {
     string filename = pl.getstring("texture", null);
     if (filename != null)
         tex = TextureCache.getTexture(api.resolveTextureFilename(filename), false);
     return tex != null && base.Update(pl, api);
 }
Example #3
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     string filename = pl.getstring("texture", null);
     if (filename != null)
         bumpTexture = TextureCache.getTexture(api.resolveTextureFilename(filename), true);
     scale = pl.getFloat("scale", scale);
     return bumpTexture != null;
 }
Example #4
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     lineColor = pl.getColor("line", lineColor);
     fillColor = pl.getColor("fill", fillColor);
     width = pl.getFloat("width", width);
     cosWidth = (float)Math.Cos(width);
     return true;
 }
Example #5
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     // get parameters
     fov = pl.getFloat("fov", fov);
     aspect = pl.getFloat("aspect", aspect);
     update();
     return true;
 }
Example #6
0
        public override bool parse(Stream stream, SunflowAPI api)
        {
            try
            {
                //UI.printInfo(UI.Module.USER, "TRI - Reading geometry: \"{0}\" ...", filename);
                //Systems.Parser p = new Systems.Parser(stream);
                //float[] verts = new float[3 * p.getNextInt()];
                //for (int v = 0; v < verts.Length; v += 3)
                //{
                //    verts[v + 0] = p.getNextFloat();
                //    verts[v + 1] = p.getNextFloat();
                //    verts[v + 2] = p.getNextFloat();
                //    p.getNextToken();
                //    p.getNextToken();
                //}
                //int[] triangles = new int[p.getNextInt() * 3];
                //for (int t = 0; t < triangles.Length; t += 3)
                //{
                //    triangles[t + 0] = p.getNextInt();
                //    triangles[t + 1] = p.getNextInt();
                //    triangles[t + 2] = p.getNextInt();
                //}

                //// create geometry
                //api.parameter("triangles", triangles);
                //api.parameter("points", "point", "vertex", verts);
                //api.geometry(filename, new TriangleMesh());

                //// create shader
                //api.shader(filename + ".shader", new SimpleShader());
                //api.parameter("shaders", filename + ".shader");

                //// create instance
                //api.instance(filename + ".instance", filename);

                //p.close();
                // output to ra3 format
                Console.WriteLine("Not supported");
                //RandomAccessFile stream = new RandomAccessFile(filename.replace(".tri", ".ra3"), "rw");
                //MappedByteBuffer map = stream.getChannel().map(MapMode.READ_WRITE, 0, 8 + 4 * (verts.Length + triangles.Length));
                //map.order(ByteOrder.LITTLE_ENDIAN);
                //IntBuffer ints = map.asIntBuffer();
                //FloatBuffer floats = map.asFloatBuffer();
                //ints.put(0, verts.Length / 3);
                //ints.put(1, triangles.Length / 3);
                //for (int i = 0; i < verts.Length; i++)
                //    floats.put(2 + i, verts[i]);
                //for (int i = 0; i < triangles.Length; i++)
                //    ints.put(2 + verts.Length + i, triangles[i]);
                //stream.close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return false;
            }
            return true;
        }
Example #7
0
        public override bool parse(Stream stream, SunflowAPI api)
        {
            try
            {
                Console.WriteLine("Unsupported RA3Parser");
                return false;
                //UI.printInfo(UI.Module.USER, "RA3 - Reading geometry: \"%s\" ...", filename);
                //File file = new File(filename);
                //FileInputStream stream = new FileInputStream(filename);
                //MappedByteBuffer map = stream.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.Length());
                //map.order(ByteOrder.LITTLE_ENDIAN);
                //IntBuffer ints = map.asIntBuffer();
                //FloatBuffer buffer = map.asFloatBuffer();
                //int numVerts = ints.get(0);
                //int numTris = ints.get(1);
                //UI.printInfo(UI.Module.USER, "RA3 -   * Reading %d vertices ...", numVerts);
                //float[] verts = new float[3 * numVerts];
                //for (int i = 0; i < verts.Length; i++)
                //    verts[i] = buffer.get(2 + i);
                //UI.printInfo(UI.Module.USER, "RA3 -   * Reading %d triangles ...", numTris);
                //int[] tris = new int[3 * numTris];
                //for (int i = 0; i < tris.Length; i++)
                //    tris[i] = ints.get(2 + verts.Length + i);
                //stream.close();
                //UI.printInfo(UI.Module.USER, "RA3 -   * Creating mesh ...");

                //// create geometry
                //api.parameter("triangles", tris);
                //api.parameter("points", "point", "vertex", verts);
                //api.geometry(filename, new TriangleMesh());

                //// create shader
                //IShader s = api.lookupShader("ra3shader");
                //if (s == null)
                //{
                //    // create default shader
                //    api.shader(filename + ".shader", new SimpleShader());
                //    api.parameter("shaders", filename + ".shader");
                //}
                //else
                //{
                //    // reuse existing shader
                //    api.parameter("shaders", "ra3shader");
                //}

                //// create instance
                //api.instance(filename + ".instance", filename);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return false;
            }

            return true;
        }
Example #8
0
 public virtual bool Update(ParameterList pl, SunflowAPI api)
 {
     bright = pl.getColor("bright", bright);
     dark = pl.getColor("dark", dark);
     samples = pl.getInt("samples", samples);
     maxDist = pl.getFloat("maxdist", maxDist);
     if (maxDist <= 0)
         maxDist = float.PositiveInfinity;
     return true;
 }
Example #9
0
 public bool Update(ParameterList pl, SunflowAPI api)
 {
     // get parameters
     fov = pl.getFloat("fov", fov);
     aspect = pl.getFloat("aspect", aspect);
     shiftX = pl.getFloat("shift.x", shiftX);
     shiftY = pl.getFloat("shift.y", shiftY);
     Update();
     return true;
 }
Example #10
0
 public void init(string name, SunflowAPI api)
 {
     api.geometry(name, this);
     api.shader(name + ".shader", this);
     api.parameter("shaders", name + ".shader");
     api.instance(name + ".instance", name);
     for (int i = 0, j = 0; i < triangles.Length; i += 3, j++)
     {
         TriangleLight t = new TriangleLight(j, this);
         string lname = string.Format("%s.light[%d]", name, j);
         api.light(lname, t);
     }
 }
Example #11
0
 public override bool update(ParameterList pl, SunflowAPI api)
 {
     radiance = pl.getColor("radiance", radiance);
     numSamples = pl.getInt("samples", numSamples);
     return base.update(pl, api);
 }
Example #12
0
 public virtual bool update(ParameterList pl, SunflowAPI api)
 {
     diff = pl.getColor("diffuse", diff);
     refl = pl.getFloat("shiny", refl);
     return(true);
 }
Example #13
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     Vector3 up = pl.getVector("up", null);
     Vector3 east = pl.getVector("east", null);
     if (up != null && east != null)
         basis = OrthoNormalBasis.makeFromWV(up, east);
     else if (up != null)
         basis = OrthoNormalBasis.makeFromW(up);
     numSkySamples = pl.getInt("samples", numSkySamples);
     sunDirWorld = pl.getVector("sundir", sunDirWorld);
     turbidity = pl.getFloat("turbidity", turbidity);
     // recompute model
     initSunSky();
     return true;
 }
Example #14
0
 public bool Update(ParameterList pl, SunflowAPI api)
 {
     nx = pl.getInt("resolutionX", nx);
     ny = pl.getInt("resolutionY", ny);
     nz = pl.getInt("resolutionZ", nz);
     voxelwx = 2.0f / nx;
     voxelwy = 2.0f / ny;
     voxelwz = 2.0f / nz;
     invVoxelwx = 1 / voxelwx;
     invVoxelwy = 1 / voxelwy;
     invVoxelwz = 1 / voxelwz;
     return true;
 }
Example #15
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     src = pl.getPoint("source", src);
     dir = pl.getVector("dir", dir);
     dir.normalize();
     r = pl.getFloat("radius", r);
     basis = OrthoNormalBasis.makeFromW(dir);
     r2 = r * r;
     radiance = pl.getColor("radiance", radiance);
     return true;
 }
 public virtual bool update(ParameterList pl, SunflowAPI api)
 {
     rhoD = pl.getColor("diffuse", rhoD);
     rhoS = pl.getColor("specular", rhoS);
     alphaX = pl.getFloat("roughnessX", alphaX);
     alphaY = pl.getFloat("roughnessY", alphaY);
     numRays = pl.getInt("samples", numRays);
     return true;
 }
Example #17
0
        public override bool parse(Stream stream, SunflowAPI api)
        {
            Console.WriteLine("Unsupported RA2Parser");
            //try
            //{
            //    UI.printInfo(UI.Module.USER, "RA2 - Reading geometry: \"{0}\" ...", filename);
            //    //File file = new File(filename);
            //    //FileInputStream stream = new FileInputStream(filename);
            //    //MappedByteBuffer map = stream.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.Length());
            //    //map.order(ByteOrder.LITTLE_ENDIAN);
            //    //FloatBuffer buffer = map.asFloatBuffer();

            //    BinaryReader reader = new BinaryReader(stream);
            //    float[] data = new float[reader.BaseStream.Length / 4];
            //    for (int i = 0; i < data.Length; i++)
            //        data[i] = reader.ReadSingle();
            //    reader.Close();
            //    api.parameter("points", "point", "vertex", data);
            //    int[] triangles = new int[3 * (data.Length / 9)];
            //    for (int i = 0; i < triangles.Length; i++)
            //        triangles[i] = i;
            //    // create geo
            //    api.parameter("triangles", triangles);
            //    api.geometry(filename, new TriangleMesh());
            //    // create shader
            //    api.shader(filename + ".shader", new SimpleShader());
            //    // create instance
            //    api.parameter("shaders", filename + ".shader");
            //    api.instance(filename + ".instance", filename);
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e);
            //    return false;
            //}
            //try
            //{
            //    filename = filename.Replace(".ra2", ".txt");
            //    UI.printInfo(UI.Module.USER, "RA2 - Reading camera  : \"{0}\" ...", filename);
            //    Systems.Parser p = new Systems.Parser(filename);
            //    Point3 eye = new Point3();
            //    eye.x = p.getNextFloat();
            //    eye.y = p.getNextFloat();
            //    eye.z = p.getNextFloat();
            //    Point3 to = new Point3();
            //    to.x = p.getNextFloat();
            //    to.y = p.getNextFloat();
            //    to.z = p.getNextFloat();
            //    Vector3 up = new Vector3();
            //    switch (p.getNextInt())
            //    {
            //        case 0:
            //            up.set(1, 0, 0);
            //            break;
            //        case 1:
            //            up.set(0, 1, 0);
            //            break;
            //        case 2:
            //            up.set(0, 0, 1);
            //            break;
            //        default:
            //            UI.printWarning(UI.Module.USER, "RA2 - Invalid up vector specification - using Z axis");
            //            up.set(0, 0, 1);
            //            break;
            //    }
            //    api.parameter("eye", eye);
            //    api.parameter("target", to);
            //    api.parameter("up", up);
            //    string name = api.getUniqueName("camera");
            //    api.parameter("fov", 80f);
            //    api.camera(name, new PinholeLens());
            //    api.parameter("camera", name);
            //    api.parameter("resolutionX", 1024);
            //    api.parameter("resolutionY", 1024);
            //    api.options(SunflowAPI.DEFAULT_OPTIONS);
            //    p.close();
            //}
            //catch (Exception e)
            //{
            //    UI.printWarning(UI.Module.USER, "RA2 - Camera file not found");
            //}
            return(true);
        }
Example #18
0
 public bool Update(ParameterList pl, SunflowAPI api)
 {
     return(true);
 }
Example #19
0
 public bool Update(ParameterList pl, SunflowAPI api)
 {
     c = pl.getColor("color", c);
     return(true);
 }
Example #20
0
 public virtual bool parse(string filename, SunflowAPI api)
 {
     return(parse(File.OpenRead(filename), api));
 }
Example #21
0
 public abstract bool parse(System.IO.Stream stream, SunflowAPI api);
Example #22
0
        public override bool parse(Stream stream, SunflowAPI api)
        {
            try
            {
                SunflowSharp.Systems.Parser p = new SunflowSharp.Systems.Parser(stream);
                p.checkNextToken("version");
                p.checkNextToken("3.04");
                p.checkNextToken("TransformBegin");

                if (p.peekNextToken("Procedural"))
                {
                    // read procedural shave rib
                    bool done1 = false;
                    while (!done1)
                    {
                        p.checkNextToken("DelayedReadArchive");
                        p.checkNextToken("[");
                        string f = p.getNextToken();
                        UI.printInfo(UI.Module.USER, "RIB - Reading voxel: \"{0}\" ...", f);
                        api.parse(f);
                        p.checkNextToken("]");
                        while (true)
                        {
                            string t = p.getNextToken();
                            if (t == null || t == "TransformEnd")
                            {
                                done1 = true;
                                break;
                            }
                            else if (t == "Procedural")
                            {
                                break;
                            }
                        }
                    }
                    return(true);
                }

                bool cubic = false;
                if (p.peekNextToken("Basis"))
                {
                    cubic = true;
                    // u basis
                    p.checkNextToken("catmull-rom");
                    p.checkNextToken("1");
                    // v basis
                    p.checkNextToken("catmull-rom");
                    p.checkNextToken("1");
                }
                while (p.peekNextToken("Declare"))
                {
                    p.getNextToken(); // name
                    p.getNextToken(); // interpolation & type
                }
                int  index = 0;
                bool done  = false;
                p.checkNextToken("Curves");
                do
                {
                    if (cubic)
                    {
                        p.checkNextToken("cubic");
                    }
                    else
                    {
                        p.checkNextToken("linear");
                    }
                    int[] nverts = parseIntArray(p);
                    for (int i = 1; i < nverts.Length; i++)
                    {
                        if (nverts[0] != nverts[i])
                        {
                            UI.printError(UI.Module.USER, "RIB - Found variable number of hair segments");
                            return(false);
                        }
                    }
                    int nhairs = nverts.Length;

                    UI.printInfo(UI.Module.USER, "RIB - Parsed {0} hair curves", nhairs);

                    api.parameter("segments", nverts[0] - 1);

                    p.checkNextToken("nonperiodic");
                    p.checkNextToken("P");
                    float[] points = parseFloatArray(p);
                    if (points.Length != 3 * nhairs * nverts[0])
                    {
                        UI.printError(UI.Module.USER, "RIB - Invalid number of points - expecting {0} - found {0}", nhairs * nverts[0], points.Length / 3);
                        return(false);
                    }
                    api.parameter("points", "point", "vertex", points);

                    UI.printInfo(UI.Module.USER, "RIB - Parsed {0} hair vertices", points.Length / 3);

                    p.checkNextToken("width");
                    float[] w = parseFloatArray(p);
                    if (w.Length != nhairs * nverts[0])
                    {
                        UI.printError(UI.Module.USER, "RIB - Invalid number of hair widths - expecting {0} - found {0}", nhairs * nverts[0], w.Length);
                        return(false);
                    }
                    api.parameter("widths", "float", "vertex", w);

                    UI.printInfo(UI.Module.USER, "RIB - Parsed {0} hair widths", w.Length);

                    string name = string.Format("{0}[{1}]", "[Stream]", index);
                    UI.printInfo(UI.Module.USER, "RIB - Creating hair object \"{0}\"", name);
                    api.geometry(name, new Hair());
                    api.instance(name + ".instance", name);

                    UI.printInfo(UI.Module.USER, "RIB - Searching for next curve group ...");
                    while (true)
                    {
                        string t = p.getNextToken();
                        if (t == null || t == "TransformEnd")
                        {
                            done = true;
                            break;
                        }
                        else if (t == "Curves")
                        {
                            break;
                        }
                    }
                    index++;
                } while (!done);
                UI.printInfo(UI.Module.USER, "RIB - Finished reading rib file");
            }
            catch (Exception e)
            {
                UI.printError(UI.Module.USER, "RIB - File not found: {0}", "[Stream]");
                return(false);
            }
            return(true);
        }
Example #23
0
 public bool Update(ParameterList pl, SunflowAPI api)
 {
     // get parameters
     fov = pl.getFloat("fov", fov);
     aspect = pl.getFloat("aspect", aspect);
     shiftX = pl.getFloat("shift.x", shiftX);
     shiftY = pl.getFloat("shift.y", shiftY);
     focusDistance = pl.getFloat("focus.distance", focusDistance);
     lensRadius = pl.getFloat("lens.radius", lensRadius);
     lensSides = pl.getInt("lens.sides", lensSides);
     lensRotation = pl.getFloat("lens.rotation", lensRotation);
     Update();
     return true;
 }
Example #24
0
        public virtual bool update(ParameterList pl, SunflowAPI api)
        {
            bool updatedTopology = false;

            {
                int[] trianglesi = pl.getIntArray("triangles");
                if (trianglesi != null)
                {
                    this.triangles  = trianglesi;
                    updatedTopology = true;
                }
            }
            if (triangles == null)
            {
                UI.printError(UI.Module.GEOM, "Unable to update mesh - triangle indices are missing");
                return(false);
            }
            if (triangles.Length % 3 != 0)
            {
                UI.printWarning(UI.Module.GEOM, "Triangle index data is not a multiple of 3 - triangles may be missing");
            }
            pl.setFaceCount(triangles.Length / 3);
            {
                ParameterList.FloatParameter pointsP = pl.getPointArray("points");
                if (pointsP != null)
                {
                    if (pointsP.interp != ParameterList.InterpolationType.VERTEX)
                    {
                        UI.printError(UI.Module.GEOM, "Point interpolation type must be set to \"vertex\" - was \"{0}\"", pointsP.interp.ToString().ToLower());
                    }
                    else
                    {
                        points          = pointsP.data;
                        updatedTopology = true;
                    }
                }
            }
            if (points == null)
            {
                UI.printError(UI.Module.GEOM, "Unable to update mesh - vertices are missing");
                return(false);
            }
            pl.setVertexCount(points.Length / 3);
            pl.setFaceVertexCount(3 * (triangles.Length / 3));
            ParameterList.FloatParameter normals = pl.getVectorArray("normals");
            if (normals != null)
            {
                this.normals = normals;
            }
            ParameterList.FloatParameter uvs = pl.getTexCoordArray("uvs");
            if (uvs != null)
            {
                this.uvs = uvs;
            }
            int[] faceShaders = pl.getIntArray("faceshaders");
            if (faceShaders != null && faceShaders.Length == triangles.Length / 3)
            {
                this.faceShaders = new byte[faceShaders.Length];
                for (int i = 0; i < faceShaders.Length; i++)
                {
                    int v = faceShaders[i];
                    if (v > 255)
                    {
                        UI.printWarning(UI.Module.GEOM, "Shader index too large on triangle {0}", i);
                    }
                    this.faceShaders[i] = (byte)(v & 0xFF);
                }
            }
            if (updatedTopology)
            {
                // create triangle acceleration structure
                init();
            }
            return(true);
        }
Example #25
0
 public void init(string name, SunflowAPI api)
 {
     // register this object with the api properly
     api.geometry(name, this);
     if (api.lookupGeometry(name) == null)
     {
         // quit if we don't see our geometry in here (error message
         // will have already been printed)
         return;
     }
     api.shader(name + ".shader", this);
     api.parameter("shaders", name + ".shader");
     api.instance(name + ".instance", name);
     api.light(name + ".light", this);
 }
Example #26
0
 public void init(string name, SunflowAPI api)
 {
     // register this object with the api properly
     api.geometry(name, this);
     api.shader(name + ".shader", this);
     api.parameter("shaders", name + ".shader");
     api.instance(name + ".instance", name);
     api.light(name + ".light", this);
 }
Example #27
0
        public override bool parse(Stream stream, SunflowAPI api)
        {
            try
            {
                SunflowSharp.Systems.Parser p = new SunflowSharp.Systems.Parser(stream);
                p.checkNextToken("version");
                p.checkNextToken("3.04");
                p.checkNextToken("TransformBegin");

                if (p.peekNextToken("Procedural"))
                {
                    // read procedural shave rib
                    bool done1 = false;
                    while (!done1)
                    {
                        p.checkNextToken("DelayedReadArchive");
                        p.checkNextToken("[");
                        string f = p.getNextToken();
                        UI.printInfo(UI.Module.USER, "RIB - Reading voxel: \"{0}\" ...", f);
                        api.include(f);
                        p.checkNextToken("]");
                        while (true)
                        {
                            string t = p.getNextToken();
                            if (t == null || t == "TransformEnd")
                            {
                                done1 = true;
                                break;
                            }
                            else if (t == "Procedural")
                                break;
                        }
                    }
                    return true;
                }

                bool cubic = false;
                if (p.peekNextToken("Basis"))
                {
                    cubic = true;
                    // u basis
                    p.checkNextToken("catmull-rom");
                    p.checkNextToken("1");
                    // v basis
                    p.checkNextToken("catmull-rom");
                    p.checkNextToken("1");
                }
                while (p.peekNextToken("Declare"))
                {
                    p.getNextToken(); // name
                    p.getNextToken(); // interpolation & type
                }
                int index = 0;
                bool done = false;
                p.checkNextToken("Curves");
                do
                {
                    if (cubic)
                        p.checkNextToken("cubic");
                    else
                        p.checkNextToken("linear");
                    int[] nverts = parseIntArray(p);
                    for (int i = 1; i < nverts.Length; i++)
                    {
                        if (nverts[0] != nverts[i])
                        {
                            UI.printError(UI.Module.USER, "RIB - Found variable number of hair segments");
                            return false;
                        }
                    }
                    int nhairs = nverts.Length;

                    UI.printInfo(UI.Module.USER, "RIB - Parsed {0} hair curves", nhairs);

                    api.parameter("segments", nverts[0] - 1);

                    p.checkNextToken("nonperiodic");
                    p.checkNextToken("P");
                    float[] points = parseFloatArray(p);
                    if (points.Length != 3 * nhairs * nverts[0])
                    {
                        UI.printError(UI.Module.USER, "RIB - Invalid number of points - expecting {0} - found {0}", nhairs * nverts[0], points.Length / 3);
                        return false;
                    }
                    api.parameter("points", "point", "vertex", points);

                    UI.printInfo(UI.Module.USER, "RIB - Parsed {0} hair vertices", points.Length / 3);

                    p.checkNextToken("width");
                    float[] w = parseFloatArray(p);
                    if (w.Length != nhairs * nverts[0])
                    {
                        UI.printError(UI.Module.USER, "RIB - Invalid number of hair widths - expecting {0} - found {0}", nhairs * nverts[0], w.Length);
                        return false;
                    }
                    api.parameter("widths", "float", "vertex", w);

                    UI.printInfo(UI.Module.USER, "RIB - Parsed {0} hair widths", w.Length);

                    string name = string.Format("{0}[{1}]", "[Stream]", index);
                    UI.printInfo(UI.Module.USER, "RIB - Creating hair object \"{0}\"", name);
                    api.geometry(name, "hair");
                    api.instance(name + ".instance", name);

                    UI.printInfo(UI.Module.USER, "RIB - Searching for next curve group ...");
                    while (true)
                    {
                        string t = p.getNextToken();
                        if (t == null || t == "TransformEnd")
                        {
                            done = true;
                            break;
                        }
                        else if (t == "Curves")
                            break;
                    }
                    index++;
                } while (!done);
                UI.printInfo(UI.Module.USER, "RIB - Finished reading rib file");
            }
            catch (Exception e)
            {
                UI.printError(UI.Module.USER, "RIB - File not found: {0}", "[Stream]");
                return false;
            }
            return true;
        }
Example #28
0
 public bool Update(ParameterList pl, SunflowAPI api)
 {
     diff = pl.getColor("diffuse", diff);
     spec = pl.getColor("specular", spec);
     string filename;
     filename = pl.getstring("diffuse.texture", null);
     if (filename != null)
         diffmap = TextureCache.getTexture(api.resolveTextureFilename(filename), false);
     filename = pl.getstring("specular.texture", null);
     if (filename != null)
         specmap = TextureCache.getTexture(api.resolveTextureFilename(filename), false);
     diffBlend = MathUtils.clamp(pl.getFloat("diffuse.blend", diffBlend), 0, 1);
     specBlend = MathUtils.clamp(pl.getFloat("specular.blend", diffBlend), 0, 1);
     glossyness = MathUtils.clamp(pl.getFloat("glossyness", glossyness), 0, 1);
     numSamples = pl.getInt("samples", numSamples);
     return true;
 }
Example #29
0
        public override bool parse(Stream stream, SunflowAPI api)
        {
            GZipStream gz = new GZipStream(stream, CompressionMode.Decompress);

            return(base.parse(gz, api));
        }
Example #30
0
 public virtual bool Update(ParameterList pl, SunflowAPI api)
 {
     diff = pl.getColor("diffuse", diff);
     refl = pl.getFloat("shiny", refl);
     return true;
 }
Example #31
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     {
         int[] quads1 = pl.getIntArray("quads");
         if (quads != null)
         {
             this.quads = quads1;
         }
     }
     if (quads == null)
     {
         UI.printError(UI.Module.GEOM, "Unable to update mesh - quad indices are missing");
         return(false);
     }
     if (quads.Length % 4 != 0)
     {
         UI.printWarning(UI.Module.GEOM, "Quad index data is not a multiple of 4 - some quads may be missing");
     }
     pl.setFaceCount(quads.Length / 4);
     {
         ParameterList.FloatParameter pointsP = pl.getPointArray("points");
         if (pointsP != null)
         {
             if (pointsP.interp != ParameterList.InterpolationType.VERTEX)
             {
                 UI.printError(UI.Module.GEOM, "Point interpolation type must be set to \"vertex\" - was \"%s\"", pointsP.interp.ToString().ToLower());
             }
             else
             {
                 points = pointsP.data;
             }
         }
     }
     if (points == null)
     {
         UI.printError(UI.Module.GEOM, "Unabled to update mesh - vertices are missing");
         return(false);
     }
     pl.setVertexCount(points.Length / 3);
     pl.setFaceVertexCount(4 * (quads.Length / 4));
     ParameterList.FloatParameter normals = pl.getVectorArray("normals");
     if (normals != null)
     {
         this.normals = normals;
     }
     ParameterList.FloatParameter uvs = pl.getTexCoordArray("uvs");
     if (uvs != null)
     {
         this.uvs = uvs;
     }
     int[] faceShaders = pl.getIntArray("faceshaders");
     if (faceShaders != null && faceShaders.Length == quads.Length / 4)
     {
         this.faceShaders = new byte[faceShaders.Length];
         for (int i = 0; i < faceShaders.Length; i++)
         {
             int v = faceShaders[i];
             if (v > 255)
             {
                 UI.printWarning(UI.Module.GEOM, "Shader index too large on quad %d", i);
             }
             this.faceShaders[i] = (byte)(v & 0xFF);
         }
     }
     return(true);
 }
Example #32
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     ParameterList.FloatParameter pts = pl.getPointArray("points");
     if (pts != null)
     {
         BoundingBox bounds = new BoundingBox();
         for (int i = 0; i < pts.data.Length; i += 3)
             bounds.include(pts.data[i], pts.data[i + 1], pts.data[i + 2]);
         // cube extents
         minX = bounds.getMinimum().x;
         minY = bounds.getMinimum().y;
         minZ = bounds.getMinimum().z;
         maxX = bounds.getMaximum().x;
         maxY = bounds.getMaximum().y;
         maxZ = bounds.getMaximum().z;
     }
     return true;
 }
Example #33
0
 public bool Update(ParameterList pl, SunflowAPI api)
 {
     color = pl.getColor("color", color);
     return true;
 }
Example #34
0
 public bool Update(ParameterList pl, SunflowAPI api)
 {
     return true;
 }
Example #35
0
        public new bool Update(ParameterList pl, SunflowAPI api)
        {
            if (outlinePoints.Count == 0) {

                int circlePoints = 16;
                double theta = 0;
                double thetaDelta = Math.PI * 2.0 / circlePoints;

                for (int i	= 0; i < circlePoints ; i++) {

                    outlinePoints.Add(new Point3((float)(pipeRadius * Math.Cos(theta)) ,(float)(pipeRadius * Math.Sin(theta)), 0f));
                    theta += thetaDelta;

                }
            }

            int circleSegments = outlinePoints.Count;

            if (points == null) {
                points = new float[ ((circleSegments * pipeSegments  * knotsPerPipeSegment) + circleSegments) * 3];
                quads = new int[circleSegments * pipeSegments * (knotsPerPipeSegment-1) * 4];
                if(smooth) {
                    normals = new ParameterList.FloatParameter(ParameterList.InterpolationType.VERTEX, new float[points.Length]);
                }
                //  	    	Console.WriteLine("mp: {0}", (circleSegments * (pipeSegments  * (knotsPerPipeSegment-1)) + circleSegments) * 3);
                //  	    	Console.WriteLine("mq: {0}", circleSegments * pipeSegments * (knotsPerPipeSegment-1) * 4 );
            }
            GenerateMesh();
            return true;
        }
Example #36
0
        public bool update(ParameterList pl, SunflowAPI api)
        {
            updateBasis(pl.getVector("center", null), pl.getVector("up", null));
            numSamples = pl.getInt("samples", numSamples);

            string filename = pl.getstring("texture", null);
            if (filename != null)
            texture = TextureCache.getTexture(api.resolveTextureFilename(filename), true);

            // no texture provided
            if (texture == null)
            return false;
            Bitmap b = texture.getBitmap();
            if (b == null)
            return false;

            // rebuild histograms if this is a new texture
            if (filename != null) {
            imageHistogram = new float[b.Width][];
            for(int i = 0;i < imageHistogram.Length;i++)
                imageHistogram[i] = new float[b.Height];
            colHistogram = new float[b.Width];
            float du = 1.0f / b.Width;
            float dv = 1.0f / b.Height;
            for (int x = 0; x < b.Width; x++) {
                for (int y = 0; y < b.Height; y++) {
                    float u = (x + 0.5f) * du;
                    float v = (y + 0.5f) * dv;
                    Color c = texture.getPixel(u, v);
                    // box filter the image
                    // c.add(texture.getPixel(u + du, v));
                    // c.add(texture.getPixel(u + du, v+ dv));
                    // c.add(texture.getPixel(u, v + dv));
                    // c.mul(0.25f);
                    imageHistogram[x][y] = c.getLuminance() * (float) Math.Sin(Math.PI * v);
                    if (y > 0)
                        imageHistogram[x][y] += imageHistogram[x][y - 1];
                }
                colHistogram[x] = imageHistogram[x][b.Height - 1];
                if (x > 0)
                    colHistogram[x] += colHistogram[x - 1];
                for (int y = 0; y < b.Height; y++)
                    imageHistogram[x][y] /= imageHistogram[x][b.Height - 1];
            }
            for (int x = 0; x < b.Width; x++)
                colHistogram[x] /= colHistogram[b.Width - 1];
            jacobian = (float) (2 * Math.PI * Math.PI) / (b.Width * b.Height);
            }
            // take fixed samples
            if (pl.getbool("fixed", samples != null)) {
            // Bitmap loc = new Bitmap(filename);
            samples = new Vector3[numSamples];
            colors = new Color[numSamples];
            for (int i = 0; i < numSamples; i++) {
                double randX = (double) i / (double) numSamples;
                double randY = QMC.halton(0, i);
                int x = 0;
                while (randX >= colHistogram[x] && x < colHistogram.Length - 1)
                    x++;
                float[] rowHistogram = imageHistogram[x];
                int y = 0;
                while (randY >= rowHistogram[y] && y < rowHistogram.Length - 1)
                    y++;
                // sample from (x, y)
                float u = (float) ((x == 0) ? (randX / colHistogram[0]) : ((randX - colHistogram[x - 1]) / (colHistogram[x] - colHistogram[x - 1])));
                float v = (float) ((y == 0) ? (randY / rowHistogram[0]) : ((randY - rowHistogram[y - 1]) / (rowHistogram[y] - rowHistogram[y - 1])));

                float px = ((x == 0) ? colHistogram[0] : (colHistogram[x] - colHistogram[x - 1]));
                float py = ((y == 0) ? rowHistogram[0] : (rowHistogram[y] - rowHistogram[y - 1]));

                float su = (x + u) / colHistogram.Length;
                float sv = (y + v) / rowHistogram.Length;

                float invP = (float) Math.Sin(sv * Math.PI) * jacobian / (numSamples * px * py);
                samples[i] = getDirection(su, sv);
                basis.transform(samples[i]);
                colors[i] = texture.getPixel(su, sv).mul(invP);
                // loc.setPixel(x, y, Color.YELLOW.copy().mul(1e6f));
            }
            // loc.save("samples.hdr");
            } else {
            // turn off
            samples = null;
            colors = null;
            }
            return true;
        }
Example #37
0
 public void init(string name, SunflowAPI api)
 {
     api.light(name, this);
     api.geometry(name + ".geo", new Sphere());
     api.shader(name + ".shader", this);
     api.parameter("shaders", name + ".shader");
     api.parameter("transform", Matrix4.translation(center.x, center.y, center.z).multiply(Matrix4.scale(radius)));
     api.instance(name + ".instance", name + ".geo");
 }
Example #38
0
 public override bool parse(Stream stream, SunflowAPI api)
 {
     GZipStream gz = new GZipStream(stream, CompressionMode.Decompress);
     return base.parse(gz, api);
 }
Example #39
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     radiance = pl.getColor("radiance", radiance);
     numSamples = pl.getInt("samples", numSamples);
     radius = pl.getFloat("radius", radius);
     r2 = radius * radius;
     center = pl.getPoint("center", center);
     return true;
 }
Example #40
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     string file = pl.getstring("filename", null);
     if (file != null)
         filename = api.resolveIncludeFilename(file);
     smoothNormals = pl.getbool("smooth_normals", smoothNormals);
     return filename != null;
 }
Example #41
0
 public bool update(ParameterList pl, SunflowAPI api)
 {
     // TODO: build accelstructure into this (?)
     return(true);
 }