summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/models/gltf/AnimatedCube/LICENSE.md15
-rw-r--r--assets/models/gltf/AnimatedCube/README.body.md3
-rw-r--r--assets/models/gltf/AnimatedCube/README.md27
-rw-r--r--assets/models/gltf/AnimatedCube/glTF/AnimatedCube.binbin0 -> 1860 bytes
-rw-r--r--assets/models/gltf/AnimatedCube/glTF/AnimatedCube.gltf262
-rw-r--r--assets/models/gltf/AnimatedCube/glTF/AnimatedCube_BaseColor.pngbin0 -> 891995 bytes
-rw-r--r--assets/models/gltf/AnimatedCube/glTF/AnimatedCube_MetallicRoughness.pngbin0 -> 319 bytes
-rw-r--r--assets/models/gltf/AnimatedCube/metadata.json25
-rw-r--r--assets/models/gltf/AnimatedCube/screenshot/screenshot.gifbin0 -> 517169 bytes
-rw-r--r--examples/property_animation/ex_property_animation.c103
-rw-r--r--src/defines.h4
-rw-r--r--src/renderer/backends/backend_opengl.c6
-rw-r--r--src/resources/gltf.c3
13 files changed, 445 insertions, 3 deletions
diff --git a/assets/models/gltf/AnimatedCube/LICENSE.md b/assets/models/gltf/AnimatedCube/LICENSE.md
new file mode 100644
index 0000000..c001f8f
--- /dev/null
+++ b/assets/models/gltf/AnimatedCube/LICENSE.md
@@ -0,0 +1,15 @@
+# LICENSE file for the model: Animated Cube
+
+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/AnimatedCube/README.body.md b/assets/models/gltf/AnimatedCube/README.body.md
new file mode 100644
index 0000000..1efdf8c
--- /dev/null
+++ b/assets/models/gltf/AnimatedCube/README.body.md
@@ -0,0 +1,3 @@
+## Screenshot
+
+![screenshot](screenshot/screenshot.gif)
diff --git a/assets/models/gltf/AnimatedCube/README.md b/assets/models/gltf/AnimatedCube/README.md
new file mode 100644
index 0000000..d5cf0a3
--- /dev/null
+++ b/assets/models/gltf/AnimatedCube/README.md
@@ -0,0 +1,27 @@
+# Animated Cube
+
+## Tags
+
+[core](../../Models-core.md), [testing](../../Models-testing.md)
+
+## Summary
+
+Same as 'Cube', but having a linear rotation animation.
+
+## Operations
+
+* [Display](https://github.khronos.org/glTF-Sample-Viewer-Release/?model=https://raw.GithubUserContent.com/KhronosGroup/glTF-Sample-Assets/main/./Models/AnimatedCube/glTF/AnimatedCube.gltf) in SampleViewer
+* [Model Directory](./)
+
+## Screenshot
+
+![screenshot](screenshot/screenshot.gif)
+
+
+## Legal
+
+© 2017, UX3D. [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode)
+
+ - Norbert Nopper for Everything
+
+#### Assembled by modelmetadata \ No newline at end of file
diff --git a/assets/models/gltf/AnimatedCube/glTF/AnimatedCube.bin b/assets/models/gltf/AnimatedCube/glTF/AnimatedCube.bin
new file mode 100644
index 0000000..72f7d2d
--- /dev/null
+++ b/assets/models/gltf/AnimatedCube/glTF/AnimatedCube.bin
Binary files differ
diff --git a/assets/models/gltf/AnimatedCube/glTF/AnimatedCube.gltf b/assets/models/gltf/AnimatedCube/glTF/AnimatedCube.gltf
new file mode 100644
index 0000000..ff117b0
--- /dev/null
+++ b/assets/models/gltf/AnimatedCube/glTF/AnimatedCube.gltf
@@ -0,0 +1,262 @@
+{
+ "accessors" : [
+ {
+ "bufferView" : 0,
+ "byteOffset" : 0,
+ "componentType" : 5126,
+ "count" : 3,
+ "max" : [
+ 2.000000
+ ],
+ "min" : [
+ 0.000000
+ ],
+ "type" : "SCALAR"
+ },
+ {
+ "bufferView" : 1,
+ "byteOffset" : 0,
+ "componentType" : 5126,
+ "count" : 3,
+ "max" : [
+ 0.000000,
+ 1.000000,
+ 0.000000,
+ 1.000000
+ ],
+ "min" : [
+ 0.000000,
+ -8.742278e-008,
+ 0.000000,
+ -1.000000
+ ],
+ "type" : "VEC4"
+ },
+ {
+ "bufferView" : 2,
+ "byteOffset" : 0,
+ "componentType" : 5123,
+ "count" : 36,
+ "max" : [
+ 35
+ ],
+ "min" : [
+ 0
+ ],
+ "type" : "SCALAR"
+ },
+ {
+ "bufferView" : 3,
+ "byteOffset" : 0,
+ "componentType" : 5126,
+ "count" : 36,
+ "max" : [
+ 1.000000,
+ 1.000000,
+ 1.000001
+ ],
+ "min" : [
+ -1.000000,
+ -1.000000,
+ -1.000000
+ ],
+ "type" : "VEC3"
+ },
+ {
+ "bufferView" : 4,
+ "byteOffset" : 0,
+ "componentType" : 5126,
+ "count" : 36,
+ "max" : [
+ 1.000000,
+ 1.000000,
+ 1.000000
+ ],
+ "min" : [
+ -1.000000,
+ -1.000000,
+ -1.000000
+ ],
+ "type" : "VEC3"
+ },
+ {
+ "bufferView" : 5,
+ "byteOffset" : 0,
+ "componentType" : 5126,
+ "count" : 36,
+ "max" : [
+ 1.000000,
+ -0.000000,
+ -0.000000,
+ 1.000000
+ ],
+ "min" : [
+ 0.000000,
+ -0.000000,
+ -1.000000,
+ -1.000000
+ ],
+ "type" : "VEC4"
+ },
+ {
+ "bufferView" : 6,
+ "byteOffset" : 0,
+ "componentType" : 5126,
+ "count" : 36,
+ "max" : [
+ 1.000000,
+ 1.000000
+ ],
+ "min" : [
+ -1.000000,
+ -1.000000
+ ],
+ "type" : "VEC2"
+ }
+ ],
+ "animations" : [
+ {
+ "channels" : [
+ {
+ "sampler" : 0,
+ "target" : {
+ "node" : 0,
+ "path" : "rotation"
+ }
+ }
+ ],
+ "name" : "animation_AnimatedCube",
+ "samplers" : [
+ {
+ "input" : 0,
+ "interpolation" : "LINEAR",
+ "output" : 1
+ }
+ ]
+ }
+ ],
+ "asset" : {
+ "generator" : "VKTS glTF 2.0 exporter",
+ "version" : "2.0"
+ },
+ "bufferViews" : [
+ {
+ "buffer" : 0,
+ "byteLength" : 12,
+ "byteOffset" : 0
+ },
+ {
+ "buffer" : 0,
+ "byteLength" : 48,
+ "byteOffset" : 12
+ },
+ {
+ "buffer" : 0,
+ "byteLength" : 72,
+ "byteOffset" : 60,
+ "target" : 34963
+ },
+ {
+ "buffer" : 0,
+ "byteLength" : 432,
+ "byteOffset" : 132,
+ "target" : 34962
+ },
+ {
+ "buffer" : 0,
+ "byteLength" : 432,
+ "byteOffset" : 564,
+ "target" : 34962
+ },
+ {
+ "buffer" : 0,
+ "byteLength" : 576,
+ "byteOffset" : 996,
+ "target" : 34962
+ },
+ {
+ "buffer" : 0,
+ "byteLength" : 288,
+ "byteOffset" : 1572,
+ "target" : 34962
+ }
+ ],
+ "buffers" : [
+ {
+ "byteLength" : 1860,
+ "uri" : "AnimatedCube.bin"
+ }
+ ],
+ "images" : [
+ {
+ "uri" : "AnimatedCube_BaseColor.png"
+ },
+ {
+ "uri" : "AnimatedCube_MetallicRoughness.png"
+ }
+ ],
+ "materials" : [
+ {
+ "name" : "AnimatedCube",
+ "pbrMetallicRoughness" : {
+ "baseColorTexture" : {
+ "index" : 0
+ },
+ "metallicRoughnessTexture" : {
+ "index" : 1
+ }
+ }
+ }
+ ],
+ "meshes" : [
+ {
+ "name" : "AnimatedCube",
+ "primitives" : [
+ {
+ "attributes" : {
+ "NORMAL" : 4,
+ "POSITION" : 3,
+ "TANGENT" : 5,
+ "TEXCOORD_0" : 6
+ },
+ "indices" : 2,
+ "material" : 0,
+ "mode" : 4
+ }
+ ]
+ }
+ ],
+ "nodes" : [
+ {
+ "mesh" : 0,
+ "name" : "AnimatedCube",
+ "rotation" : [
+ 0.000000,
+ -1.000000,
+ 0.000000,
+ 0.000000
+ ]
+ }
+ ],
+ "samplers" : [
+ {}
+ ],
+ "scene" : 0,
+ "scenes" : [
+ {
+ "nodes" : [
+ 0
+ ]
+ }
+ ],
+ "textures" : [
+ {
+ "sampler" : 0,
+ "source" : 0
+ },
+ {
+ "sampler" : 0,
+ "source" : 1
+ }
+ ]
+} \ No newline at end of file
diff --git a/assets/models/gltf/AnimatedCube/glTF/AnimatedCube_BaseColor.png b/assets/models/gltf/AnimatedCube/glTF/AnimatedCube_BaseColor.png
new file mode 100644
index 0000000..5e5cb20
--- /dev/null
+++ b/assets/models/gltf/AnimatedCube/glTF/AnimatedCube_BaseColor.png
Binary files differ
diff --git a/assets/models/gltf/AnimatedCube/glTF/AnimatedCube_MetallicRoughness.png b/assets/models/gltf/AnimatedCube/glTF/AnimatedCube_MetallicRoughness.png
new file mode 100644
index 0000000..efd2026
--- /dev/null
+++ b/assets/models/gltf/AnimatedCube/glTF/AnimatedCube_MetallicRoughness.png
Binary files differ
diff --git a/assets/models/gltf/AnimatedCube/metadata.json b/assets/models/gltf/AnimatedCube/metadata.json
new file mode 100644
index 0000000..3af6fdb
--- /dev/null
+++ b/assets/models/gltf/AnimatedCube/metadata.json
@@ -0,0 +1,25 @@
+{
+ "version": 2,
+ "legal": [
+ {
+ "license": "CC0",
+ "licenseUrl": "https://creativecommons.org/publicdomain/zero/1.0/legalcode",
+ "artist": "Norbert Nopper",
+ "year": "2017",
+ "owner": "UX3D",
+ "what": "Everything",
+ "text": "CC0 1.0 Universal",
+ "spdx": "CC0-1.0",
+ "icon": "https://licensebuttons.net/p/zero/1.0/88x31.png"
+ }
+ ],
+ "tags": [
+ "core",
+ "testing"
+ ],
+ "screenshot": "screenshot/screenshot.gif",
+ "name": "Animated Cube",
+ "path": "./Models/AnimatedCube",
+ "summary": "Same as 'Cube', but having a linear rotation animation.",
+ "createReadme": true
+} \ No newline at end of file
diff --git a/assets/models/gltf/AnimatedCube/screenshot/screenshot.gif b/assets/models/gltf/AnimatedCube/screenshot/screenshot.gif
new file mode 100644
index 0000000..eea74ee
--- /dev/null
+++ b/assets/models/gltf/AnimatedCube/screenshot/screenshot.gif
Binary files differ
diff --git a/examples/property_animation/ex_property_animation.c b/examples/property_animation/ex_property_animation.c
index e69de29..38bafd5 100644
--- a/examples/property_animation/ex_property_animation.c
+++ b/examples/property_animation/ex_property_animation.c
@@ -0,0 +1,103 @@
+#include <glfw3.h>
+
+#include "camera.h"
+#include "core.h"
+#include "input.h"
+#include "keys.h"
+#include "maths.h"
+#include "maths_types.h"
+#include "primitives.h"
+#include "render.h"
+#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;
+ bool first_mouse_update; // so the camera doesnt lurch when you run the first
+ // process_camera_rotation
+} game_state;
+
+void update_camera_rotation(input_state* input, game_state* game, camera* cam);
+
+int main() {
+ core* core = core_bringup();
+
+ model_handle animated_cube_handle =
+ model_load_gltf(core, "assets/models/gltf/AnimatedCube/glTF/AnimatedCube.gltf", false);
+ 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]));
+
+ vec3 cam_pos = vec3_create(5, 5, 5);
+ game_state game = {
+ .camera = camera_create(cam_pos, vec3_negate(cam_pos), VEC3_Y, deg_to_rad(45.0)),
+ .camera_euler = vec3_create(90, 0, 0),
+ .first_mouse_update = true,
+ };
+
+ print_vec3(game.camera.front);
+
+ // Main loop
+ const f32 camera_lateral_speed = 0.2;
+ const f32 camera_zoom_speed = 0.15;
+
+ while (!should_exit(core)) {
+ input_update(&core->input);
+
+ vec3 translation = VEC3_ZERO;
+ if (key_is_pressed(KEYCODE_W) || key_is_pressed(KEYCODE_KEY_UP)) {
+ translation = vec3_mult(game.camera.front, camera_zoom_speed);
+ } else if (key_is_pressed(KEYCODE_S) || key_is_pressed(KEYCODE_KEY_DOWN)) {
+ translation = vec3_mult(game.camera.front, -camera_zoom_speed);
+ } else if (key_is_pressed(KEYCODE_A) || key_is_pressed(KEYCODE_KEY_LEFT)) {
+ vec3 lateral = vec3_normalise(vec3_cross(game.camera.front, game.camera.up));
+ translation = vec3_mult(lateral, -camera_lateral_speed);
+ } else if (key_is_pressed(KEYCODE_D) || key_is_pressed(KEYCODE_KEY_RIGHT)) {
+ vec3 lateral = vec3_normalise(vec3_cross(game.camera.front, game.camera.up));
+ translation = vec3_mult(lateral, camera_lateral_speed);
+ }
+ game.camera.position = vec3_add(game.camera.position, translation);
+
+ // UNUSED: threadpool_process_results(&core->threadpool, 1);
+
+ render_frame_begin(&core->renderer);
+
+ mat4 model = mat4_translation(VEC3_ZERO);
+ transform tf = transform_create(VEC3_ZERO, quat_ident(), 1.0);
+
+ draw_model(&core->renderer, &game.camera, cube, tf, &our_scene);
+
+ // gfx_backend_draw_frame(&core->renderer, &game.camera, model, NULL);
+
+ render_frame_end(&core->renderer);
+ }
+
+ core_shutdown(core);
+
+ return 0;
+}
diff --git a/src/defines.h b/src/defines.h
index 4459e1a..52aa7b0 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -66,8 +66,8 @@ Renderer backend defines:
// Platform will inform renderer backend (unless user overrides)
#if defined(CEL_PLATFORM_LINUX) || defined(CEL_PLATFORM_WINDOWS)
-// #define CEL_REND_BACKEND_OPENGL 1
-#define CEL_REND_BACKEND_VULKAN 1
+#define CEL_REND_BACKEND_OPENGL 1
+// #define CEL_REND_BACKEND_VULKAN 1
#endif
#if defined(CEL_PLATFORM_MAC)
diff --git a/src/renderer/backends/backend_opengl.c b/src/renderer/backends/backend_opengl.c
index e3a4fb6..8df0933 100644
--- a/src/renderer/backends/backend_opengl.c
+++ b/src/renderer/backends/backend_opengl.c
@@ -1,4 +1,5 @@
#include <stdlib.h>
+#include "camera.h"
#define CEL_PLATFORM_LINUX
#include "defines.h"
@@ -40,6 +41,11 @@ bool gfx_backend_init(renderer *ren) {
return true;
}
+
+void gfx_backend_draw_frame(renderer* ren, camera* cam, mat4 model, texture* tex) {
+
+}
+
void gfx_backend_shutdown(renderer *ren) {}
void uniform_vec3f(u32 program_id, const char *uniform_name, vec3 *value) {
diff --git a/src/resources/gltf.c b/src/resources/gltf.c
index b269fcd..261c96f 100644
--- a/src/resources/gltf.c
+++ b/src/resources/gltf.c
@@ -211,7 +211,8 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, str8 rel
if (primitive.material != NULL) {
for (int i = 0; i < material_darray_len(out_model->materials); i++) {
- if (strcmp(primitive.material->name, out_model->materials->data[i].name)) {
+ printf("%s vs %s \n", primitive.material->name, out_model->materials->data[i].name);
+ if (strcmp(primitive.material->name, out_model->materials->data[i].name) == 0) {
TRACE("Found material");
mesh.material_index = i;
break;