Exemple #1
0
        private static void UnpackAttributeData(GlobalGeometrySectionStructBlock geometrySectionStructBlock,
                                                GlobalGeometryCompressionInfoBlock compressionInfo)
        {
            foreach (var globalGeometrySectionVertexBufferBlock in geometrySectionStructBlock.VertexBuffers)
            {
                switch (globalGeometrySectionVertexBufferBlock.VertexBuffer.Type)
                {
                case VertexAttributeType.TextureCoordinateCompressed:
                    globalGeometrySectionVertexBufferBlock.VertexBuffer =
                        UnpackTextureCoordinateData(ref globalGeometrySectionVertexBufferBlock.VertexBuffer,
                                                    compressionInfo);
                    break;

                case VertexAttributeType.CoordinateFloat:
                case VertexAttributeType.CoordinateCompressed:
                case VertexAttributeType.CoordinateWithSingleNode:
                case VertexAttributeType.CoordinateWithDoubleNode:
                case VertexAttributeType.CoordinateWithTripleNode:
                    globalGeometrySectionVertexBufferBlock.VertexBuffer =
                        UnpackWorldCoordinateData(ref globalGeometrySectionVertexBufferBlock.VertexBuffer,
                                                  compressionInfo);
                    break;

                case VertexAttributeType.TangentSpaceUnitVectorsCompressed:
                    globalGeometrySectionVertexBufferBlock.VertexBuffer =
                        UnpackLightingData(ref globalGeometrySectionVertexBufferBlock.VertexBuffer);
                    break;
                }
            }
        }
Exemple #2
0
        public PartSurfaceInfo(GlobalGeometrySectionStructBlock geometrySectionStructBlock)
        {
            var lightingData = geometrySectionStructBlock.VertexBuffers.Single(
                e => e.VertexBuffer.Type == VertexAttributeType.UnpackedLightingData).VertexBuffer.Data;
            var lightingDataStride = VertexAttributeType.UnpackedLightingData.GetSize( );
            var count = lightingData.Length / lightingDataStride;

            Normals    = new Vector3[count];
            Bitangents = new Vector3[count];
            Tangents   = new Vector3[count];
            for (var i = 0; i < count; ++i)
            {
                Normals[i] = new Vector3(
                    BitConverter.ToSingle(lightingData, i * lightingDataStride + 0),
                    BitConverter.ToSingle(lightingData, i * lightingDataStride + 4),
                    BitConverter.ToSingle(lightingData, i * lightingDataStride + 8));
                Tangents[i] = new Vector3(
                    BitConverter.ToSingle(lightingData, i * lightingDataStride + 12),
                    BitConverter.ToSingle(lightingData, i * lightingDataStride + 16),
                    BitConverter.ToSingle(lightingData, i * lightingDataStride + 20));
                Bitangents[i] = new Vector3(
                    BitConverter.ToSingle(lightingData, i * lightingDataStride + 24),
                    BitConverter.ToSingle(lightingData, i * lightingDataStride + 28),
                    BitConverter.ToSingle(lightingData, i * lightingDataStride + 32));
            }
        }
Exemple #3
0
        public static GlobalGeometrySectionStructBlock LoadSectionData(
            this GlobalGeometryBlockInfoStructBlock geometryInfo)
        {
            var resourceStream = geometryInfo.GetResourceFromCache( );

            if (resourceStream == null)
            {
                return(default(GlobalGeometrySectionStructBlock));
            }

            var sectionBlock = new GlobalGeometrySectionStructBlock( );

            using (var binaryReader = new BinaryReader(resourceStream))
            {
                sectionBlock.Read(binaryReader);

                var vertexBufferResources = geometryInfo.Resources.Where(
                    x => x.Type == GlobalGeometryBlockResourceBlock.TypeEnum.VertexBuffer).ToArray( );
                for (var i = 0;
                     i < sectionBlock.VertexBuffers.Length && i < vertexBufferResources.Length;
                     ++i)
                {
                    sectionBlock.VertexBuffers[i].VertexBuffer.Data =
                        resourceStream.GetResourceData(vertexBufferResources[i]);
                }
            }
            return(sectionBlock);
        }
Exemple #4
0
 public Mesh(GlobalGeometrySectionStructBlock section,
             GlobalGeometryCompressionInfoBlock compressionInfo) :
     this(section.Parts,
          section.Subparts,
          section.StripIndices.Select(x => x.Index).ToArray(),
          section.VertexBuffers.Select(x => x.VertexBuffer).ToArray(), compressionInfo)
 {
 }
Exemple #5
0
 public bool Contains(GlobalGeometrySectionStructBlock section)
 {
     foreach (var part in section.Parts)
     {
         if (!_storageMeta.ContainsKey(part))
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #6
0
        private static VertexAttributeType[] GetSectionVertexAttributeTypes(GlobalGeometrySectionStructBlock section)
        {
            var sectionVertexBufferTypes =
                new VertexAttributeType[section.VertexBuffers.Length];

            for (var i = 0; i < section.VertexBuffers.Length; ++i)
            {
                sectionVertexBufferTypes[i] = section.VertexBuffers[i].VertexBuffer.Type;
            }

            return(sectionVertexBufferTypes);
        }
Exemple #7
0
 public static void UnpackLightingData(GlobalGeometrySectionStructBlock renderModelSectionStructBlock)
 {
     foreach (var globalGeometrySectionVertexBufferBlock in renderModelSectionStructBlock.VertexBuffers)
     {
         if (globalGeometrySectionVertexBufferBlock.VertexBuffer.Type ==
             VertexAttributeType.TangentSpaceUnitVectorsCompressed)
         {
             globalGeometrySectionVertexBufferBlock.VertexBuffer =
                 UnpackLightingData(ref globalGeometrySectionVertexBufferBlock.VertexBuffer);
         }
     }
 }
Exemple #8
0
        public DefaultIndexedMesh(GlobalGeometrySectionStructBlock geometrySectionStructBlock,
                                  Matrix4 instanceWorldMatrix)
        {
            var collisionParts = geometrySectionStructBlock.Parts.Where(
                e => e.GlobalGeometryPartNewFlags.HasFlag(GlobalGeometryPartBlockNew.Flags.Decalable)).ToArray( );

            if (collisionParts.Length <= 0)
            {
                return;
            }


            int indicesLength = 0;

            foreach (var globalGeometryPartBlockNew in collisionParts)
            {
                indicesLength += globalGeometryPartBlockNew.StripLength;
            }

            var coordinates =
                geometrySectionStructBlock.VertexBuffers.Single(
                    e => e.VertexBuffer.Type == VertexAttributeType.CoordinateFloat).VertexBuffer.Data;
            var coordinateDataStride = VertexAttributeType.CoordinateFloat.GetSize( );
            var vertexCount          = coordinates.Length / coordinateDataStride;


            Allocate(vertexCount, coordinateDataStride, indicesLength / 3, 4 * 3);

            using (BinaryWriter binaryWriter = new BinaryWriter(LockIndices( )))
            {
                foreach (var globalGeometryPartBlockNew in collisionParts)
                {
                    int baseIndex = globalGeometryPartBlockNew.StripStartIndex;
                    for (int i = 0; i < globalGeometryPartBlockNew.StripLength; ++i)
                    {
                        binaryWriter.Write((int)geometrySectionStructBlock.StripIndices[baseIndex + i].Index);
                    }
                }
            }

            using (var binaryReader = new BinaryReader(new MemoryStream(coordinates)))
                using (var binaryWriter = new BinaryWriter(LockVerts()))
                {
                    for (var i = 0; i < vertexCount; ++i)
                    {
                        var value = binaryReader.ReadVector3( );
                        Vector3.Transform(ref value, ref instanceWorldMatrix, out value);
                        binaryWriter.Write(value);
                    }
                }
        }
Exemple #9
0
        public void BufferPartData(GlobalGeometrySectionStructBlock section)
        {
            //  Check to see if data is buffered already

            if (_buckets.Any(u => u.Contains(section)))
            {
                return;
            }

            //  Get the attribute types that the section contains and use them to check if any existing bucket
            //  builder can buffer all the attributes, if not, create a new builder to handle the data
            var attributeTypes     = GetSectionVertexAttributeTypes(section);
            var vertexAttributesId = attributeTypes.GetVertexAttributesId(  );

            if (!_bucketBuilders.ContainsKey(vertexAttributesId))
            {
                _bucketBuilders.Add(vertexAttributesId, new BucketBuilder(new Bucket(attributeTypes)));
            }

            var builder = _bucketBuilders[vertexAttributesId];

            builder.Add(section);
        }
Exemple #10
0
 public void AddIndexedMeshSurfaceData(GlobalGeometrySectionStructBlock globalGeometrySectionStructBlock)
 {
     SurfaceInfo.Add(new PartSurfaceInfo(globalGeometrySectionStructBlock));
 }
Exemple #11
0
 public DefaultIndexedMesh(GlobalGeometrySectionStructBlock geometrySectionStructBlock) : this(geometrySectionStructBlock, Matrix4.Identity)
 {
 }
Exemple #12
0
 private DefaultIndexedMesh GenerateBvhCollisionObjectFromMesh(GlobalGeometrySectionStructBlock globalGeometrySectionStructBlock, Matrix4 instanceWorldMatrix)
 {
     return(new DefaultIndexedMesh(globalGeometrySectionStructBlock, instanceWorldMatrix));
 }
Exemple #13
0
 private static bool IsCollisionMesh(GlobalGeometrySectionStructBlock globalGeometrySectionStructBlock)
 {
     return(globalGeometrySectionStructBlock.Parts.Count(
                e => e.GlobalGeometryPartNewFlags.HasFlag(GlobalGeometryPartBlockNew.Flags.Decalable)) > 0);
 }
Exemple #14
0
 public Mesh(GlobalGeometrySectionStructBlock section) :
     this(section.parts,
          section.stripIndices.Select(x => x.index).ToArray( ),
          section.vertexBuffers.Select(x => x.vertexBuffer).ToArray( ))
 {
 }
Exemple #15
0
 /// <summary>
 /// Returns true if the GlobalGeometrySectionStructBlock vertex attributes matches the bucket attributes
 /// and GeoemetryType matches
 /// </summary>
 /// <param name="sectionStructBlock"></param>
 /// <returns></returns>
 public bool CanBuffer(GlobalGeometrySectionStructBlock sectionStructBlock)
 {
     return
         (_bucket.SupportedVertexAttributes.SequenceEqual(GetSectionVertexAttributeTypes(sectionStructBlock)));
 }
Exemple #16
0
 public void Add(GlobalGeometrySectionStructBlock sectionStructBlock)
 {
     sections.Add(sectionStructBlock);
 }