MODEL LOADING BABY WORKS
This commit is contained in:
@@ -22,31 +22,28 @@ target_include_directories(lightkeeper PRIVATE "${CMAKE_CURRENT_LIST_DIR}/includ
|
||||
|
||||
target_link_libraries(lightkeeper PRIVATE destrum::destrum)
|
||||
|
||||
#symlink_assets(lightkeeper)
|
||||
|
||||
set(LK_SHADER_SRC "${CMAKE_CURRENT_LIST_DIR}/assets_src/shaders")
|
||||
set(LK_SHADER_OUT "${CMAKE_CURRENT_LIST_DIR}/assets_runtime/shaders")
|
||||
|
||||
include(../cmake/compile_shaders.cmake)
|
||||
compile_glsl_to_spv(lightkeeper "${LK_SHADER_SRC}" "${LK_SHADER_OUT}" LK_SPV)
|
||||
add_dependencies(lightkeeper lightkeeper_shaders)
|
||||
|
||||
set(ENGINE_ASSETS_SRC "${CMAKE_SOURCE_DIR}/destrum/assets_runtime")
|
||||
set(GAME_ASSETS_SRC "${CMAKE_SOURCE_DIR}/lightkeeper/assets_runtime")
|
||||
|
||||
set(ENGINE_ASSETS_DST "$<TARGET_FILE_DIR:lightkeeper>/assets/engine")
|
||||
set(GAME_ASSETS_DST "$<TARGET_FILE_DIR:lightkeeper>/assets/game")
|
||||
set(ASSETS_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/assets_src")
|
||||
set(ASSETS_RUNTIME_DIR "${CMAKE_CURRENT_LIST_DIR}/assets_runtime")
|
||||
set(OUTPUT_GAME_ASSETS_DIR "${CMAKE_BINARY_DIR}/assets/game")
|
||||
|
||||
add_custom_command(TARGET lightkeeper POST_BUILD
|
||||
# ensure parent dir exists
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:lightkeeper>/assets"
|
||||
|
||||
# remove destinations if they already exist (dir OR symlink)
|
||||
COMMAND ${CMAKE_COMMAND} -E rm -rf "${ENGINE_ASSETS_DST}"
|
||||
COMMAND ${CMAKE_COMMAND} -E rm -rf "${GAME_ASSETS_DST}"
|
||||
|
||||
# create symlinks
|
||||
COMMAND ${CMAKE_COMMAND} -E create_symlink "${ENGINE_ASSETS_SRC}" "${ENGINE_ASSETS_DST}"
|
||||
COMMAND ${CMAKE_COMMAND} -E create_symlink "${GAME_ASSETS_SRC}" "${GAME_ASSETS_DST}"
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${OUTPUT_GAME_ASSETS_DIR}"
|
||||
COMMAND ${CMAKE_COMMAND} -E rm -rf "${OUTPUT_GAME_ASSETS_DIR}"
|
||||
COMMAND ${CMAKE_COMMAND} -E create_symlink "${ASSETS_RUNTIME_DIR}" "${OUTPUT_GAME_ASSETS_DIR}"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
add_custom_target(_internal_clean_game_assets
|
||||
COMMAND TheChef
|
||||
--input "${ASSETS_SRC_DIR}"
|
||||
--output "${ASSETS_RUNTIME_DIR}"
|
||||
--clean
|
||||
)
|
||||
|
||||
add_custom_target(_internal_cook_game_assets ALL
|
||||
COMMAND TheChef
|
||||
--input "${ASSETS_SRC_DIR}"
|
||||
--output "${ASSETS_RUNTIME_DIR}"
|
||||
DEPENDS TheChef
|
||||
)
|
||||
|
||||
|
||||
BIN
lightkeeper/assets_src/kitty.glb
Normal file
BIN
lightkeeper/assets_src/kitty.glb
Normal file
Binary file not shown.
BIN
lightkeeper/assets_src/kitty.png
Normal file
BIN
lightkeeper/assets_src/kitty.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
BIN
lightkeeper/assets_src/tano.png
Normal file
BIN
lightkeeper/assets_src/tano.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 132 KiB |
BIN
lightkeeper/assets_src/test.glb
Normal file
BIN
lightkeeper/assets_src/test.glb
Normal file
Binary file not shown.
@@ -7,10 +7,12 @@
|
||||
|
||||
#include "destrum/Components/MeshRendererComponent.h"
|
||||
#include "destrum/Components/Rotator.h"
|
||||
#include "destrum/Components/Spinner.h"
|
||||
#include "destrum/Components/OrbitAndSpin.h"
|
||||
#include "destrum/ObjectModel/GameObject.h"
|
||||
#include "destrum/Util/ModelLoader.h"
|
||||
|
||||
LightKeeper::LightKeeper(): App(), renderer(meshCache, materialCache) {
|
||||
|
||||
}
|
||||
|
||||
LightKeeper::~LightKeeper() {
|
||||
@@ -27,13 +29,15 @@ void LightKeeper::customInit() {
|
||||
std::string fileStr(file.begin(), file.end());
|
||||
spdlog::info("Read from assetfstest.txt: {}", fileStr);
|
||||
testMesh.name = "Test Mesh";
|
||||
testMesh.vertices = vertices;
|
||||
testMesh.indices = indices;
|
||||
// testMesh.vertices = vertices;
|
||||
// testMesh.indices = indices;
|
||||
|
||||
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);
|
||||
|
||||
const auto testimgpath = AssetFS::GetInstance().GetFullPath("engine://textures/kobe.png");
|
||||
const auto testimgpath = AssetFS::GetInstance().GetFullPath("game://kitty.png");
|
||||
auto testimgID = gfxDevice.loadImageFromFile(testimgpath);
|
||||
spdlog::info("Test image loaded with id: {}", testimgID);
|
||||
testMaterialID = materialCache.addMaterial(gfxDevice, {
|
||||
@@ -50,6 +54,35 @@ void LightKeeper::customInit() {
|
||||
auto meshComp = testCube->AddComponent<MeshRendererComponent>();
|
||||
meshComp->SetMeshID(testMeshID);
|
||||
meshComp->SetMaterialID(testMaterialID);
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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<Rotator>(10, 5);
|
||||
|
||||
@@ -63,7 +96,6 @@ void LightKeeper::customUpdate(float dt) {
|
||||
}
|
||||
|
||||
void LightKeeper::customDraw() {
|
||||
|
||||
renderer.beginDrawing(gfxDevice);
|
||||
|
||||
const RenderContext ctx{
|
||||
|
||||
Reference in New Issue
Block a user