public void SetSkeleton(SkeletonInstance skel)
        {
            Bone bone = skel.RootBone;
            TreeNode node = new TreeNode();
            node.Name = bone.Name;
            node.Text = bone.Name;
            boneTreeView.Nodes.Add(node);
            AddChildBones(node, bone);

            skeleton = skel;
            string skeletonName = skel.MasterSkeleton.Name;
            helperSkeleton = SkeletonManager.Instance.Load(skeletonName);
        }
Exemplo n.º 2
0
		protected void SetMesh( Mesh mesh )
		{
			this.mesh = mesh;

			if ( mesh.HasSkeleton && mesh.Skeleton != null )
			{
				this.skeletonInstance = new SkeletonInstance( mesh.Skeleton );
				this.skeletonInstance.Load();
			}
			else
			{
				this.skeletonInstance = null;
			}

			this.subEntityList.Clear();
			BuildSubEntities();

			this.lodEntityList.Clear();
			// Check if mesh is using manual LOD
			if ( mesh.IsLodManual )
			{
				for ( var i = 1; i < mesh.LodLevelCount; i++ )
				{
					var usage = mesh.GetLodLevel( i );

					// manually create entity
					var lodEnt = new Entity( string.Format( "{0}Lod{1}", name, i ), usage.ManualMesh );
					this.lodEntityList.Add( lodEnt );
				}
			}

			this.animationState.RemoveAllAnimationStates();
			// init the AnimationState, if the mesh is animated
			if ( HasSkeleton )
			{
				this.numBoneMatrices = this.skeletonInstance.BoneCount;
				this.boneMatrices = new Matrix4[this.numBoneMatrices];
			}
			if ( HasSkeleton || mesh.HasVertexAnimation )
			{
				mesh.InitAnimationState( this.animationState );
				PrepareTempBlendedBuffers();
			}

			ReevaluateVertexProcessing();

			// LOD default settings
			this.meshLodFactorTransformed = 1.0f;
			// Backwards, remember low value = high detail
			this.minMeshLodIndex = 99;
			this.maxMeshLodIndex = 0;

			// Material LOD default settings
			this.materialLodFactor = 1.0f;
			this.maxMaterialLodIndex = 0;
			this.minMaterialLodIndex = 99;

			// Do we have a mesh where edge lists are not going to be available?
			//if ( ( ( this.sceneMgr.ShadowTechnique == ShadowTechnique.StencilAdditive )
			//       || ( this.sceneMgr.ShadowTechnique == ShadowTechnique.StencilModulative ) ) &&
			//     !mesh.IsEdgeListBuilt && !mesh.AutoBuildEdgeLists )
			//{
			//    this.CastShadows = false;
			//}
		}
Exemplo n.º 3
0
		protected override void dispose( bool disposeManagedResources )
		{
			if ( !IsDisposed )
			{
				if ( disposeManagedResources )
				{
					// Dispose managed resources.
					if ( this.skeletonInstance != null )
					{
						if ( !this.skeletonInstance.IsDisposed )
						{
							this.skeletonInstance.Dispose();
						}

						this.skeletonInstance = 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 );
		}
Exemplo n.º 4
0
		public void StopSharingSkeletonInstance()
		{
			if ( this.sharedSkeletonInstances == null )
			{
				throw new AxiomException( "This entity is not sharing it's skeletoninstance." );
			}

			// Are we the last to stop sharing?
			if ( this.sharedSkeletonInstances.Count == 1 )
			{
				this.sharedSkeletonInstances = null;
			}
			else
			{
				this.skeletonInstance = new SkeletonInstance( this.mesh.Skeleton );
				this.skeletonInstance.Load();
				this.animationState = new AnimationStateSet();
				this.mesh.InitAnimationState( this.animationState );
				this.frameBonesLastUpdated = new ulong[ulong.MaxValue];
				this.numBoneMatrices = this.skeletonInstance.BoneCount;
				this.boneMatrices = new Matrix4[this.numBoneMatrices];

				this.sharedSkeletonInstances.Remove( this );
				if ( this.sharedSkeletonInstances.Count == 1 )
				{
					this.sharedSkeletonInstances[ 0 ].StopSharingSkeletonInstance();
				}
				this.sharedSkeletonInstances = null;
			}
		}
Exemplo n.º 5
0
		public void ShareSkeletonInstanceWith( Entity entity )
		{
			if ( entity.Mesh.Skeleton != Mesh.Skeleton )
			{
				throw new AxiomException( "The supplied entity has a different skeleton." );
			}
			if ( this.skeletonInstance == null )
			{
				throw new AxiomException( "This entity has no skeleton." );
			}
			if ( this.sharedSkeletonInstances != null && entity.sharedSkeletonInstances != null )
			{
				throw new AxiomException(
					"Both entities already share their SkeletonInstances! At least one of the instances must not share it's instance." );
			}

			//check if we already share our skeletoninstance, we don't want to delete it if so
			if ( this.sharedSkeletonInstances != null )
			{
				entity.ShareSkeletonInstanceWith( this );
			}
			else
			{
				// Clear current skeleton
				this.skeletonInstance.Dispose();
				this.skeletonInstance = null;
				this.animationState = null;
				this.frameBonesLastUpdated = null;

				//copy Skeleton from sharer
				this.skeletonInstance = entity.skeletonInstance;
				this.animationState = entity.animationState;
				this.frameBonesLastUpdated = entity.frameBonesLastUpdated;

				// notify of shareing
				if ( entity.sharedSkeletonInstances == null )
				{
					entity.sharedSkeletonInstances = new EntityList();
					entity.sharedSkeletonInstances.Add( entity );
				}
				this.sharedSkeletonInstances = entity.sharedSkeletonInstances;
				this.sharedSkeletonInstances.Add( this );
			}
		}
Exemplo n.º 6
0
		///<summary>
		///  Adds an Entity to the static geometry.
		///  <remarks>
		///    This method takes an existing Entity and adds its details to the list of elements to include when building. Note that the Entity itself is not copied or referenced in this method; an Entity is passed simply so that you can change the materials of attached SubEntity objects if you want. You can add the same Entity instance multiple times with different material settings completely safely, and destroy the Entity before destroying this InstancedGeometry if you like. The Entity passed in is simply Must be called before 'Build'.
		///  </remarks>
		///</summary>
		///<param name="ent"> The Entity to use as a definition (the Mesh and Materials referenced will be recorded for the build call). </param>
		///<param name="position"> The world position at which to add this Entity </param>
		///<param name="orientation"> The world orientation at which to add this Entity </param>
		///<param name="scale"> </param>
		public virtual void AddEntity( Entity ent, Vector3 position, Quaternion orientation, Vector3 scale )
		{
			Mesh msh = ent.Mesh;

			// Validate
			if ( msh.IsLodManual )
			{
				LogManager.Instance.Write(
					"(InstancedGeometry): Manual LOD is not supported. Using only highest LOD level for mesh " + msh.Name );
			}

			//get the skeleton of the entity, if that's not already done
			if ( ent.Mesh.Skeleton != null && mBaseSkeleton == null )
			{
				mBaseSkeleton = ent.Mesh.Skeleton;
				mSkeletonInstance = new SkeletonInstance( mBaseSkeleton );
				mSkeletonInstance.Load();
				mAnimationState = ent.GetAllAnimationStates();
			}

			BoundingBox sharedWorldBounds;
			// queue this entities submeshes and choice of material
			// also build the lists of geometry to be used for the source of lods


			for ( int i = 0; i < ent.SubEntityCount; ++i )
			{
				SubEntity se = ent.GetSubEntity( i );
				var q = new QueuedSubMesh();

				// Get the geometry for this SubMesh
				q.submesh = se.SubMesh;
				q.geometryLodList = DetermineGeometry( q.submesh );
				q.materialName = se.MaterialName;
				q.orientation = orientation;
				q.position = position;
				q.scale = scale;
				q.ID = mObjectCount;
			}

			mObjectCount++;
		}
Exemplo n.º 7
0
		public InstancedGeometry( SceneManager owner, String name )
		{
			mOwner = owner;
			mName = name;
			mBuilt = false;
			mUpperDistance = 0.0f;
			mSquaredUpperDistance = 0.0f;
			mCastShadows = false;
			mBatchInstanceDimensions = new Vector3( 1000, 1000, 1000 );
			mHalfBatchInstanceDimensions = new Vector3( 500, 500, 500 );
			mOrigin = new Vector3( 0, 0, 0 );
			mVisible = true;
			mRenderQueueID = (byte)RenderQueueGroupID.Main;
			mRenderQueueIDSet = false;
			mObjectCount = 0;
			mInstancedGeometryInstance = null;
			mSkeletonInstance = null;
			mBaseSkeleton = null;
		}