Beispiel #1
0
        public BMDMaterialWrapper(Material mat, SuperBMDLib.Model model)
        {
            Material    = mat;
            ParentModel = model;

            Text = mat.Name;

            int textureUnit = 1;

            if (mat.TextureIndices[0] != -1)
            {
                int texIndex = mat.TextureIndices[0];

                BMDTextureMap matTexture = new BMDTextureMap(this);
                matTexture.TextureIndex = texIndex;
                matTexture.Name         = ParentModel.Textures[texIndex].Name;
                matTexture.Type         = STGenericMatTexture.TextureType.Diffuse;
                matTexture.textureUnit  = textureUnit++;

                matTexture.WrapModeS = ConvertWrapMode(ParentModel.Textures[texIndex].WrapS);
                matTexture.WrapModeT = ConvertWrapMode(ParentModel.Textures[texIndex].WrapT);
                matTexture.MinFilter = ConvertMinFilter(ParentModel.Textures[texIndex].MinFilter);
                matTexture.MagFilter = ConvertMagFilter(ParentModel.Textures[texIndex].MagFilter);

                TextureMaps.Add(matTexture);

                foreach (var textureIndex in mat.TextureIndices)
                {
                    if (textureIndex != -1)
                    {
                        Nodes.Add(ParentModel.Textures[textureIndex].Name);
                    }
                }
            }
        }
        private BcresTextureMapWrapper CreateGenericMatTexture(int textureUnit, BCRES bcres, TextureMapInfo TextureMapInfo)
        {
            STGenericMatTexture tex1 = new STGenericMatTexture();
            var TexRef  = TextureMapInfo.TextureRef;
            var Sampler = TextureMapInfo.Sampler;

            tex1.textureUnit = textureUnit++;
            tex1.Name        = TexRef.Reference.Name;
            tex1.Type        = STGenericMatTexture.TextureType.Diffuse;
            TextureMaps.Add(tex1);

            switch (TextureMapInfo.WrapU)
            {
            case PICATextureWrap.Repeat: tex1.WrapModeS = STTextureWrapMode.Repeat; break;

            case PICATextureWrap.Mirror: tex1.WrapModeS = STTextureWrapMode.Mirror; break;

            case PICATextureWrap.ClampToEdge: tex1.WrapModeS = STTextureWrapMode.Clamp; break;

            case PICATextureWrap.ClampToBorder: tex1.WrapModeS = STTextureWrapMode.Clamp; break;
            }
            switch (TextureMapInfo.WrapV)
            {
            case PICATextureWrap.Repeat: tex1.WrapModeT = STTextureWrapMode.Repeat; break;

            case PICATextureWrap.Mirror: tex1.WrapModeT = STTextureWrapMode.Mirror; break;

            case PICATextureWrap.ClampToEdge: tex1.WrapModeT = STTextureWrapMode.Clamp; break;

            case PICATextureWrap.ClampToBorder: tex1.WrapModeT = STTextureWrapMode.Clamp; break;
            }

            switch (TextureMapInfo.MagFilter)
            {
            case PICATextureFilter.Linear: tex1.MagFilter = STTextureMagFilter.Linear; break;

            case PICATextureFilter.Nearest: tex1.MagFilter = STTextureMagFilter.Nearest; break;
            }

            switch (TextureMapInfo.MinFilter)
            {
            case PICATextureFilter.Linear: tex1.MagFilter = STTextureMagFilter.Linear; break;

            case PICATextureFilter.Nearest: tex1.MagFilter = STTextureMagFilter.Nearest; break;
            }

            switch (TextureMapInfo.MipFilter)
            {
            case PICATextureFilter.Linear: tex1.MagFilter = STTextureMagFilter.Linear; break;

            case PICATextureFilter.Nearest: tex1.MagFilter = STTextureMagFilter.Nearest; break;
            }


            var wrapperTexMap = new BcresTextureMapWrapper(bcres, TextureMapInfo, tex1);

            return(wrapperTexMap);
        }
Beispiel #3
0
        public void Read(FileReader reader)
        {
            Unknown1 = reader.ReadUInt32(); //0
            uint numTextures = reader.ReadUInt32();

            Unknown2 = reader.ReadUInt32(); //0, 1, -1
            Unknown3 = reader.ReadUInt32(); //0, 1, -1

            TextureIndices = new List <ushort[]>();
            for (int i = 0; i < numTextures; i++)
            {
                TextureIndices.Add(reader.ReadUInt16s(6));
            }

            Diffuse      = new G1MTextureMap();
            Diffuse.Type = STGenericMatTexture.TextureType.Diffuse;
            TextureMaps.Add(Diffuse);
        }
Beispiel #4
0
        public MODMaterial(MOD_Parser parser, Material mat)
        {
            this.DiffuseColor = mat.DiffuseColor;

            for (int i = 0; i < mat.TextureAttributeIndices.Length; i++)
            {
                short index = mat.TextureAttributeIndices[i];
                if (index != -1)
                {
                    var attribute = parser.TextureAttributes[index];
                    TextureMaps.Add(new STGenericTextureMap()
                    {
                        WrapU = ConvertWrapMode(attribute.WrapS),
                        WrapV = ConvertWrapMode(attribute.WrapT),
                        Name  = $"Texture{attribute.TextureIndex}",
                        Type  = STTextureType.Diffuse,
                    });
                }
            }
        }
        private void ReloadMaterial()
        {
            for (int i = 0; i < Material.EnabledTextures?.Length; i++)
            {
                if (Material.EnabledTextures[i])
                {
                    H3DTextureMapWrapper matTexture = new H3DTextureMapWrapper();
                    if (i == 0)
                    {
                        matTexture.Name = Material.Texture0Name;
                    }
                    if (i == 1)
                    {
                        matTexture.Name = Material.Texture1Name;
                    }
                    if (i == 2)
                    {
                        matTexture.Name = Material.Texture2Name;
                    }

                    if (Material.TextureMappers.Length > i)
                    {
                        var mapper = Material.TextureMappers[i];
                        if (TextureMaps.Count == 0) //first texture added
                        {
                            matTexture.Type = STGenericMatTexture.TextureType.Diffuse;
                        }

                        matTexture.WrapModeS = ConvertWrapMode(mapper.WrapU);
                        matTexture.WrapModeT = ConvertWrapMode(mapper.WrapV);
                    }

                    TextureMaps.Add(matTexture);
                }
            }
        }
Beispiel #6
0
        private void ReloadMaterial()
        {
            SwitchParams.Clear();
            ValueParams.Clear();
            ColorParams.Clear();
            TextureMaps.Clear();

            for (int i = 0; i < Material.Switches?.Count; i++)
            {
                var val = Material.Switches[i];
                SwitchParams.Add(val.Name, new GFLXSwitchParam(val));
            }

            for (int i = 0; i < Material.Values?.Count; i++)
            {
                var val = Material.Values[i];
                ValueParams.Add(val.Name, new GFLXValueParam(val));
            }

            for (int i = 0; i < Material.Colors?.Count; i++)
            {
                var val = Material.Colors[i];
                ColorParams.Add(val.Name, new GFLXColorParam(val));
            }

            int textureUnit = 1;

            for (int t = 0; t < Material.TextureMaps?.Count; t++)
            {
                var    tex  = Material.TextureMaps[t];
                string name = ParentModel.Textures[(int)tex.Index];

                GFLXTextureMap matTexture = new GFLXTextureMap();
                matTexture.gflxTextureMap = tex;
                matTexture.Name           = name;
                matTexture.Transform      = new STTextureTransform();
                matTexture.SamplerName    = tex.Sampler;
                matTexture.textureUnit    = textureUnit++;
                matTexture.WrapModeS      = STTextureWrapMode.Mirror;
                matTexture.WrapModeT      = STTextureWrapMode.Repeat;
                TextureMaps.Add(matTexture);

                if (tex.Params != null)
                {
                    matTexture.WrapModeS = GFLXTextureMap.ConvertWrap(tex.Params.WrapModeX);
                    matTexture.WrapModeT = GFLXTextureMap.ConvertWrap(tex.Params.WrapModeY);
                }

                switch (tex.Sampler)
                {
                case "Texture0112`":
                case "BaseColor0":
                case "Col0Tex":
                case "L0ColTex":
                    matTexture.Type = STGenericMatTexture.TextureType.Diffuse;
                    break;

                case "EmissionMaskTex":
                    //     matTexture.Type = STGenericMatTexture.TextureType.Emission;
                    break;

                case "LyCol0Tex":
                    break;

                case "NormalMapTex":
                    matTexture.Type = STGenericMatTexture.TextureType.Normal;
                    break;

                case "AmbientTex":
                    if (SwitchParams.ContainsKey("AmbientMapEnable"))
                    {
                        if (SwitchParams["AmbientMapEnable"].Value)
                        {
                            matTexture.Type = STGenericMatTexture.TextureType.AO;
                        }
                    }
                    break;

                case "LightTblTex":
                    break;

                case "SphereMapTex":
                    break;

                case "EffectTex":
                    break;
                }


                float ScaleX = 1;
                float ScaleY = 1;
                float TransX = 0;
                float TransY = 0;

                //Lookup the uniforms and apply a transform to the texture map
                //Used for the UV viewer
                if (matTexture.Type == STGenericMatTexture.TextureType.Diffuse)
                {
                    if (ValueParams.ContainsKey("ColorUVScaleU"))
                    {
                        ScaleX = ValueParams["ColorUVScaleU"].Value;
                    }
                    if (ValueParams.ContainsKey("ColorUVScaleV"))
                    {
                        ScaleY = ValueParams["ColorUVScaleV"].Value;
                    }

                    if (ValueParams.ContainsKey("ColorUVTranslateU"))
                    {
                        TransX += ValueParams["ColorUVTranslateU"].Value;
                    }
                    if (ValueParams.ContainsKey("ColorUVTranslateV"))
                    {
                        TransY += ValueParams["ColorUVTranslateV"].Value;
                    }

                    if (ValueParams.ContainsKey("ColorBaseU"))
                    {
                        TransX += ValueParams["ColorBaseU"].Value;
                    }
                    if (ValueParams.ContainsKey("ColorBaseV"))
                    {
                        TransY += ValueParams["ColorBaseV"].Value;
                    }
                }
                if (matTexture.Type == STGenericMatTexture.TextureType.Normal)
                {
                }

                matTexture.Transform.Scale     = new OpenTK.Vector2(ScaleX, ScaleY);
                matTexture.Transform.Translate = new OpenTK.Vector2(TransX, TransY);
            }
        }