示例#1
0
        protected override void BuildVerticiesAndIndicies()
        {
            List<int> indices;
            using (LargeObjectPools.IndexListPool.Borrow(out indices))
            {
                List <WCell.Util.Graphics.Vector3> vertices;

                using (LargeObjectPools.Vector3ListPool.Borrow(out vertices))
                {
                    indices.Clear();
                    vertices.Clear();
                    var tempVertices = new List<VertexPositionNormalColored>();

                    tile.GenerateLiquidMesh(indices, vertices);

                    if (vertices.Count == 0) return;

                    foreach (var vertex in vertices)
                    {
                        var vertexPosNmlCol = new VertexPositionNormalColored(vertex.ToXna(),
                                                                              WaterColor,
                                                                              Vector3.Zero);
                        tempVertices.Add(vertexPosNmlCol);
                    }

                    _cachedIndices = indices.ToArray();
                    _cachedVertices = tempVertices.ToArray();
                }
            }

            _renderCached = true;
        }
示例#2
0
		protected override void BuildVerticiesAndIndicies()
		{
			var viewer = (TerrainViewer) Game;
			var tile = viewer.Tile;

			List<int> indices;
			using (LargeObjectPools.IndexListPool.Borrow(out indices))
			{
				List <WCell.Util.Graphics.Vector3> vertices;
				
				using (LargeObjectPools.Vector3ListPool.Borrow(out vertices))
				{
					var tempVertices = new List<VertexPositionNormalColored>();

					tile.GenerateLiquidMesh(indices, vertices);

					if (vertices != null)
					{	
						for (var v = 0; v < vertices.Count; v++)
						{
							var vertex = vertices[v];
							var vertexPosNmlCol = new VertexPositionNormalColored(vertex.ToXna(),
							                                                      WaterColor,
							                                                      Vector3.Zero);
							tempVertices.Add(vertexPosNmlCol);
						}
					}

					_cachedIndices = indices.ToArray();
					_cachedVertices = tempVertices.ToArray();
				}
			}
			_renderCached = true;
		}
示例#3
0
        protected override bool BuildPolyVerticiesAndIndicies()
        {
            List <Vector3> vertices;
            List <int>     indices;

            _manager.GetMeshVerticesAndIndices(out vertices, out indices);

            if (vertices.Count == 0 || indices.Count == 0)
            {
                return(false);
            }

            _cachedPolyVertices = new VertexPositionNormalColored[vertices.Count];
            for (var i = 0; i < vertices.Count; i++)
            {
                _cachedPolyVertices[i] = new VertexPositionNormalColored(vertices[i].ToXna(), MeshPolyColor,
                                                                         Vector3.Up.ToXna());
                PositionUtil.TransformWoWCoordsToXNACoords(ref _cachedPolyVertices[i]);
            }

            _cachedPolyIndices = new int[indices.Count];
            for (int i = 0; i < indices.Count; i++)
            {
                _cachedPolyIndices[i] = indices[i];
            }

            RenderPolyCached = true;
            return(true);
        }
示例#4
0
		protected override void BuildVerticiesAndIndicies()
		{
			var tile = Viewer.Tile;

			var tempVertices = new List<VertexPositionNormalColored>();
			var tempIndicies = new List<int>();

			for (var v = 0; v < tile.TerrainVertices.Length; v++)
			{
				var vertex1 = tile.TerrainVertices[v];
				var vertexPosNmlCol1 = new VertexPositionNormalColored(vertex1.ToXna(),
																		TerrainColor,
																		Vector3.Zero);
				tempVertices.Add(vertexPosNmlCol1);
			}

			for (var i = 0; i < tile.TerrainIndices.Length; i += 3)
			{
				var index1 = tile.TerrainIndices[i];
				var index2 = tile.TerrainIndices[i+1];
				var index3 = tile.TerrainIndices[i+2];
				tempIndicies.Add(index1);
				tempIndicies.Add(index2);
				tempIndicies.Add(index3);
			}

			_cachedIndices = tempIndicies.ToArray();
			_cachedVertices = tempVertices.ToArray();

			_renderCached = true;
		}
示例#5
0
        private void BuildVerticiesAndIndicies()
        {
            // Cycle through each ADT
            var tempVertices = new List <VertexPositionNormalColored>();
            var tempIndicies = new List <int>();
            var offset       = 0;

            foreach (var adt in _manager.MapTiles)
            {
                // Handle the ADTs
                for (var v = 0; v < adt.TerrainVertices.Count; v++)
                {
                    var vertex          = adt.TerrainVertices[v];
                    var vertexPosNmlCol = new VertexPositionNormalColored(vertex.ToXna(), TerrainColor,
                                                                          Microsoft.Xna.Framework.Vector3.Down);
                    tempVertices.Add(vertexPosNmlCol);
                }
                for (var i = 0; i < adt.Indices.Count; i++)
                {
                    tempIndicies.Add(adt.Indices[i] + offset);
                }
                offset = tempVertices.Count;

                //if (!DrawLiquids) continue;
                for (var v = 0; v < adt.LiquidVertices.Count; v++)
                {
                    var vertex          = adt.LiquidVertices[v];
                    var vertexPosNmlCol = new VertexPositionNormalColored(vertex.ToXna(), WaterColor,
                                                                          Microsoft.Xna.Framework.Vector3.Down);
                    tempVertices.Add(vertexPosNmlCol);
                }
                for (var i = 0; i < adt.LiquidIndices.Count; i++)
                {
                    tempIndicies.Add(adt.LiquidIndices[i] + offset);
                }
                offset = tempVertices.Count;
            }

            _cachedIndices  = tempIndicies.ToArray();
            _cachedVertices = tempVertices.ToArray();

            _renderCached = true;

            for (var i = 0; i < _cachedVertices.Length; i++)
            {
                PositionUtil.TransformWoWCoordsToXNACoords(ref _cachedVertices[i]);
            }
        }
        protected override void BuildVerticiesAndIndicies()
        {
            _cachedVertices = new VertexPositionNormalColored[_manager.Vertices.Count];
            _cachedIndices  = new int[_manager.Indices.Count];

            for (var i = 0; i < _manager.Vertices.Count; i++)
            {
                var position = _manager.Vertices[i];
                PositionUtil.TransformWoWCoordsToXNACoords(ref position);
                _cachedVertices[i] = new VertexPositionNormalColored(position.ToXna(), SelectedTriangleColor,
                                                                     Vector3.Up);
            }

            for (var i = 0; i < _manager.Indices.Count; i++)
            {
                _cachedIndices[i] = _manager.Indices[i];
            }
        }
        public static int GetVertexSize(VertexFormatBits format)
        {
            switch (format)
            {
            case VertexFormatBits.Position: return(VertexPosition.GetSizeInFloats());

            case VertexFormatBits.PositionColored:
                return(VertexPositionColored.GetSizeInFloats());

            case VertexFormatBits.PositionNormal:
                return(VertexPositionNormal.GetSizeInFloats());

            case VertexFormatBits.PositionNormalColored:
                return(VertexPositionNormalColored.GetSizeInFloats());

            default: break;
            }
            return(VertexPosition.GetSizeInFloats());
        }
        void BuildVerticesAndIndices()
        {
            _cachedVertices = new VertexPositionNormalColored[environment.RenderingVerticies.Length * 2];
            for (var i = 0; i < environment.RenderingVerticies.Length; i++)
            {
                var vertPosNmlClr = environment.RenderingVerticies[i];
                _cachedVertices[i * 2] = new VertexPositionNormalColored(vertPosNmlClr.Position, vertColor,
                                                                         vertPosNmlClr.Normal);
                _cachedVertices[i * 2 + 1] = new VertexPositionNormalColored(vertPosNmlClr.Position + vertPosNmlClr.Normal,
                                                                             vertColor, vertPosNmlClr.Normal);
            }

            _cachedIndices = new int[_cachedVertices.Length];
            for (var i = 0; i < _cachedVertices.Length; i++)
            {
                _cachedIndices[i] = i;
            }

            RebuildBuffers();
            _renderCached = true;
        }
示例#9
0
        public void Select(ref Triangle tri, bool doNotReplace, Color color)
        {
            var v = _cachedVertices.Length;
            var i = _cachedIndices.Length;

            if (doNotReplace)
            {
                Array.Resize(ref _cachedVertices, _cachedVertices.Length + 3);
                Array.Resize(ref _cachedIndices, _cachedIndices.Length + 3);
            }
            else
            {
                v = i = 0;
                _cachedVertices = new VertexPositionNormalColored[3];
                _cachedIndices  = new int[3];
            }

            // add vertices
            var normal = WCell.Util.Graphics.Vector3.Cross(tri.Point3 - tri.Point1, tri.Point2 - tri.Point1).ToXna();

            normal.Normalize();

            _cachedVertices[v] = new VertexPositionNormalColored(tri.Point1.ToXna(),
                                                                 color,
                                                                 normal);

            _cachedVertices[v + 1] = new VertexPositionNormalColored(tri.Point2.ToXna(),
                                                                     color,
                                                                     normal);

            _cachedVertices[v + 2] = new VertexPositionNormalColored(tri.Point3.ToXna(),
                                                                     color,
                                                                     normal);


            // add indices
            _cachedIndices[i]     = v;
            _cachedIndices[i + 1] = v + 1;
            _cachedIndices[i + 2] = v + 2;
        }
示例#10
0
		public void Select(ref Triangle tri, bool doNotReplace, Color color)
		{
			var v = _cachedVertices.Length;
			var i = _cachedIndices.Length;

			if (doNotReplace)
			{
				Array.Resize(ref _cachedVertices, _cachedVertices.Length + 3);
				Array.Resize(ref _cachedIndices, _cachedIndices.Length + 3);
			}
			else
			{
				v = i = 0;
				_cachedVertices = new VertexPositionNormalColored[3];
				_cachedIndices = new int[3];
			}

			// add vertices
			var normal = WCell.Util.Graphics.Vector3.Cross(tri.Point3 - tri.Point1, tri.Point2 - tri.Point1).ToXna();
			normal.Normalize();

			_cachedVertices[v] = new VertexPositionNormalColored(tri.Point1.ToXna(),
																	color,
																	normal);

			_cachedVertices[v+1] = new VertexPositionNormalColored(tri.Point2.ToXna(),
																	color,
																	normal);

			_cachedVertices[v+2] = new VertexPositionNormalColored(tri.Point3.ToXna(),
																	color,
																	normal);


			// add indices
			_cachedIndices[i] = v;
			_cachedIndices[i+1] = v+1;
			_cachedIndices[i+2] = v+2;
		}
示例#11
0
        protected override void BuildVerticiesAndIndicies()
        {
            // Cycle through each M2
            var tempVertices = _manager.RenderVertices;
            var tempIndicies = _manager.RenderIndices;

            _cachedVertices = new VertexPositionNormalColored[tempVertices.Count];
            for (var i = 0; i < tempVertices.Count; i++)
            {
                var vec = tempVertices[i];
                PositionUtil.TransformWoWCoordsToXNACoords(ref vec);
                _cachedVertices[i] = new VertexPositionNormalColored(vec.ToXna(), M2Color,
                                                                     Microsoft.Xna.Framework.Vector3.Down);
            }

            _cachedIndices = new int[tempIndicies.Count];
            for (var i = 0; i < tempIndicies.Count; i++)
            {
                _cachedIndices[i] = tempIndicies[i];
            }

            _renderCached = true;
        }
示例#12
0
        protected override void BuildVerticiesAndIndicies()
        {
            var tempIndices  = new List <int>();
            var tempVertices = new List <VertexPositionNormalColored>();

            foreach (var vertex in tile.TerrainVertices)
            {
                var vertexPosNmlCol1 = new VertexPositionNormalColored(vertex.ToXna(),
                                                                       TerrainColor,
                                                                       Vector3.Zero);
                tempVertices.Add(vertexPosNmlCol1);
            }

            foreach (var index in tile.TerrainIndices)
            {
                tempIndices.Add(index);
            }

            _cachedVertices = tempVertices.ToArray();
            _cachedIndices  = tempIndices.ToArray();

            _renderCached = true;
        }
示例#13
0
        protected override void BuildVerticiesAndIndicies()
        {
            var tempIndices = new List<int>();
            var tempVertices = new List<VertexPositionNormalColored>();

            foreach (var vertex in tile.TerrainVertices)
            {
                var vertexPosNmlCol1 = new VertexPositionNormalColored(vertex.ToXna(),
                                                                       TerrainColor,
                                                                       Vector3.Zero);
                tempVertices.Add(vertexPosNmlCol1);
            }

            foreach (var index in tile.TerrainIndices)
            {
                tempIndices.Add(index);
            }

            _cachedVertices = tempVertices.ToArray();
            _cachedIndices = tempIndices.ToArray();

            _renderCached = true;
        }
示例#14
0
        protected override void BuildVerticiesAndIndicies()
        {
            // Cycle through each M2
            var tempVertices = _manager.RenderVertices;
            var tempIndicies = _manager.RenderIndices;

            _cachedVertices = new VertexPositionNormalColored[tempVertices.Count];
            for (var i = 0; i < tempVertices.Count; i++)
            {
                var vec = tempVertices[i];
                PositionUtil.TransformWoWCoordsToXNACoords(ref vec);
                _cachedVertices[i] = new VertexPositionNormalColored(vec.ToXna(), M2Color,
                                                                     Microsoft.Xna.Framework.Vector3.Down);
            }

            _cachedIndices = new int[tempIndicies.Count];
            for (var i = 0; i < tempIndicies.Count; i++)
            {
                _cachedIndices[i] = tempIndicies[i];
            }

            _renderCached = true;
        }
示例#15
0
        protected override void BuildVerticiesAndIndicies()
        {
            List <int> indices;

            using (LargeObjectPools.IndexListPool.Borrow(out indices))
            {
                List <WCell.Util.Graphics.Vector3> vertices;

                using (LargeObjectPools.Vector3ListPool.Borrow(out vertices))
                {
                    indices.Clear();
                    vertices.Clear();
                    var tempVertices = new List <VertexPositionNormalColored>();

                    tile.GenerateLiquidMesh(indices, vertices);

                    if (vertices.Count == 0)
                    {
                        return;
                    }

                    foreach (var vertex in vertices)
                    {
                        var vertexPosNmlCol = new VertexPositionNormalColored(vertex.ToXna(),
                                                                              WaterColor,
                                                                              Vector3.Zero);
                        tempVertices.Add(vertexPosNmlCol);
                    }

                    _cachedIndices  = indices.ToArray();
                    _cachedVertices = tempVertices.ToArray();
                }
            }

            _renderCached = true;
        }
示例#16
0
        public TriangleList Optimize()
        {
            IList <VertexPositionNormalColored> vertices = Vertices;
            IList <int> indices       = Indices;
            var         hash          = new Dictionary <VertexPositionNormalColored, int>();
            var         resultIndices = new List <int>();

            for (int i = 0; i < indices.Count; i++)
            {
                VertexPositionNormalColored vertex = vertices[indices[i]];
                int index;
                if (!hash.TryGetValue(vertex, out index))
                {
                    index = hash.Count;
                    hash.Add(vertex, index);
                }
                resultIndices.Add(index);
            }
            return(new TriangleList()
            {
                Indices = resultIndices.ToArray(),
                Vertices = hash.Keys.ToArray(),
            });
        }
示例#17
0
        protected override bool BuildPolyVerticiesAndIndicies()
        {
            List<Vector3> polyVertices;
            List<int> polyIndices;
            _manager.GetMeshVerticesAndIndices(out polyVertices, out polyIndices);
            if (polyVertices.Count == 0 || polyIndices == null) return false;

            _cachedPolyVertices = new VertexPositionNormalColored[polyVertices.Count];
            for (var i = 0; i < polyVertices.Count; i++)
            {
                _cachedPolyVertices[i] = new VertexPositionNormalColored(polyVertices[i].ToXna(), RecastFrameColor,
                                                                         Vector3.Up.ToXna());
                PositionUtil.TransformWoWCoordsToXNACoords(ref _cachedPolyVertices[i]);
            }

            _cachedPolyIndices = new int[polyIndices.Count];
            for (int i = 0; i < polyIndices.Count; i++)
            {
                _cachedPolyIndices[i] = polyIndices[i];
            }

            RenderPolyCached = true;
            return true;
        }
示例#18
0
		public GenericRenderer(Game game)
			: base(game)
		{
			_cachedVertices = new VertexPositionNormalColored[0];
			_cachedIndices = new int[0];
		}
        protected static VertexBuffer ToVertexBuffer
        (
            Rhino.Geometry.Mesh mesh,
            Primitive.Part part,
            out VertexFormatBits vertexFormatBits,
            System.Drawing.Color color = default
        )
        {
            int verticesCount = part.EndVertexIndex - part.StartVertexIndex;
            int normalCount   = mesh.Normals.Count == mesh.Vertices.Count ? verticesCount : 0;
            int colorsCount   = color.IsEmpty ? (mesh.VertexColors.Count == mesh.Vertices.Count ? verticesCount : 0) : verticesCount;

            bool hasVertices = verticesCount > 0;
            bool hasNormals  = normalCount > 0;
            bool hasColors   = colorsCount > 0;

            if (hasVertices)
            {
                var vertices = mesh.Vertices;
                if (hasNormals)
                {
                    var normals = mesh.Normals;
                    if (hasColors)
                    {
                        vertexFormatBits = VertexFormatBits.PositionNormalColored;
                        var colors = mesh.VertexColors;
                        var vb     = new VertexBuffer(verticesCount * VertexPositionNormalColored.GetSizeInFloats());
                        vb.Map(verticesCount * VertexPositionNormalColored.GetSizeInFloats());
                        using (var stream = vb.GetVertexStreamPositionNormalColored())
                        {
                            for (int v = part.StartVertexIndex; v < part.EndVertexIndex; ++v)
                            {
                                var  c = !color.IsEmpty ? color : colors[v];
                                uint T = Math.Max(1, 255u - c.A);
                                stream.AddVertex(new VertexPositionNormalColored(RawEncoder.ToHost(vertices[v]), RawEncoder.ToHost(normals[v]), new ColorWithTransparency(c.R, c.G, c.B, T)));
                            }
                        }
                        vb.Unmap();
                        return(vb);
                    }
                    else
                    {
                        vertexFormatBits = VertexFormatBits.PositionNormal;
                        var vb = new VertexBuffer(verticesCount * VertexPositionNormal.GetSizeInFloats());
                        vb.Map(verticesCount * VertexPositionNormal.GetSizeInFloats());
                        using (var stream = vb.GetVertexStreamPositionNormal())
                        {
                            for (int v = part.StartVertexIndex; v < part.EndVertexIndex; ++v)
                            {
                                stream.AddVertex(new VertexPositionNormal(RawEncoder.ToHost(vertices[v]), RawEncoder.ToHost(normals[v])));
                            }
                        }
                        vb.Unmap();
                        return(vb);
                    }
                }
                else
                {
                    if (hasColors)
                    {
                        vertexFormatBits = VertexFormatBits.PositionColored;
                        var colors = mesh.VertexColors;
                        var vb     = new VertexBuffer(verticesCount * VertexPositionColored.GetSizeInFloats());
                        vb.Map(verticesCount * VertexPositionColored.GetSizeInFloats());
                        using (var stream = vb.GetVertexStreamPositionColored())
                        {
                            for (int v = part.StartVertexIndex; v < part.EndVertexIndex; ++v)
                            {
                                var  c = !color.IsEmpty ? color : colors[v];
                                uint T = Math.Max(1, 255u - c.A);
                                stream.AddVertex(new VertexPositionColored(RawEncoder.ToHost(vertices[v]), new ColorWithTransparency(c.R, c.G, c.B, T)));
                            }
                        }
                        vb.Unmap();
                        return(vb);
                    }
                    else
                    {
                        vertexFormatBits = VertexFormatBits.Position;
                        var vb = new VertexBuffer(verticesCount * VertexPosition.GetSizeInFloats());
                        vb.Map(verticesCount * VertexPosition.GetSizeInFloats());
                        using (var stream = vb.GetVertexStreamPosition())
                        {
                            for (int v = part.StartVertexIndex; v < part.EndVertexIndex; ++v)
                            {
                                stream.AddVertex(new VertexPosition(RawEncoder.ToHost(vertices[v])));
                            }
                        }
                        vb.Unmap();
                        return(vb);
                    }
                }
            }

            vertexFormatBits = 0;
            return(null);
        }
        protected static int ToPointsBuffer
        (
            Rhino.Geometry.PointCloud pointCloud,
            Primitive.Part part,
            out VertexFormatBits vertexFormatBits,
            out VertexBuffer vb, out int vertexCount,
            out IndexBuffer ib
        )
        {
            int pointsCount = part.VertexCount;
            int normalCount = pointCloud.ContainsNormals ? pointsCount : 0;
            int colorsCount = pointCloud.ContainsColors  ? pointsCount : 0;

            bool hasPoints  = pointsCount > 0;
            bool hasNormals = normalCount == pointsCount;
            bool hasColors  = colorsCount == pointsCount;

            if (hasPoints)
            {
                if (hasNormals)
                {
                    if (hasColors)
                    {
                        vertexFormatBits = VertexFormatBits.PositionNormalColored;
                        vb = new VertexBuffer(pointsCount * VertexPositionNormalColored.GetSizeInFloats());
                        vb.Map(pointsCount * VertexPositionNormalColored.GetSizeInFloats());

                        using (var vstream = vb.GetVertexStreamPositionNormalColored())
                        {
                            for (int p = part.StartVertexIndex; p < part.EndVertexIndex; ++p)
                            {
                                var point = pointCloud[p];
                                var c     = new ColorWithTransparency(point.Color.R, point.Color.G, point.Color.B, 255u - point.Color.A);
                                vstream.AddVertex(new VertexPositionNormalColored(RawEncoder.ToHost(point.Location), RawEncoder.ToHost(point.Normal), c));
                            }
                        }

                        vb.Unmap();
                    }
                    else
                    {
                        vertexFormatBits = VertexFormatBits.PositionNormal;
                        vb = new VertexBuffer(pointsCount * VertexPositionNormal.GetSizeInFloats());
                        vb.Map(pointsCount * VertexPositionNormal.GetSizeInFloats());

                        using (var vstream = vb.GetVertexStreamPositionNormal())
                        {
                            for (int p = part.StartVertexIndex; p < part.EndVertexIndex; ++p)
                            {
                                var point = pointCloud[p];
                                vstream.AddVertex(new VertexPositionNormal(RawEncoder.ToHost(point.Location), RawEncoder.ToHost(point.Normal)));
                            }
                        }

                        vb.Unmap();
                    }
                }
                else
                {
                    if (hasColors)
                    {
                        vertexFormatBits = VertexFormatBits.PositionColored;
                        vb = new VertexBuffer(pointsCount * VertexPositionColored.GetSizeInFloats());
                        vb.Map(pointsCount * VertexPositionColored.GetSizeInFloats());

                        using (var vstream = vb.GetVertexStreamPositionColored())
                        {
                            for (int p = part.StartVertexIndex; p < part.EndVertexIndex; ++p)
                            {
                                var point = pointCloud[p];
                                var c     = new ColorWithTransparency(point.Color.R, point.Color.G, point.Color.B, 255u - point.Color.A);
                                vstream.AddVertex(new VertexPositionColored(RawEncoder.ToHost(point.Location), c));
                            }
                        }

                        vb.Unmap();
                    }
                    else
                    {
                        vertexFormatBits = VertexFormatBits.Position;
                        vb = new VertexBuffer(pointsCount * VertexPosition.GetSizeInFloats());
                        vb.Map(pointsCount * VertexPosition.GetSizeInFloats());

                        using (var vstream = vb.GetVertexStreamPosition())
                        {
                            for (int p = part.StartVertexIndex; p < part.EndVertexIndex; ++p)
                            {
                                var point = pointCloud[p];
                                vstream.AddVertex(new VertexPosition(RawEncoder.ToHost(point.Location)));
                            }
                        }

                        vb.Unmap();
                    }
                }

                ib = IndexPointsBuffer(pointsCount);
            }
            else
            {
                vertexFormatBits = 0;
                vb = null;
                ib = null;
            }

            vertexCount = pointsCount;
            return(pointsCount);
        }
示例#21
0
        void BuildVerticesAndIndices()
        {
            _cachedVertices = new VertexPositionNormalColored[environment.RenderingVerticies.Length*2];
            for (var i = 0; i < environment.RenderingVerticies.Length; i++)
            {
                var vertPosNmlClr = environment.RenderingVerticies[i];
                _cachedVertices[i*2] = new VertexPositionNormalColored(vertPosNmlClr.Position, vertColor,
                                                                     vertPosNmlClr.Normal);
                _cachedVertices[i*2 + 1] = new VertexPositionNormalColored(vertPosNmlClr.Position + vertPosNmlClr.Normal,
                                                                         vertColor, vertPosNmlClr.Normal);
            }

            _cachedIndices = new int[_cachedVertices.Length];
            for (var i = 0; i < _cachedVertices.Length; i++)
            {
                _cachedIndices[i] = i;
            }

            RebuildBuffers();
            _renderCached = true;
        }
示例#22
0
		protected override void BuildVerticiesAndIndicies()
		{
			var mesh = Viewer.Tile.NavMesh;
			var vertices = mesh.Vertices;

			List<int> indices;
			mesh.GetTriangles(out indices);

			if (vertices.Length == 0 || indices.Count == 0) return;

			_cachedVertices = new VertexPositionNormalColored[vertices.Length];
			for (var i = 0; i < vertices.Length; i++)
			{
				var vertex = vertices[i];
				_cachedVertices[i] = new VertexPositionNormalColored(vertex.ToXna(),
																		RenderColor,
																		Microsoft.Xna.Framework.Vector3.Zero);
			}

			_cachedIndices = new int[indices.Count];
			for (int i = 0; i < indices.Count; i++)
			{
				_cachedIndices[i] = indices[i];
			}

			_renderCached = true;
		}
示例#23
0
        protected override void BuildVerticiesAndIndicies()
        {
            var vertCount = _manager.WmoVertices.Count +
                            _manager.WmoM2Vertices.Count +
                            _manager.WmoLiquidVertices.Count;

            _cachedVertices = new VertexPositionNormalColored[vertCount];

            var idxCount = _manager.WmoIndices.Count +
                           _manager.WmoM2Indices.Count +
                           _manager.WmoLiquidIndices.Count;

            _cachedIndices = new int[idxCount];

            var vertices = _manager.WmoVertices;
            var indices  = _manager.WmoIndices;

            for (var i = 0; i < vertices.Count; i++)
            {
                var vec = vertices[i];
                PositionUtil.TransformWoWCoordsToXNACoords(ref vec);
                _cachedVertices[i] = new VertexPositionNormalColored(vec.ToXna(), WMOColor, Vector3.Down);
            }
            for (var i = 0; i < indices.Count; i++)
            {
                _cachedIndices[i] = indices[i];
            }

            // Add the M2 stuff
            var vecOffset = vertices.Count;

            vertices = _manager.WmoM2Vertices;
            for (var i = 0; i < vertices.Count; i++)
            {
                var vec = vertices[i];
                PositionUtil.TransformWoWCoordsToXNACoords(ref vec);
                _cachedVertices[i + vecOffset] = new VertexPositionNormalColored(vec.ToXna(), WMOModelColor,
                                                                                 Vector3.Down);
            }
            var idxOffset = indices.Count;

            indices = _manager.WmoM2Indices;
            for (var i = 0; i < indices.Count; i++)
            {
                _cachedIndices[i + idxOffset] = indices[i] + vecOffset;
            }

            // Add the Liquid stuff
            vecOffset += vertices.Count;
            vertices   = _manager.WmoLiquidVertices;
            for (var i = 0; i < vertices.Count; i++)
            {
                var vec = vertices[i];
                PositionUtil.TransformWoWCoordsToXNACoords(ref vec);
                _cachedVertices[i + vecOffset] = new VertexPositionNormalColored(vec.ToXna(), WMOWaterColor,
                                                                                 Vector3.Down);
            }
            idxOffset += indices.Count;
            indices    = _manager.WmoLiquidIndices;
            for (var i = 0; i < indices.Count; i++)
            {
                _cachedIndices[i + idxOffset] = indices[i] + vecOffset;
            }

            _renderCached = true;
        }
示例#24
0
        private void CopyToTerrainBuffers(VertexPositionNormalColored[] vertices, int[] indices)
        {
            terrainVertexBuffer = new VertexBuffer(device, typeof(VertexPositionNormalColored), vertices.Length, BufferUsage.WriteOnly);
            terrainVertexBuffer.SetData(vertices);

            terrainIndexBuffer = new IndexBuffer(device, typeof(int), indices.Length, BufferUsage.WriteOnly);
            terrainIndexBuffer.SetData(indices);
        }
示例#25
0
        private VertexPositionNormalColored[] CalculateNormals(VertexPositionNormalColored[] vertices, int[] indices)
        {
            for (int i = 0; i < vertices.Length; i++)
                vertices[i].Normal = new Vector3(0, 0, 0);

            for (int i = 0; i < indices.Length / 3; i++)
            {
                int index1 = indices[i * 3];
                int index2 = indices[i * 3 + 1];
                int index3 = indices[i * 3 + 2];

                Vector3 side1 = vertices[index1].Position - vertices[index3].Position;
                Vector3 side2 = vertices[index1].Position - vertices[index2].Position;
                Vector3 normal = Vector3.Cross(side1, side2);

                vertices[index1].Normal += normal;
                vertices[index2].Normal += normal;
                vertices[index3].Normal += normal;
            }

            for (int i = 0; i < vertices.Length; i++)
                vertices[i].Normal.Normalize();

            return vertices;
        }
示例#26
0
        protected override void BuildVerticiesAndIndicies()
        {
            var vertCount = _manager.WmoVertices.Count +
                            _manager.WmoM2Vertices.Count +
                            _manager.WmoLiquidVertices.Count;
            _cachedVertices = new VertexPositionNormalColored[vertCount];

            var idxCount = _manager.WmoIndices.Count +
                           _manager.WmoM2Indices.Count +
                           _manager.WmoLiquidIndices.Count;
            _cachedIndices = new int[idxCount];

            var vertices = _manager.WmoVertices;
            var indices = _manager.WmoIndices;

            for (var i = 0; i < vertices.Count; i++)
            {
                var vec = vertices[i];
                PositionUtil.TransformWoWCoordsToXNACoords(ref vec);
                _cachedVertices[i] = new VertexPositionNormalColored(vec.ToXna(), WMOColor, Vector3.Down);
            }
            for (var i = 0; i < indices.Count; i++)
            {
                _cachedIndices[i] = indices[i];
            }

            // Add the M2 stuff
            var vecOffset = vertices.Count;
            vertices = _manager.WmoM2Vertices;
            for (var i = 0; i < vertices.Count; i++)
            {
                var vec = vertices[i];
                PositionUtil.TransformWoWCoordsToXNACoords(ref vec);
                _cachedVertices[i + vecOffset] = new VertexPositionNormalColored(vec.ToXna(), WMOModelColor,
                                                                                 Vector3.Down);
            }
            var idxOffset = indices.Count;
            indices = _manager.WmoM2Indices;
            for (var i = 0; i < indices.Count; i++)
            {
                _cachedIndices[i + idxOffset] = indices[i] + vecOffset;
            }

            // Add the Liquid stuff
            vecOffset += vertices.Count;
            vertices = _manager.WmoLiquidVertices;
            for (var i = 0; i < vertices.Count; i++)
            {
                var vec = vertices[i];
                PositionUtil.TransformWoWCoordsToXNACoords(ref vec);
                _cachedVertices[i + vecOffset] = new VertexPositionNormalColored(vec.ToXna(), WMOWaterColor,
                                                                                 Vector3.Down);
            }
            idxOffset += indices.Count;
            indices = _manager.WmoLiquidIndices;
            for (var i = 0; i < indices.Count; i++)
            {
                _cachedIndices[i + idxOffset] = indices[i] + vecOffset;
            }

            _renderCached = true;
        }
示例#27
0
 /// <summary>
 /// Changes the coodinate system of a vertex from WoW based to XNA based.
 /// </summary>
 /// <param name="vertex">A vertex with WoW coords</param>
 public static void TransformWoWCoordsToXNACoords(ref VertexPositionNormalColored vertex)
 {
     TransformWoWCoordsToXNACoords(ref vertex.Position);
 }
示例#28
0
 public GenericRenderer(Game game)
     : base(game)
 {
     _cachedVertices = new VertexPositionNormalColored[0];
     _cachedIndices  = new int[0];
 }
示例#29
0
        // Create and populate a pair of vertex and index buffers. Also update parameters associated with the format of the vertices.
        private void ProcessFaces(RenderingPassBufferStorage bufferStorage)
        {
            List <MeshInfo> meshes = bufferStorage.Meshes;

            if (meshes.Count == 0)
            {
                return;
            }
            List <int> numVerticesInMeshesBefore = new List <int>();

            bool useNormals = this.Inputs.EnableFaceNormal;

            // Vertex attributes are stored sequentially in vertex buffers. The attributes can include position, normal vector, and color.
            // All vertices within a vertex buffer must have the same format. Possible formats are enumerated by VertexFormatBits.
            // Vertex format also determines the type of rendering effect that can be used with the vertex buffer. In this sample,
            // the color is always encoded in the vertex attributes.

            bufferStorage.FormatBits = useNormals ? VertexFormatBits.PositionNormalColored : VertexFormatBits.PositionColored;

            // The format of the vertices determines the size of the vertex buffer.
            int vertexBufferSizeInFloats = (useNormals ? VertexPositionNormalColored.GetSizeInFloats() : VertexPositionColored.GetSizeInFloats()) *
                                           bufferStorage.VertexBufferCount;

            numVerticesInMeshesBefore.Add(0);

            bufferStorage.VertexBuffer = new VertexBuffer(vertexBufferSizeInFloats);
            bufferStorage.VertexBuffer.Map(vertexBufferSizeInFloats);

            int numMeshes = meshes.Count;

            if (useNormals)
            {
                // A VertexStream is used to write data into a VertexBuffer.
                VertexStreamPositionNormalColored vertexStream = bufferStorage.VertexBuffer.GetVertexStreamPositionNormalColored();
                for (int i = 0; i < numMeshes; i++)
                {
                    var  meshInfo = meshes[i];
                    Mesh mesh     = meshInfo.Mesh;
                    foreach (XYZ vertex in mesh.Vertices)
                    {
                        vertexStream.AddVertex(new VertexPositionNormalColored(vertex + meshInfo.Offset, meshInfo.Normal, meshInfo.ColorWithTransparency));
                    }

                    numVerticesInMeshesBefore.Add(numVerticesInMeshesBefore.Last() + mesh.Vertices.Count);
                }
            }
            else
            {
                // A VertexStream is used to write data into a VertexBuffer.
                VertexStreamPositionColored vertexStream = bufferStorage.VertexBuffer.GetVertexStreamPositionColored();
                for (int i = 0; i < numMeshes; i++)
                {
                    var  meshInfo = meshes[i];
                    Mesh mesh     = meshInfo.Mesh;
                    // make the color of all faces white in HLR
                    ColorWithTransparency color = meshInfo.ColorWithTransparency;
                    foreach (XYZ vertex in mesh.Vertices)
                    {
                        vertexStream.AddVertex(new VertexPositionColored(vertex + meshInfo.Offset, color));
                    }

                    numVerticesInMeshesBefore.Add(numVerticesInMeshesBefore.Last() + mesh.Vertices.Count);
                }
            }

            bufferStorage.VertexBuffer.Unmap();

            // Primitives are specified using a pair of vertex and index buffers. An index buffer contains a sequence of indices into
            // the associated vertex buffer, each index referencing a particular vertex.

            int meshNumber = 0;

            bufferStorage.IndexBufferCount = bufferStorage.PrimitiveCount * IndexTriangle.GetSizeInShortInts();
            int indexBufferSizeInShortInts = 1 * bufferStorage.IndexBufferCount;

            bufferStorage.IndexBuffer = new IndexBuffer(indexBufferSizeInShortInts);
            bufferStorage.IndexBuffer.Map(indexBufferSizeInShortInts);
            {
                // An IndexStream is used to write data into an IndexBuffer.
                IndexStreamTriangle indexStream = bufferStorage.IndexBuffer.GetIndexStreamTriangle();
                foreach (MeshInfo meshInfo in meshes)
                {
                    Mesh mesh       = meshInfo.Mesh;
                    int  startIndex = numVerticesInMeshesBefore[meshNumber];
                    for (int i = 0; i < mesh.NumTriangles; i++)
                    {
                        MeshTriangle mt = mesh.get_Triangle(i);
                        // Add three indices that define a triangle.
                        indexStream.AddTriangle(new IndexTriangle((int)(startIndex + mt.get_Index(0)),
                                                                  (int)(startIndex + mt.get_Index(1)),
                                                                  (int)(startIndex + mt.get_Index(2))));
                    }
                    meshNumber++;
                }
            }
            bufferStorage.IndexBuffer.Unmap();

            // VertexFormat is a specification of the data that is associated with a vertex (e.g., position).
            bufferStorage.VertexFormat = new VertexFormat(bufferStorage.FormatBits);
            // Effect instance is a specification of the appearance of geometry. For example, it may be used to specify color, if there is no color information provided with the vertices.
            bufferStorage.EffectInstance = new EffectInstance(bufferStorage.FormatBits);
        }
示例#30
0
        // Create and populate a pair of vertex and index buffers. Also update parameters associated with the format of the vertices.
        private void ProcessTriangles(RenderingPassBufferStorage bufferStorage)
        {
            List <TriangleInfo> triangles = bufferStorage.Triangles;

            if (triangles.Count == 0)
            {
                return;
            }

            bool useNormals = this.Inputs.EnableFaceNormal;

            // Vertex attributes are stored sequentially in vertex buffers. The attributes can include position, normal vector, and color.
            // All vertices within a vertex buffer must have the same format. Possible formats are enumerated by VertexFormatBits.
            // Vertex format also determines the type of rendering effect that can be used with the vertex buffer. In this sample,
            // the color is always encoded in the vertex attributes.

            bufferStorage.FormatBits = useNormals ? VertexFormatBits.PositionNormalColored : VertexFormatBits.PositionColored;

            // The format of the vertices determines the size of the vertex buffer.
            int vertexBufferSizeInFloats = (useNormals ? VertexPositionNormalColored.GetSizeInFloats() : VertexPositionColored.GetSizeInFloats()) *
                                           bufferStorage.VertexBufferCount;

            bufferStorage.VertexBuffer = new VertexBuffer(vertexBufferSizeInFloats);
            bufferStorage.VertexBuffer.Map(vertexBufferSizeInFloats);

            int numTriangles = triangles.Count;

            if (useNormals)
            {
                // A VertexStream is used to write data into a VertexBuffer.
                VertexStreamPositionNormalColored vertexStream = bufferStorage.VertexBuffer.GetVertexStreamPositionNormalColored();
                for (int i = 0; i < numTriangles; i++)
                {
                    var           triangleInfo = triangles[i];
                    g3.Triangle3d triangle     = triangleInfo.Triangle;
                    vertexStream.AddVertex(new VertexPositionNormalColored(triangle.V0.ToXYZ() + triangleInfo.Offset, triangleInfo.Normal, triangleInfo.ColorWithTransparency));
                    vertexStream.AddVertex(new VertexPositionNormalColored(triangle.V1.ToXYZ() + triangleInfo.Offset, triangleInfo.Normal, triangleInfo.ColorWithTransparency));
                    vertexStream.AddVertex(new VertexPositionNormalColored(triangle.V2.ToXYZ() + triangleInfo.Offset, triangleInfo.Normal, triangleInfo.ColorWithTransparency));
                }
            }
            else
            {
                // A VertexStream is used to write data into a VertexBuffer.
                VertexStreamPositionColored vertexStream = bufferStorage.VertexBuffer.GetVertexStreamPositionColored();
                for (int i = 0; i < numTriangles; i++)
                {
                    var           triangleInfo = triangles[i];
                    g3.Triangle3d triangle     = triangleInfo.Triangle;
                    // make the color of all faces white in HLR
                    ColorWithTransparency color = triangleInfo.ColorWithTransparency;
                    vertexStream.AddVertex(new VertexPositionColored(triangle.V0.ToXYZ() + triangleInfo.Offset, color));
                    vertexStream.AddVertex(new VertexPositionColored(triangle.V1.ToXYZ() + triangleInfo.Offset, color));
                    vertexStream.AddVertex(new VertexPositionColored(triangle.V2.ToXYZ() + triangleInfo.Offset, color));
                }
            }

            bufferStorage.VertexBuffer.Unmap();

            // Primitives are specified using a pair of vertex and index buffers. An index buffer contains a sequence of indices into
            // the associated vertex buffer, each index referencing a particular vertex.

            bufferStorage.IndexBufferCount = bufferStorage.PrimitiveCount * IndexTriangle.GetSizeInShortInts();
            int indexBufferSizeInShortInts = 1 * bufferStorage.IndexBufferCount;

            bufferStorage.IndexBuffer = new IndexBuffer(indexBufferSizeInShortInts);
            bufferStorage.IndexBuffer.Map(indexBufferSizeInShortInts);
            // An IndexStream is used to write data into an IndexBuffer.
            IndexStreamTriangle indexStream = bufferStorage.IndexBuffer.GetIndexStreamTriangle();
            int currIndex = 0;

            for (int i = 0; i < numTriangles; i++)
            {
                // Add three indices that define a triangle.
                indexStream.AddTriangle(new IndexTriangle(currIndex + 0, currIndex + 1, currIndex + 2));
                currIndex += 3;
            }
            bufferStorage.IndexBuffer.Unmap();

            // VertexFormat is a specification of the data that is associated with a vertex (e.g., position).
            bufferStorage.VertexFormat = new VertexFormat(bufferStorage.FormatBits);
            // Effect instance is a specification of the appearance of geometry. For example, it may be used to specify color, if there is no color information provided with the vertices.
            bufferStorage.EffectInstance = new EffectInstance(bufferStorage.FormatBits);
        }
示例#31
0
        private VertexPositionNormalColored[] SetUpTerrainVertices()
        {
            VertexPositionNormalColored[] terrainVertices = new VertexPositionNormalColored[terrainWidth * terrainLength];

            for (int x = 0; x < terrainWidth; x++)
            {
                for (int y = 0; y < terrainLength; y++)
                {
                    terrainVertices[x + y * terrainWidth].Position = new Vector3(x, heightData[x, y], -y);

                    if (heightData[x, y] < 6) { terrainVertices[x + y * terrainWidth].Color = Color.Blue; }
                    else if (heightData[x, y] < 8) { terrainVertices[x + y * terrainWidth].Color = Color.Aquamarine; }
                    else if (heightData[x, y] < 10) { terrainVertices[x + y * terrainWidth].Color = Color.SandyBrown; }
                    else if (heightData[x, y] < 15) { terrainVertices[x + y * terrainWidth].Color = Color.Green; }
                    else if (heightData[x, y] < 18) { terrainVertices[x + y * terrainWidth].Color = Color.ForestGreen; }
                    else if (heightData[x, y] < 25) { terrainVertices[x + y * terrainWidth].Color = Color.SaddleBrown; }
                    else if (heightData[x, y] < 30) { terrainVertices[x + y * terrainWidth].Color = Color.DimGray; }
                    else { terrainVertices[x + y * terrainWidth].Color = Color.White; }
                }
            }

            return terrainVertices;
        }
示例#32
0
        private void BuildVerticiesAndIndicies()
        {
            // Cycle through each ADT
            var tempVertices = new List<VertexPositionNormalColored>();
            var tempIndicies = new List<int>();
            var offset = 0;
            foreach (var adt in _manager.MapTiles)
            {
                // Handle the ADTs
                for (var v = 0; v < adt.TerrainVertices.Count; v++)
                {
                    var vertex = adt.TerrainVertices[v];
                    var vertexPosNmlCol = new VertexPositionNormalColored(vertex.ToXna(), TerrainColor,
                                                                          Microsoft.Xna.Framework.Vector3.Down);
                    tempVertices.Add(vertexPosNmlCol);
                }
                for (var i = 0; i < adt.Indices.Count; i++)
                {
                    tempIndicies.Add(adt.Indices[i] + offset);
                }
                offset = tempVertices.Count;

                //if (!DrawLiquids) continue;
                for (var v = 0; v < adt.LiquidVertices.Count; v++)
                {
                    var vertex = adt.LiquidVertices[v];
                    var vertexPosNmlCol = new VertexPositionNormalColored(vertex.ToXna(), WaterColor,
                                                                          Microsoft.Xna.Framework.Vector3.Down);
                    tempVertices.Add(vertexPosNmlCol);
                }
                for (var i = 0; i < adt.LiquidIndices.Count; i++)
                {
                    tempIndicies.Add(adt.LiquidIndices[i] + offset);
                }
                offset = tempVertices.Count;
            }

            _cachedIndices = tempIndicies.ToArray();
            _cachedVertices = tempVertices.ToArray();

            _renderCached = true;

            for (var i = 0; i < _cachedVertices.Length; i++)
            {
                PositionUtil.TransformWoWCoordsToXNACoords(ref _cachedVertices[i]);
            }
        }
示例#33
0
 /// <summary>
 /// Changes the coodinate system of a vertex from WoW based to XNA based.
 /// </summary>
 /// <param name="vertex">A vertex with WoW coords</param>
 public static void TransformWoWCoordsToXNACoords(ref VertexPositionNormalColored vertex)
 {
     TransformWoWCoordsToXNACoords(ref vertex.Position);
 }