diff --git a/include/level_object_entries.h b/include/level_object_entries.h index 847de7e9..5d192cb3 100644 --- a/include/level_object_entries.h +++ b/include/level_object_entries.h @@ -28,7 +28,7 @@ typedef struct LevelObjectEntry_Scenery { /* 0x00 */ LevelObjectEntryCommon common; /* 0x08 */ u8 modelIndex; /* 0x09 */ u8 radius; - /* 0x0A */ u8 angleY; + /* 0x0A */ u8 angleY; Hint((Angle, DivideBy:64)) /* 0x0B */ u8 solid; } LevelObjectEntry_Scenery; @@ -132,7 +132,7 @@ typedef struct LevelObjectEntry_Checkpoint { /* 0x00 */ LevelObjectEntryCommon common; /* 0x08 */ u8 scale; /* 0x09 */ u8 unk9; - /* 0x0A */ u8 angleY; + /* 0x0A */ u8 angleY; Hint((Angle, DivideBy:64)) /* 0x0B */ s8 unkB; /* 0x0C */ s8 unkC; /* 0x0D */ s8 unkD; @@ -154,8 +154,8 @@ typedef struct LevelObjectEntry_Checkpoint { typedef struct LevelObjectEntry_Door { /* 0x00 */ LevelObjectEntryCommon common; - /* 0x08 */ u8 closedRotation; //Hint((Angle, DivideBy:64)) - /* 0x09 */ u8 openRotation; //Hint((Angle, DivideBy:64)) + /* 0x08 */ u8 closedRotation; Hint((Angle, DivideBy:64)) + /* 0x09 */ u8 openRotation; Hint((Angle, DivideBy:64)) /* 0x0A */ u8 modelIndex; /* 0x0B */ u8 distanceToOpen; /* 0x0C */ s8 unkC; @@ -247,9 +247,9 @@ typedef struct LevelObjectEntry_TexScroll { typedef struct LevelObjectEntry_ModeChange { /* 0x00 */ LevelObjectEntryCommon common; - /* 0x08 */ u8 radius; - /* 0x09 */ u8 angleY; - /* 0x0A */ u8 vehicleID; + /* 0x08 */ u8 radius; + /* 0x09 */ u8 angleY; Hint((Angle, DivideBy:64)) + /* 0x0A */ u8 vehicleID; Hint((Enum:Vehicle)) /* 0x0B */ u8 padB; } LevelObjectEntry_ModeChange; @@ -299,7 +299,7 @@ typedef struct LevelObjectEntry_Weather { typedef struct LevelObjectEntry_Bridge_WhaleRamp { /* 0x00 */ LevelObjectEntryCommon common; /* 0x08 */ u8 modelIndex; - /* 0x09 */ u8 angleY; + /* 0x09 */ u8 angleY; Hint((Angle, DivideBy:64)) /* 0x0A */ u8 unkA; /* 0x0B */ u8 unkB; /* 0x0C */ u8 radius; @@ -321,7 +321,7 @@ typedef struct LevelObjectEntry_SeaMonster { typedef struct LevelObjectEntry_Bonus { /* 0x00 */ LevelObjectEntryCommon common; /* 0x08 */ u8 radius; - /* 0x09 */ u8 angleY; + /* 0x09 */ u8 angleY; Hint((Angle, DivideBy:64)) /* 0x0A */ u8 unkA; } LevelObjectEntry_Bonus; @@ -364,12 +364,12 @@ typedef struct LevelObjectEntry_CharacterFlag { */ typedef struct LevelObjectEntry_Animation { /* 0x00 */ LevelObjectEntryCommon common; - /* 0x08 */ u8 z_rotation; //Hint((Angle, DivideBy:256)) - /* 0x09 */ u8 x_rotation; //Hint((Angle, DivideBy:256)) - /* 0x0A */ u8 y_rotation; //Hint((Angle, DivideBy:256)) + /* 0x08 */ u8 z_rotation; Hint((Angle, DivideBy:256)) + /* 0x09 */ u8 x_rotation; Hint((Angle, DivideBy:256)) + /* 0x0A */ u8 y_rotation; Hint((Angle, DivideBy:256)) /* 0x0B */ u8 scale; Hint((Scale, DivideBy:64)) - /* 0x0C */ s16 objectIdToSpawn; - /* 0x0E */ s16 animationStartDelay; + /* 0x0C */ s16 objectIdToSpawn; Hint((Object)) // Index into the Level-Object Translation Table. + /* 0x0E */ s16 animationStartDelay; Hint((Time, RoundToPlaces:3)) // Pause before continuing? /* 0x10 */ s8 actorIndex; /* 0x11 */ s8 order; /* 0x12 */ s8 objAnimIndex; @@ -390,9 +390,9 @@ typedef struct LevelObjectEntry_Animation { /* 0x21 */ s8 channel; /* 0x22 */ s8 unk22; /* 0x23 */ s8 unk23; - /* 0x24 */ s16 pauseFrameCount; + /* 0x24 */ s16 pauseFrameCount; Hint((Time, RoundToPlaces:4)) // Pause before continuing? /* 0x26 */ s8 specialHide; - /* 0x27 */ u8 messageId; + /* 0x27 */ u8 messageId; Hint((AssetId:ASSET_GAME_TEXT)) /* 0x28 */ s8 unk28; /* 0x29 */ s8 unk29; /* 0x2A */ s8 unk2A; @@ -415,7 +415,7 @@ typedef struct LevelObjectEntry_Trigger { /* 0x00 */ LevelObjectEntryCommon common; /* 0x08 */ u8 scale; /* 0x09 */ s8 index; - /* 0x0A */ u8 angleY; + /* 0x0A */ u8 angleY; Hint((Angle, DivideBy:64)) /* 0x0B */ u8 unkB; /* 0x0C */ u8 unkC; /* 0x0D */ u8 unkD; @@ -425,7 +425,7 @@ typedef struct LevelObjectEntry_AirZippers_WaterZippers { /* 0x00 */ LevelObjectEntryCommon common; /* 0x08 */ u8 unk8; /* 0x09 */ u8 radius; - /* 0x0A */ u8 angleY; + /* 0x0A */ u8 angleY; Hint((Angle, DivideBy:64)) /* 0x0B */ u8 padB; } LevelObjectEntry_AirZippers_WaterZippers; @@ -481,14 +481,14 @@ typedef struct LevelObjectEntry_Log { /* 0x00 */ LevelObjectEntryCommon common; /* 0x08 */ u8 modelIndex; /* 0x09 */ u8 radius; - /* 0x0A */ u8 angleY; + /* 0x0A */ u8 angleY; Hint((Angle, DivideBy:64)) /* 0x0B */ u8 padB; } LevelObjectEntry_Log; typedef struct LevelObjectEntry_LavaSpurt { /* 0x00 */ LevelObjectEntryCommon common; - /* 0x08 */ u8 delayTimer; - /* 0x09 */ u8 initialTimer; + /* 0x08 */ u8 delayTimer; Hint((Time)) + /* 0x09 */ u8 initialTimer; Hint((Time)) } LevelObjectEntry_LavaSpurt; typedef struct LevelObjectEntry_PosArrow { @@ -502,7 +502,7 @@ typedef struct LevelObjectEntry_HitTester { typedef struct LevelObjectEntry_MidiFade { /* 0x00 */ LevelObjectEntryCommon common; /* 0x08 */ u8 scale; - /* 0x09 */ u8 angleY; + /* 0x09 */ u8 angleY; Hint((Angle, DivideBy:64)) /* 0x0A */ u8 unkA[16]; // Is this 16 bytes or 15 bytes with a padded 0? /* 0x1A */ u8 unk1A; /* 0x1B */ u8 unk1B; @@ -526,7 +526,7 @@ typedef struct LevelObjectEntry_EffectBox { typedef struct LevelObjectEntry_TrophyCab { /* 0x00 */ LevelObjectEntryCommon common; - /* 0x08 */ u8 angleY; + /* 0x08 */ u8 angleY; Hint((Angle, DivideBy:64)) /* 0x09 */ u8 pad9; } LevelObjectEntry_TrophyCab; @@ -556,8 +556,8 @@ typedef struct LevelObjectEntry_Laserbolt { typedef struct LevelObjectEntry_Lasergun { /* 0x00 */ LevelObjectEntryCommon common; - /* 0x08 */ u8 angleY; - /* 0x09 */ u8 angleX; + /* 0x08 */ u8 angleY; Hint((Angle, DivideBy:256)) + /* 0x09 */ u8 angleX; /* 0x0A */ s8 targeting; /* 0x0B */ s8 fireRate; /* 0x0C */ u8 laserDuration; @@ -568,7 +568,7 @@ typedef struct LevelObjectEntry_GroundZipper { /* 0x00 */ LevelObjectEntryCommon common; /* 0x08 */ u8 unk8; /* 0x09 */ u8 scale; - /* 0x0A */ u8 angleY; + /* 0x0A */ u8 angleY; Hint((Angle, DivideBy:64)) /* 0x0B */ u8 unkB; } LevelObjectEntry_GroundZipper; @@ -622,7 +622,7 @@ typedef struct LevelObjectEntry_Lighthouse_RocketSignpost { /* 0x00 */ LevelObjectEntryCommon common; /* 0x08 */ u8 unk8; /* 0x09 */ u8 radius; - /* 0x0A */ u8 angleY; + /* 0x0A */ u8 angleY; Hint((Angle, DivideBy:64)) /* 0x0B */ u8 padB; } LevelObjectEntry_Lighthouse_RocketSignpost; @@ -653,8 +653,8 @@ typedef struct LevelObjectEntry_SilverCoinAdv2 { typedef struct LevelObjectEntry_TTDoor { /* 0x00 */ LevelObjectEntryCommon common; - /* 0x08 */ u8 angleY; - /* 0x09 */ u8 unk9; + /* 0x08 */ u8 angleY; Hint((Angle, DivideBy:64)) // Rotation when closed + /* 0x09 */ u8 unk9; Hint((Angle, DivideBy:64)) // Rotation when open /* 0x0A */ u8 unkA; /* 0x0B */ u8 unkB; /* 0x0C */ u8 radius; diff --git a/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/builder/buildTypes/buildObjectMap.o b/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/builder/buildTypes/buildObjectMap.o index e2aa38ca..87c6f687 100644 Binary files a/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/builder/buildTypes/buildObjectMap.o and b/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/builder/buildTypes/buildObjectMap.o differ diff --git a/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/extract/extractTypes/extractObjectMap.o b/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/extract/extractTypes/extractObjectMap.o index f32b7c26..911e63ab 100644 Binary files a/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/extract/extractTypes/extractObjectMap.o and b/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/extract/extractTypes/extractObjectMap.o differ diff --git a/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/helpers/assetsHelper.o b/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/helpers/assetsHelper.o index 0a6e8de7..58b033f9 100644 Binary files a/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/helpers/assetsHelper.o and b/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/helpers/assetsHelper.o differ diff --git a/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/helpers/c/cStructGltfHelper.o b/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/helpers/c/cStructGltfHelper.o index bd528c6d..ebe6e5b5 100644 Binary files a/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/helpers/c/cStructGltfHelper.o and b/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/helpers/c/cStructGltfHelper.o differ diff --git a/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/helpers/c/cTypes.o b/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/helpers/c/cTypes.o index 06c84681..a2edc66e 100644 Binary files a/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/helpers/c/cTypes.o and b/tools/dkr_assets_tool_src/_build/dkr_assets_tool_src/helpers/c/cTypes.o differ diff --git a/tools/dkr_assets_tool_src/builder/buildTypes/buildObjectMap.cpp b/tools/dkr_assets_tool_src/builder/buildTypes/buildObjectMap.cpp index cbe412ab..aa4a4e27 100644 --- a/tools/dkr_assets_tool_src/builder/buildTypes/buildObjectMap.cpp +++ b/tools/dkr_assets_tool_src/builder/buildTypes/buildObjectMap.cpp @@ -69,7 +69,7 @@ BuildObjectMap::BuildObjectMap(DkrAssetsSettings &settings, BuildInfo &info) : _ if(entryCommon != entryStruct) { for(size_t entry = 0; entry < entryStruct->entry_count(); entry++) { CStructEntry *structMember = entryStruct->get_entry(entry); - CStructGltfHelper::put_gltf_node_extra_into_struct_entry(structMember, gltf, i, bytes); + CStructGltfHelper::put_gltf_node_extra_into_struct_entry(_settings, structMember, gltf, i, bytes); } } diff --git a/tools/dkr_assets_tool_src/extract/extractTypes/extractObjectMap.cpp b/tools/dkr_assets_tool_src/extract/extractTypes/extractObjectMap.cpp index 7f0ecc8b..e2128d51 100644 --- a/tools/dkr_assets_tool_src/extract/extractTypes/extractObjectMap.cpp +++ b/tools/dkr_assets_tool_src/extract/extractTypes/extractObjectMap.cpp @@ -115,7 +115,7 @@ ExtractObjectMap::ExtractObjectMap(DkrAssetsSettings &settings, ExtractInfo &inf if(entryCommon != entryStruct) { for(size_t i = 0; i < entryStruct->entry_count(); i++) { CStructEntry *structMember = entryStruct->get_entry(i); - CStructGltfHelper::put_struct_entry_into_gltf_node_extra(structMember, gltfFile, gltfObjNode, bytes); + CStructGltfHelper::put_struct_entry_into_gltf_node_extra(_settings, structMember, gltfFile, gltfObjNode, bytes); } } diff --git a/tools/dkr_assets_tool_src/fileTypes/ttGhost.hpp b/tools/dkr_assets_tool_src/fileTypes/ttGhost.hpp index 0f2cba9d..c57e577d 100644 --- a/tools/dkr_assets_tool_src/fileTypes/ttGhost.hpp +++ b/tools/dkr_assets_tool_src/fileTypes/ttGhost.hpp @@ -1,8 +1,9 @@ #pragma once #include "types.hpp" +#include "misc/constants.hpp" -#define GHOST_TIME_FPS 60.0 +#define GHOST_TIME_FPS DKR_FPS /* Size: 8 bytes */ typedef struct GhostHeader { diff --git a/tools/dkr_assets_tool_src/helpers/assetsHelper.cpp b/tools/dkr_assets_tool_src/helpers/assetsHelper.cpp index 3378497f..0bb148c6 100644 --- a/tools/dkr_assets_tool_src/helpers/assetsHelper.cpp +++ b/tools/dkr_assets_tool_src/helpers/assetsHelper.cpp @@ -37,6 +37,16 @@ JsonFile *AssetsHelper::get_asset_section_json(DkrAssetsSettings &settings, cons return _get_section_json(settings.pathToAssets, assetSectionId); } +size_t AssetsHelper::get_asset_section_count(DkrAssetsSettings &settings, const std::string assetSectionId) { + JsonFile *assetSection = get_asset_section_json(settings, assetSectionId); + + if(assetSection == nullptr) { + return 0; + } + + return assetSection->length_of_array("/files/order"); +} + // Returns the asset JSON file from a section ID & build ID. JsonFile *AssetsHelper::get_asset_json(DkrAssetsSettings &settings, const std::string assetSectionId, std::string buildId) { JsonFile *out = nullptr; diff --git a/tools/dkr_assets_tool_src/helpers/assetsHelper.h b/tools/dkr_assets_tool_src/helpers/assetsHelper.h index 86cba559..66344099 100644 --- a/tools/dkr_assets_tool_src/helpers/assetsHelper.h +++ b/tools/dkr_assets_tool_src/helpers/assetsHelper.h @@ -29,11 +29,13 @@ public: static JsonFile *get_main_json(DkrAssetsSettings &settings); static JsonFile *get_main_json(fs::path pathToAssets); static JsonFile *get_asset_section_json(DkrAssetsSettings &settings, const std::string assetSectionId); + static size_t get_asset_section_count(DkrAssetsSettings &settings, const std::string assetSectionId); static JsonFile *get_asset_json(DkrAssetsSettings &settings, const std::string assetSectionId, std::string buildId=""); static int get_asset_index(DkrAssetsSettings &settings, const std::string assetSectionId, std::string &buildId); static std::string get_section_path(DkrAssetsSettings &settings, const std::string &assetSectionId); static std::string get_build_id_of_index(DkrAssetsSettings &settings, const std::string &assetSectionId, int index); + static DeferredAssetInfo get_deferred_asset_info(DkrAssetsSettings &settings, const std::string assetSectionId); private: static JsonFile *_get_section_json(fs::path pathToAssets, const std::string &assetSectionId); diff --git a/tools/dkr_assets_tool_src/helpers/c/cStructGltfHelper.cpp b/tools/dkr_assets_tool_src/helpers/c/cStructGltfHelper.cpp index 8d2ba482..f57cbd2c 100644 --- a/tools/dkr_assets_tool_src/helpers/c/cStructGltfHelper.cpp +++ b/tools/dkr_assets_tool_src/helpers/c/cStructGltfHelper.cpp @@ -1,21 +1,32 @@ #include "cStructGltfHelper.h" +#include "helpers/assetsHelper.h" #include "helpers/c/cContext.h" #include "helpers/c/cTypes.h" +#include // for std::round + enum StructHintType { NO_HINT, ENUM, // An enum from include/enums.h ASSET_ID, ANGLE, // Converts angle byte into degrees. - SCALE // Divide by some number to get a float representation of scale. + SCALE, // Divide by some number to get a float representation of scale. + OBJECT, // Index into the Level-Object Translation Table. + TIME // Convert integer ticks to seconds. }; std::unordered_map hintTypes = { { "Enum", StructHintType::ENUM }, - { "Angle", StructHintType::ANGLE } + { "AssetId", StructHintType::ASSET_ID }, + { "Angle", StructHintType::ANGLE }, + { "Scale", StructHintType::SCALE }, + { "Object", StructHintType::OBJECT }, + { "Time", StructHintType::TIME } }; +// Enum + // Gets an enum symbol from a struct member and an integer value. // Assumption: structMember has the "Enum" hint. std::string get_hint_enum_value(CStructEntry *structMember, int value) { @@ -46,8 +57,28 @@ int get_value_from_hint_enum(CStructEntry *structMember, std::string &enumValue) return value; } +// AssetId + +std::string get_hint_asset_build_id(DkrAssetsSettings &settings, CStructEntry *structMember, int value) { + std::string assetSectionId = structMember->get_hint_value("AssetId"); + if(value == -1 || (value >= AssetsHelper::get_asset_section_count(settings, assetSectionId))) { + return ""; + } + return AssetsHelper::get_build_id_of_index(settings, assetSectionId, value); +} + +int get_value_from_hint_asset_build_id(DkrAssetsSettings &settings, CStructEntry *structMember, std::string &buildId) { + if(buildId.empty()) { + return -1; + } + std::string assetSectionId = structMember->get_hint_value("AssetId"); + return AssetsHelper::get_asset_index(settings, assetSectionId, buildId); +} + +// Angle + double get_hint_angle(CStructEntry *structMember, int value) { - std::string divideByStr = structMember->get_hint_value("DivideBy", "64"); + std::string divideByStr = structMember->get_hint_value("DivideBy", "64"); // Defaults to 64 double divideBy = std::stod(divideByStr); double angle = (value / divideBy) * 360.0; // Convert value to degrees @@ -63,7 +94,7 @@ double get_hint_angle(CStructEntry *structMember, int value) { } int get_value_from_hint_angle(CStructEntry *structMember, double angle) { - std::string divideByStr = structMember->get_hint_value("DivideBy", "64"); + std::string divideByStr = structMember->get_hint_value("DivideBy", "64"); // Defaults to 64 double divideBy = std::stod(divideByStr); if((angle < 0.0) && (!CTypes::is_signed_type(structMember->type))) { @@ -73,11 +104,69 @@ int get_value_from_hint_angle(CStructEntry *structMember, double angle) { angle += maxAngle; // convert angle back to unsigned. } - int out = (int)((angle / 360.0) * divideBy); // Convert from degrees + int out = (int)std::round((angle / 360.0) * divideBy); // Convert from degrees return CTypes::clamp_int(structMember->type, out); } -void CStructGltfHelper::put_struct_entry_into_gltf_node_extra(CStructEntry *structMember, WriteableGltfFile &gltfFile, int gltfNode, uint8_t *bytes) { +// Scale + +double get_hint_scale(CStructEntry *structMember, int value) { + std::string divideByStr = structMember->get_hint_value("DivideBy", "64"); // Defaults to 64 + double divideBy = std::stod(divideByStr); + return (double)value / divideBy; +} + +int get_value_from_hint_scale(CStructEntry *structMember, double scale) { + std::string divideByStr = structMember->get_hint_value("DivideBy", "64"); // Defaults to 64 + double divideBy = std::stod(divideByStr); + return (int)std::round(scale * divideBy); +} + +// Object + +std::string get_hint_object(DkrAssetsSettings &settings, CStructEntry *structMember, int objectIndex) { + if(objectIndex < 0) { + return ""; + } + JsonFile *transTable = AssetsHelper::get_asset_json(settings, "ASSET_LEVEL_OBJECT_TRANSLATION_TABLE"); + return transTable->get_string("/table/" + std::to_string(objectIndex)); +} + +int get_value_from_hint_object(DkrAssetsSettings &settings, CStructEntry *structMember, std::string &buildId) { + if(buildId.empty()) { + return -1; + } + JsonFile *transTable = AssetsHelper::get_asset_json(settings, "ASSET_LEVEL_OBJECT_TRANSLATION_TABLE"); + return transTable->get_index_of_elem_in_array("/table", buildId); +} + +// Time + +double get_hint_time(CStructEntry *structMember, int value) { + std::string roundToPlacesStr = structMember->get_hint_value("RoundToPlaces", ""); // Defaults to no rounding. + + double timeSeconds = (double)value / DKR_FPS; + + if(!roundToPlacesStr.empty()) { + double roundToPlaces = std::stod(roundToPlacesStr); + roundToPlaces = std::pow(10, roundToPlaces); // 10 ^ N power. + + // Round time to Nth place + timeSeconds *= roundToPlaces; + timeSeconds = std::round(timeSeconds); + timeSeconds /= roundToPlaces; + } + + return timeSeconds; +} + +int get_value_from_hint_time(CStructEntry *structMember, double timeSeconds) { + return (int)std::round(timeSeconds * DKR_FPS); +} + +/***************************************************************************************/ + +void CStructGltfHelper::put_struct_entry_into_gltf_node_extra(DkrAssetsSettings &settings, CStructEntry *structMember, WriteableGltfFile &gltfFile, int gltfNode, uint8_t *bytes) { CStructEntry::InternalType internalType = structMember->get_internal_type(); StructHintType hintType = StructHintType::NO_HINT; if(structMember->has_hint()) { @@ -97,12 +186,42 @@ void CStructGltfHelper::put_struct_entry_into_gltf_node_extra(CStructEntry *stru gltfFile.set_node_extra(gltfNode, structMember->name, enumValue); break; } + case StructHintType::ASSET_ID: + { + std::string buildId = get_hint_asset_build_id(settings, structMember, value); + if(!buildId.empty()) { + gltfFile.set_node_extra(gltfNode, structMember->name, buildId); + } + break; + } case StructHintType::ANGLE: { double angle = get_hint_angle(structMember, value); gltfFile.set_node_extra(gltfNode, structMember->name, angle); break; } + case StructHintType::SCALE: + { + double scale = get_hint_scale(structMember, value); + gltfFile.set_node_extra(gltfNode, structMember->name, scale); + break; + } + case StructHintType::OBJECT: + { + std::string buildId = get_hint_object(settings, structMember, value); + if(!buildId.empty()) { + gltfFile.set_node_extra(gltfNode, structMember->name, buildId); + } + break; + } + case StructHintType::TIME: + { + if(value != -1) { + double timeSeconds = get_hint_time(structMember, value); + gltfFile.set_node_extra(gltfNode, structMember->name, timeSeconds); + } + break; + } default: DebugHelper::error("Unimplemented hint type: ", structMember->get_hint_type()); break; @@ -126,12 +245,46 @@ void CStructGltfHelper::put_struct_entry_into_gltf_node_extra(CStructEntry *stru arrayOfValues.push_back(tinygltf::Value(enumValue)); break; } + case StructHintType::ASSET_ID: + { + std::string buildId = get_hint_asset_build_id(settings, structMember, value); + if(!buildId.empty()) { + arrayOfValues.push_back(tinygltf::Value(buildId)); + } else { + arrayOfValues.push_back(tinygltf::Value()); // push null + } + break; + } case StructHintType::ANGLE: { double angle = get_hint_angle(structMember, value); arrayOfValues.push_back(tinygltf::Value(angle)); break; } + case StructHintType::SCALE: + { + double scale = get_hint_scale(structMember, value); + arrayOfValues.push_back(tinygltf::Value(scale)); + break; + } + case StructHintType::OBJECT: + { + std::string buildId = get_hint_object(settings, structMember, value); + if(!buildId.empty()) { + arrayOfValues.push_back(tinygltf::Value(buildId)); + } else { + arrayOfValues.push_back(tinygltf::Value()); // push null + } + break; + } + case StructHintType::TIME: + { + if(value != -1) { + double timeSeconds = get_hint_time(structMember, value); + arrayOfValues.push_back(tinygltf::Value(timeSeconds)); + } + break; + } default: DebugHelper::error("Unimplemented hint type: ", structMember->get_hint_type()); break; @@ -149,7 +302,7 @@ void CStructGltfHelper::put_struct_entry_into_gltf_node_extra(CStructEntry *stru } } -void CStructGltfHelper::put_gltf_node_extra_into_struct_entry(CStructEntry *structMember, GltfFile &gltfFile, int gltfNode, uint8_t *bytes) { +void CStructGltfHelper::put_gltf_node_extra_into_struct_entry(DkrAssetsSettings &settings, CStructEntry *structMember, GltfFile &gltfFile, int gltfNode, uint8_t *bytes) { CStructEntry::InternalType internalType = structMember->get_internal_type(); StructHintType hintType = StructHintType::NO_HINT; if(structMember->has_hint()) { @@ -170,12 +323,48 @@ void CStructGltfHelper::put_gltf_node_extra_into_struct_entry(CStructEntry *stru value = get_value_from_hint_enum(structMember, enumValue); break; } + case StructHintType::ASSET_ID: + { + std::string buildId = gltfFile.get_node_extra(gltfNode, structMember->name, ""); + if(buildId.empty()) { + value = -1; + } else { + value = get_value_from_hint_asset_build_id(settings, structMember, buildId); + } + break; + } case StructHintType::ANGLE: { double angle = gltfFile.get_node_extra(gltfNode, structMember->name, 0.0); value = get_value_from_hint_angle(structMember, angle); break; } + case StructHintType::SCALE: + { + double scale = gltfFile.get_node_extra(gltfNode, structMember->name, 0.0); + value = get_value_from_hint_scale(structMember, scale); + break; + } + case StructHintType::OBJECT: + { + std::string buildId = gltfFile.get_node_extra(gltfNode, structMember->name, ""); + if(buildId.empty()) { + value = -1; + } else { + value = get_value_from_hint_object(settings, structMember, buildId); + } + break; + } + case StructHintType::TIME: + { + double timeSeconds = gltfFile.get_node_extra(gltfNode, structMember->name, -1.0); + if(timeSeconds == -1.0) { + value = -1; + break; + } + value = get_value_from_hint_time(structMember, timeSeconds); + break; + } default: DebugHelper::error("Unimplemented hint type: ", structMember->get_hint_type()); break; @@ -195,9 +384,33 @@ void CStructGltfHelper::put_gltf_node_extra_into_struct_entry(CStructEntry *stru case StructHintType::ENUM: values.push_back(get_value_from_hint_enum(structMember, val.Get())); break; + case StructHintType::ASSET_ID: + if(val.Type() == 0) { // Check if null + values.push_back(-1); + } else { + values.push_back(get_value_from_hint_asset_build_id(settings, structMember, val.Get())); + } + break; case StructHintType::ANGLE: values.push_back(get_value_from_hint_angle(structMember, val.Get())); break; + case StructHintType::SCALE: + values.push_back(get_value_from_hint_scale(structMember, val.Get())); + break; + case StructHintType::OBJECT: + if(val.Type() == 0) { // Check if null + values.push_back(-1); + } else { + values.push_back(get_value_from_hint_object(settings, structMember, val.Get())); + } + break; + case StructHintType::TIME: + if(val.Type() == 0) { // Check if null + values.push_back(-1); + } else { + values.push_back(get_value_from_hint_time(structMember, val.Get())); + } + break; default: DebugHelper::error("Unimplemented hint type: ", structMember->get_hint_type()); break; diff --git a/tools/dkr_assets_tool_src/helpers/c/cStructGltfHelper.h b/tools/dkr_assets_tool_src/helpers/c/cStructGltfHelper.h index 393b6cf8..30555cc5 100644 --- a/tools/dkr_assets_tool_src/helpers/c/cStructGltfHelper.h +++ b/tools/dkr_assets_tool_src/helpers/c/cStructGltfHelper.h @@ -1,15 +1,16 @@ #include "helpers/c/cStructHelper.h" #include "helpers/gltf/gltfHelper.h" +#include "misc/settings.hpp" // Class that helps with interacting with both cStructs and Gltf files class CStructGltfHelper { public: // struct entry -> gltf node extra - static void put_struct_entry_into_gltf_node_extra(CStructEntry *structMember, WriteableGltfFile &gltfFile, + static void put_struct_entry_into_gltf_node_extra(DkrAssetsSettings &settings, CStructEntry *structMember, WriteableGltfFile &gltfFile, int gltfNode, uint8_t *bytes); // gltf node extra -> struct entry - static void put_gltf_node_extra_into_struct_entry(CStructEntry *structMember, GltfFile &gltfFile, + static void put_gltf_node_extra_into_struct_entry(DkrAssetsSettings &settings, CStructEntry *structMember, GltfFile &gltfFile, int gltfNode, uint8_t *bytes); }; diff --git a/tools/dkr_assets_tool_src/helpers/c/cStructHelper.cpp b/tools/dkr_assets_tool_src/helpers/c/cStructHelper.cpp index 0d8fe849..50a071a7 100644 --- a/tools/dkr_assets_tool_src/helpers/c/cStructHelper.cpp +++ b/tools/dkr_assets_tool_src/helpers/c/cStructHelper.cpp @@ -230,7 +230,6 @@ int64_t CStructEntry::get_integer_from_data(uint8_t *data, bool isBigEndian) { void CStructEntry::set_integer_to_data(uint8_t *data, int64_t value, bool isBigEndian) { size_t numBytes = get_byte_size(); - for(size_t i = 0; i < numBytes; i++) { size_t index = get_offset() + ((isBigEndian) ? numBytes - i - 1 : i); data[index] = value >> (int64_t)(i * 8); diff --git a/tools/dkr_assets_tool_src/misc/constants.hpp b/tools/dkr_assets_tool_src/misc/constants.hpp index 2f7ffd67..1571af32 100644 --- a/tools/dkr_assets_tool_src/misc/constants.hpp +++ b/tools/dkr_assets_tool_src/misc/constants.hpp @@ -29,3 +29,5 @@ const bool DEFAULT_VERBOSE_VALUE = true; const bool USING_ASSERTS = true; const double DEFAULT_MODEL_SCALE_GLTF = 1.0 / 1000.0; + +const double DKR_FPS = 60.0; // For time conversions