Exemplo n.º 1
0
 public I3dm()
 {
     I3dmHeader         = new I3dmHeader();
     FeatureTable       = new FeatureTable();
     FeatureTableJson   = string.Empty;
     BatchTableJson     = string.Empty;
     FeatureTableBinary = new byte[0];
     BatchTableBinary   = new byte[0];
 }
Exemplo n.º 2
0
        public static I3dm Read(BinaryReader reader)
        {
            var i3dmHeader        = new I3dmHeader(reader);
            var featureTableJson  = Encoding.UTF8.GetString(reader.ReadBytes(i3dmHeader.FeatureTableJsonByteLength));
            var featureTableBytes = reader.ReadBytes(i3dmHeader.FeatureTableBinaryByteLength);
            var batchTableJson    = Encoding.UTF8.GetString(reader.ReadBytes(i3dmHeader.BatchTableJsonByteLength));
            var batchTableBytes   = reader.ReadBytes(i3dmHeader.BatchTableBinaryByteLength);

            var glbLength = i3dmHeader.ByteLength - i3dmHeader.Length;
            var glbBuffer = reader.ReadBytes(glbLength);

            var serializeOptions = new JsonSerializerOptions();

            serializeOptions.IgnoreNullValues = true;
            serializeOptions.Converters.Add(new Vector3Converter());
            var featureTable = JsonSerializer.Deserialize <FeatureTable>(featureTableJson.TrimEnd(), serializeOptions);

            var positions = GetVector3Collection(featureTable.InstancesLength, featureTable.PositionOffset.offset, featureTableBytes);

            var i3dm = i3dmHeader.GltfFormat == 0 ?
                       new I3dm(positions, Encoding.UTF8.GetString(glbBuffer)) : new I3dm(positions, glbBuffer);

            i3dm.I3dmHeader         = i3dmHeader;
            i3dm.FeatureTableJson   = featureTableJson;
            i3dm.FeatureTableBinary = featureTableBytes;
            i3dm.BatchTableJson     = batchTableJson;
            i3dm.BatchTableBinary   = batchTableBytes;
            i3dm.FeatureTable       = featureTable;

            if (featureTable.NormalUpOffset != null)
            {
                i3dm.NormalUps = GetVector3Collection(featureTable.InstancesLength, featureTable.NormalUpOffset.offset, featureTableBytes);
            }
            if (featureTable.NormalRightOffset != null)
            {
                i3dm.NormalRights = GetVector3Collection(featureTable.InstancesLength, featureTable.NormalRightOffset.offset, featureTableBytes);
            }
            if (featureTable.ScaleNonUniformOffset != null)
            {
                i3dm.ScaleNonUniforms = GetVector3Collection(featureTable.InstancesLength, featureTable.ScaleNonUniformOffset.offset, featureTableBytes);
            }
            if (featureTable.BatchIdOffset != null)
            {
                i3dm.BatchIds = GetBatchIdCollection(featureTable.InstancesLength, featureTable.BatchIdOffset.offset, featureTableBytes, featureTable.BatchIdOffset.componentType);
            }
            if (featureTable.ScaleOffset != null)
            {
                i3dm.Scales = GetFloatCollection(featureTable.InstancesLength, featureTable.ScaleOffset.offset, featureTableBytes);
            }
            if (featureTable.RtcCenter != null)
            {
                i3dm.RtcCenter = featureTable.RtcCenter;
            }

            return(i3dm);
        }
Exemplo n.º 3
0
        public static I3dm Read(Stream stream)
        {
            using (var reader = new BinaryReader(stream))
            {
                var i3dmHeader        = new I3dmHeader(reader);
                var featureTableJson  = Encoding.UTF8.GetString(reader.ReadBytes(i3dmHeader.FeatureTableJsonByteLength));
                var featureTableBytes = reader.ReadBytes(i3dmHeader.FeatureTableBinaryByteLength);
                var batchTableJson    = Encoding.UTF8.GetString(reader.ReadBytes(i3dmHeader.BatchTableJsonByteLength));
                var batchTableBytes   = reader.ReadBytes(i3dmHeader.BatchTableBinaryByteLength);
                var glbLength         = (int)(reader.BaseStream.Length - reader.BaseStream.Position);
                var glbBuffer         = reader.ReadBytes(glbLength);
                var featureTable      = JsonSerializer.Deserialize <FeatureTable>(featureTableJson);

                var positions = GetVector3Collection(featureTable.InstancesLength, featureTable.PositionOffset.offset, featureTableBytes);

                var i3dm = new I3dm(positions, glbBuffer)
                {
                    I3dmHeader         = i3dmHeader,
                    GlbData            = glbBuffer,
                    FeatureTableJson   = featureTableJson,
                    FeatureTableBinary = featureTableBytes,
                    BatchTableJson     = batchTableJson,
                    BatchTableBinary   = batchTableBytes,
                    FeatureTable       = featureTable
                };

                if (featureTable.NormalUpOffset != null)
                {
                    i3dm.NormalUps = GetVector3Collection(featureTable.InstancesLength, featureTable.NormalUpOffset.offset, featureTableBytes);
                }
                if (featureTable.NormalRightOffset != null)
                {
                    i3dm.NormalRights = GetVector3Collection(featureTable.InstancesLength, featureTable.NormalRightOffset.offset, featureTableBytes);
                }
                if (featureTable.ScaleNonUniformOffset != null)
                {
                    i3dm.ScaleNonUniforms = GetVector3Collection(featureTable.InstancesLength, featureTable.ScaleNonUniformOffset.offset, featureTableBytes);
                }
                if (featureTable.BatchIdOffset != null)
                {
                    i3dm.BatchIds = GetBatchIdCollection(featureTable.InstancesLength, featureTable.BatchIdOffset.offset, featureTableBytes, featureTable.BatchIdOffset.componentType);
                }
                if (featureTable.ScaleOffset != null)
                {
                    i3dm.Scales = GetFloatCollection(featureTable.InstancesLength, featureTable.ScaleOffset.offset, featureTableBytes);
                }
                if (featureTable.RtcCenterOffset != null)
                {
                    i3dm.RtcCenter = GetVector3(featureTable.RtcCenterOffset.offset, featureTableBytes);
                }

                return(i3dm);
            }
        }
Exemplo n.º 4
0
        public static I3dm Read(Stream stream)
        {
            using (var reader = new BinaryReader(stream))
            {
                var i3dmHeader        = new I3dmHeader(reader);
                var featureTableJson  = Encoding.UTF8.GetString(reader.ReadBytes(i3dmHeader.FeatureTableJsonByteLength));
                var featureTableBytes = reader.ReadBytes(i3dmHeader.FeatureTableBinaryByteLength);
                var batchTableJson    = Encoding.UTF8.GetString(reader.ReadBytes(i3dmHeader.BatchTableJsonByteLength));
                var batchTableBytes   = reader.ReadBytes(i3dmHeader.BatchTableBinaryByteLength);
                var glbLength         = (int)(reader.BaseStream.Length - reader.BaseStream.Position);
                var glbBuffer         = reader.ReadBytes(glbLength);
                var featureTable      = JsonSerializer.Deserialize <FeatureTable>(featureTableJson);
                // todo: batch table ids'... complexity it can be any format like 'UNSIGNED_BYTE' or others

                var i3dm = new I3dm
                {
                    I3dmHeader         = i3dmHeader,
                    GlbData            = glbBuffer,
                    FeatureTableJson   = featureTableJson,
                    FeatureTableBinary = featureTableBytes,
                    BatchTableJson     = batchTableJson,
                    BatchTableBinary   = batchTableBytes,
                    FeatureTable       = featureTable
                };

                if (featureTable.PositionOffset != null)
                {
                    i3dm.Positions = GetVector3Collection(featureTable.InstancesLength, featureTable.PositionOffset.byteOffset, featureTableBytes);
                }
                ;
                if (featureTable.NormalUpOffset != null)
                {
                    i3dm.NormalUps = GetVector3Collection(featureTable.InstancesLength, featureTable.NormalUpOffset.byteOffset, featureTableBytes);
                }
                if (featureTable.NormalRightOffset != null)
                {
                    i3dm.NormalRights = GetVector3Collection(featureTable.InstancesLength, featureTable.NormalRightOffset.byteOffset, featureTableBytes);
                }
                if (featureTable.ScaleNonUniformOffset != null)
                {
                    i3dm.ScaleNonUniforms = GetVector3Collection(featureTable.InstancesLength, featureTable.ScaleNonUniformOffset.byteOffset, featureTableBytes);
                }
                if (featureTable.BatchIdOffset != null)
                {
                    // todo: uint8 is handled here (As byte), add uint16(default - as System.UInt16 ) and uint32 (as System.UInt32)
                    i3dm.BatchIdsBytes = GetBatchIdCollection(featureTable.InstancesLength, featureTable.BatchIdOffset.byteOffset, featureTableBytes);
                }

                return(i3dm);
            }
        }