コード例 #1
0
        public static SphereFigure create_glass_sphere(IMatrix transformation, double refractiveIndex)
        {
            var glassMaterial = new SolidColorMaterial(
                MaterialConstants.Default.GetColor(Tuple4.ZeroPoint),
                MaterialConstants.Default.Ambient,
                MaterialConstants.Default.Diffuse,
                MaterialConstants.Default.Specular,
                MaterialConstants.Default.Shininess,
                MaterialConstants.Default.Reflective,
                refractiveIndex,
                1.0);

            return(new SphereFigure(transformation, glassMaterial));
        }
コード例 #2
0
        public void Replace_material_color(string id, double ambient)
        {
            var m = material[id];

            material[id] = new SolidColorMaterial(
                m.GetColor(Tuple4.ZeroPoint),
                ambient,
                m.Diffuse,
                m.Specular,
                m.Shininess,
                m.Reflective,
                m.RefractiveIndex,
                m.Transparency);
        }
コード例 #3
0
 public void Given_material(string id)
 {
     materials[id] = new SolidColorMaterial(); // Default Material
 }
コード例 #4
0
        private void And_figure(string id, string figureType, DataTable dataTable)
        {
            IMatrix transformation  = Matrix4x4.Identity;
            var     defaultMaterial = MaterialConstants.Default;

            Tuple4 color           = defaultMaterial.GetColor(Tuple4.ZeroPoint);
            double ambient         = defaultMaterial.Ambient;
            double diffuse         = defaultMaterial.Diffuse;
            double specular        = defaultMaterial.Specular;
            double reflective      = defaultMaterial.Reflective;
            double refractiveIndex = defaultMaterial.RefractiveIndex;
            double transparency    = defaultMaterial.Transparency;

            foreach (var row in dataTable.Rows)
            {
                var cells = row.Cells.ToArray();
                switch (cells[0].Value)
                {
                case "material.color":
                {
                    var entries = cells[1].Value
                                  .Split(new char[] { ',', '(', ')', ' ' }, System.StringSplitOptions.RemoveEmptyEntries)
                                  .ToArray();

                    color = new Tuple4(double.Parse(entries[0]), double.Parse(entries[1]), double.Parse(entries[2]), TupleFlavour.Vector);
                    break;
                }

                case "material.ambient":
                    ambient = double.Parse(cells[1].Value);
                    break;

                case "material.diffuse":
                    diffuse = double.Parse(cells[1].Value);
                    break;

                case "material.specular":
                    specular = double.Parse(cells[1].Value);
                    break;

                case "material.reflective":
                    reflective = double.Parse(cells[1].Value);
                    break;

                case "material.transparency":
                    transparency = double.Parse(cells[1].Value);
                    break;

                case "material.refractive_index":
                    refractiveIndex = double.Parse(cells[1].Value);
                    break;

                case "transform":
                {
                    var entries = cells[1].Value
                                  .Split(new char[] { ',', ')', '(', ' ' }, System.StringSplitOptions.RemoveEmptyEntries)
                                  .ToArray();

                    switch (entries[0])
                    {
                    case "scaling":
                        transformation = MatrixOperations.Multiply(transformation,
                                                                   MatrixOperations.Geometry3D.Scale(
                                                                       double.Parse(entries[1]),
                                                                       double.Parse(entries[2]),
                                                                       double.Parse(entries[3])));
                        break;

                    case "translation":
                        transformation = MatrixOperations.Multiply(transformation,
                                                                   MatrixOperations.Geometry3D.Translation(
                                                                       double.Parse(entries[1]),
                                                                       double.Parse(entries[2]),
                                                                       double.Parse(entries[3])));
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    break;
                }

                default:
                    throw new NotImplementedException(cells[0].Value);
                }
            }

            var material = new SolidColorMaterial(color,
                                                  ambient,
                                                  diffuse,
                                                  specular,
                                                  defaultMaterial.Shininess,
                                                  reflective,
                                                  refractiveIndex,
                                                  transparency);

            switch (figureType)
            {
            case "sphere":
                figure[id] = new SphereFigure(transformation, material);
                break;

            case "plane":
                figure[id] = new PlaneFigure(transformation, material);
                break;

            default:
                throw new NotImplementedException(figureType);
            }
        }
コード例 #5
0
    // Called by the camera to apply the image effect
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (m_RenderSolidColorCmdBuf != null && SolidColorMaterial && CutoffMaterial && CompositeMaterial)
        {
            int rtW = source.width / m_DownSample;
            int rtH = source.height / m_DownSample;

            // Step 1. Draw Solid Color Target Object(使用 Command Buffer 代替之前的那个附加相机)
            SolidColorMaterial.SetColor("_Color", m_OutlineColor);
            if (m_SolidColorRT == null)
            {
                m_SolidColorRT            = RenderTexture.GetTemporary(rtW, rtH, 0);
                m_SolidColorRT.filterMode = FilterMode.Bilinear;
            }
            Graphics.SetRenderTarget(m_SolidColorRT);
            Graphics.ExecuteCommandBuffer(m_RenderSolidColorCmdBuf);

            // Step 2. Copy to buffer2
            if (m_Buffer2 == null)
            {
                m_Buffer2            = RenderTexture.GetTemporary(rtW, rtH, 0);
                m_Buffer2.filterMode = FilterMode.Bilinear;
            }
            Graphics.Blit(m_SolidColorRT, m_Buffer2);

            // Step 3. Blur
            if (m_Buffer3 == null)
            {
                m_Buffer3            = RenderTexture.GetTemporary(rtW, rtH, 0);
                m_Buffer3.filterMode = FilterMode.Bilinear;
            }
            bool oddEven = true;
            for (int i = 0; i < m_Iterations; i++)
            {
                if (oddEven)
                {
                    FourTapCone(m_Buffer2, m_Buffer3, i);
                }
                else
                {
                    FourTapCone(m_Buffer3, m_Buffer2, i);
                }
                oddEven = !oddEven;
            }
            RenderTexture blurBuffer = null;                // 引用,指向 blur 的结果 buffer
            if (!oddEven)
            {
                blurBuffer = m_Buffer3;
            }
            else
            {
                blurBuffer = m_Buffer2;
            }

            // Step 4. 用 cutoffMaterial 进行 blurBuffer - solidColorRT 操作,得到线框
            CutoffMaterial.SetTexture("_BlurredTex", blurBuffer);
            if (m_Buffer4 == null)
            {
                m_Buffer4            = RenderTexture.GetTemporary(rtW, rtH, 0);
                m_Buffer4.filterMode = FilterMode.Bilinear;
            }
            Graphics.Blit(m_SolidColorRT, m_Buffer4, CutoffMaterial);

            // Step 5.用 compositeMaterial 进行 原图 + 线框操作
            CompositeMaterial.SetTexture("_SrcTex", source);
            CompositeMaterial.SetFloat("_OutlineStrength", m_OutlineStrength);
            Graphics.Blit(m_Buffer4, destination, CompositeMaterial);
        }
        else
        {
            Graphics.Blit(source, destination);
        }
    }
コード例 #6
0
ファイル: Scheme.cs プロジェクト: madmaxoft/MineViewer
        /// <summary>
        /// Loads a set of named schemes from a file.
        /// </summary>
        public static Dictionary <string, Scheme> Load(Stream File)
        {
            Lua.lua_State l = Lua.luaL_newstate();
            Lua.luaL_openlibs(l);

            // Add block constants
            foreach (KeyValuePair <string, byte> blockname in Names)
            {
                Lua.lua_pushnumber(l, blockname.Value);
                Lua.lua_setglobal(l, blockname.Key);
            }

            // Derive function
            Lua.lua_pushcfunction(l, delegate(Lua.lua_State ll)
            {
                int source = Lua.lua_gettop(ll);
                Lua.lua_newtable(ll);
                int dest = Lua.lua_gettop(ll);

                // Copy
                Lua.lua_pushnil(ll);
                while (Lua.lua_next(ll, source) != 0)
                {
                    Lua.lua_pushvalue(ll, -2); // Copy key on top
                    Lua.lua_pushvalue(ll, -2); // Copy value on top

                    Lua.lua_settable(ll, dest);

                    Lua.lua_pop(ll, 1); // Remove value
                }


                return(1);
            });
            Lua.lua_setglobal(l, "Derive");

            // Create a "Schemes" variable

            Lua.lua_newtable(l);
            Lua.lua_setglobal(l, "Schemes");

            // Run that shit
            string lua        = new StreamReader(File).ReadToEnd();
            int    compileerr = Lua.luaL_loadstring(l, lua);

            if (compileerr != 0)
            {
                string error = Lua.lua_tostring(l, -1).ToString();
                Lua.lua_pop(l, 1); // pop the error
                throw LuaException.Create(error, false);
            }

            int runerr = Lua.lua_pcall(l, 0, 0, 0);

            if (runerr != 0)
            {
                string error = Lua.lua_tostring(l, -1).ToString();
                Lua.lua_pop(l, 1); // pop the error
                throw LuaException.Create(error, true);
            }

            Lua.lua_pop(l, 1); // Pop the file

            // Read off schemes
            Dictionary <string, Scheme> schemes = new Dictionary <string, Scheme>();

            Lua.lua_getglobal(l, "Schemes");
            Lua.lua_pushnil(l);
            while (Lua.lua_next(l, -2) != 0)
            {
                // v, k, test table
                int    k    = -2;
                string name = Lua.lua_tostring(l, k).ToString();
                Dictionary <byte, IMaterial> data = new Dictionary <byte, IMaterial>();

                int internal_table = Lua.lua_gettop(l);
                // v, k, test table

                Lua.lua_pushnil(l);
                // nil, v, k, test table

                while (Lua.lua_next(l, internal_table) != 0)
                {
                    // v, k, v, k, test table
                    int k2 = -2;

                    byte id = (byte)Lua.lua_tonumber(l, k2);

                    int block_tbl = Lua.lua_gettop(l);

                    Lua.lua_getfield(l, block_tbl, "r");      // 1
                    Lua.lua_getfield(l, block_tbl, "g");      // 2
                    Lua.lua_getfield(l, block_tbl, "b");      // 3
                    Lua.lua_getfield(l, block_tbl, "a");      // 4
                    Lua.lua_getfield(l, block_tbl, "border"); // 5
                    Lua.lua_getfield(l, block_tbl, "b_r");    // 6
                    Lua.lua_getfield(l, block_tbl, "b_g");    // 7
                    Lua.lua_getfield(l, block_tbl, "b_b");    // 8

                    double r      = Lua.lua_tonumber(l, block_tbl + 1);
                    double g      = Lua.lua_tonumber(l, block_tbl + 2);
                    double b      = Lua.lua_tonumber(l, block_tbl + 3);
                    double a      = Lua.lua_tonumber(l, block_tbl + 4);
                    double border = Lua.lua_tonumber(l, block_tbl + 5);
                    double b_r    = Lua.lua_tonumber(l, block_tbl + 6);
                    double b_g    = Lua.lua_tonumber(l, block_tbl + 7);
                    double b_b    = Lua.lua_tonumber(l, block_tbl + 8);

                    if (id == 20)
                    {
                        int abc = 101;
                        abc++;
                    }

                    if (border == 0)
                    {
                        if (a > 0.0)
                        {
                            data[id] = new SolidColorMaterial(Color.RGBA(r, g, b, a));
                        }
                        else
                        {
                            data[id] = new SolidColorMaterial(Color.RGB(r, g, b));
                        }
                    }
                    else
                    {
                        if (a > 0.0)
                        {
                            data[id] = new BorderedMaterial(Color.RGB(b_r, b_g, b_b), border, new SolidColorMaterial(Color.RGBA(r, g, b, a)));
                        }
                        else
                        {
                            data[id] = new BorderedMaterial(Color.RGB(b_r, b_g, b_b), border, new SolidColorMaterial(Color.RGB(r, g, b)));
                        }
                    }

                    Lua.lua_pop(l, 8); // pop all the values

                    Lua.lua_pop(l, 1); // pop val - k is poped with next()
                    // k, v, k, test table
                }
                // v, k, test table
                Lua.lua_pop(l, 1);

                schemes.Add(name, new Scheme(data));
            }

            return(schemes);
        }
コード例 #7
0
ファイル: Scheme.cs プロジェクト: dzamkov/MineViewer
        /// <summary>
        /// Loads a set of named schemes from a file.
        /// </summary>
        public static Dictionary<string, Scheme> Load(Stream File)
        {
            Lua.lua_State l = Lua.luaL_newstate();
            Lua.luaL_openlibs(l);

            // Add block constants
            foreach(KeyValuePair<string, byte> blockname in Names)
            {
                Lua.lua_pushnumber(l, blockname.Value);
                Lua.lua_setglobal(l, blockname.Key);
            }

            // Derive function
            Lua.lua_pushcfunction(l, delegate(Lua.lua_State ll)
            {
                int source = Lua.lua_gettop(ll);
                Lua.lua_newtable(ll);
                int dest = Lua.lua_gettop(ll);

                // Copy
                Lua.lua_pushnil(ll);
                while (Lua.lua_next(ll, source) != 0)
                {
                    Lua.lua_pushvalue(ll, -2); // Copy key on top
                    Lua.lua_pushvalue(ll, -2); // Copy value on top

                    Lua.lua_settable(ll, dest);

                    Lua.lua_pop(ll, 1); // Remove value
                }

                return 1;
            });
            Lua.lua_setglobal(l, "Derive");

            // Create a "Schemes" variable

            Lua.lua_newtable(l);
            Lua.lua_setglobal(l, "Schemes");

            // Run that shit
            string lua = new StreamReader(File).ReadToEnd();
            int compileerr = Lua.luaL_loadstring(l, lua);

            if(compileerr != 0)
            {
                string error = Lua.lua_tostring(l, -1).ToString();
                Lua.lua_pop(l, 1); // pop the error
                throw LuaException.Create(error, false);
            }

            int runerr = Lua.lua_pcall(l, 0, 0, 0);
            if (runerr != 0)
            {
                string error = Lua.lua_tostring(l, -1).ToString();
                Lua.lua_pop(l, 1); // pop the error
                throw LuaException.Create(error, true);
            }

            Lua.lua_pop(l, 1); // Pop the file

            // Read off schemes
            Dictionary<string, Scheme> schemes = new Dictionary<string, Scheme>();
            Lua.lua_getglobal(l, "Schemes");
            Lua.lua_pushnil(l);
            while(Lua.lua_next(l, -2) != 0)
            {
                // v, k, test table
                int k = -2;
                string name = Lua.lua_tostring(l, k).ToString();
                Dictionary<byte, IMaterial> data = new Dictionary<byte, IMaterial>();

                int internal_table = Lua.lua_gettop(l);
                // v, k, test table

                Lua.lua_pushnil(l);
                // nil, v, k, test table

                while (Lua.lua_next(l, internal_table) != 0)
                {
                    // v, k, v, k, test table
                    int k2 = -2;

                    byte id = (byte)Lua.lua_tonumber(l, k2);

                    int block_tbl = Lua.lua_gettop(l);

                    Lua.lua_getfield(l, block_tbl, "r"); // 1
                    Lua.lua_getfield(l, block_tbl, "g"); // 2
                    Lua.lua_getfield(l, block_tbl, "b"); // 3
                    Lua.lua_getfield(l, block_tbl, "a"); // 4
                    Lua.lua_getfield(l, block_tbl, "border"); // 5
                    Lua.lua_getfield(l, block_tbl, "b_r"); // 6
                    Lua.lua_getfield(l, block_tbl, "b_g"); // 7
                    Lua.lua_getfield(l, block_tbl, "b_b"); // 8

                    double r = Lua.lua_tonumber(l, block_tbl + 1);
                    double g = Lua.lua_tonumber(l, block_tbl + 2);
                    double b = Lua.lua_tonumber(l, block_tbl + 3);
                    double a = Lua.lua_tonumber(l, block_tbl + 4);
                    double border = Lua.lua_tonumber(l, block_tbl + 5);
                    double b_r = Lua.lua_tonumber(l, block_tbl + 6);
                    double b_g = Lua.lua_tonumber(l, block_tbl + 7);
                    double b_b = Lua.lua_tonumber(l, block_tbl + 8);

                    if (id == 20)
                    {
                        int abc = 101;
                        abc++;
                    }

                    if(border == 0)
                    {
                        if(a>0.0)
                            data[id] = new SolidColorMaterial(Color.RGBA(r, g, b, a));
                        else
                            data[id] = new SolidColorMaterial(Color.RGB(r, g, b));
                    }
                    else
                    {
                        if(a > 0.0)
                            data[id] = new BorderedMaterial(Color.RGB(b_r, b_g, b_b), border, new SolidColorMaterial(Color.RGBA(r, g, b, a)));
                        else
                            data[id] = new BorderedMaterial(Color.RGB(b_r, b_g, b_b), border, new SolidColorMaterial(Color.RGB(r, g, b)));
                    }

                    Lua.lua_pop(l, 8); // pop all the values

                    Lua.lua_pop(l, 1); // pop val - k is poped with next()
                    // k, v, k, test table
                }
                // v, k, test table
                Lua.lua_pop(l, 1);

                schemes.Add(name, new Scheme(data));
            }

            return schemes;
        }