當前位置: 首頁>>代碼示例>>C#>>正文


C# BitPack.UnpackInt方法代碼示例

本文整理匯總了C#中BitPack.UnpackInt方法的典型用法代碼示例。如果您正苦於以下問題:C# BitPack.UnpackInt方法的具體用法?C# BitPack.UnpackInt怎麽用?C# BitPack.UnpackInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BitPack的用法示例。


在下文中一共展示了BitPack.UnpackInt方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: LoadMesh

        public virtual void LoadMesh(string filename)
        {
            byte[] buffer = File.ReadAllBytes(filename);
            BitPack input = new BitPack(buffer, 0);

            _header = TrimAt0(input.UnpackString(24));
            if (!String.Equals(_header, MESH_HEADER))
                return;

            // Populate base mesh variables
            _hasWeights = (input.UnpackByte() != 0);
            _hasDetailTexCoords = (input.UnpackByte() != 0);
            _position = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
            _rotationAngles = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
            _rotationOrder = input.UnpackByte();
            _scale = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
            _numVertices = (ushort)input.UnpackUShort();

            // Populate the vertex array
            _vertices = new Vertex[_numVertices];

            for (int i = 0; i < _numVertices; i++)
                _vertices[i].Coord = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());

            for (int i = 0; i < _numVertices; i++)
                _vertices[i].Normal = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());

            for (int i = 0; i < _numVertices; i++)
                _vertices[i].BiNormal = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());

            for (int i = 0; i < _numVertices; i++)
                _vertices[i].TexCoord = new Vector2(input.UnpackFloat(), input.UnpackFloat());

            if (_hasDetailTexCoords)
            {
                for (int i = 0; i < _numVertices; i++)
                    _vertices[i].DetailTexCoord = new Vector2(input.UnpackFloat(), input.UnpackFloat());
            }

            if (_hasWeights)
            {
                for (int i = 0; i < _numVertices; i++)
                    _vertices[i].Weight = input.UnpackFloat();
            }

            _numFaces = input.UnpackUShort();

            _faces = new Face[_numFaces];

            for (int i = 0; i < _numFaces; i++)
                _faces[i].Indices = new short[] { input.UnpackShort(), input.UnpackShort(), input.UnpackShort() };

            if (_hasWeights)
            {
                _numSkinJoints = input.UnpackUShort();
                _skinJoints = new string[_numSkinJoints];

                for (int i = 0; i < _numSkinJoints; i++)
                {
                    _skinJoints[i] = TrimAt0(input.UnpackString(64));
                }
            }
            else
            {
                _numSkinJoints = 0;
                _skinJoints = new string[0];
            }

            // Grab morphs
            List<Morph> morphs = new List<Morph>();
            string morphName = TrimAt0(input.UnpackString(64));

            while (morphName != MORPH_FOOTER)
            {
                if (input.BytePos + 48 >= input.Data.Length) throw new FileLoadException("Encountered end of file while parsing morphs");

                Morph morph = new Morph();
                morph.Name = morphName;
                morph.NumVertices = input.UnpackInt();
                morph.Vertices = new MorphVertex[morph.NumVertices];

                for (int i = 0; i < morph.NumVertices; i++)
                {
                    morph.Vertices[i].VertexIndex = input.UnpackUInt();
                    morph.Vertices[i].Coord = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
                    morph.Vertices[i].Normal = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
                    morph.Vertices[i].BiNormal = new Vector3(input.UnpackFloat(), input.UnpackFloat(), input.UnpackFloat());
                    morph.Vertices[i].TexCoord = new Vector2(input.UnpackFloat(), input.UnpackFloat());
                }

                morphs.Add(morph);

                // Grab the next name
                morphName = TrimAt0(input.UnpackString(64));
            }

            _morphs = morphs.ToArray();

            // Check if there are remaps or if we're at the end of the file
            if (input.BytePos < input.Data.Length - 1)
//.........這裏部分代碼省略.........
開發者ID:justincc,項目名稱:libopenmetaverse,代碼行數:101,代碼來源:LindenMesh.cs


注:本文中的BitPack.UnpackInt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。