/// <summary> /// Clones this instance. /// </summary> /// <returns>The cloned animated model data.</returns> public InternalSkinnedModel Clone() { var newModel = new InternalSkinnedModel(); newModel.graphics = this.graphics; newModel.BoundingBox = this.BoundingBox; for (int i = 0; i < this.Meshes.Count; i++) { SkinnedMesh currentMesh = this.Meshes[i]; SkinnedVertexBuffer currentBuffer = currentMesh.VertexBuffer as SkinnedVertexBuffer; var newVertices = new SkinnedVertex[currentMesh.NumVertices]; Array.Copy(currentBuffer.CpuVertices, newVertices, currentBuffer.CpuVertices.Length); var newBuffer = new SkinnedVertexBuffer(currentBuffer.VertexBufferFormat); newBuffer.SetData(newVertices, currentBuffer.VertexCount); var newIndexBuffer = new IndexBuffer(this.internalindices[i]); var newMesh = new SkinnedMesh( currentMesh.VertexOffset, currentMesh.NumVertices, currentMesh.IndexOffset, currentMesh.NumPrimitives, newBuffer, newIndexBuffer, PrimitiveType.TriangleList); newMesh.Name = currentMesh.Name; newModel.Meshes.Add(newMesh); this.graphics.BindIndexBuffer(newModel.Meshes[i].IndexBuffer); this.graphics.BindVertexBuffer(newModel.Meshes[i].VertexBuffer); } return(newModel); }
/// <summary> /// Reload the static model /// </summary> protected override void UnloadModel() { if (this.InternalModel != null && !string.IsNullOrEmpty(this.InternalModel.AssetPath)) { this.Assets.UnloadAsset(this.InternalModel.AssetPath); this.BoundingBox = new BoundingBox(); this.InternalModel = null; } }
/// <summary> /// Performs further custom initialization for this instance. /// </summary> protected override void Initialize() { base.Initialize(); this.boneTransforms = new Matrix[this.Animation.InternalAnimation.BindPose.Count]; this.worldTransforms = new Matrix[this.Animation.InternalAnimation.BindPose.Count]; this.skinTransforms = new Matrix[this.Animation.InternalAnimation.BindPose.Count]; this.skinnedModel = this.Model.InternalModel.Clone(); }
/// <summary> /// Reload the static model /// </summary> protected override void LoadModel() { if (!string.IsNullOrEmpty(this.ModelPath)) { this.InternalModel = Assets.LoadAsset <InternalSkinnedModel>(this.ModelPath); if (!this.customBoundingBoxSet) { this.BoundingBox = this.InternalModel.BoundingBox; } } }
/// <summary> /// Releases unmanaged and - optionally - managed resources /// </summary> /// <param name="disposing"> /// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources. /// </param> protected override void Dispose(bool disposing) { if (!this.disposed) { if (disposing) { if (this.skinnedModel != null) { this.skinnedModel.Unload(); this.skinnedModel = null; } this.disposed = true; } } }
/// <summary> /// Refresh the model references /// </summary> private void RefreshModel() { if (this.skinnedModel == null || (this.skinnedModel.AssetPath != this.Model.ModelPath)) { if (this.skinnedModel != null) { this.skinnedModel.Unload(); this.skinnedModel = null; } if (this.Model.InternalModel != null) { this.skinnedModel = this.Model.InternalModel.Clone(); Array.Resize(ref this.meshMaterials, this.skinnedModel.Meshes.Count); Array.Resize(ref this.updateVertexBuffer, this.skinnedModel.Meshes.Count); } this.boneNames.Clear(); } }
/// <summary> /// Performs further custom initialization for this instance. /// </summary> protected override void Initialize() { this.InternalModel = Assets.LoadAsset <InternalSkinnedModel>(this.ModelPath); this.BoundingBox = this.InternalModel.BoundingBox; }