Esempio n. 1
0
        /// <summary>
        /// Appends a geometry data object to the Mesh, returns false if the mesh would become too big and needs splitting
        /// </summary>
        /// <param name="geometryMeshData"></param>
        public bool Add(XbimGeometryData geometryMeshData, short modelId = 0)
        {
            var transform = XbimMatrix3D.FromArray(geometryMeshData.DataArray2);

            if (geometryMeshData.GeometryType == XbimGeometryType.TriangulatedMesh)
            {
                var strm     = new XbimTriangulatedModelStream(geometryMeshData.ShapeData);
                var fragment = strm.BuildWithNormals(this, transform, modelId);
                if (fragment.EntityLabel == -1) //nothing was added due to size being exceeded
                {
                    return(false);
                }
                fragment.EntityLabel  = geometryMeshData.IfcProductLabel;
                fragment.EntityTypeId = geometryMeshData.IfcTypeId;
                _meshes.Add(fragment);
            }
            else if (geometryMeshData.GeometryType == XbimGeometryType.BoundingBox)
            {
                var r3D = XbimRect3D.FromArray(geometryMeshData.ShapeData);
                Add(MakeBoundingBox(r3D, transform), geometryMeshData.IfcProductLabel, IfcMetaData.GetType(geometryMeshData.IfcTypeId), modelId);
            }
            else
            {
                throw new XbimException("Illegal geometry type found");
            }
            return(true);
        }
Esempio n. 2
0
 public void FromXbimTriangulatedModelStream(XbimTriangulatedModelStream SourceStream)
 {
     SourceStream.BuildPNI(this);
 }
Esempio n. 3
0
        public PositionsNormalsIndicesBinaryStreamWriter(byte[] ShapeData)
        {
            XbimTriangulatedModelStream SourceStream = new XbimTriangulatedModelStream(ShapeData);

            SourceStream.BuildPNI(this);
        }
Esempio n. 4
0
        // this function seems only to be called in meshing XbimGeometryModelCollection
        //
        public void MergeStream(XbimTriangulatedModelStream other)
        {
            if (other.IsEmpty)
            {
                return;
            }
            if (this.IsEmpty)
            {
                // just take the other stream
                _dataStream = other.DataStream;
                return;
            }

            BinaryReader[] r = new BinaryReader[] {
                new BinaryReader(this.DataStream),
                new BinaryReader(other.DataStream)
            };

            MemoryStream result = new MemoryStream(0x4000);
            BinaryWriter w      = new BinaryWriter(result);

            r[0].BaseStream.Seek(0, SeekOrigin.Begin);
            r[1].BaseStream.Seek(0, SeekOrigin.Begin);

            int[] CountUniquePositions = new int[2] {
                r[0].ReadInt32(), r[1].ReadInt32()
            };
            int[] CountUniqueNormals = new int[2] {
                r[0].ReadInt32(), r[1].ReadInt32()
            };
            int[] CountUniquePositionNormals = new int[2] {
                r[0].ReadInt32(), r[1].ReadInt32()
            };
            int[] CountAllTriangles = new int[2] {
                r[0].ReadInt32(), r[1].ReadInt32()
            };
            int[] CountPolygons = new int[2] {
                r[0].ReadInt32(), r[1].ReadInt32()
            };

            w.Write((uint)CountUniquePositions.Sum());
            w.Write((uint)CountUniqueNormals.Sum());
            w.Write((uint)CountUniquePositionNormals.Sum());
            w.Write((uint)CountAllTriangles.Sum());
            w.Write((uint)CountPolygons.Sum());


            // copies point coordinates
            for (int i = 0; i < 2; i++)
            {
                w.Write(r[i].ReadBytes(sizeof(float) * 3 * CountUniquePositions[i]));
            }
            // copies normal vectors
            for (int i = 0; i < 2; i++)
            {
                w.Write(r[i].ReadBytes(sizeof(float) * 3 * CountUniqueNormals[i]));
            }

            // indices to points need to be copied in consideration of remapping
            uint offset = 0;
            uint sumout = (uint)CountUniquePositions.Sum();

            for (int i = 0; i < 2; i++)
            {
                IndexConverter c1 = new IndexConverter((uint)CountUniquePositions[i], r[i], sumout, w);
                c1.Offset = offset;
                for (int iIndex = 0; iIndex < CountUniquePositionNormals[i]; iIndex++)                 // loop each position-normal
                {
                    c1.ConvertIndex();
                }
                offset += (uint)CountUniquePositions[i];
            }

            // indices to normals need to be copied in consideration of remapping
            offset = 0;
            sumout = (uint)CountUniqueNormals.Sum();
            for (int i = 0; i < 2; i++)
            {
                IndexConverter c1 = new IndexConverter((uint)CountUniqueNormals[i], r[i], sumout, w);
                c1.Offset = offset;
                for (int iIndex = 0; iIndex < CountUniquePositionNormals[i]; iIndex++)                 // loop each position-normal
                {
                    c1.ConvertIndex();
                }
                offset += (uint)CountUniqueNormals[i];
            }

            // now loop polygons
            offset = 0;
            sumout = (uint)CountUniquePositionNormals.Sum();
            for (int i = 0; i < 2; i++)
            {
                for (int iPoly = 0; iPoly < CountPolygons[i]; iPoly++)
                {
                    // copy polygon type straight accross
                    w.Write(r[i].ReadByte());
                    // copy point count straight accross but keeping value
                    int iCountPoints = r[i].ReadInt32();
                    w.Write(iCountPoints);

                    IndexConverter c1 = new IndexConverter((uint)CountUniquePositionNormals[i], r[i], sumout, w);
                    c1.Offset = offset;
                    for (int iPolyPoint = 0; iPolyPoint < iCountPoints; iPolyPoint++)
                    {
                        c1.ConvertIndex();
                    }
                }
                offset += (uint)CountUniquePositionNormals[i];
            }
            w.Flush();
            // w.Close();
            _dataStream.Dispose();
            _dataStream = result;
        }
Esempio n. 5
0
 static XbimTriangulatedModelStream()
 {
     Empty = new XbimTriangulatedModelStream(true);
 }