Browse Source

working at editor

meemknight 2 years ago
parent
commit
9a436ac610

+ 4 - 0
Pika/core/pikaRuntime/containerManager/containerManager.cpp

@@ -395,6 +395,10 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 			auto callUpdate = [&](pika::WindowState &windowState) -> bool
 			{
 
+				c.second.requestedContainerInfo.mainAllocator = &c.second.allocator; //reset this
+				c.second.requestedContainerInfo.bonusAllocators = &c.second.bonusAllocators;
+
+
 				auto t1 = std::chrono::high_resolution_clock::now();
 
 				loadedDll.bindAllocatorDllRealm(&c.second.allocator);

+ 248 - 0
Pika/core/pikaSTD/engineLibraresSupport/engineGL3DSupport.cpp

@@ -160,5 +160,253 @@ void pika::gl3d::chromaticAberationSettingsWindow(int imguiId, ::gl3d::Renderer3
 	ImGui::DragFloat("Chromatic aberation defocus", &renderer.postProcess.unfocusDistance,
 		0.01, 0, 100);
 
+	ImGui::PopID();
+}
+
+void pika::gl3d::lightEditorSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer)
+{
+	ImGui::PushID(imguiId);
+
+	auto &pointLights = renderer.internal.pointLightIndexes;
+
+	static int pointLightSelector = -1;
+	ImGui::Text("Point lightd Count %d", pointLights.size());
+	ImGui::InputInt("Current Point light:", &pointLightSelector);
+	int n = ImGui::Button("New Light"); ImGui::SameLine();
+	int remove = ImGui::Button("Remove Light");
+
+	int lightSize = renderer.getPointLightShadowSize();
+	ImGui::DragInt("Point light shadow texture size", &lightSize);
+	renderer.setPointLightShadowSize(lightSize);
+
+	if (pointLightSelector < -1)
+	{
+		pointLightSelector = -1;
+	}
+
+	if (n || (pointLightSelector >= (int)pointLights.size()))
+	{
+		//pointLights.push_back(
+		renderer.createPointLight({0,0,0});
+	}
+
+	pointLightSelector = std::min(pointLightSelector, (int)pointLights.size() - 1);
+
+	if (remove)
+	{
+		if (pointLightSelector >= 0)
+		{
+			::gl3d::PointLight light;
+			light.id_ = pointLights[pointLightSelector];
+			renderer.detletePointLight(light);
+			pointLightSelector = std::min(pointLightSelector, (int)pointLights.size() - 1);
+		}
+
+	}
+
+	ImGui::NewLine();
+
+	if (pointLightSelector >= 0)
+	{
+		ImGui::PushID(12);
+
+		::gl3d::PointLight light;
+		light.id_ = pointLights[pointLightSelector];
+
+		glm::vec3 color = renderer.getPointLightColor(light);
+		ImGui::ColorEdit3("Color", &color[0]);
+		renderer.setPointLightColor(light, color);
+
+		glm::vec3 position = renderer.getPointLightPosition(light);
+		ImGui::DragFloat3("Position", &position[0], 0.1);
+		renderer.setPointLightPosition(light, position);
+
+		float distance = renderer.getPointLightDistance(light);
+		ImGui::DragFloat("Distance##point", &distance, 0.05, 0);
+		renderer.setPointLightDistance(light, distance);
+
+		float attenuation = renderer.getPointLightAttenuation(light);
+		ImGui::DragFloat("Attenuation##point", &attenuation, 0.05, 0);
+		renderer.setPointLightAttenuation(light, attenuation);
+
+		float hardness = renderer.getPointLightHardness(light);
+		ImGui::DragFloat("Hardness##point", &hardness, 0.05, 0.001);
+		renderer.setPointLightHardness(light, hardness);
+
+		bool shadows = renderer.getPointLightShadows(light);
+		ImGui::Checkbox("Cast shadows##point", &shadows);
+		renderer.setPointLightShadows(light, shadows);
+
+		ImGui::PopID();
+	}
+
+	{
+		ImGui::NewLine();
+
+		auto &directionalLights = renderer.internal.directionalLightIndexes;
+
+		static int directionalLightSelector = -1;
+		ImGui::Text("Directional lightd Count %d", directionalLights.size());
+		ImGui::InputInt("Current directional light:", &directionalLightSelector);
+		int n = ImGui::Button("New Directional Light"); ImGui::SameLine();
+		int remove = ImGui::Button("Remove Directional Light");
+
+		int lightSize = renderer.getDirectionalLightShadowSize();
+		ImGui::DragInt("Directional light shadow texture size", &lightSize);
+		renderer.setDirectionalLightShadowSize(lightSize);
+
+		if (directionalLightSelector < -1)
+		{
+			directionalLightSelector = -1;
+		}
+
+		if (n || directionalLightSelector >= (int)directionalLights.size())
+		{
+			renderer.createDirectionalLight(glm::vec3(0.f));
+		}
+
+		directionalLightSelector
+			= std::min(directionalLightSelector, (int)directionalLights.size() - 1);
+
+		if (remove)
+		{
+			if (directionalLightSelector >= 0)
+			{
+				::gl3d::DirectionalLight light;
+				light.id_ = directionalLights[directionalLightSelector];
+
+				renderer.deleteDirectionalLight(light);
+				directionalLightSelector = std::min(directionalLightSelector, (int)directionalLights.size() - 1);
+			}
+
+		}
+
+		ImGui::NewLine();
+
+		if (directionalLightSelector >= 0)
+		{
+			::gl3d::DirectionalLight light;
+			light.id_ = directionalLights[directionalLightSelector];
+
+			ImGui::PushID(13);
+
+			glm::vec3 color = renderer.getDirectionalLightColor(light);
+			ImGui::ColorEdit3("Color##dir", &color[0]);
+			renderer.setDirectionalLightColor(light, color);
+
+			glm::vec3 direction = renderer.getDirectionalLightDirection(light);
+			ImGui::DragFloat3("Direction##dir", &direction[0], 0.01);
+			renderer.setDirectionalLightDirection(light, direction);
+
+			float hardness = renderer.getDirectionalLightHardness(light);
+			ImGui::SliderFloat("Hardness##dir", &hardness, 0.1, 10);
+			renderer.setDirectionalLightHardness(light, hardness);
+
+			bool castShadows = renderer.getDirectionalLightShadows(light);
+			ImGui::Checkbox("Cast shadows##dir", &castShadows);
+			renderer.setDirectionalLightShadows(light, castShadows);
+
+
+			//ImGui::SliderFloat3("frustumSplit",
+			//	&renderer.directionalShadows.frustumSplits[0], 0, 1);
+
+			ImGui::PopID();
+		}
+	}
+
+	{
+		auto &spotLights = renderer.internal.spotLightIndexes;
+
+		ImGui::NewLine();
+
+		static int spotLightSelector = -1;
+		ImGui::Text("Spot lightd Count %d", spotLights.size());
+		ImGui::InputInt("Current spot light:", &spotLightSelector);
+		int n = ImGui::Button("New Spot Light"); ImGui::SameLine();
+		int remove = ImGui::Button("Remove Spot Light");
+
+		int lightSize = renderer.getSpotLightShadowSize();
+		ImGui::DragInt("Spot light shadow texture size", &lightSize);
+		renderer.setSpotLightShadowSize(lightSize);
+
+		if (spotLightSelector < -1)
+		{
+			spotLightSelector = -1;
+		}
+
+		if (n || spotLightSelector >= (int)spotLights.size())
+		{
+
+			renderer.createSpotLight({0,0,0}, glm::radians(90.f),
+				{0,-1,0});
+		}
+
+		spotLightSelector
+			= std::min(spotLightSelector, (int)spotLights.size() - 1);
+
+		if (remove)
+		{
+			if (spotLightSelector >= 0)
+			{
+				::gl3d::SpotLight light;
+				light.id_ = spotLights[spotLightSelector];
+
+				renderer.deleteSpotLight(light);
+
+				spotLightSelector = std::min(spotLightSelector,
+					(int)renderer.internal.spotLights.size() - 1);
+			}
+
+		}
+
+		ImGui::NewLine();
+
+		if (spotLightSelector >= 0)
+		{
+			ImGui::PushID(14);
+
+			::gl3d::SpotLight light;
+			light.id_ = spotLights[spotLightSelector];
+
+			glm::vec3 color = renderer.getSpotLightColor(light);
+			ImGui::ColorEdit3("Color##spot", &color[0]);
+			renderer.setSpotLightColor(light, color);
+
+			glm::vec3 position = renderer.getSpotLightPosition(light);
+			ImGui::DragFloat3("Position##spot", &position[0], 0.1);
+			renderer.setSpotLightPosition(light, position);
+
+			glm::vec3 direction = renderer.getSpotLightDirection(light);
+			ImGui::DragFloat3("Direction##spot", &direction[0], 0.05);
+			renderer.setSpotLightDirection(light, direction);
+
+			float distance = renderer.getSpotLightDistance(light);
+			ImGui::DragFloat("Distance##spot", &distance, 0.05, 0);
+			renderer.setSpotLightDistance(light, distance);
+
+			float attenuation = renderer.getSpotLightAttenuation(light);
+			ImGui::DragFloat("Attenuation##spot", &attenuation, 0.05, 0);
+			renderer.setSpotLightAttenuation(light, attenuation);
+
+			float hardness = renderer.getSpotLightHardness(light);
+			ImGui::DragFloat("Hardness##spot", &hardness, 0.05, 0, 20);
+			renderer.setSpotLightHardness(light, hardness);
+
+
+			float angle = renderer.getSpotLightFov(light);
+			ImGui::SliderAngle("fov", &angle, 0, 180);
+			renderer.setSpotLightFov(light, angle);
+
+			bool castShadows = renderer.getSpotLightShadows(light);
+			ImGui::Checkbox("Cast shadows##spot", &castShadows);
+			renderer.setSpotLightShadows(light, castShadows);
+
+
+			ImGui::PopID();
+		}
+	}
+
+
+
 	ImGui::PopID();
 }

+ 3 - 0
Pika/core/pikaSTD/engineLibraresSupport/engineGL3DSupport.h

@@ -33,6 +33,9 @@ namespace pika
 
 		void chromaticAberationSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer);
 
+		void lightEditorSettingsWindow(int imguiId, ::gl3d::Renderer3D &renderer);
+
+
 	};
 };
 

+ 50 - 4
Pika/pluggins/pluggins/threeDEditor.h

@@ -7,9 +7,9 @@
 #include <shortcutApi/shortcutApi.h>
 #include <pikaSizes.h>
 #include <imgui_spinner.h>
+#include <imfilebrowser.h>
 #include <engineLibraresSupport/engineGL3DSupport.h>
 
-
 struct ThreeDEditor: public Container
 {
 
@@ -21,11 +21,13 @@ struct ThreeDEditor: public Container
 		info.defaultHeapMemorySize = pika::MB(1000); //todo option to use global allocator
 
 		info.requestImguiFbo = true;
-		info.requestImguiIds = 100;
+		info.requestImguiIds = 1;
 
 		return info;
 	}
 
+	ImGui::FileBrowser fileBrowserSkyBox;
+
 	gl3d::Renderer3D renderer;
 	gl3d::Model model;
 	gl3d::Entity entity;
@@ -73,13 +75,12 @@ struct ThreeDEditor: public Container
 		RequestedContainerInfo &requestedInfo)
 	{
 
-
 		renderer.setErrorCallback(&errorCallbackCustom, &requestedInfo);
 		renderer.fileOpener.userData = &requestedInfo;
 		renderer.fileOpener.readEntireFileBinaryCallback = readEntireFileBinaryCustom;
 		renderer.fileOpener.readEntireFileCallback = readEntireFileCustom;
 		renderer.fileOpener.fileExistsCallback = defaultFileExistsCustom;
-
+	
 
 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 		glEnable(GL_DEPTH_TEST);
@@ -120,6 +121,51 @@ struct ThreeDEditor: public Container
 				pika::gl3d::chromaticAberationSettingsWindow(requestedInfo.requestedImguiIds, renderer);
 			}
 			
+			if (ImGui::CollapsingHeader("lights settings", ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding))
+			{
+				pika::gl3d::lightEditorSettingsWindow(requestedInfo.requestedImguiIds, renderer);
+			}
+
+			if (ImGui::CollapsingHeader("Sky box", ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_FramePadding))
+			{
+
+				if (ImGui::Button("delete skybox"))
+				{
+					renderer.skyBox.clearTextures();
+				}
+
+				if (ImGui::Button("select new skybox"))
+				{
+					fileBrowserSkyBox.SetTitle("Sellect map");
+					fileBrowserSkyBox.SetPwd(PIKA_RESOURCES_PATH);
+					fileBrowserSkyBox.SetTypeFilters({".hdr", ".png"});
+					fileBrowserSkyBox.Open();
+				}
+
+				ImGui::ColorEdit3("Global Ambient color", &renderer.skyBox.color[0]);
+
+			}
+			
+			fileBrowserSkyBox.Display();
+
+			if (fileBrowserSkyBox.HasSelected())
+			{
+				if (fileBrowserSkyBox.GetSelected().extension() == ".hdr")
+				{
+					//todo api to log errors
+					renderer.skyBox.clearTextures();
+					renderer.skyBox = renderer.loadHDRSkyBox(fileBrowserSkyBox.GetSelected().string().c_str());
+				}
+				else if (fileBrowserSkyBox.GetSelected().extension() == ".png")
+				{
+					renderer.skyBox.clearTextures();
+					renderer.skyBox = renderer.loadSkyBox(fileBrowserSkyBox.GetSelected().string().c_str());
+				}
+
+				fileBrowserSkyBox.ClearSelected();
+				fileBrowserSkyBox.Close();
+			}
+
 		}
 		ImGui::End();
 

+ 2 - 4
Pika/resources/logs.txt

@@ -1,4 +1,2 @@
-#2023-02-13 13:46:53: Created container: Gameplay
-#2023-02-13 13:47:09: Created container: ThreeDEditor
-#2023-02-13 13:48:27: Destroyed continer: Gameplay #1
-#2023-02-13 13:48:27: Destroyed continer: ThreeDEditor #2
+#2023-02-13 19:38:43: Created container: Gameplay
+#2023-02-13 19:43:58: Created container: ThreeDEditor