Axiom.Core.Entity.AttachObjectToBone C# (CSharp) Method

AttachObjectToBone() public method

Attaches another object to a certain bone of the skeleton which this entity uses.
public AttachObjectToBone ( string boneName, Axiom.Core.MovableObject sceneObject, Quaternion offsetOrientation, Vector3 offsetPosition ) : Axiom.Animating.TagPoint
boneName string The name of the bone (in the skeleton) to attach this object.
sceneObject Axiom.Core.MovableObject Reference to the object to attach.
offsetOrientation Axiom.Math.Quaternion An adjustment to the orientation of the attached object, relative to the bone.
offsetPosition Vector3 An adjustment to the position of the attached object, relative to the bone.
return Axiom.Animating.TagPoint
		public TagPoint AttachObjectToBone( string boneName,
											MovableObject sceneObject,
											Quaternion offsetOrientation,
											Vector3 offsetPosition )
		{
			if ( this.childObjectList.ContainsKey( sceneObject.Name ) )
			{
				throw new AxiomException( "An object with the name {0} is already attached.", sceneObject.Name );
			}

			if ( sceneObject.IsAttached )
			{
				throw new AxiomException( "MovableObject '{0}' is already attached to '{1}'",
										  sceneObject.Name,
										  sceneObject.ParentNode.Name );
			}

			if ( !this.HasSkeleton )
			{
				throw new AxiomException( "Entity '{0}' has no skeleton to attach an object to.", this.name );
			}

			Bone bone = this.skeletonInstance.GetBone( boneName );
			if ( bone == null )
			{
				throw new AxiomException( "Entity '{0}' does not have a skeleton with a bone named '{1}'.",
										  this.name,
										  boneName );
			}

			TagPoint tagPoint = this.skeletonInstance.CreateTagPointOnBone( bone, offsetOrientation, offsetPosition );

			tagPoint.ParentEntity = this;
			tagPoint.ChildObject = sceneObject;

			this.AttachObjectImpl( sceneObject, tagPoint );

			// Trigger update of bounding box if necessary
			if ( this.parentNode != null )
			{
				this.parentNode.NeedUpdate();
			}

			return tagPoint;
		}

Same methods

Entity::AttachObjectToBone ( string boneName, Axiom.Core.MovableObject sceneObject ) : Axiom.Animating.TagPoint
Entity::AttachObjectToBone ( string boneName, Axiom.Core.MovableObject sceneObject, Quaternion offsetOrientation ) : Axiom.Animating.TagPoint

Usage Example

		/// <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;

		}