private void LoadMesh(string filename) { int lastBackslash = filename.LastIndexOf('\\'); string clippedFilename = filename.Substring(lastBackslash + 1); string srcDir = filename.Substring(0, lastBackslash + 1); SetAnimation(null); UpdateAnimationListBox(); if (boneDisplay != null) { boneDisplay.Close(); boneDisplay = null; } if (loadedModel != null) { // clean up the last model if we are loading a new one RemoveCollisionObjects(0); CleanupSockets(); CleanupBones(); CleanupNormalsRenderable(); Debug.Assert(attachedNodes.Count == 0); modelNode.DetachObject(loadedModel); sceneManager.RemoveEntity(loadedModel); } CleanupGroundPlaneRenderable(); Mesh mesh = ReadMesh(Matrix4.Identity, srcDir, clippedFilename); SetupPoseAnimation(mesh); // // Create the list of triangles used to query mouse hits // mesh.CreateTriangleIntersector(); loadedMesh = mesh; loadedModel = sceneManager.CreateEntity("model", mesh); Text = "ModelViewer: " + filename; // move the camera focus to the middle of the new model ModelHeight = loadedModel.BoundingBox.Maximum.y - loadedModel.BoundingBox.Minimum.y; if (CameraRadius < loadedModel.BoundingRadius) { CameraRadius = loadedModel.BoundingRadius; } PositionCamera(); modelNode.AttachObject(loadedModel); AddCollisionObject(loadedModel, modelNode, 0, Path.GetFileNameWithoutExtension(clippedFilename) + ".physics"); //modelNode.DetachObject(loadedModel); loadedModel.ShowBoundingBox = showBoundingBox; if (loadedModel.Mesh != null && loadedModel.Mesh.ContainsAnimation("manual")) { AnimationState manualAnimState = loadedModel.GetAnimationState("manual"); manualAnimState.Time = 0; manualAnimState.IsEnabled = true; } PopulateSubMeshListBox(); PopulateAnimationListBox(); PopulateSocketListBox(); PopulateBonesListBox(); // disable the fields parentBoneLabel.Visible = false; parentBoneValueLabel.Text = ""; parentBoneValueLabel.Visible = false; }
private void displayBoneInformationToolStripMenuItem_Click(object sender, EventArgs e) { //if (currentAnimation != null) { // StringBuilder message = new StringBuilder(); // message.Append(string.Format("Animation at {0:g}: {1}\n", currentAnimation.Time, currentAnimation.Name)); // Bone b = loadedModel.Skeleton.RootBone; // DumpBones(message, b, 0); // Trace.TraceInformation(message.ToString()); // // currentAnimation. // // MessageBox.Show(message.ToString()); //} if (loadedModel != null && loadedModel.Skeleton != null) { if (boneDisplay == null) boneDisplay = new BoneDisplay(this); boneDisplay.SetSkeleton(loadedModel.Skeleton); boneDisplay.Show(); boneDisplay.UpdateFields(); } else { MessageBox.Show("A model with a skeleton must be loaded in order to display bones"); } }