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

DefineSurface() public method

Sets up the surface by defining it's control points, type and initial subdivision level.
This method initialises the surface by passing it a set of control points. The type of curves to be used are also defined here, although the only supported option currently is a bezier patch. You can also specify a global subdivision level here if you like, although it is recommended that the parameter is left as AUTO_LEVEL, which means the system decides how much subdivision is required (based on the curvature of the surface).
public DefineSurface ( Array controlPointArray, Axiom.Graphics.VertexDeclaration declaration, int width, int height, PatchSurfaceType type, int uMaxSubdivisionLevel, int vMaxSubdivisionLevel, VisibleSide visibleSide ) : void
controlPointArray System.Array /// An array containing the vertex data which define control points of the curves /// rather than actual vertices. Note that you are expected to provide not /// just position information, but potentially normals and texture coordinates too. /// The array is internally treated as a contiguous memory buffer without any gaps between the elements. /// The format of the buffer is defined in the VertexDeclaration parameter. ///
declaration Axiom.Graphics.VertexDeclaration /// VertexDeclaration describing the contents of the buffer. /// Note this declaration must _only_ draw on buffer source 0! ///
width int Specifies the width of the patch in control points.
height int Specifies the height of the patch in control points.
type PatchSurfaceType The type of surface.
uMaxSubdivisionLevel int /// If you want to manually set the top level of subdivision, /// do it here, otherwise let the system decide. ///
vMaxSubdivisionLevel int /// If you want to manually set the top level of subdivision, /// do it here, otherwise let the system decide. ///
visibleSide VisibleSide Determines which side of the patch (or both) triangles are generated for.
return void
		public void DefineSurface( Array controlPointArray, VertexDeclaration declaration, int width, int height,
			PatchSurfaceType type, int uMaxSubdivisionLevel, int vMaxSubdivisionLevel, VisibleSide visibleSide )
		{

			if ( height == 0 || width == 0 )
			{
				return; // Do nothing - garbage
			}

			//pin the input to have a pointer
			Memory.UnpinObject( controlPointArray );
			this.controlPointBuffer = Memory.PinObject( controlPointArray );

			this.type = type;
			this.controlWidth = width;
			this.controlHeight = height;
			this.controlCount = width * height;
			this.declaration = declaration;

			// Copy positions into Vector3 vector
			controlPoints.Clear();
			VertexElement elem = declaration.FindElementBySemantic( VertexElementSemantic.Position );
			int vertSize = declaration.GetVertexSize( 0 );

			unsafe
			{
				byte* pVert = (byte*)controlPointBuffer;
				float* pReal = null;
				for ( int i = 0; i < controlCount; i++ )
				{
					pReal = (float*)( pVert + ( i * vertSize ) + elem.Offset );
					controlPoints.Add( new Vector3( pReal[ 0 ], pReal[ 1 ], pReal[ 2 ] ) );
				}
			}
			this.side = visibleSide;

			// Determine max level
			// Initialize to 100% detail
			subdivisionFactor = 1.0f;

			if ( uMaxSubdivisionLevel == AUTO_LEVEL )
			{
				uLevel = maxULevel = GetAutoULevel();
			}
			else
			{
				uLevel = maxULevel = uMaxSubdivisionLevel;
			}

			if ( vMaxSubdivisionLevel == AUTO_LEVEL )
			{
				vLevel = maxVLevel = GetAutoVLevel();
			}
			else
			{
				vLevel = maxVLevel = vMaxSubdivisionLevel;
			}

			// Derive mesh width / height
			meshWidth = ( LevelWidth( maxULevel ) - 1 ) * ( ( controlWidth - 1 ) / 2 ) + 1;
			meshHeight = ( LevelWidth( maxVLevel ) - 1 ) * ( ( controlHeight - 1 ) / 2 ) + 1;

			// Calculate number of required vertices / indexes at max resolution
			requiredVertexCount = meshWidth * meshHeight;
			int iterations = ( side == VisibleSide.Both ) ? 2 : 1;
			requiredIndexCount = ( meshWidth - 1 ) * ( meshHeight - 1 ) * 2 * iterations * 3;

			// Calculate bounds based on control points
			Vector3 min = Vector3.Zero;
			Vector3 max = Vector3.Zero;
			float maxSqRadius = 0.0f;
			bool first = true;

			for ( int i = 0; i < controlPoints.Count; i++ )
			{
				Vector3 vec = controlPoints[ i ];
				if ( first )
				{
					min = max = vec;
					maxSqRadius = vec.LengthSquared;
					first = false;
				}
				else
				{
					min.Floor( vec );
					max.Ceil( vec );
					maxSqRadius = Utility.Max( vec.LengthSquared, maxSqRadius );
				}
			}

			// set the bounds of the patch
			aabb.SetExtents( min, max );
			boundingSphereRadius = Utility.Sqrt( maxSqRadius );
		}

Same methods

PatchSurface::DefineSurface ( Array controlPointArray, Axiom.Graphics.VertexDeclaration decl, int width, int height ) : void

Usage Example

Beispiel #1
0
        // ------------------------------------

        // ------------------------------------
        /// <summary>
        ///     Creates a new PatchMesh.
        /// </summary>
        /// <remarks>
        ///     As defined in <see cref="MeshManager.CreateBezierPatch" />.
        /// </remarks>
        public PatchMesh(string name, System.Array controlPointBuffer, VertexDeclaration declaration,
                         int width, int height, int uMaxSubdivisionLevel, int vMaxSubdivisionLevel, VisibleSide visibleSide,
                         BufferUsage vbUsage, BufferUsage ibUsage, bool vbUseShadow, bool ibUseShadow) : base(name)
        {
            vertexBufferUsage     = vbUsage;
            useVertexShadowBuffer = vbUseShadow;
            indexBufferUsage      = ibUsage;
            useIndexShadowBuffer  = ibUseShadow;

            // Init patch builder
            // define the surface
            // NB clone the declaration to make it independent
            vertexDeclaration = (VertexDeclaration)declaration.Clone();
            patchSurface.DefineSurface(controlPointBuffer, vertexDeclaration, width, height,
                                       PatchSurfaceType.Bezier, uMaxSubdivisionLevel, vMaxSubdivisionLevel, visibleSide);
        }
All Usage Examples Of Axiom.Core.PatchSurface::DefineSurface