Defines an instance of a discrete, movable object based on a Mesh.
Axiom generally divides renderable objects into 2 groups, discrete (separate) and relatively small objects which move around the world, and large, sprawling geometry which makes up generally immovable scenery, aka 'level geometry'.

The Mesh and SubMesh classes deal with the definition of the geometry used by discrete movable objects. Entities are actual instances of objects based on this geometry in the world. Therefore there is usually a single set Mesh for a car, but there may be multiple entities based on it in the world. Entities are able to override aspects of the Mesh it is defined by, such as changing material properties per instance (so you can have many cars using the same geometry but different textures for example). Because a Mesh is split into a list of SubMesh objects for this purpose, the Entity class is a grouping class (much like the Mesh class) and much of the detail regarding individual changes is kept in the SubEntity class. There is a 1:1 relationship between SubEntity instances and the SubMesh instances associated with the Mesh the Entity is based on.

Entity and SubEntity classes are never created directly. Use SceneManager.CreateEntity(string, string) (passing a model name) to create one.

Entities are included in the scene by using SceneNode.AttachObject to associate them with a scene node.

Inheritance: Axiom.Core.MovableObject
		/// <summary>
		/// 
		/// </summary>
		/// <param name="sceneMgr"></param>
		private void SetupBody( SceneManager sceneMgr )
		{
			// create main model
			bodyNode = sceneMgr.RootSceneNode.CreateChildSceneNode( Vector3.UnitY * CharHeight );
			bodyEnt = sceneMgr.CreateEntity( "SinbadBody", "Sinbad.mesh" );
			bodyNode.AttachObject( bodyEnt );

			// create swords and attach to sheath
			sword1 = sceneMgr.CreateEntity( "SinbadSword1", "Sword.mesh" );
			sword2 = sceneMgr.CreateEntity( "SinbadSword2", "Sword.mesh" );
			bodyEnt.AttachObjectToBone( "Sheath.L", sword1 );
			bodyEnt.AttachObjectToBone( "Sheath.R", sword2 );

			// create a couple of ribbon trails for the swords, just for fun
			NamedParameterList paras = new NamedParameterList();
			paras[ "numberOfChains" ] = "2";
			paras[ "maxElements" ] = "80";
			swordTrail = (RibbonTrail)sceneMgr.CreateMovableObject( "SinbadRibbon", "RibbonTrail", paras );
			swordTrail.MaterialName = "Examples/LightRibbonTrail";
			swordTrail.TrailLength = 20;
			swordTrail.IsVisible = false;
			sceneMgr.RootSceneNode.AttachObject( swordTrail );

			for ( int i = 0; i < 2; i++ )
			{
				swordTrail.SetInitialColor( i, new ColorEx( 1, 0.8f, 0 ) );
				swordTrail.SetColorChange( i, new ColorEx( 0.75f, 0.25f, 0.25f, 0.25f ) );
				swordTrail.SetWidthChange( i, 1 );
				swordTrail.SetInitialWidth( i, 0.5f );
			}

			keyDirection = Vector3.Zero;
			verticalVelocity = 0;

		}
Exemple #2
0
		protected override void SetupContent()
		{
			var blankTerrain = false;

			this.editMarker = SceneManager.CreateEntity( "editMarker", "sphere.mesh" );
			this.editNode = SceneManager.RootSceneNode.CreateChildSceneNode();
			this.editNode.AttachObject( this.editMarker );
			this.editNode.Scale = new Vector3( 0.05f, 0.05f, 0.05f );

			_setupControls();

			CameraManager.TopSpeed = 50;

			DragLook = true;

			MaterialManager.Instance.SetDefaultTextureFiltering( TextureFiltering.Anisotropic );
			MaterialManager.Instance.DefaultAnisotropy = 7;

			SceneManager.SetFog( FogMode.Linear, new ColorEx( 0.07f, 0.07f, 0.08f ), 0, 10000, 25000 );

			var lightDir = new Vector3( 0.55f, 0.3f, 0.75f );
			lightDir.Normalize();

			var l = SceneManager.CreateLight( "tsLight" );
			l.Type = LightType.Directional;
			l.Direction = lightDir;
			l.Diffuse = ColorEx.White;
			l.Specular = new ColorEx( 0.4f, 0.4f, 0.4f );

			SceneManager.AmbientLight = new ColorEx( 0.2f, 0.2f, 0.2f );

			this.terrainGroup = new TerrainGroup( SceneManager, Alignment.Align_X_Z, (ushort)TerrainSize, TerrainWorldSize );
			this.terrainGroup.SetFilenameConvention( TerrainFilePrefix, TerrainFileSuffix );
			this.terrainGroup.Origin = this.terrainPos;

			_configureTerrainDefaults( l );
#if PAGING
	// Paging setup
            pageManager = new PageManager();
            // Since we're not loading any pages from .page files, we need a way just 
            // to say we've loaded them without them actually being loaded
            pageManager.PageProvider = dummyPageProvider;
            pageManager.AddCamera( Camera );
            terrainPaging = new TerrainPaging( pageManager );
            PagedWorld world = pageManager.CreateWorld();
            terrainPaging.CreateWorldSection( world, terrainGroup, 2000, 3000,
                TerrainPageMinX, TerrainPageMinY,
                TerrainPageMaxX, TerrainPageMaxY );
#else
			for ( long x = TerrainPageMinX; x <= TerrainPageMaxX; ++x )
			{
				for ( long y = TerrainPageMinY; y <= TerrainPageMaxY; ++y )
				{
					_defineTerrain( x, y, blankTerrain );
				}
			}
			// sync load since we want everything in place when we start
			this.terrainGroup.LoadAllTerrains( true );
#endif

			if ( this.terrainsImported )
			{
				foreach ( var ts in this.terrainGroup.TerrainSlots )
				{
					_initBlendMaps( ts.Instance );
				}
			}

			this.terrainGroup.FreeTemporaryResources();

			var e = SceneManager.CreateEntity( "TudoMesh", "tudorhouse.mesh" );
			var entPos = new Vector3( this.terrainPos.x + 2043, 0, this.terrainPos.z + 1715 );
			var rot = new Quaternion();
			entPos.y = this.terrainGroup.GetHeightAtWorldPosition( entPos ) + 65.5 + this.terrainPos.y;
			rot = Quaternion.FromAngleAxis( Utility.RangeRandom( -180, 180 ), Vector3.UnitY );
			var sn = SceneManager.RootSceneNode.CreateChildSceneNode( entPos, rot );
			sn.Scale = new Vector3( 0.12, 0.12, 0.12 );
			sn.AttachObject( e );
			this.houseList.Add( e );

			e = SceneManager.CreateEntity( "TudoMesh1", "tudorhouse.mesh" );
			entPos = new Vector3( this.terrainPos.x + 1850, 0, this.terrainPos.z + 1478 );
			entPos.y = this.terrainGroup.GetHeightAtWorldPosition( entPos ) + 65.5 + this.terrainPos.y;
			rot = Quaternion.FromAngleAxis( Utility.RangeRandom( -180, 180 ), Vector3.UnitY );
			sn = SceneManager.RootSceneNode.CreateChildSceneNode( entPos, rot );
			sn.Scale = new Vector3( 0.12, 0.12, 0.12 );
			sn.AttachObject( e );
			this.houseList.Add( e );

			e = SceneManager.CreateEntity( "TudoMesh2", "tudorhouse.mesh" );
			entPos = new Vector3( this.terrainPos.x + 1970, 0, this.terrainPos.z + 2180 );
			entPos.y = this.terrainGroup.GetHeightAtWorldPosition( entPos ) + 65.5 + this.terrainPos.y;
			rot = Quaternion.FromAngleAxis( Utility.RangeRandom( -180, 180 ), Vector3.UnitY );
			sn = SceneManager.RootSceneNode.CreateChildSceneNode( entPos, rot );
			sn.Scale = new Vector3( 0.12, 0.12, 0.12 );
			sn.AttachObject( e );
			this.houseList.Add( e );

			//SceneManager.SetSkyDome( true, "Examples/CloudyNoonSkyBox", 5000, 8 );
			SceneManager.SetSkyDome( true, "Examples/CloudySky", 5000, 8 );
		}
		protected bool ExtractSkeletonData( Entity entity, out int boneCount, out int weightCount )
		{
			bool isValidData = false;
			boneCount = 0;
			weightCount = 0;

			//Check if we have pose animation which the HS sub render state does not
			//know how to handle
			bool hasVertexAnim = entity.Mesh.HasVertexAnimation;

			//gather data on the skeleton
			if ( !hasVertexAnim && entity.HasSkeleton )
			{
				//get weights count
				Mesh mesh = entity.Mesh;
				//              nb: OGRE source gets ..blendIndexToBoneIndexMap.Count, is this accurate?
				boneCount = mesh.BoneAssignmentList.Count;

				int totalMeshes = mesh.SubMeshCount;
				for ( int i = 0; i < totalMeshes; i++ )
				{
					var ro = new RenderOperation();
					SubMesh subMesh = mesh.GetSubMesh( i );
					subMesh.GetRenderOperation( ro, 0 );

					//get the largest bone assignment
					if ( boneCount > subMesh.BoneAssignmentList.Count )
					{
					}
					else
					{
						boneCount = subMesh.BoneAssignmentList.Count;
					}

					//go over vertex decleration
					//check that they have blend indices and blend weights
					VertexElement declWeights =
						ro.vertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.BlendWeights, 0 );
					VertexElement declIndexes =
						ro.vertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.BlendIndices, 0 );
					if ( ( declWeights != null ) && ( declIndexes != null ) )
					{
						isValidData = true;
						switch ( declWeights.Type )
						{
							case VertexElementType.Float1:
								weightCount = Axiom.Math.Utility.Clamp( weightCount, weightCount, 1 );
								break;
							case VertexElementType.Float2:
								weightCount = Axiom.Math.Utility.Clamp( weightCount, weightCount, 2 );
								break;
							case VertexElementType.Float3:
								weightCount = Axiom.Math.Utility.Clamp( weightCount, weightCount, 3 );
								break;
							case VertexElementType.Float4:
								weightCount = Axiom.Math.Utility.Clamp( weightCount, weightCount, 4 );
								break;
							default:
								isValidData = false;
								break;
						}
						if ( isValidData == false )
						{
							break;
						}
					}
				}
			}
			return isValidData;
		}
		public void PrepareEntityForSkinning( Entity entity, SkinningType skinningType, bool correctAntipodalityHandling,
		                                      bool shearScale )
		{
			if ( entity != null )
			{
				//TODO!
				int lodLevels = entity.MeshLodIndex + 1;
				for ( int indexLod = 0; indexLod < lodLevels; indexLod++ )
				{
					Entity curEntity = entity;
					if ( indexLod > 0 )
					{
						// curEntity = entity.GetManualLodLevel(indexLod - 1);
					}

					int boneCount = 0;
					int weightCount = 0;
					bool isValid = ExtractSkeletonData( curEntity, out boneCount, out weightCount );
					int numSubEntites = curEntity.SubEntityCount;
					for ( int indexSub = 0; indexSub < numSubEntites; indexSub++ )
					{
						SubEntity subEntity = curEntity.GetSubEntity( indexSub );
						Material mat = subEntity.Material;
						ImprintSkeletonData( mat, isValid, boneCount, weightCount, skinningType,
						                     correctAntipodalityHandling, shearScale );
					}
				}
			}
		}
		private void SetupInstancedMaterialToEntity( Entity ent )
		{
			for ( int i = 0; i < ent.SubEntityCount; ++i )
			{
				SubEntity se = ent.GetSubEntity( i );
				string materialName = se.MaterialName;
				se.MaterialName = BuildInstancedMaterial( materialName );
			}
		}
Exemple #6
0
        /// <summary>
        /// 
        /// </summary>
        protected void SetupScene()
        {
            // Set ambient light
            SceneManager.AmbientLight = new ColorEx( 0.3f, 0.3f, 0.3f );
            SceneManager.SetSkyBox( true, "SkyBox", 1000 );

            mainNode = SceneManager.RootSceneNode.CreateChildSceneNode();


            for ( int i = 0; i < NumLights; ++i )
            {
                lightPivots[ i ] = SceneManager.RootSceneNode.CreateChildSceneNode();
                lightPivots[ i ].Rotate( lightRotationAxes[ i ], lightRotationAngles[ i ] );
                // Create a light, use default parameters
                lights[ i ] = SceneManager.CreateLight( "Light" + i );
                lights[ i ].Position = lightPositions[ i ];
                lights[ i ].Diffuse = diffuseLightColors[ i ];
                lights[ i ].Specular = specularLightColors[ i ];
                lights[ i ].IsVisible = lightState[ i ];
                //lights[i]->setAttenuation(400, 0.1 , 1 , 0);
                // Attach light
                lightPivots[ i ].AttachObject( lights[ i ] );
                // Create billboard for light
                lightFlareSets[ i ] = SceneManager.CreateBillboardSet( "Flare" + i );
                lightFlareSets[ i ].MaterialName = "LightFlare";
                lightPivots[ i ].AttachObject( lightFlareSets[ i ] );
                lightFlares[ i ] = lightFlareSets[ i ].CreateBillboard( lightPositions[ i ] );
                lightFlares[ i ].Color = diffuseLightColors[ i ];
                lightFlareSets[ i ].IsVisible = lightState[ i ];
            }

            // move the camera a bit right and make it look at the knot
            Camera.MoveRelative( new Vector3( 50,0, 100 ) );
            Camera.LookAt( new Vector3( 0, 10, 0 ) );

            // Define a plane mesh that will be used for the ocean surface
            Plane oceanSurface = new Plane( Vector3.UnitY, 20 );

            MeshManager.Instance.CreatePlane( "OceanSurface",
                ResourceGroupManager.DefaultResourceGroupName,
                oceanSurface,
                1000, 1000, 50, 50, true, 1, 1, 1, Vector3.UnitZ );

            oceanSurfaceEnt = SceneManager.CreateEntity( "OceanSurface", "OceanSurface" );
            SceneManager.RootSceneNode.CreateChildSceneNode().AttachObject( oceanSurfaceEnt );
            oceanSurfaceEnt.MaterialName = materialControlsContainer[ 0 ].MaterialName;
        }