Esempio n. 1
0
/*****************************************************************
* ProcessLevelNode()	Processes a single fbx node and loads in appropiate data
*
* Ins:					node
*
* Outs:					meshes
*
* Returns:				bool
*
* Mod. Date:		    09/02/2015
* Mod. Initials:	    NH
*****************************************************************/
bool CLevelLoader::ProcessLevelNode(FbxNode* node, vector<CMesh>& meshes)
{
	FbxNodeAttribute* attribute = node->GetNodeAttribute();

	if (attribute != NULL)
	{
		if (attribute->GetAttributeType() == FbxNodeAttribute::eMesh)
		{
			CMesh* tempMesh = new CMesh;
			FbxMesh* attributeMesh = (FbxMesh*)attribute;
			CAssetManager * assetManager = CAssetManager::GetInstance();

			bool errorCheck = assetManager->LoadMesh(attributeMesh, *tempMesh);
			if (errorCheck == false)
			{
				attribute->Destroy();
				return false;
			}

			//now get prefix and apply texture, collision, etc...
			const char* objName = node->GetName();
			std::string prefix = "    ";

			for (unsigned int i = 0; i < 4; i++)
			{
				prefix[i] = objName[i];
			}

			if (strcmp(prefix.c_str(), "Wal_") == 0)//wall prefab
			{
				tempMesh->ConvertVertices();

				CWallObject* tempWall = new CWallObject("Wall");
				tempWall->AddCollider(new CCollider(false, Bounds::AABB, tempMesh->GetVertices()));
				tempWall->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetNormalMapPS(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Maze_Wall.dds"));
				tempWall->GetRenderMesh()->SetNormals(L"../Game/Assets/Art/2D/Normal Maps/Rocky.dds");
				tempWall->GetRenderMesh()->GetSpecular() = 0.5f;

				m_cpEnvironmentObjects.push_back(tempWall);

				m_cpObjectManager->AddObject(tempWall, CObjectManager::eObjectType::Static);
			}
			else if (strcmp(prefix.c_str(), "Flr_") == 0)//floor prefab
			{
				tempMesh->ConvertVertices();

				CFloorObject* tempFloor = new CFloorObject("Floor");
				tempFloor->AddCollider(new CCollider(false, Bounds::Plane, tempMesh->GetVertices()));
				tempFloor->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetNormalMapPS(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Maze_Ground.dds"));
				tempFloor->GetRenderMesh()->SetNormals(L"../Game/Assets/Art/2D/Normal Maps/Rocky.dds");
				tempFloor->GetRenderMesh()->GetSpecular() = 1.5f;

				m_cpEnvironmentObjects.push_back(tempFloor);

				m_cpObjectManager->AddObject(tempFloor, CObjectManager::eObjectType::Static);
			}
			else if (strcmp(prefix.c_str(), "Grd_") == 0)//ground prefab(around pits)
			{
				tempMesh->ConvertVertices();
				
				/*
				float f3Min[3] =
				{
					FLT_MAX,
					FLT_MAX,
					FLT_MAX
				};

				float f3Max[3] =
				{
					-FLT_MAX,
					-FLT_MAX,
					-FLT_MAX
				};

				for (unsigned int i = 0; i < tempMesh->GetVertices().size(); i++)
				{
					for (unsigned int xyz = 0; xyz < 3; xyz++)
					{
						if (tempMesh->GetVertices()[i].m_fPosition[xyz] < f3Min[xyz])
						{
							f3Min[xyz] = tempMesh->GetVertices()[i].m_fPosition[xyz];
						}
						if (tempMesh->GetVertices()[i].m_fPosition[xyz] > f3Max[xyz])
						{
							f3Max[xyz] = tempMesh->GetVertices()[i].m_fPosition[xyz];
						}
					}
				}

				XMFLOAT3 f3Center;
				f3Center.x = (f3Min[0] + f3Max[0]) / 2.0f;
				f3Center.y = (f3Min[1] + f3Max[1]) / 2.0f;
				f3Center.z = (f3Min[2] + f3Max[2]) / 2.0f;

				f3Center.y -= 20.0f;

				XMFLOAT3 f3Extents;
				f3Extents.x = f3Max[0] - f3Center.x;
				f3Extents.y = f3Max[1] - f3Center.y;
				f3Extents.z = f3Max[2] - f3Center.z;


				CBounds* tempBounds = new CAABB(f3Center, f3Extents);
				*/

				CPitWallObject* tempPitWall = new CPitWallObject("PitWall");
				//tempPitWall->AddCollider(new CCollider(false, tempBounds, true));
				tempPitWall->AddCollider(new CCollider(false, Bounds::AABB, tempMesh->GetVertices()));
				tempPitWall->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetNormalMapPS(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Maze_Ground.dds"));
				tempPitWall->GetRenderMesh()->SetNormals(L"../Game/Assets/Art/2D/Normal Maps/Rocky.dds");
				tempPitWall->GetRenderMesh()->GetSpecular() = 1.5f;

				//try moving collider down
				//XMFLOAT3 newCenter = ((CAABB*)(tempPitWall->GetColliders()[0]->GetBounds()))->GetCenter();
				//newCenter.y -= 20.0f;
				//((CAABB*)(tempPitWall->GetColliders()[0]->GetBounds()))->SetCenter(newCenter);

				m_cpEnvironmentObjects.push_back(tempPitWall);

				m_cpObjectManager->AddObject(tempPitWall, CObjectManager::eObjectType::Static);
			}
			else if (strcmp(prefix.c_str(), "Dor_") == 0)//door prefab
			{
				//tempMesh->ConvertVertices();
				//
				//CDoorObject* tempDoor = new CDoorObject("Door");
				////tempDoor->
				////tempDoor->
				//
				//m_cpEnvironmentObjects.push_back(tempDoor);
				//
				//m_cpObjectManager->AddObject(tempDoor, CObjectManager::eObjectType::Dynamic);
			}
			else if (strcmp(prefix.c_str(), "Pit_") == 0)//pit bottom prefab
			{
				tempMesh->ConvertVertices();

				CPitObject* tempPit = new CPitObject("Pit");
				tempPit->AddCollider(new CCollider(false, Bounds::Plane, tempMesh->GetVertices()));
				tempPit->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetNormalMapPS(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Maze_Ground.dds"));
				tempPit->GetRenderMesh()->SetNormals(L"../Game/Assets/Art/2D/Normal Maps/Rocky.dds");
				tempPit->GetRenderMesh()->GetSpecular() = 1.5f;

				m_cpEnvironmentObjects.push_back(tempPit);

				m_cpObjectManager->AddObject(tempPit, CObjectManager::eObjectType::Static);
			}
			else if (strcmp(prefix.c_str(), "BPT_") == 0)//big pit bottom prefab
			{
				tempMesh->ConvertVertices();

				CPitObject* tempBigPit = new CPitObject("BigPit");
				tempBigPit->AddCollider(new CCollider(false, Bounds::Plane, tempMesh->GetVertices()));
				tempBigPit->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetNormalMapPS(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Maze_Ground.dds"));
				tempBigPit->GetRenderMesh()->SetNormals(L"../Game/Assets/Art/2D/Normal Maps/Rocky.dds");
				tempBigPit->GetRenderMesh()->GetSpecular() = 1.5f;

				m_cpEnvironmentObjects.push_back(tempBigPit);
				m_cpBigPitObjects.push_back(tempBigPit);

				m_cpObjectManager->AddObject(tempBigPit, CObjectManager::eObjectType::Static);

				//now create teleporter for this bridge location
				XMFLOAT3 teleportPoint = { 0.0f, 0.0f, 0.0f };

				if (((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetExtents().x > ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetExtents().z)
				{
					teleportPoint.x = ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetCenter().x + 1000.0f;
					teleportPoint.y = ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetCenter().y + 1000.0f;
					teleportPoint.z = ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetCenter().z;
				}
				else
				{
					teleportPoint.x = ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetCenter().x;
					teleportPoint.y = ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetCenter().y + 1000.0f;
					teleportPoint.z = ((CPlane*)(tempBigPit->GetColliders()[0]->GetBounds()))->GetCenter().z + 1000.0f;
				}

				CWaypointObject* bridgeTeleport = new CWaypointObject("BridgeTeleporter");
				bridgeTeleport->SetPosition(teleportPoint);

				m_cpBridgeTeleporters.push_back(bridgeTeleport);
			}
			else if (strcmp(prefix.c_str(), "Ext_") == 0)//exit door
			{
				m_cvExitDoorMeshes.push_back(*tempMesh);
			}
			else if (strcmp(prefix.c_str(), "GFL_") == 0)//grass floor
			{
				tempMesh->ConvertVertices();

				CFloorObject* tempGrassFloor = new CFloorObject("SafeHavenFloor");
				tempGrassFloor->AddCollider(new CCollider(false, Bounds::Plane, tempMesh->GetVertices()));
				tempGrassFloor->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetPixelShader(), nullptr, nullptr, nullptr, L"../Game/Assets/Art/2D/Textures/Ground_Grass.dds"));

				m_cpEnvironmentObjects.push_back(tempGrassFloor);

				m_cpObjectManager->AddObject(tempGrassFloor, CObjectManager::eObjectType::Static);
			}
			else if (strcmp(prefix.c_str(), "Skl_") == 0)//skeleton spawn point
			{
				tempMesh->ConvertVertices();
				XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices());

				CSpawnerObject* tempSpawner = new CSpawnerObject("SkeletonSpawn");
				tempSpawner->GetSpawnPosition() = tempPos;

				m_cpSkeletonSpawnObjects.push_back(tempSpawner);
			}
			else if (strcmp(prefix.c_str(), "Orc_") == 0)//orc spawn point
			{
				tempMesh->ConvertVertices();
				XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices());
				
				CSpawnerObject* tempSpawner = new CSpawnerObject("OrcSpawn");
				tempSpawner->GetSpawnPosition() = tempPos;

				
				m_cpOrcSpawnObjects.push_back(tempSpawner);
			}
			else if (strcmp(prefix.c_str(), "ECS_") == 0)//enemy cave spawners
			{
			}
			else if (strcmp(prefix.c_str(), "Min_") == 0)//minotaur spawn point
			{
				tempMesh->ConvertVertices();
				XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices());

				CSpawnerObject* tempSpawner = new CSpawnerObject("MinotaurSpawn");
				tempSpawner->GetSpawnPosition() = tempPos;


				m_cpMinotaurSpawnObjects.push_back(tempSpawner);
			}
			else if (strcmp(prefix.c_str(), "Mpt_") == 0)//minotaur waypoints
			{
#pragma region Minotaur Waypoints

				string tempName = "                             ";
				for (int i = 4; i < 30; i++)
				{
					tempName[i] = objName[i];

					if ((int)objName[i] == 'e')
					{
						break;
					}
				}

				//get waypoint ID
				int firstNum = (int)tempName[4] - 48;
				int secondNum = (int)tempName[5] - 48;
				int thirdNum = (int)tempName[6] - 48;

				int WayPointID = (firstNum * 100) + (secondNum * 10) + thirdNum;

				//get adjacent waypoint IDs
				int AdjacentIDs[4] = { -1, -1, -1, -1 };
				int nextAdjacent = 0;

				for (int i = 7; i < 30; i++)
				{
					if ((int)tempName[i] == '_')
					{
						nextAdjacent++;
						continue;
					}
					if ((int)tempName[i] == 'e')
					{
						break;
					}

					int firstNum = (int)tempName[i] - 48;
					int secondNum = (int)tempName[i + 1] - 48;
					int thirdNum = (int)tempName[i + 2] - 48;

					AdjacentIDs[nextAdjacent] = (firstNum * 100) + (secondNum * 10) + thirdNum;
					if (AdjacentIDs[nextAdjacent] >= 147)
					{
						break;
					}
					i += 2;
				}

				//create node
				tempMesh->ConvertVertices();
				XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices());
				CNode* tempNode = new CNode(WayPointID, tempPos);

				//create and add edges
				for (unsigned int i = 0; i < 4; i++)
				{
					if (AdjacentIDs[i] == -1)
					{
						continue;
					}

					tempNode->addEdge(new CEdge(1.0f, AdjacentIDs[i]));
				}

				//add node to navgraph
				m_cpMinotaurNavGraph->AddNode(tempNode);

#pragma endregion
			}
			else if (strcmp(prefix.c_str(), "CWL_") == 0)//cracked wall location
			{
				//tempMesh->ConvertVertices();

				//CCrackedWall* tempCrackedWall = new CCrackedWall("CrackedWall");
				//tempCrackedWall->AddCollider(new CCollider(false, Bounds::AABB, tempMesh->GetVertices()));
				//tempCrackedWall->SetRenderMesh(new CRenderMesh(tempMesh->GetIndices(), tempMesh->GetVertices(), GRAPHICS->GetVertexShader(), GRAPHICS->GetPixelShader(), nullptr, nullptr, nullptr));

				//m_cpEnvironmentObjects.push_back(tempCrackedWall);

				//m_cpObjectManager->AddObject(tempCrackedWall, CObjectManager::eObjectType::Static);
			}
			else if (strcmp(prefix.c_str(), "LWC_") == 0)//light weapon upgrade chest location
			{
			}
			else if (strcmp(prefix.c_str(), "HWC_") == 0)//heavy weapon upgrade chest location
			{
			}
			else if (strcmp(prefix.c_str(), "HUC_") == 0)//health upgrade chest location
			{
			}
			else if (strcmp(prefix.c_str(), "Tor_") == 0)//torch location
			{
#pragma region Torches

				std::string tempName = "            ";
				for (unsigned int i = 4; i < 12; i++)
				{
					tempName[i] = objName[i];
				}

				XMFLOAT3 tiltDirection = { 0, 0, 0 };

				//get x value
				int secondNum = (int)tempName[5] - 48;
				if (tempName[4] == 'n')
				{
					tiltDirection.x = -((float)secondNum);
				}
				else
				{
					tiltDirection.x = (float)secondNum;
				}

				//get y value
				secondNum = (int)tempName[8] - 48;
				if (tempName[7] == 'n')
				{
					tiltDirection.y = -((float)secondNum);
				}
				else
				{
					tiltDirection.y = (float)secondNum;
				}

				//get z value
				secondNum = (int)tempName[11] - 48;
				if (tempName[10] == 'n')
				{
					tiltDirection.z = -((float)secondNum);
				}
				else
				{
					tiltDirection.z = (float)secondNum;
				}

				tempMesh->ConvertVertices();
				XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices());

				m_cpTorchObjects.push_back(new CTorch(m_cpObjectManager, tempPos, tiltDirection));

#pragma endregion
			}
			else if (strcmp(prefix.c_str(), "STL_") == 0)//pressure plate spike trap
			{
				tempMesh->ConvertVertices();
				XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices());

				m_cpSpikeTrapObjects.push_back(new CSpikeTrap(tempPos, true, 0.0f, 1.0f));
			}
			else if (strcmp(prefix.c_str(), "AST_") == 0)//alternating spike trap
			{
				std::string tempName = "          ";
				for (unsigned int i = 4; i < 9; i++)
				{
					tempName[i] = objName[i];
				}

				int firstNum = (int)tempName[4] - 48;
				int secondNum = (int)tempName[5] - 48;

				float startTime = (float)firstNum + ((float)secondNum / 10.0f);

				firstNum = (int)tempName[7] - 48;
				secondNum = (int)tempName[8] - 48;

				float offsetTime = (float)firstNum + ((float)secondNum / 10.0f);

				tempMesh->ConvertVertices();
				XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices());

				m_cpAltSpikeTrapObjects.push_back(new CSpikeTrap(tempPos, false, startTime, offsetTime));
			}
			else if (strcmp(prefix.c_str(), "SBT_") == 0)//spinning blade trap
			{
				std::string tempName = "        ";
				for (unsigned int i = 4; i < 7; i++)
				{
					tempName[i] = objName[i];
				}

				int firstNum = (int)tempName[4] - 48;
				int secondNum = (int)tempName[5] - 48;

				float rotationTime = (float)firstNum + ((float)secondNum / 10.0f);

				tempMesh->ConvertVertices();
				XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices());

				m_cpSpinningBladeObjects.push_back(new CSpinningBlade(tempPos, rotationTime));
			}
			else if (strcmp(prefix.c_str(), "FTE_") == 0)//fire trap emmiter
			{
#pragma region Fire Trap

				std::string tempName = "            ";
				for (unsigned int i = 4; i < 12; i++)
				{
					tempName[i] = objName[i];
				}

				XMFLOAT3 fireDirection = { 0, 0, 0 };

				int secondNum = (int)tempName[5] - 48;
				if (tempName[4] == 'n')
				{
					fireDirection.x = -((float)secondNum);
				}
				else
				{
					fireDirection.x = (float)secondNum;
				}

				secondNum = (int)tempName[8] - 48;
				if (tempName[7] == 'n')
				{
					fireDirection.y = -((float)secondNum);
				}
				else
				{
					fireDirection.y = (float)secondNum;
				}

				secondNum = (int)tempName[11] - 48;
				if (tempName[10] == 'n')
				{
					fireDirection.z = -((float)secondNum);
				}
				else
				{
					fireDirection.z = (float)secondNum;
				}

				tempMesh->ConvertVertices();
				XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices());

				m_cpFireTrapObjects.push_back(new CFireTrap(m_cpObjectManager, tempPos, fireDirection));

#pragma endregion
			}
			else if (strcmp(prefix.c_str(), "Tre_") == 0)//cuttable trees
			{
			}
			else if (strcmp(prefix.c_str(), "Bsh_") == 0)//bushes
			{
				tempMesh->ConvertVertices();
				XMFLOAT3 tempPos = GetAABBCentroid(tempMesh->GetVertices());

				m_cpBushObjects.push_back(new CBush(m_cpObjectManager, tempPos));
			}
			else if (strcmp(prefix.c_str(), "EDT_") == 0)//exit door teleporters
			{
				m_cvExitTeleporterMeshes.push_back(*tempMesh);
			}
			else if (strcmp(prefix.c_str(), "Inv_") == 0)//invisible walls
			{
				tempMesh->ConvertVertices();

				CWallObject* tempWall = new CWallObject("Wall");
				tempWall->AddCollider(new CCollider(false, Bounds::AABB, tempMesh->GetVertices()));
				tempWall->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetPixelShader()));
				tempWall->GetRenderMesh()->GetRender() = false;

				m_cpInvisibleWallObjects.push_back(tempWall);

				m_cpObjectManager->AddObject(tempWall, CObjectManager::eObjectType::Static);
			}
			else if (strcmp(prefix.c_str(), "Kil_") == 0)//kill floor
			{
				tempMesh->ConvertVertices();

				CFloorObject* tempFloor = new CFloorObject("KillFloor");
				tempFloor->AddCollider(new CCollider(false, Bounds::Plane, tempMesh->GetVertices()));
				tempFloor->SetRenderMesh(new CRenderMesh(tempMesh, GRAPHICS->GetVertexShader(), GRAPHICS->GetPixelShader()));
				tempFloor->GetRenderMesh()->GetRender() = false;

				m_cpKillFloorObjects.push_back(tempFloor);

				m_cpObjectManager->AddObject(tempFloor, CObjectManager::eObjectType::Static);
			}
			else
			{
				meshes.push_back(*tempMesh);
			}

			attributeMesh->Destroy();
			delete tempMesh;
		}
	}

	for (int i = 0; i < node->GetChildCount(); i++)
	{
		ProcessLevelNode(node->GetChild(i), meshes);
	}

	return true;
}