Patch specialization of Mesh.
Instances of this class should be created by calling MeshManager.CreateBezierPatch.
Inheritance: Axiom.Core.Mesh
        /// <summary>
        ///     Creates a Bezier patch based on an array of control vertices.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="controlPointBuffer"></param>
        /// <param name="declaration"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="uMaxSubdivisionLevel"></param>
        /// <param name="vMaxSubdivisionLevel"></param>
        /// <param name="visibleSide"></param>
        /// <param name="vbUsage"></param>
        /// <param name="ibUsage"></param>
        /// <param name="vbUseShadow"></param>
        /// <param name="ibUseShadow"></param>
        /// <returns></returns>
        public PatchMesh CreateBezierPatch(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)
        {
            PatchMesh mesh = (PatchMesh)GetByName(name);

            if (mesh != null)
            {
                throw new AxiomException("A mesh with the name {0} already exists!", name);
            }

            mesh = new PatchMesh(name, controlPointBuffer, declaration, width, height,
                                 uMaxSubdivisionLevel, vMaxSubdivisionLevel, visibleSide, vbUsage, ibUsage, vbUseShadow, ibUseShadow);

            mesh.IsManuallyDefined = true;

            base.Load(mesh, 0);

            return(mesh);
        }
Ejemplo n.º 2
0
		/// <summary>
		///     Creates a Bezier patch based on an array of control vertices.
		/// </summary>
		public PatchMesh CreateBezierPatch( string name, string group, Array controlPointBuffer, VertexDeclaration declaration,
			int width, int height, int uMaxSubdivisionLevel, int vMaxSubdivisionLevel, VisibleSide visibleSide,
			BufferUsage vbUsage, BufferUsage ibUsage, bool vbUseShadow, bool ibUseShadow )
		{
			if ( width < 3 || height < 3 )
			{
				throw new Exception( "Bezier patch requires at least 3x3 control points." );
			}
			PatchMesh mesh = (PatchMesh)this[ name ];

			if ( mesh != null )
			{
				throw new AxiomException( "A mesh with the name {0} already exists!", name );
			}

			mesh = new PatchMesh( this, name, nextHandle, group );

			mesh.Define( controlPointBuffer, declaration, width, height, uMaxSubdivisionLevel, vMaxSubdivisionLevel, visibleSide, vbUsage, ibUsage, vbUseShadow, ibUseShadow );

			mesh.Load();

			_add( mesh );

			return mesh;
		}
Ejemplo n.º 3
0
		protected override void SetupContent()
		{
			ResourceGroupManager.Instance.InitializeAllResourceGroups();
			// setup some basic lighting for our scene
			SceneManager.AmbientLight = new ColorEx( 0.5f, 0.5f, 0.5f );
			SceneManager.CreateLight( "BezierLight" ).Position = new Vector3( 100, 100, 100 );

			// define the control point vertices for our patch
			// Patch data
			PatchVertex[] patchVertices = new PatchVertex[ 9 ];

			patchVertices[ 0 ].X = -500;
			patchVertices[ 0 ].Y = 200;
			patchVertices[ 0 ].Z = -500;
			patchVertices[ 0 ].Nx = -0.5f;
			patchVertices[ 0 ].Ny = 0.5f;
			patchVertices[ 0 ].Nz = 0;
			patchVertices[ 0 ].U = 0;
			patchVertices[ 0 ].V = 0;

			patchVertices[ 1 ].X = 0;
			patchVertices[ 1 ].Y = 500;
			patchVertices[ 1 ].Z = -750;
			patchVertices[ 1 ].Nx = 0;
			patchVertices[ 1 ].Ny = 0.5f;
			patchVertices[ 1 ].Nz = 0;
			patchVertices[ 1 ].U = 0.5f;
			patchVertices[ 1 ].V = 0;

			patchVertices[ 2 ].X = 500;
			patchVertices[ 2 ].Y = 1000;
			patchVertices[ 2 ].Z = -500;
			patchVertices[ 2 ].Nx = 0.5f;
			patchVertices[ 2 ].Ny = 0.5f;
			patchVertices[ 2 ].Nz = 0;
			patchVertices[ 2 ].U = 1;
			patchVertices[ 2 ].V = 0;

			patchVertices[ 3 ].X = -500;
			patchVertices[ 3 ].Y = 0;
			patchVertices[ 3 ].Z = 0;
			patchVertices[ 3 ].Nx = -0.5f;
			patchVertices[ 3 ].Ny = 0.5f;
			patchVertices[ 3 ].Nz = 0;
			patchVertices[ 3 ].U = 0;
			patchVertices[ 3 ].V = 0.5f;

			patchVertices[ 4 ].X = 0;
			patchVertices[ 4 ].Y = 500;
			patchVertices[ 4 ].Z = 0;
			patchVertices[ 4 ].Nx = 0;
			patchVertices[ 4 ].Ny = 0.5f;
			patchVertices[ 4 ].Nz = 0;
			patchVertices[ 4 ].U = 0.5f;
			patchVertices[ 4 ].V = 0.5f;

			patchVertices[ 5 ].X = 500;
			patchVertices[ 5 ].Y = -50;
			patchVertices[ 5 ].Z = 0;
			patchVertices[ 5 ].Nx = 0.5f;
			patchVertices[ 5 ].Ny = 0.5f;
			patchVertices[ 5 ].Nz = 0;
			patchVertices[ 5 ].U = 1;
			patchVertices[ 5 ].V = 0.5f;

			patchVertices[ 6 ].X = -500;
			patchVertices[ 6 ].Y = 0;
			patchVertices[ 6 ].Z = 500;
			patchVertices[ 6 ].Nx = -0.5f;
			patchVertices[ 6 ].Ny = 0.5f;
			patchVertices[ 6 ].Nz = 0;
			patchVertices[ 6 ].U = 0;
			patchVertices[ 6 ].V = 1;

			patchVertices[ 7 ].X = 0;
			patchVertices[ 7 ].Y = 500;
			patchVertices[ 7 ].Z = 500;
			patchVertices[ 7 ].Nx = 0;
			patchVertices[ 7 ].Ny = 0.5f;
			patchVertices[ 7 ].Nz = 0;
			patchVertices[ 7 ].U = 0.5f;
			patchVertices[ 7 ].V = 1;

			patchVertices[ 8 ].X = 500;
			patchVertices[ 8 ].Y = 200;
			patchVertices[ 8 ].Z = 800;
			patchVertices[ 8 ].Nx = 0.5f;
			patchVertices[ 8 ].Ny = 0.5f;
			patchVertices[ 8 ].Nz = 0;
			patchVertices[ 8 ].U = 1;
			patchVertices[ 8 ].V = 1;
			// specify a vertex format declaration for our patch: 3 floats for position, 3 floats for normal, 2 floats for UV
			patchDeclaration = HardwareBufferManager.Instance.CreateVertexDeclaration();
			patchDeclaration.AddElement( 0, 0, VertexElementType.Float3, VertexElementSemantic.Position );
			patchDeclaration.AddElement( 0, 12, VertexElementType.Float3, VertexElementSemantic.Normal );
			patchDeclaration.AddElement( 0, 24, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0 );

			// create a patch mesh using vertices and declaration
			patch = MeshManager.Instance.CreateBezierPatch( "patch", ResourceGroupManager.DefaultResourceGroupName, patchVertices, patchDeclaration, 3, 3, 5, 5, VisibleSide.Both, BufferUsage.StaticWriteOnly, BufferUsage.DynamicWriteOnly, true, true );

			// Start patch at 0 detail
			patch.Subdivision = 0;

			// Create entity based on patch
			patchEntity = SceneManager.CreateEntity( "Entity1", "patch" );
			Material material = (Material)MaterialManager.Instance.Create( "TextMat", ResourceGroupManager.DefaultResourceGroupName, null );
			material.GetTechnique( 0 ).GetPass( 0 ).CreateTextureUnitState( "BumpyMetal.jpg" );

			patchEntity.MaterialName = "TextMat";
			patchPass = material.GetTechnique( 0 ).GetPass( 0 );

			// Attach the entity to the root of the scene
			SceneManager.RootSceneNode.AttachObject( patchEntity );

			// save the main pass of the material so we can toggle wireframe on it
			if ( material != null )
			{
				patchPass = material.GetTechnique( 0 ).GetPass( 0 );

				// use an orbit style camera
				CameraManager.setStyle( CameraStyle.Orbit );
				CameraManager.SetYawPitchDist( 0, 0, 250 );

				TrayManager.ShowCursor();

				// create slider to adjust detail and checkbox to toggle wireframe
				Slider slider = TrayManager.CreateThickSlider( TrayLocation.TopLeft, "Detail", "Detail", 120, 44, 0, 1, 6 );
				CheckBox box = TrayManager.CreateCheckBox( TrayLocation.TopLeft, "Wireframe", "Wireframe", 120 );
				slider.SliderMoved += new SliderMovedHandler( slider_SliderMoved );
				box.CheckChanged += new CheckChangedHandler( box_CheckChanged );

			}
		}
        /// <summary>
        ///     Creates a Bezier patch based on an array of control vertices.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="controlPointBuffer"></param>
        /// <param name="declaration"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="uMaxSubdivisionLevel"></param>
        /// <param name="vMaxSubdivisionLevel"></param>
        /// <param name="visibleSide"></param>
        /// <param name="vbUsage"></param>
        /// <param name="ibUsage"></param>
        /// <param name="vbUseShadow"></param>
        /// <param name="ibUseShadow"></param>
        /// <returns></returns>
        public PatchMesh CreateBezierPatch(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)
        {
            PatchMesh mesh = (PatchMesh)GetByName(name);

            if(mesh != null) {
                throw new AxiomException("A mesh with the name {0} already exists!", name);
            }

            mesh = new PatchMesh(name, controlPointBuffer, declaration, width, height,
                uMaxSubdivisionLevel, vMaxSubdivisionLevel, visibleSide, vbUsage, ibUsage, vbUseShadow, ibUseShadow);

            mesh.IsManuallyDefined = true;

            base.Load(mesh, 0);

            return mesh;
        }
        // Just override the mandatory create scene method
        protected override void CreateScene()
        {
            // Set ambient light
            scene.AmbientLight = new ColorEx(0.2f, 0.2f, 0.2f);

            // Create point light
            Light light = scene.CreateLight("MainLight");

            // Accept default settings: point light, white diffuse, just set position.
            // I could attach the light to a SceneNode if I wanted it to move automatically with
            // other objects, but I don't.
            light.Type = LightType.Directional;
            light.Direction = new Vector3(-0.5f, -0.5f, 0);

            // Create patch with positions, normals, and 1 set of texcoords
            patchDeclaration = HardwareBufferManager.Instance.CreateVertexDeclaration();
            patchDeclaration.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position);
            patchDeclaration.AddElement(0, 12, VertexElementType.Float3, VertexElementSemantic.Normal);
            patchDeclaration.AddElement(0, 24, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0);

            // Patch data
            PatchVertex[] patchVertices = new PatchVertex[9];

            patchVertices[0].X = -500; patchVertices[0].Y = 200; patchVertices[0].Z = -500;
            patchVertices[0].Nx = -0.5f; patchVertices[0].Ny = 0.5f; patchVertices[0].Nz = 0;
            patchVertices[0].U = 0; patchVertices[0].V = 0;

            patchVertices[1].X = 0; patchVertices[1].Y = 500; patchVertices[1].Z = -750;
            patchVertices[1].Nx = 0; patchVertices[1].Ny = 0.5f; patchVertices[1].Nz = 0;
            patchVertices[1].U = 0.5f; patchVertices[1].V = 0;

            patchVertices[2].X = 500; patchVertices[2].Y = 1000; patchVertices[2].Z = -500;
            patchVertices[2].Nx = 0.5f; patchVertices[2].Ny = 0.5f; patchVertices[2].Nz = 0;
            patchVertices[2].U = 1; patchVertices[2].V = 0;

            patchVertices[3].X = -500; patchVertices[3].Y = 0; patchVertices[3].Z = 0;
            patchVertices[3].Nx = -0.5f; patchVertices[3].Ny = 0.5f; patchVertices[3].Nz = 0;
            patchVertices[3].U = 0; patchVertices[3].V = 0.5f;

            patchVertices[4].X = 0; patchVertices[4].Y = 500; patchVertices[4].Z = 0;
            patchVertices[4].Nx = 0; patchVertices[4].Ny = 0.5f; patchVertices[4].Nz = 0;
            patchVertices[4].U = 0.5f; patchVertices[4].V = 0.5f;

            patchVertices[5].X = 500; patchVertices[5].Y = -50; patchVertices[5].Z = 0;
            patchVertices[5].Nx = 0.5f; patchVertices[5].Ny = 0.5f; patchVertices[5].Nz = 0;
            patchVertices[5].U = 1; patchVertices[5].V = 0.5f;

            patchVertices[6].X = -500; patchVertices[6].Y = 0; patchVertices[6].Z = 500;
            patchVertices[6].Nx = -0.5f; patchVertices[6].Ny = 0.5f; patchVertices[6].Nz = 0;
            patchVertices[6].U = 0; patchVertices[6].V = 1;

            patchVertices[7].X = 0; patchVertices[7].Y = 500; patchVertices[7].Z = 500;
            patchVertices[7].Nx = 0; patchVertices[7].Ny = 0.5f; patchVertices[7].Nz = 0;
            patchVertices[7].U = 0.5f; patchVertices[7].V = 1;

            patchVertices[8].X = 500; patchVertices[8].Y = 200; patchVertices[8].Z = 800;
            patchVertices[8].Nx = 0.5f; patchVertices[8].Ny = 0.5f; patchVertices[8].Nz = 0;
            patchVertices[8].U = 1; patchVertices[8].V = 1;

            patch = MeshManager.Instance.CreateBezierPatch("Bezier1", patchVertices, patchDeclaration, 3, 3, 5, 5, VisibleSide.Both, BufferUsage.StaticWriteOnly, BufferUsage.DynamicWriteOnly, true, true);

            // Start patch a 0 detail
            patch.SetSubdivision(0);

            // Create entity based on patch
            patchEntity = scene.CreateEntity("Entity1", "Bezier1");

            Material material = (Material)MaterialManager.Instance.Create("TextMat");
            material.GetTechnique(0).GetPass(0).CreateTextureUnitState("BumpyMetal.jpg");
            patchEntity.MaterialName = "TextMat";

            // Attach the entity to the root of the scene
            scene.RootSceneNode.AttachObject(patchEntity);

            camera.Position = new Vector3(500, 500, 1500);
            camera.LookAt(new Vector3(0, 200, -300));
        }
Ejemplo n.º 6
0
        public void OnLoad()
        {
            // Create patch with positions, normals, and 1 set of texcoords
            var patchDeclaration = HardwareBufferManager.Instance.CreateVertexDeclaration();
            patchDeclaration.AddElement(0, 0, VertexElementType.Float3, VertexElementSemantic.Position);
            patchDeclaration.AddElement(0, 12, VertexElementType.Float3, VertexElementSemantic.Normal);
            patchDeclaration.AddElement(0, 24, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0);

            var patchVertices = new PatchVertex[9];

            patchVertices[0].X = -500;
            patchVertices[0].Y = 200;
            patchVertices[0].Z = -500;
            patchVertices[0].Nx = -0.5f;
            patchVertices[0].Ny = 0.5f;
            patchVertices[0].Nz = 0;
            patchVertices[0].U = 0;
            patchVertices[0].V = 0;

            patchVertices[1].X = 0;
            patchVertices[1].Y = 500;
            patchVertices[1].Z = -750;
            patchVertices[1].Nx = 0;
            patchVertices[1].Ny = 0.5f;
            patchVertices[1].Nz = 0;
            patchVertices[1].U = 0.5f;
            patchVertices[1].V = 0;

            patchVertices[2].X = 500;
            patchVertices[2].Y = 1000;
            patchVertices[2].Z = -500;
            patchVertices[2].Nx = 0.5f;
            patchVertices[2].Ny = 0.5f;
            patchVertices[2].Nz = 0;
            patchVertices[2].U = 1;
            patchVertices[2].V = 0;

            patchVertices[3].X = -500;
            patchVertices[3].Y = 0;
            patchVertices[3].Z = 0;
            patchVertices[3].Nx = -0.5f;
            patchVertices[3].Ny = 0.5f;
            patchVertices[3].Nz = 0;
            patchVertices[3].U = 0;
            patchVertices[3].V = 0.5f;

            patchVertices[4].X = 0;
            patchVertices[4].Y = 500;
            patchVertices[4].Z = 0;
            patchVertices[4].Nx = 0;
            patchVertices[4].Ny = 0.5f;
            patchVertices[4].Nz = 0;
            patchVertices[4].U = 0.5f;
            patchVertices[4].V = 0.5f;

            patchVertices[5].X = 500;
            patchVertices[5].Y = -50;
            patchVertices[5].Z = 0;
            patchVertices[5].Nx = 0.5f;
            patchVertices[5].Ny = 0.5f;
            patchVertices[5].Nz = 0;
            patchVertices[5].U = 1;
            patchVertices[5].V = 0.5f;

            patchVertices[6].X = -500;
            patchVertices[6].Y = 0;
            patchVertices[6].Z = 500;
            patchVertices[6].Nx = -0.5f;
            patchVertices[6].Ny = 0.5f;
            patchVertices[6].Nz = 0;
            patchVertices[6].U = 0;
            patchVertices[6].V = 1;

            patchVertices[7].X = 0;
            patchVertices[7].Y = 500;
            patchVertices[7].Z = 500;
            patchVertices[7].Nx = 0;
            patchVertices[7].Ny = 0.5f;
            patchVertices[7].Nz = 0;
            patchVertices[7].U = 0.5f;
            patchVertices[7].V = 1;

            patchVertices[8].X = 500;
            patchVertices[8].Y = 200;
            patchVertices[8].Z = 800;
            patchVertices[8].Nx = 0.5f;
            patchVertices[8].Ny = 0.5f;
            patchVertices[8].Nz = 0;
            patchVertices[8].U = 1;
            patchVertices[8].V = 1;

            _patch = MeshManager.Instance.CreateBezierPatch("Bezier1", ResourceGroupManager.DefaultResourceGroupName, patchVertices, patchDeclaration, 3, 3, 5, 5, VisibleSide.Both, BufferUsage.StaticWriteOnly, BufferUsage.DynamicWriteOnly, true, true);
            _patch.Subdivision = 1.0f;

            _scene = _root.CreateSceneManager("DefaultSceneManager", "SLSharpInstance");
            _scene.ClearScene();

            _patchEntity = _scene.CreateEntity("Entity1", "Bezier1");
            _camera = _scene.CreateCamera("MainCamera");



            var mat = (Material)MaterialManager.Instance.Create("test", ResourceGroupManager.DefaultResourceGroupName);
            var pass = mat.GetTechnique(0).GetPass(0);
            pass.LightingEnabled = false;


            _patchEntity.MaterialName = mat.Name;

            _scene.RootSceneNode.AttachObject(_patchEntity);

            _camera.LookAt(Vector3.Zero);
            _camera.Near = 5;
            _camera.AutoAspectRatio = true;

            var vp = _root.AutoWindow.AddViewport(_camera, 0, 0, 1.0f, 1.0f, 100);
            vp.BackgroundColor = ColorEx.CornflowerBlue;

        }