Example #1
0
        public void ParseElementBinaryLittleEndian(byte[] bytes, int bytesOffset,
                                                   out int bytesUsed, out List <int> triangles)
        {
            if (NElement == 0)
            {
                bytesUsed = 0;
                triangles = null;
                return;
            }

            var listProperty = DictProperties["vertex_indices"] as PlyListProperty;

            bytesUsed = PlyProperty.GetDataBytes(listProperty.CountNumFormat) + NElement * 3 * PlyProperty.GetDataBytes(listProperty.ValueNumFormat);

            triangles = new List <int>();

            int            facesRead             = 0;
            int            bytesRead             = 0;
            int            bytesPerTriangleIndex = 4;
            CoordinateType coordType             = _plyHeader.GlobalMeshInfoElement.GetCoordinateType();

            int[] triangle = new int[3];
            while (facesRead < NElement)
            {
                var faceIndex  = bytesOffset + bytesRead;
                var indexCount = bytes[faceIndex];
                if (indexCount == 3)
                {
                    for (int i = 0; i < indexCount; ++i)
                    {
                        triangle[i] = System.BitConverter.ToInt32(PlyElement.GetBytesSubarray(bytes, faceIndex + 1 + i * bytesPerTriangleIndex, bytesPerTriangleIndex), 0);
                    }
                    if (coordType == CoordinateType.Left)
                    {
                        triangles.AddRange(triangle);
                    }
                    else // Coordinate.Right
                    {
                        int tmp = triangle[1];
                        triangle[1] = triangle[2];
                        triangle[2] = tmp;
                        triangles.AddRange(triangle);
                    }

                    bytesRead += 1 + indexCount * bytesPerTriangleIndex;
                }
                else
                {
                    Debug.LogWarning("Warning: Found a face is not a triangle face, skipping...");
                }

                facesRead++;
            }
        }
Example #2
0
 public PlyProperty(string valueFormat)
 {
     ValueNumFormat = PlyProperty.GetDataFormat(valueFormat);
     ValueDataBytes = PlyProperty.GetDataBytes(ValueNumFormat);
 }
Example #3
0
 public PlyListProperty(string countFormat, string valueFormat, string name) : base(valueFormat)
 {
     CountNumFormat = PlyProperty.GetDataFormat(countFormat);
     IsValid        = CountNumFormat != ENumFormat.nf_invalid && ValueNumFormat != ENumFormat.nf_invalid;
     _name          = name;
 }