private bool ParseMultiProperties(IList <string> header, int elementIndex) { int propertyIndexOffset = 0; if (IsGlobal) { propertyIndexOffset = 1; } DictProperties = new Dictionary <string, PlyProperty>(); int iStart = elementIndex + 1; int bytesOffset = 0; string value = null; for (int i = iStart; i < header.Count; i++) { var propertyLine = header[i]; if (propertyLine.Contains("property")) { var propertyElements = propertyLine.Split(' '); if (IsGlobal) { value = propertyElements[3 + propertyIndexOffset]; } PlyMultiProperty plyProperty = new PlyMultiProperty(propertyElements[1 + propertyIndexOffset], propertyElements[2 + propertyIndexOffset], i - iStart, bytesOffset, value); if (!IsGlobal) { bytesOffset += plyProperty.ValueDataBytes; } if (!plyProperty.IsValid) { Debug.LogWarning("Ply: Unknown property value type of element " + ElementName); return(false); } DictProperties.Add(propertyElements[2 + propertyIndexOffset], plyProperty); } else { break; } } return(true); }
public void ParseElementBinaryLittleEndian(byte[] bytes, int bytesOffset, out int bytesUsed, out List <Color32> lineColors) { if (NElement == 0) { bytesUsed = 0; lineColors = null; return; } lineColors = new List <Color32>(); int linesRead = 0; int bytesRead = 0; int[] triangle = new int[3]; while (linesRead < NElement) { var lineIndex = bytesOffset + bytesRead; // First read color info PlyMultiProperty redmultiProperty = (DictProperties["red"] as PlyMultiProperty); PlyMultiProperty greenmultiProperty = (DictProperties["green"] as PlyMultiProperty); PlyMultiProperty bluemultiProperty = (DictProperties["blue"] as PlyMultiProperty); PlyMultiProperty alphamultiProperty = (DictProperties["alpha"] as PlyMultiProperty); byte r = bytes[lineIndex + redmultiProperty.BytesOffset]; byte g = bytes[lineIndex + greenmultiProperty.BytesOffset]; byte b = bytes[lineIndex + bluemultiProperty.BytesOffset]; byte a = bytes[lineIndex + alphamultiProperty.BytesOffset]; lineColors.Add(new Color32(r, g, b, a)); bytesRead += 4; // rgba 4 bytes linesRead++; } bytesUsed = bytesRead; }
public void ParseElementBinaryLittleEndian(byte[] bytes, out int bytesUsed, out IList <Vector3> vertices, out IList <Vector3> normals, out IList <Color32> colors) { if (NElement == 0) { bytesUsed = 0; vertices = null; normals = null; colors = null; return; } vertices = HasPosition ? new List <Vector3>() : null; normals = HasNormal ? new List <Vector3>() : null; colors = HasColor ? new List <Color32>() : null; int bytesPerVertex = 0; foreach (var keyvalue in DictProperties) { bytesPerVertex += keyvalue.Value.ValueDataBytes; } bytesUsed = bytesPerVertex * NElement; int[] coordinateTranslate; int[] signs; _header.GlobalMeshInfoElement.GetCoordinateTransalte(out coordinateTranslate, out signs); float ratioToMeter = _header.GlobalMeshInfoElement.GetUnitToMeterRatio(); float[] value = new float[3]; for (int i = 0; i < NElement; ++i) { int byteIndex = i * bytesPerVertex; if (HasPosition) { PlyMultiProperty xmultiProperty = (DictProperties["x"] as PlyMultiProperty); PlyMultiProperty ymultiProperty = (DictProperties["y"] as PlyMultiProperty); PlyMultiProperty zmultiProperty = (DictProperties["z"] as PlyMultiProperty); value[0] = System.BitConverter.ToSingle(PlyElement.GetBytesSubarray(bytes, byteIndex + xmultiProperty.BytesOffset, xmultiProperty.ValueDataBytes), 0); value[1] = System.BitConverter.ToSingle(PlyElement.GetBytesSubarray(bytes, byteIndex + ymultiProperty.BytesOffset, ymultiProperty.ValueDataBytes), 0); value[2] = System.BitConverter.ToSingle(PlyElement.GetBytesSubarray(bytes, byteIndex + zmultiProperty.BytesOffset, zmultiProperty.ValueDataBytes), 0); vertices.Add(new Vector3(value[coordinateTranslate[0]] * signs[0], value[coordinateTranslate[1]] * signs[1], value[coordinateTranslate[2]] * signs[2]) * ratioToMeter); } if (HasNormal) { PlyMultiProperty xmultiProperty = (DictProperties["nx"] as PlyMultiProperty); PlyMultiProperty ymultiProperty = (DictProperties["ny"] as PlyMultiProperty); PlyMultiProperty zmultiProperty = (DictProperties["nz"] as PlyMultiProperty); value[0] = System.BitConverter.ToSingle(PlyElement.GetBytesSubarray(bytes, byteIndex + xmultiProperty.BytesOffset, xmultiProperty.ValueDataBytes), 0); value[1] = System.BitConverter.ToSingle(PlyElement.GetBytesSubarray(bytes, byteIndex + ymultiProperty.BytesOffset, ymultiProperty.ValueDataBytes), 0); value[2] = System.BitConverter.ToSingle(PlyElement.GetBytesSubarray(bytes, byteIndex + zmultiProperty.BytesOffset, zmultiProperty.ValueDataBytes), 0); Vector3 normal = new Vector3(value[coordinateTranslate[0]] * signs[0], value[coordinateTranslate[1]] * signs[1], value[coordinateTranslate[2]] * signs[2]) * ratioToMeter; normal.Normalize(); normals.Add(normal); } if (HasColor) { PlyMultiProperty redmultiProperty = (DictProperties["red"] as PlyMultiProperty); PlyMultiProperty greenmultiProperty = (DictProperties["green"] as PlyMultiProperty); PlyMultiProperty bluemultiProperty = (DictProperties["blue"] as PlyMultiProperty); PlyMultiProperty alphamultiProperty = (DictProperties["alpha"] as PlyMultiProperty); byte r = bytes[byteIndex + redmultiProperty.BytesOffset]; byte g = bytes[byteIndex + greenmultiProperty.BytesOffset]; byte b = bytes[byteIndex + bluemultiProperty.BytesOffset]; byte a = bytes[byteIndex + alphamultiProperty.BytesOffset]; colors.Add(new Color32(r, g, b, a)); } } }