Ejemplo n.º 1
0
 public Gltf.Material buildMaterial(string nm, xxMaterial om)
 {
     return(new Material()
     {
         extras = new
         {
             flags = om.Unknown1,
             // shader-specific textures
             tex1 = getTexture(om.Textures[1].Name),
             tex2 = getTexture(om.Textures[2].Name),
         },
         name = nm,
         extensions = new Dictionary <string, object>()
         {
             ["KHR_materials_pbrSpecularGlossiness"] = new Gltf.Material.PbrSpecularGlossiness()
             {
                 diffuseFactor = om.Diffuse.ToArray(),
                 diffuseTexture = getMatTexture(om.Textures[0]),
                 specularFactor = om.Specular.ToArray(),
                 specularGlossinessTexture = getMatTexture(om.Textures[3]),
                 glossinessFactor = om.Power / 100,
             }
         },
     });
 }
Ejemplo n.º 2
0
        public static xxMaterial CreateMaterial(ImportedMaterial material)
        {
            xxMaterial xxMat = new xxMaterial();
            xxMat.Name = material.Name;
            xxMat.Diffuse = material.Diffuse;
            xxMat.Ambient = material.Ambient;
            xxMat.Specular = material.Specular;
            xxMat.Emissive = material.Emissive;
            xxMat.Power = material.Power;

            xxMat.Textures = new xxMaterialTexture[4];
            for (int i = 0; i < xxMat.Textures.Length; i++)
            {
                xxMat.Textures[i] = new xxMaterialTexture();
                if ((material.Textures != null) && (i < material.Textures.Length) && (material.Textures[i] != null))
                {
                    xxMat.Textures[i].Name = material.Textures[i];
                }
                else
                {
                    xxMat.Textures[i].Name = String.Empty;
                }
            }
            return xxMat;
        }
Ejemplo n.º 3
0
            private void ExportMaterial(xxMaterial mat, xxParser parser, List<xxTexture> usedTextures)
            {
                string matName = EncodeName(mat.Name);

                // material
                XmlElement material = doc.CreateElement("material", uri);
                material.SetAttribute("id", matName);
                material.SetAttribute("name", matName);
                libraries[(int)LibraryIdx.Materials].AppendChild(material);

                XmlElement materialEffect = doc.CreateElement("instance_effect", uri);
                materialEffect.SetAttribute("url", "#" + matName + "-fx");
                material.AppendChild(materialEffect);

                // effect
                XmlElement effect = doc.CreateElement("effect", uri);
                effect.SetAttribute("id", matName + "-fx");
                effect.SetAttribute("name", matName);
                libraries[(int)LibraryIdx.Effects].AppendChild(effect);

                XmlElement effectProfile = doc.CreateElement("profile_COMMON", uri);
                effect.AppendChild(effectProfile);

                XmlElement effectTechnique = doc.CreateElement("technique", uri);
                effectTechnique.SetAttribute("sid", "standard");
                // added at the end

                XmlElement effectPhong = doc.CreateElement("phong", uri);
                effectTechnique.AppendChild(effectPhong);

                XmlElement effectEmission = doc.CreateElement("emission", uri);
                effectPhong.AppendChild(effectEmission);
                XmlElement effectEmissionColor = doc.CreateElement("color", uri);
                effectEmissionColor.SetAttribute("sid", "emission");
                effectEmissionColor.InnerText = mat.Emissive.Red.ToFloatString() + " " + mat.Emissive.Green.ToFloatString() + " " + mat.Emissive.Blue.ToFloatString() + " " + mat.Emissive.Alpha.ToFloatString();
                effectEmission.AppendChild(effectEmissionColor);

                XmlElement effectAmbient = doc.CreateElement("ambient", uri);
                effectPhong.AppendChild(effectAmbient);
                XmlElement effectAmbientColor = doc.CreateElement("color", uri);
                effectAmbientColor.SetAttribute("sid", "ambient");
                effectAmbientColor.InnerText = mat.Ambient.Red.ToFloatString() + " " + mat.Ambient.Green.ToFloatString() + " " + mat.Ambient.Blue.ToFloatString() + " " + mat.Ambient.Alpha.ToFloatString();
                effectAmbient.AppendChild(effectAmbientColor);

                XmlElement effectDiffuse = doc.CreateElement("diffuse", uri);
                effectPhong.AppendChild(effectDiffuse);

                XmlElement effectSpecular = doc.CreateElement("specular", uri);
                effectPhong.AppendChild(effectSpecular);
                XmlElement effectSpecularColor = doc.CreateElement("color", uri);
                effectSpecularColor.SetAttribute("sid", "ambient");
                effectSpecularColor.InnerText = mat.Specular.Red.ToFloatString() + " " + mat.Specular.Green.ToFloatString() + " " + mat.Specular.Blue.ToFloatString() + " " + mat.Specular.Alpha.ToFloatString();
                effectSpecular.AppendChild(effectSpecularColor);

                XmlElement effectShininess = doc.CreateElement("shininess", uri);
                effectPhong.AppendChild(effectShininess);
                XmlElement effectShininessFloat = doc.CreateElement("float", uri);
                effectShininessFloat.SetAttribute("sid", "shininess");
                effectShininessFloat.InnerText = mat.Power.ToFloatString();
                effectShininess.AppendChild(effectShininessFloat);

                XmlElement effectReflective = doc.CreateElement("reflective", uri);
                effectPhong.AppendChild(effectReflective);
                XmlElement effectReflectiveColor = doc.CreateElement("color", uri);
                effectReflectiveColor.SetAttribute("sid", "reflective");
                effectReflectiveColor.InnerText = "0 0 0 1";
                effectReflective.AppendChild(effectReflectiveColor);

                XmlElement effectReflectivity = doc.CreateElement("reflectivity", uri);
                effectPhong.AppendChild(effectReflectivity);
                XmlElement effectReflectivityFloat = doc.CreateElement("float", uri);
                effectReflectivityFloat.SetAttribute("sid", "reflectivity");
                effectReflectivityFloat.InnerText = "0.5";
                effectReflectivity.AppendChild(effectReflectivityFloat);

                XmlElement effectTransparent = doc.CreateElement("transparent", uri);
                effectPhong.AppendChild(effectTransparent);
                XmlElement effectTransparentColor = doc.CreateElement("color", uri);
                effectTransparentColor.SetAttribute("sid", "transparent");
                effectTransparentColor.InnerText = "0 0 0 1";
                effectTransparent.AppendChild(effectTransparentColor);

                XmlElement effectTransparency = doc.CreateElement("transparency", uri);
                effectPhong.AppendChild(effectTransparency);
                XmlElement effectTransparencyFloat = doc.CreateElement("float", uri);
                effectTransparencyFloat.SetAttribute("sid", "transparency");
                effectTransparencyFloat.InnerText = "1";
                effectTransparency.AppendChild(effectTransparencyFloat);

                xxMaterialTexture matTex = mat.Textures[0];
                string matTexName = matTex.Name;
                if ((matTexName == null) || (matTexName == String.Empty))
                {
                    XmlElement effectDiffuseColor = doc.CreateElement("color", uri);
                    effectDiffuseColor.InnerText = mat.Diffuse.Red.ToFloatString() + " " + mat.Diffuse.Green.ToFloatString() + " " + mat.Diffuse.Blue.ToFloatString() + " " + mat.Diffuse.Alpha.ToFloatString();
                    effectDiffuse.AppendChild(effectDiffuseColor);
                }
                else
                {
                    xxTexture usedTex = null;
                    foreach (xxTexture tex in parser.TextureList)
                    {
                        if (matTexName == tex.Name)
                        {
                            usedTex = tex;
                            break;
                        }
                    }

                    if (usedTex == null)
                    {
                        XmlElement effectDiffuseColor = doc.CreateElement("color", uri);
                        effectDiffuseColor.InnerText = mat.Diffuse.Red.ToFloatString() + " " + mat.Diffuse.Green.ToFloatString() + " " + mat.Diffuse.Blue.ToFloatString() + " " + mat.Diffuse.Alpha.ToFloatString();
                        effectDiffuse.AppendChild(effectDiffuseColor);
                    }
                    else
                    {
                        if (!usedTextures.Contains(usedTex))
                        {
                            usedTextures.Add(usedTex);
                        }
                        string texName = EncodeName(usedTex.Name);

                        XmlElement effectDiffuseTexture = doc.CreateElement("texture", uri);
                        effectDiffuseTexture.SetAttribute("texture", texName + "-image");
                        effectDiffuseTexture.SetAttribute("texcoord", "CHANNEL0");
                        effectDiffuse.AppendChild(effectDiffuseTexture);

                        XmlElement effectDiffuseTextureExtra = doc.CreateElement("extra", uri);
                        effectDiffuseTexture.AppendChild(effectDiffuseTextureExtra);

                        XmlElement effectDiffuseTextureTechnique = doc.CreateElement("technique", uri);
                        effectDiffuseTextureTechnique.SetAttribute("profile", "MAYA");
                        effectDiffuseTextureExtra.AppendChild(effectDiffuseTextureTechnique);

                        XmlElement effectDiffuseTextureWrapU = doc.CreateElement("wrapU", uri);
                        effectDiffuseTextureWrapU.SetAttribute("sid", "wrapU0");
                        effectDiffuseTextureWrapU.InnerText = "TRUE";
                        effectDiffuseTextureTechnique.AppendChild(effectDiffuseTextureWrapU);

                        XmlElement effectDiffuseTextureWrapV = doc.CreateElement("wrapV", uri);
                        effectDiffuseTextureWrapV.SetAttribute("sid", "wrapV0");
                        effectDiffuseTextureWrapV.InnerText = "TRUE";
                        effectDiffuseTextureTechnique.AppendChild(effectDiffuseTextureWrapV);

                        XmlElement effectDiffuseTextureBlend = doc.CreateElement("blend_mode", uri);
                        effectDiffuseTextureBlend.InnerText = "NONE";
                        effectDiffuseTextureTechnique.AppendChild(effectDiffuseTextureBlend);
                    }
                }

                effectProfile.AppendChild(effectTechnique);
            }
Ejemplo n.º 4
0
        public void MergeMaterial(xxMaterial mat, int srcFormat)
        {
            var newMat = mat.Clone();
            xx.ConvertFormat(newMat, srcFormat, Parser.Format);

            bool found = false;
            for (int i = 0; i < Parser.MaterialList.Count; i++)
            {
                var oldMat = Parser.MaterialList[i];
                if (oldMat.Name == newMat.Name)
                {
                    if (Parser.Format > srcFormat)
                    {
                        xx.CopyUnknowns(oldMat, newMat);
                    }

                    Parser.MaterialList.RemoveAt(i);
                    Parser.MaterialList.Insert(i, newMat);
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                Parser.MaterialList.Add(newMat);
            }
        }
Ejemplo n.º 5
0
        protected xxMaterial ParseMaterial()
        {
            xxMaterial mat = new xxMaterial();
            mat.Name = reader.ReadName();
            mat.Diffuse = reader.ReadColor4();
            mat.Ambient = reader.ReadColor4();
            mat.Specular = reader.ReadColor4();
            mat.Emissive = reader.ReadColor4();
            mat.Power = reader.ReadSingle();

            mat.Textures = new xxMaterialTexture[4];
            for (int i = 0; i < mat.Textures.Length; i++)
            {
                mat.Textures[i] = new xxMaterialTexture();
                mat.Textures[i].Name = reader.ReadName();
                mat.Textures[i].Unknown1 = reader.ReadBytes(16);
            }

            if (Format < 0)
            {
                mat.Unknown1 = reader.ReadBytes(4);
            }
            else
            {
                mat.Unknown1 = reader.ReadBytes(88);
            }
            return mat;
        }