From cd6656be354de8facfaac015053e800490c555ee Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Fri, 1 Mar 2024 10:06:18 +0000 Subject: [PATCH 1/2] Fix archive Incorrect cmake directory was messing up reading from zips STB was failing to read from zips, it was failing to get the file info, something we were using as an early out, now if that files on the filepath, we use the memory read instead since stream needs to be a success to get to that point. --- Engine/source/CMakeLists.txt | 2 +- Engine/source/gfx/bitmap/gBitmap.cpp | 11 ++++++++--- Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp | 8 +++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Engine/source/CMakeLists.txt b/Engine/source/CMakeLists.txt index f1c243940..342338160 100644 --- a/Engine/source/CMakeLists.txt +++ b/Engine/source/CMakeLists.txt @@ -97,7 +97,7 @@ endif (WIN32 AND TORQUE_D3D11) # Handle core torqueAddSourceDirectories("core" "core/stream" "core/strings" "core/util" - "core/util/journal" "core/util/zip" "core/util/compressors") + "core/util/journal" "core/util/zip" "core/util/zip/compressors") # Handle GUI torqueAddSourceDirectories("gui" "gui/buttons" "gui/containers" "gui/controls" "gui/core" "gui/game" "gui/shiny" "gui/utility" "gui/3d") diff --git a/Engine/source/gfx/bitmap/gBitmap.cpp b/Engine/source/gfx/bitmap/gBitmap.cpp index 8fc0590b6..82c8b2c7f 100644 --- a/Engine/source/gfx/bitmap/gBitmap.cpp +++ b/Engine/source/gfx/bitmap/gBitmap.cpp @@ -1279,9 +1279,14 @@ template<> void *Resource::create(const Torque::Path &path) const String extension = path.getExtension(); if( !bmp->readBitmap( extension, path ) ) { - Con::errorf( "Resource::create - error reading '%s'", path.getFullPath().c_str() ); - delete bmp; - bmp = NULL; + // we can only get here if the stream was successful, so attempt to read the stream. + Con::warnf("Was unable to load as file, going to try the stream instead."); + if (!bmp->readBitmapStream(extension, stream, stream.getStreamSize())) + { + Con::errorf("Resource::create - error reading '%s'", path.getFullPath().c_str()); + delete bmp; + bmp = NULL; + } } return bmp; diff --git a/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp b/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp index a5a97917a..00ef53891 100644 --- a/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp +++ b/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp @@ -195,6 +195,12 @@ bool sReadSTB(const Torque::Path& path, GBitmap* bitmap) if (!stbi_info(path.getFullPath().c_str(), &x, &y, &channels)) { FrameAllocator::setWaterMark(prevWaterMark); + const char* stbErr = stbi_failure_reason(); + + if (!stbErr) + stbErr = "Unknown Error!"; + + Con::errorf("STB failed to get image info: %s", stbErr); return false; } @@ -326,7 +332,7 @@ bool sReadStreamSTB(Stream& stream, GBitmap* bitmap, U32 len) stbErr = "Unknown Error!"; Con::errorf("STB failed to get image info: %s", stbErr); - return false; + Con::warnf("Going to attempt to load stream anyway."); } S32 reqCom = comp; From 6355da5df63b05f780579cbb2ff46ae29d3dea79 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Fri, 1 Mar 2024 15:01:47 +0000 Subject: [PATCH 2/2] various fixes STB probably shouldn't fail on failed info, just continue. Assimp only add sequences if there are any. Update kork chan asset. --- .../source/gfx/bitmap/loaders/bitmapSTB.cpp | 6 +-- Engine/source/ts/assimp/assimpShapeLoader.cpp | 54 ++++++++++--------- .../shapes/kork_chanShape.asset.taml | 6 --- .../Prototyping/shapes/kork_chanShape.tscript | 30 ++--------- .../shapes/kork_chanShape_shape.asset.taml | 5 ++ .../shapes/kork_chan_image.asset.taml | 3 +- .../shapes/kork_chan_mat.asset.taml | 7 ++- 7 files changed, 44 insertions(+), 67 deletions(-) delete mode 100644 Templates/BaseGame/game/data/Prototyping/shapes/kork_chanShape.asset.taml create mode 100644 Templates/BaseGame/game/data/Prototyping/shapes/kork_chanShape_shape.asset.taml diff --git a/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp b/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp index 00ef53891..6eb79895c 100644 --- a/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp +++ b/Engine/source/gfx/bitmap/loaders/bitmapSTB.cpp @@ -200,8 +200,7 @@ bool sReadSTB(const Torque::Path& path, GBitmap* bitmap) if (!stbErr) stbErr = "Unknown Error!"; - Con::errorf("STB failed to get image info: %s", stbErr); - return false; + Con::errorf("STB get file info: %s", stbErr); } // do this to map 2 channels to 4, 2 channel not supported by gbitmap yet.. @@ -331,8 +330,7 @@ bool sReadStreamSTB(Stream& stream, GBitmap* bitmap, U32 len) if (!stbErr) stbErr = "Unknown Error!"; - Con::errorf("STB failed to get image info: %s", stbErr); - Con::warnf("Going to attempt to load stream anyway."); + Con::errorf("STB get memory info: %s", stbErr); } S32 reqCom = comp; diff --git a/Engine/source/ts/assimp/assimpShapeLoader.cpp b/Engine/source/ts/assimp/assimpShapeLoader.cpp index 908e186f2..8478e4b78 100644 --- a/Engine/source/ts/assimp/assimpShapeLoader.cpp +++ b/Engine/source/ts/assimp/assimpShapeLoader.cpp @@ -261,38 +261,40 @@ void AssimpShapeLoader::processAnimations() Vector ambientChannels; F32 duration = 0.0f; - - for (U32 i = 0; i < mScene->mNumAnimations; ++i) + if (mScene->mNumAnimations > 0) { - aiAnimation* anim = mScene->mAnimations[i]; - for (U32 j = 0; j < anim->mNumChannels; j++) + for (U32 i = 0; i < mScene->mNumAnimations; ++i) { - aiNodeAnim* nodeAnim = anim->mChannels[j]; - // Determine the maximum keyframe time for this animation - F32 maxKeyTime = 0.0f; - for (U32 k = 0; k < nodeAnim->mNumPositionKeys; k++) { - maxKeyTime = getMax(maxKeyTime, (F32)nodeAnim->mPositionKeys[k].mTime); - } - for (U32 k = 0; k < nodeAnim->mNumRotationKeys; k++) { - maxKeyTime = getMax(maxKeyTime, (F32)nodeAnim->mRotationKeys[k].mTime); - } - for (U32 k = 0; k < nodeAnim->mNumScalingKeys; k++) { - maxKeyTime = getMax(maxKeyTime, (F32)nodeAnim->mScalingKeys[k].mTime); - } + aiAnimation* anim = mScene->mAnimations[i]; + for (U32 j = 0; j < anim->mNumChannels; j++) + { + aiNodeAnim* nodeAnim = anim->mChannels[j]; + // Determine the maximum keyframe time for this animation + F32 maxKeyTime = 0.0f; + for (U32 k = 0; k < nodeAnim->mNumPositionKeys; k++) { + maxKeyTime = getMax(maxKeyTime, (F32)nodeAnim->mPositionKeys[k].mTime); + } + for (U32 k = 0; k < nodeAnim->mNumRotationKeys; k++) { + maxKeyTime = getMax(maxKeyTime, (F32)nodeAnim->mRotationKeys[k].mTime); + } + for (U32 k = 0; k < nodeAnim->mNumScalingKeys; k++) { + maxKeyTime = getMax(maxKeyTime, (F32)nodeAnim->mScalingKeys[k].mTime); + } - ambientChannels.push_back(nodeAnim); + ambientChannels.push_back(nodeAnim); - duration = getMax(duration, maxKeyTime); + duration = getMax(duration, maxKeyTime); + } } + + ambientSeq->mNumChannels = ambientChannels.size(); + ambientSeq->mChannels = ambientChannels.address(); + ambientSeq->mDuration = duration; + ambientSeq->mTicksPerSecond = 24.0; + + AssimpAppSequence* defaultAssimpSeq = new AssimpAppSequence(ambientSeq); + appSequences.push_back(defaultAssimpSeq); } - - ambientSeq->mNumChannels = ambientChannels.size(); - ambientSeq->mChannels = ambientChannels.address(); - ambientSeq->mDuration = duration; - ambientSeq->mTicksPerSecond = 24.0; - - AssimpAppSequence* defaultAssimpSeq = new AssimpAppSequence(ambientSeq); - appSequences.push_back(defaultAssimpSeq); } void AssimpShapeLoader::computeBounds(Box3F& bounds) diff --git a/Templates/BaseGame/game/data/Prototyping/shapes/kork_chanShape.asset.taml b/Templates/BaseGame/game/data/Prototyping/shapes/kork_chanShape.asset.taml deleted file mode 100644 index 475aa7543..000000000 --- a/Templates/BaseGame/game/data/Prototyping/shapes/kork_chanShape.asset.taml +++ /dev/null @@ -1,6 +0,0 @@ - diff --git a/Templates/BaseGame/game/data/Prototyping/shapes/kork_chanShape.tscript b/Templates/BaseGame/game/data/Prototyping/shapes/kork_chanShape.tscript index b53ee1f48..4df275dee 100644 --- a/Templates/BaseGame/game/data/Prototyping/shapes/kork_chanShape.tscript +++ b/Templates/BaseGame/game/data/Prototyping/shapes/kork_chanShape.tscript @@ -1,28 +1,8 @@ -//--- OBJECT WRITE BEGIN --- -new TSShapeConstructor(kork_chanShape_fbx) { - baseShapeAsset = "Prototyping:kork_chanShape"; - upAxis = "DEFAULT"; - unit = "-1"; - LODType = "TrailingNumber"; + +singleton TSShapeConstructor(kork_chanShapefbx) +{ + baseShapeAsset = ":kork_chanShape_shape"; singleDetailSize = "0"; - IgnoreNodeScale = "0"; - AdjustCenter = "0"; - AdjustFloor = "0"; - forceUpdateMaterials = "0"; - convertLeftHanded = "0"; - calcTangentSpace = "0"; - genUVCoords = "0"; - transformUVCoords = "0"; - flipUVCoords = "1"; - findInstances = "0"; - limitBoneWeights = "0"; - JoinIdenticalVerts = "1"; - reverseWindingOrder = "1"; - invertNormals = "0"; - removeRedundantMats = "1"; - animTiming = "Seconds"; + neverImportMat = "DefaultMaterial ColorEffect*"; animFPS = "2"; - canSave = "1"; - canSaveDynamicFields = "1"; }; -//--- OBJECT WRITE END --- diff --git a/Templates/BaseGame/game/data/Prototyping/shapes/kork_chanShape_shape.asset.taml b/Templates/BaseGame/game/data/Prototyping/shapes/kork_chanShape_shape.asset.taml new file mode 100644 index 000000000..ec589dd35 --- /dev/null +++ b/Templates/BaseGame/game/data/Prototyping/shapes/kork_chanShape_shape.asset.taml @@ -0,0 +1,5 @@ + diff --git a/Templates/BaseGame/game/data/Prototyping/shapes/kork_chan_image.asset.taml b/Templates/BaseGame/game/data/Prototyping/shapes/kork_chan_image.asset.taml index db20da923..88c5b7a6f 100644 --- a/Templates/BaseGame/game/data/Prototyping/shapes/kork_chan_image.asset.taml +++ b/Templates/BaseGame/game/data/Prototyping/shapes/kork_chan_image.asset.taml @@ -1,4 +1,3 @@ + imageFile="@assetFile=kork_chan.png"/> diff --git a/Templates/BaseGame/game/data/Prototyping/shapes/kork_chan_mat.asset.taml b/Templates/BaseGame/game/data/Prototyping/shapes/kork_chan_mat.asset.taml index c6b7a02b1..39a276210 100644 --- a/Templates/BaseGame/game/data/Prototyping/shapes/kork_chan_mat.asset.taml +++ b/Templates/BaseGame/game/data/Prototyping/shapes/kork_chan_mat.asset.taml @@ -5,12 +5,11 @@ + doubleSided="true" + originalAssetName="kork_chan_mat"> + DiffuseMapAsset="Prototyping:kork_chan_image"/>