Пример #1
0
        int ProcessMaterial(ref Block block, ref Color color)
        {
            Material material = null;
            int materialIndex = -1;
            for (int i = 0; i < block.Materials.Count; i++)
            {
                var m = block.Materials[i];
                var mColor = m.DiffuseColor;

                // RGB で比較し、A が異なっても同じ Material とします。
                if (mColor.R == color.R && mColor.G == color.G && mColor.B == color.B)
                {
                    material = m;
                    materialIndex = i;
                    break;
                }
            }

            if (material == null)
            {
                material = new Material
                {
                    DiffuseColor = new MaterialColor
                    {
                        R = color.R,
                        G = color.G,
                        B = color.B
                    }
                };
                block.Materials.Add(material);
                materialIndex = block.Materials.Count - 1;
            }

            return materialIndex;
        }
Пример #2
0
        /// <summary>
        /// 正八面体風のデータを定義する Block を作成します。
        /// </summary>
        /// <returns>作成された Block。</returns>
        Block CreateOctahedronLikeBlock()
        {
            var block = new Block();
            block.Materials = new List<Material>();
            block.Elements = new List<Element>();

            MaterialColor[] diffuses =
            {
                new MaterialColor(255, 255, 255),
                new MaterialColor(255,   0,   0),
                new MaterialColor(  0, 255,   0),
                new MaterialColor(  0,   0, 255),
                new MaterialColor(127, 127,   0),
                new MaterialColor(127,   0, 127),
                new MaterialColor(  0, 127, 127),
                new MaterialColor(  0,   0,   0),
            };
            Material[] materials = new Material[8];
            for (int i = 0; i < 8; i++)
            {
                materials[i] = new Material();
                materials[i].DiffuseColor = diffuses[i];
                block.Materials.Add(materials[i]);
            }

            int materialIndex;
            for (int x = -8; x < 8; x++)
            {
                for (int y = -8; y < 8; y++)
                {
                    for (int z = -8; z < 8; z++)
                    {
                        int testX = (x < 0) ? -x : x + 1;
                        int testY = (y < 0) ? -y : y + 1;
                        int testZ = (z < 0) ? -z : z + 1;

                        if (testX + testY + testZ <= 10)
                        {
                            materialIndex = 0;
                            if (x < 0) materialIndex |= 1;
                            if (y < 0) materialIndex |= 2;
                            if (z < 0) materialIndex |= 4;

                            var element = new Element();
                            element.Position = new Position(x, y, z);
                            element.MaterialIndex = materialIndex;
                            block.Elements.Add(element);
                        }
                    }
                }
            }

            return block;
        }
Пример #3
0
        /// <summary>
        /// 16 * 16 * 16 の全てを使用した Block を生成します。
        /// </summary>
        Block CreateFullFilledBlock()
        {
            var block = new Block();
            block.Materials = new List<Material>();
            block.Elements = new List<Element>();

            MaterialColor[] diffuses =
            {
                new MaterialColor(255, 255, 255),
                new MaterialColor(255,   0,   0),
                new MaterialColor(  0, 255,   0),
                new MaterialColor(  0,   0, 255),
                new MaterialColor(127, 127,   0),
                new MaterialColor(127,   0, 127),
                new MaterialColor(  0, 127, 127),
                new MaterialColor(  0,   0,   0),
            };
            Material[] materials = new Material[8];
            for (int i = 0; i < 8; i++)
            {
                materials[i] = new Material();
                materials[i].DiffuseColor = diffuses[i];
                block.Materials.Add(materials[i]);
            }

            int materialIndex;
            for (int x = -8; x < 8; x++)
            {
                for (int y = -8; y < 8; y++)
                {
                    for (int z = -8; z < 8; z++)
                    {
                        materialIndex = 0;
                        if (x < 0) materialIndex |= 1;
                        if (y < 0) materialIndex |= 2;
                        if (z < 0) materialIndex |= 4;

                        var element = new Element();
                        element.Position = new Position(x, y, z);
                        element.MaterialIndex = materialIndex;
                        block.Elements.Add(element);
                    }
                }
            }

            return block;
        }
Пример #4
0
        // todo: Block にメソッドを作る?
        public int CreateMaterial(
            MaterialColor diffuseColor,
            MaterialColor emissiveColor,
            MaterialColor specularColor, float specularPower)
        {
            var materials = Block.Materials;

            for (int i = 0; i < materials.Count; i++)
            {
                var m = materials[i];
                if (m.DiffuseColor == diffuseColor &&
                    m.EmissiveColor == emissiveColor &&
                    m.SpecularColor == specularColor && m.SpecularPower == specularPower)
                {
                    return i;
                }
            }

            var material = new Material
            {
                DiffuseColor = diffuseColor,
                EmissiveColor = emissiveColor,
                SpecularColor = specularColor,
                SpecularPower = specularPower
            };
            materials.Add(material);

            return materials.Count - 1;
        }