private static byte[] EncodeValues(int[] values) { var valuesLength = values.Length; var byteCount = 1 + 4 + valuesLength * 4; // (byte)codecType + (int)integersToRead + (int[])values var bytesList = new List <byte>(byteCount) { (byte)CODECType.Null }; bytesList.AddRange(StreamUtils.ToBytes(valuesLength)); for (int i = 0; i < valuesLength; ++i) { bytesList.AddRange(StreamUtils.ToBytes(values[i])); } return(bytesList.ToArray()); }
public VertexBasedShapeCompressedRepData(int[][] triStrips, float[][] vertexPositions, float[][] vertexNormals = null) { VersionNumber = 1; NormalBinding = (byte)(vertexNormals == null ? 0 : 1); TextureCoordBinding = 0; ColourBinding = 0; QuantizationParameters = new QuantizationParameters(0, 0, 0, 0); // Next we need to make sure that first index of each tristrip is bigger by 1 than last index of previous tristrip // Next we need to extract first index of each tristrip also add last index of last tristrip + 1 var newVertexIndex = 0; var newTriStrips = new int[triStrips.Length][]; var newVertexPositions = new List <float[]>(vertexPositions.Length); var newVertexNormals = vertexNormals == null ? null : new List <float[]>(vertexNormals.Length); for (int triStripIndex = 0, triStripCount = triStrips.Length; triStripIndex < triStripCount; ++triStripIndex) { var triStrip = triStrips[triStripIndex]; var indicesCount = triStrip.Length; var newTriStrip = new int[indicesCount]; for (int i = 0; i < indicesCount; ++i) { newTriStrip[i] = newVertexIndex++; var vertexIndex = triStrip[i]; newVertexPositions.Add(vertexPositions[vertexIndex]); if (vertexNormals != null) { newVertexNormals.Add(vertexNormals[vertexIndex]); } } newTriStrips[triStripIndex] = newTriStrip; } TriStrips = newTriStrips; TriStrips = newTriStrips; Positions = newVertexPositions.ToArray(); Normals = vertexNormals != null?newVertexNormals.ToArray() : null; //Next build vertex data from positons and normals eg x y z, xn yn zn -> repeat //Next convert vertex data to byte array var vertexData = new List <byte>((3 * 4 * newVertexPositions.Count) * (vertexNormals == null ? 1 : 2)); for (int i = 0, c = newVertexPositions.Count; i < c; ++i) { if (vertexNormals != null) { var vertexNormal = Normals[i]; vertexData.AddRange(StreamUtils.ToBytes(vertexNormal[0])); vertexData.AddRange(StreamUtils.ToBytes(vertexNormal[1])); vertexData.AddRange(StreamUtils.ToBytes(vertexNormal[2])); } var vertexPosition = Positions[i]; vertexData.AddRange(StreamUtils.ToBytes(vertexPosition[0])); vertexData.AddRange(StreamUtils.ToBytes(vertexPosition[1])); vertexData.AddRange(StreamUtils.ToBytes(vertexPosition[2])); } LosslessCompressedRawVertexData = new LosslessCompressedRawVertexData(vertexData.ToArray()); }