Axiom.Core.PatchSurface.Build C# (CSharp) Method

Build() public method

Tells the system to build the mesh relating to the surface into externally created buffers.
The VertexDeclaration of the vertex buffer must be identical to the one passed into DefineSurface(Array, VertexDeclaration, int, int). In addition, there must be enough space in the buffer to accommodate the patch at full detail level; you should check RequiredVertexCount and RequiredIndexCount to determine this. This method does not create an internal mesh for this patch and so GetMesh will return null if you call it after building the patch this way.
public Build ( HardwareVertexBuffer destVertexBuffer, int vertexStart, HardwareIndexBuffer destIndexBuffer, int indexStart ) : void
destVertexBuffer Axiom.Graphics.HardwareVertexBuffer The destination vertex buffer in which to build the patch.
vertexStart int The offset at which to start writing vertices for this patch.
destIndexBuffer Axiom.Graphics.HardwareIndexBuffer The destination index buffer in which to build the patch.
indexStart int The offset at which to start writing indexes for this patch.
return void
		public void Build( HardwareVertexBuffer destVertexBuffer, int vertexStart, HardwareIndexBuffer destIndexBuffer, int indexStart )
		{
			if ( controlPoints.Count == 0 )
			{
				return;
			}

			vertexBuffer = destVertexBuffer;
			vertexOffset = vertexStart;
			indexBuffer = destIndexBuffer;
			indexOffset = indexStart;

			// lock just the region we are interested in
			IntPtr lockedBuffer = vertexBuffer.Lock(
				vertexOffset * declaration.GetVertexSize( 0 ),
				requiredVertexCount * declaration.GetVertexSize( 0 ),
				BufferLocking.NoOverwrite );

			DistributeControlPoints( lockedBuffer );

			// subdivide the curves to the max
			// Do u direction first, so need to step over v levels not done yet
			int vStep = 1 << maxVLevel;
			int uStep = 1 << maxULevel;

			// subdivide this row in u
			for ( int v = 0; v < meshHeight; v += vStep )
			{
				SubdivideCurve( lockedBuffer, v * meshWidth, uStep, meshWidth / uStep, uLevel );
			}

			// Now subdivide in v direction, this time all the u direction points are there so no step
			for ( int u = 0; u < meshWidth; u++ )
			{
				SubdivideCurve( lockedBuffer, u, vStep * meshWidth, meshHeight / vStep, vLevel );
			}

			// don't forget to unlock!
			vertexBuffer.Unlock();

			// Make triangles from mesh at this current level of detail
			MakeTriangles();
		}

Usage Example

Ejemplo n.º 1
0
        protected override void LoadImpl()
        {
            SubMesh sm = CreateSubMesh();

            sm.vertexData        = new VertexData();
            sm.useSharedVertices = false;

            // Set up the vertex buffer
            sm.vertexData.vertexStart       = 0;
            sm.vertexData.vertexCount       = patchSurface.RequiredVertexCount;
            sm.vertexData.vertexDeclaration = vertexDeclaration;

            HardwareVertexBuffer buffer =
                HardwareBufferManager.Instance.CreateVertexBuffer(
                    vertexDeclaration.GetVertexSize(0),
                    sm.vertexData.vertexCount,
                    vertexBufferUsage,
                    useVertexShadowBuffer);

            // bind the vertex buffer
            sm.vertexData.vertexBufferBinding.SetBinding(0, buffer);

            // create the index buffer
            sm.indexData.indexStart  = 0;
            sm.indexData.indexCount  = patchSurface.RequiredIndexCount;
            sm.indexData.indexBuffer =
                HardwareBufferManager.Instance.CreateIndexBuffer(
                    IndexType.Size16,
                    sm.indexData.indexCount,
                    indexBufferUsage,
                    useIndexShadowBuffer);

            // build the path
            patchSurface.Build(buffer, 0, sm.indexData.indexBuffer, 0);

            // set the bounds
            this.BoundingBox          = patchSurface.Bounds;
            this.BoundingSphereRadius = patchSurface.BoundingSphereRadius;
        }