示例#1
0
        static int _StripCount;                            // stripcount

        /// <summary>
        /// GL_MakeAliasModelDisplayLists
        /// </summary>
        public static void MakeAliasModelDisplayLists(model_t m, aliashdr_t hdr)
        {
            _AliasModel = m;
            _AliasHdr   = hdr;

            //
            // look for a cached version
            //
            string path = Path.ChangeExtension("glquake/" + Path.GetFileNameWithoutExtension(m.name), ".ms2");

            DisposableWrapper <BinaryReader> file;

            Common.FOpenFile(path, out file);
            if (file != null)
            {
                using (file)
                {
                    BinaryReader reader = file.Object;
                    _NumCommands = reader.ReadInt32();
                    _NumOrder    = reader.ReadInt32();
                    for (int i = 0; i < _NumCommands; i++)
                    {
                        _Commands[i] = reader.ReadInt32();
                    }
                    for (int i = 0; i < _NumOrder; i++)
                    {
                        _VertexOrder[i] = reader.ReadInt32();
                    }
                }
            }
            else
            {
                //
                // build it from scratch
                //
                Con.Print("meshing {0}...\n", m.name);

                BuildTris();            // trifans or lists

                //
                // save out the cached version
                //
                string fullpath = Path.Combine(Common.GameDir, path);
                Stream fs       = Sys.FileOpenWrite(fullpath, true);
                if (fs != null)
                {
                    using (BinaryWriter writer = new BinaryWriter(fs, Encoding.ASCII))
                    {
                        writer.Write(_NumCommands);
                        writer.Write(_NumOrder);
                        for (int i = 0; i < _NumCommands; i++)
                        {
                            writer.Write(_Commands[i]);
                        }
                        for (int i = 0; i < _NumOrder; i++)
                        {
                            writer.Write(_VertexOrder[i]);
                        }
                    }
                }
            }

            //
            // save the data out
            //
            _AliasHdr.poseverts = _NumOrder;

            int[] cmds = new int[_NumCommands];                        //Hunk_Alloc (numcommands * 4);
            _AliasHdr.commands = cmds;                                 // in bytes??? // (byte*)cmds - (byte*)paliashdr;
            Buffer.BlockCopy(_Commands, 0, cmds, 0, _NumCommands * 4); //memcpy (cmds, commands, numcommands * 4);

            trivertx_t[][] poseverts = Mod.PoseVerts;
            trivertx_t[]   verts     = new trivertx_t[_AliasHdr.numposes * _AliasHdr.poseverts]; // Hunk_Alloc (paliashdr->numposes * paliashdr->poseverts * sizeof(trivertx_t) );
            _AliasHdr.posedata = verts;                                                          // (byte*)verts - (byte*)paliashdr;
            int offset = 0;

            for (int i = 0; i < _AliasHdr.numposes; i++)
            {
                for (int j = 0; j < _NumOrder; j++)
                {
                    verts[offset++] = poseverts[i][_VertexOrder[j]];  // *verts++ = poseverts[i][vertexorder[j]];
                }
            }
        }
示例#2
0
        /// <summary>
        /// Mod_LoadAliasGroup
        /// </summary>
        /// <returns>Offset of next data block in source byte array</returns>
        static int LoadAliasGroup(ByteArraySegment pin, ref maliasframedesc_t frame)
        {
            int offset = pin.StartIndex;
            daliasgroup_t pingroup = Sys.BytesToStructure<daliasgroup_t>(pin.Data, offset);
            int numframes = Common.LittleLong(pingroup.numframes);

            frame.Init();
            frame.firstpose = _PoseNum;
            frame.numposes = numframes;

            for (int i = 0; i < 3; i++)
            {
                // these are byte values, so we don't have to worry about endianness
                frame.bboxmin.v[i] = pingroup.bboxmin.v[i];
                frame.bboxmin.v[i] = pingroup.bboxmax.v[i];
            }

            offset += daliasgroup_t.SizeInBytes;
            daliasinterval_t pin_intervals = Sys.BytesToStructure<daliasinterval_t>(pin.Data, offset); // (daliasinterval_t*)(pingroup + 1);

            frame.interval = Common.LittleFloat(pin_intervals.interval);

            offset += numframes * daliasinterval_t.SizeInBytes;

            for (int i = 0; i < numframes; i++)
            {
                trivertx_t[] tris = new trivertx_t[_Header.numverts];
                int offset1 = offset + daliasframe_t.SizeInBytes;
                for (int j = 0; j < _Header.numverts; j++, offset1 += trivertx_t.SizeInBytes)
                {
                    tris[j] = Sys.BytesToStructure<trivertx_t>(pin.Data, offset1);
                }
                _PoseVerts[_PoseNum] = tris;
                _PoseNum++;

                offset += daliasframe_t.SizeInBytes + _Header.numverts * trivertx_t.SizeInBytes;
            }

            return offset;
        }
示例#3
0
        static int[] _VertexOrder = new int[MAX_COMMANDS]; // vertexorder

        #endregion Fields

        #region Methods

        /// <summary>
        /// GL_MakeAliasModelDisplayLists
        /// </summary>
        public static void MakeAliasModelDisplayLists(model_t m, aliashdr_t hdr)
        {
            _AliasModel = m;
            _AliasHdr = hdr;

            //
            // look for a cached version
            //
            string path = Path.ChangeExtension("glquake/" + Path.GetFileNameWithoutExtension(m.name), ".ms2");

            DisposableWrapper<BinaryReader> file;
            Common.FOpenFile(path, out file);
            if (file != null)
            {
                using (file)
                {
                    BinaryReader reader = file.Object;
                    _NumCommands = reader.ReadInt32();
                    _NumOrder = reader.ReadInt32();
                    for (int i = 0; i < _NumCommands; i++)
                        _Commands[i] = reader.ReadInt32();
                    for (int i = 0; i < _NumOrder; i++)
                        _VertexOrder[i] = reader.ReadInt32();
                }
            }
            else
            {
                //
                // build it from scratch
                //
                Con.Print("meshing {0}...\n", m.name);

                BuildTris();		// trifans or lists

                //
                // save out the cached version
                //
                string fullpath = Path.Combine(Common.GameDir, path);
                Stream fs = Sys.FileOpenWrite(fullpath, true);
                if (fs != null)
                    using (BinaryWriter writer = new BinaryWriter(fs, Encoding.ASCII))
                    {
                        writer.Write(_NumCommands);
                        writer.Write(_NumOrder);
                        for (int i = 0; i < _NumCommands; i++)
                            writer.Write(_Commands[i]);
                        for (int i = 0; i < _NumOrder; i++)
                            writer.Write(_VertexOrder[i]);
                    }
            }

            //
            // save the data out
            //
            _AliasHdr.poseverts = _NumOrder;

            int[] cmds = new int[_NumCommands]; //Hunk_Alloc (numcommands * 4);
            _AliasHdr.commands = cmds; // in bytes??? // (byte*)cmds - (byte*)paliashdr;
            Buffer.BlockCopy(_Commands, 0, cmds, 0, _NumCommands * 4); //memcpy (cmds, commands, numcommands * 4);

            trivertx_t[][] poseverts = Mod.PoseVerts;
            trivertx_t[] verts = new trivertx_t[_AliasHdr.numposes * _AliasHdr.poseverts]; // Hunk_Alloc (paliashdr->numposes * paliashdr->poseverts * sizeof(trivertx_t) );
            _AliasHdr.posedata = verts; // (byte*)verts - (byte*)paliashdr;
            int offset = 0;
            for (int i = 0; i < _AliasHdr.numposes; i++)
                for (int j = 0; j < _NumOrder; j++)
                {
                    verts[offset++] = poseverts[i][_VertexOrder[j]];  // *verts++ = poseverts[i][vertexorder[j]];
                }
        }
示例#4
0
        /// <summary>
        /// Mod_LoadAliasFrame
        /// </summary>
        /// <returns>Offset of next data block in source byte array</returns>
        static int LoadAliasFrame(ByteArraySegment pin, ref maliasframedesc_t frame)
        {
            daliasframe_t pdaliasframe = Sys.BytesToStructure<daliasframe_t>(pin.Data, pin.StartIndex);

            frame.name = Common.GetString(pdaliasframe.name);
            frame.firstpose = _PoseNum;
            frame.numposes = 1;
            frame.bboxmin.Init();
            frame.bboxmax.Init();

            for (int i = 0; i < 3; i++)
            {
                // these are byte values, so we don't have to worry about
                // endianness
                frame.bboxmin.v[i] = pdaliasframe.bboxmin.v[i];
                frame.bboxmax.v[i] = pdaliasframe.bboxmax.v[i];
            }

            trivertx_t[] verts = new trivertx_t[_Header.numverts];
            int offset = pin.StartIndex + daliasframe_t.SizeInBytes; //pinframe = (trivertx_t*)(pdaliasframe + 1);
            for (int i = 0; i < verts.Length; i++, offset += trivertx_t.SizeInBytes)
            {
                verts[i] = Sys.BytesToStructure<trivertx_t>(pin.Data, offset);
            }
            _PoseVerts[_PoseNum] = verts;
            _PoseNum++;

            return offset;
        }