Ejemplo n.º 1
0
        public void SetMaterialPhong(int origin, int idx, object[] diffuse, object[] ambient, object[] emissive, object[] specular, double shininess, double unknown)
        {
            odfMaterial mat = Parser.MaterialSection[idx];

            float[] diff = Utility.ConvertToFloatArray(diffuse);
            float[] amb  = Utility.ConvertToFloatArray(ambient);
            float[] emi  = Utility.ConvertToFloatArray(emissive);
            float[] spec = Utility.ConvertToFloatArray(specular);
            if (origin == 0)
            {
                mat.Diffuse       = new Color4(diff[3], diff[0], diff[1], diff[2]);
                mat.Ambient       = new Color4(amb[3], amb[0], amb[1], amb[2]);
                mat.Emissive      = new Color4(emi[3], emi[0], emi[1], emi[2]);
                mat.Specular      = new Color4(spec[3], spec[0], spec[1], spec[2]);
                mat.SpecularPower = (float)shininess;
                mat.Unknown1      = (float)unknown;
            }
            else
            {
                odfMaterialList        matList = odf.FindMaterialList(mat.Id, Parser.MataSection);
                odfMaterialPropertySet matProp = matList[origin - 1];
                matProp.Unknown1      = (float)unknown;
                matProp.Diffuse       = new Color4(diff[3], diff[0], diff[1], diff[2]);
                matProp.Ambient       = new Color4(amb[3], amb[0], amb[1], amb[2]);
                matProp.Emissive      = new Color4(emi[3], emi[0], emi[1], emi[2]);
                matProp.Specular      = new Color4(spec[3], spec[0], spec[1], spec[2]);
                matProp.SpecularPower = (float)shininess;
            }
        }
Ejemplo n.º 2
0
        private bool loadMATA(BinaryReader reader, odfFileSection fileSec)
        {
            ObjectName     name        = new ObjectName(reader.ReadBytes(64));
            ObjectID       id          = new ObjectID(reader.ReadBytes(4));
            int            numMatLists = reader.ReadInt32();
            odfMATASection mataSec     = new odfMATASection(id, numMatLists);

            mataSec.Name = name;
            for (int i = 0; i < numMatLists; i++)
            {
                id = new ObjectID(reader.ReadBytes(4));
                float           unk1    = reader.ReadSingle();
                int             numSets = reader.ReadInt32();
                odfMaterialList matList = new odfMaterialList(numSets);
                matList.MaterialId = id;
                matList.Unknown1   = unk1;
                matList.Unknown2   = reader.ReadInt32();
                if (!loadMaterialPropertySets(reader, numSets, matList))
                {
                    return(false);
                }

                mataSec.AddChild(matList);
            }

            fileSec.Section = mataSec;
            MataSection     = mataSec;
            return(true);
        }
Ejemplo n.º 3
0
        public void MergeMaterial(odfMaterial srcMat, odfParser srcParser)
        {
            odfMaterial newMat = srcMat.Clone();

            bool found = false;

            for (int i = 0; i < Parser.MaterialSection.Count; i++)
            {
                odfMaterial oldMat = Parser.MaterialSection[i];
                if (oldMat.Name == newMat.Name)
                {
                    newMat.Id = oldMat.Id;
                    Parser.MaterialSection.RemoveChild(i);
                    Parser.MaterialSection.InsertChild(i, newMat);

                    found = true;
                    break;
                }
            }

            if (!found)
            {
                Parser.MaterialSection.AddChild(newMat);
                if (Parser.IsUsedID(newMat.Id))
                {
                    newMat.Id = Parser.GetNewID(typeof(odfMaterial));
                    Report.ReportLog("Warning! Material " + newMat.Name + " got a new ID : " + newMat.Id);
                }
                else
                {
                    Parser.UsedIDs.Add((int)newMat.Id, typeof(odfMaterial));
                }
            }

            if (Parser.MataSection != null && srcParser.MataSection != null)
            {
                odfMaterialList newMatList = odf.FindMaterialList(newMat.Id, srcParser.MataSection);
                if (newMatList != null)
                {
                    odfMaterialList matList = odf.FindMaterialList(newMat.Id, Parser.MataSection);
                    if (matList != null)
                    {
                        int originalIdx = Parser.MataSection.IndexOf(matList);
                        Parser.MataSection.RemoveChild(originalIdx);
                        Parser.MataSection.InsertChild(originalIdx, newMatList);
                    }
                    else
                    {
                        Parser.MataSection.AddChild(newMatList);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public odfMaterialList Clone()
        {
            odfMaterialList matList = new odfMaterialList(Count);

            matList.Unknown1 = Unknown1;
            matList.Unknown2 = Unknown2;
            foreach (odfMaterialPropertySet prop in this)
            {
                odfMaterialPropertySet newProp = prop.Clone();
                matList.AddChild(newProp);
            }
            return(matList);
        }
Ejemplo n.º 5
0
        public void RemoveMaterial(int idx)
        {
            odfMaterial mat = Parser.MaterialSection[idx];

            if (Parser.MataSection != null)
            {
                odfMaterialList matList = odf.FindMaterialList(mat.Id, Parser.MataSection);
                if (matList != null)
                {
                    Parser.MataSection.RemoveChild(matList);
                }
            }

            Parser.MaterialSection.RemoveChild(idx);
            Parser.UsedIDs.Remove((int)mat.Id);
        }
Ejemplo n.º 6
0
        private bool loadMaterialPropertySets(BinaryReader reader, int numSets, odfMaterialList matSec)
        {
            for (int setIdx = 0; setIdx < numSets; setIdx++)
            {
                odfMaterialPropertySet matPSet = new odfMaterialPropertySet();
                matPSet.Unknown1      = reader.ReadSingle();
                matPSet.Diffuse       = reader.ReadColor4();
                matPSet.Ambient       = reader.ReadColor4();
                matPSet.Specular      = reader.ReadColor4();
                matPSet.Emissive      = reader.ReadColor4();
                matPSet.SpecularPower = reader.ReadSingle();

                matSec.AddChild(matPSet);
            }

            return(true);
        }
Ejemplo n.º 7
0
        public void CopyMaterial(int idx)
        {
            odfMaterial mat    = Parser.MaterialSection[idx];
            odfMaterial newMat = mat.Clone();

            newMat.Name.Name += "_copy";
            newMat.Id         = Parser.GetNewID(typeof(odfMaterial));
            Parser.MaterialSection.AddChild(newMat);

            if (Parser.MataSection != null)
            {
                for (int i = 0; i < Parser.MataSection.Count; i++)
                {
                    odfMaterialList matList = Parser.MataSection[i];
                    if (matList.MaterialId == mat.Id)
                    {
                        odfMaterialList newMatList = matList.Clone();
                        newMatList.MaterialId = newMat.Id;
                        Parser.MataSection.AddChild(newMatList);
                        break;
                    }
                }
            }
        }