コード例 #1
0
        public bool Render(RenderMode mode, float scale, BCA animation, int frame)
        {
            bool rendered_something = false;

            for (int i = 0; i < m_ModelChunks.Length; i++)
            {
                ModelChunk mdchunk = m_ModelChunks[i];

                if (animation != null && frame > -1)
                {
                    if (mdchunk.Render(mode, scale, animation, frame))
                    {
                        rendered_something = true;
                    }
                }
                else
                {
                    if (mdchunk.Render(mode, scale))
                    {
                        rendered_something = true;
                    }
                }
            }

            return(rendered_something);
        }
コード例 #2
0
        private void btnOpenBCA_Click(object sender, EventArgs e)
        {
            bool wasRunning = m_Running;

            String startFolder = "";

            if (m_BMD != null)
            {
                startFolder = Helper.getDirectory(m_BMD.m_FileName);
            }
            m_ROMFileSelect.ReInitialize("Please select an animation (BCA) file to open.", new String[] { ".bca" }, startFolder);
            var result = m_ROMFileSelect.ShowDialog();

            if (result == DialogResult.OK)
            {
                StopTimer();

                m_BCA           = new BCA(Program.m_ROM.GetFileFromName(m_ROMFileSelect.m_SelectedFile));
                txtBCAName.Text = m_BCA.m_FileName;

                m_AnimationFrameNumber  = 0;
                m_AnimationNumFrames    = m_BCA.m_NumFrames;
                txtCurrentFrameNum.Text = "" + m_AnimationFrameNumber;
                txtNumFrames.Text       = "" + (m_BCA.m_NumFrames - 1);

                if (wasRunning)
                {
                    StartTimer();
                }
            }
        }
コード例 #3
0
        private void btnOpenBCA_Click(object sender, EventArgs e)
        {
            bool wasRunning = m_Running;

            m_ROMFileSelect.Text = "Please select an animation (BCA) file to open.";
            var result = m_ROMFileSelect.ShowDialog();

            if (result == DialogResult.OK)
            {
                StopTimer();

                m_BCA           = new BCA(Program.m_ROM.GetFileFromName(m_ROMFileSelect.m_SelectedFile));
                txtBCAName.Text = m_BCA.m_FileName;

                m_AnimationFrameNumber  = 0;
                m_AnimationNumFrames    = m_BCA.m_NumFrames;
                txtCurrentFrameNum.Text = "" + m_AnimationFrameNumber;
                txtNumFrames.Text       = "" + (m_BCA.m_NumFrames - 1);

                if (wasRunning)
                {
                    StartTimer();
                }
            }
        }
コード例 #4
0
        public static int[] GetDisplayLists(BMD model, BCA animation = null, int frame = -1)
        {
            if (model == null || !m_Models.ContainsKey(model.m_FileName))
            {
                return(null);
            }

            CachedModel cmdl = m_Models[model.m_FileName];

            if (cmdl.m_DisplayLists != null && animation == null)
            {
                return(cmdl.m_DisplayLists);
            }

            int[] dl   = new int[3];
            bool  keep = false;

            dl[0] = GL.GenLists(1);
            GL.NewList(dl[0], ListMode.Compile);
            keep = cmdl.m_Model.Render(RenderMode.Opaque, 1f, animation, frame);
            GL.EndList();
            if (!keep)
            {
                GL.DeleteLists(dl[0], 1); dl[0] = 0;
            }

            dl[1] = GL.GenLists(1);
            GL.NewList(dl[1], ListMode.Compile);
            keep = cmdl.m_Model.Render(RenderMode.Translucent, 1f, animation, frame);
            GL.EndList();
            if (!keep)
            {
                GL.DeleteLists(dl[1], 1); dl[1] = 0;
            }

            dl[2] = GL.GenLists(1);
            GL.NewList(dl[2], ListMode.Compile);
            keep = cmdl.m_Model.Render(RenderMode.Picking, 1f, animation, frame);
            GL.EndList();
            if (!keep)
            {
                GL.DeleteLists(dl[2], 1); dl[2] = 0;
            }

            cmdl.m_DisplayLists = dl;
            return(dl);
        }
コード例 #5
0
            public AnimationData(BCA bca, uint offset, int boneID)
            {
                m_BCA = bca;

                m_ScaleX       = new AnimationDescriptor(m_BCA.m_File, offset + 0x00);
                m_ScaleY       = new AnimationDescriptor(m_BCA.m_File, offset + 0x04);
                m_ScaleZ       = new AnimationDescriptor(m_BCA.m_File, offset + 0x08);
                m_RotationX    = new AnimationDescriptor(m_BCA.m_File, offset + 0x0C);
                m_RotationY    = new AnimationDescriptor(m_BCA.m_File, offset + 0x10);
                m_RotationZ    = new AnimationDescriptor(m_BCA.m_File, offset + 0x14);
                m_TranslationX = new AnimationDescriptor(m_BCA.m_File, offset + 0x18);
                m_TranslationY = new AnimationDescriptor(m_BCA.m_File, offset + 0x1C);
                m_TranslationZ = new AnimationDescriptor(m_BCA.m_File, offset + 0x20);

                m_ScaleXValues       = ReadValuesForDescriptor20_12Float(m_BCA.m_ScaleValuesOffset, m_ScaleX);
                m_ScaleYValues       = ReadValuesForDescriptor20_12Float(m_BCA.m_ScaleValuesOffset, m_ScaleY);
                m_ScaleZValues       = ReadValuesForDescriptor20_12Float(m_BCA.m_ScaleValuesOffset, m_ScaleZ);
                m_RotationXValues    = ReadValuesForDescriptor4_12Rotation(m_BCA.m_RotationValuesOffset, m_RotationX);
                m_RotationYValues    = ReadValuesForDescriptor4_12Rotation(m_BCA.m_RotationValuesOffset, m_RotationY);
                m_RotationZValues    = ReadValuesForDescriptor4_12Rotation(m_BCA.m_RotationValuesOffset, m_RotationZ);
                m_TranslationXValues = ReadValuesForDescriptor20_12Float(m_BCA.m_TranslationValuesOffset, m_TranslationX);
                m_TranslationYValues = ReadValuesForDescriptor20_12Float(m_BCA.m_TranslationValuesOffset, m_TranslationY);
                m_TranslationZValues = ReadValuesForDescriptor20_12Float(m_BCA.m_TranslationValuesOffset, m_TranslationZ);
            }
コード例 #6
0
ファイル: BCA.cs プロジェクト: RicoPlays/sm64dse
            public AnimationData(BCA bca, uint offset, int boneID)
            {
                m_BCA = bca;

                m_ScaleX = new AnimationDescriptor(m_BCA.m_File, offset + 0x00);
                m_ScaleY = new AnimationDescriptor(m_BCA.m_File, offset + 0x04);
                m_ScaleZ = new AnimationDescriptor(m_BCA.m_File, offset + 0x08);
                m_RotationX = new AnimationDescriptor(m_BCA.m_File, offset + 0x0C);
                m_RotationY = new AnimationDescriptor(m_BCA.m_File, offset + 0x10);
                m_RotationZ = new AnimationDescriptor(m_BCA.m_File, offset + 0x14);
                m_TranslationX = new AnimationDescriptor(m_BCA.m_File, offset + 0x18);
                m_TranslationY = new AnimationDescriptor(m_BCA.m_File, offset + 0x1C);
                m_TranslationZ = new AnimationDescriptor(m_BCA.m_File, offset + 0x20);

                m_ScaleXValues = ReadValuesForDescriptor20_12Float(m_BCA.m_ScaleValuesOffset, m_ScaleX);
                m_ScaleYValues = ReadValuesForDescriptor20_12Float(m_BCA.m_ScaleValuesOffset, m_ScaleY);
                m_ScaleZValues = ReadValuesForDescriptor20_12Float(m_BCA.m_ScaleValuesOffset, m_ScaleZ);
                m_RotationXValues = ReadValuesForDescriptor4_12Rotation(m_BCA.m_RotationValuesOffset, m_RotationX);
                m_RotationYValues = ReadValuesForDescriptor4_12Rotation(m_BCA.m_RotationValuesOffset, m_RotationY);
                m_RotationZValues = ReadValuesForDescriptor4_12Rotation(m_BCA.m_RotationValuesOffset, m_RotationZ);
                m_TranslationXValues = ReadValuesForDescriptor20_12Float(m_BCA.m_TranslationValuesOffset, m_TranslationX);
                m_TranslationYValues = ReadValuesForDescriptor20_12Float(m_BCA.m_TranslationValuesOffset, m_TranslationY);
                m_TranslationZValues = ReadValuesForDescriptor20_12Float(m_BCA.m_TranslationValuesOffset, m_TranslationZ);
            }
コード例 #7
0
        private void btnImportAnimation_Click(object sender, EventArgs e)
        {
            if (m_BMD == null || m_BCA == null)
            {
                MessageBox.Show("Please select a valid model (BMD) and animation (BCA) to replace.");
                return;
            }
            if (txtInputAnimation.Text == null || txtInputAnimation.Text.Equals(""))
            {
                MessageBox.Show("Please select an animation file or model to import.");
                return;
            }

            float scale;

            if (!Helper.TryParseFloat(txtScale.Text, out scale))
            {
                MessageBox.Show("Please enter a valid Scale value as a decimal value, eg. 1.234");
                return;
            }

            string animationFormat = txtInputAnimation.Text.Substring(txtInputAnimation.Text.Length - 3).ToLowerInvariant();

            bool wasRunning = m_Running;

            StopTimer();

            try
            {
                ModelBase loadedModel = null;
                switch (animationFormat)
                {
                case "dae":
                {
                    if (txtInputModel.Text != null && !txtInputModel.Text.Equals(""))
                    {
                        loadedModel = BMDImporter.LoadModel(txtInputAnimation.Text, scale);
                        m_BMD       = BMDImporter.CallBMDWriter(ref m_BMD.m_File, loadedModel,
                                                                BMDImporter.BMDExtraImportOptions.DEFAULT, true);
                    }
                    // >>> TODO <<<
                    // Below line in necessary to an obscure bug with NARC files, if you have two file from the same
                    // NARC open and modify and save the first, when you then go to save the second, it won't have
                    // picked up the changes from the first file and when saved will write the original first file and
                    // the modified second file.
                    NitroFile animationFile = Program.m_ROM.GetFileFromName(m_BCA.m_FileName);
                    m_BCA = BMDImporter.ConvertAnimatedDAEToBCA(ref animationFile, txtInputAnimation.Text, m_BCAImportationOptions, true);
                }
                break;

                case "ica":
                {
                    if (txtInputModel.Text != null && !txtInputModel.Text.Equals(""))
                    {
                        loadedModel = BMDImporter.LoadModel(txtInputModel.Text, scale);
                        m_BMD       = BMDImporter.CallBMDWriter(ref m_BMD.m_File, loadedModel,
                                                                BMDImporter.BMDExtraImportOptions.DEFAULT, true);
                    }
                    NitroFile animationFile = Program.m_ROM.GetFileFromName(m_BCA.m_FileName);
                    m_BCA = BMDImporter.ConvertICAToBCA(ref animationFile, txtInputAnimation.Text, loadedModel,
                                                        scale, BMDImporter.BMDExtraImportOptions.DEFAULT, m_BCAImportationOptions, true);
                }
                break;
                }

                m_AnimationFrameNumber  = 0;
                m_AnimationNumFrames    = m_BCA.m_NumFrames;
                txtCurrentFrameNum.Text = "" + m_AnimationFrameNumber;
                txtNumFrames.Text       = "" + (m_BCA.m_NumFrames - 1);

                PrerenderModel();

                if (wasRunning)
                {
                    StartTimer();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred: \n" + ex.Message + "\n\n" + ex.StackTrace);
                m_BMD = new BMD(Program.m_ROM.GetFileFromName(m_BMD.m_FileName));
                m_BCA = new BCA(Program.m_ROM.GetFileFromName(m_BCA.m_FileName));
            }
        }
コード例 #8
0
ファイル: BMD.cs プロジェクト: RicoPlays/sm64dse
        public bool Render(RenderMode mode, float scale, BCA animation, int frame)
        {
            bool rendered_something = false;

            for (int i = 0; i < m_ModelChunks.Length; i++)
            {
                ModelChunk mdchunk = m_ModelChunks[i];

                if (animation != null && frame > -1)
                {
                    if (mdchunk.Render(mode, scale, animation, frame))
                        rendered_something = true;
                }
                else
                {
                    if (mdchunk.Render(mode, scale))
                        rendered_something = true;
                }
            }

            return rendered_something;
        }
コード例 #9
0
ファイル: BMD.cs プロジェクト: RicoPlays/sm64dse
            public bool Render(RenderMode mode, float scale, BCA animation, int frame)
            {
                BeginMode[] beginmodes = { BeginMode.Triangles, BeginMode.Quads, BeginMode.TriangleStrip, BeginMode.QuadStrip };
                bool rendered_something = false;

                if (m_MatGroups.Length == 0)
                    return false;

                bool usesAnimation = (animation != null && frame > -1);
                Matrix4[] animMatrices = (usesAnimation) ?
                    animation.GetAllMatricesForFrame(m_Model.m_ModelChunks, frame) : null;

                foreach (MaterialGroup matgroup in m_MatGroups)
                {
                    if (matgroup.m_Geometry.Count == 0)
                        continue;

                    if (mode == RenderMode.Picking)
                    {
                        GL.DepthMask(!matgroup.IsTranslucent());

                        if ((!m_Billboard) && ((matgroup.m_PolyAttribs & 0xC0) != 0xC0))
                        {
                            GL.Enable(EnableCap.CullFace);
                            GL.CullFace(matgroup.m_CullMode);
                        }
                        else
                            GL.Disable(EnableCap.CullFace);

                        foreach (BMD.VertexList vtxlist in matgroup.m_Geometry)
                        {
                            if (vtxlist.m_VertexList.Count == 0)
                                continue;

                            GL.Begin(beginmodes[vtxlist.m_PolyType]);

                            foreach (BMD.Vertex vtx in vtxlist.m_VertexList)
                            {
                                Vector3 finalvtx = vtx.m_Position;

                                if (!usesAnimation)
                                {
                                    Matrix4 bonemtx = matgroup.m_BoneMatrices[vtx.m_MatrixID];
                                    Vector3.Transform(ref finalvtx, ref bonemtx, out finalvtx);
                                }
                                else
                                {
                                    int boneID = matgroup.m_BoneIDs[vtx.m_MatrixID];
                                    Matrix4 animMatrix = animMatrices[boneID];
                                    Vector3.Transform(ref finalvtx, ref animMatrix, out finalvtx);
                                }
                                Vector3.Multiply(ref finalvtx, scale, out finalvtx);

                                GL.Vertex3(finalvtx);
                            }

                            GL.End();
                            rendered_something = true;
                        }
                    }
                    else
                    {
                        if ((mode == RenderMode.Opaque) && (matgroup.IsTranslucent())) continue;
                        if ((mode == RenderMode.Translucent) && (!matgroup.IsTranslucent())) continue;

                        if ((!m_Billboard) && ((matgroup.m_PolyAttribs & 0xC0) != 0xC0))
                        {
                            GL.Enable(EnableCap.CullFace);
                            GL.CullFace(matgroup.m_CullMode);
                        }
                        else
                            GL.Disable(EnableCap.CullFace);

                        /*if ((matgroup.m_PolyAttribs & 0xF) != 0x0)
                        {
                            GL.Enable(EnableCap.Lighting);

                            if ((matgroup.m_PolyAttribs & 0x1) != 0x0) GL.Enable(EnableCap.Light0);
                            else GL.Disable(EnableCap.Light0);
                            if ((matgroup.m_PolyAttribs & 0x2) != 0x0) GL.Enable(EnableCap.Light1);
                            else GL.Disable(EnableCap.Light1);
                            if ((matgroup.m_PolyAttribs & 0x4) != 0x0) GL.Enable(EnableCap.Light2);
                            else GL.Disable(EnableCap.Light2);
                            if ((matgroup.m_PolyAttribs & 0x8) != 0x0) GL.Enable(EnableCap.Light3);
                            else GL.Disable(EnableCap.Light3);

                            GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, matgroup.m_DiffuseColor);
                            GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Ambient, matgroup.m_AmbientColor);
                            GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Specular, matgroup.m_SpecularColor);
                            GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Emission, matgroup.m_EmissionColor);
                        }
                        else*/
                        GL.Disable(EnableCap.Lighting);

                        GL.BindTexture(TextureTarget.Texture2D, matgroup.m_GLTextureID);

                        if (matgroup.m_GLTextureID != 0)
                            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)matgroup.m_TexEnvMode);

                        foreach (BMD.VertexList vtxlist in matgroup.m_Geometry)
                        {
                            if (vtxlist.m_VertexList.Count == 0)
                                continue;

                            GL.Begin(beginmodes[vtxlist.m_PolyType]);

                            foreach (BMD.Vertex vtx in vtxlist.m_VertexList)
                            {
                                GL.Color4(vtx.m_Color);
                                if (matgroup.m_GLTextureID != 0)
                                    GL.TexCoord2(vtx.m_TexCoord);

                                if ((matgroup.m_PolyAttribs & 0xF) != 0x0)
                                    GL.Normal3(vtx.m_Normal);

                                Vector3 finalvtx = vtx.m_Position;
                                if (!usesAnimation)
                                {
                                    Matrix4 bonemtx = matgroup.m_BoneMatrices[vtx.m_MatrixID];
                                    Vector3.Transform(ref finalvtx, ref bonemtx, out finalvtx);
                                }
                                else
                                {
                                    int boneID = matgroup.m_BoneIDs[vtx.m_MatrixID];
                                    Matrix4 animMatrix = animMatrices[boneID];
                                    Vector3.Transform(ref finalvtx, ref animMatrix, out finalvtx);
                                }
                                Vector3.Multiply(ref finalvtx, scale, out finalvtx);
                                GL.Vertex3(finalvtx);
                            }

                            GL.End();
                            rendered_something = true;
                        }
                    }
                }

                return rendered_something;
            }
コード例 #10
0
            public bool Render(RenderMode mode, float scale, BCA animation, int frame)
            {
                PrimitiveType[] primitiveTypes     = new PrimitiveType[] { PrimitiveType.Triangles, PrimitiveType.Quads, PrimitiveType.TriangleStrip, PrimitiveType.QuadStrip };
                bool            rendered_something = false;

                if (m_MatGroups.Length == 0)
                {
                    return(false);
                }

                bool usesAnimation = (animation != null && frame > -1);

                Matrix4[] animMatrices = (usesAnimation) ?
                                         animation.GetAllMatricesForFrame(m_Model.m_ModelChunks, frame) : null;

                foreach (MaterialGroup matgroup in m_MatGroups)
                {
                    if (matgroup.m_Geometry.Count == 0)
                    {
                        continue;
                    }

                    if (mode == RenderMode.Picking)
                    {
                        GL.DepthMask(!matgroup.IsTranslucent());

                        if ((!m_Billboard) && ((matgroup.m_PolyAttribs & 0xC0) != 0xC0))
                        {
                            GL.Enable(EnableCap.CullFace);
                            GL.CullFace(matgroup.m_CullMode);
                        }
                        else
                        {
                            GL.Disable(EnableCap.CullFace);
                        }

                        foreach (BMD.VertexList vtxlist in matgroup.m_Geometry)
                        {
                            if (vtxlist.m_VertexList.Count == 0)
                            {
                                continue;
                            }

                            GL.Begin(primitiveTypes[vtxlist.m_PolyType]);

                            foreach (BMD.Vertex vtx in vtxlist.m_VertexList)
                            {
                                Vector3 finalvtx = vtx.m_Position;

                                if (!usesAnimation)
                                {
                                    Matrix4 bonemtx = matgroup.m_BoneMatrices[vtx.m_MatrixID];
                                    Vector3.Transform(ref finalvtx, ref bonemtx, out finalvtx);
                                }
                                else
                                {
                                    int     boneID     = matgroup.m_BoneIDs[vtx.m_MatrixID];
                                    Matrix4 animMatrix = animMatrices[boneID];
                                    Vector3.Transform(ref finalvtx, ref animMatrix, out finalvtx);
                                }
                                Vector3.Multiply(ref finalvtx, scale, out finalvtx);

                                GL.Vertex3(finalvtx);
                            }

                            GL.End();
                            rendered_something = true;
                        }
                    }
                    else
                    {
                        if ((mode == RenderMode.Opaque) && (matgroup.IsTranslucent()))
                        {
                            continue;
                        }
                        if ((mode == RenderMode.Translucent) && (!matgroup.IsTranslucent()))
                        {
                            continue;
                        }

                        if ((!m_Billboard) && ((matgroup.m_PolyAttribs & 0xC0) != 0xC0))
                        {
                            GL.Enable(EnableCap.CullFace);
                            GL.CullFace(matgroup.m_CullMode);
                        }
                        else
                        {
                            GL.Disable(EnableCap.CullFace);
                        }

                        /*if ((matgroup.m_PolyAttribs & 0xF) != 0x0)
                         * {
                         *  GL.Enable(EnableCap.Lighting);
                         *
                         *  if ((matgroup.m_PolyAttribs & 0x1) != 0x0) GL.Enable(EnableCap.Light0);
                         *  else GL.Disable(EnableCap.Light0);
                         *  if ((matgroup.m_PolyAttribs & 0x2) != 0x0) GL.Enable(EnableCap.Light1);
                         *  else GL.Disable(EnableCap.Light1);
                         *  if ((matgroup.m_PolyAttribs & 0x4) != 0x0) GL.Enable(EnableCap.Light2);
                         *  else GL.Disable(EnableCap.Light2);
                         *  if ((matgroup.m_PolyAttribs & 0x8) != 0x0) GL.Enable(EnableCap.Light3);
                         *  else GL.Disable(EnableCap.Light3);
                         *
                         *  GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, matgroup.m_DiffuseColor);
                         *  GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Ambient, matgroup.m_AmbientColor);
                         *  GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Specular, matgroup.m_SpecularColor);
                         *  GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Emission, matgroup.m_EmissionColor);
                         * }
                         * else*/
                        GL.Disable(EnableCap.Lighting);

                        GL.BindTexture(TextureTarget.Texture2D, matgroup.m_GLTextureID);

                        if (matgroup.m_GLTextureID != 0)
                        {
                            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)matgroup.m_TexEnvMode);
                        }

                        foreach (BMD.VertexList vtxlist in matgroup.m_Geometry)
                        {
                            if (vtxlist.m_VertexList.Count == 0)
                            {
                                continue;
                            }

                            GL.Begin(primitiveTypes[vtxlist.m_PolyType]);

                            foreach (BMD.Vertex vtx in vtxlist.m_VertexList)
                            {
                                GL.Color4(vtx.m_Color);
                                if (matgroup.m_GLTextureID != 0 && vtx.m_TexCoord != null)
                                {
                                    GL.TexCoord2((Vector2)vtx.m_TexCoord);
                                }

                                if ((matgroup.m_PolyAttribs & 0xF) != 0x0 && vtx.m_Normal != null)
                                {
                                    GL.Normal3((Vector3)vtx.m_Normal);
                                }

                                Vector3 finalvtx = vtx.m_Position;
                                if (!usesAnimation)
                                {
                                    Matrix4 bonemtx = matgroup.m_BoneMatrices[vtx.m_MatrixID];
                                    Vector3.Transform(ref finalvtx, ref bonemtx, out finalvtx);
                                }
                                else
                                {
                                    int     boneID     = matgroup.m_BoneIDs[vtx.m_MatrixID];
                                    Matrix4 animMatrix = animMatrices[boneID];
                                    Vector3.Transform(ref finalvtx, ref animMatrix, out finalvtx);
                                }
                                Vector3.Multiply(ref finalvtx, scale, out finalvtx);
                                GL.Vertex3(finalvtx);
                            }

                            GL.End();
                            rendered_something = true;
                        }
                    }
                }

                return(rendered_something);
            }