private void initScene() { SceneManager smgr = device.SceneManager; AnimatedMesh m = smgr.AddHillPlaneMesh("plane", new Dimension2Df(16), new Dimension2Di(16), null, 8); sceneNodePainter = smgr.AddAnimatedMeshSceneNode(m); sceneNodePainter.Scale = new Vector3Df(0.4f); sceneNodePainter.SetMaterialTexture(0, texture); sceneNodePainter.SetMaterialFlag(MaterialFlag.Lighting, false); SceneNodeAnimator a = smgr.CreateRotationAnimator(new Vector3Df(0, 0.1f, 0)); sceneNodePainter.AddAnimator(a); a.Drop(); sceneNodeRTT = smgr.AddWaterSurfaceSceneNode(m.GetMesh(0), 2, 100, 20); sceneNodeRTT.SetMaterialFlag(MaterialFlag.Lighting, false); sceneNodeRTT.SetMaterialType(MaterialType.Solid); sceneNodeRTT.Scale = new Vector3Df(0.2f); sceneNodeRTT.Position = new Vector3Df(60, 10, 40); sceneNodeRTT.Rotation = new Vector3Df(-30, 20, 0); textureRTT = smgr.VideoDriver.AddRenderTargetTexture(new Dimension2Di(512)); sceneNodeRTT.SetMaterialTexture(0, textureRTT); smgr.AddCameraSceneNode(null, new Vector3Df(0, 40, -60), new Vector3Df(0, -15, 0)); }
static void Main(string[] args) { device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(1024, 600)); device.SetWindowCaption("LightningShots - Irrlicht Engine"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh mesh = smgr.GetMesh("20kdm2.bsp"); MeshSceneNode node = smgr.AddMeshSceneNode(mesh.GetMesh(0)); node.Position = new Vector3Df(-1300, -144, -1249); node.SetMaterialType(MaterialType.LightMapLightingM4); node.SetMaterialFlag(MaterialFlag.Lighting, true); node.TriangleSelector = smgr.CreateTriangleSelector(node.Mesh, node); node.TriangleSelector.Drop(); smgr.AmbientLight = new Colorf(0.15f, 0.14f, 0.13f); CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(); lightningShot = new LightningShot(smgr, node.TriangleSelector); device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); device.CursorControl.Visible = false; while (device.Run()) { driver.BeginScene(true, true, new Color(100, 80, 75)); smgr.DrawAll(); lightningShot.Draw(device.Timer.Time); GUIFont f = device.GUIEnvironment.BuiltInFont; f.Draw("Use [LMB] to shoot", 10, 10, Color.OpaqueYellow); f.Draw("Total lightnings: " + lightningShot.TotalLightnings, 10, 20, Color.OpaqueWhite); f.Draw("Total shots: " + lightningShot.TotalShots, 10, 30, Color.OpaqueWhite); f.Draw(driver.FPS + " fps", 10, 40, Color.OpaqueWhite); driver.EndScene(); } lightningShot.Drop(); device.Drop(); }
void Start() { input = GetComponent <MarioInput>(); status = GetComponent <MarioStatus>(); sound = GetComponent <MarioSound>(); controller = GetComponent <SuperCharacterController>(); anim = AnimatedMesh.GetComponent <Animation>(); transparencyShaderSwapper = AnimatedMesh.GetComponent <ShaderSwapper>(); goldMaterialSwapper = AnimatedMesh.GetComponent <MaterialSwapper>(); transparencyFade = AnimatedMesh.GetComponent <TransparencyFade>(); RunSmokeEffect.enableEmission = false; anim["run_redux"].speed = 1.7f; lookDirection = Quaternion.AngleAxis(InitialRotation, controller.up) * Vector3.forward; artUpDirection = controller.up; currentState = MarioStates.EnterLevel; }
static void Main() { IrrlichtDevice device = IrrlichtDevice.CreateDevice( DriverType.Software, new Dimension2Di(640, 480), 16, false, false, false); device.SetWindowCaption("Hello World! - Irrlicht Engine Demo"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; gui.AddStaticText("Hello World! This is the Irrlicht Software renderer!", new Recti(10, 10, 260, 22), true); AnimatedMesh mesh = smgr.GetMesh("../../media/sydney.md2"); AnimatedMeshSceneNode node = smgr.AddAnimatedMeshSceneNode(mesh); if (node != null) { node.SetMaterialFlag(MaterialFlag.Lighting, false); node.SetMD2Animation(AnimationTypeMD2.Stand); node.SetMaterialTexture(0, driver.GetTexture("../../media/sydney.bmp")); } smgr.AddCameraSceneNode(null, new Vector3Df(0, 30, -40), new Vector3Df(0, 5, 0)); while (device.Run()) { driver.BeginScene(ClearBufferFlag.All, new Color(100, 101, 140)); smgr.DrawAll(); gui.DrawAll(); driver.EndScene(); } device.Drop(); }
static void Main(string[] args) { DriverType driverType; Console.Write("Please select the driver you want for this example:\n" + " (a) OpenGL\n (b) Direct3D 9.0c\n (c) Direct3D 8.1\n" + " (d) Burning's Software Renderer\n (e) Software Renderer\n" + " (f) NullDevice\n (otherKey) exit\n\n"); ConsoleKeyInfo i = Console.ReadKey(); switch (i.Key) { case ConsoleKey.A: driverType = DriverType.OpenGL; break; case ConsoleKey.B: driverType = DriverType.Direct3D9; break; case ConsoleKey.C: driverType = DriverType.Direct3D8; break; case ConsoleKey.D: driverType = DriverType.BurningsVideo; break; case ConsoleKey.E: driverType = DriverType.Software; break; case ConsoleKey.F: driverType = DriverType.Null; break; default: return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh mesh = smgr.GetMesh("20kdm2.bsp"); SceneNode node = null; if (mesh != null) { node = smgr.AddOctreeSceneNode(mesh.GetMesh(0), null, -1, 1024); } if (node != null) { node.Position = new Vector3Df(-1300, -144, -1249); } smgr.AddCameraSceneNodeFPS(); device.CursorControl.Visible = false; int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(true, true, new Color(200, 200, 200)); smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Quake 3 Map Example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
private void exportToolStripMenuItem_Click(object sender, EventArgs e) { using (var sf = new SaveFileDialog()) { sf.Filter = "Irrlicht mesh | *.irrm | Collada mesh | *.coll | STL Mesh | *.stl | OBJ Mesh | *.obj | PLY Mesh | *.ply | B3D Mesh | *.b3d | FBX Mesh | *.fbx"; if (sf.ShowDialog() == DialogResult.OK) { MeshWriterType mwt = 0; switch (Path.GetExtension(sf.FileName).Trim()) { case ".irrm": mwt = MeshWriterType.IrrMesh; break; case ".coll": mwt = MeshWriterType.Collada; break; case ".obj": mwt = MeshWriterType.Obj; break; case ".stl": mwt = MeshWriterType.Stl; break; case ".ply": mwt = MeshWriterType.Ply; break; case ".b3d": mwt = MeshWriterType.B3d; break; case ".fbx": mwt = MeshWriterType.Fbx; break; default: MessageBox.Show(this, "Wrong file format selected, choose correct file format!", "WolvenKit", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var mw = smgr.CreateMeshWriter(mwt); AnimatedMesh sm = mesh; SkinnedMesh s = null; if (meshToAnimate != null) { sm = meshToAnimate; } if (!string.IsNullOrEmpty(activeAnim)) { s = helper.applyAnimation(activeAnim, meshToAnimate); if (s != null) { sm = s; } } if (mw.WriteMesh(dev.FileSystem.CreateWriteFile(sf.FileName), sm, MeshWriterFlag.None)) { MessageBox.Show(this, "Sucessfully wrote file!", "WolvenKit", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(this, "Failed to write file!", "WolvenKit", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (sm != null) { sm.Drop(); } if (mw != null) { mw.Drop(); } if (s != null) { s.Drop(); } } } }
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 if (panelRenderWindow.IsDisposed) { throw new Exception("Form closed!"); } DeviceSettings s = new DeviceSettings( IntPtr.Zero, DriverType.Direct3D9, 0, //antialias new Color(100, 101, 140), false); if (panelRenderWindow.InvokeRequired) { panelRenderWindow.Invoke(new MethodInvoker(delegate { s.WindowID = panelRenderWindow.Handle; })); } dev = IrrlichtDevice.CreateDevice(s); if (dev == null) { throw new NullReferenceException("Could not create device for engine!"); } dev.OnEvent += new IrrlichtDevice.EventHandler(this.device_OnEvent); dev.Logger.LogLevel = LogLevel.Warning; drv = dev.VideoDriver; smgr = dev.SceneManager; gui = dev.GUIEnvironment; _ = smgr.FileSystem.AddFileArchive(activeMod.FileDirectory); smgr.Attributes.AddValue("TW_TW3_LOAD_SKEL", true); smgr.Attributes.AddValue("TW_TW3_LOAD_BEST_LOD_ONLY", true); // added by vl if (meshFile != null && meshFile.Length > 0) { mesh = smgr.GetMesh(meshFile); } if (mesh == null) { throw new Exception("Failed to load mesh."); } mesh.Grab(); smgr.MeshManipulator.RecalculateNormals(mesh); meshLoaded = true; float scaleMul = 1.0f; node = smgr.AddAnimatedMeshSceneNode(mesh); helper = smgr.GetMeshLoader(smgr.MeshLoaderCount - 1).getMeshLoaderHelper(); // hacked to gat witcher3 loader if (node != null && meshLoaded) { node.Scale = new Vector3Df(3.0f); node.SetMaterialFlag(MaterialFlag.Lighting, false); scaleMul = node.BoundingBox.Radius / 4; if (!string.IsNullOrEmpty(rigFile)) { meshToAnimate = helper.loadRig(rigFile, mesh); if (meshToAnimate == null) { throw new Exception("Failed to load rig."); } else { meshToAnimate.Grab(); rigLoaded = true; Logger.LogString("Rig loaded!", Logtype.Success); node.Mesh = meshToAnimate; } } if (!string.IsNullOrEmpty(animFile) && rigLoaded) { animList = helper.loadAnimation(animFile, meshToAnimate); if (animList.Count > 0) { animLoaded = true; Logger.LogString($"{animList.Count} animations loaded! Select animation to play", Logtype.Success); } else { Logger.LogString("No animations loaded!", Logtype.Important); } } setMaterialsSettings(node); } 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; var animText = activeAnim; var mAnimText = gui.AddStaticText(animText, new Recti(0, this.ClientSize.Height - 80, 100, this.ClientSize.Height - 70)); var mPositionText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 70, 100, this.ClientSize.Height - 60)); var mRotationText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 60, 100, this.ClientSize.Height - 50)); var fpsText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 50, 100, this.ClientSize.Height - 40)); var infoText = gui.AddStaticText("[Space] - Reset\n[LMouse] - Rotate\n[MMouse] - Move\n[Wheel] - Zoom", new Recti(0, this.ClientSize.Height - 40, 100, this.ClientSize.Height)); mAnimText.OverrideColor = mPositionText.OverrideColor = mRotationText.OverrideColor = fpsText.OverrideColor = infoText.OverrideColor = new Color(255, 255, 255); mAnimText.BackgroundColor = mPositionText.BackgroundColor = mRotationText.BackgroundColor = fpsText.BackgroundColor = infoText.BackgroundColor = new Color(0, 0, 0); viewPort = drv.ViewPort; var lineMat = new Material { Lighting = false }; while (dev.Run()) { drv.ViewPort = viewPort; drv.BeginScene(ClearBufferFlag.Depth | ClearBufferFlag.Color, s.BackColor); node.Position = modelPosition; node.Rotation = modelAngle; //update info box mPositionText.Text = $"X: {modelPosition.X.ToString("F2")} Y: {modelPosition.Y.ToString("F2")} Z: {modelPosition.Z.ToString("F2")}"; mRotationText.Text = $"Yaw: {modelAngle.Y.ToString("F2")} Roll: {modelAngle.Z.ToString("F2")}"; fpsText.Text = $"FPS: {drv.FPS}"; smgr.DrawAll(); gui.DrawAll(); // draw xyz axis right bottom drv.ViewPort = new Recti(this.ClientSize.Width - 100, this.ClientSize.Height - 80, this.ClientSize.Width, this.ClientSize.Height); drv.SetMaterial(lineMat); var matrix = new Matrix(new Vector3Df(0, 0, 0), modelAngle); drv.SetTransform(TransformationState.World, matrix); matrix = matrix.BuildProjectionMatrixOrthoLH(100, 80, camera.NearValue, camera.FarValue); drv.SetTransform(TransformationState.Projection, matrix); matrix = matrix.BuildCameraLookAtMatrixLH(new Vector3Df(50, 0, 0), new Vector3Df(0, 0, 0), new Vector3Df(0, 1f, 0)); drv.SetTransform(TransformationState.View, matrix); drv.Draw3DLine(0, 0, 0, 30f, 0, 0, Color.SolidGreen); drv.Draw3DLine(0, 0, 0, 0, 30f, 0, Color.SolidBlue); drv.Draw3DLine(0, 0, 0, 0, 0, 30f, Color.SolidRed); drv.EndScene(); // if we requested to stop, we close the device if (worker.CancellationPending) { dev.Close(); } } // drop device dev.Drop(); }
static void loadModel(string f) { string e = Path.GetExtension(f); switch (e) { // if a texture is loaded apply it to the current model case ".jpg": case ".pcx": case ".png": case ".ppm": case ".pgm": case ".pbm": case ".psd": case ".tga": case ".bmp": case ".wal": case ".rgb": case ".rgba": Texture t = device.VideoDriver.GetTexture(f); if (t != null && model != null) { // always reload texture device.VideoDriver.RemoveTexture(t); t = device.VideoDriver.GetTexture(f); model.SetMaterialTexture(0, t); } return; // if a archive is loaded add it to the FileArchive case ".pk3": case ".zip": case ".pak": case ".npk": device.FileSystem.AddFileArchive(f); return; } // load a model into the engine if (model != null) { model.Remove(); } model = null; if (e == ".irr") { device.SceneManager.LoadScene(f); model = device.SceneManager.GetSceneNodeFromType(SceneNodeType.AnimatedMesh); return; } AnimatedMesh m = device.SceneManager.GetMesh(f); if (m == null) { // model could not be loaded if (startUpModelFile != f) { device.GUIEnvironment.AddMessageBox(caption, "The model could not be loaded. Maybe it is not a supported file format."); } return; } // set default material properties if (octree) { model = device.SceneManager.AddOctreeSceneNode(m.GetMesh(0)); } else { AnimatedMeshSceneNode n = device.SceneManager.AddAnimatedMeshSceneNode(m); model = n; } model.SetMaterialFlag(MaterialFlag.Lighting, useLight); model.SetMaterialFlag(MaterialFlag.NormalizeNormals, useLight); model.DebugDataVisible = DebugSceneType.Off; // we need to uncheck the menu entries. would be cool to fake a menu event, but // that's not so simple. so we do it brute force GUIContextMenu u = device.GUIEnvironment.RootElement.GetElementFromID((int)guiID.ToggleDebugInfo, true) as GUIContextMenu; if (u != null) { for (int i = 0; i < 6; i++) { u.SetItemChecked(i, false); } } updateScaleInfo(model); }
private static float _playerVerticalSpeed = 0.0f; // used to calculate vertical speed for gravity and jump static void Main(string[] args) { IrrlichtDevice device = IrrlichtDevice.CreateDevice(DriverType.OpenGL, new Dimension2Di(ResolutionX, ResolutionY), 24, false, false, false); device.OnEvent += Device_OnEvent; device.SetWindowCaption("Hello World! - Irrlicht Engine Demo"); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment gui = device.GUIEnvironment; gui.AddStaticText("Hello World! This is the Irrlicht Software renderer!", new Recti(10, 10, 260, 22), true); AnimatedMesh mesh = smgr.GetMesh("../../media/sydney.md2"); AnimatedMeshSceneNode sydneyNode = smgr.AddAnimatedMeshSceneNode(mesh); var cubeSceneNode = smgr.AddCubeSceneNode(2.0f); cubeSceneNode.Scale = new Vector3Df(6.0f, 2.0f, 100.0f); cubeSceneNode.Position = new Vector3Df(cubeSceneNode.Position.X, GroundAltitude + 0.5f, cubeSceneNode.Position.Z); if (sydneyNode != null) { sydneyNode.SetMaterialFlag(MaterialFlag.Lighting, true); sydneyNode.SetMD2Animation(AnimationTypeMD2.Stand); sydneyNode.SetMaterialTexture(0, driver.GetTexture("../../media/sydney.bmp")); } var lightSceneNode = smgr.AddLightSceneNode(); var light = lightSceneNode.LightData; light.DiffuseColor = new Colorf(0.8f, 1.0f, 1.0f); light.Type = LightType.Directional; light.Position = new Vector3Df(0.0f, 5.0f, 5.0f); var cam = smgr.AddCameraSceneNode(null, new Vector3Df(20, 30, -40), new Vector3Df(20, 5, 0)); device.Timer.Start(); uint then = device.Timer.RealTime; while (device.Run()) { // As the game is simple we will handle our simple physics ourselves uint now = device.Timer.RealTime; uint elapsed = now - then; float elapsedTimeSec = (float)elapsed / 1000.0f; then = now; // we target 58.8 FPS if (elapsed < 17) { device.Sleep(17 - (int)elapsed); } else { // uh-oh, it took more than .125 sec to do render loop! // what do we do now? } _playerVerticalSpeed += elapsedTimeSec * -(VerticalGravity * 10.0f); var calculatedNewPos = sydneyNode.Position - new Vector3Df(0.0f, _playerVerticalSpeed * elapsedTimeSec, 0.0f); float offsetSydney = sydneyNode.BoundingBox.Extent.Y / 2.0f; _isGrounded = calculatedNewPos.Y <= (GroundAltitude + offsetSydney); if (_isGrounded) { _playerVerticalSpeed = 0.0f; calculatedNewPos.Y = GroundAltitude + offsetSydney; } else { calculatedNewPos.Y = calculatedNewPos.Y; } sydneyNode.Position = calculatedNewPos; driver.BeginScene(true, true, new Color(100, 101, 140)); smgr.DrawAll(); gui.DrawAll(); driver.EndScene(); } device.Drop(); }
static void Main() { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; GUIEnvironment env = device.GUIEnvironment; driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, true); // add irrlicht logo env.AddImage(driver.GetTexture("../../media/irrlichtlogoalpha2.tga"), new Vector2Di(10)); // add camera CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(); camera.Position = new Vector3Df(-200, 200, -200); // disable mouse cursor device.CursorControl.Visible = false; driver.Fog = new Fog(new Color(138, 125, 81, 0), FogType.Linear, 250, 1000, 0.003f, true, false); AnimatedMesh roomMesh = smgr.GetMesh("../../media/room.3ds"); SceneNode room = null; SceneNode earth = null; if (roomMesh != null) { // the room mesh doesn't have proper texture mapping on the floor, // so we can recreate them on runtime smgr.MeshManipulator.MakePlanarTextureMapping(roomMesh.GetMesh(0), 0.003f); Texture normalMap = driver.GetTexture("../../media/rockwall_height.bmp"); if (normalMap != null) { driver.MakeNormalMapTexture(normalMap, 9.0f); } Mesh tangentMesh = smgr.MeshManipulator.CreateMeshWithTangents(roomMesh.GetMesh(0)); room = smgr.AddMeshSceneNode(tangentMesh); room.SetMaterialTexture(0, driver.GetTexture("../../media/rockwall.jpg")); room.SetMaterialTexture(1, normalMap); room.GetMaterial(0).SpecularColor = new Color(0); room.GetMaterial(0).Shininess = 0.0f; room.SetMaterialFlag(MaterialFlag.Fog, true); room.SetMaterialType(MaterialType.ParallaxMapSolid); room.GetMaterial(0).MaterialTypeParam = 1.0f / 64.0f; // adjust height for parallax effect tangentMesh.Drop(); // drop mesh because we created it with a "create" call } // add earth sphere AnimatedMesh earthMesh = smgr.GetMesh("../../media/earth.x"); if (earthMesh != null) { // perform various task with the mesh manipulator MeshManipulator manipulator = smgr.MeshManipulator; // create mesh copy with tangent informations from original earth.x mesh Mesh tangentSphereMesh = manipulator.CreateMeshWithTangents(earthMesh.GetMesh(0)); // set the alpha value of all vertices to 200 manipulator.SetVertexColorAlpha(tangentSphereMesh, 200); // scale the mesh by factor 50 Matrix m = new Matrix(); m.Scale = new Vector3Df(50); manipulator.Transform(tangentSphereMesh, m); earth = smgr.AddMeshSceneNode(tangentSphereMesh); earth.Position = new Vector3Df(-70, 130, 45); // load heightmap, create normal map from it and set it Texture earthNormalMap = driver.GetTexture("../../media/earthbump.jpg"); if (earthNormalMap != null) { driver.MakeNormalMapTexture(earthNormalMap, 20); earth.SetMaterialTexture(1, earthNormalMap); earth.SetMaterialType(MaterialType.NormalMapTransparentVertexAlpha); } // adjust material settings earth.SetMaterialFlag(MaterialFlag.Fog, true); // add rotation animator SceneNodeAnimator anim = smgr.CreateRotationAnimator(new Vector3Df(0, 0.1f, 0)); earth.AddAnimator(anim); anim.Drop(); // drop mesh because we created it with a "create" call. tangentSphereMesh.Drop(); } // add light 1 (more green) LightSceneNode light1 = smgr.AddLightSceneNode(null, new Vector3Df(), new Colorf(0.5f, 1.0f, 0.5f, 0.0f), 800); if (light1 != null) { light1.DebugDataVisible = DebugSceneType.BBox; // add fly circle animator to light SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(50, 300, 0), 190.0f, -0.003f); light1.AddAnimator(anim); anim.Drop(); // attach billboard to the light BillboardSceneNode bill = smgr.AddBillboardSceneNode(light1, new Dimension2Df(60, 60)); bill.SetMaterialFlag(MaterialFlag.Lighting, false); bill.SetMaterialFlag(MaterialFlag.ZWrite, false); bill.SetMaterialType(MaterialType.TransparentAddColor); bill.SetMaterialTexture(0, driver.GetTexture("../../media/particlegreen.jpg")); } // add light 2 (red) SceneNode light2 = smgr.AddLightSceneNode(null, new Vector3Df(), new Colorf(1.0f, 0.2f, 0.2f, 0.0f), 800.0f); if (light2 != null) { // add fly circle animator to light SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 150, 0), 200.0f, 0.001f, new Vector3Df(0.2f, 0.9f, 0.0f)); light2.AddAnimator(anim); anim.Drop(); // attach billboard to light SceneNode bill = smgr.AddBillboardSceneNode(light2, new Dimension2Df(120, 120)); bill.SetMaterialFlag(MaterialFlag.Lighting, false); bill.SetMaterialFlag(MaterialFlag.ZWrite, false); bill.SetMaterialType(MaterialType.TransparentAddColor); bill.SetMaterialTexture(0, driver.GetTexture("../../media/particlered.bmp")); // add particle system ParticleSystemSceneNode ps = smgr.AddParticleSystemSceneNode(false, light2); // create and set emitter ParticleEmitter em = ps.CreateBoxEmitter( new AABBox(-3, 0, -3, 3, 1, 3), new Vector3Df(0.0f, 0.03f, 0.0f), 80, 100, new Color(255, 255, 255, 10), new Color(255, 255, 255, 10), 400, 1100); em.MinStartSize = new Dimension2Df(30.0f, 40.0f); em.MaxStartSize = new Dimension2Df(30.0f, 40.0f); ps.Emitter = em; em.Drop(); // create and set affector ParticleAffector paf = ps.CreateFadeOutParticleAffector(); ps.AddAffector(paf); paf.Drop(); // adjust some material settings ps.SetMaterialFlag(MaterialFlag.Lighting, false); ps.SetMaterialFlag(MaterialFlag.ZWrite, false); ps.SetMaterialTexture(0, driver.GetTexture("../../media/fireball.bmp")); ps.SetMaterialType(MaterialType.TransparentAddColor); } MyEventReceiver receiver = new MyEventReceiver(device, room, earth); int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(0)); smgr.DrawAll(); env.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Per pixel lighting example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
static void Main() { bool shadows = AskForRealtimeShadows(); DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480), 16, false, shadows); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; AnimatedMesh mesh = smgr.GetMesh("../../media/room.3ds"); smgr.MeshManipulator.MakePlanarTextureMapping(mesh.GetMesh(0), 0.004f); SceneNode node = smgr.AddAnimatedMeshSceneNode(mesh); node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.jpg")); node.GetMaterial(0).SpecularColor = new Color(0); mesh = smgr.AddHillPlaneMesh("myHill", new Dimension2Df(20, 20), new Dimension2Di(40, 40), null, 0, new Dimension2Df(0), new Dimension2Df(10, 10)); node = smgr.AddWaterSurfaceSceneNode(mesh.GetMesh(0), 3.0f, 300.0f, 30.0f); node.Position = new Vector3Df(0, 7, 0); node.SetMaterialTexture(0, driver.GetTexture("../../media/stones.jpg")); node.SetMaterialTexture(1, driver.GetTexture("../../media/water.jpg")); node.SetMaterialType(MaterialType.Reflection2Layer); // create light node = smgr.AddLightSceneNode(null, new Vector3Df(0), new Colorf(1.0f, 0.6f, 0.7f, 1.0f), 800); SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 150, 0), 250); node.AddAnimator(anim); anim.Drop(); // attach billboard to light node = smgr.AddBillboardSceneNode(node, new Dimension2Df(50, 50)); node.SetMaterialFlag(MaterialFlag.Lighting, false); node.SetMaterialType(MaterialType.TransparentAddColor); node.SetMaterialTexture(0, driver.GetTexture("../../media/particlewhite.bmp")); // create a particle system ParticleSystemSceneNode ps = smgr.AddParticleSystemSceneNode(false); if (ps != null) { ParticleEmitter em = ps.CreateBoxEmitter( new AABBox(-7, 0, -7, 7, 1, 7), // emitter size new Vector3Df(0.0f, 0.06f, 0.0f), // initial direction 80, 100, // emit rate new Color(255, 255, 255, 0), // darkest color new Color(255, 255, 255, 0), // brightest color 800, 2000, 0, // min and max age, angle new Dimension2Df(10.0f), // min size new Dimension2Df(20.0f)); // max size ps.Emitter = em; // this grabs the emitter em.Drop(); // so we can drop it here without deleting it ParticleAffector paf = ps.CreateFadeOutParticleAffector(); ps.AddAffector(paf); // same goes for the affector paf.Drop(); ps.Position = new Vector3Df(-70, 60, 40); ps.Scale = new Vector3Df(2); ps.SetMaterialFlag(MaterialFlag.Lighting, false); ps.SetMaterialFlag(MaterialFlag.ZWrite, false); ps.SetMaterialTexture(0, driver.GetTexture("../../media/fire.bmp")); ps.SetMaterialType(MaterialType.TransparentAddColor); } VolumeLightSceneNode n = smgr.AddVolumeLightSceneNode(null, -1, 32, // Subdivisions on U axis 32, // Subdivisions on V axis new Color(255, 255, 255, 0), // foot color new Color(0, 0, 0, 0)); // tail color if (n != null) { n.Scale = new Vector3Df(56); n.Position = new Vector3Df(-120, 50, 40); // load textures for animation List <Texture> textures = new List <Texture>(); for (int i = 7; i > 0; i--) { string s = string.Format("../../media/portal{0}.bmp", i); textures.Add(driver.GetTexture(s)); } // create texture animator SceneNodeAnimator glow = smgr.CreateTextureAnimator(textures, 0.150f); // add the animator n.AddAnimator(glow); // drop the animator because it was created with a create() function glow.Drop(); } // add animated character mesh = smgr.GetMesh("../../media/dwarf.x"); AnimatedMeshSceneNode anode = smgr.AddAnimatedMeshSceneNode(mesh); anode.Position = new Vector3Df(-50, 20, -60); anode.AnimationSpeed = 15; // add shadow anode.AddShadowVolumeSceneNode(); smgr.ShadowColor = new Color(0, 0, 0, 150); // make the model a little bit bigger and normalize its normals // because of the scaling, for correct lighting anode.Scale = new Vector3Df(2); anode.SetMaterialFlag(MaterialFlag.NormalizeNormals, true); CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(); camera.Position = new Vector3Df(-50, 50, -150); // disable mouse cursor device.CursorControl.Visible = false; int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(0)); smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "SpecialFX example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
static void Main() { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh q3levelmesh = smgr.GetMesh("20kdm2.bsp"); MeshSceneNode q3node = null; // The Quake mesh is pickable, but doesn't get highlighted. if (q3levelmesh != null) { q3node = smgr.AddOctreeSceneNode(q3levelmesh.GetMesh(0), null, IDFlag_IsPickable); } TriangleSelector selector = null; if (q3node != null) { q3node.Position = new Vector3Df(-1350, -130, -1400); selector = smgr.CreateOctreeTriangleSelector(q3node.Mesh, q3node, 128); q3node.TriangleSelector = selector; // We're not done with this selector yet, so don't drop it. } // Set a jump speed of 3 units per second, which gives a fairly realistic jump // when used with the gravity of (0, -1000, 0) in the collision response animator. CameraSceneNode camera = smgr.AddCameraSceneNodeFPS(null, 100.0f, 0.3f, ID_IsNotPickable, null, true, 3.0f); camera.Position = new Vector3Df(50, 50, -60); camera.Target = new Vector3Df(-70, 30, -60); if (selector != null) { SceneNodeAnimator anim = smgr.CreateCollisionResponseAnimator( selector, camera, new Vector3Df(30, 50, 30), new Vector3Df(0, -1000, 0), new Vector3Df(0, 30, 0)); selector.Drop(); // As soon as we're done with the selector, drop it. camera.AddAnimator(anim); anim.Drop(); // And likewise, drop the animator when we're done referring to it. } // Now I create three animated characters which we can pick, a dynamic light for // lighting them, and a billboard for drawing where we found an intersection. // First, let's get rid of the mouse cursor. We'll use a billboard to show what we're looking at. device.CursorControl.Visible = false; // Add the billboard. BillboardSceneNode bill = smgr.AddBillboardSceneNode(); bill.SetMaterialType(MaterialType.TransparentAddColor); bill.SetMaterialTexture(0, driver.GetTexture("../../media/particle.bmp")); bill.SetMaterialFlag(MaterialFlag.Lighting, false); bill.SetMaterialFlag(MaterialFlag.ZBuffer, false); bill.SetSize(20, 20, 20); bill.ID = ID_IsNotPickable; // This ensures that we don't accidentally ray-pick it AnimatedMeshSceneNode node = null; // Add an MD2 node, which uses vertex-based animation. node = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/faerie.md2"), null, IDFlag_IsPickable | IDFlag_IsHighlightable); node.Position = new Vector3Df(-90, -15, -140); // Put its feet on the floor. node.Scale = new Vector3Df(1.6f); // Make it appear realistically scaled node.SetMD2Animation(AnimationTypeMD2.Point); node.AnimationSpeed = 20.0f; node.GetMaterial(0).SetTexture(0, driver.GetTexture("../../media/faerie2.bmp")); node.GetMaterial(0).Lighting = true; node.GetMaterial(0).NormalizeNormals = true; // Now create a triangle selector for it. The selector will know that it // is associated with an animated node, and will update itself as necessary. selector = smgr.CreateTriangleSelector(node); node.TriangleSelector = selector; selector.Drop(); // We're done with this selector, so drop it now. // And this B3D file uses skinned skeletal animation. node = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/ninja.b3d"), null, IDFlag_IsPickable | IDFlag_IsHighlightable); node.Scale = new Vector3Df(10); node.Position = new Vector3Df(-75, -66, -80); node.Rotation = new Vector3Df(0, 90, 0); node.AnimationSpeed = 8.0f; node.GetMaterial(0).NormalizeNormals = true; // Just do the same as we did above. selector = smgr.CreateTriangleSelector(node); node.TriangleSelector = selector; selector.Drop(); // This X files uses skeletal animation, but without skinning. node = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/dwarf.x"), null, IDFlag_IsPickable | IDFlag_IsHighlightable); node.Position = new Vector3Df(-70, -66, -30); // Put its feet on the floor. node.Rotation = new Vector3Df(0, -90, 0); // And turn it towards the camera. node.AnimationSpeed = 20.0f; selector = smgr.CreateTriangleSelector(node); node.TriangleSelector = selector; selector.Drop(); // And this mdl file uses skinned skeletal animation. node = smgr.AddAnimatedMeshSceneNode(smgr.GetMesh("../../media/yodan.mdl"), null, IDFlag_IsPickable | IDFlag_IsHighlightable); node.Position = new Vector3Df(-90, -25, 20); node.Scale = new Vector3Df(0.8f); node.GetMaterial(0).Lighting = true; node.AnimationSpeed = 20.0f; // Just do the same as we did above. selector = smgr.CreateTriangleSelector(node); node.TriangleSelector = selector; selector.Drop(); // Add a light, so that the unselected nodes aren't completely dark. LightSceneNode light = smgr.AddLightSceneNode(null, new Vector3Df(-60, 100, 400), new Colorf(1.0f, 1.0f, 1.0f), 600.0f); light.ID = ID_IsNotPickable; // Make it an invalid target for selection. // Remember which scene node is highlighted SceneNode highlightedSceneNode = null; SceneCollisionManager collMan = smgr.SceneCollisionManager; int lastFPS = -1; // draw the selection triangle only as wireframe Material material = new Material(); material.Lighting = false; material.Wireframe = true; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(0)); smgr.DrawAll(); // Unlight any currently highlighted scene node if (highlightedSceneNode != null) { highlightedSceneNode.SetMaterialFlag(MaterialFlag.Lighting, true); highlightedSceneNode = null; } // All intersections in this example are done with a ray cast out from the camera to // a distance of 1000. You can easily modify this to check (e.g.) a bullet // trajectory or a sword's position, or create a ray from a mouse click position using // collMan.GetRayFromScreenCoordinates() Line3Df ray = new Line3Df(); ray.Start = camera.Position; ray.End = ray.Start + (camera.Target - ray.Start).Normalize() * 1000.0f; // This call is all you need to perform ray/triangle collision on every scene node // that has a triangle selector, including the Quake level mesh. It finds the nearest // collision point/triangle, and returns the scene node containing that point. // Irrlicht provides other types of selection, including ray/triangle selector, // ray/box and ellipse/triangle selector, plus associated helpers. // See the methods of ISceneCollisionManager SceneNode selectedSceneNode = collMan.GetSceneNodeAndCollisionPointFromRay( ray, out Vector3Df intersection, // This will be the position of the collision out Triangle3Df hitTriangle, // This will be the triangle hit in the collision IDFlag_IsPickable); // This ensures that only nodes that we have set up to be pickable are considered // If the ray hit anything, move the billboard to the collision position // and draw the triangle that was hit. if (selectedSceneNode != null) { bill.Position = intersection; // We need to reset the transform before doing our own rendering. driver.SetTransform(TransformationState.World, Matrix.Identity); driver.SetMaterial(material); driver.Draw3DTriangle(hitTriangle, new Color(255, 0, 0)); // We can check the flags for the scene node that was hit to see if it should be // highlighted. The animated nodes can be highlighted, but not the Quake level mesh if ((selectedSceneNode.ID & IDFlag_IsHighlightable) == IDFlag_IsHighlightable) { highlightedSceneNode = selectedSceneNode; // Highlighting in this case means turning lighting OFF for this node, // which means that it will be drawn with full brightness. highlightedSceneNode.SetMaterialFlag(MaterialFlag.Lighting, false); } } // We're all done drawing, so end the scene. driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Collision detection example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
static void Main() { DriverType?driverType = AskForDriver(); if (!driverType.HasValue) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480)); if (device == null) { return; } VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh mesh = smgr.GetMesh("20kdm2.bsp"); SceneNode node = null; if (mesh != null) { node = smgr.AddOctreeSceneNode(mesh.GetMesh(0), null, -1, 1024); } if (node != null) { node.Position = new Vector3Df(-1300, -144, -1249); } smgr.AddCameraSceneNodeFPS(); device.CursorControl.Visible = false; int lastFPS = -1; while (device.Run()) { if (device.WindowActive) { driver.BeginScene(ClearBufferFlag.All, new Color(200, 200, 200)); smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Quake 3 Map Example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } } device.Drop(); }
/// <summary> /// The irrlicht thread for rendering. /// </summary> private void StartIrr() { try { IrrlichtCreationParameters irrparam = new IrrlichtCreationParameters(); if (irrlichtPanel.IsDisposed) { throw new Exception("Form closed!"); } if (irrlichtPanel.InvokeRequired) { irrlichtPanel.Invoke(new MethodInvoker(delegate { irrparam.WindowID = irrlichtPanel.Handle; })); } irrparam.DriverType = DriverType.Direct3D9; irrparam.BitsPerPixel = 16; device = IrrlichtDevice.CreateDevice(irrparam); if (device == null) { throw new NullReferenceException("Could not create device for engine!"); } device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); driver = device.VideoDriver; smgr = device.SceneManager; gui = device.GUIEnvironment; var animText = ""; if (Animations.AnimationNames.Count > 0 && currAnimIdx != -1) { animText = "Animation: " + Animations.AnimationNames[currAnimIdx].Key; } var mAnimText = gui.AddStaticText(animText, new Recti(0, this.ClientSize.Height - 80, 100, this.ClientSize.Height - 70)); var mPositionText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 70, 100, this.ClientSize.Height - 60)); var mRotationText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 60, 100, this.ClientSize.Height - 50)); var fpsText = gui.AddStaticText("", new Recti(0, this.ClientSize.Height - 50, 100, this.ClientSize.Height - 40)); var infoText = gui.AddStaticText("[Space] - Reset\n[LMouse] - Rotate\n[MMouse] - Move\n[Wheel] - Zoom", new Recti(0, this.ClientSize.Height - 40, 100, this.ClientSize.Height)); mAnimText.OverrideColor = mPositionText.OverrideColor = mRotationText.OverrideColor = fpsText.OverrideColor = infoText.OverrideColor = new Color(255, 255, 255); mAnimText.BackgroundColor = mPositionText.BackgroundColor = mRotationText.BackgroundColor = fpsText.BackgroundColor = infoText.BackgroundColor = new Color(0, 0, 0); skinnedMesh = smgr.CreateSkinnedMesh(); //foreach (var meshBuffer in cdata.staticMesh.MeshBuffers) // skinnedMesh.AddMeshBuffer(meshBuffer); AnimatedMesh am = smgr.GetMesh(meshFile.FileName); foreach (var meshBuffer in am.MeshBuffers) { skinnedMesh.AddMeshBuffer(meshBuffer); } smgr.MeshManipulator.RecalculateNormals(skinnedMesh); if (RigFile != null) { rig.Apply(skinnedMesh); if (AnimFile != null && currAnimIdx != -1) { anims.Apply(skinnedMesh); } } skinnedMesh.SetDirty(HardwareBufferType.VertexAndIndex); skinnedMesh.FinalizeMeshPopulation(); AnimatedMeshSceneNode n = smgr.AddAnimatedMeshSceneNode(skinnedMesh); if (n == null) { throw new Exception("Could not create animated scene node!"); } else { node = n; } node.Scale = new Vector3Df(3.0f); node.SetMaterialFlag(MaterialFlag.Lighting, false); SetMaterials(driver); CameraSceneNode 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 * CommonData.PI_OVER_180; scaleMul = node.BoundingBox.Radius / 4; var viewPort = driver.ViewPort; var lineMat = new Material { Lighting = false }; resetDebugViewMenu(); //reset debug view featchers smgr.Attributes.SetValue(SceneParameters.DebugNormalLength, scaleMul / 2); //calculate normals length // main drawing loop while (device.Run() && driver != null) { if (this.Visible) { driver.ViewPort = viewPort; driver.BeginScene(ClearBufferFlag.All, new Color(100, 101, 140)); node.Position = modelPosition; node.Rotation = modelAngle; //update info box mPositionText.Text = $"X: {modelPosition.X.ToString("F2")} Y: {modelPosition.Y.ToString("F2")} Z: {modelPosition.Z.ToString("F2")}"; mRotationText.Text = $"Yaw: {modelAngle.Y.ToString("F2")} Roll: {modelAngle.Z.ToString("F2")}"; fpsText.Text = $"FPS: {driver.FPS}"; smgr.DrawAll(); gui.DrawAll(); // draw xyz axis right bottom driver.ViewPort = new Recti(this.ClientSize.Width - 100, this.ClientSize.Height - 80, this.ClientSize.Width, this.ClientSize.Height); driver.SetMaterial(lineMat); var matrix = new Matrix(new Vector3Df(0, 0, 0), modelAngle); driver.SetTransform(TransformationState.World, matrix); matrix = matrix.BuildProjectionMatrixOrthoLH(100, 80, camera.NearValue, camera.FarValue); driver.SetTransform(TransformationState.Projection, matrix); matrix = matrix.BuildCameraLookAtMatrixLH(new Vector3Df(50, 0, 0), new Vector3Df(0, 0, 0), new Vector3Df(0, 1f, 0)); driver.SetTransform(TransformationState.View, matrix); driver.Draw3DLine(0, 0, 0, 30f, 0, 0, Color.SolidGreen); driver.Draw3DLine(0, 0, 0, 0, 30f, 0, Color.SolidBlue); driver.Draw3DLine(0, 0, 0, 0, 0, 30f, Color.SolidRed); driver.EndScene(); } else { device.Yield(); } } device.Drop(); } catch (ThreadAbortException) { } catch (NullReferenceException) { } catch (Exception ex) { if (!this.IsDisposed) { MessageBox.Show(ex.Message); //this.Invoke(new MethodInvoker(delegate { this.Close(); })); } } }
static void Main(string[] args) { DriverType driverType; if (!AskUserForDriver(out driverType)) { return; } IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType, new Dimension2Di(ResX, ResY), 32, fullScreen); if (device == null) { return; } device.OnEvent += new IrrlichtDevice.EventHandler(device_OnEvent); VideoDriver driver = device.VideoDriver; SceneManager smgr = device.SceneManager; // load model AnimatedMesh model = smgr.GetMesh("../../media/sydney.md2"); if (model == null) { return; } AnimatedMeshSceneNode model_node = smgr.AddAnimatedMeshSceneNode(model); // load texture if (model_node != null) { Texture texture = driver.GetTexture("../../media/sydney.bmp"); model_node.SetMaterialTexture(0, texture); model_node.SetMD2Animation(AnimationTypeMD2.Run); model_node.SetMaterialFlag(MaterialFlag.Lighting, false); } // load map device.FileSystem.AddFileArchive("../../media/map-20kdm2.pk3"); AnimatedMesh map = smgr.GetMesh("20kdm2.bsp"); if (map != null) { SceneNode map_node = smgr.AddOctreeSceneNode(map.GetMesh(0)); map_node.Position = new Vector3Df(-850, -220, -850); } // create 3 fixed and one user-controlled cameras camera[0] = smgr.AddCameraSceneNode(null, new Vector3Df(50, 0, 0), new Vector3Df(0)); // font camera[1] = smgr.AddCameraSceneNode(null, new Vector3Df(0, 50, 0), new Vector3Df(0)); // top camera[2] = smgr.AddCameraSceneNode(null, new Vector3Df(0, 0, 50), new Vector3Df(0)); // left camera[3] = smgr.AddCameraSceneNodeFPS(); // user-controlled camera[3].Position = new Vector3Df(-50, 0, -50); device.CursorControl.Visible = false; int lastFPS = -1; while (device.Run()) { // set the viewpoint to the whole screen and begin scene driver.ViewPort = new Recti(0, 0, ResX, ResY); driver.BeginScene(true, true, new Color(100, 100, 100)); if (splitScreen) { smgr.ActiveCamera = camera[0]; driver.ViewPort = new Recti(0, 0, ResX / 2, ResY / 2); // top left smgr.DrawAll(); smgr.ActiveCamera = camera[1]; driver.ViewPort = new Recti(ResX / 2, 0, ResX, ResY / 2); // top right smgr.DrawAll(); smgr.ActiveCamera = camera[2]; driver.ViewPort = new Recti(0, ResY / 2, ResX / 2, ResY); // bottom left smgr.DrawAll(); driver.ViewPort = new Recti(ResX / 2, ResY / 2, ResX, ResY); // bottom right } smgr.ActiveCamera = camera[3]; smgr.DrawAll(); driver.EndScene(); int fps = driver.FPS; if (lastFPS != fps) { device.SetWindowCaption(String.Format( "Split Screen example - Irrlicht Engine [{0}] fps: {1}", driver.Name, fps)); lastFPS = fps; } } device.Drop(); }
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(); }