Пример #1
0
        /// <summary>
        /// Reads a buffer mesh from a byte array
        /// </summary>
        /// <param name="source">Byte source</param>
        /// <param name="address">Address at which the buffermesh is located</param>
        public static BufferMesh Read(byte[] source, uint address, uint imageBase)
        {
            BufferVertex[] vertices       = new BufferVertex[source.ToUInt16(address)];
            bool           continueWeight = source.ToUInt16(address + 2) != 0;

            BufferCorner[] corners   = new BufferCorner[source.ToUInt32(address + 4)];
            uint[]         triangles = new uint[source.ToUInt32(address + 8)];

            address += 12;
            BufferMaterial material = BufferMaterial.Read(source, ref address);

            uint tmpAddr = source.ToUInt32(address) - imageBase;

            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = BufferVertex.Read(source, ref tmpAddr);
            }

            tmpAddr = source.ToUInt32(address += 4) - imageBase;

            for (int i = 0; i < corners.Length; i++)
            {
                corners[i] = BufferCorner.Read(source, ref tmpAddr);
            }

            tmpAddr = source.ToUInt32(address += 4) - imageBase;

            for (int i = 0; i < triangles.Length; i++)
            {
                triangles[i] = source.ToUInt32(tmpAddr);
                tmpAddr     += 4;
            }

            if (vertices.Length == 0)
            {
                return(new BufferMesh(corners, triangles, material));
            }
            else if (corners.Length == 0)
            {
                return(new BufferMesh(vertices, continueWeight));
            }
            else
            {
                return(new BufferMesh(vertices, continueWeight, corners, triangles, material));
            }
        }
Пример #2
0
 /// <summary>
 /// Returns true if the position and normal are equal
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool EqualPosNrm(BufferVertex other)
 {
     return(Position == other.Position && Normal == other.Normal);
 }