Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wivlaro committed Dec 15, 2024
1 parent 910c28b commit c1296d0
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 69 deletions.
9 changes: 0 additions & 9 deletions src/Animator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <unordered_set>
#include <set>
#include <Corrade/Containers/GrowableArray.h>
#include <Magnum/Trade/AbstractImporter.h>
#include <Magnum/Trade/AnimationData.h>
#include <Corrade/Containers/StructuredBindings.h>
#include <Magnum/Math/CubicHermite.h>
Expand All @@ -27,8 +26,6 @@ namespace MagnumGame {
, _fakeBoneCamera{_boneScene}
, _skins{NoInit, asset._skins.size()}
{


std::map<int, BoneObject *> boneMap;

std::function<void(BoneObject &, const AnimatorAsset::Bone &, int)> instantiateBone =
Expand Down Expand Up @@ -107,12 +104,6 @@ namespace MagnumGame {
auto targetBone = asset._bonesById.find(animatedObjectId);

if (targetBone != asset._bonesById.end()) {
// Debug{} << "Track" << animationName << "track" << trackIndex
// << "target" << animationData.trackTarget(trackIndex)
// << targetBone->second.name
// << "type" << animationData.trackType(trackIndex)
// << "(name" << animationData.trackTargetName(trackIndex) << ")"
// << "result" << animationData.trackResultType(trackIndex);
addAnimationTrack(animationData, trackIndex, targetBone->second, boneMap);
}
else {
Expand Down
1 change: 0 additions & 1 deletion src/Animator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <Magnum/Animation/Animation.h>
#include <Magnum/Animation/Player.h>
#include <Magnum/SceneGraph/AbstractFeature.h>
#include <Magnum/SceneGraph/AbstractObject.h>
Expand Down
48 changes: 19 additions & 29 deletions src/AnimatorAsset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,36 @@
#include <ranges>
#include <assert.h>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/StructuredBindings.h>
#include <Magnum/Trade/SceneData.h>
#include <Magnum/Trade/SkinData.h>
#include <Magnum/Trade/MeshData.h>
#include <Magnum/MeshTools/Compile.h>
#include <Corrade/Containers/StructuredBindings.h>

#include "GameAssets.h"

namespace MagnumGame {
AnimatorAsset::SkinAsset::SkinAsset(const Containers::ArrayView<const UnsignedInt> &joints,
const Containers::ArrayView<const Matrix4>& inverseBindMatrices)
AnimatorAsset::SkinAsset::SkinAsset(const Containers::ArrayView<const UnsignedInt> &joints,
const Containers::ArrayView<const Matrix4> &inverseBindMatrices)
: _jointBoneIds(InPlaceInit, joints),
_inverseBindMatrices(InPlaceInit,inverseBindMatrices)
{
_inverseBindMatrices(InPlaceInit, inverseBindMatrices) {
}

AnimatorAsset::AnimatorAsset(Trade::AbstractImporter &importer)
: _meshes(DefaultInit, importer.meshCount())
, _textures(GameAssets::loadTextures(importer))
, _materials(GameAssets::loadMaterials(importer, _textures))
, _skins{NoInit, importer.skin3DCount()}
{
, _textures(GameAssets::loadTextures(importer))
, _materials(GameAssets::loadMaterials(importer, _textures))
, _skins{NoInit, importer.skin3DCount()} {
auto sceneId = importer.defaultScene();
Debug{} << "Scene" << sceneId << ":" << importer.sceneName(sceneId);
auto sceneData = importer.scene(sceneId);

std::set<int> meshTree{};
std::map<int, Bone &>& boneMap = _bonesById;
std::function<bool(int, Bone &, int)> processBones = [&](int parentId, Bone &parentBone, int depth) {
assert(boneMap.find(parentId) == boneMap.end());
boneMap.insert({parentId, parentBone});
assert(boneMap.find(parentId) != boneMap.end());
assert(&boneMap.find(parentId)->second == &parentBone);
assert(_bonesById.find(parentId) == _bonesById.end());
_bonesById.insert({parentId, parentBone});
assert(_bonesById.find(parentId) != _bonesById.end());
assert(&_bonesById.find(parentId)->second == &parentBone);

parentBone.boneId = parentId;

Expand All @@ -54,7 +50,7 @@ namespace MagnumGame {
parentBone.children = Containers::Array<Bone>{NoInit, childIds.size()};
for (size_t childIndex = 0; childIndex < childIds.size(); ++childIndex) {
auto childId = childIds[childIndex];
auto& childBone = *new (&parentBone.children[childIndex]) Bone(importer.objectName(childId));
auto &childBone = *new(&parentBone.children[childIndex]) Bone(importer.objectName(childId));

if (auto transform = sceneData->transformation3DFor(childId)) {
childBone.defaultTranslation = transform->translation();
Expand Down Expand Up @@ -84,7 +80,7 @@ namespace MagnumGame {

auto jointIds = skinData->joints();
assert(jointIds.size() == inverseBindMatrices.size());
new (&_skins[skinId]) SkinAsset{jointIds, inverseBindMatrices};
new(&_skins[skinId]) SkinAsset{jointIds, inverseBindMatrices};
}

Debug{} << "Meshes:" << importer.meshCount();
Expand All @@ -102,25 +98,22 @@ namespace MagnumGame {
perVertexJointCounts[meshId] = MeshTools::compiledPerVertexJointCount(*meshData);
}

std::function<void(int, SkinMeshNode&, int)> processMeshes = [&](int parentId, SkinMeshNode& parentAsset, int depth) {

std::function<void(int, SkinMeshNode &, int)> processMeshes = [&](int parentId, SkinMeshNode &parentAsset, int depth) {
if (meshTree.find(parentId) == meshTree.end()) {
Debug{} << std::string(depth, '\t') << "Skipping" << parentId << (parentId == -1
? "ROOT"
: importer.objectName(parentId))
Debug{} << std::string(depth, '\t') << "Skipping"
<< parentId << (parentId == -1 ? "ROOT" : importer.objectName(parentId))
<< "No Mesh";
return;
}


auto childIds = sceneData->childrenFor(parentId);
parentAsset.children = Containers::Array<SkinMeshNode>{NoInit, childIds.size()};
for (size_t childIndex = 0; childIndex < childIds.size(); ++childIndex) {
auto childId = childIds[childIndex];
auto childName = importer.objectName(childId);
Debug{} << std::string(depth, '\t') << "Object" << childId << childName;

auto &child = *new (&parentAsset.children[childIndex]) SkinMeshNode(childName);;
auto &child = *new(&parentAsset.children[childIndex]) SkinMeshNode(childName);;
if (auto transform = sceneData->transformation3DFor(childId)) {
child.transform = *transform;
}
Expand All @@ -132,10 +125,8 @@ namespace MagnumGame {
break;
}
for (auto [meshId,matId]: sceneData->meshesMaterialsFor(childId)) {

Debug{} << std::string(depth, '\t') << " " << "Mesh" << meshId << importer.meshName(meshId) <<
"Material" << matId <<
(matId != -1 ? importer.materialName(matId) : "NO MATERIAL");
"Material" << matId << (matId != -1 ? importer.materialName(matId) : "NO MATERIAL");

auto meshPerVertexJointCounts = perVertexJointCounts[meshId];
child.skinMesh = {
Expand All @@ -162,5 +153,4 @@ namespace MagnumGame {
}
}
}

} // MagnumGame
} // MagnumGame
2 changes: 1 addition & 1 deletion src/GameAssets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include <Magnum/Trade/MaterialData.h>
#include <Magnum/Trade/TextureData.h>
#include <Magnum/Trade/ImageData.h>
#include <Magnum/ImageView.h>
#include <Magnum/GL/Texture.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/Math/Matrix4.h>
#include <Magnum/Math/Vector3.h>
#include <Magnum/Math/Color.h>
#include <Magnum/ImageView.h>
#include <Corrade/Utility/Path.h>

#include "MagnumGameApp.h"
Expand Down
15 changes: 7 additions & 8 deletions src/GameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/Path.h>
#include <Corrade/Utility/String.h>
#include <Corrade/Containers/StructuredBindings.h>
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/MeshTools/Compile.h>
#include <Magnum/Trade/LightData.h>
#include <Magnum/Trade/MeshData.h>
#include <Magnum/Trade/SceneData.h>
#include <Magnum/GL/Renderer.h>
#include <Corrade/Containers/StructuredBindings.h>
#include <Magnum/DebugTools/ObjectRenderer.h>

#include "GameAssets.h"
#include "OnGroundQuery.h"
#include "Player.h"

namespace MagnumGame {
Expand Down Expand Up @@ -139,12 +138,12 @@ namespace MagnumGame {

Debug debug{};
debug << "\tLight" << objectId << light
<< lightData->type()
<< "atten" << lightData->attenuation()
<< "color" << lightData->color()
<< "intensity" << lightData->intensity()
<< "range" <<lightData->range()
<< "cone angles" << lightData->innerConeAngle() << lightData->outerConeAngle();
<< lightData->type()
<< "atten" << lightData->attenuation()
<< "color" << lightData->color()
<< "intensity" << lightData->intensity()
<< "range" << lightData->range()
<< "cone angles" << lightData->innerConeAngle() << lightData->outerConeAngle();

if (auto matrix = sceneData->transformation3DFor(objectId)) {
debug << "\tTransformation" << matrix->translation();
Expand Down
3 changes: 0 additions & 3 deletions src/GameState.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#pragma once
#include <vector>
#include <BulletCollision/CollisionDispatch/btGhostObject.h>
#include <BulletCollision/CollisionShapes/btSphereShape.h>
#include <Corrade/Containers/Optional.h>
#include <Magnum/Math/Vector3.h>

#include "GameAssets.h"
#include "MagnumGameApp.h"
Expand Down
4 changes: 0 additions & 4 deletions src/MagnumGameApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@
#include <Magnum/Timeline.h>
#include <Magnum/BulletIntegration/DebugDraw.h>
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Mesh.h>
#include <Magnum/GL/Renderer.h>
#include <Magnum/Math/Color.h>
#include <Magnum/Math/Time.h>
#include <Magnum/MeshTools/Compile.h>
#include <Magnum/MeshTools/Transform.h>
#include <Magnum/SceneGraph/Camera.h>
#include <Magnum/SceneGraph/Scene.h>
#include <Magnum/Shaders/PhongGL.h>
#include <Magnum/Trade/AbstractImporter.h>
#include <Magnum/Trade/TextureData.h>
#include <Magnum/Trade/MaterialData.h>
#include <Magnum/Text/AbstractFont.h>
#include <Magnum/TextureTools/Atlas.h>
#include <Magnum/ImageView.h>
Expand All @@ -37,7 +34,6 @@

#include "DebugLines.h"
#include "GameState.h"
#include "GameAssets.h"
#include "UserInterface.h"

#ifdef BT_USE_DOUBLE_PRECISION
Expand Down
1 change: 0 additions & 1 deletion src/MagnumGameApp_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#endif

#include "GameState.h"
#include "OnGroundQuery.h"
#include "Player.h"
#include "Tweakables.h"
#include "UserInterface.h"
Expand Down
1 change: 0 additions & 1 deletion src/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <vector>
#include "Player.h"

#include "DebugLines.h"
#include "OnGroundQuery.h"
#include "TexturedDrawable.h"
#include "RigidBody.h"
Expand Down
10 changes: 5 additions & 5 deletions src/TexturedDrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
namespace MagnumGame {
TexturedDrawable::TexturedDrawable(SceneGraph::AbstractObject3D &object,
const Trade::ImageData2D &image,
Magnum::Shaders::PhongGL &shader,
Magnum::GL::Mesh &mesh,
Shaders::PhongGL &shader,
GL::Mesh &mesh,
SceneGraph::DrawableGroup3D &drawables,
UnsignedInt objectId)
: SceneGraph::Drawable3D(object, &drawables),
Expand All @@ -32,8 +32,8 @@ namespace MagnumGame {

TexturedDrawable::TexturedDrawable(SceneGraph::AbstractObject3D &object,
GL::Texture2D *texture,
Magnum::Shaders::PhongGL &shader,
Magnum::GL::Mesh &mesh,
Shaders::PhongGL &shader,
GL::Mesh &mesh,
SceneGraph::DrawableGroup3D &drawables,
UnsignedInt objectId)
: SceneGraph::Drawable3D{object, &drawables},
Expand All @@ -58,7 +58,7 @@ namespace MagnumGame {
return t;
}

void TexturedDrawable::draw(const Magnum::Matrix4 &transformation, SceneGraph::Camera3D &camera) {
void TexturedDrawable::draw(const Matrix4 &transformation, SceneGraph::Camera3D &camera) {
if (_color.a() <= 0.0f) return;
CHECK_GL_ERROR(__FILE__, __LINE__);
_shader.setProjectionMatrix(camera.projectionMatrix());
Expand Down
2 changes: 0 additions & 2 deletions src/TexturedDrawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#pragma once

#include <Corrade/Containers/Optional.h>
#include <Magnum/SceneGraph/Drawable.h>
#include <Magnum/Math/Color.h>
#include <Magnum/Trade/Trade.h>
#include <Magnum/GL/GL.h>
Expand All @@ -14,7 +13,6 @@

#include "Animator.h"
#include "IEnableDrawable.h"
#include "MagnumGameCommon.h"


namespace MagnumGame {
Expand Down
1 change: 0 additions & 1 deletion src/Tweakables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <sstream>
#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Utility/DebugStl.h>

#include "MagnumGameApp.h"
#include "Player.h"
Expand Down
2 changes: 0 additions & 2 deletions src/Tweakables.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#pragma once
#include <functional>
#include <utility>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/Pointer.h>

#include "MagnumGameApp.h"
#include "UserInterface.h"
Expand Down
1 change: 0 additions & 1 deletion src/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <Corrade/Containers/GrowableArray.h>
#include <Magnum/Math/Matrix3.h>
#include <Magnum/Math/Color.h>

namespace MagnumGame {
using namespace Magnum::Math::Literals;
Expand Down
1 change: 0 additions & 1 deletion src/UserInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/Reference.h>
#include <Corrade/PluginManager/Manager.h>
#include <Magnum/Math/Matrix3.h>
#include <Magnum/Shaders/DistanceFieldVectorGL.h>
Expand Down

0 comments on commit c1296d0

Please sign in to comment.