Esempio n. 1
0
        /// <summary>After the draw pass, builds flat buffers.</summary>
        public void CompletedLayout()
        {
            int total = TotalBlockCount;

            BlockCount = total;

            if (total != LastBlockCount)
            {
                // We gained or lost some blocks - resize our buffers:
                UV.Resize(total);
                UV2.Resize(total);
                Colours.Resize(total);
                Vertices.Resize(total);
                Triangles.Resize(total);
            }

            // Always make sure UV3 and Normals are valid:
            if (Normals != null)
            {
                Normals.ResizeMatch(total, Vertices.Buffer.Length);
            }

            if (UV3 != null)
            {
                UV3.ResizeMatch(total, Vertices.Buffer.Length);
            }

            LastBlockCount = total;

            // Flatten now:
            Flatten(FirstBuffer, total);

            // Output the new mesh data:
            Flush();
        }
        /// <summary>Let the mesh know a layout routine was completed.
        /// <see cref="PowerUI.Renderman.Layout"/>.</summary>
        public void CompletedLayout()
        {
            if (BlockCount != LastBlockCount)
            {
                // We gained or lost some blocks - resize our buffers:
                UV.Resize(BlockCount);
                UV2.Resize(BlockCount);

                if (Normals != null)
                {
                    Normals.Resize(BlockCount);
                }

                if (Tangents != null)
                {
                    Tangents.Resize(BlockCount);
                }

                Colours.Resize(BlockCount);
                Vertices.Resize(BlockCount);
                Triangles.Resize(BlockCount);
            }

            // Allocate the new block indices:
            int vertexIndex   = 0;
            int triangleIndex = 0;

            MeshBlock currentBlock = FirstBlock;

            while (currentBlock != null)
            {
                currentBlock.VertexIndex = vertexIndex;
                // Write the triangles:
                // First triangle - Top left corner:
                Triangles.Buffer[triangleIndex++] = vertexIndex;
                // Top right corner:
                Triangles.Buffer[triangleIndex++] = vertexIndex + 1;
                // Bottom left corner:
                Triangles.Buffer[triangleIndex++] = vertexIndex + 2;
                // Second triangle - Top right corner:
                Triangles.Buffer[triangleIndex++] = vertexIndex + 1;
                // Bottom right corner:
                Triangles.Buffer[triangleIndex++] = vertexIndex + 3;
                // Bottom left corner:
                Triangles.Buffer[triangleIndex++] = vertexIndex + 2;

                // Write the block:
                currentBlock.Layout();
                currentBlock.Paint();

                vertexIndex += 4;
                currentBlock = currentBlock.BlockAfter;
            }

            // Output the new mesh data:
            Flush();
        }