Пример #1
0
 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     var fileStream = new FileStream(bldPath + "\\" + listBox1.SelectedIndex.ToString("D4"), FileMode.Open);
     file_2 = bldPath + "\\" + listBox1.SelectedIndex.ToString("D4");
     _nsbmd = NsbmdLoader.LoadNsbmd(fileStream);
     #region Create texture
     File.Create(Path.GetTempPath() + "BLDtexture.nsbtx").Close();
     BinaryWriter writeBLDtexture = new BinaryWriter(File.OpenWrite(Path.GetTempPath() + "BLDtexture.nsbtx"));
     writeBLDtexture.Write((UInt32)0x30585442);
     writeBLDtexture.Write((UInt32)0x0001FEFF);
     fileStream.Position = 0x8;
     int nsbmdSize = fileStream.ReadByte() + (fileStream.ReadByte() << 8) + (fileStream.ReadByte() << 16) + (fileStream.ReadByte() << 24);
     fileStream.Position = 0x14;
     int nsbmdTexOffset = fileStream.ReadByte() + (fileStream.ReadByte() << 8) + (fileStream.ReadByte() << 16) + (fileStream.ReadByte() << 24);
     int texSize = nsbmdSize - nsbmdTexOffset + 0x14;
     writeBLDtexture.Write((UInt32)texSize);
     writeBLDtexture.Write((UInt32)0x00010010);
     writeBLDtexture.Write((UInt32)0x00000014);
     fileStream.Position = nsbmdTexOffset;
     for (int i = 0; i < texSize - 0x14; i++)
     {
         writeBLDtexture.Write((byte)fileStream.ReadByte());
     }
     fileStream.Close();
     writeBLDtexture.Close();
     _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(Path.GetTempPath() + "BLDtexture.nsbtx")), out _nsbmd.Textures, out _nsbmd.Palettes);
     #endregion
     try
     {
         _nsbmd.MatchTextures();
     }
     catch { }
     RenderBuilding(null, null);
     comboBox1.SelectedIndex = 0;
 }
Пример #2
0
        /// <summary>
        /// Load actual map.
        /// </summary>
        /// <param name="file">Map file.</param>
        private static void LoadMap(FileInfo file)
        {
            // Init file read.
            var fileStream = new FileStream(file.FullName, FileMode.Open);
            var reader = new BinaryReader(fileStream);
            Stream nsbmdStream = fileStream;

            // Abort on invalid filesize.
            if (fileStream.Length < 4)
                return ;

            // Read first 4 bytes to determine if
            // file is raw NSBMD.
            var firstFileBytes = reader.ReadInt32();
            fileStream.Position = 0;

            // The file is _definitely_ no NSBMD.
            // Treat it as Pokemon map.
            if (firstFileBytes != Nsbmd.NDS_TYPE_BMD0)
            {
                var demuxer = new PkmnMapDemuxer(reader);
                var memStream = new MemoryStream(demuxer.DemuxBMDBytes()); // Extract BMD bytes from map.
                fileStream.Close();
                fileStream.Dispose();
                nsbmdStream = memStream;
            }

            // Load nsbmd from stream.
            _nsbmd = NsbmdLoader.LoadNsbmd(nsbmdStream);
            nsbmdStream.Close();
            nsbmdStream.Dispose();

            // Material names used in model.
            var modelUsedMaterialList =
                GetMaterialListForNsbmd(_nsbmd);

            // Find matching texture file.
            _usedTextureFile = GetTextureFileToUseForModel(modelUsedMaterialList);

            // If no texture file found, abort.
            if (String.IsNullOrEmpty(_usedTextureFile))
            {
                return ;

                //MessageBox.Show("No matching texture file found! Aborting now...");
                //Environment.Exit(-1);
            }

            // Load materials from external texture file.
            IEnumerable<NsbmdMaterial> loadedMaterials = null;
            var usedTextureFile = new FileInfo(_textureDirectory.FullName + @"\" + _usedTextureFile);

            loadedMaterials = NsbtxLoader.LoadNsbtx(usedTextureFile);

            // Set materials in NSBMD.
            _nsbmd.models[0].Materials.AddRange(loadedMaterials);
            _nsbmd.materials = loadedMaterials;
            _nsbmd.MatchTextures();
        }
Пример #3
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     renderer.ClearOBJ();
     if (comboBox1.SelectedIndex == 0)
     {
         var fileStream = new FileStream(bldPath + "\\" + listBox1.SelectedIndex.ToString("D4"), FileMode.Open);
         file_2 = bldPath + "\\" + listBox1.SelectedIndex.ToString("D4");
         _nsbmd = NsbmdLoader.LoadNsbmd(fileStream);
         fileStream.Close();
         _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(Path.GetTempPath() + "BLDtexture.nsbtx")), out _nsbmd.Textures, out _nsbmd.Palettes);
         try
         {
             _nsbmd.MatchTextures();
         }
         catch { }
         simpleOpenGlControl1.Invalidate();
         RenderBuilding(null, null);
     }
     else
     {
         _nsbmd.models[0].Palettes.Clear();
         _nsbmd.models[0].Textures.Clear();
         var fileStream = new FileStream(bldPath + "\\" + listBox1.SelectedIndex.ToString("D4"), FileMode.Open);
         file_2 = bldPath + "\\" + listBox1.SelectedIndex.ToString("D4");
         _nsbmd = NsbmdLoader.LoadNsbmd(fileStream);
         fileStream.Close();
         _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(editorTileset + "\\" + (comboBox1.SelectedIndex - 1).ToString("D4"))), out _nsbmd.Textures, out _nsbmd.Palettes);
         try
         {
             _nsbmd.MatchTextures();
         }
         catch { }
         simpleOpenGlControl1.Invalidate();
         RenderBuilding(null, null);
     }
 }
Пример #4
0
        /// <summary>
        /// Generate NSBMD from stream.
        /// </summary>
        internal static Nsbmd FromStream(Stream stream)
        {
            var result = new Nsbmd();

            var reader = new BinaryReader(stream);

            int tmp;
            tmp = reader.ReadInt32();
            if (tmp != NDS_TYPE_BMD0)
                throw new Exception();
            tmp = reader.ReadInt32();
            if (tmp != NDS_TYPE_MAGIC2)
                throw new Exception();
            int filesize = reader.ReadInt32();
            if (filesize > stream.Length)
                throw new Exception();
            int numblock = reader.ReadInt32();
            numblock >>= 16;
            if (numblock == 0)
            {
                throw new Exception("DEBUG: no of block zero.\n");
            }
            ///////////////////////////////////////////////////////
            // allocate memory for storing blockoffset
            int[] blockoffset = new int[numblock];
            for (int i = 0; i < numblock; i++)
            {
                tmp = reader.ReadInt32();
                blockoffset[i] = tmp;
            }

            ///////////////////////////////////////////////////////
            // now go to read the blocks
            for (int i = 0; i < numblock; i++)
            {
                stream.Position = blockoffset[i];
                int id = reader.ReadInt32();
                int texnum = 0, palnum = 0;

                switch (id)
                {
                    case NDS_TYPE_MDL0:
                        result.models = ReadMdl0(stream, blockoffset[i]);

                        break;
                    case NDS_TYPE_TEX0:
                        result.materials = NsbtxLoader.ReadTex0(stream, blockoffset[i], out texnum, out palnum, out result.Textures, out result.Palettes);
                        break;
                    default:
                        throw new Exception("Unknown ID");
                        break;
                }
            }

            return result;
        }
Пример #5
0
        /// <summary>
        /// Return material list for NSBMD model.
        /// </summary>
        /// <param name="nsbmd">NSBMD model.</param>
        /// <returns>Material list.</returns>
        private static string[] GetMaterialListForNsbmd(Nsbmd nsbmd)
        {
            var identityStrList = new List<String>();
            foreach (var model in nsbmd.models)
            {
                foreach (var mat in model.Materials)
                {
                    if (String.IsNullOrEmpty(mat.texname))
                        continue;
                    identityStrList.Add(mat.texname);
                }
            }
            identityStrList.Sort();

            return identityStrList.ToArray();
        }
Пример #6
0
        //MTX44[] mt;
        /// <summary>
        /// Render model to OpenGL surface.
        /// </summary>
        public void RenderModel(string file2, MKDS_Course_Editor.NSBTA.NSBTA.NSBTA_File ani, int[] aniframeS, int[] aniframeT, int[] aniframeScaleS, int[] aniframeScaleT, int[] aniframeR, MKDS_Course_Editor.NSBCA.NSBCA.NSBCA_File ca, RenderMode r, bool anim, bool anim2, int selectedanim, float X, float Y, float dist, float elev, float ang, bool licht, MKDS_Course_Editor.NSBTP.NSBTP.NSBTP_File p, Nsbmd nsb)
        {
            MTX44 tmp = new MTX44();
            file = file2;
            for (var j = 0; j < Model.Polygons.Count - 1; j++)
            {
                var poly = Model.Polygons[j];
                int matid = poly.MatId;
                var mat = Model.Materials[matid];
            }
            int light = Gl.glIsEnabled(Gl.GL_LIGHTING);
            Gl.glDisable(Gl.GL_LIGHTING);
            Gl.glLineWidth(2.0F);
            /*float xmin = Model.boundXmin;
            float ymin = Model.boundYmin;
            float zmin = Model.boundZmin;
            float xmax = Model.boundXmax + Model.boundXmin;
            float ymax = Model.boundYmax +Model.boundYmin;
            float zmax = -Model.boundZmax +Model.boundZmin;
            float[][] box = {new float[]
                {
                    xmin, ymin, zmin
                }, new float[]{
                    xmax, ymin, zmin
                }, new float[]{
                    xmax, ymin, zmin
                }, new float[]{
                    xmax, ymax, zmin
                }, new float[]{
                    xmax, ymax, zmin
                }, new float[]{
                    xmin, ymax, zmin
                }, new float[]{
                    xmin, ymax, zmin
                }, new float[]{
                    xmin, ymax, zmax
                }, new float[]{
                    xmin, ymax, zmax
                }, new float[]{
                    xmin, ymin, zmax
                }, new float[]{
                    xmin, ymin, zmax
                }, new float[]{
                    xmax, ymin, zmax
                }, new float[]{
                    xmax, ymin, zmax
                }, new float[]{
                    xmax, ymax, zmax
                }, new float[]{
                    xmin, ymin, zmin
                }, new float[]{
                    xmin, ymax, zmin
                }, new float[]{
                    xmin, ymin, zmin
                }, new float[]{
                    xmin, ymin, zmax
                }, new float[]{
                    xmax, ymin, zmin
                }, new float[]{
                    xmax, ymin, zmax
                }, new float[]{
                    xmax, ymax, zmin
                }, new float[]{
                    xmax, ymax, zmax
                }, new float[]{
                    xmin, ymax, zmax
                }, new float[]{
                    xmax, ymax, zmax
                }
            };
            Gl.glColor3f(1.0F, 1.0F, 1.0F);
            Gl.glBegin(1);
            for(int i = 0; i < box.Length; i++)
                Gl.glVertex3f(box[i][0], box[i][1], box[i][2]);

            Gl.glEnd();*/
            if (light == 1)
            {
                Gl.glEnable(Gl.GL_LIGHTING);
            }
            Gl.glLineWidth(1.0F);
            //float[] fmatrix = new float[64 * 16];
            //float[] jmatrix = new float[Model.Objects.Count * 16];

            ////////////////////////////////////////////////////////////
            // prepare the matrix stack
            for (var i = 0; i < Model.Objects.Count; i++)
            {
                var obj = Model.Objects[i];
                var m_trans = obj.TransVect;

                if (obj.RestoreID != -1)
                    Gl.glLoadMatrixf(MatrixStack[obj.RestoreID].Floats);
                if (obj.StackID != -1)
                {
                    if (obj.Trans)
                        Gl.glTranslatef(m_trans[0], m_trans[1], m_trans[2]);
                    /*if ( obj.rot )  {
                                mtx_Rotate( &tmp, obj->pivot, obj->neg, obj->a, obj->b );
                            glMultMatrixf( (GLfloat *)&tmp );
                        } // TODO
                         */
                    Gl.glGetFloatv(Gl.GL_MODELVIEW_MATRIX, MatrixStack[obj.StackID].Floats);
                    stackID = obj.StackID; // save the last stackID
                }
            }
            Gl.glLoadIdentity();
            ////////////////////////////////////////////////////////////
            // display one polygon of the current model at a time
            //Todo

            ////////////////////////////////////////////////////////////
            // display all polygons of the current model
            for (var i = 0; i < Model.Polygons.Count - 1; i++)
            {
                var poly = Model.Polygons[i];

                if (gOptTexture && !gOptWireFrame && g_mat)
                {
                    int matid = poly.MatId;
                    if (matid == -1)
                    {
                        Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
                        if (writevertex)
                        {
                            mattt.Add(new System.Windows.Media.ImageBrush());
                        }
                    }
                    else
                    {
                        if (writevertex)
                        {
                            mattt.Add(matt[matid]);
                        }
                        NsbmdMaterial mat = Model.Materials[matid];
                        if ((mat.format == 1 || mat.format == 6) && r != RenderMode.Translucent) continue;
                        if ((mat.format == 0 || mat.format == 2 || mat.format == 3 || mat.format == 4 || mat.format == 5 || mat.format == 7) && r != RenderMode.Opaque) continue;
                        Gl.glBindTexture(Gl.GL_TEXTURE_2D, matid + 1 + matstart);

                        // Convert pixel coords to normalised STs
                        Gl.glMatrixMode(Gl.GL_TEXTURE);
                        Gl.glLoadIdentity();
                        if (p.Header.file_size != 0 && new List<string>(p.MPT.names).Contains(mat.MaterialName))
                        {
                            NsbmdMaterial mmm = mat;
                            int texid = 0;
                            for (int l = 0; l < nsb.Textures.Count; l++)
                            {
                                if (nsb.Textures[l].texname == p.AnimData[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)].KeyFrames[frame_[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)]].texName) { texid = l; break; }
                            }
                            mmm.spdata = nsb.Textures[texid].spdata;
                            mmm.texdata = nsb.Textures[texid].texdata;
                            mmm.texname = nsb.Textures[texid].texname;
                            mmm.texoffset = nsb.Textures[texid].texoffset;
                            mmm.texsize = nsb.Textures[texid].texsize;
                            mmm.width = nsb.Textures[texid].width;
                            mmm.height = nsb.Textures[texid].height;
                            mmm.format = nsb.Textures[texid].format;
                            mmm.color0 = nsb.Textures[texid].color0;

                            int palid = 0;
                            for (int l = 0; l < nsb.Textures.Count; l++)
                            {
                                if (nsb.Palettes[l].palname == p.AnimData[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)].KeyFrames[frame_[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)]].palName) { palid = l; break; }
                            }
                            mmm.paldata = nsb.Palettes[palid].paldata;
                            mmm.palname = nsb.Palettes[palid].palname;
                            mmm.paloffset = nsb.Palettes[palid].paloffset;
                            mmm.palsize = nsb.Palettes[palid].palsize;
                            MakeTexture(matid, mmm);
                            if (anim2)
                            {
                                if (nr[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)] == Math.Round((float)(p.MPT.infoBlock.Data[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)].Unknown1) / 512f))
                                {
                                    nr[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)] = 0;
                                    if (frame[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)] == p.MPT.NoFrames - 1)
                                    {
                                        frame[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)] = 0;
                                        frame_[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)] = 0;
                                    }
                                    else
                                    {
                                        frame[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)]++;
                                        if (p.AnimData[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)].KeyFrames.Length != frame_[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)] + 1)
                                        {
                                            if (frame[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)] == p.AnimData[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)].KeyFrames[frame_[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)] + 1].Start)
                                            {
                                                frame_[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)]++;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    nr[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)]++;//= (float)p.MPT.infoBlock.Data[new List<string>(p.MPT.names).IndexOf(mat.MaterialName)].Unknown1 / 4096f;
                                }
                            }
                        }
                        try
                        {
                            if (ani.Header.file_size != 0 && new List<string>(ani.MAT.names).Contains(mat.MaterialName))
                            {
                                int index = new List<string>(ani.MAT.names).IndexOf(mat.MaterialName);
                                Gl.glScaled((double)ani.SRTData[index].scaleS[aniframeScaleS[index]], (double)ani.SRTData[index].scaleT[aniframeScaleT[index]], 1);
                                Gl.glRotated((double)ani.SRTData[index].rotate[aniframeR[index]], 1, 0, 0);
                                //Gl.glRotated((double)ani.SRTData[index].rotate[aniframeR[index] + 1], 0, 1, 0);
                                Gl.glTranslated((double)ani.SRTData[index].translateS[aniframeS[index]], (double)ani.SRTData[index].translateT[aniframeT[index]], 0);
                                if (anim2)
                                {
                                    if (aniframeS[index] == ani.SRTData[index].translateS.Length - 1)
                                    {
                                        aniframeS[index] = 0;
                                    }
                                    else
                                    {
                                        aniframeS[index]++;
                                    }
                                    if (aniframeT[index] == ani.SRTData[index].translateT.Length - 1)
                                    {
                                        aniframeT[index] = 0;
                                    }
                                    else
                                    {
                                        aniframeT[index]++;
                                    }
                                    if (aniframeR[index] == (ani.SRTData[index].rotate.Length - 2) / 2)
                                    {
                                        aniframeR[index] = 0;
                                    }
                                    else
                                    {
                                        aniframeR[index]++;
                                    }
                                    if (aniframeScaleS[index] == ani.SRTData[index].scaleS.Length - 1)
                                    {
                                        aniframeScaleS[index] = 0;
                                    }
                                    else
                                    {
                                        aniframeScaleS[index]++;
                                    }
                                    if (aniframeScaleT[index] == ani.SRTData[index].scaleT.Length - 1)
                                    {
                                        aniframeScaleT[index] = 0;
                                    }
                                    else
                                    {
                                        aniframeScaleT[index]++;
                                    }
                                }
                                goto noscale;
                            }
                            else
                            {
                                goto scale;
                            }
                        }
                        catch
                        {

                        }
                    noscale:
                        if (!mat.isEnvironmentMap)
                        {
                            Gl.glScalef(1.0f / ((float)mat.width), 1.0f / ((float)mat.height), 1.0f);
                        }
                        goto end;
                    scale:
                        if (!mat.isEnvironmentMap)
                        {
                            if (mat.mtx == null)
                            {
                                Gl.glScalef((float)mat.scaleS / ((float)mat.width), (float)mat.scaleT / ((float)mat.height), 1.0f);
                                Gl.glRotatef(mat.rot, 0, 1, 0);
                                Gl.glTranslatef(mat.transS, mat.transT, 0);
                            }
                            else
                            {
                                Gl.glScalef(1.0f / ((float)mat.width), 1.0f / ((float)mat.height), 1.0f);
                                Gl.glMultMatrixf(mat.mtx);
                            }
                        }
                    end:
                        //Gl.glColor4f(1, 1, 0, 0);
                        Gl.glEnable(Gl.GL_ALPHA_TEST);
                        Gl.glAlphaFunc(Gl.GL_GREATER, 0f);
                        Gl.glColor4f(0xff, 0xff, 0xff, 0xff);//(float)mat.Alpha / 31.0f);

                        if (licht && (((mat.PolyAttrib >> 0) & 0x1) == 0 && ((mat.PolyAttrib >> 1) & 0x1) == 0 && ((mat.PolyAttrib >> 2) & 0x1) == 0 && ((mat.PolyAttrib >> 3) & 0x1) == 0) == false)
                        {
                            //Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, new float[] { 1, 1, 1, 0 });
                            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, new float[] { (float)mat.DiffuseColor.R / 255f, (float)mat.DiffuseColor.G / 255f, (float)mat.DiffuseColor.B / 255f, (float)mat.DiffuseColor.A / 255f });
                            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT, new float[] { (float)mat.AmbientColor.R / 255f, (float)mat.AmbientColor.G / 255f, (float)mat.AmbientColor.B / 255f, (float)mat.AmbientColor.A / 255f });
                            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_SPECULAR, new float[] { (float)mat.SpecularColor.R / 255f, (float)mat.SpecularColor.G / 255f, (float)mat.SpecularColor.B / 255f, (float)mat.SpecularColor.A / 255f });
                            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_EMISSION, new float[] { (float)mat.EmissionColor.R / 255f, (float)mat.EmissionColor.G / 255f, (float)mat.EmissionColor.B / 255f, (float)mat.EmissionColor.A / 255f });
                            //Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_POSITION, new float[] { 1, 1, 1, 0 });
                            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_DIFFUSE, new float[] { (float)mat.DiffuseColor.R / 255f, (float)mat.DiffuseColor.G / 255f, (float)mat.DiffuseColor.B / 255f, (float)mat.DiffuseColor.A / 255f });
                            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_AMBIENT, new float[] { (float)mat.AmbientColor.R / 255f, (float)mat.AmbientColor.G / 255f, (float)mat.AmbientColor.B / 255f, (float)mat.AmbientColor.A / 255f });
                            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_SPECULAR, new float[] { (float)mat.SpecularColor.R / 255f, (float)mat.SpecularColor.G / 255f, (float)mat.SpecularColor.B / 255f, (float)mat.SpecularColor.A / 255f });
                            Gl.glLightfv(Gl.GL_LIGHT1, Gl.GL_EMISSION, new float[] { (float)mat.EmissionColor.R / 255f, (float)mat.EmissionColor.G / 255f, (float)mat.EmissionColor.B / 255f, (float)mat.EmissionColor.A / 255f });
                            //Gl.glLightfv(Gl.GL_LIGHT2, Gl.GL_POSITION, new float[] { 1.0f, 1.0f, 1.0f, 0 });
                            Gl.glLightfv(Gl.GL_LIGHT2, Gl.GL_DIFFUSE, new float[] { (float)mat.DiffuseColor.R / 255f, (float)mat.DiffuseColor.G / 255f, (float)mat.DiffuseColor.B / 255f, (float)mat.DiffuseColor.A / 255f });
                            Gl.glLightfv(Gl.GL_LIGHT2, Gl.GL_AMBIENT, new float[] { (float)mat.AmbientColor.R / 255f, (float)mat.AmbientColor.G / 255f, (float)mat.AmbientColor.B / 255f, (float)mat.AmbientColor.A / 255f });
                            Gl.glLightfv(Gl.GL_LIGHT2, Gl.GL_SPECULAR, new float[] { (float)mat.SpecularColor.R / 255f, (float)mat.SpecularColor.G / 255f, (float)mat.SpecularColor.B / 255f, (float)mat.SpecularColor.A / 255f });
                            Gl.glLightfv(Gl.GL_LIGHT2, Gl.GL_EMISSION, new float[] { (float)mat.EmissionColor.R / 255f, (float)mat.EmissionColor.G / 255f, (float)mat.EmissionColor.B / 255f, (float)mat.EmissionColor.A / 255f });
                            //Gl.glLightfv(Gl.GL_LIGHT3, Gl.GL_POSITION, new float[] { 1.0f, 1.0f, 1.0f, 0 });
                            Gl.glLightfv(Gl.GL_LIGHT3, Gl.GL_DIFFUSE, new float[] { (float)mat.DiffuseColor.R / 255f, (float)mat.DiffuseColor.G / 255f, (float)mat.DiffuseColor.B / 255f, (float)mat.DiffuseColor.A / 255f });
                            Gl.glLightfv(Gl.GL_LIGHT3, Gl.GL_AMBIENT, new float[] { (float)mat.AmbientColor.R / 255f, (float)mat.AmbientColor.G / 255f, (float)mat.AmbientColor.B / 255f, (float)mat.AmbientColor.A / 255f });
                            Gl.glLightfv(Gl.GL_LIGHT3, Gl.GL_SPECULAR, new float[] { (float)mat.SpecularColor.R / 255f, (float)mat.SpecularColor.G / 255f, (float)mat.SpecularColor.B / 255f, (float)mat.SpecularColor.A / 255f });
                            Gl.glLightfv(Gl.GL_LIGHT3, Gl.GL_EMISSION, new float[] { (float)mat.EmissionColor.R / 255f, (float)mat.EmissionColor.G / 255f, (float)mat.EmissionColor.B / 255f, (float)mat.EmissionColor.A / 255f });

                            Gl.glEnable(Gl.GL_LIGHTING);
                            if (((mat.PolyAttrib >> 0) & 0x1) == 1) Gl.glEnable(Gl.GL_LIGHT0);
                            else Gl.glDisable(Gl.GL_LIGHT0);
                            if (((mat.PolyAttrib >> 1) & 0x1) == 1) Gl.glEnable(Gl.GL_LIGHT1);
                            else Gl.glDisable(Gl.GL_LIGHT1);
                            if (((mat.PolyAttrib >> 2) & 0x1) == 1) Gl.glEnable(Gl.GL_LIGHT2);
                            else Gl.glDisable(Gl.GL_LIGHT2);
                            if (((mat.PolyAttrib >> 3) & 0x1) == 1) Gl.glEnable(Gl.GL_LIGHT3);
                            else Gl.glDisable(Gl.GL_LIGHT3);

                            if (mat.diffuseColor)
                            {
                                //Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE);
                                Gl.glColor4f((float)mat.DiffuseColor.R / 255f, (float)mat.DiffuseColor.G / 255f, (float)mat.DiffuseColor.B / 255f, (float)mat.DiffuseColor.A / 255f);
                                //Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT);
                                //Gl.glColor4f((float)mat.AmbientColor.R / 255f, (float)mat.AmbientColor.G / 255f, (float)mat.AmbientColor.B / 255f, (float)mat.AmbientColor.A / 255f);
                                //Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_SPECULAR);
                                //Gl.glColor4f((float)mat.SpecularColor.R / 255f, (float)mat.SpecularColor.G / 255f, (float)mat.SpecularColor.B / 255f, (float)mat.SpecularColor.A / 255f);
                                //Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_EMISSION);
                                //Gl.glColor4f((float)mat.EmissionColor.R / 255f, (float)mat.EmissionColor.G / 255f, (float)mat.EmissionColor.B / 255f, (float)mat.EmissionColor.A / 255f);
                                //Gl.glEnable(Gl.GL_COLOR_MATERIAL);
                            }
                            // Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE, new float[] { (float)mat.DiffuseColor.R / 255f, (float)mat.DiffuseColor.G / 255f, (float)mat.DiffuseColor.B / 255f, (float)mat.Alpha / 31.0f });
                            //Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT, new float[] { (float)mat.AmbientColor.R / 255f, (float)mat.AmbientColor.G / 255f, (float)mat.AmbientColor.B / 255f, (float)mat.AmbientColor.A / 255f });
                            //Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_SPECULAR, new float[] { (float)mat.SpecularColor.R / 255f, (float)mat.SpecularColor.G / 255f, (float)mat.SpecularColor.B / 255f, (float)mat.SpecularColor.A / 255f });
                            //Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_EMISSION, new float[] { (float)mat.EmissionColor.R / 255f, (float)mat.EmissionColor.G / 255f, (float)mat.EmissionColor.B / 255f, (float)mat.EmissionColor.A / 255f });
                            //Gl.glEnable(Gl.GL_COLOR_MATERIAL);
                        }
                        else
                        {
                            Gl.glDisable(Gl.GL_LIGHTING);
                            Gl.glDisable(Gl.GL_LIGHT0);
                            Gl.glDisable(Gl.GL_LIGHT1);
                            Gl.glDisable(Gl.GL_LIGHT2);
                            Gl.glDisable(Gl.GL_LIGHT3);
                            if (mat.diffuseColor)
                            {
                                //Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE);
                                Gl.glColor4f((float)mat.DiffuseColor.R / 255f, (float)mat.DiffuseColor.G / 255f, (float)mat.DiffuseColor.B / 255f, (float)mat.DiffuseColor.A / 255f);
                                //Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT);
                                //Gl.glColor4f((float)mat.AmbientColor.R / 255f, (float)mat.AmbientColor.G / 255f, (float)mat.AmbientColor.B / 255f, (float)mat.AmbientColor.A / 255f);
                                //Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_SPECULAR);
                                //Gl.glColor4f((float)mat.SpecularColor.R / 255f, (float)mat.SpecularColor.G / 255f, (float)mat.SpecularColor.B / 255f, (float)mat.SpecularColor.A / 255f);
                                //Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_EMISSION);
                                //Gl.glColor4f((float)mat.EmissionColor.R / 255f, (float)mat.EmissionColor.G / 255f, (float)mat.EmissionColor.B / 255f, (float)mat.EmissionColor.A / 255f);
                                //Gl.glEnable(Gl.GL_COLOR_MATERIAL);
                            }
                            //else
                            //{
                            //	Gl.glColor4f(1, 1, 1, 1);
                                //Gl.glDisable(Gl.GL_COLOR_MATERIAL);
                            //}
                        }
                        Gl.glEnable(Gl.GL_BLEND);
                        if (mat.isEnvironmentMap)
                        {
                            Gl.glTexGeni(Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
                            Gl.glTexGeni(Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
                            Gl.glEnable(Gl.GL_TEXTURE_GEN_S);
                            Gl.glEnable(Gl.GL_TEXTURE_GEN_T);
                            //Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE);
                        }
                        else
                        {
                            Gl.glDisable(Gl.GL_TEXTURE_GEN_S);
                            Gl.glDisable(Gl.GL_TEXTURE_GEN_T);
                            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
                        }

                        int mode = -1;
                        switch ((mat.PolyAttrib >> 4) & 0x3)
                        {
                            case 0:
                                mode = Gl.GL_MODULATE;
                                break;
                            case 1:
                                mode = Gl.GL_DECAL;
                                break;
                            case 2:
                                mode = Gl.GL_MODULATE;
                                break;
                            case 3:
                                mode = Gl.GL_MODULATE;
                                break;
                        }
                        Gl.glTexEnvi(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, mode);
                        int cullmode = -1;
                        //Gl.glEnable(Gl.GL_CULL_FACE);
                        switch (mat.PolyAttrib >> 6 & 0x03)
                        {
                            case 0x03: cullmode = Gl.GL_NONE; break;
                            case 0x02: cullmode = Gl.GL_BACK; break;
                            case 0x01: cullmode = Gl.GL_FRONT; break;
                            case 0x00: cullmode = Gl.GL_FRONT_AND_BACK; break;
                        }
                        Gl.glCullFace(cullmode);
                    }

                }
                else
                {
                    Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
                }
                // Gl.glMatrixMode(Gl.GL_MODELVIEW_MATRIX);
                //Gl.glLoadIdentity();
                if (!gOptColoring)
                {
                    Gl.glColor3f(1, 1, 1);
                }
                stackID = poly.StackID; // the first matrix used by this polygon
                Process3DCommand(poly.PolyData, Model.Materials[poly.MatId], poly.JointID, true);
                /*if (MatrixStack[poly.StackID][0] == 0 && MatrixStack[poly.StackID][5] == 0 && MatrixStack[poly.StackID][10] == 0 && MatrixStack[poly.StackID][15] == 0)
                {

                }
                else
                {

                }*/
            }
            writevertex = false;
        }
Пример #7
0
 public void RenderModel(string file2, MKDS_Course_Editor.NSBTA.NSBTA.NSBTA_File ani, int[] aniframeS, int[] aniframeT, int[] aniframeScaleS, int[] aniframeScaleT, int[] aniframeR, MKDS_Course_Editor.NSBCA.NSBCA.NSBCA_File ca, bool anim, int selectedani, float X, float Y, float dist, float elev, float ang, bool licht, MKDS_Course_Editor.NSBTP.NSBTP.NSBTP_File p, Nsbmd nsb)
 {
     if (lastselectedanim != selectedani && selectedani != -1)
     {
         Tx = new int[ca.JAC[selectedani].ObjInfo.Length];
         Ty = new int[ca.JAC[selectedani].ObjInfo.Length];
         Tz = new int[ca.JAC[selectedani].ObjInfo.Length];
         R = new int[ca.JAC[selectedani].ObjInfo.Length];
         Sx = new int[ca.JAC[selectedani].ObjInfo.Length];
         Sy = new int[ca.JAC[selectedani].ObjInfo.Length];
         Sz = new int[ca.JAC[selectedani].ObjInfo.Length];
         S2x = new int[ca.JAC[selectedani].ObjInfo.Length];
         S2y = new int[ca.JAC[selectedani].ObjInfo.Length];
         S2z = new int[ca.JAC[selectedani].ObjInfo.Length];
         lastselectedanim = selectedani;
     }
     if (frame == null && p.Header.file_size != 0)
     {
         frame = new int[p.MPT.names.Length];
         frame_ = new int[p.MPT.names.Length];
         nr = new int[p.MPT.names.Length];
     }
     RenderModel(file2, ani, aniframeS, aniframeT, aniframeScaleS, aniframeScaleT, aniframeR, ca, RenderMode.Opaque, anim, anim, selectedani, X, Y, dist, elev, ang, licht, p, nsb); //anim, anim);
     RenderModel(file2, ani, aniframeS, aniframeT, aniframeScaleS, aniframeScaleT, aniframeR, ca, RenderMode.Translucent, false, anim, selectedani, X, Y, dist, elev, ang, licht, p, nsb);
 }
Пример #8
0
 public void RenderModel(string file2, MKDS_Course_Editor.NSBTA.NSBTA.NSBTA_File ani, int[] aniframeS, int[] aniframeT, int[] aniframeScaleS, int[] aniframeScaleT, int[] aniframeR, MKDS_Course_Editor.NSBCA.NSBCA.NSBCA_File ca, bool anim, int selectedani, float X, float Y, float dist, float elev, float ang, MKDS_Course_Editor.NSBTP.NSBTP.NSBTP_File p, Nsbmd nsb)
 {
     RenderModel(file2, ani, aniframeS, aniframeT, aniframeScaleS, aniframeScaleT, aniframeR, ca, anim, selectedani, X, Y, dist, elev, ang, true, p, nsb);
 }
Пример #9
0
 // Select Tileset
 private void comboBox7_SelectedIndexChanged(object sender, EventArgs e)
 {
     renderer.ClearOBJ();
     if (comboBox7.SelectedIndex == 0)
     {
         Gl.glDisable(Gl.GL_TEXTURE_2D);
         var fileStream = new FileStream(Path.GetTempPath() + "map.nsbmd", FileMode.Open);
         file_2 = Path.GetTempPath() + "map.nsbmd";
         _nsbmd = NsbmdLoader.LoadNsbmd(fileStream);
         fileStream.Close();
         simpleOpenGlControl2.Invalidate();
         button20_Click(null, null);
     }
     else
     {
         _nsbmd.models[0].Palettes.Clear();
         _nsbmd.models[0].Textures.Clear();
         Gl.glEnable(Gl.GL_TEXTURE_2D);
         var fileStream = new FileStream(Path.GetTempPath() + "map.nsbmd", FileMode.Open);
         file_2 = Path.GetTempPath() + "map.nsbmd";
         _nsbmd = NsbmdLoader.LoadNsbmd(fileStream);
         fileStream.Close();
         _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(workingFolder + @"data\a\0\1\tilesets" + "\\" + (comboBox7.SelectedIndex - 1).ToString("D4"))), out _nsbmd.Textures, out _nsbmd.Palettes);
         try
         {
             _nsbmd.MatchTextures();
         }
         catch { }
         simpleOpenGlControl2.Invalidate();
         button20_Click(null, null);
     }
 }
Пример #10
0
 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     var fileStream = new FileStream(bldPath + "\\" + "model" + "\\" + listBox1.SelectedIndex.ToString("D4"), FileMode.Open);
     file_2 = bldPath + "\\" + "model" + "\\" + listBox1.SelectedIndex.ToString("D4");
     _nsbmd = NsbmdLoader.LoadNsbmd(fileStream);
     if (!checkBox1.Checked)
     {
         _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(Form1.workingFolder + @"data\a\1\7\bldtilesets" + "\\" + comboBox1.SelectedIndex.ToString("D4"))), out _nsbmd.Textures, out _nsbmd.Palettes);
     }
     else
     {
         _nsbmd.materials = LibNDSFormats.NSBTX.NsbtxLoader.LoadNsbtx(new MemoryStream(File.ReadAllBytes(Form1.workingFolder + @"data\a\1\7\bld2tilesets" + "\\" + comboBox1.SelectedIndex.ToString("D4"))), out _nsbmd.Textures, out _nsbmd.Palettes);
     }
     try
     {
         _nsbmd.MatchTextures();
     }
     catch { }
     RenderBuilding(null, null);
     fileStream.Close();
     System.IO.BinaryReader readHeader = new System.IO.BinaryReader(File.OpenRead(bldPath + "\\" + "header" + "\\" + listBox1.SelectedIndex.ToString("D4")));
     numericUpDown1.Value = readHeader.ReadUInt16(); // ID
     readHeader.BaseStream.Position += 2;
     numericUpDown2.Value = readHeader.ReadUInt16(); // Door ID
     numericUpDown3.Value = readHeader.ReadInt16(); // X
     numericUpDown4.Value = readHeader.ReadInt16(); // Y
     numericUpDown5.Value = readHeader.ReadInt16(); // Z
     readHeader.Close();
 }