Ejemplo n.º 1
0
 public InstanceNodeElement(Stream stream)
     : base(stream)
 {
     ChildNodeObjectID = StreamUtils.ReadInt32(stream);
 }
Ejemplo n.º 2
0
 public LODNodeElement(Stream stream)
     : base(stream)
 {
     reservedField1 = new VecF32(stream);
     reservedField2 = StreamUtils.ReadInt32(stream);
 }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        public VertexBasedShapeCompressedRepData(Stream stream)
        {
            VersionNumber          = StreamUtils.ReadInt16(stream);
            NormalBinding          = StreamUtils.ReadByte(stream);
            TextureCoordBinding    = StreamUtils.ReadByte(stream);
            ColourBinding          = StreamUtils.ReadByte(stream);
            QuantizationParameters = new QuantizationParameters(stream);

            var primitiveListIndices = Int32CompressedDataPacket.GetArrayI32(stream, Int32CompressedDataPacket.PredictorType.Stride1);

            MemoryStream vertexDataStream;

            if (QuantizationParameters.BitsPerVertex == 0)
            {
                LosslessCompressedRawVertexData = new LosslessCompressedRawVertexData(stream);

                vertexDataStream = new MemoryStream(LosslessCompressedRawVertexData.VertexData);
            }

            else
            {
                throw new NotImplementedException("LossyQuantizedRawVertexData NOT IMPLEMENTED");
            }

            var readNormals       = NormalBinding == 1;
            var readTextureCoords = TextureCoordBinding == 1;
            var readColours       = ColourBinding == 1;

            var vertexEntrySize  = 3 + (readNormals ? 3 : 0) + (readTextureCoords ? 2 : 0) + (readColours ? 3 : 0);
            var vertexEntryCount = (vertexDataStream.Length / 4) / vertexEntrySize;

            var vertexPositions          = new float[vertexEntryCount][];
            var vertexNormals            = readNormals ? new float[vertexEntryCount][] : null;
            var vertexColours            = readColours ? new float[vertexEntryCount][] : null;
            var vertexTextureCoordinates = readTextureCoords ? new float[vertexEntryCount][] : null;

            for (int i = 0; i < vertexEntryCount; ++i)
            {
                if (readTextureCoords)
                {
                    vertexTextureCoordinates[i] = new float[] { StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream) }
                }
                ;

                if (readColours)
                {
                    vertexColours[i] = new float[] { StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream) }
                }
                ;

                if (readNormals)
                {
                    vertexNormals[i] = new float[] { StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream) }
                }
                ;

                vertexPositions[i] = new float[] { StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream), StreamUtils.ReadFloat(vertexDataStream) };
            }

            Positions = vertexPositions;
            Normals   = vertexNormals;

            var triStripCount = primitiveListIndices.Length - 1;
            var triStrips     = new int[triStripCount][];

            for (int triStripIndex = 0; triStripIndex < triStripCount; ++triStripIndex)
            {
                var startIndex = primitiveListIndices[triStripIndex];
                var endIndex   = primitiveListIndices[triStripIndex + 1];

                var indicesCount = endIndex - startIndex;
                var indices      = new int[indicesCount];

                for (int i = 0; i < indicesCount; ++i)
                {
                    indices[i] = startIndex + i;
                }

                triStrips[triStripIndex] = indices;
            }

            TriStrips = triStrips;
        }
    }
}
Ejemplo n.º 5
0
 public UniformQuantizerData(Stream stream)
 {
     Min          = StreamUtils.ReadFloat(stream);
     Max          = StreamUtils.ReadFloat(stream);
     NumberOfBits = StreamUtils.ReadByte(stream);
 }
Ejemplo n.º 6
0
 public TOCEntry(Stream stream) : this(new GUID(stream), StreamUtils.ReadInt32(stream), StreamUtils.ReadInt32(stream), StreamUtils.ReadUInt32(stream))
 {
 }
Ejemplo n.º 7
0
        private static int[] DecodeBytes(Stream stream)
        {
            var codecType = (CODECType)StreamUtils.ReadByte(stream);

            Int32ProbabilityContexts int32ProbabilityContexts = null;

            //int outOfBandValueCount;
            //int[] outOfBandValues;

            if (codecType == CODECType.Huffman || codecType == CODECType.Arithmetic)
            {
                throw new NotImplementedException("Huffman && Arithmetic codec NOT IMPLEMENTED");

                /*int32ProbabilityContexts = new Int32ProbabilityContexts(stream);
                 * outOfBandValueCount = StreamUtils.ReadInt32(stream);
                 *
                 * if (outOfBandValueCount > 0)
                 * {
                 *  outOfBandValues = DecodeBytes(stream);
                 * }*/
            }

            if (codecType != CODECType.Null)
            {
                var codeTextLength    = StreamUtils.ReadInt32(stream);
                var valueElementCount = StreamUtils.ReadInt32(stream);
                //var symbolCount = valueElementCount;

                if (int32ProbabilityContexts != null && int32ProbabilityContexts.ProbabilityContextTableEntries.Length > 1)
                {
                    StreamUtils.ReadInt32(stream); //symbolCount
                }

                var wordsToRead = StreamUtils.ReadInt32(stream);
                var codeText    = new uint[wordsToRead];
                for (int i = 0; i < wordsToRead; ++i)
                {
                    UInt32 codeTextWord;

                    if (StreamUtils.DataIsLittleEndian) // Convert to BigEndian
                    {
                        var bytes = StreamUtils.ReadBytes(stream, 4, true);
                        Array.Reverse(bytes);

                        var result = new UInt32[1];
                        Buffer.BlockCopy(bytes, 0, result, 0, 4);

                        codeTextWord = result[0];
                    }

                    else
                    {
                        codeTextWord = StreamUtils.ReadUInt32(stream);
                    }

                    codeText[i] = codeTextWord;
                }

                switch (codecType)
                {
                case CODECType.Bitlength:
                    return(BitlengthCoder.Decode(codeText, valueElementCount, codeTextLength));

                case CODECType.Huffman:
                    throw new NotImplementedException("Huffman codec NOT IMPLEMENTED");

                case CODECType.Arithmetic:
                    throw new NotImplementedException("Huffman codec NOT IMPLEMENTED");
                }
            }

            else
            {
                var integersToRead = StreamUtils.ReadInt32(stream);

                var decodedSymbols = new int[integersToRead];

                for (int i = 0; i < integersToRead; ++i)
                {
                    decodedSymbols[i] = StreamUtils.ReadInt32(stream);
                }

                return(decodedSymbols);
            }

            return(new int[0]);
        }
Ejemplo n.º 8
0
 public GUID(Stream stream)
 {
     guid = new Guid(StreamUtils.ReadInt32(stream), StreamUtils.ReadInt16(stream), StreamUtils.ReadInt16(stream), StreamUtils.ReadBytes(stream, 8, false));
 }
Ejemplo n.º 9
0
 public SegmentHeader(Stream stream) : this(new GUID(stream), StreamUtils.ReadInt32(stream), StreamUtils.ReadInt32(stream))
 {
 }
Ejemplo n.º 10
0
 public PartNodeElement(Stream stream)
     : base(stream)
 {
     versionNumber = StreamUtils.ReadInt16(stream);
     reservedField = StreamUtils.ReadInt32(stream);
 }
Ejemplo n.º 11
0
 public QuantizationParameters(Stream stream) : this(StreamUtils.ReadByte(stream), StreamUtils.ReadByte(stream), StreamUtils.ReadByte(stream), StreamUtils.ReadByte(stream))
 {
 }
 public FloatingPointPropertyAtomElement(Stream stream)
     : base(stream)
 {
     Value = StreamUtils.ReadFloat(stream);
 }
Ejemplo n.º 13
0
 public LogicElementHeaderZLIB(Stream stream)
 {
     CompressionFlag      = StreamUtils.ReadInt32(stream);
     CompressedDataLength = StreamUtils.ReadInt32(stream);
     CompressionAlgorithm = StreamUtils.ReadByte(stream);
 }
Ejemplo n.º 14
0
 public BasePropertyAtomElement(Stream stream)
 {
     ObjectID   = StreamUtils.ReadInt32(stream);
     StateFlags = StreamUtils.ReadUInt32(stream);
 }
Ejemplo n.º 15
0
 public BaseAttributeElement(Stream stream)
 {
     ObjectId          = StreamUtils.ReadInt32(stream);
     StateFlags        = StreamUtils.ReadByte(stream);
     FieldInhibitFlags = StreamUtils.ReadUInt32(stream);
 }