private void selectAnimationToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { node.DebugDataVisible = DebugSceneType.Off; SkinnedMesh sm = helper.applyAnimation(e.ClickedItem.Text, meshToAnimate); if (sm != null) { modelPosition = new Vector3Df(0.0f); modelAngle = new Vector3Df(0.0f); node.Mesh = sm; resetDebugViewMenu(); setMaterialsSettings(node); activeAnim = e.ClickedItem.Text; } }
private void backgroundRendering_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; DeviceSettings settings = e.Argument as DeviceSettings; // create irrlicht device using provided settings IrrlichtDevice dev = IrrlichtDevice.CreateDevice(settings); if (dev == null) { throw new Exception("Failed to create Irrlicht device."); } dev.Logger.LogLevel = LogLevel.Warning; VideoDriver drv = dev.VideoDriver; SceneManager smgr = dev.SceneManager; smgr.FileSystem.AddFileArchive("E:/WitcherMods/modTest/Test/files/Mod/Bundle"); smgr.FileSystem.AddFileArchive("E:/WitcherMods/modTest/Test/files/Raw/Mod/TextureCache"); smgr.Attributes.AddValue("TW_TW3_LOAD_SKEL", true); smgr.Attributes.AddValue("TW_TW3_LOAD_BEST_LOD_ONLY", true); // setup a simple 3d scene //CameraSceneNode cam = smgr.AddCameraSceneNode(); //cam.Target = new Vector3Df(0); // added by vl AnimatedMesh mesh = smgr.GetMesh("E:/WitcherMods/modTest/Test/files/Mod/Bundle/characters/models/animals/cat/model/t_01__cat.w2mesh"); if (mesh == null) { throw new Exception("Failed to load mesh."); } smgr.MeshManipulator.RecalculateNormals(mesh); List <String> animList = null; float scaleMul = 1.0f; AnimatedMeshSceneNode node = smgr.AddAnimatedMeshSceneNode(mesh); MeshLoaderHelper helper = smgr.GetMeshLoader(smgr.MeshLoaderCount - 1).getMeshLoaderHelper(); if (node != null) { scaleMul = node.BoundingBox.Radius / 4; node.Scale = new Vector3Df(3.0f); node.SetMaterialFlag(MaterialFlag.Lighting, false); SkinnedMesh sm = helper.loadRig("E:/WitcherMods/modTest/Test/files/Mod/Bundle/characters/base_entities/cat_base/cat_base.w2rig", mesh); if (sm == null) { throw new Exception("Failed to load rig."); } animList = helper.loadAnimation("E:/WitcherMods/modTest/Test/files/Mod/Bundle/animations/animals/cat/cat_animation.w2anims", sm); if (animList.Count > 0) { AnimatedMesh am = helper.applyAnimation(animList[0], sm); node.Mesh = am; } //scaleSkeleton(sm, 3.0f); //sm.SkinMesh(); mesh.Drop(); sm.Drop(); setMaterialsSettings(node); /* * animList = helper.loadAnimation("E:/WitcherMods/modTest/Test/files/Mod/Bundle/animations/animals/cat/cat_animation.w2anims", node); * if (animList.Count > 0) * { * helper.applyAnimation(animList[0]); * } */ } var camera = smgr.AddCameraSceneNode(null, new Vector3Df(node.BoundingBox.Radius * 8, node.BoundingBox.Radius, 0), new Vector3Df(0, node.BoundingBox.Radius, 0) ); camera.NearValue = 0.001f; camera.FOV = 45.0f * 3.14f / 180.0f; node.DebugDataVisible ^= DebugSceneType.BBox | DebugSceneType.Skeleton; node.Position = new Vector3Df(0.0f); /* * SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 15, 0), 30.0f); * cam.AddAnimator(anim); * anim.Drop(); * * SceneNode cube = smgr.AddCubeSceneNode(20); * cube.SetMaterialTexture(0, drv.GetTexture("../../media/wall.bmp")); * cube.SetMaterialTexture(1, drv.GetTexture("../../media/water.jpg")); * cube.SetMaterialFlag(MaterialFlag.Lighting, false); * cube.SetMaterialType(MaterialType.Reflection2Layer); */ if (settings.BackColor == null) { smgr.AddSkyBoxSceneNode( "../../media/irrlicht2_up.jpg", "../../media/irrlicht2_dn.jpg", "../../media/irrlicht2_lf.jpg", "../../media/irrlicht2_rt.jpg", "../../media/irrlicht2_ft.jpg", "../../media/irrlicht2_bk.jpg"); } dev.GUIEnvironment.AddImage( drv.GetTexture("../../media/lime_logo_alpha.png"), new Vector2Di(30, 0)); // draw all int lastFPS = -1; while (dev.Run()) { if (settings.BackColor == null) { // indeed, we do not need to spend time on cleaning color buffer if we use skybox drv.BeginScene(ClearBufferFlag.Depth); } else { drv.BeginScene(ClearBufferFlag.Depth | ClearBufferFlag.Color, settings.BackColor); } smgr.DrawAll(); dev.GUIEnvironment.DrawAll(); drv.EndScene(); int fps = drv.FPS; if (lastFPS != fps) { // report progress using common BackgroundWorker' method // note: we cannot do just labelRenderingStatus.Text = "...", // because we are running another thread worker.ReportProgress(fps, drv.Name); lastFPS = fps; } // if we requested to stop, we close the device if (worker.CancellationPending) { dev.Close(); } } // drop device dev.Drop(); }