Skip to content

Commit bd4c0ea

Browse files
Add initial animation support to GfxModel
Introduces GfxAnimation and GfxAnimator structures to the model system, and begins parsing animation data from glTF files. Removes borealis-test target and related config from build scripts, and updates external glfw submodule.
1 parent 07398b8 commit bd4c0ea

File tree

7 files changed

+93
-40
lines changed

7 files changed

+93
-40
lines changed

Makefile

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,14 @@ endif
1111
ifeq ($(config),debug)
1212
borealis_config = debug
1313
resource_packer_config = debug
14-
borealis_test_config = debug
1514
glad_config = debug
1615
glfw3_config = debug
1716
stb_config = debug
1817
glm_config = debug
1918

20-
else ifeq ($(config),debug_(renderdoc))
21-
borealis_config = debug_(renderdoc)
22-
resource_packer_config = debug_(renderdoc)
23-
borealis_test_config = debug_(renderdoc)
24-
glad_config = debug_(renderdoc)
25-
glfw3_config = debug_(renderdoc)
26-
stb_config = debug_(renderdoc)
27-
glm_config = debug_(renderdoc)
28-
2919
else ifeq ($(config),release)
3020
borealis_config = release
3121
resource_packer_config = release
32-
borealis_test_config = release
3322
glad_config = release
3423
glfw3_config = release
3524
stb_config = release
@@ -39,7 +28,7 @@ else
3928
$(error "invalid configuration $(config)")
4029
endif
4130

42-
PROJECTS := borealis resource_packer borealis-test glad glfw3 stb glm
31+
PROJECTS := borealis resource_packer glad glfw3 stb glm
4332

4433
.PHONY: all clean help $(PROJECTS)
4534

@@ -57,12 +46,6 @@ ifneq (,$(resource_packer_config))
5746
@${MAKE} --no-print-directory -C . -f resource_packer.make config=$(resource_packer_config)
5847
endif
5948

60-
borealis-test: borealis glad glfw3 resource_packer
61-
ifneq (,$(borealis_test_config))
62-
@echo "==== Building borealis-test ($(borealis_test_config)) ===="
63-
@${MAKE} --no-print-directory -C . -f borealis-test.make config=$(borealis_test_config)
64-
endif
65-
6649
glad:
6750
ifneq (,$(glad_config))
6851
@echo "==== Building glad ($(glad_config)) ===="
@@ -90,7 +73,6 @@ endif
9073
clean:
9174
@${MAKE} --no-print-directory -C . -f borealis.make clean
9275
@${MAKE} --no-print-directory -C . -f resource_packer.make clean
93-
@${MAKE} --no-print-directory -C . -f borealis-test.make clean
9476
@${MAKE} --no-print-directory -C ext/glad -f Makefile clean
9577
@${MAKE} --no-print-directory -C ext/glfw -f Makefile clean
9678
@${MAKE} --no-print-directory -C ext/stb -f Makefile clean
@@ -101,15 +83,13 @@ help:
10183
@echo ""
10284
@echo "CONFIGURATIONS:"
10385
@echo " debug"
104-
@echo " debug_\(renderdoc\)"
10586
@echo " release"
10687
@echo ""
10788
@echo "TARGETS:"
10889
@echo " all (default)"
10990
@echo " clean"
11091
@echo " borealis"
11192
@echo " resource_packer"
112-
@echo " borealis-test"
11393
@echo " glad"
11494
@echo " glfw3"
11595
@echo " stb"

ext/glad/Makefile

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,15 @@ endef
4747
ifeq ($(config),debug)
4848
OBJDIR = build/Debug
4949
DEFINES += -D_CRT_SECURE_NO_WARNINGS -DDEBUG
50-
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g -std=c11 -Wno-warnings -Wall -fcompare-debug-second
51-
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g -Wno-warnings -Wall -fcompare-debug-second
52-
ALL_LDFLAGS += $(LDFLAGS) -L/usr/lib64 -m64
53-
54-
else ifeq ($(config),debug_(renderdoc))
55-
OBJDIR = build/Debug (RenderDoc)
56-
DEFINES += -D_CRT_SECURE_NO_WARNINGS -DDEBUG
57-
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g -std=c11 -Wno-warnings -Wall -fcompare-debug-second
58-
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g -Wno-warnings -Wall -fcompare-debug-second
50+
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -g -std=c11 -Wall -fcompare-debug-second
51+
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -g -Wall -fcompare-debug-second
5952
ALL_LDFLAGS += $(LDFLAGS) -L/usr/lib64 -m64
6053

6154
else ifeq ($(config),release)
6255
OBJDIR = build/Release
6356
DEFINES += -D_CRT_SECURE_NO_WARNINGS -DNDEBUG
64-
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -std=c11 -Wno-warnings -Wall -fcompare-debug-second
65-
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -Wno-warnings -Wall -fcompare-debug-second
57+
ALL_CFLAGS += $(CFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -std=c11 -Wall -fcompare-debug-second
58+
ALL_CXXFLAGS += $(CXXFLAGS) $(ALL_CPPFLAGS) -m64 -O2 -Wall -fcompare-debug-second
6659
ALL_LDFLAGS += $(LDFLAGS) -L/usr/lib64 -m64 -s
6760

6861
endif

ext/glfw

include/borealis/gfx/model.hpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,41 @@ namespace brl
104104
friend GfxModel;
105105
};
106106

107+
struct GfxAnimation {
108+
109+
enum ChannelInterpolation {
110+
LINEAR,
111+
STEP,
112+
CUBICSPLINE
113+
};
114+
115+
enum ChannelType {
116+
TRANSLATION,
117+
ROTATION,
118+
SCALE
119+
};
120+
121+
struct AnimationFrame {
122+
float time;
123+
};
124+
125+
struct Vec3AnimationFrame : AnimationFrame {
126+
glm::vec3 value;
127+
};
128+
129+
struct Channel {
130+
int boneIndex;
131+
ChannelInterpolation interpolation;
132+
ChannelType type;
133+
134+
std::vector<AnimationFrame> frames;
135+
};
136+
137+
std::string name;
138+
139+
140+
141+
};
107142

108143

109144
struct GfxModel {
@@ -112,6 +147,7 @@ namespace brl
112147
std::vector<GfxMaterialDescription*> materialDescriptions;
113148
std::vector<GfxMaterial*> materials;
114149
std::vector<GfxSkin*> skins;
150+
std::vector<GfxAnimation*> animation;
115151

116152
static GfxModel* loadModel(std::string path);
117153

@@ -209,6 +245,16 @@ namespace brl
209245
GfxModelEntity* model = nullptr;
210246
};
211247

248+
249+
250+
struct GfxAnimator : EcsEntity {
251+
252+
GfxAnimation* animation;
253+
254+
private:
255+
GfxModelEntity* model= nullptr;
256+
};
257+
212258
struct GfxModelEntity : EcsEntity
213259
{
214260
std::vector<GfxSkeleton*> skeletons;

mingw_test.bat

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
make clean
2-
make -j8 config=debug
3-
cd out
4-
.\borealis-test.exe
5-
cd ../
2+
make -j8 config=debug

projects.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ project "borealis"
4040

4141
prebuildcommands { resource_packer.." ".._SCRIPT_DIR.."/default_assets/ ".._MAIN_SCRIPT_DIR.."/out/default_assets.res" }
4242

43-
postbuildcommands {
44-
"setx BOREALIS_DIR \"".._SCRIPT_DIR .. "\""
45-
}
43+
postbuildcommands {"setx BOREALIS_DIR \"".._SCRIPT_DIR .. "\""}
4644

4745
links {
4846
"glad",

src/brl/gfx/model.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,45 @@ brl::GfxModel::GfxModel(std::string path)
590590
skins.push_back(s);
591591
}
592592

593+
//https://github.com/mikelma/craftium/blob/7594e8af5637cd77da18bd33520a4907b9a19c6d/irr/src/CGLTFMeshFileLoader.cpp#L646
594+
//https://github.khronos.org/glTF-Tutorials/gltfTutorial/gltfTutorial_007_Animations.html
595+
// https://github.khronos.org/glTF-Tutorials/gltfTutorial/gltfTutorial_006_SimpleAnimation.html
596+
// https://github.com/raysan5/raylib/blob/8fa5f1fe2cf7efeda59a5d935a259ccb1cb97f1c/src/rmodels.c#L6347
597+
//https://raw.githubusercontent.com/KhronosGroup/glTF/refs/heads/main/specification/2.0/figures/gltfOverview-2.0.0d.png
598+
599+
for (tinygltf::Animation anim : model.animations) {
600+
601+
GfxAnimation* animation = new GfxAnimation();
602+
603+
for (tinygltf::AnimationChannel channel : anim.channels) {
604+
605+
GfxAnimation::Channel animChannel{};
606+
607+
tinygltf::AnimationSampler sampler = anim.samplers[channel.sampler];
608+
609+
int targetBone = -1;
610+
611+
for (int i = 0; i <model.skins[0].joints.size(); i++) {
612+
if (model.skins[0].joints[i] == channel.target_node){
613+
targetBone = i;
614+
}
615+
}
616+
617+
if (targetBone == -1)
618+
continue;
619+
620+
if (sampler.interpolation == "LINEAR")
621+
animChannel.interpolation = GfxAnimation::LINEAR;
622+
if (sampler.interpolation == "STEP")
623+
animChannel.interpolation = GfxAnimation::STEP;
624+
if (sampler.interpolation == "CUBICSPLINE")
625+
animChannel.interpolation = GfxAnimation::CUBICSPLINE;
626+
627+
628+
}
629+
630+
animations.push_back(animation);
631+
}
593632
}
594633

595634
brl::GfxModelNode* brl::GfxModel::processNode(tinygltf::Node aNode, tinygltf::Model scene, int index)

0 commit comments

Comments
 (0)