コード例 #1
0
        public static int BindTexture(MatTexture tex, bool IsWiiU)
        {
            GL.ActiveTexture(TextureUnit.Texture0 + tex.hash + 1);
            GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.Id);

            if (IsWiiU)
            {
                foreach (var ftexContainer in PluginRuntime.ftexContainers)
                {
                    if (ftexContainer.Textures.ContainsKey(tex.Name))
                    {
                        BindGLTexture(tex, ftexContainer.Textures[tex.Name].RenderableTex.display);
                    }
                }
            }
            else
            {
                foreach (var bntx in PluginRuntime.bntxContainers)
                {
                    if (bntx.Textures.ContainsKey(tex.Name))
                    {
                        BindGLTexture(tex, bntx.Textures[tex.Name].RenderableTex.display);
                    }
                }
            }


            return(tex.hash + 1);
        }
コード例 #2
0
ファイル: BFRES_Render.cs プロジェクト: week9/Switch-Toolbox
        private static void BindGLTexture(MatTexture tex, SF.Shader shader, STGenericTexture texture)
        {
            //If the texture is still not initialized then return
            if (!texture.RenderableTex.GLInitialized)
            {
                return;
            }

            if (tex.Type == STGenericMatTexture.TextureType.Diffuse)
            {
                shader.SetInt("RedChannel", (int)texture.RedChannel);
                shader.SetInt("GreenChannel", (int)texture.GreenChannel);
                shader.SetInt("BlueChannel", (int)texture.BlueChannel);
                shader.SetInt("AlphaChannel", (int)texture.AlphaChannel);
            }


            //     GL.ActiveTexture(TextureUnit.Texture0 + texid);
            GL.BindTexture(TextureTarget.Texture2D, texture.RenderableTex.TexID);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)MatTexture.wrapmode[tex.WrapModeS]);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)MatTexture.wrapmode[tex.WrapModeT]);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)MatTexture.minfilter[tex.MinFilter]);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)MatTexture.magfilter[tex.MagFilter]);
            GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, 0.0f);
        }
コード例 #3
0
            public void MakeMetal(int newDifTexId, int newCubeTexId, float[] minGain, float[] refColor, float[] fresParams, float[] fresColor, bool preserveDiffuse = false, bool preserveNrmMap = true)
            {
                UpdateLabeledTextureIds();

                float materialHash = -1f;

                if (propertyValuesByName.ContainsKey("NU_materialHash"))
                {
                    materialHash = propertyValuesByName["NU_materialHash"][0];
                }
                animatedPropertyValuesByName.Clear();
                propertyValuesByName.Clear();

                // The texture ID used for diffuse later.
                int difTexId = newDifTexId;

                if (preserveDiffuse)
                {
                    difTexId = Diffuse1Id;
                }

                // add all the textures
                textures.Clear();
                displayTexId = -1;

                MatTexture diffuse   = new MatTexture(difTexId);
                MatTexture cube      = new MatTexture(newCubeTexId);
                MatTexture normal    = new MatTexture(normalId);
                MatTexture dummyRamp = MatTexture.GetDefault();

                dummyRamp.hash = 0x10080000;

                if (HasNormalMap && preserveNrmMap)
                {
                    Flags = 0x9601106B;
                    textures.Add(diffuse);
                    textures.Add(cube);
                    textures.Add(normal);
                    textures.Add(dummyRamp);
                }
                else
                {
                    Flags = 0x96011069;
                    textures.Add(diffuse);
                    textures.Add(cube);
                    textures.Add(dummyRamp);
                }

                // add material properties
                propertyValuesByName.Add("NU_colorSamplerUV", new float[] { 1, 1, 0, 0 });
                propertyValuesByName.Add("NU_fresnelColor", fresColor);
                propertyValuesByName.Add("NU_blinkColor", new float[] { 0f, 0f, 0f, 0 });
                propertyValuesByName.Add("NU_reflectionColor", refColor);
                propertyValuesByName.Add("NU_aoMinGain", minGain);
                propertyValuesByName.Add("NU_lightMapColorOffset", new float[] { 0f, 0f, 0f, 0 });
                propertyValuesByName.Add("NU_fresnelParams", fresParams);
                propertyValuesByName.Add("NU_alphaBlendParams", new float[] { 0f, 0f, 0f, 0 });
                propertyValuesByName.Add("NU_materialHash", new float[] { materialHash, 0f, 0f, 0 });
            }
コード例 #4
0
        public void OnPropertyChanged()
        {
            if (textureRefListView.SelectedIndices.Count <= 0)
            {
                return;
            }

            int        index            = textureRefListView.SelectedIndices[0];
            MatTexture ActiveMatTexture = (MatTexture)material.TextureMaps[index];

            if (ActiveMatTexture.wiiUSampler != null)
            {
                ActiveMatTexture.wrapModeS = (int)ActiveMatTexture.wiiUSampler.ClampX;
                ActiveMatTexture.wrapModeT = (int)ActiveMatTexture.wiiUSampler.ClampY;
                ActiveMatTexture.wrapModeW = (int)ActiveMatTexture.wiiUSampler.ClampZ;

                if (ActiveMatTexture.wiiUSampler.MinFilter == ResUGX2.GX2TexXYFilterType.Point)
                {
                    ActiveMatTexture.minFilter = 1;
                }
                if (ActiveMatTexture.wiiUSampler.MagFilter == ResUGX2.GX2TexXYFilterType.Point)
                {
                    ActiveMatTexture.magFilter = 1;
                }
                if (ActiveMatTexture.wiiUSampler.MinFilter == ResUGX2.GX2TexXYFilterType.Bilinear)
                {
                    ActiveMatTexture.minFilter = 0;
                }
                if (ActiveMatTexture.wiiUSampler.MagFilter == ResUGX2.GX2TexXYFilterType.Bilinear)
                {
                    ActiveMatTexture.magFilter = 0;
                }
            }
            else
            {
                ActiveMatTexture.wrapModeS = (int)ActiveMatTexture.switchSampler.WrapModeU;
                ActiveMatTexture.wrapModeT = (int)ActiveMatTexture.switchSampler.WrapModeV;
                ActiveMatTexture.wrapModeW = (int)ActiveMatTexture.switchSampler.WrapModeW;

                if (ActiveMatTexture.switchSampler.ShrinkXY == ResNX.Sampler.ShrinkFilterModes.Points)
                {
                    ActiveMatTexture.minFilter = 1;
                }
                if (ActiveMatTexture.switchSampler.ExpandXY == ResNX.Sampler.ExpandFilterModes.Points)
                {
                    ActiveMatTexture.magFilter = 1;
                }
                if (ActiveMatTexture.switchSampler.ShrinkXY == ResNX.Sampler.ShrinkFilterModes.Linear)
                {
                    ActiveMatTexture.minFilter = 0;
                }
                if (ActiveMatTexture.switchSampler.ExpandXY == ResNX.Sampler.ExpandFilterModes.Linear)
                {
                    ActiveMatTexture.magFilter = 0;
                }
            }

            LibraryGUI.Instance.UpdateViewport();
        }
コード例 #5
0
        public void OnPropertyChanged()
        {
            if (textureRefListView.SelectedIndices.Count <= 0)
            {
                return;
            }

            int        index            = textureRefListView.SelectedIndices[0];
            MatTexture ActiveMatTexture = (MatTexture)material.TextureMaps[index];

            if (ActiveMatTexture.wiiUSampler != null)
            {
                ActiveMatTexture.WrapModeS = SetWrapMode((int)ActiveMatTexture.wiiUSampler.ClampX);
                ActiveMatTexture.WrapModeT = SetWrapMode((int)ActiveMatTexture.wiiUSampler.ClampY);
                ActiveMatTexture.WrapModeW = SetWrapMode((int)ActiveMatTexture.wiiUSampler.ClampZ);

                if (ActiveMatTexture.wiiUSampler.MinFilter == ResUGX2.GX2TexXYFilterType.Point)
                {
                    ActiveMatTexture.MinFilter = STTextureMinFilter.Nearest;
                }
                if (ActiveMatTexture.wiiUSampler.MagFilter == ResUGX2.GX2TexXYFilterType.Point)
                {
                    ActiveMatTexture.MagFilter = STTextureMagFilter.Nearest;
                }
                if (ActiveMatTexture.wiiUSampler.MinFilter == ResUGX2.GX2TexXYFilterType.Bilinear)
                {
                    ActiveMatTexture.MinFilter = STTextureMinFilter.Linear;
                }
                if (ActiveMatTexture.wiiUSampler.MagFilter == ResUGX2.GX2TexXYFilterType.Bilinear)
                {
                    ActiveMatTexture.MagFilter = STTextureMagFilter.Linear;
                }
            }
            else
            {
                ActiveMatTexture.WrapModeS = SetWrapMode((int)ActiveMatTexture.switchSampler.WrapModeU);
                ActiveMatTexture.WrapModeT = SetWrapMode((int)ActiveMatTexture.switchSampler.WrapModeV);
                ActiveMatTexture.WrapModeW = SetWrapMode((int)ActiveMatTexture.switchSampler.WrapModeW);

                if (ActiveMatTexture.switchSampler.ShrinkXY == ResNX.Sampler.ShrinkFilterModes.Points)
                {
                    ActiveMatTexture.MinFilter = STTextureMinFilter.Nearest;
                }
                if (ActiveMatTexture.switchSampler.ExpandXY == ResNX.Sampler.ExpandFilterModes.Points)
                {
                    ActiveMatTexture.MagFilter = STTextureMagFilter.Nearest;
                }
                if (ActiveMatTexture.switchSampler.ShrinkXY == ResNX.Sampler.ShrinkFilterModes.Linear)
                {
                    ActiveMatTexture.MinFilter = STTextureMinFilter.Linear;
                }
                if (ActiveMatTexture.switchSampler.ExpandXY == ResNX.Sampler.ExpandFilterModes.Linear)
                {
                    ActiveMatTexture.MagFilter = STTextureMagFilter.Linear;
                }
            }

            LibraryGUI.UpdateViewport();
        }
コード例 #6
0
            public void AddDefaultMaterial()
            {
                Material mat = Material.GetDefault();

                materials.Add(mat);
                mat.textures.Add(new MatTexture(0x10000000));
                mat.textures.Add(MatTexture.GetDefault());
            }
コード例 #7
0
 private static void SetTextureUniforms(FMAT mat, FSHP m, SHShaderProgram shader)
 {
     for (int t = 0; t < mat.TextureMaps.Count; t++)
     {
         MatTexture matex = (MatTexture)mat.TextureMaps[t];
         mat.HasDiffuseMap = TextureUniform(shader, mat, $"tex_map{t}", matex);
     }
 }
コード例 #8
0
 private static void BindGLTexture(MatTexture tex, int texid)
 {
     //   GL.ActiveTexture(TextureUnit.Texture0 + texid);
     GL.BindTexture(TextureTarget.Texture2D, texid);
     GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)MatTexture.wrapmode[tex.wrapModeS]);
     GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)MatTexture.wrapmode[tex.wrapModeT]);
     GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, 0.0f);
 }
コード例 #9
0
        private void samplerCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (samplerCB.SelectedIndex >= 0 && textureRefListView.SelectedIndices.Count > 0)
            {
                int        index  = textureRefListView.SelectedIndices[0];
                MatTexture matTex = (MatTexture)material.TextureMaps[index];

                matTex.SamplerName = samplerCB.GetItemText(samplerCB.SelectedItem);

                samplerHintTB.Text = GetHint(matTex.SamplerName);
            }
        }
コード例 #10
0
ファイル: BFRES_Render.cs プロジェクト: week9/Switch-Toolbox
        private static bool BindBNTX(BNTX bntx, MatTexture tex, SF.Shader shader, string activeTex)
        {
            if (bntx.Textures[activeTex].RenderableTex == null ||
                !bntx.Textures[activeTex].RenderableTex.GLInitialized)
            {
                bntx.Textures[activeTex].LoadOpenGLTexture();
            }

            BindGLTexture(tex, shader, bntx.Textures[activeTex]);

            return(bntx.Textures[activeTex].RenderableTex.GLInitialized);
        }
コード例 #11
0
ファイル: BFRES_Render.cs プロジェクト: week9/Switch-Toolbox
        private static bool BindFTEX(BFRESGroupNode ftexContainer, MatTexture tex, SF.Shader shader, string activeTex)
        {
            FTEX ftex = (FTEX)ftexContainer.ResourceNodes[activeTex];

            if (ftex.RenderableTex == null || !ftex.RenderableTex.GLInitialized)
            {
                ftex.LoadOpenGLTexture();
            }

            BindGLTexture(tex, shader, ftex);

            return(ftex.RenderableTex.GLInitialized);
        }
コード例 #12
0
            public MatTexture Clone()
            {
                MatTexture t = new MatTexture();

                t.hash      = hash;
                t.mapMode   = mapMode;
                t.wrapModeS = wrapModeS;
                t.wrapModeT = wrapModeT;
                t.minFilter = minFilter;
                t.magFilter = magFilter;
                t.mipDetail = mipDetail;
                t.unknown   = unknown;
                t.unknown2  = unknown2;
                return(t);
            }
コード例 #13
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show("NOTE! Texture maps are adjusted by shader options which link by shaders. These are not possible to edit yet, do you want to continue?", "Material Editor", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);

            if (result == DialogResult.OK)
            {
                var tex = new MatTexture();
                tex.SamplerName       = GetSamplerName("_a0");
                tex.FragShaderSampler = "_a0";
                tex.Name      = "Untitled";
                tex.Type      = Toolbox.Library.STGenericMatTexture.TextureType.Unknown;
                tex.WrapModeS = STTextureWrapMode.Repeat;
                tex.WrapModeT = STTextureWrapMode.Repeat;
                tex.WrapModeW = STTextureWrapMode.Clamp;

                if (material.GetResFileU() != null)
                {
                    var texSampler = new ResUGX2.TexSampler();
                    texSampler.BorderType          = ResUGX2.GX2TexBorderType.ClearBlack;
                    texSampler.ClampX              = ResUGX2.GX2TexClamp.Wrap;
                    texSampler.ClampY              = ResUGX2.GX2TexClamp.Wrap;
                    texSampler.ClampZ              = ResUGX2.GX2TexClamp.Clamp;
                    texSampler.DepthCompareEnabled = false;
                    texSampler.DepthCompareFunc    = ResUGX2.GX2CompareFunction.Never;
                    texSampler.MagFilter           = ResUGX2.GX2TexXYFilterType.Point;
                    texSampler.MaxAnisotropicRatio = ResUGX2.GX2TexAnisoRatio.Ratio_1_1;
                    texSampler.MinFilter           = ResUGX2.GX2TexXYFilterType.Point;
                    texSampler.MipFilter           = ResUGX2.GX2TexMipFilterType.Linear;
                    texSampler.ZFilter             = 0;
                    texSampler.MaxLod              = 13;
                    texSampler.MinLod              = 0;
                    texSampler.LodBias             = 0;
                    tex.wiiUSampler = texSampler;
                }
                else
                {
                    var texSampler = new ResNX.Sampler();
                    tex.switchSampler = texSampler;
                }
                material.TextureMaps.Add(tex);

                var item = new ListViewItem();
                item.Text = "Untitled";
                item.SubItems.Add(tex.SamplerName);
                item.SubItems.Add(tex.FragShaderSampler);
                textureRefListView.Items.Add(item);
            }
        }
コード例 #14
0
        private static void BindGLTexture(MatTexture tex, SHShaderProgram shader, STGenericTexture texture)
        {
            //If the texture is still not initialized then return
            if (!texture.RenderableTex.GLInitialized)
            {
                return;
            }

            //     GL.ActiveTexture(TextureUnit.Texture0 + texid);
            GL.BindTexture(TextureTarget.Texture2D, texture.RenderableTex.TexID);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)MatTexture.wrapmode[tex.WrapModeS]);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)MatTexture.wrapmode[tex.WrapModeT]);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)MatTexture.minfilter[tex.MinFilter]);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)MatTexture.magfilter[tex.MagFilter]);
            GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, 0.0f);
        }
コード例 #15
0
        public static int BindTexture(MatTexture tex, bool IsWiiU)
        {
            GL.ActiveTexture(TextureUnit.Texture0 + tex.textureUnit + 1);
            //    GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.Id);

            string activeTex = tex.Name;

            if (tex.animatedTexName != "")
            {
                activeTex = tex.animatedTexName;
            }

            if (IsWiiU)
            {
                foreach (var ftexContainer in PluginRuntime.ftexContainers)
                {
                    if (ftexContainer.ResourceNodes.ContainsKey(activeTex))
                    {
                        FTEX ftex = (FTEX)ftexContainer.ResourceNodes[activeTex];

                        if (ftex.RenderableTex == null || !ftex.RenderableTex.GLInitialized)
                        {
                            ftex.LoadOpenGLTexture();
                        }

                        BindGLTexture(tex, ftex.RenderableTex.TexID);
                    }
                }
            }
            else
            {
                foreach (var bntx in PluginRuntime.bntxContainers)
                {
                    if (bntx.Textures.ContainsKey(activeTex))
                    {
                        if (bntx.Textures[activeTex].RenderableTex == null ||
                            !bntx.Textures[activeTex].RenderableTex.GLInitialized)
                        {
                            bntx.Textures[activeTex].LoadOpenGLTexture();
                        }

                        BindGLTexture(tex, bntx.Textures[activeTex].RenderableTex.TexID);
                    }
                }
            }
            return(tex.textureUnit + 1);
        }
コード例 #16
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var tex = new MatTexture();

            tex.SamplerName       = GetSamplerName("_a0");
            tex.FragShaderSampler = "_a0";
            tex.Name      = "Untitled";
            tex.Type      = Switch_Toolbox.Library.STGenericMatTexture.TextureType.Unknown;
            tex.wrapModeS = 0;
            tex.wrapModeT = 0;
            tex.wrapModeW = 2;

            if (material.GetResFileU() != null)
            {
                var texSampler = new ResUGX2.TexSampler();
                texSampler.BorderType          = ResUGX2.GX2TexBorderType.ClearBlack;
                texSampler.ClampX              = ResUGX2.GX2TexClamp.Wrap;
                texSampler.ClampY              = ResUGX2.GX2TexClamp.Wrap;
                texSampler.ClampZ              = ResUGX2.GX2TexClamp.Clamp;
                texSampler.DepthCompareEnabled = false;
                texSampler.DepthCompareFunc    = ResUGX2.GX2CompareFunction.Never;
                texSampler.MagFilter           = ResUGX2.GX2TexXYFilterType.Point;
                texSampler.MaxAnisotropicRatio = ResUGX2.GX2TexAnisoRatio.TwoToOne;
                texSampler.MinFilter           = ResUGX2.GX2TexXYFilterType.Point;
                texSampler.MipFilter           = ResUGX2.GX2TexMipFilterType.Linear;
                texSampler.ZFilter             = 0;
                texSampler.MaxLod              = 13;
                texSampler.MinLod              = 0;
                texSampler.LodBias             = 0;
                tex.wiiUSampler = texSampler;
            }
            else
            {
                var texSampler = new ResNX.Sampler();
                tex.switchSampler = texSampler;
            }
            material.TextureMaps.Add(tex);

            var item = new ListViewItem();

            item.Text = "Untitled";
            item.SubItems.Add(tex.SamplerName);
            item.SubItems.Add(tex.FragShaderSampler);
            textureRefListView.Items.Add(item);
        }
コード例 #17
0
        public void LoadTexture(MatTexture texture)
        {
            ActiveMatTexture = texture;

            nameTB.Text = texture.Name;

            samplerCB.Items.Clear();
            samplerCB.Items.Add(texture.SamplerName);
            samplerCB.SelectedItem = texture.SamplerName;

            if (texture.wiiUSampler != null)
            {
                stPropertyGrid1.LoadProperty(texture.wiiUSampler, OnPropertyChanged);
            }
            else
            {
                stPropertyGrid1.LoadProperty(texture.switchSampler, OnPropertyChanged);
            }

            foreach (BNTX bntx in PluginRuntime.bntxContainers)
            {
                if (bntx.Textures.ContainsKey(texture.Name))
                {
                    Thread = new Thread((ThreadStart)(() =>
                    {
                        textureBP.Image = Switch_Toolbox.Library.Imaging.GetLoadingImage();
                        textureBP.Image = bntx.Textures[texture.Name].GetBitmap();
                    }));
                    Thread.Start();
                }
            }
            foreach (BFRESGroupNode ftexCont in PluginRuntime.ftexContainers)
            {
                if (ftexCont.ResourceNodes.ContainsKey(texture.Name))
                {
                    Thread = new Thread((ThreadStart)(() =>
                    {
                        textureBP.Image = Switch_Toolbox.Library.Imaging.GetLoadingImage();
                        textureBP.Image = ((FTEX)ftexCont.ResourceNodes[texture.Name]).GetBitmap();
                    }));
                    Thread.Start();
                }
            }
        }
コード例 #18
0
ファイル: Material.cs プロジェクト: y4my4my4m/Smash-Forge
            public static Material GetDefault()
            {
                Material material = new Material();

                material.Flags    = 0x94010161;
                material.cullMode = 0x0405;
                material.entries.Add("NU_colorSamplerUV", new float[] { 1, 1, 0, 0 });
                material.entries.Add("NU_fresnelColor", new float[] { 1, 1, 1, 1 });
                material.entries.Add("NU_blinkColor", new float[] { 0, 0, 0, 0 });
                material.entries.Add("NU_aoMinGain", new float[] { 0, 0, 0, 0 });
                material.entries.Add("NU_lightMapColorOffset", new float[] { 0, 0, 0, 0 });
                material.entries.Add("NU_fresnelParams", new float[] { 1, 0, 0, 0 });
                material.entries.Add("NU_alphaBlendParams", new float[] { 0, 0, 0, 0 });
                material.entries.Add("NU_materialHash", new float[] { FileData.toFloat(0x7E538F65), 0, 0, 0 });

                material.textures.Add(new MatTexture(0x10000000));
                material.textures.Add(MatTexture.GetDefault());
                return(material);
            }
コード例 #19
0
ファイル: BFRES_Render.cs プロジェクト: week9/Switch-Toolbox
        private static bool TextureUniform(SF.Shader shader, FMAT mat, string name, MatTexture mattex)
        {
            if (mattex.textureState == STGenericMatTexture.TextureState.Binded)
            {
                return(true);
            }

            // Bind the texture and create the uniform if the material has the right textures.
            bool IsBound = BindTexture(mattex, mat, shader, mat.GetResFileU() != null);
            int  texId   = mattex.textureUnit + 1;

            if (IsBound)
            {
                GL.Uniform1(shader.GetUniformLocation(name), texId);
            }
            else
            {
                return(false);
            }

            return(true);
        }
コード例 #20
0
 private void SamplerEditor_SelectedIndexChanged(object sender, EventArgs e)
 {
     int        index  = textureRefListView.SelectedIndices[0];
     MatTexture matTex = (MatTexture)material.TextureMaps[index];
 }
コード例 #21
0
        private void textureRefListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Do this only if none are selected so they don't flicker off/on on change
            if (textureRefListView.SelectedIndices.Count <= 0)
            {
                btnEdit.Enabled    = false;
                samplerHintTB.Text = "";
                samplerTB.Text     = "";
                btnRemove.Enabled  = false;
            }

            Reset();

            if (textureRefListView.SelectedIndices.Count > 0)
            {
                btnEdit.Enabled   = true;
                btnRemove.Enabled = true;

                int index = textureRefListView.SelectedIndices[0];

                MatTexture matTex = (MatTexture)material.TextureMaps[index];

                samplerHintTB.Text = matTex.Type.ToString();

                string name = matTex.Name;
                textureNameTB.Text = name;

                if (matTex.SamplerName != null)
                {
                    samplerTB.Text = matTex.SamplerName;
                }

                if (matTex.switchSampler != null)
                {
                    stPropertyGrid1.LoadProperty(matTex.switchSampler, OnPropertyChanged);
                }
                if (matTex.wiiUSampler != null)
                {
                    stPropertyGrid1.LoadProperty(matTex.wiiUSampler, OnPropertyChanged);
                }

                foreach (BNTX bntx in PluginRuntime.bntxContainers)
                {
                    if (bntx.Textures.ContainsKey(name))
                    {
                        Thread = new Thread((ThreadStart)(() =>
                        {
                            textureBP.Image = Toolbox.Library.Imaging.GetLoadingImage();
                            textureBP.Image = bntx.Textures[name].GetBitmap();
                        }));
                        Thread.Start();
                    }
                }
                foreach (BFRESGroupNode ftexCont in PluginRuntime.ftexContainers)
                {
                    if (ftexCont.ResourceNodes.ContainsKey(name))
                    {
                        Thread = new Thread((ThreadStart)(() =>
                        {
                            textureBP.Image = Toolbox.Library.Imaging.GetLoadingImage();
                            textureBP.Image = ((FTEX)ftexCont.ResourceNodes[name]).GetBitmap();
                        }));
                        Thread.Start();
                    }
                }
            }
        }
コード例 #22
0
        private void ReadTextureRefs(Material mat, Mesh poly)
        {
            int AlbedoCount = 0;
            int id          = 0;

            string TextureName = "";

            foreach (TextureRef tex in mat.TextureRefs)
            {
                TextureName = mat.TextureRefs[id].Name;

                MatTexture texture = new MatTexture();

                bool IsAlbedo = HackyTextureList.Any(TextureName.Contains);

                //This works decently for now. I tried samplers but Kirby Star Allies doesn't map with samplers properly?
                if (IsAlbedo)
                {
                    if (AlbedoCount == 0)
                    {
                        try
                        {
                            poly.texHashs.Add(BNTX.textured[TextureName].texture.display);
                            AlbedoCount++;
                        }
                        catch
                        {
                            poly.texHashs.Add(0);
                        }
                        poly.TextureMapTypes.Add("Diffuse");
                    }
                }
                else if (TextureName.Contains("Nrm") || TextureName.Contains("Norm") || TextureName.Contains("norm") || TextureName.Contains("nrm"))
                {
                    try
                    {
                        poly.texHashs.Add(BNTX.textured[TextureName].texture.display);
                    }
                    catch
                    {
                        poly.texHashs.Add(1);
                    }
                    poly.material.HasNormalMap = true;
                    poly.TextureMapTypes.Add("Normal");
                }
                else if (TextureName.Contains("Emm"))
                {
                    try
                    {
                        poly.texHashs.Add(BNTX.textured[TextureName].texture.display);
                    }
                    catch
                    {
                        poly.texHashs.Add(2);
                    }
                    poly.TextureMapTypes.Add("EmissionMap");
                }
                else if (TextureName.Contains("Spm"))
                {
                    try
                    {
                        poly.texHashs.Add(BNTX.textured[TextureName].texture.display);
                    }
                    catch
                    {
                        poly.texHashs.Add(2);
                    }
                    poly.TextureMapTypes.Add("SpecularMap");
                }
                else if (TextureName.Contains("b00"))
                {
                    try
                    {
                        poly.texHashs.Add(BNTX.textured[TextureName].texture.display);
                    }
                    catch
                    {
                        poly.texHashs.Add(2);
                    }
                    poly.TextureMapTypes.Add("Bake1");
                }
                else if (TextureName.Contains("b01") || TextureName.Contains("Moc"))
                {
                    try
                    {
                        poly.texHashs.Add(BNTX.textured[TextureName].texture.display);
                    }
                    catch
                    {
                        poly.texHashs.Add(3);
                    }
                    poly.TextureMapTypes.Add("Bake2");
                }
                else if (TextureName.Contains("MRA")) //Metalness, Roughness, and Cavity Map in one
                {
                    try
                    {
                        poly.texHashs.Add(BNTX.textured[TextureName].texture.display);
                    }
                    catch
                    {
                        poly.texHashs.Add(7);
                    }
                    poly.TextureMapTypes.Add("MRA");
                }
                else if (TextureName.Contains("mtl"))
                {
                    try
                    {
                        poly.texHashs.Add(BNTX.textured[TextureName].texture.display);
                    }
                    catch
                    {
                        poly.texHashs.Add(8);
                    }
                    poly.TextureMapTypes.Add("Metalness");
                }
                else if (TextureName.Contains("rgh"))
                {
                    try
                    {
                        poly.texHashs.Add(BNTX.textured[TextureName].texture.display);
                    }
                    catch
                    {
                        poly.texHashs.Add(9);
                    }
                    poly.TextureMapTypes.Add("Roughness");
                }
                texture.Name = TextureName;
                id++;
            }
        }
コード例 #23
0
        private void ReadTextureRefs(Material mat, Mesh poly)
        {
            int AlbedoCount = 0;
            int id          = 0;

            string TextureName = "";

            foreach (TextureRef tex in mat.TextureRefs)
            {
                TextureName = mat.TextureRefs[id].Name;

                MatTexture texture = new MatTexture();

                texture.wrapModeS   = (int)mat.Samplers[id].WrapModeU;
                texture.wrapModeT   = (int)mat.Samplers[id].WrapModeV;
                texture.wrapModeW   = (int)mat.Samplers[id].WrapModeW;
                texture.SamplerName = mat.SamplerDict.Keys.ElementAt(id);
                texture.Name        = TextureName;


                if (poly.material.shaderassign.samplers.Count >= id) //Set samplers that get padded to pixel shader
                {
                    try
                    {
                        texture.FragShaderSampler = poly.material.shaderassign.samplers[texture.SamplerName];
                    }
                    catch
                    {
                        //This shouldn't happen but just incase
                    }
                }



                bool IsAlbedo = HackyTextureList.Any(TextureName.Contains);

                //This works decently for now. I tried samplers but Kirby Star Allies doesn't map with samplers properly?
                if (IsAlbedo)
                {
                    if (AlbedoCount == 0)
                    {
                        poly.material.HasDiffuseMap = true;
                        AlbedoCount++;
                        texture.hash = 0;
                        texture.Type = MatTexture.TextureType.Diffuse;
                    }
                    if (AlbedoCount == 1)
                    {
                        //   poly.material.HasDiffuseLayer = true;
                        //    texture.hash = 19;
                        //   texture.Type = MatTexture.TextureType.DiffuseLayer2;
                    }
                }


                else if (TextureName.Contains("Nrm") || TextureName.Contains("Norm") || TextureName.Contains("norm") || TextureName.Contains("nrm"))
                {
                    texture.hash = 1;
                    poly.material.HasNormalMap = true;
                    texture.Type = MatTexture.TextureType.Normal;
                }
                else if (TextureName.Contains("Emm"))
                {
                    texture.hash = 8;
                    poly.material.HasEmissionMap = true;
                    texture.Type = MatTexture.TextureType.Emission;
                }
                else if (TextureName.Contains("Spm"))
                {
                    texture.hash = 4;
                    poly.material.HasSpecularMap = true;
                    texture.Type = MatTexture.TextureType.Specular;
                }
                else if (TextureName.Contains("b00") || TextureName.Contains("Moc") || TextureName.Contains("AO"))
                {
                    //AO and shadow can use the same sampler. Shader options will determine which channels to use
                    texture.hash = 2;
                    poly.material.HasShadowMap = true;
                    texture.Type = MatTexture.TextureType.Shadow;
                }
                else if (TextureName.Contains("b01"))
                {
                    texture.hash = 3;
                    poly.material.HasLightMap = true;
                }
                else if (TextureName.Contains("MRA")) //Metalness, Roughness, and Cavity Map in one
                {
                    texture.hash         = 21;
                    poly.material.HasMRA = true;
                    texture.Type         = MatTexture.TextureType.MRA;
                }
                else if (TextureName.Contains("mtl"))
                {
                    texture.hash = 16;
                    poly.material.HasMetalnessMap = true;
                    texture.Type = MatTexture.TextureType.Metalness;
                }
                else if (TextureName.Contains("rgh"))
                {
                    texture.Type = MatTexture.TextureType.Roughness;
                    texture.hash = 15;
                    poly.material.HasRoughnessMap = true;
                }
                else if (TextureName.Contains("Mlt"))
                {
                    texture.hash = 14;
                    poly.material.HasSphereMap = true;
                    texture.Type = MatTexture.TextureType.SphereMap;
                }
                else if (texture.SamplerName == "_a0" && AlbedoCount == 0) //Load the diffuse sampler if it cannot load
                {
                    poly.material.HasDiffuseMap = true;
                    AlbedoCount++;
                    texture.hash = 0;
                    texture.Type = MatTexture.TextureType.Diffuse;
                }

                //Now determine the types by sampler from fragment shader
                //a0 and a1 will not be defined this way however because KSA using only those in no particular order
                if (texture.FragShaderSampler == "_t0")
                {
                    poly.material.HasTransparencyMap = true;
                }
                if (texture.FragShaderSampler == "_e0")
                {
                    poly.material.HasEmissionMap = true;
                }
                if (texture.FragShaderSampler == "_e1")
                {
                    poly.material.HasEmissionMap = true;
                }
                if (texture.FragShaderSampler == "_b0")
                {
                    poly.material.HasShadowMap = true;
                }
                if (texture.FragShaderSampler == "_b1")
                {
                    poly.material.HasLightMap = true;
                }
                if (texture.FragShaderSampler == "_n0")
                {
                    poly.material.HasNormalMap = true;
                }
                if (texture.FragShaderSampler == "_s0")
                {
                    poly.material.HasSpecularMap = true;
                }

                poly.material.textures.Add(texture);
                id++;
            }
        }
コード例 #24
0
        private void SamplerEditor_SelectedIndexChanged(object sender, EventArgs e)
        {
            int        index  = textureRefListView.SelectedIndices[0];
            MatTexture matTex = (MatTexture)material.TextureMaps[index];

            if (matTex.switchSampler != null)
            {
                var samp = matTex.switchSampler;
                samp.BorderColorType = (ResGFX.TexBorderType)filterBorderCB.SelectedItem;
                samp.WrapModeU       = (ResGFX.TexClamp)wrapUCB.SelectedItem;
                samp.WrapModeV       = (ResGFX.TexClamp)wrapVCB.SelectedItem;
                samp.WrapModeW       = (ResGFX.TexClamp)wrapWCB.SelectedItem;
                samp.CompareFunc     = (ResGFX.CompareFunction)depthFuncCB.SelectedItem;
                // samp.MaxAnisotropic = (ResGFX.GX2TexAnisoRatio)lodMinUD.Value;
                //  samp.FilterMode = (ResUGX2.GX2TexXYFilterType)lodMinUD.Value;
                //  samp.MipFilter = (ResUGX2.GX2TexMipFilterType)filterZCB.SelectedItem;
                //   samp.ZFilter = (ResUGX2.GX2TexZFilterType)filterZCB.SelectedItem;
                //   samp.DepthCompareEnabled = deptComparechkBox.Checked;
            }
            else
            {
                var samp = matTex.wiiUSampler;

                if (filterBorderCB.SelectedItem != null)
                {
                    samp.BorderType = (ResUGX2.GX2TexBorderType)filterBorderCB.SelectedItem;
                }
                if (wrapUCB.SelectedItem != null)
                {
                    samp.ClampX = (ResUGX2.GX2TexClamp)wrapUCB.SelectedItem;
                }
                if (wrapVCB.SelectedItem != null)
                {
                    samp.ClampY = (ResUGX2.GX2TexClamp)wrapVCB.SelectedItem;
                }
                if (wrapWCB.SelectedItem != null)
                {
                    samp.ClampZ = (ResUGX2.GX2TexClamp)wrapWCB.SelectedItem;
                }
                if (depthFuncCB.SelectedItem != null)
                {
                    samp.DepthCompareFunc = (ResUGX2.GX2CompareFunction)depthFuncCB.SelectedItem;
                }
                if (filterAntitropicCB.SelectedItem != null)
                {
                    samp.MaxAnisotropicRatio = (ResUGX2.GX2TexAnisoRatio)filterAntitropicCB.SelectedItem;
                }
                if (filterShrinkCB.SelectedItem != null)
                {
                    samp.MinFilter = (ResUGX2.GX2TexXYFilterType)filterShrinkCB.SelectedItem;
                }
                if (filterExpandCB.SelectedItem != null)
                {
                    samp.MagFilter = (ResUGX2.GX2TexXYFilterType)filterExpandCB.SelectedItem;
                }
                if (filterMipmapCB.SelectedItem != null)
                {
                    samp.MipFilter = (ResUGX2.GX2TexMipFilterType)filterMipmapCB.SelectedItem;
                }
                if (filterZCB.SelectedItem != null)
                {
                    samp.ZFilter = (ResUGX2.GX2TexZFilterType)filterZCB.SelectedItem;
                }
                samp.DepthCompareEnabled = deptComparechkBox.Checked;
            }
            matTex.BiasLod = (float)biasUD.Value;
            matTex.MaxLod  = (float)lodMaxUD.Value;
            matTex.MinLod  = (float)lodMinUD.Value;
        }
コード例 #25
0
        private void textureRefListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Do this only if none are selected so they don't flicker off/on on change
            if (textureRefListView.SelectedIndices.Count <= 0)
            {
                btnEdit.Enabled        = false;
                btnSamplerEdit.Enabled = false;
            }

            Reset();

            if (textureRefListView.SelectedIndices.Count > 0)
            {
                btnEdit.Enabled        = true;
                btnSamplerEdit.Enabled = true;

                int index = textureRefListView.SelectedIndices[0];

                MatTexture matTex = (MatTexture)material.TextureMaps[index];

                string name = matTex.Name;
                textureNameTB.Text = name;

                if (matTex.SamplerName != null)
                {
                    if (!samplerCB.Items.Contains(matTex.SamplerName))
                    {
                        samplerCB.Items.Add(matTex.SamplerName);
                    }

                    samplerCB.SelectedItem = matTex.SamplerName;
                }

                if (matTex.switchSampler != null)
                {
                }
                if (matTex.wiiUSampler != null)
                {
                    LoadWiiUSamplerEnums();

                    wrapUCB.SelectedItem = matTex.wiiUSampler.ClampX;
                    wrapVCB.SelectedItem = matTex.wiiUSampler.ClampY;
                    wrapWCB.SelectedItem = matTex.wiiUSampler.ClampZ;

                    deptComparechkBox.Checked       = matTex.wiiUSampler.DepthCompareEnabled;
                    depthFuncCB.SelectedItem        = matTex.wiiUSampler.DepthCompareFunc;
                    filterShrinkCB.SelectedItem     = matTex.wiiUSampler.MinFilter;
                    filterExpandCB.SelectedItem     = matTex.wiiUSampler.MagFilter;
                    filterBorderCB.SelectedItem     = matTex.wiiUSampler.BorderType;
                    filterMipmapCB.SelectedItem     = matTex.wiiUSampler.MipFilter;
                    filterAntitropicCB.SelectedItem = matTex.wiiUSampler.MaxAnisotropicRatio;
                    filterZCB.SelectedItem          = matTex.wiiUSampler.ZFilter;
                }
                lodMaxUD.Value = (decimal)matTex.MaxLod;
                lodMinUD.Value = (decimal)matTex.MinLod;
                biasUD.Value   = (decimal)matTex.BiasLod;

                foreach (BNTX bntx in PluginRuntime.bntxContainers)
                {
                    if (bntx.Textures.ContainsKey(name))
                    {
                        Thread = new Thread((ThreadStart)(() =>
                        {
                            textureBP.Image = Switch_Toolbox.Library.Imaging.GetLoadingImage();
                            textureBP.Image = bntx.Textures[name].GetBitmap();
                        }));
                        Thread.Start();
                    }
                }
                foreach (BFRESGroupNode ftexCont in PluginRuntime.ftexContainers)
                {
                    if (ftexCont.ResourceNodes.ContainsKey(name))
                    {
                        Thread = new Thread((ThreadStart)(() =>
                        {
                            textureBP.Image = Switch_Toolbox.Library.Imaging.GetLoadingImage();
                            textureBP.Image = ((FTEX)ftexCont.ResourceNodes[name]).GetBitmap();
                        }));
                        Thread.Start();
                    }
                }
            }
        }
コード例 #26
0
ファイル: NUD.cs プロジェクト: CosmewGH/Kami-Modpack-Builder
        public static List <Material> ReadMaterials(FileData d, PolyData p, int nameOffset)
        {
            int             propoff = p.texprop1;
            List <Material> mats    = new List <Material>();

            while (propoff != 0)
            {
                d.seek(propoff);

                Material m = new Material();
                mats.Add(m);
                m.textures = new List <MatTexture>();

                d.skip(4); //m.Flags = (uint)d.readInt();
                d.skip(4);
                d.skip(2); //m.srcFactor = d.readUShort();
                ushort texCount = d.readUShort();
                d.skip(2); //m.dstFactor = d.readUShort();
                d.skip(1); //m.alphaTest = d.readByte();
                d.skip(1); //m.alphaFunction = d.readByte();

                d.skip(1); // unknown
                d.skip(1); //m.RefAlpha = d.readByte();
                d.skip(2); //m.cullMode = d.readUShort();
                d.skip(4); // padding
                d.skip(4); //m.unkownWater = d.readInt();
                d.skip(4); //m.zBufferOffset = d.readInt();

                for (ushort i = 0; i < texCount; i++)
                {
                    MatTexture tex = new MatTexture();
                    tex.hashPos = d.pos();
                    tex.hash    = d.readInt();
                    d.skip(6); // padding?
                    d.skip(2); //tex.mapMode = d.readUShort();
                    d.skip(1); //tex.wrapModeS = d.readByte();
                    d.skip(1); //tex.wrapModeT = d.readByte();
                    d.skip(1); //tex.minFilter = d.readByte();
                    d.skip(1); //tex.magFilter = d.readByte();
                    d.skip(1); //tex.mipDetail = d.readByte();
                    d.skip(1); //tex.unknown = d.readByte();
                    d.skip(4); // padding?
                    d.skip(2); //tex.unknown2 = d.readShort();
                    m.textures.Add(tex);
                }

                int head = 0x20;

                if (d.Endian != Endianness.Little)
                {
                    while (head != 0)
                    {
                        head = d.readInt();
                        int nameStart = d.readInt();

                        string name = d.readString(nameOffset + nameStart, -1);

                        int pos        = d.pos();
                        int valueCount = d.readInt();
                        d.skip(4);

                        // Material properties should always have 4 values. Use 0 for remaining values.
                        float[] values = new float[4];
                        for (int i = 0; i < values.Length; i++)
                        {
                            if (i < valueCount)
                            {
                                values[i] = d.readFloat();
                            }
                            else
                            {
                                values[i] = 0;
                            }
                        }
                        //m.entries.Add(name, values);

                        d.seek(pos);

                        if (head == 0)
                        {
                            d.skip(0x20 - 8);
                        }
                        else
                        {
                            d.skip(head - 8);
                        }
                    }
                }

                if (propoff == p.texprop1)
                {
                    propoff = p.texprop2;
                }
                else if (propoff == p.texprop2)
                {
                    propoff = p.texprop3;
                }
                else if (propoff == p.texprop3)
                {
                    propoff = p.texprop4;
                }
            }

            return(mats);
        }
コード例 #27
0
ファイル: BFRES_WiiU.cs プロジェクト: Masterkal99/Smash-Forge
        public void Read(ResFile TargetWiiUBFRES)
        {
            Nodes.Add(TModels);
            Nodes.Add(TTextures);
            Nodes.Add(TShaderparam);
            Nodes.Add(TColoranim);
            Nodes.Add(TTextureSRT);
            Nodes.Add(TTexturePat);
            Nodes.Add(TBonevisabilty);
            Nodes.Add(TVisualAnim);
            Nodes.Add(TShapeAnim);
            Nodes.Add(TSceneAnim);
            Nodes.Add(TEmbedded);
            ImageKey         = "bfres";
            SelectedImageKey = "bfres";

            FSKACount = TargetWiiUBFRES.SkeletalAnims.Count;
            FTXPCount = TargetWiiUBFRES.TexPatternAnims.Count;
            FSHUCount = TargetWiiUBFRES.ColorAnims.Count + TargetWiiUBFRES.TexSrtAnims.Count + TargetWiiUBFRES.ShaderParamAnims.Count;

            AnimationCountTotal = FSKACount + FTXPCount + FSHUCount;

            FTEXContainer = new FTEXContainer();
            foreach (Texture tex in TargetWiiUBFRES.Textures.Values)
            {
                string TextureName = tex.Name;
                FTEX   texture     = new FTEX();
                texture.ReadFTEX(tex);

                TTextures.Nodes.Add(texture);

                FTEXContainer.FTEXtextures.Add(texture.Text, texture);
                Runtime.FTEXContainerList.Add(FTEXContainer);
            }

            int ModelCur = 0;

            //FMDLs -Models-
            foreach (Model mdl in TargetWiiUBFRES.Models.Values)
            {
                FMDL_Model model = new FMDL_Model(); //This will store VBN data and stuff
                model.Text = mdl.Name;

                TModels.Nodes.Add(model);

                model.Node_Array = new int[mdl.Skeleton.MatrixToBoneList.Count];
                int nodes = 0;
                foreach (ushort node in mdl.Skeleton.MatrixToBoneList)
                {
                    model.Node_Array[nodes] = node;
                    nodes++;
                }

                foreach (Syroot.NintenTools.Bfres.Bone bn in mdl.Skeleton.Bones.Values)
                {
                    Bone bone = new Bone(model.skeleton);
                    bone.Text        = bn.Name;
                    bone.boneId      = bn.BillboardIndex;
                    bone.parentIndex = bn.ParentIndex;
                    bone.scale       = new float[3];
                    bone.rotation    = new float[4];
                    bone.position    = new float[3];

                    if (bn.FlagsRotation == BoneFlagsRotation.Quaternion)
                    {
                        bone.boneRotationType = 1;
                    }
                    else
                    {
                        bone.boneRotationType = 0;
                    }

                    bone.scale[0]    = bn.Scale.X;
                    bone.scale[1]    = bn.Scale.Y;
                    bone.scale[2]    = bn.Scale.Z;
                    bone.rotation[0] = bn.Rotation.X;
                    bone.rotation[1] = bn.Rotation.Y;
                    bone.rotation[2] = bn.Rotation.Z;
                    bone.rotation[3] = bn.Rotation.W;
                    bone.position[0] = bn.Position.X;
                    bone.position[1] = bn.Position.Y;
                    bone.position[2] = bn.Position.Z;

                    model.skeleton.bones.Add(bone);
                }
                model.skeleton.reset();
                model.skeleton.update();

                //MeshTime!!
                int ShapeCur = 0;
                foreach (Shape shp in mdl.Shapes.Values)
                {
                    Mesh poly = new Mesh();
                    poly.Text            = shp.Name;
                    poly.MaterialIndex   = shp.MaterialIndex;
                    poly.VertexSkinCount = shp.VertexSkinCount;
                    poly.boneIndx        = shp.BoneIndex;
                    poly.fmdlIndx        = ModelCur;

                    foreach (int bn in shp.SkinBoneIndices)
                    {
                        if (!poly.BoneIndexList.ContainsKey(model.skeleton.bones[bn].Text))
                        {
                            poly.BoneIndexList.Add(model.skeleton.bones[bn].Text, bn);
                        }
                    }

                    TModels.Nodes[ModelCur].Nodes.Add(poly);

                    //Create a buffer instance which stores all the buffer data
                    VertexBufferHelper helper = new VertexBufferHelper(mdl.VertexBuffers[shp.VertexBufferIndex], TargetWiiUBFRES.ByteOrder);

                    //Set each array first from the lib if exist. Then add the data all in one loop
                    Syroot.Maths.Vector4F[] vec4Positions = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4Normals   = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4uv0       = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4uv1       = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4uv2       = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4c0        = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4t0        = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4b0        = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4w0        = new Syroot.Maths.Vector4F[0];
                    Syroot.Maths.Vector4F[] vec4i0        = new Syroot.Maths.Vector4F[0];


                    foreach (VertexAttrib att in mdl.VertexBuffers[shp.VertexBufferIndex].Attributes.Values)
                    {
                        Mesh.VertexAttribute attr = new Mesh.VertexAttribute();
                        attr.Name = att.Name;
                        // attr.Format = att.Format;

                        if (att.Name == "_p0")
                        {
                            vec4Positions = WiiUAttributeData(att, helper, "_p0");
                        }
                        if (att.Name == "_n0")
                        {
                            vec4Normals = WiiUAttributeData(att, helper, "_n0");
                        }
                        if (att.Name == "_u0")
                        {
                            vec4uv0 = WiiUAttributeData(att, helper, "_u0");
                        }
                        if (att.Name == "_u1")
                        {
                            vec4uv1 = WiiUAttributeData(att, helper, "_u1");
                        }
                        if (att.Name == "_u2")
                        {
                            vec4uv2 = WiiUAttributeData(att, helper, "_u2");
                        }
                        if (att.Name == "_c0")
                        {
                            vec4c0 = WiiUAttributeData(att, helper, "_c0");
                        }
                        if (att.Name == "_t0")
                        {
                            vec4t0 = WiiUAttributeData(att, helper, "_t0");
                        }
                        if (att.Name == "_b0")
                        {
                            vec4b0 = WiiUAttributeData(att, helper, "_b0");
                        }
                        if (att.Name == "_w0")
                        {
                            vec4w0 = WiiUAttributeData(att, helper, "_w0");
                        }
                        if (att.Name == "_i0")
                        {
                            vec4i0 = WiiUAttributeData(att, helper, "_i0");
                        }

                        poly.vertexAttributes.Add(attr);
                    }
                    for (int i = 0; i < vec4Positions.Length; i++)
                    {
                        Vertex v = new Vertex();
                        if (vec4Positions.Length > 0)
                        {
                            v.pos = new Vector3(vec4Positions[i].X, vec4Positions[i].Y, vec4Positions[i].Z);
                        }
                        if (vec4Normals.Length > 0)
                        {
                            v.nrm = new Vector3(vec4Normals[i].X, vec4Normals[i].Y, vec4Normals[i].Z);
                        }
                        if (vec4uv0.Length > 0)
                        {
                            v.uv0 = new Vector2(vec4uv0[i].X, vec4uv0[i].Y);
                        }
                        if (vec4uv1.Length > 0)
                        {
                            v.uv1 = new Vector2(vec4uv1[i].X, vec4uv1[i].Y);
                        }
                        if (vec4uv2.Length > 0)
                        {
                            v.uv2 = new Vector2(vec4uv2[i].X, vec4uv2[i].Y);
                        }
                        if (vec4w0.Length > 0)
                        {
                            v.boneWeights.Add(vec4w0[i].X);
                            v.boneWeights.Add(vec4w0[i].Y);
                            v.boneWeights.Add(vec4w0[i].Z);
                            v.boneWeights.Add(vec4w0[i].W);
                        }
                        if (vec4i0.Length > 0)
                        {
                            v.boneIds.Add((int)vec4i0[i].X);
                            v.boneIds.Add((int)vec4i0[i].Y);
                            v.boneIds.Add((int)vec4i0[i].Z);
                            v.boneIds.Add((int)vec4i0[i].W);
                        }
                        if (vec4t0.Length > 0)
                        {
                            v.tan = new Vector4(vec4t0[i].X, vec4t0[i].Y, vec4t0[i].Z, vec4t0[i].W);
                        }
                        if (vec4b0.Length > 0)
                        {
                            v.bitan = new Vector4(vec4b0[i].X, vec4b0[i].Y, vec4b0[i].Z, vec4b0[i].W);
                        }
                        if (vec4c0.Length > 0)
                        {
                            v.col = new Vector4(vec4c0[i].X, vec4c0[i].Y, vec4c0[i].Z, vec4c0[i].W);
                        }

                        if (poly.VertexSkinCount == 1)
                        {
                            Matrix4 sb = model.skeleton.bones[model.Node_Array[v.boneIds[0]]].transform;
                            //  Console.WriteLine(model.skeleton.bones[model.Node_Array[v.boneIds[0]]].Text);
                            v.pos = Vector3.TransformPosition(v.pos, sb);
                            v.nrm = Vector3.TransformNormal(v.nrm, sb);
                        }
                        if (poly.VertexSkinCount == 0)
                        {
                            Matrix4 NoBindFix = model.skeleton.bones[poly.boneIndx].transform;
                            v.pos = Vector3.TransformPosition(v.pos, NoBindFix);
                            v.nrm = Vector3.TransformNormal(v.nrm, NoBindFix);
                        }

                        poly.vertices.Add(v);
                    }

                    //shp.Meshes.Count - 1 //For going to the lowest poly LOD mesh


                    poly.BoundingCount = shp.SubMeshBoundings.Count;

                    int CurLOD = 0;
                    foreach (var lod in shp.Meshes)
                    {
                        Mesh.LOD_Mesh lodmsh = new Mesh.LOD_Mesh();
                        lodmsh.index = CurLOD++;

                        uint   FaceCount    = lod.IndexCount;
                        uint[] indicesArray = lod.GetIndices().ToArray();

                        for (int face = 0; face < FaceCount; face++)
                        {
                            lodmsh.faces.Add((int)indicesArray[face] + (int)lod.FirstVertex);
                        }

                        poly.lodMeshes.Add(lodmsh);
                    }

                    foreach (Bounding bnd in shp.SubMeshBoundings)
                    {
                        Mesh.BoundingBox box = new Mesh.BoundingBox();
                        box.Center = new Vector3(bnd.Center.X, bnd.Center.Y, bnd.Center.Z);
                        box.Extent = new Vector3(bnd.Extent.X, bnd.Extent.Y, bnd.Extent.Z);

                        poly.boundingBoxes.Add(box); //Each box is by LOD mesh. This will be in a seperate class later so only one will be added
                    }
                    foreach (float r in shp.RadiusArray)
                    {
                        poly.radius.Add(r);
                    }

                    // Read materials
                    Material mat = mdl.Materials[shp.MaterialIndex];

                    int SampIndex = 0;
                    foreach (var smp in mat.Samplers)
                    {
                        poly.material.Samplers.Add(smp.Key, SampIndex);
                        SampIndex++;
                    }

                    int AlbedoCount = 0;

                    string TextureName = "";

                    MaterialData.ShaderAssign shaderassign = new MaterialData.ShaderAssign();

                    if (mat.ShaderAssign != null) //Some special cases (env models) have none
                    {
                        shaderassign.ShaderModel   = mat.ShaderAssign.ShadingModelName;
                        shaderassign.ShaderArchive = mat.ShaderAssign.ShaderArchiveName;


                        int o = 0;
                        foreach (var op in mat.ShaderAssign.ShaderOptions)
                        {
                            shaderassign.options.Add(op.Key, mat.ShaderAssign.ShaderOptions[o]);
                            o++;
                        }

                        int sa = 0;
                        foreach (var smp in mat.ShaderAssign.SamplerAssigns)
                        {
                            shaderassign.samplers.Add(smp.Key, mat.ShaderAssign.SamplerAssigns[sa]);
                            sa++;
                        }

                        int va = 0;
                        foreach (var att in mat.ShaderAssign.AttribAssigns)
                        {
                            shaderassign.attributes.Add(att.Key, mat.ShaderAssign.AttribAssigns[va]);
                            va++;
                        }
                    }

                    poly.material.shaderassign = shaderassign;

                    int id = 0;
                    foreach (TextureRef tex in mdl.Materials[shp.MaterialIndex].TextureRefs)
                    {
                        TextureName = tex.Name;

                        MatTexture texture = new MatTexture();

                        texture.wrapModeS = (int)mdl.Materials[shp.MaterialIndex].Samplers[id].TexSampler.ClampX;
                        texture.wrapModeT = (int)mdl.Materials[shp.MaterialIndex].Samplers[id].TexSampler.ClampY;


                        bool IsAlbedo = HackyTextureList.Any(TextureName.Contains);

                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_a0")
                        {
                            poly.material.HasDiffuseMap = true;
                            texture.hash = 0;
                            texture.Type = MatTexture.TextureType.Diffuse;
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_a1")
                        {
                            poly.material.HasDiffuseLayer = true;
                            texture.hash = 19;
                            texture.Type = MatTexture.TextureType.DiffuseLayer2;
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_n0")
                        {
                            texture.hash = 1;
                            poly.material.HasNormalMap = true;
                            texture.Type = MatTexture.TextureType.Normal;
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_s0")
                        {
                            texture.hash = 4;
                            poly.material.HasSpecularMap = true;
                            texture.Type = MatTexture.TextureType.Specular;
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_b0")
                        {
                            texture.hash = 2;
                            poly.material.HasShadowMap = true;
                            texture.Type = MatTexture.TextureType.Shadow;
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_b1")
                        {
                            texture.hash = 3;
                            poly.material.HasLightMap = true;
                            texture.Type = MatTexture.TextureType.Light;
                        }
                        if (mdl.Materials[shp.MaterialIndex].Samplers[id].Name == "_e0")
                        {
                            texture.hash = 8;
                            poly.material.HasEmissionMap = true;
                            texture.Type = MatTexture.TextureType.Emission;
                        }

                        texture.Name = TextureName;
                        poly.material.textures.Add(texture);
                        id++;
                    }

                    foreach (Sampler smp in mat.Samplers.Values)
                    {
                        SamplerInfo s = new SamplerInfo();
                        s.WrapModeU = (int)smp.TexSampler.ClampX;
                        s.WrapModeV = (int)smp.TexSampler.ClampY;
                        s.WrapModeW = (int)smp.TexSampler.ClampZ;
                        poly.material.samplerinfo.Add(s);
                    }

                    poly.material.Name = mdl.Materials[shp.MaterialIndex].Name;
                    if (mdl.Materials[shp.MaterialIndex].ShaderParamData != null) //Some special cases (env models) have none
                    {
                        using (Syroot.BinaryData.BinaryDataReader reader = new Syroot.BinaryData.BinaryDataReader(new MemoryStream(mdl.Materials[shp.MaterialIndex].ShaderParamData)))
                        {
                            reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
                            foreach (Syroot.NintenTools.Bfres.ShaderParam param in mdl.Materials[shp.MaterialIndex].ShaderParams.Values)
                            {
                                ShaderParam prm = new ShaderParam();

                                prm.Type = param.Type;
                                prm.Name = param.Name;

                                switch (param.Type)
                                {
                                case ShaderParamType.Float:
                                    reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                    prm.Value_float = reader.ReadSingle();
                                    break;

                                case ShaderParamType.Float2:
                                    reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                    prm.Value_float2 = new Vector2(
                                        reader.ReadSingle(),
                                        reader.ReadSingle());
                                    break;

                                case ShaderParamType.Float3:
                                    reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                    prm.Value_float3 = new Vector3(
                                        reader.ReadSingle(),
                                        reader.ReadSingle(),
                                        reader.ReadSingle()); break;

                                case ShaderParamType.Float4:
                                    reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                    prm.Value_float4 = new Vector4(
                                        reader.ReadSingle(),
                                        reader.ReadSingle(),
                                        reader.ReadSingle(),
                                        reader.ReadSingle()); break;

                                case ShaderParamType.TexSrt:
                                    reader.Seek(param.DataOffset, SeekOrigin.Begin);
                                    ShaderParam.TextureSRT texSRT = new ShaderParam.TextureSRT();
                                    texSRT.Mode      = reader.ReadSingle(); //Scale mode, Maya, max ect
                                    texSRT.scale     = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                                    texSRT.rotate    = reader.ReadSingle();
                                    texSRT.translate = new Vector2(reader.ReadSingle(), reader.ReadSingle());

                                    prm.Value_TexSrt = texSRT; break;
                                }
                                poly.material.matparam.Add(param.Name, prm);
                            }
                            reader.Close();
                        }
                    }


                    model.poly.Add(poly);
                    ShapeCur++;
                }
                models.Add(model);
                ModelCur++;
            }
        }
コード例 #28
0
        //--------------------------------------------------------------------------------------------------------------------------------
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.R))
            {
                inputR = true;
            }

            if (debug_face_image)
            {
                //デバック時、テクスチャも生成し、どこを検出しているか確認できる   During debugging, you can see where they are detected
                if (lock_out_mat != null)
                {
                    if (last_mat != -1)
                    {
                        lock (lock_out_mat[last_mat])
                        {
                            MatTexture.Mat2Texture(out_mat[last_mat], out_texture2D);
                        }

                        gameObject.GetComponent <Renderer>().material.mainTexture = out_texture2D;
                    }
                }
            }
            else
            {
                //位置・回転を反映          adapt position and rotation
                if (model != transform)
                {
                    Position = model.position + pos * position_scale + pos_offset;
                    Rotation = Quaternion.Euler(model.eulerAngles + rot * rotation_scale);
                }

                transform.position = Position;
                transform.rotation = Rotation;
            }
            try
            {
                if (mode == DetectMode.Dlib68 || mode == DetectMode.Mixed)
                {
                    if (blink_tracking)
                    {
                        lock (lock_eye_blink)
                        {
                            if (eye_L_c < 0)
                            {
                                eye_L_c = 0;
                            }
                            else if (eye_L_c > 1)
                            {
                                eye_L_c = 1;
                            }

                            if (eye_R_c < 0)
                            {
                                eye_R_c = 0;
                            }
                            else if (eye_R_c > 1)
                            {
                                eye_R_c = 1;
                            }

                            LeftEyeCloseness  = eye_L_c;
                            RightEyeCloseness = eye_R_c;
                        }
                    }

                    if (eye_tracking)
                    {
                        lock (lock_eye_rotL)
                        {
                            LeftEyeRotation = lefteyerotation;
                        }

                        lock (lock_eye_rotR)
                        {
                            RightEyeRotation = righteyerotation;
                        }
                    }
                }
                lock (lock_fps)
                {
                    if (fin_time.Count == 8)
                    {
                        LinkedListNode <DateTime> node = fin_time.First;
                        for (int i = 0; i < 7; i++)
                        {
                            frame_time[i] = (int)(node.Next.Value - node.Value).TotalMilliseconds;
                            node          = node.Next;
                        }
                        //非同期で走らせてるやつのずらす時間を生成  Clac time which make diff of async roop.
                        diff_time = (int)elapt_time.Average() / (thread - 1);
                        if (diff_time < 1000 / fps_limit)
                        {
                            diff_time = 1000 / fps_limit;
                        }
                    }
                }

                if (mode != DetectMode.OpenCV)
                {
                    if (mode == DetectMode.Dlib5)
                    {
                        lock (lock_landmarks)
                        {
                            Vector2[] parts = new Vector2[5];
                            for (uint i = 0; i < 5; i++)
                            {
                                parts[i].x = landmark_detection[i].X;
                                parts[i].y = landmark_detection[i].Y;
                            }

                            Landmarks = parts;
                        }
                    }
                    else
                    {
                        lock (lock_landmarks)
                        {
                            Vector2[] parts = new Vector2[68];
                            for (uint i = 0; i < 68; i++)
                            {
                                parts[i].x = landmark_detection[i].X;
                                parts[i].y = landmark_detection[i].Y;
                            }

                            Landmarks = parts;
                        }
                    }
                }

                if (fin_time.Count == 8)
                {
                    if (logToFile)
                    {
                        fps_writer.WriteLine(1000 / frame_time.Average());
                        final_writer.WriteLine(Position.x + "," + Position.y + "," + Position.z + "," + Rotation.x + "," + Rotation.y + "," + Rotation.z +
                                               "," + LeftEyeCloseness + "," + RightEyeCloseness + "," + LeftEyeRotation.x + "," + LeftEyeRotation.y + "," + RightEyeRotation.x + "," + RightEyeRotation.y);
                    }
                    else
                    {
                        if (debug_fps)
                        {
                            Debug.Log("FPS = " + (1000 / frame_time.Average()) + " or " + (1000 / diff_time));
                        }
                    }
                }
            }
            catch (Exception) { }
        }
コード例 #29
0
        public static void ReadTextureRefs(this FMAT m, Material mat)
        {
            m.TextureMaps.Clear();

            int    AlbedoCount = 0;
            int    id          = 0;
            string TextureName = "";

            if (mat.TextureRefs == null)
            {
                mat.TextureRefs = new List <TextureRef>();
            }

            int textureUnit = 1;

            foreach (var tex in mat.TextureRefs)
            {
                TextureName = tex.Name;

                MatTexture texture = new MatTexture();
                texture.wiiUSampler = mat.Samplers[id].TexSampler;

                texture.MinLod  = mat.Samplers[id].TexSampler.MinLod;
                texture.MaxLod  = mat.Samplers[id].TexSampler.MaxLod;
                texture.BiasLod = mat.Samplers[id].TexSampler.LodBias;

                texture.wrapModeS = (int)mat.Samplers[id].TexSampler.ClampX;
                texture.wrapModeT = (int)mat.Samplers[id].TexSampler.ClampY;
                texture.wrapModeW = (int)mat.Samplers[id].TexSampler.ClampZ;
                mat.Samplers.TryGetKey(mat.Samplers[id], out texture.SamplerName);

                string useSampler = texture.SamplerName;

                //Use the fragment sampler in the shader assign section. It's usually more accurate this way
                if (mat.ShaderAssign.SamplerAssigns.ContainsKey(texture.SamplerName))
                {
                    useSampler = mat.ShaderAssign.SamplerAssigns[texture.SamplerName];
                }


                if (mat.Samplers[id].TexSampler.MinFilter == GX2TexXYFilterType.Point)
                {
                    texture.minFilter = 1;
                }
                if (mat.Samplers[id].TexSampler.MagFilter == GX2TexXYFilterType.Point)
                {
                    texture.magFilter = 1;
                }
                if (mat.Samplers[id].TexSampler.MinFilter == GX2TexXYFilterType.Bilinear)
                {
                    texture.minFilter = 0;
                }
                if (mat.Samplers[id].TexSampler.MagFilter == GX2TexXYFilterType.Bilinear)
                {
                    texture.magFilter = 0;
                }

                if (Runtime.activeGame == Runtime.ActiveGame.MK8D)
                {
                    if (useSampler == "_a0")
                    {
                        if (AlbedoCount == 0)
                        {
                            m.HasDiffuseMap = true;
                            AlbedoCount++;
                            texture.Type = MatTexture.TextureType.Diffuse;
                        }
                    }
                    if (useSampler == "_n0")
                    {
                        m.HasNormalMap = true;
                        texture.Type   = MatTexture.TextureType.Normal;
                    }
                    if (useSampler == "_e0")
                    {
                        m.HasEmissionMap = true;
                        texture.Type     = MatTexture.TextureType.Emission;
                    }
                    if (useSampler == "_s0")
                    {
                        m.HasSpecularMap = true;
                        texture.Type     = MatTexture.TextureType.Specular;
                    }
                    if (useSampler == "_x0")
                    {
                        m.HasSphereMap = true;
                        texture.Type   = MatTexture.TextureType.SphereMap;
                    }
                    if (useSampler == "_b0")
                    {
                        m.HasShadowMap = true;
                        texture.Type   = MatTexture.TextureType.Shadow;
                    }
                    if (useSampler == "_b1")
                    {
                        m.HasLightMap = true;
                        texture.Type  = MatTexture.TextureType.Light;
                    }
                }
                else if (Runtime.activeGame == Runtime.ActiveGame.SMO)
                {
                    if (useSampler == "_a0")
                    {
                        if (AlbedoCount == 0)
                        {
                            m.HasDiffuseMap = true;
                            AlbedoCount++;
                            texture.Type = MatTexture.TextureType.Diffuse;
                        }
                    }
                    if (useSampler == "_n0")
                    {
                        m.HasNormalMap = true;
                        texture.Type   = MatTexture.TextureType.Normal;
                    }
                    if (useSampler == "_e0")
                    {
                        m.HasEmissionMap = true;
                        texture.Type     = MatTexture.TextureType.Emission;
                    }
                    if (TextureName.Contains("mtl"))
                    {
                        m.HasMetalnessMap = true;
                        texture.Type      = MatTexture.TextureType.Metalness;
                    }
                    else if (TextureName.Contains("rgh"))
                    {
                        texture.Type      = MatTexture.TextureType.Roughness;
                        m.HasRoughnessMap = true;
                    }
                    else if (TextureName.Contains("sss"))
                    {
                        texture.Type = MatTexture.TextureType.SubSurfaceScattering;
                        m.HasSubSurfaceScatteringMap = true;
                    }
                }
                else
                {
                    if (texture.SamplerName == "_a0")
                    {
                        m.HasDiffuseMap = true;
                        AlbedoCount++;
                        texture.Type = MatTexture.TextureType.Diffuse;
                    }
                    if (texture.SamplerName == "_n0")
                    {
                        m.HasNormalMap = true;
                        texture.Type   = MatTexture.TextureType.Normal;
                    }
                    else if (TextureName.Contains("Emm"))
                    {
                        m.HasEmissionMap = true;
                        texture.Type     = MatTexture.TextureType.Emission;
                    }
                    else if (TextureName.Contains("Spm"))
                    {
                        m.HasSpecularMap = true;
                        texture.Type     = MatTexture.TextureType.Specular;
                    }
                    else if (TextureName.Contains("b00"))
                    {
                        m.HasShadowMap = true;
                        texture.Type   = MatTexture.TextureType.Shadow;
                    }
                    else if (TextureName.Contains("Moc") || TextureName.Contains("AO"))
                    {
                        m.HasAmbientOcclusionMap = true;
                        texture.Type             = MatTexture.TextureType.AO;
                    }
                    else if (TextureName.Contains("b01"))
                    {
                        m.HasLightMap = true;
                        texture.Type  = MatTexture.TextureType.Light;
                    }
                    else if (TextureName.Contains("MRA")) //Metalness, Roughness, and Cavity Map in one
                    {
                        m.HasRoughnessMap = true;
                        texture.Type      = MatTexture.TextureType.MRA;
                    }
                    else if (TextureName.Contains("mtl"))
                    {
                        m.HasMetalnessMap = true;
                        texture.Type      = MatTexture.TextureType.Metalness;
                    }
                    else if (TextureName.Contains("rgh"))
                    {
                        texture.Type      = MatTexture.TextureType.Roughness;
                        m.HasRoughnessMap = true;
                    }
                    else if (TextureName.Contains("sss"))
                    {
                        texture.Type = MatTexture.TextureType.SubSurfaceScattering;
                        m.HasSubSurfaceScatteringMap = true;
                    }
                }

                texture.textureUnit = textureUnit++;

                texture.Name = TextureName;
                m.TextureMaps.Add(texture);

                id++;
            }
        }
コード例 #30
0
            public static MatTexture GetDefault()
            {
                MatTexture defaultTex = new MatTexture((int)DummyTextures.DummyRamp);

                return(defaultTex);
            }