Ejemplo n.º 1
0
        private void DrawModel(FSHP m, FMDL mdl, Shader shader, bool drawSelection = false)
        {
            if (m.lodMeshes[m.DisplayLODIndex].faces.Count <= 3)
            {
                return;
            }

            SetUniforms(m.GetMaterial(), shader, m, m.DisplayId);
            SetTextureUniforms(m.GetMaterial(), m, shader);
            SetBoneUniforms(shader, mdl);
            SetVertexAttributes(m, shader);
            ApplyTransformFix(mdl, m, shader);

            if (m.Checked && m.Parent.Parent.Checked)
            {
                if ((m.IsSelected))
                {
                    DrawModelSelection(m, shader);
                }
                else
                {
                    if (Runtime.RenderModelWireframe)
                    {
                        DrawModelWireframe(m, shader);
                    }
                    if (Runtime.RenderModels)
                    {
                        PrimitiveType primitiveType = PrimitiveType.Triangles;

                        switch (m.lodMeshes[m.DisplayLODIndex].PrimitiveType)
                        {
                        case STPolygonType.Line:
                            primitiveType = PrimitiveType.Lines;
                            break;

                        case STPolygonType.LineStrip:
                            primitiveType = PrimitiveType.LineStrip;
                            break;

                        case STPolygonType.Point:
                            primitiveType = PrimitiveType.Points;
                            break;

                        case STPolygonType.Triangle:
                            primitiveType = PrimitiveType.Triangles;
                            break;
                        }

                        GL.DrawElements(primitiveType, m.lodMeshes[m.DisplayLODIndex].displayFaceSize, DrawElementsType.UnsignedInt, m.Offset);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void CheckMissingTextures(FSHP shape)
        {
            bool ImportMissingTextures = false;

            foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers)
            {
                foreach (MatTexture tex in shape.GetMaterial().textures)
                {
                    if (!bntx.Textures.ContainsKey(tex.Name))
                    {
                        if (!ImportMissingTextures)
                        {
                            DialogResult result = MessageBox.Show("Missing textures found! Would you like to use placeholders?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                            if (result == DialogResult.Yes)
                            {
                                ImportMissingTextures = true;
                            }
                            else
                            {
                                return;
                            }
                        }

                        if (ImportMissingTextures)
                        {
                            bntx.ImportPlaceholderTexture(tex.Name);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void vtxAttributesCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (vtxAttributesCB.SelectedIndex != -1)
            {
                vtxFormatCB.SelectedIndex = vtxAttributesCB.SelectedIndex;

                string SelectedText = vtxAttributesCB.GetItemText(vtxAttributesCB.SelectedItem);
                if (activeShape.GetMaterial().shaderassign.attributes.ContainsValue(SelectedText))
                {
                    var VertexShaderAttributre = activeShape.GetMaterial().shaderassign.attributes.FirstOrDefault(x => x.Value == SelectedText).Key;

                    shaderAttCB.SelectedIndex = shaderAttCB.FindStringExact(VertexShaderAttributre);
                }
                else
                {
                    shaderAttCB.SelectedIndex = shaderAttCB.FindStringExact("NONE");
                }
            }
        }
Ejemplo n.º 4
0
 public static void SetShaderAssignAttributes(FMAT.ShaderAssign shd, FSHP shape)
 {
     foreach (var att in shape.vertexAttributes)
     {
         if (!shd.attributes.ContainsValue(att.Name) && !shd.attributes.ContainsKey(att.Name))
         {
             shd.attributes.Add(att.Name, att.Name);
         }
     }
     foreach (var tex in shape.GetMaterial().textures)
     {
         if (!shd.samplers.ContainsValue(tex.SamplerName))
         {
             shd.samplers.Add(tex.SamplerName, tex.SamplerName);
         }
     }
 }
Ejemplo n.º 5
0
        public void LoadShape(FSHP fshp)
        {
            InitializeControls();

            activeShape = fshp;

            shapeVertexSkinCountUD.Value = (decimal)fshp.VertexSkinCount;

            FMDL fmdl = fshp.GetParentModel();

            //Load info
            nameTB.Bind(fshp, "Text");
            shapeIndexUD.Value = fmdl.shapes.IndexOf(fshp);

            //Load meshes to toggle LOD display
            for (int i = 0; i < fshp.lodMeshes.Count; i++)
            {
                lodDisplayCB.Items.Add($"mesh {i}");
            }
            lodDisplayCB.SelectedIndex = activeShape.DisplayLODIndex;

            //Load material (all materials will load when activated)
            materialComboBox1.Items.Add(fshp.GetMaterial().Text);
            materialComboBox1.SelectedIndex = 0;

            //Load bone binded (all bones will load when activated)
            bonesCB.Items.Add(fmdl.Skeleton.bones[fshp.BoneIndex].Text);
            bonesCB.SelectedIndex = 0;

            //Load transform
            GetShapeTransform();

            if (fshp.VertexBufferU != null)
            {
                vertexBufferSkinCountUD.Maximum = (decimal)fshp.VertexBufferU.VertexSkinCount;
                vertexBufferSkinCountUD.Value   = (decimal)fshp.VertexBufferU.VertexSkinCount;
                vertexBufferList1.LoadVertexBuffers(fshp, fshp.VertexBufferU);
            }
            else
            {
                vertexBufferSkinCountUD.Maximum = (decimal)fshp.VertexBuffer.VertexSkinCount;
                vertexBufferSkinCountUD.Value   = (decimal)fshp.VertexBuffer.VertexSkinCount;
                vertexBufferList1.LoadVertexBuffers(fshp, fshp.VertexBuffer);
            }

            vtxCountUD.Maximum = fshp.vertices.Count;
            vtxCountUD.Value   = fshp.vertices.Count;


            if (fshp.ShapeU != null)
            {
                keyShapeList1.LoadKeyShapes(fshp.ShapeU.KeyShapes);
            }
            else
            {
                keyShapeList1.LoadKeyShapes(fshp.Shape.KeyShapes, fshp.Shape.KeyShapeDict);
            }

            int lodIndx = 0;

            foreach (var mesh in fshp.lodMeshes)
            {
                lodListView.Items.Add($"Detail Level {lodIndx++}");
            }

            IsLoaded = true;
        }
Ejemplo n.º 6
0
        public void LoadObject(FMDL mdl, FSHP shape)
        {
            InitializeControls();

            activeShape = shape;
            activeModel = mdl;



            //Load all the material names unless there's alot
            if (mdl.materials.Count < 1)
            {
                ReloadMaterialList();
            }
            else
            {
                materialComboBox1.Items.Add(shape.GetMaterial().Text);
                materialComboBox1.SelectedIndex = 0;
            }
            for (int i = 0; i < shape.lodMeshes.Count; i++)
            {
                LODMeshCB.Items.Add($"mesh {i}");
            }
            LODMeshCB.SelectedIndex = activeShape.DisplayLODIndex;

            textBoxName.Text      = shape.Text;
            textBoxBoneIndex.Text = shape.BoneIndex.ToString();
            textBoxMatIndex.Text  = shape.MaterialIndex.ToString();


            bonesCB.Items.Add(mdl.Skeleton.bones[shape.boneIndx].Text);
            bonesCB.SelectedIndex       = 0;
            textBoxVertexSkinCount.Text = shape.VertexSkinCount.ToString();

            if (BFRES.IsWiiU)
            {
            }
            else
            {
                if (shape.Shape.Flags == ShapeFlags.SubMeshBoundaryConsistent)
                {
                    checkBoxUseSubMeshBoundryConsistent.Checked = true;
                }
                if (shape.Shape.Flags == ShapeFlags.HasVertexBuffer)
                {
                    checkBoxUseVertexBuffer.Checked = true;
                }
            }


            shaderAttCB.Items.Add("NONE");
            foreach (FSHP.VertexAttribute att in shape.vertexAttributes)
            {
                vtxAttributesCB.Items.Add(att.Name);
                vtxFormatCB.Items.Add(att.Format);

                if (activeShape.GetMaterial().shaderassign.attributes.ContainsValue(att.Name))
                {
                    var VertexShaderAttributre = activeShape.GetMaterial().shaderassign.attributes.FirstOrDefault(x => x.Value == att.Name).Key;

                    shaderAttCB.Items.Add(VertexShaderAttributre);
                }
            }

            if (vtxAttributesCB.Items.Count > 0)
            {
                vtxAttributesCB.SelectedIndex = 0;
            }
            if (vtxFormatCB.Items.Count > 0)
            {
                vtxFormatCB.SelectedIndex = 0;
            }


            Vector3 translate = new Vector3(0);
            Vector3 scale     = new Vector3(1);
            Vector4 rotate    = new Vector4(0);

            translate = activeShape.boundingBoxes[0].Center;

            transXUD.Value = (decimal)translate.X;
            transYUD.Value = (decimal)translate.Y;
            transZUD.Value = (decimal)translate.Z;
            rotUDX.Value   = (decimal)rotate.X;
            rotUDY.Value   = (decimal)rotate.Y;
            rotUDZ.Value   = (decimal)rotate.Z;
            scaleUDX.Value = (decimal)scale.X;
            scaleUDY.Value = (decimal)scale.Y;
            scaleUDZ.Value = (decimal)scale.Z;

            RenderTools.DrawCube(translate, 2);
        }
Ejemplo n.º 7
0
        private void DrawModel(FSHP m, FMDL mdl, SF.Shader shader, bool ModelSelected)
        {
            if (m.lodMeshes[m.DisplayLODIndex].faces.Count <= 3)
            {
                return;
            }

            var mat = m.GetFMAT();

            if (shader != OpenTKSharedResources.shaders["BFRES_Normals"])
            {
                bool useVertexColors = true;
                if (mat.shaderassign.ShaderArchive == "Park_UBER")
                {
                    useVertexColors = false;
                }

                SetRenderSettings(shader, useVertexColors);
                SetRenderPass(mat);
                SetUniforms(mat, shader, m, m.DisplayId);
                SetTextureUniforms(mat, m, shader);
            }
            SetBoneUniforms(shader, mdl, m);
            ApplyTransformFix(mdl, m, shader);
            SetVertexAttributes(m, shader);

            //Check the binded bone if it's visible from bone visual anims
            //     if (!mdl.Skeleton.bones[m.boneIndx].Visible)
            //         m.Checked = false;

            if (m.Checked && mdl.Skeleton.bones.Count > 0 && mdl.Skeleton.bones[m.BoneIndex].Visible && mat.Enabled)
            {
                shader.SetVector3("materialSelectColor", new Vector3(0));
                if (m.GetMaterial().IsSelected)
                {
                    shader.SetVector3("materialSelectColor", ColorUtility.ToVector3(Color.FromArgb(0, 163, 204)));
                    DrawModelSelection(m, shader);
                }
                else if (m.IsSelected || ModelSelected)
                {
                    DrawModelSelection(m, shader);
                }
                else
                {
                    if (Runtime.RenderModelWireframe)
                    {
                        DrawModelWireframe(m, shader);
                    }
                    if (Runtime.RenderModels)
                    {
                        DrawMdoelHoverSelection(m, shader, IsSelected(), Hovered);

                        PrimitiveType primitiveType = PrimitiveType.Triangles;

                        switch (m.lodMeshes[m.DisplayLODIndex].PrimativeType)
                        {
                        case STPrimitiveType.Lines:
                            primitiveType = PrimitiveType.Lines;
                            break;

                        case STPrimitiveType.LineStrips:
                            primitiveType = PrimitiveType.LineStrip;
                            break;

                        case STPrimitiveType.Points:
                            primitiveType = PrimitiveType.Points;
                            break;

                        case STPrimitiveType.Triangles:
                            primitiveType = PrimitiveType.Triangles;
                            break;
                        }

                        GL.DrawElements(primitiveType, m.lodMeshes[m.DisplayLODIndex].displayFaceSize, DrawElementsType.UnsignedInt, m.Offset);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void DrawModel(FSHP m, FMDL mdl, ShaderProgram shader, bool drawSelection)
        {
            if (m.lodMeshes[m.DisplayLODIndex].faces.Count <= 3)
            {
                return;
            }

            if (shader != normalsShaderProgram)
            {
                SetRenderPass(m.GetMaterial(), shader, m, m.DisplayId);
                SetUniforms(m.GetMaterial(), shader, m, m.DisplayId);
                SetTextureUniforms(m.GetMaterial(), m, shader);
            }
            SetBoneUniforms(shader, mdl, m);
            ApplyTransformFix(mdl, m, shader);
            SetVertexAttributes(m, shader);

            //Check the binded bone if it's visible from bone visual anims
            //     if (!mdl.Skeleton.bones[m.boneIndx].Visible)
            //         m.Checked = false;

            if (m.Checked && mdl.Skeleton.bones.Count > 0 && mdl.Skeleton.bones[m.BoneIndex].Visible)
            {
                shader.SetVector3("materialSelectColor", new Vector3(0));
                if (m.GetMaterial().IsSelected)
                {
                    shader.SetVector3("materialSelectColor", ColorUtility.ToVector3(Color.FromArgb(0, 163, 204)));
                    DrawModelSelection(m, shader);
                }
                else if ((m.IsSelected))
                {
                    DrawModelSelection(m, shader);
                }
                else
                {
                    if (Runtime.RenderModelWireframe)
                    {
                        DrawModelWireframe(m, shader);
                    }
                    if (Runtime.RenderModels)
                    {
                        DrawMdoelHoverSelection(m, shader, IsSelected(), Hovered);

                        PrimitiveType primitiveType = PrimitiveType.Triangles;

                        switch (m.lodMeshes[m.DisplayLODIndex].PrimitiveType)
                        {
                        case STPolygonType.Line:
                            primitiveType = PrimitiveType.Lines;
                            break;

                        case STPolygonType.LineStrip:
                            primitiveType = PrimitiveType.LineStrip;
                            break;

                        case STPolygonType.Point:
                            primitiveType = PrimitiveType.Points;
                            break;

                        case STPolygonType.Triangle:
                            primitiveType = PrimitiveType.Triangles;
                            break;
                        }

                        GL.DrawElements(primitiveType, m.lodMeshes[m.DisplayLODIndex].displayFaceSize, DrawElementsType.UnsignedInt, m.Offset);
                    }
                }
            }
        }