Utility class which defines the sub-parts of an Entity.

Just as models are split into meshes, an Entity is made up of potentially multiple SubEntities. These are mainly here to provide the link between the Material which the SubEntity uses (which may be the default Material for the SubMesh or may have been changed for this object) and the SubMesh data.

SubEntity instances are never created manually. They are created at the same time as their parent Entity by the SceneManager method CreateEntity.

Inheritance: DisposableObject, IRenderable
Exemple #1
0
		/// <summary>
		///		Used to build a list of sub-entities from the meshes located in the mesh.
		/// </summary>
		protected void BuildSubEntities()
		{
			// loop through the models meshes and create sub entities from them
			for ( var i = 0; i < this.mesh.SubMeshCount; i++ )
			{
				var subMesh = this.mesh.GetSubMesh( i );
				var sub = new SubEntity();
				sub.Parent = this;
				sub.SubMesh = subMesh;

				if ( subMesh.IsMaterialInitialized )
				{
					sub.MaterialName = subMesh.MaterialName;
				}

				this.subEntityList.Add( sub );
			}
		}
Exemple #2
0
			public EntityShadowRenderable( Entity parent, HardwareIndexBuffer indexBuffer, VertexData vertexData,
			                               bool createSeparateLightCap, SubEntity subEntity, bool isLightCap )
			{
				this.parent = parent;

				// Save link to vertex data
				this.currentVertexData = vertexData;

				// Initialize render op
				renderOperation.indexData = new IndexData();
				renderOperation.indexData.indexBuffer = indexBuffer;
				renderOperation.indexData.indexStart = 0;
				// index start and count are sorted out later

				// Create vertex data which just references position component (and 2 component)
				renderOperation.vertexData = new VertexData();
				renderOperation.vertexData.vertexDeclaration = HardwareBufferManager.Instance.CreateVertexDeclaration();
				renderOperation.vertexData.vertexBufferBinding = HardwareBufferManager.Instance.CreateVertexBufferBinding();

				// Map in position data
				renderOperation.vertexData.vertexDeclaration.AddElement( 0, 0, VertexElementType.Float3,
				                                                         VertexElementSemantic.Position );
				this.originalPosBufferBinding =
					vertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.Position ).Source;

				this.positionBuffer = vertexData.vertexBufferBinding.GetBuffer( this.originalPosBufferBinding );
				renderOperation.vertexData.vertexBufferBinding.SetBinding( 0, this.positionBuffer );

				// Map in w-coord buffer (if present)
				if ( vertexData.hardwareShadowVolWBuffer != null )
				{
					renderOperation.vertexData.vertexDeclaration.AddElement( 1, 0, VertexElementType.Float1,
					                                                         VertexElementSemantic.TexCoords, 0 );
					this.wBuffer = vertexData.hardwareShadowVolWBuffer;
					renderOperation.vertexData.vertexBufferBinding.SetBinding( 1, this.wBuffer );
				}

				// Use same vertex start as input
				renderOperation.vertexData.vertexStart = vertexData.vertexStart;

				if ( isLightCap )
				{
					// Use original vertex count, no extrusion
					renderOperation.vertexData.vertexCount = vertexData.vertexCount;
				}
				else
				{
					// Vertex count must take into account the doubling of the buffer,
					// because second half of the buffer is the extruded copy
					renderOperation.vertexData.vertexCount = vertexData.vertexCount*2;

					if ( createSeparateLightCap )
					{
						// Create child light cap
						lightCap = new EntityShadowRenderable( parent, indexBuffer, vertexData, false, subEntity, true );
					}
				}
			}
Exemple #3
0
			/// <summary>
			/// 
			/// </summary>
			/// <param name="disposeManagedResources"></param>
			protected override void dispose( bool disposeManagedResources )
			{
				if ( !IsDisposed )
				{
					if ( disposeManagedResources )
					{
						// Dispose managed resources.
						if ( lightCap != null )
						{
							if ( !lightCap.IsDisposed )
							{
								lightCap.Dispose();
							}

							lightCap = null;
						}

						if ( this.wBuffer != null )
						{
							if ( !this.wBuffer.IsDisposed )
							{
								this.wBuffer.Dispose();
							}

							this.wBuffer = null;
						}

						if ( this.positionBuffer != null )
						{
							if ( !this.positionBuffer.IsDisposed )
							{
								this.positionBuffer.Dispose();
							}

							this.positionBuffer = null;
						}

						if ( this.subEntity != null )
						{
							if ( !this.subEntity.IsDisposed )
							{
								this.subEntity.Dispose();
							}

							this.subEntity = null;
						}

						if ( this.currentVertexData != null )
						{
							if ( !this.currentVertexData.IsDisposed )
							{
								this.currentVertexData.Dispose();
							}

							this.currentVertexData = null;
						}
					}

					// There are no unmanaged resources to release, but
					// if we add them, they need to be released here.
				}

				// If it is available, make the call to the
				// base class's Dispose(Boolean) method
				base.dispose( disposeManagedResources );
			}
Exemple #4
0
			public EntityShadowRenderable( Entity parent, HardwareIndexBuffer indexBuffer, VertexData vertexData,
			                               bool createSeperateLightCap, SubEntity subEntity )
				: this( parent, indexBuffer, vertexData, createSeperateLightCap, subEntity, false )
			{
			}