Пример #1
0
		/// <summary>
		/// User wants to add normals to the mesh
		/// </summary>
		private void buttonAddNormals_Click(object sender, EventArgs e)
		{
			AutoMesh mesh = mMesh.Clone(d3dModel, MeshFlags.Managed, 
										mMesh.M.VertexFormat | VertexFormats.Normal,
										Format.A8R8G8B8, Usage.AutoGenerateMipMap, Pool.Managed);
			mesh.M.ComputeNormals();
			mMesh.Dispose();
			mMesh = mesh;
			
			DisplayMeshInfo();
		}
Пример #2
0
		/// <summary>
		/// Setup the form by loading the mesh
		/// </summary>
		private void FormViewMesh_Shown(object sender, EventArgs e)
		{
			// ToDo: Show a message form while loading			
			AutoMesh autoMesh = null;

			// Load the mesh (or fail and exit)
			try
			{
				autoMesh = AutoMesh.LoadFromXFile(mFileName, MeshFlags.SystemMemory, d3dModel);									
			}
			catch 
			{
				// Dispose whatever we have
				try { autoMesh.Dispose(); } catch { }
				autoMesh = null;
				
				MessageBox.Show(this, "Error loading mesh");
				Hide();
				return;
			}
			
			// Detect unsupported texture formats
			VertexFormats format = autoMesh.M.VertexFormat;
			if ( (format & VertexFormats.TextureCountMask) != VertexFormats.Texture0
					&& (format & VertexFormats.Texture1) != VertexFormats.Texture1 )
			{
				MessageBox.Show(this, "Multiple textures not supported");
				autoMesh.Dispose();
				Hide();
				return;
			}

			// Unsupported vertex formats
			VertexFormats unsupported = VertexFormats.Specular
										| VertexFormats.LastBetaD3DColor
										| VertexFormats.LastBetaUByte4
										| VertexFormats.PointSize
										| VertexFormats.Transformed;
			if ( (int)(format & unsupported) != 0)
			{
				MessageBox.Show(this, "Unsupported vertex format");
				autoMesh.Dispose();
				Hide();
				return;
			}
			
			// No position (sometimes this happens)
			if ( (format & VertexFormats.Position) != VertexFormats.Position )
			{
				MessageBox.Show(this, "Unsupported vertex format (no position detected!)");
				autoMesh.Dispose();
				Hide();
				return;
			}
			
			// Clone to new format, using 32 bit pixel format.
			try
			{
				mMesh = autoMesh.Clone(d3dModel, MeshFlags.Managed, autoMesh.M.VertexFormat,
										Format.A8R8G8B8, Usage.AutoGenerateMipMap, Pool.Managed);
			}
			catch
			{
				MessageBox.Show(this, "Error cloning mesh");
				try { autoMesh.Dispose(); } catch  { }
				try { mMesh.Dispose(); } catch { }
				Hide();
				return;
			}
			
			autoMesh.Dispose();
			autoMesh = null;
			
			// Display mesh info
			DisplayMeshInfo();						
		}