当前位置: 首页>>代码示例>>C#>>正文


C# ImmutableArray.SetValue方法代码示例

本文整理汇总了C#中ImmutableArray.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ImmutableArray.SetValue方法的具体用法?C# ImmutableArray.SetValue怎么用?C# ImmutableArray.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImmutableArray的用法示例。


在下文中一共展示了ImmutableArray.SetValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

        private void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.ASCII);
            long basePosition = reader.BaseStream.Position;

            string signature = Encoding.ASCII.GetString(reader.ReadBytes(4));

            if (signature != "IDSV")
                throw new InvalidDataException("File signature does not match 'IDSV'.");

            Version = reader.ReadInt32();

            if (Version != 4)
                throw new InvalidDataException(string.Format("File version {0} does not match 4.", Version));

            Checksum = reader.ReadInt32();
            Lods = reader.ReadInt32();

            VertexCounts = new ImmutableArray<int>(MaxNumberOfLods);
            for (int i = 0; i < MaxNumberOfLods; ++i)
            {
                VertexCounts = VertexCounts.SetValue(reader.ReadInt32(), i);
            }

            Fixup[] fixups = new Fixup[reader.ReadInt32()];
            long fixupOffset = reader.ReadInt32();
            long vertexDataOffset = reader.ReadInt32();
            long tangentDataOffset = reader.ReadInt32();
            
            reader.BaseStream.Position = basePosition + fixupOffset;

            for (int i = 0; i < fixups.Length; ++i)
            {
                fixups[i].Lod = reader.ReadInt32();
                fixups[i].SourceVertexID = reader.ReadInt32();
                fixups[i].VertexCount = reader.ReadInt32();
            }

            long vertexCount = (tangentDataOffset - vertexDataOffset) / 48;

            ImmutableArray<BoneWeight>[] boneWeights = new ImmutableArray<BoneWeight>[vertexCount];
            Vector3f[] positions = new Vector3f[vertexCount];
            Vector3f[] normals = new Vector3f[vertexCount];
            Vector2f[] textureCoordinates = new Vector2f[vertexCount];
            Vector4f[] tangents = new Vector4f[vertexCount];

            reader.BaseStream.Position = basePosition + vertexDataOffset;
            for (int v = 0; v < vertexCount; ++v)
            {
                float boneWeight0 = reader.ReadSingle();
                float boneWeight1 = reader.ReadSingle();
                float boneWeight2 = reader.ReadSingle();
                byte bone0 = reader.ReadByte();
                byte bone1 = reader.ReadByte();
                byte bone2 = reader.ReadByte();

                byte boneCount = reader.ReadByte();

                switch (boneCount)
                {
                    case 0:
                        boneWeights[v] = new ImmutableArray<BoneWeight>(0);
                        break;
                    case 1:
                        boneWeights[v] = new ImmutableArray<BoneWeight>(new BoneWeight[] {
                            new BoneWeight(boneWeight0, bone0) });
                        break;
                    case 2:
                        boneWeights[v] = new ImmutableArray<BoneWeight>(new BoneWeight[] {
                            new BoneWeight(boneWeight0, bone0),
                            new BoneWeight(boneWeight1, bone1)});
                        break;
                    case 3:
                        boneWeights[v] = new ImmutableArray<BoneWeight>(new BoneWeight[] {
                            new BoneWeight(boneWeight0, bone0),
                            new BoneWeight(boneWeight1, bone1),
                            new BoneWeight(boneWeight2, bone2)});
                        break;
                }

                positions[v] = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                normals[v] = new Vector3f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                textureCoordinates[v] = new Vector2f(reader.ReadSingle(), reader.ReadSingle());
            }
            
            reader.BaseStream.Position = basePosition + tangentDataOffset;
            for (int v = 0; v < vertexCount; ++v)
            {
                tangents[v] = new Vector4f(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
            }

            Vertex[] vertices = new Vertex[vertexCount];

            for(int v=0;v<vertices.Length;++v)
            {
                vertices[v] = new Vertex(boneWeights[v], positions[v], normals[v], textureCoordinates[v], tangents[v]);
            }

            Vertices = new ImmutableArray<Vertex>(vertices);
        }
开发者ID:Frassle,项目名称:Ibasa,代码行数:100,代码来源:Vvd.cs


注:本文中的ImmutableArray.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。