|
|
|
|
@@ -25,138 +25,138 @@ void LightKeeper::customInit() {
|
|
|
|
|
|
|
|
|
|
const float aspectRatio = static_cast<float>(m_params.renderSize.x) / static_cast<float>(m_params.renderSize.y);
|
|
|
|
|
camera.setAspectRatio(aspectRatio);
|
|
|
|
|
|
|
|
|
|
testMesh.name = "Test Mesh";
|
|
|
|
|
auto list_of_models = ModelLoader::LoadGLTF_CPUMeshes_MergedPerMesh(AssetFS::GetInstance().GetFullPath("game://kitty.glb").generic_string());
|
|
|
|
|
testMesh = list_of_models[0];
|
|
|
|
|
testMeshID = meshCache.addMesh(gfxDevice, testMesh);
|
|
|
|
|
spdlog::info("TestMesh uploaded with id: {}", testMeshID);
|
|
|
|
|
|
|
|
|
|
auto testimgID = gfxDevice.loadImageFromFile(AssetFS::GetInstance().GetFullPath("game://kitty.png"));
|
|
|
|
|
spdlog::info("Test image loaded with id: {}", testimgID);
|
|
|
|
|
testMaterialID = materialCache.addMaterial(gfxDevice, {
|
|
|
|
|
.baseColor = glm::vec3(1.f),
|
|
|
|
|
.diffuseTexture = testimgID,
|
|
|
|
|
});
|
|
|
|
|
spdlog::info("Test material created with id: {}", testMaterialID);
|
|
|
|
|
|
|
|
|
|
camera.SetRotation(glm::radians(glm::vec2(90.f, 0.f)));
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// testMesh.name = "Test Mesh";
|
|
|
|
|
// auto list_of_models = ModelLoader::LoadGLTF_CPUMeshes_MergedPerMesh(AssetFS::GetInstance().GetFullPath("game://kitty.glb").generic_string());
|
|
|
|
|
// testMesh = list_of_models[0];
|
|
|
|
|
// testMeshID = meshCache.addMesh(gfxDevice, testMesh);
|
|
|
|
|
// spdlog::info("TestMesh uploaded with id: {}", testMeshID);
|
|
|
|
|
//
|
|
|
|
|
// auto testimgID = gfxDevice.loadImageFromFile(AssetFS::GetInstance().GetFullPath("game://kitty.png"));
|
|
|
|
|
// spdlog::info("Test image loaded with id: {}", testimgID);
|
|
|
|
|
// testMaterialID = materialCache.addMaterial(gfxDevice, {
|
|
|
|
|
// .baseColor = glm::vec3(1.f),
|
|
|
|
|
// .diffuseTexture = testimgID,
|
|
|
|
|
// });
|
|
|
|
|
// spdlog::info("Test material created with id: {}", testMaterialID);
|
|
|
|
|
//
|
|
|
|
|
// camera.SetRotation(glm::radians(glm::vec2(90.f, 0.f)));
|
|
|
|
|
//
|
|
|
|
|
auto& scene = SceneManager::GetInstance().CreateScene("Main");
|
|
|
|
|
|
|
|
|
|
// auto testCube = std::make_shared<GameObject>("TestCube");
|
|
|
|
|
// auto meshComp = testCube->AddComponent<MeshRendererComponent>();
|
|
|
|
|
// meshComp->SetMeshID(testMeshID);
|
|
|
|
|
// meshComp->SetMaterialID(testMaterialID);
|
|
|
|
|
const int count = 100;
|
|
|
|
|
const float radius = 5.0f;
|
|
|
|
|
|
|
|
|
|
const float orbitRadius = 5.0f;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
|
// auto childCube = std::make_shared<GameObject>(fmt::format("ChildCube{}", i));
|
|
|
|
|
//
|
|
|
|
|
// auto childMeshComp = childCube->AddComponent<MeshRendererComponent>();
|
|
|
|
|
// childMeshComp->SetMeshID(testMeshID);
|
|
|
|
|
// childMeshComp->SetMaterialID(testMaterialID);
|
|
|
|
|
// // auto testCube = std::make_shared<GameObject>("TestCube");
|
|
|
|
|
// // auto meshComp = testCube->AddComponent<MeshRendererComponent>();
|
|
|
|
|
// // meshComp->SetMeshID(testMeshID);
|
|
|
|
|
// // meshComp->SetMaterialID(testMaterialID);
|
|
|
|
|
// const int count = 100;
|
|
|
|
|
// const float radius = 5.0f;
|
|
|
|
|
//
|
|
|
|
|
// childCube->GetTransform().SetWorldScale(glm::vec3(0.1f));
|
|
|
|
|
// const float orbitRadius = 5.0f;
|
|
|
|
|
//
|
|
|
|
|
// // Add orbit + self spin
|
|
|
|
|
// auto orbit = childCube->AddComponent<OrbitAndSpin>(orbitRadius, glm::vec3(0.0f));
|
|
|
|
|
// orbit->Randomize(1337u + (uint32_t)i); // stable random per index
|
|
|
|
|
// for (int i = 0; i < count; ++i) {
|
|
|
|
|
// // auto childCube = std::make_shared<GameObject>(fmt::format("ChildCube{}", i));
|
|
|
|
|
// //
|
|
|
|
|
// // auto childMeshComp = childCube->AddComponent<MeshRendererComponent>();
|
|
|
|
|
// // childMeshComp->SetMeshID(testMeshID);
|
|
|
|
|
// // childMeshComp->SetMaterialID(testMaterialID);
|
|
|
|
|
// //
|
|
|
|
|
// // childCube->GetTransform().SetWorldScale(glm::vec3(0.1f));
|
|
|
|
|
// //
|
|
|
|
|
// // // Add orbit + self spin
|
|
|
|
|
// // auto orbit = childCube->AddComponent<OrbitAndSpin>(orbitRadius, glm::vec3(0.0f));
|
|
|
|
|
// // orbit->Randomize(1337u + (uint32_t)i); // stable random per index
|
|
|
|
|
// //
|
|
|
|
|
// // scene.Add(childCube);
|
|
|
|
|
// }
|
|
|
|
|
// // testCube->AddComponent<Spinner>(glm::vec3(0, 1, 0), glm::radians(10.0f)); // spin around Y, rad/sec
|
|
|
|
|
// //rotate 180 around X axis
|
|
|
|
|
// // testCube->GetTransform().SetLocalRotation(glm::quat(glm::vec3(glm::radians(180.0f), 0.0f, 0.0f)));
|
|
|
|
|
// //
|
|
|
|
|
// auto globeRoot = std::make_shared<GameObject>("GlobeRoot");
|
|
|
|
|
// globeRoot->GetTransform().SetWorldPosition(glm::vec3(0.0f));
|
|
|
|
|
// globeRoot->AddComponent<Spinner>(glm::vec3(0, 1, 0), 1.0f); // spin around Y, rad/sec
|
|
|
|
|
// scene.Add(globeRoot);
|
|
|
|
|
//
|
|
|
|
|
// scene.Add(childCube);
|
|
|
|
|
}
|
|
|
|
|
// testCube->AddComponent<Spinner>(glm::vec3(0, 1, 0), glm::radians(10.0f)); // spin around Y, rad/sec
|
|
|
|
|
//rotate 180 around X axis
|
|
|
|
|
// testCube->GetTransform().SetLocalRotation(glm::quat(glm::vec3(glm::radians(180.0f), 0.0f, 0.0f)));
|
|
|
|
|
//
|
|
|
|
|
auto globeRoot = std::make_shared<GameObject>("GlobeRoot");
|
|
|
|
|
globeRoot->GetTransform().SetWorldPosition(glm::vec3(0.0f));
|
|
|
|
|
globeRoot->AddComponent<Spinner>(glm::vec3(0, 1, 0), 1.0f); // spin around Y, rad/sec
|
|
|
|
|
scene.Add(globeRoot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// scene.Add(testCube);
|
|
|
|
|
|
|
|
|
|
// const auto skyboxID = AssetFS::GetInstance().GetFullPath("engine://textures/skybox.jpg");
|
|
|
|
|
// const auto skyboxID = AssetFS::GetInstance().GetFullPath("engine://textures/mars.jpg");
|
|
|
|
|
const auto skyboxID = AssetFS::GetInstance().GetCookedPathForFile("game://starmap_2020_4k.exr");
|
|
|
|
|
//
|
|
|
|
|
// const auto skyboxID = AssetFS::GetInstance().GetFullPath("engine://textures/test-skybox.png");
|
|
|
|
|
// // scene.Add(testCube);
|
|
|
|
|
//
|
|
|
|
|
const auto vertShaderPath = AssetFS::GetInstance().GetCookedPathForFile("engine://shaders/cubemap.vert");
|
|
|
|
|
const auto fragShaderPath = AssetFS::GetInstance().GetCookedPathForFile("engine://shaders/cubemap.frag");
|
|
|
|
|
// // const auto skyboxID = AssetFS::GetInstance().GetFullPath("engine://textures/skybox.jpg");
|
|
|
|
|
// // const auto skyboxID = AssetFS::GetInstance().GetFullPath("engine://textures/mars.jpg");
|
|
|
|
|
// const auto skyboxID = AssetFS::GetInstance().GetCookedPathForFile("game://starmap_2020_4k.exr");
|
|
|
|
|
// //
|
|
|
|
|
// // const auto skyboxID = AssetFS::GetInstance().GetFullPath("engine://textures/test-skybox.png");
|
|
|
|
|
// //
|
|
|
|
|
// const auto vertShaderPath = AssetFS::GetInstance().GetCookedPathForFile("engine://shaders/cubemap.vert");
|
|
|
|
|
// const auto fragShaderPath = AssetFS::GetInstance().GetCookedPathForFile("engine://shaders/cubemap.frag");
|
|
|
|
|
// //
|
|
|
|
|
// skyboxCubemap = std::make_unique<CubeMap>();
|
|
|
|
|
// skyboxCubemap->LoadCubeMap(skyboxID.generic_string());
|
|
|
|
|
// skyboxCubemap->InitCubemapPipeline(vertShaderPath.generic_string(), fragShaderPath.generic_string());
|
|
|
|
|
// skyboxCubemap->CreateCubeMap();
|
|
|
|
|
//
|
|
|
|
|
skyboxCubemap = std::make_unique<CubeMap>();
|
|
|
|
|
skyboxCubemap->LoadCubeMap(skyboxID.generic_string());
|
|
|
|
|
skyboxCubemap->InitCubemapPipeline(vertShaderPath.generic_string(), fragShaderPath.generic_string());
|
|
|
|
|
skyboxCubemap->CreateCubeMap();
|
|
|
|
|
|
|
|
|
|
renderer.setSkyboxTexture(skyboxCubemap->GetCubeMapImageID());
|
|
|
|
|
|
|
|
|
|
// renderer.setSkyboxTexture(skyboxCubemap->GetCubeMapImageID());
|
|
|
|
|
//
|
|
|
|
|
const auto planeObj = std::make_shared<GameObject>("GroundPlane");
|
|
|
|
|
const auto planeMeshComp = planeObj->AddComponent<MeshRendererComponent>();
|
|
|
|
|
const auto planeModel = ModelLoader::LoadGLTF_CPUMeshes_MergedPerMesh(AssetFS::GetInstance().GetFullPath("game://plane.glb").generic_string());
|
|
|
|
|
const auto planeMeshID = meshCache.addMesh(gfxDevice, planeModel[0]);
|
|
|
|
|
|
|
|
|
|
const auto planeTextureID = gfxDevice.loadImageFromFile(AssetFS::GetInstance().GetFullPath("game://grass.png"));
|
|
|
|
|
const auto planeMaterialID = materialCache.addMaterial(gfxDevice, {
|
|
|
|
|
.baseColor = glm::vec3(1.f),
|
|
|
|
|
.textureFilteringMode = TextureFilteringMode::Nearest,
|
|
|
|
|
.diffuseTexture = planeTextureID,
|
|
|
|
|
.name = "GroundPlaneMaterial",
|
|
|
|
|
});
|
|
|
|
|
planeMeshComp->SetMeshID(planeMeshID);
|
|
|
|
|
planeMeshComp->SetMaterialID(planeMaterialID);
|
|
|
|
|
planeObj->GetTransform().SetWorldPosition(glm::vec3(0.f, -1.0f, 0.f));
|
|
|
|
|
planeObj->GetTransform().SetWorldScale(glm::vec3(10.f, 1.f, 10.f));
|
|
|
|
|
scene.Add(planeObj);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// At the bottom of customInit(), replace the incomplete CharObj block:
|
|
|
|
|
|
|
|
|
|
const auto CharObj = std::make_shared<GameObject>("Character");
|
|
|
|
|
|
|
|
|
|
auto charModel = ModelLoader::LoadSkinnedModel(
|
|
|
|
|
AssetFS::GetInstance().GetFullPath("engine://char2.fbx").generic_string()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const auto charMeshID = meshCache.addMesh(gfxDevice, charModel.meshes[0]);
|
|
|
|
|
|
|
|
|
|
const auto charTextureID = gfxDevice.loadImageFromFile(AssetFS::GetInstance().GetFullPath("engine://char.jpg"));
|
|
|
|
|
const auto charMaterialID = materialCache.addMaterial(gfxDevice, {
|
|
|
|
|
.baseColor = glm::vec3(1.f),
|
|
|
|
|
.diffuseTexture = charTextureID,
|
|
|
|
|
.name = "CharacterMaterial",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const auto charMeshComp = CharObj->AddComponent<MeshRendererComponent>();
|
|
|
|
|
charMeshComp->SetMeshID(charMeshID);
|
|
|
|
|
charMeshComp->SetMaterialID(charMaterialID);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto animator = CharObj->AddComponent<Animator>();
|
|
|
|
|
animator->setSkeleton(std::move(charModel.skeleton));
|
|
|
|
|
for (auto& clip : charModel.animations) {
|
|
|
|
|
animator->addClip(std::make_shared<SkeletalAnimation>(std::move(clip)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auto& clip : charModel.animations)
|
|
|
|
|
spdlog::info("Loaded animation: '{}' ({:.2f}s)", clip.name, clip.duration);
|
|
|
|
|
|
|
|
|
|
if (!charModel.animations.empty())
|
|
|
|
|
// animator->play("Armature|Armature|mixamo.com");
|
|
|
|
|
// // animator->play(charModel.animations[0].name);
|
|
|
|
|
animator->play("Armature|Armature|Armature|main");
|
|
|
|
|
// or: animator->play("Run", 0.2f); // 0.2s cross-fade
|
|
|
|
|
|
|
|
|
|
CharObj->GetTransform().SetWorldPosition(glm::vec3(0.f, 0.f, 0.f));
|
|
|
|
|
// CharObj->GetTransform().SetWorldScale(0.01f, 0.01f, 0.01f);
|
|
|
|
|
scene.Add(CharObj);
|
|
|
|
|
// //
|
|
|
|
|
// const auto planeObj = std::make_shared<GameObject>("GroundPlane");
|
|
|
|
|
// const auto planeMeshComp = planeObj->AddComponent<MeshRendererComponent>();
|
|
|
|
|
// const auto planeModel = ModelLoader::LoadGLTF_CPUMeshes_MergedPerMesh(AssetFS::GetInstance().GetFullPath("game://plane.glb").generic_string());
|
|
|
|
|
// const auto planeMeshID = meshCache.addMesh(gfxDevice, planeModel[0]);
|
|
|
|
|
//
|
|
|
|
|
// const auto planeTextureID = gfxDevice.loadImageFromFile(AssetFS::GetInstance().GetFullPath("game://grass.png"));
|
|
|
|
|
// const auto planeMaterialID = materialCache.addMaterial(gfxDevice, {
|
|
|
|
|
// .baseColor = glm::vec3(1.f),
|
|
|
|
|
// .textureFilteringMode = TextureFilteringMode::Nearest,
|
|
|
|
|
// .diffuseTexture = planeTextureID,
|
|
|
|
|
// .name = "GroundPlaneMaterial",
|
|
|
|
|
// });
|
|
|
|
|
// planeMeshComp->SetMeshID(planeMeshID);
|
|
|
|
|
// planeMeshComp->SetMaterialID(planeMaterialID);
|
|
|
|
|
// planeObj->GetTransform().SetWorldPosition(glm::vec3(0.f, -1.0f, 0.f));
|
|
|
|
|
// planeObj->GetTransform().SetWorldScale(glm::vec3(10.f, 1.f, 10.f));
|
|
|
|
|
// scene.Add(planeObj);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// // At the bottom of customInit(), replace the incomplete CharObj block:
|
|
|
|
|
//
|
|
|
|
|
// const auto CharObj = std::make_shared<GameObject>("Character");
|
|
|
|
|
//
|
|
|
|
|
// auto charModel = ModelLoader::LoadSkinnedModel(
|
|
|
|
|
// AssetFS::GetInstance().GetFullPath("engine://char2.fbx").generic_string()
|
|
|
|
|
// );
|
|
|
|
|
//
|
|
|
|
|
// const auto charMeshID = meshCache.addMesh(gfxDevice, charModel.meshes[0]);
|
|
|
|
|
//
|
|
|
|
|
// const auto charTextureID = gfxDevice.loadImageFromFile(AssetFS::GetInstance().GetFullPath("engine://char.jpg"));
|
|
|
|
|
// const auto charMaterialID = materialCache.addMaterial(gfxDevice, {
|
|
|
|
|
// .baseColor = glm::vec3(1.f),
|
|
|
|
|
// .diffuseTexture = charTextureID,
|
|
|
|
|
// .name = "CharacterMaterial",
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// const auto charMeshComp = CharObj->AddComponent<MeshRendererComponent>();
|
|
|
|
|
// charMeshComp->SetMeshID(charMeshID);
|
|
|
|
|
// charMeshComp->SetMaterialID(charMaterialID);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// const auto animator = CharObj->AddComponent<Animator>();
|
|
|
|
|
// animator->setSkeleton(std::move(charModel.skeleton));
|
|
|
|
|
// for (auto& clip : charModel.animations) {
|
|
|
|
|
// animator->addClip(std::make_shared<SkeletalAnimation>(std::move(clip)));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// for (const auto& clip : charModel.animations)
|
|
|
|
|
// spdlog::info("Loaded animation: '{}' ({:.2f}s)", clip.name, clip.duration);
|
|
|
|
|
//
|
|
|
|
|
// if (!charModel.animations.empty())
|
|
|
|
|
// // animator->play("Armature|Armature|mixamo.com");
|
|
|
|
|
// // // animator->play(charModel.animations[0].name);
|
|
|
|
|
// animator->play("Armature|Armature|Armature|main");
|
|
|
|
|
// // or: animator->play("Run", 0.2f); // 0.2s cross-fade
|
|
|
|
|
//
|
|
|
|
|
// CharObj->GetTransform().SetWorldPosition(glm::vec3(0.f, 0.f, 0.f));
|
|
|
|
|
// // CharObj->GetTransform().SetWorldScale(0.01f, 0.01f, 0.01f);
|
|
|
|
|
// scene.Add(CharObj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LightKeeper::customUpdate(float dt) {
|
|
|
|
|
@@ -198,8 +198,20 @@ void LightKeeper::customDraw() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LightKeeper::customCleanup() {
|
|
|
|
|
auto device = gfxDevice.getDevice().device;
|
|
|
|
|
|
|
|
|
|
vkDeviceWaitIdle(device);
|
|
|
|
|
|
|
|
|
|
SceneManager::GetInstance().Destroy();
|
|
|
|
|
renderer.cleanup(gfxDevice.getDevice().device);
|
|
|
|
|
|
|
|
|
|
if (skyboxCubemap) {
|
|
|
|
|
skyboxCubemap.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderer.cleanup(gfxDevice);
|
|
|
|
|
|
|
|
|
|
materialCache.cleanup(gfxDevice);
|
|
|
|
|
meshCache.cleanup(gfxDevice);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LightKeeper::onWindowResize(int newWidth, int newHeight) {
|
|
|
|
|
|