private static void RenderEditor(FrameEventArgs e) { imgui.Update(mainWindow.KeyboardState, mainWindow.MouseState, (float)e.Time); Ogl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); Ogl.ClearColor(0.1f, 0.1f, 0.1f, 255); EntygineApp.RenderFrame(e); Ogl.Viewport(0, 0, mainWindow.Size.X, mainWindow.Size.Y); imgui.WindowResized(mainWindow.Size.X, mainWindow.Size.Y); mainEditorDrawer.Draw(); imgui.Render(); }
public static void LoadEngine() { if (loadedEngine) { return; } loadedEngine = true; Ogl.enableErrorCheck = true; InitConsole(); DevConsole.Log(LogType.Info, "Creating Entity World..."); coreWorker = new WorkerCycleCore(); EntityWorld world = InitEcs(); RenderPipelineCore.SetPipeline(new ForwardRenderPipeline()); InitPhysics(); InitSkybox(); InitUI(world); InitLight(); InitScene(world); DevConsole.Log(LogType.Info, "Entity world created."); Ogl.ClearColor(0.1f, 0.1f, 0.2f, 1.0f); Ogl.Enable(EnableCap.DepthTest); Ogl.Enable(EnableCap.CullFace); Ogl.Enable(EnableCap.ProgramPointSize); Ogl.PointSize(10f); EntityWorld InitEcs() { EntityWorld world = EntityWorld.CreateWorld(); world.Runner.AssignToWorker(coreWorker).CreateSystemsAuto(world); EntityWorld.SetActive(world); return(world); } void InitPhysics() { PhysicsRunner physicsRunner = new PhysicsRunner(); PhysicsWorld world = new PhysicsWorld(); PhysicsWorld.SetDefaultWorld(world); physicsRunner.AddWorld(world); physicsRunner.AssignToWorker(coreWorker); } void InitScene(EntityWorld world) { Mesh meshResource = MeshPrimitives.CreateCube(1); Shader shaderResource = Shader.CreateShaderWithPath(AssetBrowser.Utilities.LocalToAbsolutePath(@"Shaders\standard.vert"), AssetBrowser.Utilities.LocalToAbsolutePath(@"Shaders\standard.frag"), "Standard Shader"); Texture2D texture = new Texture2D(AssetBrowser.Utilities.LocalToAbsolutePath(@"Textures\Box.png"), "Box"); Material materialResource = new Material(shaderResource, texture); SC_RenderMesh renderMesh = new SC_RenderMesh(meshResource, materialResource); EntityArchetype meshArchetype = new EntityArchetype(typeof(SC_RenderMesh), typeof(C_Transform), typeof(C_Position)); EntityArchetype boxArchetype = new EntityArchetype(typeof(SC_RenderMesh), typeof(C_Transform), typeof(C_Position), typeof(C_BoxTag)); Entity planeEntity = world.EntityManager.CreateEntity(meshArchetype); world.EntityManager.SetComponent(planeEntity, new C_Position() { value = new Vec3f(0, 0, 0) }); //world.EntityManager.SetComponent(planeEntity, new C_PhysicsBody() { body = new PhysicBody() { isStatic = true } }); Mesh planeMesh = MeshPrimitives.CreatePlaneXZ(50); Material planeMaterial = new Material(shaderResource, Texture2D.CreateWhiteTexture(64, 64)); world.EntityManager.SetSharedComponent(planeEntity, new SC_RenderMesh(planeMesh, planeMaterial)); Entity planeEntity2 = world.EntityManager.CreateEntity(meshArchetype); world.EntityManager.SetComponent(planeEntity2, new C_Position() { value = new Vec3f(0, 5, -10) }); //world.EntityManager.SetComponent(planeEntity2, new C_PhysicsBody() { body = new PhysicBody() { isStatic = true } }); Mesh planeMesh2 = MeshPrimitives.CreatePlaneXY(10); Material planeMaterial2 = new Material(shaderResource, texture); world.EntityManager.SetSharedComponent(planeEntity2, new SC_RenderMesh(planeMesh2, planeMaterial2)); Entity boxEntity = world.EntityManager.CreateEntity(boxArchetype); world.EntityManager.SetComponent(boxEntity, new C_Position() { value = new Vec3f(0, 2, 0) }); //world.EntityManager.SetComponent(boxEntity, new C_PhysicsBody() { body = new PhysicBody() }); world.EntityManager.SetSharedComponent(boxEntity, renderMesh); Entity boxEntity2 = world.EntityManager.CreateEntity(boxArchetype); world.EntityManager.SetComponent(boxEntity2, new C_Position() { value = new Vec3f(2, 2, 0) }); //world.EntityManager.SetComponent(boxEntity2, new C_PhysicsBody() { body = new PhysicBody() }); world.EntityManager.SetSharedComponent(boxEntity2, renderMesh); Entity boxEntity3 = world.EntityManager.CreateEntity(boxArchetype); world.EntityManager.SetComponent(boxEntity3, new C_Position() { value = new Vec3f(-2, 2, 0) }); //world.EntityManager.SetComponent(boxEntity3, new C_PhysicsBody() { body = new PhysicBody() }); world.EntityManager.SetSharedComponent(boxEntity3, renderMesh); EntityArchetype editorCameraArchetype = new EntityArchetype(typeof(C_Camera), typeof(C_Transform), typeof(C_EditorCamera)); Entity cameraEditorEntity = world.EntityManager.CreateEntity(editorCameraArchetype); world.EntityManager.SetComponent(cameraEditorEntity, new C_Camera() { cameraData = CameraData.CreatePerpectiveCamera(45f, 800f / 600f, 0.1f, 100f) }); world.EntityManager.SetComponent(cameraEditorEntity, new C_EditorCamera() { speed = 10f, focusPoint = new Vector3(0, 2, 0), focusDistance = 12, pitch = 20, yaw = 115, sensitivity = 20 }); } void InitLight() { if (RenderPipelineCore.TryGetContext(out LightsRenderData lightData)) { lightData.lights.Add(new DirectionalLight()); } } void InitUI(EntityWorld world) { EntityArchetype canvasArch = new EntityArchetype(typeof(C_UICanvas)); var entity = world.EntityManager.CreateEntity(canvasArch); world.EntityManager.SetComponent(entity, new C_UICanvas() { canvas = new UICanvas() }); }