Ejemplo n.º 1
0
        /// <summary>
        /// Converts <paramref name="nvr"/> to a <see cref="WorldGeometry"/>
        /// </summary>
        /// <param name="nvr">The <see cref="NVRFile"/> to be used for models</param>
        /// <param name="bucketTemplate">The <see cref="WGEOBucketGeometry"/> to be used a a template for bucket geometry</param>
        /// <returns>A <see cref="WorldGeometry"/> converted from <paramref name="nvr"/></returns>
        public static WorldGeometry ConvertNVR(NVRFile nvr, BucketGrid bucketTemplate)
        {
            List <WorldGeometryModel> models = new List <WorldGeometryModel>();

            foreach (NVRMesh mesh in nvr.Meshes)
            {
                List <WorldGeometryVertex> vertices = new List <WorldGeometryVertex>();
                List <uint> indices = mesh.IndexedPrimitives[0].Indices.Select(x => (uint)x).ToList();

                foreach (NVRVertex vertex in mesh.IndexedPrimitives[0].Vertices)
                {
                    if (mesh.IndexedPrimitives[0].VertexType == NVRVertexType.NVRVERTEX_4)
                    {
                        NVRVertex4 vertex4 = vertex as NVRVertex4;
                        vertices.Add(new WorldGeometryVertex(vertex4.Position, NVRVertex.IsGroundType(mesh.Material) ? new Vector2(0, 0) : vertex4.UV));
                    }
                    else if (mesh.IndexedPrimitives[0].VertexType == NVRVertexType.NVRVERTEX_8)
                    {
                        NVRVertex8 vertex8 = vertex as NVRVertex8;
                        vertices.Add(new WorldGeometryVertex(vertex8.Position, NVRVertex.IsGroundType(mesh.Material) ? new Vector2(0, 0) : vertex8.UV));
                    }
                    else if (mesh.IndexedPrimitives[0].VertexType == NVRVertexType.NVRVERTEX_12)
                    {
                        NVRVertex12 vertex12 = vertex as NVRVertex12;
                        vertices.Add(new WorldGeometryVertex(vertex12.Position, vertex12.UV));
                    }
                }

                models.Add(new WorldGeometryModel(mesh.Material.Channels[0].Name, mesh.Material.Name, vertices, indices));
            }

            return(new WorldGeometry(models, bucketTemplate));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new <see cref="WorldGeometry"/> from a <see cref="Stream"/>
        /// </summary>
        /// <param name="stream">The <see cref="Stream"/> to read from</param>
        public WorldGeometry(Stream stream)
        {
            using (BinaryReader br = new BinaryReader(stream))
            {
                string magic = Encoding.ASCII.GetString(br.ReadBytes(4));
                if (magic != "WGEO")
                {
                    throw new InvalidFileSignatureException();
                }

                uint version = br.ReadUInt32();
                if (version != 5 && version != 4)
                {
                    throw new UnsupportedFileVersionException();
                }

                uint modelCount = br.ReadUInt32();
                uint faceCount  = br.ReadUInt32();

                for (int i = 0; i < modelCount; i++)
                {
                    this.Models.Add(new WorldGeometryModel(br));
                }

                if (version == 5)
                {
                    this.BucketGrid = new BucketGrid(br);
                }
            }
        }
Ejemplo n.º 3
0
        public void Setup()
        {
            m_Tree    = new BucketGrid <TestObject>(new FloatRect(0, 0, 100, 100), (int)Math.Sqrt(NumBuckets), (int)Math.Sqrt(NumBuckets));
            m_Objects = new List <TestObject>(N);

            for (int i = 0; i < N; i++)
            {
                var obj = new TestObject(RandomPosition());
                m_Objects.Add(obj);
                m_Tree.Add(obj);
            }
        }
Ejemplo n.º 4
0
        public BucketGridDemo()
        {
            m_Bounds = new FloatRect(new Vector2f(0, 0), (Vector2f)Game.Window.Size);

            m_Grid = new BucketGrid <CircleShape>(m_Bounds, 100, 100);

            for (var i = 0; i < m_NumCircles; i++)
            {
                var pos = GetRandomPos();
                var obj = new CircleShape(2f)
                {
                    FillColor = Color.Blue,
                    Position  = pos
                };

                m_TestObjects.Add(obj, RandomVelocity());

                m_Grid.Add(obj);
            }

            m_Grid.Update();
        }
        public MapGeometry(Stream stream)
        {
            using (BinaryReader br = new BinaryReader(stream))
            {
                string magic = Encoding.ASCII.GetString(br.ReadBytes(4));
                if (magic != "OEGM")
                {
                    throw new InvalidFileSignatureException();
                }

                uint version = br.ReadUInt32();
                if (version != 5 && version != 6 && version != 7 && version != 9 && version != 11)
                {
                    throw new UnsupportedFileVersionException();
                }

                bool useSeparatePointLights = false;
                if (version < 7)
                {
                    useSeparatePointLights = br.ReadBoolean();
                }

                if (version >= 9)
                {
                    this.UnknownString1 = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt32()));

                    if (version >= 11)
                    {
                        this.UnknownString2 = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt32()));
                    }
                }

                List <MapGeometryVertexElementGroup> vertexElementGroups = new List <MapGeometryVertexElementGroup>();
                uint vertexElementGroupCount = br.ReadUInt32();
                for (int i = 0; i < vertexElementGroupCount; i++)
                {
                    vertexElementGroups.Add(new MapGeometryVertexElementGroup(br));
                }

                uint        vertexBufferCount   = br.ReadUInt32();
                List <long> vertexBufferOffsets = new List <long>();
                for (int i = 0; i < vertexBufferCount; i++)
                {
                    uint bufferSize = br.ReadUInt32();

                    vertexBufferOffsets.Add(br.BaseStream.Position);
                    br.BaseStream.Seek(bufferSize, SeekOrigin.Current);
                }

                uint            indexBufferCount = br.ReadUInt32();
                List <ushort[]> indexBuffers     = new List <ushort[]>();
                for (int i = 0; i < indexBufferCount; i++)
                {
                    ushort[] indexBuffer;

                    uint bufferSize = br.ReadUInt32();
                    indexBuffer = new ushort[bufferSize / 2];

                    for (int j = 0; j < bufferSize / 2; j++)
                    {
                        indexBuffer[j] = br.ReadUInt16();
                    }

                    indexBuffers.Add(indexBuffer);
                }

                uint modelCount = br.ReadUInt32();
                for (int i = 0; i < modelCount; i++)
                {
                    this.Models.Add(new MapGeometryModel(br, vertexElementGroups, vertexBufferOffsets, indexBuffers, useSeparatePointLights, version));
                }

                this.BucketGrid = new BucketGrid(br);
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new <see cref="WorldGeometry"/>
 /// </summary>
 /// <param name="models">Models of this <see cref="WorldGeometry"/></param>
 /// <param name="bucketGrid"><see cref="BucketGrid"/> of this <see cref="WorldGeometry"/></param>
 public WorldGeometry(List <WorldGeometryModel> models, BucketGrid bucketGrid)
 {
     this.Models     = models;
     this.BucketGrid = bucketGrid;
 }
Ejemplo n.º 7
0
        public void GetClosestObjectTest()
        {
            BucketGrid <TestObject> tree = new BucketGrid <TestObject>(m_Bounds, 10, 10);

            SpacePartitionerTests.GetClosestObjectTest(tree);
        }
Ejemplo n.º 8
0
        public void AddRemoveTest()
        {
            BucketGrid <TestObject> tree = new BucketGrid <TestObject>(m_Bounds, 10, 10);

            SpacePartitionerTests.AddRemoveTest(tree);
        }