Browse Source

finished steve model

meemknight 2 years ago
parent
commit
0b6f58787a

+ 7 - 1
Pika/core/pikaEditor/assetManagerWindow/assetManagerWindow.cpp

@@ -64,9 +64,11 @@ namespace pika
 		std::string longPath = currentPath.string();
 		std::string longPath = currentPath.string();
 		std::string root = PIKA_RESOURCES_PATH;
 		std::string root = PIKA_RESOURCES_PATH;
 		std::string enginePath = "PIKA_RESOURCES_PATH/";
 		std::string enginePath = "PIKA_RESOURCES_PATH/";
+		std::string copyPath = "";
 		if (longPath.size() > root.size())
 		if (longPath.size() > root.size())
 		{
 		{
 			enginePath += (longPath.c_str() + root.size());
 			enginePath += (longPath.c_str() + root.size());
+			copyPath += (longPath.c_str() + root.size());
 		}
 		}
 
 
 		for (char &c : enginePath)
 		for (char &c : enginePath)
@@ -156,7 +158,11 @@ namespace pika
 
 
 					if (ImGui::Button("copy file location for engine"))
 					if (ImGui::Button("copy file location for engine"))
 					{
 					{
-						std::string s =  "PIKA_RESOURCES_PATH \"" + p.path().filename().string() + "\"";
+						std::string s = "PIKA_RESOURCES_PATH";
+						if (!copyPath.empty())
+						{
+							s += " \"" + copyPath + "\"";
+						}
 
 
 						ImGui::SetClipboardText(s.c_str());
 						ImGui::SetClipboardText(s.c_str());
 						ImGui::CloseCurrentPopup();
 						ImGui::CloseCurrentPopup();

+ 14 - 2
Pika/core/pikaRuntime/containerManager/containerManager.cpp

@@ -229,7 +229,7 @@ pika::containerId_t pika::ContainerManager::createContainer
 	container.requestedContainerInfo.consoleWindow = consoleWindow;
 	container.requestedContainerInfo.consoleWindow = consoleWindow;
 #pragma endregion
 #pragma endregion
 
 
-	pika::StaticString<256> cmdArgs = {};
+	pika::StaticString<256> cmdArgs = {}; //todo magic number
 	
 	
 	if (cmd.size() > cmdArgs.MAX_SIZE)
 	if (cmd.size() > cmdArgs.MAX_SIZE)
 	{
 	{
@@ -288,13 +288,14 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 	
 	
 #pragma endregion
 #pragma endregion
 
 
-	
+	std::vector<CreateContainerInfo> containersToCreate;
 
 
 #pragma region running containers
 #pragma region running containers
 	for (auto &c : runningContainers)
 	for (auto &c : runningContainers)
 	{
 	{
 
 
 		c.second.requestedContainerInfo.consoleWindow = consoleWindow;
 		c.second.requestedContainerInfo.consoleWindow = consoleWindow;
+		c.second.requestedContainerInfo.internal.containersToCreate = &containersToCreate;
 
 
 
 
 		if (c.second.flags.status == pika::RuntimeContainer::FLAGS::STATUS_RUNNING
 		if (c.second.flags.status == pika::RuntimeContainer::FLAGS::STATUS_RUNNING
@@ -574,6 +575,17 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 	}
 	}
 #pragma endregion
 #pragma endregion
 
 
+
+#pragma region create new containers
+
+	for (auto &i : containersToCreate)
+	{
+		createContainer(i.containerName.to_string(), loadedDll, logs, imguiIdManager, consoleWindow, i.cmdArgs.to_string());
+	}
+
+#pragma endregion
+
+
 }
 }
 
 
 void pika::ContainerManager::reloadDll(pika::LoadedDll &loadedDll, pika::PikaWindow &window, pika::LogManager &logs)
 void pika::ContainerManager::reloadDll(pika::LoadedDll &loadedDll, pika::PikaWindow &window, pika::LogManager &logs)

+ 1 - 1
Pika/core/pikaSTD/stringManipulation/stringManipulation.cpp

@@ -70,7 +70,7 @@ namespace pika
 		return size - 1;
 		return size - 1;
 	}
 	}
 
 
-	size_t strlcpy(char *dst, std::string src, size_t size)
+	size_t strlcpy(char *dst, const std::string &src, size_t size)
 	{
 	{
 		return strlcpy(dst, src.c_str(), size);
 		return strlcpy(dst, src.c_str(), size);
 	}
 	}

+ 1 - 1
Pika/core/pikaSTD/stringManipulation/stringManipulation.h

@@ -23,7 +23,7 @@ namespace pika
 	//returns char coppied (will be at max size-1)
 	//returns char coppied (will be at max size-1)
 	size_t strlcpy(char *dst, const char *src, size_t size);
 	size_t strlcpy(char *dst, const char *src, size_t size);
 
 
-	size_t strlcpy(char *dst, std::string src, size_t size);
+	size_t strlcpy(char *dst, const std::string &src, size_t size);
 
 
 
 
 	std::vector<std::string> split(const char *source, char c);
 	std::vector<std::string> split(const char *source, char c);

+ 26 - 0
Pika/core/sharedRuntime/baseContainer.h

@@ -11,6 +11,7 @@
 #include <fstream>
 #include <fstream>
 #include <staticString.h>
 #include <staticString.h>
 #include <vector>
 #include <vector>
+#include <stringManipulation/stringManipulation.h>
 
 
 
 
 #define READENTIREFILE(x) bool x(const char* name, void* buffer, size_t size)
 #define READENTIREFILE(x) bool x(const char* name, void* buffer, size_t size)
@@ -23,6 +24,11 @@ typedef GETFILESIZE(getFileSize_t);
 
 
 static constexpr size_t MaxAllocatorsCount = 128;
 static constexpr size_t MaxAllocatorsCount = 128;
 
 
+struct CreateContainerInfo
+{
+	pika::StaticString<257> containerName = {};
+	pika::StaticString<257> cmdArgs = {};
+};
 
 
 //this is passed by the engine. You should not modify the data
 //this is passed by the engine. You should not modify the data
 //this is also used by the engine to give you acces to some io functions
 //this is also used by the engine to give you acces to some io functions
@@ -85,8 +91,28 @@ struct RequestedContainerInfo
 		decltype(glfwGetWindowPos) *getWindowPosFunc = nullptr;
 		decltype(glfwGetWindowPos) *getWindowPosFunc = nullptr;
 		decltype(glfwSetInputMode) *setInputModeFunc = nullptr;
 		decltype(glfwSetInputMode) *setInputModeFunc = nullptr;
 
 
+		std::vector<CreateContainerInfo> *containersToCreate;
+
 	}internal;
 	}internal;
 
 
+	//resets global allocator!
+	void createContainer(std::string containerName, std::string cmdArgs = "")
+	{
+		PIKA_DEVELOPMENT_ONLY_ASSERT(internal.containersToCreate, "missing containersToCreate pointer");
+		CreateContainerInfo info;
+
+		if (containerName.size() >= info.containerName.MAX_SIZE-1) { return; }
+		if (cmdArgs.size() >= info.cmdArgs.MAX_SIZE-1) { return; }
+
+		info.containerName = {containerName.c_str()};
+		info.cmdArgs = {cmdArgs.c_str()};
+
+		pika::memory::setGlobalAllocatorToStandard();
+		internal.containersToCreate->push_back(info);
+		pika::memory::setGlobalAllocator(mainAllocator);
+
+	}
+
 	//returns true if succeded (can return false if console is disabeled)
 	//returns true if succeded (can return false if console is disabeled)
 	bool consoleWrite(const char* c)
 	bool consoleWrite(const char* c)
 	{
 	{

BIN
Pika/engineResources/engineSaves/windowPos1.bin


BIN
Pika/engineResources/engineSaves/windowPos2.bin


BIN
Pika/engineResources/input.recording


+ 4 - 4
Pika/gameplay/containers/minecraftDungeons/mcDungeons.cpp

@@ -143,11 +143,11 @@ glm::vec2  McDungeonsGameplay::performCollision(Player &player, glm::vec2 pos, g
 
 
 	const float BLOCK_SIZE = 1.f;
 	const float BLOCK_SIZE = 1.f;
 
 
-	minX = (pos.x - abs(delta.x) - BLOCK_SIZE) / BLOCK_SIZE;
-	maxX = ceil((pos.x + abs(delta.x) + BLOCK_SIZE + size.x) / BLOCK_SIZE);
+	minX = (pos.x - abs(delta.x) - BLOCK_SIZE - size.x/2.f) / BLOCK_SIZE;
+	maxX = ceil((pos.x + abs(delta.x) + BLOCK_SIZE + size.x / 2.f) / BLOCK_SIZE);
 
 
-	minY = (pos.y - abs(delta.y) - BLOCK_SIZE) / BLOCK_SIZE;
-	maxY = ceil((pos.y + abs(delta.y) + BLOCK_SIZE + size.y) / BLOCK_SIZE);
+	minY = (pos.y - abs(delta.y) - BLOCK_SIZE - size.y / 2.f) / BLOCK_SIZE;
+	maxY = ceil((pos.y + abs(delta.y) + BLOCK_SIZE + size.y/2.f) / BLOCK_SIZE);
 
 
 	minX = std::max(0, minX);
 	minX = std::max(0, minX);
 	minY = std::max(0, minY);
 	minY = std::max(0, minY);

+ 10 - 0
Pika/gameplay/containers/minecraftDungeons/mcDungeonsEditor.h

@@ -673,6 +673,16 @@ struct McDungeonsEditor: public Container
 		return true;
 		return true;
 	}
 	}
 
 
+	void destruct()
+	{
+
+		this->renderer.clearAllRendererResources();
+		this->renderer.skyBox.clearTextures();
+		this->renderer.colorCorrectionTexture().clear();
+		//this->renderer2d.clear();
+
+	}
+
 };
 };
 
 
 //todo flag to clear screen from engine
 //todo flag to clear screen from engine

+ 39 - 9
Pika/gameplay/containers/minecraftDungeons/mcDungeonsgameplay.h

@@ -51,6 +51,18 @@ struct McDungeonsGameplay: public Container
 
 
 	glm::vec2 performCollision(Player &player, glm::vec2 pos, glm::vec2 size,
 	glm::vec2 performCollision(Player &player, glm::vec2 pos, glm::vec2 size,
 		glm::vec2 delta, bool &upTouch, bool &downTouch, bool &leftTouch, bool &rightTouch);
 		glm::vec2 delta, bool &upTouch, bool &downTouch, bool &leftTouch, bool &rightTouch);
+	gl3d::Entity player;
+
+	enum Animations
+	{
+		attack = 0,
+		idle = 1,
+		run = 2,
+		run2 = 3,
+		zombieAttack = 4,
+		zombieIdle = 5,
+		zombieWalk = 6,
+	};
 
 
 
 
 	gl2d::Renderer2D renderer2d;
 	gl2d::Renderer2D renderer2d;
@@ -59,7 +71,7 @@ struct McDungeonsGameplay: public Container
 	gl3d::Entity entity;
 	gl3d::Entity entity;
 	GLuint blocksTexture;
 	GLuint blocksTexture;
 
 
-	gl3d::Entity player;
+	gl3d::Entity sword;
 
 
 	Player playerPhysics;
 	Player playerPhysics;
 	float rotation = 0;
 	float rotation = 0;
@@ -438,12 +450,22 @@ struct McDungeonsGameplay: public Container
 
 
 
 
 		auto playerModel = renderer.loadModel(PIKA_RESOURCES_PATH "mcDungeons/steve.glb", 0, 1);
 		auto playerModel = renderer.loadModel(PIKA_RESOURCES_PATH "mcDungeons/steve.glb", 0, 1);
-		auto mat = renderer.loadMaterial(PIKA_RESOURCES_PATH "mcDungeons/steve.mtl", 0);
-		if (mat.size() < 1) { return false; }
+		//auto mat = renderer.loadMaterial(PIKA_RESOURCES_PATH "mcDungeons/steve.mtl", 0);
+		//if (mat.size() < 1) { return false; }
 		player = renderer.createEntity(playerModel, gl3d::Transform{glm::vec3{22,13,32}}, false);
 		player = renderer.createEntity(playerModel, gl3d::Transform{glm::vec3{22,13,32}}, false);
-		renderer.setEntityMeshMaterial(player, 0, mat[0]);
+		//{
+		//	int count = renderer.getEntityMeshesCount(player);
+		//	if (!count)return 0;
+		//	for (int i = 0; i < count; i++)
+		//	{
+		//		renderer.setEntityMeshMaterial(player, i, mat[0]);
+		//	}
+		//}
 		renderer.setEntityAnimate(player, true);
 		renderer.setEntityAnimate(player, true);
+		renderer.setEntityAnimationIndex(player, Animations::idle);
 
 
+		auto swordModel = renderer.loadModel(PIKA_RESOURCES_PATH "/mcDungeons/minecraft_sword.glb", gl3d::TextureLoadQuality::maxQuality, 0.1);
+		sword = renderer.createEntity(swordModel, {}, false);
 
 
 		renderer.camera.farPlane = 200;
 		renderer.camera.farPlane = 200;
 		renderer.directionalShadows.frustumSplits[0] = 0.06;
 		renderer.directionalShadows.frustumSplits[0] = 0.06;
@@ -551,12 +573,11 @@ struct McDungeonsGameplay: public Container
 					};
 					};
 					
 					
 					desiredRotation = std::atan2(dir.x, dir.y);
 					desiredRotation = std::atan2(dir.x, dir.y);
-					renderer.setEntityAnimate(player, 0);
-
+					renderer.setEntityAnimationIndex(player, Animations::run);
 				}
 				}
 				else
 				else
 				{
 				{
-					renderer.setEntityAnimate(player, 1);
+					renderer.setEntityAnimationIndex(player, Animations::idle);
 				}
 				}
 
 
 				float speed = 3;
 				float speed = 3;
@@ -626,13 +647,23 @@ struct McDungeonsGameplay: public Container
 			gl3d::Transform t;
 			gl3d::Transform t;
 			t.rotation.y = rotation;
 			t.rotation.y = rotation;
 			t.position = glm::vec3(playerPhysics.position.x, 13, playerPhysics.position.y);
 			t.position = glm::vec3(playerPhysics.position.x, 13, playerPhysics.position.y);
-			t.scale = glm::vec3(0.2);
+			t.scale = glm::vec3(0.5);
 			renderer.setEntityTransform(player, t);
 			renderer.setEntityTransform(player, t);
 			glm::vec3 playerPos = t.position;
 			glm::vec3 playerPos = t.position;
 			glm::vec3 cameraViewDir = glm::normalize(glm::vec3(-1, 1.7, 1));
 			glm::vec3 cameraViewDir = glm::normalize(glm::vec3(-1, 1.7, 1));
 			glm::vec3 cameraPos = playerPos + cameraViewDir * 12.f;
 			glm::vec3 cameraPos = playerPos + cameraViewDir * 12.f;
 		#pragma endregion
 		#pragma endregion
 
 
+		#pragma region sword
+			{
+				gl3d::Transform t;
+				renderer.getEntityJointTransform(player, "arm.r", t);
+				t.scale = glm::vec3(1);
+				renderer.setEntityTransform(sword, t);
+			}
+		#pragma endregion
+
+
 		#pragma region camera hover
 		#pragma region camera hover
 			{
 			{
 				static float cameraYoffset = 0;
 				static float cameraYoffset = 0;
@@ -698,7 +729,6 @@ struct McDungeonsGameplay: public Container
 		glDisable(GL_DEPTH_TEST);
 		glDisable(GL_DEPTH_TEST);
 
 
 
 
-		renderer2d.renderRectangle({windowState.w / 2 - 5, windowState.h / 2 - 5,10,10}, Colors_Orange);
 
 
 
 
 		renderer2d.flush();
 		renderer2d.flush();

+ 4 - 5
Pika/gameplay/containers/pikaGameplay.h

@@ -74,10 +74,10 @@ struct Gameplay : public Container
 		//	requestedInfo.consoleWrite("save\n");
 		//	requestedInfo.consoleWrite("save\n");
 		//}
 		//}
 
 
-		//if (input.buttons[pika::Button::G].released())
-		//{
-		//	return 0;
-		//}
+		if (input.buttons[pika::Button::G].released())
+		{
+			requestedInfo.createContainer("Gameplay");
+		}
 
 
 		requestedInfo.consoleWrite(input.typedInput);
 		requestedInfo.consoleWrite(input.typedInput);
 
 
@@ -107,7 +107,6 @@ struct Gameplay : public Container
 			Colors_Red, {}, 0.f);
 			Colors_Red, {}, 0.f);
 
 
 
 
-
 		//requestedInfo.consoleWrite((std::string("Mouse: ") + std::to_string(input.mouseX) + " " +
 		//requestedInfo.consoleWrite((std::string("Mouse: ") + std::to_string(input.mouseX) + " " +
 		//	std::to_string(input.mouseY) + "\n").c_str());
 		//	std::to_string(input.mouseY) + "\n").c_str());
 
 

+ 1 - 1
Pika/resources/3d/default.gl3d

@@ -1 +1 @@
-{"SSR":false,"SSRdata":{"maxRayDelta":0.6000000238418579,"maxRayStep":1.75,"maxSteps":20,"minRayStep":0.4000000059604645,"numBinarySearchSteps":7},"adaptiveResolution":false,"chromaticAberation":false,"chromaticAberationData":{"strength":20.0,"unfocusDistance":5.0},"exposure":1.7000000476837158,"frustumCulling":true,"fxaa":false,"fxaaData":{"edgeDarkTreshold":0.125,"edgeMinTreshold":0.02800000086426735,"iterations":12,"qualityMultiplyer":0.800000011920929,"subPixelQuality":0.949999988079071},"light subscatter":true,"normal mapping":true,"ssao":false,"ssaoData":{"bias":0.02500000037252903,"exponent":5.0,"radius":0.20000000298023224,"sampleCount":16}}
+{"SSR":false,"SSRdata":{"maxRayDelta":0.6000000238418579,"maxRayStep":1.75,"maxSteps":20,"minRayStep":0.4000000059604645,"numBinarySearchSteps":7},"adaptiveResolution":false,"chromaticAberation":false,"chromaticAberationData":{"strength":20.0,"unfocusDistance":5.0},"colorCorrection":false,"exposure":1.7000000476837158,"frustumCulling":true,"fxaa":false,"fxaaData":{"edgeDarkTreshold":0.125,"edgeMinTreshold":0.02800000086426735,"iterations":12,"qualityMultiplyer":0.800000011920929,"subPixelQuality":0.949999988079071},"light subscatter":true,"normal mapping":true,"ssao":true,"ssaoData":{"bias":0.02500000037252903,"exponent":5.0,"radius":0.20000000298023224,"sampleCount":16}}

+ 8 - 1
Pika/resources/logs.txt

@@ -1 +1,8 @@
-#2023-03-02 17:33:52: Created container: Gameplay
+#2023-03-11 10:09:39: Created container: Gameplay
+#2023-03-11 10:09:45: Created container: McDungeonsGameplay
+#2023-03-11 10:10:06: Reloaded dll
+#2023-03-11 10:10:50: Reloaded dll
+#2023-03-11 10:11:23: Reloaded dll
+#2023-03-11 10:12:15: Reloaded dll
+#2023-03-11 10:12:44: Destroyed continer: Gameplay #1
+#2023-03-11 10:12:45: Destroyed continer: McDungeonsGameplay #2

BIN
Pika/resources/mcDungeons/map1.mcDungeons


BIN
Pika/resources/mcDungeons/minecraft_sword.glb


BIN
Pika/resources/mcDungeons/steve.glb


+ 142 - 9
Pika/thirdparty/gl3d/gl3d.cpp

@@ -1,6 +1,6 @@
 ////////////////////////////////////////////////
 ////////////////////////////////////////////////
-//gl32 --Vlad Luta -- 
-//built on 2023-02-28
+//gl3D --Vlad Luta -- 
+//built on 2023-03-07
 ////////////////////////////////////////////////
 ////////////////////////////////////////////////
 
 
 #include "gl3d.h"
 #include "gl3d.h"
@@ -36318,6 +36318,7 @@ namespace gl3d
 #include <random>
 #include <random>
 #include <string>
 #include <string>
 
 
+#include <glm/gtx/matrix_decompose.hpp>
 
 
 #ifdef _MSC_VER
 #ifdef _MSC_VER
 //#pragma warning( disable : 4244 4305 4267 4996 4018)
 //#pragma warning( disable : 4244 4305 4267 4996 4018)
@@ -38621,6 +38622,68 @@ namespace gl3d
 		return en.canBeAnimated();
 		return en.canBeAnimated();
 	}
 	}
 
 
+	int Renderer3D::getEntityJointIndex(Entity &e, std::string name)
+	{
+		auto i = internal.getEntityIndex(e);
+		if (i < 0) { return -1; } //warn or sthing
+		
+		auto &en = internal.cpuEntities[i];
+
+		int index = 0;
+		for (auto &j : en.joints)
+		{
+			if (j.name == name)
+			{
+				return index;
+			}
+			index++;
+		}
+		return -1;
+	}
+
+	bool Renderer3D::getEntityJointTransform(Entity &e, std::string boneName, Transform &t)
+	{
+		return getEntityJointTransform(e, getEntityJointIndex(e, boneName), t);
+	}
+
+	bool Renderer3D::getEntityJointTransform(Entity &e, int boneIndex, Transform &t)
+	{
+		t = {};
+		if (boneIndex < 0) { return false; }
+
+
+		auto i = internal.getEntityIndex(e);
+		if (i < 0) { return -1; } //warn or sthing
+		auto &en = internal.cpuEntities[i];
+		
+		if (en.joints.size() <= boneIndex)
+		{
+			return false;
+		}
+
+		//if (!en.animate())
+		//{
+		//	Transform t;
+		//
+		//	t.position = en.joints[boneIndex].trans;
+		//	t.scale = en.joints[boneIndex].scale;
+		//	t.rotation = glm::eulerAngles(en.joints[boneIndex].rotation);
+		//
+		//	glm::mat4 mat = t.getTransformMatrix();
+		//	mat = getTransformMatrix(en.transform) * mat;
+		//	t.setFromMatrix(mat);
+		//	return true;
+		//}
+		//else
+		{
+			glm::mat4 mat = en.joints[boneIndex].worldMatrix;
+			mat = getTransformMatrix(en.transform) * mat;
+			t.setFromMatrix(mat);
+			return true;
+		}
+		
+	}
+
 	void Renderer3D::setExposure(float exposure)
 	void Renderer3D::setExposure(float exposure)
 	{
 	{
 		internal.lightShader.lightPassUniformBlockCpuData.exposure =
 		internal.lightShader.lightPassUniformBlockCpuData.exposure =
@@ -39657,6 +39720,24 @@ namespace gl3d
 
 
 	};
 	};
 
 
+	void applyPoseToJointsForExtractingPositions(
+		std::vector<glm::mat4> &skinningMatrixes,
+		std::vector<Joint> &joints, int index,
+		glm::mat4 parentTransform
+	)
+	{
+		auto currentLocalTransform = skinningMatrixes[index];
+		auto worldSpaceTransform = parentTransform * currentLocalTransform;
+
+		auto &j = joints[index];
+		for (auto &c : j.children)
+		{
+			applyPoseToJointsForExtractingPositions(skinningMatrixes, joints, c, worldSpaceTransform);
+		}
+
+		joints[index].worldMatrix = worldSpaceTransform * j.localBindTransform;
+
+	};
 
 
 	ColorLookupTexture Renderer3D::loadColorLookupTextureFromFile(const char *path)
 	ColorLookupTexture Renderer3D::loadColorLookupTextureFromFile(const char *path)
 	{
 	{
@@ -39841,7 +39922,8 @@ namespace gl3d
 									float interpolate;
 									float interpolate;
 								};
 								};
 
 
-								auto searchFrame = [&](auto& frames, float time)
+								//trans, rot, scale
+								auto searchFrame = [&](auto& frames, float time, int type)
 								{
 								{
 									
 									
 									int size = frames.size();
 									int size = frames.size();
@@ -39870,9 +39952,55 @@ namespace gl3d
 											}
 											}
 											else
 											else
 											{
 											{
-												float secondTime = animation.keyFramesRot[b][frame + 1].timeStamp;
-												float interpolation = (time - currentFrame.timeStamp) / (secondTime - currentFrame.timeStamp);
-												return FoundFrames{frame, frame + 1, interpolation};
+												float secondTime = 0;
+
+												if (type == 0)
+												{
+													if (animation.keyFramesTrans[b].size() <= frame + 1)
+													{
+														secondTime = 0;
+													}else
+													{
+														secondTime = animation.keyFramesTrans[b][frame + 1].timeStamp;
+													}
+												}
+												else if (type == 1)
+												{
+													if (animation.keyFramesRot[b].size() <= frame + 1)
+													{
+														secondTime = 0;
+													}
+													else
+													{
+														secondTime = animation.keyFramesRot[b][frame + 1].timeStamp;
+													}
+												}
+												else if (type == 2)
+												{
+													if (animation.keyFramesScale[b].size() <= frame + 1)
+													{
+														secondTime = 0;
+													}
+													else
+													{
+														secondTime = animation.keyFramesScale[b][frame + 1].timeStamp;
+													}
+												}
+												else
+												{
+													assert(0);
+												}
+
+												if (secondTime != 0)
+												{
+													float interpolation = (time - currentFrame.timeStamp) / (secondTime - currentFrame.timeStamp);
+													return FoundFrames{frame, frame + 1, interpolation};
+												}
+												else
+												{
+													//last frame reached
+													return FoundFrames{frame, frame, 0};
+												}
 											}
 											}
 										}
 										}
 										else //not found this time
 										else //not found this time
@@ -39913,7 +40041,7 @@ namespace gl3d
 								{
 								{
 									if (!animation.keyFramesRot[b].empty())
 									if (!animation.keyFramesRot[b].empty())
 									{
 									{
-										auto foundFrames = searchFrame(animation.keyFramesRot[b], time);
+										auto foundFrames = searchFrame(animation.keyFramesRot[b], time, 1);
 
 
 										rotation = glm::slerp(
 										rotation = glm::slerp(
 											animation.keyFramesRot[b][foundFrames.id1].rotation,
 											animation.keyFramesRot[b][foundFrames.id1].rotation,
@@ -39931,7 +40059,7 @@ namespace gl3d
 									if (!animation.keyFramesTrans[b].empty())
 									if (!animation.keyFramesTrans[b].empty())
 									{
 									{
 
 
-										auto foundFrames = searchFrame(animation.keyFramesTrans[b], time);
+										auto foundFrames = searchFrame(animation.keyFramesTrans[b], time, 0);
 
 
 										translation = lerp(
 										translation = lerp(
 											animation.keyFramesTrans[b][foundFrames.id1].translation,
 											animation.keyFramesTrans[b][foundFrames.id1].translation,
@@ -39950,7 +40078,7 @@ namespace gl3d
 									if (!animation.keyFramesScale[b].empty())
 									if (!animation.keyFramesScale[b].empty())
 									{
 									{
 
 
-										auto foundFrames = searchFrame(animation.keyFramesScale[b], time);
+										auto foundFrames = searchFrame(animation.keyFramesScale[b], time, 2);
 
 
 										scale = lerp(
 										scale = lerp(
 											animation.keyFramesScale[b][foundFrames.id1].scale,
 											animation.keyFramesScale[b][foundFrames.id1].scale,
@@ -40031,6 +40159,11 @@ namespace gl3d
 								r, glm::mat4(1.f));
 								r, glm::mat4(1.f));
 						}
 						}
 
 
+						for (auto r : animation.root)
+						{
+							applyPoseToJointsForExtractingPositions(skinningMatrixes, entity.joints, r, glm::mat4(1.f));
+						}
+
 					#pragma region save animation data to the gpu
 					#pragma region save animation data to the gpu
 						glBindBuffer(GL_SHADER_STORAGE_BUFFER, entity.appliedSkinningMatricesBuffer);
 						glBindBuffer(GL_SHADER_STORAGE_BUFFER, entity.appliedSkinningMatricesBuffer);
 						glBufferData(GL_SHADER_STORAGE_BUFFER, appliedSkinningMatrixes.size() * sizeof(glm::mat4),
 						glBufferData(GL_SHADER_STORAGE_BUFFER, appliedSkinningMatrixes.size() * sizeof(glm::mat4),

+ 7 - 3
Pika/thirdparty/gl3d/gl3d.h

@@ -1,6 +1,6 @@
 ////////////////////////////////////////////////
 ////////////////////////////////////////////////
-//gl32 --Vlad Luta -- 
-//built on 2023-02-28
+//gl3D --Vlad Luta -- 
+//built on 2023-03-07
 ////////////////////////////////////////////////
 ////////////////////////////////////////////////
 
 
 
 
@@ -318,6 +318,7 @@ namespace gl3d
 		glm::quat rotation{ 0.f,0.f,0.f,1.f };
 		glm::quat rotation{ 0.f,0.f,0.f,1.f };
 		glm::vec3 trans{ 1.f,1.f,1.f };
 		glm::vec3 trans{ 1.f,1.f,1.f };
 		glm::vec3 scale{ 1.f,1.f,1.f };
 		glm::vec3 scale{ 1.f,1.f,1.f };
+		glm::mat4 worldMatrix; //for extracting position data per bone
 
 
 		//int index{};
 		//int index{};
 		//int root = 0;
 		//int root = 0;
@@ -34792,7 +34793,10 @@ namespace gl3d
 		void setEntityAnimate(Entity& e, bool animate); //true = display animations. To pause set the animation speed to 0.
 		void setEntityAnimate(Entity& e, bool animate); //true = display animations. To pause set the animation speed to 0.
 		bool getEntityAnimate(Entity& e); //returns true if it is animating
 		bool getEntityAnimate(Entity& e); //returns true if it is animating
 		bool entityCanAnimate(Entity& e); //returns true if it is can be animated
 		bool entityCanAnimate(Entity& e); //returns true if it is can be animated
+		int getEntityJointIndex(Entity &e, std::string name); //returns -1 on error
 
 
+		bool getEntityJointTransform(Entity &e, std::string boneName, Transform &t); //returns 0 on error
+		bool getEntityJointTransform(Entity &e, int boneIndex, Transform &t); //returns 0 on error
 
 
 		//this is used for apis like imgui.
 		//this is used for apis like imgui.
 		std::vector<char*> *getEntityMeshesNames(Entity& e);
 		std::vector<char*> *getEntityMeshesNames(Entity& e);
@@ -34926,7 +34930,7 @@ namespace gl3d
 
 
 			glm::ivec2 currentDimensions = {};
 			glm::ivec2 currentDimensions = {};
 
 
-			bool colorCorrection = 0;
+			bool colorCorrection = 0; //todo also check if texture is present
 
 
 			void create(int w, int h, ErrorReporter &errorReporter, FileOpener &fileOpener);
 			void create(int w, int h, ErrorReporter &errorReporter, FileOpener &fileOpener);