Exemple #1
0
        public Zone(Editor e,Area a)
        {
            //name = a.Name;
            editor = e;
            area = a;
            attachPoint = new VertexMarker();
            attachPoint.setPosition(Geometry.Geometry.convertPoint(a.AttachmentPoint));
            attachPoint.Colour = System.Drawing.Brushes.Green;
            outline = new Outline(Geometry.Geometry.getOutline(a.Content));
            propertypanel = new ZoneProperty(this);

            possession = Possession.Neutral;
            Name = string.Format("Zone {0}", a.Id);
            setSelected(false);
        }
        protected Area ReadArea(Stream ms)
        {
            var currentZone = new Area {Content = new AreaContent()};
            var buffer = new byte[4];

            ms.AssertAreaMagic();

            ms.Read(buffer, 0, buffer.Length);
            int zoneDataVersion = BitConverter.ToInt32(buffer, 0);
            if (zoneDataVersion != 2)
                throw new InvalidDataException("Zone data version != 2 not supported!");

            ms.Read(buffer, 0, buffer.Length);
            currentZone.Id = BitConverter.ToInt32(buffer, 0);

            ms.Read(buffer, 0, buffer.Length);
            int idStrLen = BitConverter.ToInt32(buffer, 0);
            var idStrBuffer = new byte[Utils.RoundToNextDivBy4(idStrLen)];
            ms.Read(idStrBuffer, 0, idStrBuffer.Length);
            currentZone.Name = Encoding.UTF8.GetString(idStrBuffer).TrimEnd('\0');

            ms.AssertAreaMagic();

            var attachmentPt = new Point3D();
            ms.Read(buffer, 0, buffer.Length);
            attachmentPt.X = BitConverter.ToSingle(buffer, 0);
            ms.Read(buffer, 0, buffer.Length);
            attachmentPt.Y = BitConverter.ToSingle(buffer, 0);
            ms.Read(buffer, 0, buffer.Length);
            attachmentPt.Z = BitConverter.ToSingle(buffer, 0);
            currentZone.AttachmentPoint = attachmentPt;

            ms.AssertAreaMagic();

            ms.Read(buffer, 0, buffer.Length);
            var subParts = BitConverter.ToInt32(buffer, 0);

            for (int sp = 0; sp < subParts; sp++)
            {
                var aced = new AreaClipped();
                ms.Read(buffer, 0, buffer.Length);
                aced.StartTriangle = BitConverter.ToInt32(buffer, 0);
                ms.Read(buffer, 0, buffer.Length);
                aced.TriangleCount = BitConverter.ToInt32(buffer, 0);
                ms.Read(buffer, 0, buffer.Length);
                aced.StartVertex = BitConverter.ToInt32(buffer, 0);
                ms.Read(buffer, 0, buffer.Length);
                aced.VertexCount = BitConverter.ToInt32(buffer, 0);
                currentZone.Content.ClippedAreas.Add(aced);
            }

            ms.AssertAreaMagic();

            ms.Read(buffer, 0, buffer.Length);
            currentZone.Content.BorderTriangle.StartTriangle = BitConverter.ToInt32(buffer, 0);
            ms.Read(buffer, 0, buffer.Length);
            currentZone.Content.BorderTriangle.TriangleCount = BitConverter.ToInt32(buffer, 0);
            ms.Read(buffer, 0, buffer.Length);
            currentZone.Content.BorderTriangle.StartVertex = BitConverter.ToInt32(buffer, 0);
            ms.Read(buffer, 0, buffer.Length);
            currentZone.Content.BorderTriangle.VertexCount = BitConverter.ToInt32(buffer, 0);

            ms.AssertAreaMagic();

            ms.Read(buffer, 0, buffer.Length);
            currentZone.Content.BorderVertex.StartVertex = BitConverter.ToInt32(buffer, 0);
            ms.Read(buffer, 0, buffer.Length);
            currentZone.Content.BorderVertex.VertexCount = BitConverter.ToInt32(buffer, 0);

            ms.AssertAreaMagic();

            ms.Read(buffer, 0, buffer.Length);
            int vertexCount = BitConverter.ToInt32(buffer, 0);

            ms.Read(buffer, 0, buffer.Length);
            int trianglesCount = BitConverter.ToInt32(buffer, 0);

            for (int v = 0; v < vertexCount; v++)
            {
                var curVertex = new AreaVertex();

                ms.Read(buffer, 0, buffer.Length);
                curVertex.X = BitConverter.ToSingle(buffer, 0);

                ms.Read(buffer, 0, buffer.Length);
                curVertex.Y = BitConverter.ToSingle(buffer, 0);

                ms.Read(buffer, 0, buffer.Length);
                curVertex.Z = BitConverter.ToSingle(buffer, 0);

                ms.Read(buffer, 0, buffer.Length);
                curVertex.W = BitConverter.ToSingle(buffer, 0);

                ms.Read(buffer, 0, buffer.Length);
                curVertex.Center = BitConverter.ToSingle(buffer, 0);

                currentZone.Content.Vertices.Add(curVertex);
            }

            ms.AssertAreaMagic();

            for (int f = 0; f < trianglesCount; f++)
            {
                var currentTriangle = new MeshTriangularFace();

                ms.Read(buffer, 0, buffer.Length);
                currentTriangle.Point1 = BitConverter.ToInt32(buffer, 0);

                ms.Read(buffer, 0, buffer.Length);
                currentTriangle.Point2 = BitConverter.ToInt32(buffer, 0);

                ms.Read(buffer, 0, buffer.Length);
                currentTriangle.Point3 = BitConverter.ToInt32(buffer, 0);

                currentZone.Content.Triangles.Add(currentTriangle);
            }

            ms.AssertAreaMagic();
            ms.Seek(4, SeekOrigin.Current);

            ms.AssertAreaMagic();

            ms.Read(buffer, 0, buffer.Length);
            if (BitConverter.ToUInt32(buffer, 0) != 809782853)
                throw new InvalidDataException("END0 expected!");

            return currentZone;
        }
Exemple #3
0
 public Area getArea()
 {
     var area = new Area();
     area.AttachmentPoint = Geometry.Geometry.convertPoint(attachPoint.getPosition());
     area.Content = Geometry.Geometry.getFromOutline(outline.getOutline());
     area.Name = string.Format("zone_{0}",Guid.NewGuid().ToString());
     return area;
 }