Ejemplo n.º 1
0
        /// <summary>
        /// 頂点を追加します。
        /// </summary>
        /// <param name="vertex">頂点。</param>
        public void AddVertex(ref VertexPositionNormalColorTexture vertex)
        {
            vertices[VertexCount++] = vertex;

            // AABB を更新。
            Vector3.Max(ref box.Max, ref vertex.Position, out box.Max);
            Vector3.Min(ref box.Min, ref vertex.Position, out box.Min);
        }
Ejemplo n.º 2
0
        void AddMesh(int x, int y, int z, ref Color color, MeshPart source, ChunkVertices destination)
        {
            foreach (var index in source.Indices)
                destination.AddIndex(index);

            var vertices = source.Vertices;
            for (int i = 0; i < vertices.Length; i++)
            {
                var sourceVertex = vertices[i];

                var vertex = new VertexPositionNormalColorTexture
                {
                    Position = sourceVertex.Position,
                    Normal = sourceVertex.Normal,
                    Color = color,
                    TextureCoordinate = sourceVertex.TextureCoordinate
                };

                // ブロック位置へ移動。
                vertex.Position.X += x;
                vertex.Position.Y += y;
                vertex.Position.Z += z;

                // ブロックの MeshPart はその中心に原点があるため、半ブロック移動。
                vertex.Position += blockMeshOffset;

                // チャンク メッシュはメッシュの中心位置を原点とするため、半メッシュ移動。
                vertex.Position -= meshManager.MeshOffset;

                destination.AddVertex(ref vertex);
            }
        }
Ejemplo n.º 3
0
        public void SetVertices(VertexPositionNormalColorTexture[] vertices, int vertexCount)
        {
            if (vertices == null) throw new ArgumentNullException("vertices");
            if (vertexCount < 0 || vertices.Length < vertexCount) throw new ArgumentOutOfRangeException("vertexCount");

            VertexCount = vertexCount;

            if (vertexCount != 0)
            {
                if (vertexBuffer != null && vertexBuffer.VertexCount != vertexCount)
                {
                    vertexBuffer.Dispose();
                    vertexBuffer = null;
                }

                if (vertexBuffer == null)
                    vertexBuffer = new DynamicVertexBuffer(
                        graphicsDevice, typeof(VertexPositionNormalColorTexture), vertexCount, BufferUsage.WriteOnly);

                vertexBuffer.SetData(vertices, 0, vertexCount, SetDataOptions.Discard);
            }
            else
            {
                if (vertexBuffer != null)
                {
                    vertexBuffer.Dispose();
                    vertexBuffer = null;
                }
            }
        }