summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--assets/models/gltf/SimpleSkin/LICENSE.md15
-rw-r--r--assets/models/gltf/SimpleSkin/README.body.md18
-rw-r--r--assets/models/gltf/SimpleSkin/README.md42
-rw-r--r--assets/models/gltf/SimpleSkin/glTF-Embedded/SimpleSkin.gltf131
-rw-r--r--assets/models/gltf/SimpleSkin/glTF/SimpleSkin.gltf131
-rw-r--r--assets/models/gltf/SimpleSkin/glTF/inverseBindMatrices.binbin0 -> 128 bytes
-rw-r--r--assets/models/gltf/SimpleSkin/glTF/skinAnimation.binbin0 -> 240 bytes
-rw-r--r--assets/models/gltf/SimpleSkin/glTF/skinGeometry.binbin0 -> 168 bytes
-rw-r--r--assets/models/gltf/SimpleSkin/glTF/skinningData.binbin0 -> 320 bytes
-rw-r--r--assets/models/gltf/SimpleSkin/metadata.json26
-rw-r--r--assets/models/gltf/SimpleSkin/screenshot/inverseBindMatrices.pngbin0 -> 43880 bytes
-rw-r--r--assets/models/gltf/SimpleSkin/screenshot/screenshot.gifbin0 -> 2000860 bytes
-rw-r--r--assets/models/gltf/SimpleSkin/screenshot/skinAnimation.pngbin0 -> 100791 bytes
-rw-r--r--assets/models/gltf/SimpleSkin/screenshot/skinGeometry.pngbin0 -> 74566 bytes
-rw-r--r--assets/models/gltf/SimpleSkin/screenshot/skinningData.pngbin0 -> 86339 bytes
-rw-r--r--examples/example_scene.h31
-rw-r--r--examples/property_animation/ex_property_animation.c34
-rw-r--r--src/animation.c18
-rw-r--r--src/resources/gltf.c77
20 files changed, 466 insertions, 58 deletions
diff --git a/.gitignore b/.gitignore
index f082afc..605c5e9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,5 +5,6 @@ _temp
.vscode
.cache
.clangd
+.DS_Store
compile_commands.json
node_modules/ \ No newline at end of file
diff --git a/assets/models/gltf/SimpleSkin/LICENSE.md b/assets/models/gltf/SimpleSkin/LICENSE.md
new file mode 100644
index 0000000..e602203
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/LICENSE.md
@@ -0,0 +1,15 @@
+# LICENSE file for the model: Simple Skin
+
+All files in this directory tree are licensed as indicated below.
+
+* All files directly associated with the model including all text, image and binary files:
+
+ * [CC0 1.0 Universal]("https://creativecommons.org/publicdomain/zero/1.0/legalcode") [SPDX license identifier: "CC0-1.0"]
+
+* This file and all other metadocumentation files including "metadata.json":
+
+ * [Creative Commons Attribtution 4.0 International]("https://creativecommons.org/licenses/by/4.0/legalcode") [SPDX license identifier: "CC-BY-4.0"]
+
+Full license text of these licenses are available at the links above
+
+#### Generated by modelmetadata \ No newline at end of file
diff --git a/assets/models/gltf/SimpleSkin/README.body.md b/assets/models/gltf/SimpleSkin/README.body.md
new file mode 100644
index 0000000..00cd41e
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/README.body.md
@@ -0,0 +1,18 @@
+## Screenshot
+
+![screenshot](screenshot/screenshot.gif)
+
+## Notes
+
+Details about skinning using this particular model are explained in the
+[skinning section of the glTF tutorial](https://github.com/javagl/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_019_SimpleSkin.md).
+
+## Data layout
+
+The following images show the data layout of this sample:
+
+![skinGeometry](screenshot/skinGeometry.png)
+![skinAnimation](screenshot/skinAnimation.png)
+![inverseBindMatrices](screenshot/inverseBindMatrices.png)
+![skinningData](screenshot/skinningData.png)
+
diff --git a/assets/models/gltf/SimpleSkin/README.md b/assets/models/gltf/SimpleSkin/README.md
new file mode 100644
index 0000000..ec08353
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/README.md
@@ -0,0 +1,42 @@
+# Simple Skin
+
+## Tags
+
+[core](../../Models-core.md), [testing](../../Models-testing.md), [written](../../Models-written.md)
+
+## Summary
+
+A simple example of vertex skinning in glTF
+
+## Operations
+
+* [Display](https://github.khronos.org/glTF-Sample-Viewer-Release/?model=https://raw.GithubUserContent.com/KhronosGroup/glTF-Sample-Assets/main/./Models/SimpleSkin/glTF/SimpleSkin.gltf) in SampleViewer
+* [Model Directory](./)
+
+## Screenshot
+
+![screenshot](screenshot/screenshot.gif)
+
+## Notes
+
+Details about skinning using this particular model are explained in the
+[skinning section of the glTF tutorial](https://github.com/javagl/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_019_SimpleSkin.md).
+
+## Data layout
+
+The following images show the data layout of this sample:
+
+![skinGeometry](screenshot/skinGeometry.png)
+![skinAnimation](screenshot/skinAnimation.png)
+![inverseBindMatrices](screenshot/inverseBindMatrices.png)
+![skinningData](screenshot/skinningData.png)
+
+
+
+## Legal
+
+© 2017, Public. [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode)
+
+ - javagl for Everything
+
+#### Assembled by modelmetadata \ No newline at end of file
diff --git a/assets/models/gltf/SimpleSkin/glTF-Embedded/SimpleSkin.gltf b/assets/models/gltf/SimpleSkin/glTF-Embedded/SimpleSkin.gltf
new file mode 100644
index 0000000..e9f4e4d
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/glTF-Embedded/SimpleSkin.gltf
@@ -0,0 +1,131 @@
+{
+ "scene" : 0,
+ "scenes" : [ {
+ "nodes" : [ 0, 1 ]
+ } ],
+
+ "nodes" : [ {
+ "skin" : 0,
+ "mesh" : 0
+ }, {
+ "children" : [ 2 ]
+ }, {
+ "translation" : [ 0.0, 1.0, 0.0 ],
+ "rotation" : [ 0.0, 0.0, 0.0, 1.0 ]
+ } ],
+
+ "meshes" : [ {
+ "primitives" : [ {
+ "attributes" : {
+ "POSITION" : 1,
+ "JOINTS_0" : 2,
+ "WEIGHTS_0" : 3
+ },
+ "indices" : 0
+ } ]
+ } ],
+
+ "skins" : [ {
+ "inverseBindMatrices" : 4,
+ "joints" : [ 1, 2 ]
+ } ],
+
+ "animations" : [ {
+ "channels" : [ {
+ "sampler" : 0,
+ "target" : {
+ "node" : 2,
+ "path" : "rotation"
+ }
+ } ],
+ "samplers" : [ {
+ "input" : 5,
+ "interpolation" : "LINEAR",
+ "output" : 6
+ } ]
+ } ],
+
+ "buffers" : [ {
+ "uri" : "data:application/gltf-buffer;base64,AAABAAMAAAADAAIAAgADAAUAAgAFAAQABAAFAAcABAAHAAYABgAHAAkABgAJAAgAAAAAvwAAAAAAAAAAAAAAPwAAAAAAAAAAAAAAvwAAAD8AAAAAAAAAPwAAAD8AAAAAAAAAvwAAgD8AAAAAAAAAPwAAgD8AAAAAAAAAvwAAwD8AAAAAAAAAPwAAwD8AAAAAAAAAvwAAAEAAAAAAAAAAPwAAAEAAAAAA",
+ "byteLength" : 168
+ }, {
+ "uri" : "data:application/gltf-buffer;base64,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAABAPwAAgD4AAAAAAAAAAAAAQD8AAIA+AAAAAAAAAAAAAAA/AAAAPwAAAAAAAAAAAAAAPwAAAD8AAAAAAAAAAAAAgD4AAEA/AAAAAAAAAAAAAIA+AABAPwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAA=",
+ "byteLength" : 320
+ }, {
+ "uri" : "data:application/gltf-buffer;base64,AACAPwAAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAAAAAAAAAAACAPwAAgD8AAAAAAAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAIC/AAAAAAAAgD8=",
+ "byteLength" : 128
+ }, {
+ "uri" : "data:application/gltf-buffer;base64,AAAAAAAAAD8AAIA/AADAPwAAAEAAACBAAABAQAAAYEAAAIBAAACQQAAAoEAAALBAAAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAkxjEPkSLbD8AAAAAAAAAAPT9ND/0/TQ/AAAAAAAAAAD0/TQ/9P00PwAAAAAAAAAAkxjEPkSLbD8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAkxjEvkSLbD8AAAAAAAAAAPT9NL/0/TQ/AAAAAAAAAAD0/TS/9P00PwAAAAAAAAAAkxjEvkSLbD8AAAAAAAAAAAAAAAAAAIA/",
+ "byteLength" : 240
+ } ],
+
+ "bufferViews" : [ {
+ "buffer" : 0,
+ "byteLength" : 48,
+ "target" : 34963
+ }, {
+ "buffer" : 0,
+ "byteOffset" : 48,
+ "byteLength" : 120,
+ "target" : 34962
+ }, {
+ "buffer" : 1,
+ "byteLength" : 320,
+ "byteStride" : 16
+ }, {
+ "buffer" : 2,
+ "byteLength" : 128
+ }, {
+ "buffer" : 3,
+ "byteLength" : 240
+ } ],
+
+ "accessors" : [ {
+ "bufferView" : 0,
+ "componentType" : 5123,
+ "count" : 24,
+ "type" : "SCALAR"
+ }, {
+ "bufferView" : 1,
+ "componentType" : 5126,
+ "count" : 10,
+ "type" : "VEC3",
+ "max" : [ 0.5, 2.0, 0.0 ],
+ "min" : [ -0.5, 0.0, 0.0 ]
+ }, {
+ "bufferView" : 2,
+ "componentType" : 5123,
+ "count" : 10,
+ "type" : "VEC4"
+ }, {
+ "bufferView" : 2,
+ "byteOffset" : 160,
+ "componentType" : 5126,
+ "count" : 10,
+ "type" : "VEC4"
+ }, {
+ "bufferView" : 3,
+ "componentType" : 5126,
+ "count" : 2,
+ "type" : "MAT4"
+ }, {
+ "bufferView" : 4,
+ "componentType" : 5126,
+ "count" : 12,
+ "type" : "SCALAR",
+ "max" : [ 5.5 ],
+ "min" : [ 0.0 ]
+ }, {
+ "bufferView" : 4,
+ "byteOffset" : 48,
+ "componentType" : 5126,
+ "count" : 12,
+ "type" : "VEC4",
+ "max" : [ 0.0, 0.0, 0.707, 1.0 ],
+ "min" : [ 0.0, 0.0, -0.707, 0.707 ]
+ } ],
+
+ "asset" : {
+ "version" : "2.0"
+ }
+} \ No newline at end of file
diff --git a/assets/models/gltf/SimpleSkin/glTF/SimpleSkin.gltf b/assets/models/gltf/SimpleSkin/glTF/SimpleSkin.gltf
new file mode 100644
index 0000000..52f0aa0
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/glTF/SimpleSkin.gltf
@@ -0,0 +1,131 @@
+{
+ "scene" : 0,
+ "scenes" : [ {
+ "nodes" : [ 0, 1 ]
+ } ],
+
+ "nodes" : [ {
+ "skin" : 0,
+ "mesh" : 0
+ }, {
+ "children" : [ 2 ]
+ }, {
+ "translation" : [ 0.0, 1.0, 0.0 ],
+ "rotation" : [ 0.0, 0.0, 0.0, 1.0 ]
+ } ],
+
+ "meshes" : [ {
+ "primitives" : [ {
+ "attributes" : {
+ "POSITION" : 1,
+ "JOINTS_0" : 2,
+ "WEIGHTS_0" : 3
+ },
+ "indices" : 0
+ } ]
+ } ],
+
+ "skins" : [ {
+ "inverseBindMatrices" : 4,
+ "joints" : [ 1, 2 ]
+ } ],
+
+ "animations" : [ {
+ "channels" : [ {
+ "sampler" : 0,
+ "target" : {
+ "node" : 2,
+ "path" : "rotation"
+ }
+ } ],
+ "samplers" : [ {
+ "input" : 5,
+ "interpolation" : "LINEAR",
+ "output" : 6
+ } ]
+ } ],
+
+ "buffers" : [ {
+ "uri" : "skinGeometry.bin",
+ "byteLength" : 168
+ }, {
+ "uri" : "skinningData.bin",
+ "byteLength" : 320
+ }, {
+ "uri" : "inverseBindMatrices.bin",
+ "byteLength" : 128
+ }, {
+ "uri" : "skinAnimation.bin",
+ "byteLength" : 240
+ } ],
+
+ "bufferViews" : [ {
+ "buffer" : 0,
+ "byteLength" : 48,
+ "target" : 34963
+ }, {
+ "buffer" : 0,
+ "byteOffset" : 48,
+ "byteLength" : 120,
+ "target" : 34962
+ }, {
+ "buffer" : 1,
+ "byteLength" : 320,
+ "byteStride" : 16
+ }, {
+ "buffer" : 2,
+ "byteLength" : 128
+ }, {
+ "buffer" : 3,
+ "byteLength" : 240
+ } ],
+
+ "accessors" : [ {
+ "bufferView" : 0,
+ "componentType" : 5123,
+ "count" : 24,
+ "type" : "SCALAR"
+ }, {
+ "bufferView" : 1,
+ "componentType" : 5126,
+ "count" : 10,
+ "type" : "VEC3",
+ "max" : [ 0.5, 2.0, 0.0 ],
+ "min" : [ -0.5, 0.0, 0.0 ]
+ }, {
+ "bufferView" : 2,
+ "componentType" : 5123,
+ "count" : 10,
+ "type" : "VEC4"
+ }, {
+ "bufferView" : 2,
+ "byteOffset" : 160,
+ "componentType" : 5126,
+ "count" : 10,
+ "type" : "VEC4"
+ }, {
+ "bufferView" : 3,
+ "componentType" : 5126,
+ "count" : 2,
+ "type" : "MAT4"
+ }, {
+ "bufferView" : 4,
+ "componentType" : 5126,
+ "count" : 12,
+ "type" : "SCALAR",
+ "max" : [ 5.5 ],
+ "min" : [ 0.0 ]
+ }, {
+ "bufferView" : 4,
+ "byteOffset" : 48,
+ "componentType" : 5126,
+ "count" : 12,
+ "type" : "VEC4",
+ "max" : [ 0.0, 0.0, 0.707, 1.0 ],
+ "min" : [ 0.0, 0.0, -0.707, 0.707 ]
+ } ],
+
+ "asset" : {
+ "version" : "2.0"
+ }
+} \ No newline at end of file
diff --git a/assets/models/gltf/SimpleSkin/glTF/inverseBindMatrices.bin b/assets/models/gltf/SimpleSkin/glTF/inverseBindMatrices.bin
new file mode 100644
index 0000000..5af0b5e
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/glTF/inverseBindMatrices.bin
Binary files differ
diff --git a/assets/models/gltf/SimpleSkin/glTF/skinAnimation.bin b/assets/models/gltf/SimpleSkin/glTF/skinAnimation.bin
new file mode 100644
index 0000000..ff550c6
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/glTF/skinAnimation.bin
Binary files differ
diff --git a/assets/models/gltf/SimpleSkin/glTF/skinGeometry.bin b/assets/models/gltf/SimpleSkin/glTF/skinGeometry.bin
new file mode 100644
index 0000000..15375c4
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/glTF/skinGeometry.bin
Binary files differ
diff --git a/assets/models/gltf/SimpleSkin/glTF/skinningData.bin b/assets/models/gltf/SimpleSkin/glTF/skinningData.bin
new file mode 100644
index 0000000..fd0c165
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/glTF/skinningData.bin
Binary files differ
diff --git a/assets/models/gltf/SimpleSkin/metadata.json b/assets/models/gltf/SimpleSkin/metadata.json
new file mode 100644
index 0000000..764a837
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/metadata.json
@@ -0,0 +1,26 @@
+{
+ "version": 2,
+ "legal": [
+ {
+ "license": "CC0",
+ "licenseUrl": "https://creativecommons.org/publicdomain/zero/1.0/legalcode",
+ "artist": "javagl",
+ "year": "2017",
+ "owner": "Public",
+ "what": "Everything",
+ "text": "CC0 1.0 Universal",
+ "spdx": "CC0-1.0",
+ "icon": "https://licensebuttons.net/p/zero/1.0/88x31.png"
+ }
+ ],
+ "tags": [
+ "core",
+ "testing",
+ "written"
+ ],
+ "screenshot": "screenshot/screenshot.gif",
+ "name": "Simple Skin",
+ "path": "./Models/SimpleSkin",
+ "summary": "A simple example of vertex skinning in glTF",
+ "createReadme": true
+} \ No newline at end of file
diff --git a/assets/models/gltf/SimpleSkin/screenshot/inverseBindMatrices.png b/assets/models/gltf/SimpleSkin/screenshot/inverseBindMatrices.png
new file mode 100644
index 0000000..a069f59
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/screenshot/inverseBindMatrices.png
Binary files differ
diff --git a/assets/models/gltf/SimpleSkin/screenshot/screenshot.gif b/assets/models/gltf/SimpleSkin/screenshot/screenshot.gif
new file mode 100644
index 0000000..c8fb353
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/screenshot/screenshot.gif
Binary files differ
diff --git a/assets/models/gltf/SimpleSkin/screenshot/skinAnimation.png b/assets/models/gltf/SimpleSkin/screenshot/skinAnimation.png
new file mode 100644
index 0000000..20257e1
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/screenshot/skinAnimation.png
Binary files differ
diff --git a/assets/models/gltf/SimpleSkin/screenshot/skinGeometry.png b/assets/models/gltf/SimpleSkin/screenshot/skinGeometry.png
new file mode 100644
index 0000000..2569d9f
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/screenshot/skinGeometry.png
Binary files differ
diff --git a/assets/models/gltf/SimpleSkin/screenshot/skinningData.png b/assets/models/gltf/SimpleSkin/screenshot/skinningData.png
new file mode 100644
index 0000000..bd25b70
--- /dev/null
+++ b/assets/models/gltf/SimpleSkin/screenshot/skinningData.png
Binary files differ
diff --git a/examples/example_scene.h b/examples/example_scene.h
new file mode 100644
index 0000000..eb0be18
--- /dev/null
+++ b/examples/example_scene.h
@@ -0,0 +1,31 @@
+#pragma once
+#include "render_types.h"
+
+const vec3 pointlight_positions[4] = {
+ { 0.7, 0.2, 2.0 },
+ { 2.3, -3.3, -4.0 },
+ { -4.0, 2.0, -12.0 },
+ { 0.0, 0.0, -3.0 },
+};
+static point_light point_lights[4];
+
+static scene make_default_scene() {
+ directional_light dir_light = { .direction = (vec3){ -0.2, -1.0, -0.3 },
+ .ambient = (vec3){ 0.2, 0.2, 0.2 },
+ .diffuse = (vec3){ 0.5, 0.5, 0.5 },
+ .specular = (vec3){ 1.0, 1.0, 1.0 } };
+
+ for (int i = 0; i < 4; i++) {
+ point_lights[i].position = pointlight_positions[i];
+ point_lights[i].ambient = (vec3){ 0.05, 0.05, 0.05 };
+ point_lights[i].diffuse = (vec3){ 0.8, 0.8, 0.8 };
+ point_lights[i].specular = (vec3){ 1.0, 1.0, 1.0 };
+ point_lights[i].constant = 1.0;
+ point_lights[i].linear = 0.09;
+ point_lights[i].quadratic = 0.032;
+ }
+
+ scene our_scene = { .dir_light = dir_light, .n_point_lights = 4 };
+ memcpy(&our_scene.point_lights, &point_lights, sizeof(point_light[4]));
+ return our_scene;
+} \ No newline at end of file
diff --git a/examples/property_animation/ex_property_animation.c b/examples/property_animation/ex_property_animation.c
index 0d4a0d7..5ca0836 100644
--- a/examples/property_animation/ex_property_animation.c
+++ b/examples/property_animation/ex_property_animation.c
@@ -1,5 +1,6 @@
#include <glfw3.h>
+#include "../example_scene.h"
#include "animation.h"
#include "camera.h"
#include "core.h"
@@ -13,14 +14,6 @@
#include "render_backend.h"
#include "render_types.h"
-const vec3 pointlight_positions[4] = {
- { 0.7, 0.2, 2.0 },
- { 2.3, -3.3, -4.0 },
- { -4.0, 2.0, -12.0 },
- { 0.0, 0.0, -3.0 },
-};
-point_light point_lights[4];
-
typedef struct game_state {
camera camera;
vec3 camera_euler;
@@ -42,22 +35,7 @@ int main() {
model* cube = &core->models->data[animated_cube_handle.raw];
model_upload_meshes(&core->renderer, cube);
- directional_light dir_light = { .direction = (vec3){ -0.2, -1.0, -0.3 },
- .ambient = (vec3){ 0.2, 0.2, 0.2 },
- .diffuse = (vec3){ 0.5, 0.5, 0.5 },
- .specular = (vec3){ 1.0, 1.0, 1.0 } };
-
- for (int i = 0; i < 4; i++) {
- point_lights[i].position = pointlight_positions[i];
- point_lights[i].ambient = (vec3){ 0.05, 0.05, 0.05 };
- point_lights[i].diffuse = (vec3){ 0.8, 0.8, 0.8 };
- point_lights[i].specular = (vec3){ 1.0, 1.0, 1.0 };
- point_lights[i].constant = 1.0;
- point_lights[i].linear = 0.09;
- point_lights[i].quadratic = 0.032;
- }
- scene our_scene = { .dir_light = dir_light, .n_point_lights = 4 };
- memcpy(&our_scene.point_lights, &point_lights, sizeof(point_light[4]));
+ scene our_scene = make_default_scene();
vec3 cam_pos = vec3_create(5, 5, 5);
game_state game = {
@@ -73,7 +51,7 @@ int main() {
const f32 camera_zoom_speed = 0.15;
// animation
- animation_clip track = cube->animations->data[0];
+ animation_clip track = cube->animations->data[0];
f64 total_time = 0.0;
while (!should_exit(core)) {
@@ -81,8 +59,10 @@ int main() {
currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
- total_time += deltaTime * 0.00001;
- f64 t = fmod(total_time * 1000.0, 1.0);
+ lastFrame = currentFrame;
+ total_time += deltaTime;
+ printf("delta time %f\n", deltaTime);
+ f64 t = fmod(total_time, 1.0);
INFO("Total time: %f", t);
vec3 translation = VEC3_ZERO;
diff --git a/src/animation.c b/src/animation.c
index f6741e8..de7e9a2 100644
--- a/src/animation.c
+++ b/src/animation.c
@@ -1,6 +1,6 @@
#include "animation.h"
-#include "maths.h"
#include "log.h"
+#include "maths.h"
keyframe animation_sample(animation_sampler *sampler, f32 t) {
size_t previous_index = 0;
@@ -15,7 +15,6 @@ keyframe animation_sample(animation_sampler *sampler, f32 t) {
}
previous_time = current_time;
previous_index = i;
-
}
size_t next_index = (previous_index + 1) % sampler->animation.n_timestamps;
@@ -26,13 +25,14 @@ keyframe animation_sample(animation_sampler *sampler, f32 t) {
keyframe next_value = sampler->animation.values.values[next_index];
printf("%d %d\n", previous_index, next_index);
-
- f32 time_diff = sampler->animation.timestamps[next_index] - sampler->animation.timestamps[previous_index
- ];
- f32 percent = (t - sampler->animation.timestamps[next_index]) / time_diff;
- quat interpolated_rot = quat_slerp(sampler->animation.values.values[previous_index].rotation,
- sampler->animation.values.values[next_index].rotation, percent);
+ f32 time_diff =
+ sampler->animation.timestamps[next_index] - sampler->animation.timestamps[previous_index];
+ f32 percent = (t - sampler->animation.timestamps[next_index]) / time_diff;
+
+ quat interpolated_rot =
+ quat_slerp(sampler->animation.values.values[previous_index].rotation,
+ sampler->animation.values.values[next_index].rotation, percent);
- return (keyframe){ .rotation = interpolated_rot };
+ return (keyframe){ .rotation = interpolated_rot };
} \ No newline at end of file
diff --git a/src/resources/gltf.c b/src/resources/gltf.c
index 6081e45..eade8e6 100644
--- a/src/resources/gltf.c
+++ b/src/resources/gltf.c
@@ -63,6 +63,14 @@ model_handle model_load_gltf(struct core *core, const char *path, bool invert_te
return (model_handle){ .raw = index };
}
+void assert_path_type_matches_component_type(cgltf_animation_path_type target_path,
+ cgltf_accessor *output) {
+ if (target_path == cgltf_animation_path_type_rotation) {
+ assert(output->component_type == cgltf_component_type_r_32f);
+ assert(output->type == cgltf_type_vec4);
+ }
+}
+
// TODO: Brainstorm how I can make this simpler and break it up into more testable pieces
bool model_load_gltf_str(const char *file_string, const char *filepath, str8 relative_path,
@@ -175,7 +183,8 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, str8 rel
vec2_darray_push(tmp_uvs, tex);
}
} else if (attribute.type == cgltf_attribute_type_joints) {
- // TODO: handle joints
+ cgltf_accessor *accessor = attribute.data;
+ assert(accessor->component_type == cgltf_component_type_r_32u);
} else {
WARN("Unhandled cgltf_attribute_type: %s. skipping..", attribute.name);
}
@@ -257,19 +266,32 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, str8 rel
animation_sampler *sampler = arena_alloc(arena, sizeof(animation_sampler));
- // animation_sampler **target_property;
+ animation_sampler **target_property;
keyframe_kind data_type;
switch (channel.target_path) {
case cgltf_animation_path_type_rotation:
- // target_property = &clip.rotation;
+ target_property = &clip.rotation;
data_type = KEYFRAME_ROTATION;
break;
+ case cgltf_animation_path_type_translation:
+ target_property = &clip.translation;
+ data_type = KEYFRAME_TRANSLATION;
+ break;
+ case cgltf_animation_path_type_scale:
+ target_property = &clip.scale;
+ data_type = KEYFRAME_SCALE;
+ break;
+ case cgltf_animation_path_type_weights:
+ target_property = &clip.weights;
+ data_type = KEYFRAME_WEIGHTS;
+ WARN("Morph target weights arent supported yet");
+ return false;
default:
WARN("unsupported animation type");
return false;
}
- // *target_property = sampler;
+ *target_property = sampler;
sampler->current_index = 0;
printf("1 %d index\n", sampler->current_index);
@@ -277,48 +299,59 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, str8 rel
// keyframe times
size_t n_frames = channel.sampler->input->count;
- printf("n_frames: %d\n", n_frames);
assert(channel.sampler->input->component_type == cgltf_component_type_r_32f);
// FIXME: CASSERT_MSG function "Expected animation sampler input component to be type f32
// (keyframe times)");
- printf("2 %d index\n", sampler->current_index);
f32 *times = arena_alloc(arena, n_frames * sizeof(f32));
- printf("3 %d index\n", sampler->current_index);
sampler->animation.n_timestamps = n_frames;
- printf("n_timestamps: %d\n", sampler->animation.n_timestamps);
sampler->animation.timestamps = times;
cgltf_accessor_unpack_floats(channel.sampler->input, times, n_frames);
-
- printf("4 %d index\n", sampler->current_index);
- if (channel.target_path == cgltf_animation_path_type_rotation) {
- assert(channel.sampler->output->component_type == cgltf_component_type_r_32f);
- assert(channel.sampler->output->type == cgltf_type_vec4);
- }
+ assert_path_type_matches_component_type(channel.target_path, channel.sampler->output);
// keyframe values
size_t n_values = channel.sampler->output->count;
assert(n_frames == n_values);
- ERROR("N frames %d", n_frames);
keyframes keyframes = { 0 };
keyframes.kind = KEYFRAME_ROTATION;
keyframes.count = n_values;
keyframes.values = arena_alloc(arena, n_values * sizeof(keyframe));
for (cgltf_size v = 0; v < channel.sampler->output->count; ++v) {
- quat rot;
- cgltf_accessor_read_float(channel.sampler->output, v, &rot.x, 4);
- printf("Quat %f %f %f %f\n", rot.x, rot.y, rot.z, rot.w);
- keyframes.values[v].rotation = rot;
+ switch (data_type) {
+ case KEYFRAME_ROTATION: {
+ quat rot;
+ cgltf_accessor_read_float(channel.sampler->output, v, &rot.x, 4);
+ printf("Quat %f %f %f %f\n", rot.x, rot.y, rot.z, rot.w);
+ keyframes.values[v].rotation = rot;
+ break;
+ }
+ case KEYFRAME_TRANSLATION: {
+ vec3 trans;
+ cgltf_accessor_read_float(channel.sampler->output, v, &trans.x, 3);
+ keyframes.values[v].translation = trans;
+ break;
+ }
+ case KEYFRAME_SCALE: {
+ vec3 scale;
+ cgltf_accessor_read_float(channel.sampler->output, v, &scale.x, 3);
+ keyframes.values[v].scale = scale;
+ break;
+ }
+ case KEYFRAME_WEIGHTS: {
+ // TODO
+ break;
+ }
+ }
}
sampler->animation.values = keyframes;
sampler->min = channel.sampler->input->min[0];
sampler->max = channel.sampler->input->max[0];
- clip.rotation = sampler;
- printf("%d timestamps\n", sampler->animation.n_timestamps);
- printf("%d index\n", sampler->current_index);
+ // clip.rotation = sampler;
+ // printf("%d timestamps\n", sampler->animation.n_timestamps);
+ // printf("%d index\n", sampler->current_index);
}
WARN("stuff %ld", clip.rotation->animation.n_timestamps);