Revision: 76982
http://sourceforge.net/p/brlcad/code/76982
Author: starseeker
Date: 2020-08-28 12:48:26 +0000 (Fri, 28 Aug 2020)
Log Message:
-----------
Not using skeletons (stripping down to the core pieces that we'll want for
basic shaded rendering.)
Modified Paths:
--------------
brlcad/branches/swrast/src/libdm/tests/renderer/api.h
brlcad/branches/swrast/src/libdm/tests/renderer/scene.c
brlcad/branches/swrast/src/libdm/tests/renderer/scene.h
brlcad/branches/swrast/src/libdm/tests/renderer/scenes/blinn_shader.c
brlcad/branches/swrast/src/libdm/tests/renderer/scenes/blinn_shader.h
brlcad/branches/swrast/src/libdm/tests/renderer/scenes/cache_helper.c
brlcad/branches/swrast/src/libdm/tests/renderer/scenes/scene_helper.c
Removed Paths:
-------------
brlcad/branches/swrast/src/libdm/tests/renderer/skeleton.c
brlcad/branches/swrast/src/libdm/tests/renderer/skeleton.h
Modified: brlcad/branches/swrast/src/libdm/tests/renderer/api.h
===================================================================
--- brlcad/branches/swrast/src/libdm/tests/renderer/api.h 2020-08-27
20:56:40 UTC (rev 76981)
+++ brlcad/branches/swrast/src/libdm/tests/renderer/api.h 2020-08-28
12:48:26 UTC (rev 76982)
@@ -18,7 +18,6 @@
#include "maths.h"
#include "mesh.h"
#include "scene.h"
-#include "skeleton.h"
#include "texture.h"
scene_t *scene_from_file(const char *filename, mat4_t root);
@@ -28,10 +27,6 @@
mesh_t *cache_acquire_mesh(const char *filename);
void cache_release_mesh(mesh_t *mesh);
-/* skeleton related functions */
-skeleton_t *cache_acquire_skeleton(const char *filename);
-void cache_release_skeleton(skeleton_t *skeleton);
-
/* texture related functions */
texture_t *cache_acquire_texture(const char *filename, usage_t usage);
void cache_release_texture(texture_t *texture);
Modified: brlcad/branches/swrast/src/libdm/tests/renderer/scene.c
===================================================================
--- brlcad/branches/swrast/src/libdm/tests/renderer/scene.c 2020-08-27
20:56:40 UTC (rev 76981)
+++ brlcad/branches/swrast/src/libdm/tests/renderer/scene.c 2020-08-28
12:48:26 UTC (rev 76982)
@@ -4,7 +4,6 @@
#include "maths.h"
#include "mesh.h"
#include "scene.h"
-#include "skeleton.h"
#include "texture.h"
scene_t *scene_create(vec3_t background, model_t *skybox, model_t **models,
Modified: brlcad/branches/swrast/src/libdm/tests/renderer/scene.h
===================================================================
--- brlcad/branches/swrast/src/libdm/tests/renderer/scene.h 2020-08-27
20:56:40 UTC (rev 76981)
+++ brlcad/branches/swrast/src/libdm/tests/renderer/scene.h 2020-08-28
12:48:26 UTC (rev 76982)
@@ -4,7 +4,6 @@
#include "graphics.h"
#include "maths.h"
#include "mesh.h"
-#include "skeleton.h"
#include "texture.h"
typedef struct {
@@ -26,9 +25,6 @@
mesh_t *mesh;
program_t *program;
mat4_t transform;
- /* for animation */
- skeleton_t *skeleton;
- int attached;
/* for sorting */
int opaque;
float distance;
Modified: brlcad/branches/swrast/src/libdm/tests/renderer/scenes/blinn_shader.c
===================================================================
--- brlcad/branches/swrast/src/libdm/tests/renderer/scenes/blinn_shader.c
2020-08-27 20:56:40 UTC (rev 76981)
+++ brlcad/branches/swrast/src/libdm/tests/renderer/scenes/blinn_shader.c
2020-08-28 12:48:26 UTC (rev 76982)
@@ -5,46 +5,10 @@
/* low-level api */
-static mat4_t get_model_matrix(blinn_attribs_t *attribs,
- blinn_uniforms_t *uniforms) {
- if (uniforms->joint_matrices) {
- mat4_t joint_matrices[4];
- mat4_t skin_matrix;
-
- joint_matrices[0] = uniforms->joint_matrices[(int)attribs->joint.x];
- joint_matrices[1] = uniforms->joint_matrices[(int)attribs->joint.y];
- joint_matrices[2] = uniforms->joint_matrices[(int)attribs->joint.z];
- joint_matrices[3] = uniforms->joint_matrices[(int)attribs->joint.w];
-
- skin_matrix = mat4_combine(joint_matrices, attribs->weight);
- return mat4_mul_mat4(uniforms->model_matrix, skin_matrix);
- } else {
- return uniforms->model_matrix;
- }
-}
-
-static mat3_t get_normal_matrix(blinn_attribs_t *attribs,
- blinn_uniforms_t *uniforms) {
- if (uniforms->joint_n_matrices) {
- mat3_t joint_n_matrices[4];
- mat3_t skin_n_matrix;
-
- joint_n_matrices[0] =
uniforms->joint_n_matrices[(int)attribs->joint.x];
- joint_n_matrices[1] =
uniforms->joint_n_matrices[(int)attribs->joint.y];
- joint_n_matrices[2] =
uniforms->joint_n_matrices[(int)attribs->joint.z];
- joint_n_matrices[3] =
uniforms->joint_n_matrices[(int)attribs->joint.w];
-
- skin_n_matrix = mat3_combine(joint_n_matrices, attribs->weight);
- return mat3_mul_mat3(uniforms->normal_matrix, skin_n_matrix);
- } else {
- return uniforms->normal_matrix;
- }
-}
-
static vec4_t shadow_vertex_shader(blinn_attribs_t *attribs,
blinn_varyings_t *varyings,
blinn_uniforms_t *uniforms) {
- mat4_t model_matrix = get_model_matrix(attribs, uniforms);
+ mat4_t model_matrix = uniforms->model_matrix;
mat4_t light_vp_matrix = uniforms->light_vp_matrix;
vec4_t input_position = vec4_from_vec3(attribs->position, 1);
@@ -58,8 +22,8 @@
static vec4_t common_vertex_shader(blinn_attribs_t *attribs,
blinn_varyings_t *varyings,
blinn_uniforms_t *uniforms) {
- mat4_t model_matrix = get_model_matrix(attribs, uniforms);
- mat3_t normal_matrix = get_normal_matrix(attribs, uniforms);
+ mat4_t model_matrix = uniforms->model_matrix;
+ mat3_t normal_matrix = uniforms->normal_matrix;
mat4_t camera_vp_matrix = uniforms->camera_vp_matrix;
mat4_t light_vp_matrix = uniforms->light_vp_matrix;
@@ -252,27 +216,11 @@
static void update_model(model_t *model, perframe_t *perframe) {
float ambient_intensity = perframe->ambient_intensity;
float punctual_intensity = perframe->punctual_intensity;
- skeleton_t *skeleton = model->skeleton;
mat4_t model_matrix = model->transform;
mat3_t normal_matrix;
- mat4_t *joint_matrices;
- mat3_t *joint_n_matrices;
blinn_uniforms_t *uniforms;
- if (skeleton) {
- skeleton_update_joints(skeleton, perframe->frame_time);
- joint_matrices = skeleton_get_joint_matrices(skeleton);
- joint_n_matrices = skeleton_get_normal_matrices(skeleton);
- if (model->attached >= 0) {
- mat4_t node_matrix = joint_matrices[model->attached];
- model_matrix = mat4_mul_mat4(model_matrix, node_matrix);
- joint_matrices = NULL;
- joint_n_matrices = NULL;
- }
- } else {
- joint_matrices = NULL;
- joint_n_matrices = NULL;
- }
+
normal_matrix = mat3_inverse_transpose(mat3_from_mat4(model_matrix));
uniforms = (blinn_uniforms_t*)program_get_uniforms(model->program);
@@ -284,8 +232,6 @@
perframe->light_view_matrix);
uniforms->camera_vp_matrix = mat4_mul_mat4(perframe->camera_proj_matrix,
perframe->camera_view_matrix);
- uniforms->joint_matrices = joint_matrices;
- uniforms->joint_n_matrices = joint_n_matrices;
uniforms->ambient_intensity = float_clamp(ambient_intensity, 0, 5);
uniforms->punctual_intensity = float_clamp(punctual_intensity, 0, 5);
uniforms->shadow_map = perframe->shadow_map;
@@ -324,7 +270,6 @@
cache_release_texture(uniforms->specular_map);
cache_release_texture(uniforms->emission_map);
program_release(model->program);
- cache_release_skeleton(model->skeleton);
cache_release_mesh(model->mesh);
free(model);
}
@@ -334,7 +279,6 @@
}
model_t *blinn_create_model(const char *mesh, mat4_t transform,
- const char *skeleton, int attached,
blinn_material_t *material) {
int sizeof_attribs = sizeof(blinn_attribs_t);
int sizeof_varyings = sizeof(blinn_varyings_t);
@@ -359,8 +303,6 @@
model->mesh = cache_acquire_mesh(mesh);
model->program = program;
model->transform = transform;
- model->skeleton = cache_acquire_skeleton(skeleton);
- model->attached = attached;
model->opaque = !material->enable_blend;
model->distance = 0;
model->update = update_model;
Modified: brlcad/branches/swrast/src/libdm/tests/renderer/scenes/blinn_shader.h
===================================================================
--- brlcad/branches/swrast/src/libdm/tests/renderer/scenes/blinn_shader.h
2020-08-27 20:56:40 UTC (rev 76981)
+++ brlcad/branches/swrast/src/libdm/tests/renderer/scenes/blinn_shader.h
2020-08-28 12:48:26 UTC (rev 76982)
@@ -27,8 +27,6 @@
mat3_t normal_matrix;
mat4_t light_vp_matrix;
mat4_t camera_vp_matrix;
- mat4_t *joint_matrices;
- mat3_t *joint_n_matrices;
float ambient_intensity;
float punctual_intensity;
texture_t *shadow_map;
@@ -62,7 +60,6 @@
} blinn_material_t;
model_t *blinn_create_model(const char *mesh, mat4_t transform,
- const char *skeleton, int attached,
blinn_material_t *material);
#endif
Modified: brlcad/branches/swrast/src/libdm/tests/renderer/scenes/cache_helper.c
===================================================================
--- brlcad/branches/swrast/src/libdm/tests/renderer/scenes/cache_helper.c
2020-08-27 20:56:40 UTC (rev 76981)
+++ brlcad/branches/swrast/src/libdm/tests/renderer/scenes/cache_helper.c
2020-08-28 12:48:26 UTC (rev 76982)
@@ -69,65 +69,6 @@
}
}
-/* skeleton related functions */
-
-typedef struct {
- char *filename;
- skeleton_t *skeleton;
- int references;
-} cached_skeleton_t;
-
-static cached_skeleton_t *g_skeletons = NULL;
-
-skeleton_t *cache_acquire_skeleton(const char *filename) {
- if (filename != NULL) {
- cached_skeleton_t cached_skeleton;
- int num_skeletons = darray_size(g_skeletons);
- int i;
-
- for (i = 0; i < num_skeletons; i++) {
- if (strcmp(g_skeletons[i].filename, filename) == 0) {
- if (g_skeletons[i].references > 0) {
- g_skeletons[i].references += 1;
- } else {
- assert(g_skeletons[i].references == 0);
- assert(g_skeletons[i].skeleton == NULL);
- g_skeletons[i].skeleton = skeleton_load(filename);
- g_skeletons[i].references = 1;
- }
- return g_skeletons[i].skeleton;
- }
- }
-
- cached_skeleton.filename = duplicate_string(filename);
- cached_skeleton.skeleton = skeleton_load(filename);
- cached_skeleton.references = 1;
- darray_push(g_skeletons, cached_skeleton, cached_skeleton_t);
- return cached_skeleton.skeleton;
- } else {
- return NULL;
- }
-}
-
-void cache_release_skeleton(skeleton_t *skeleton) {
- if (skeleton != NULL) {
- int num_skeletons = darray_size(g_skeletons);
- int i;
- for (i = 0; i < num_skeletons; i++) {
- if (g_skeletons[i].skeleton == skeleton) {
- assert(g_skeletons[i].references > 0);
- g_skeletons[i].references -= 1;
- if (g_skeletons[i].references == 0) {
- skeleton_release(g_skeletons[i].skeleton);
- g_skeletons[i].skeleton = NULL;
- }
- return;
- }
- }
- assert(0);
- }
-}
-
/* texture related functions */
typedef struct {
@@ -196,7 +137,6 @@
void cache_cleanup(void) {
int num_meshes = darray_size(g_meshes);
- int num_skeletons = darray_size(g_skeletons);
int num_textures = darray_size(g_textures);
int i;
for (i = 0; i < num_meshes; i++) {
@@ -204,11 +144,6 @@
assert(g_meshes[i].references == 0);
free(g_meshes[i].filename);
}
- for (i = 0; i < num_skeletons; i++) {
- assert(g_skeletons[i].skeleton == NULL);
- assert(g_skeletons[i].references == 0);
- free(g_skeletons[i].filename);
- }
for (i = 0; i < num_textures; i++) {
assert(g_textures[i].texture == NULL);
assert(g_textures[i].references == 0);
@@ -215,9 +150,7 @@
free(g_textures[i].filename);
}
darray_free(g_meshes);
- darray_free(g_skeletons);
darray_free(g_textures);
g_meshes = NULL;
- g_skeletons = NULL;
g_textures = NULL;
}
Modified: brlcad/branches/swrast/src/libdm/tests/renderer/scenes/scene_helper.c
===================================================================
--- brlcad/branches/swrast/src/libdm/tests/renderer/scenes/scene_helper.c
2020-08-27 20:56:40 UTC (rev 76981)
+++ brlcad/branches/swrast/src/libdm/tests/renderer/scenes/scene_helper.c
2020-08-28 12:48:26 UTC (rev 76982)
@@ -33,7 +33,6 @@
typedef struct {
int index;
char mesh[LINE_SIZE];
- char skeleton[LINE_SIZE];
int attached;
int material;
int transform;
@@ -176,14 +175,16 @@
static scene_model_t read_model(FILE *file) {
scene_model_t model;
int items;
+ char skel[LINE_SIZE];
+ int attach;
items = fscanf(file, " model %d:", &model.index);
assert(items == 1);
items = fscanf(file, " mesh: %s", model.mesh);
assert(items == 1);
- items = fscanf(file, " skeleton: %s", model.skeleton);
+ items = fscanf(file, " skeleton: %s", skel);
assert(items == 1);
- items = fscanf(file, " attached: %d", &model.attached);
+ items = fscanf(file, " attached: %d", &attach);
assert(items == 1);
items = fscanf(file, " material: %d", &model.material);
assert(items == 1);
@@ -252,8 +253,6 @@
scene_transform_t scene_transform;
scene_model_t scene_model;
const char *mesh;
- const char *skeleton;
- int attached;
mat4_t transform;
blinn_material_t material;
model_t *model;
@@ -265,8 +264,6 @@
UNUSED_VAR(num_materials);
mesh = wrap_path(scene_model.mesh);
- skeleton = wrap_path(scene_model.skeleton);
- attached = scene_model.attached;
scene_transform = scene_transforms[scene_model.transform];
transform = mat4_mul_mat4(root_transform, scene_transform.matrix);
@@ -281,8 +278,7 @@
material.enable_blend = wrap_knob(scene_material.enable_blend);
material.alpha_cutoff = scene_material.alpha_cutoff;
- model = blinn_create_model(mesh, transform, skeleton, attached,
- &material);
+ model = blinn_create_model(mesh, transform, &material);
darray_push(models, model, model_t *);
}
Deleted: brlcad/branches/swrast/src/libdm/tests/renderer/skeleton.c
===================================================================
--- brlcad/branches/swrast/src/libdm/tests/renderer/skeleton.c 2020-08-27
20:56:40 UTC (rev 76981)
+++ brlcad/branches/swrast/src/libdm/tests/renderer/skeleton.c 2020-08-28
12:48:26 UTC (rev 76982)
@@ -1,350 +0,0 @@
-
-#include <assert.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "macro.h"
-#include "maths.h"
-#include "private.h"
-#include "api.h"
-
-/*
- * for skeletal animation, see
- *
https://people.rennes.inria.fr/Ludovic.Hoyet/teaching/IMO/05_IMO2016_Skinning.pdf
- */
-
-typedef struct {
- int joint_index;
- int parent_index;
- mat4_t inverse_bind;
- /* translations */
- int num_translations;
- float *translation_times;
- vec3_t *translation_values;
- /* rotations */
- int num_rotations;
- float *rotation_times;
- quat_t *rotation_values;
- /* scales */
- int num_scales;
- float *scale_times;
- vec3_t *scale_values;
- /* interpolated */
- mat4_t transform;
-} joint_t;
-
-struct skeleton {
- float min_time;
- float max_time;
- int num_joints;
- joint_t *joints;
- /* cached result */
- mat4_t *joint_matrices;
- mat3_t *normal_matrices;
- float last_time;
-};
-
-/* skeleton loading/releasing */
-
-static void read_inverse_bind(FILE *file, joint_t *joint) {
- char line[LINE_SIZE];
- int items;
- int i;
- items = fscanf(file, " %s", line);
- assert(items == 1 && strcmp(line, "inverse-bind:") == 0);
- for (i = 0; i < 4; i++) {
- items = fscanf(file, " %f %f %f %f",
- &joint->inverse_bind.m[i][0],
- &joint->inverse_bind.m[i][1],
- &joint->inverse_bind.m[i][2],
- &joint->inverse_bind.m[i][3]);
- assert(items == 4);
- }
- UNUSED_VAR(items);
-}
-
-static void read_translations(FILE *file, joint_t *joint) {
- int items;
- int i;
- items = fscanf(file, " translations %d:", &joint->num_translations);
- assert(items == 1 && joint->num_translations >= 0);
- if (joint->num_translations > 0) {
- int time_size = sizeof(float) * joint->num_translations;
- int value_size = sizeof(vec3_t) * joint->num_translations;
- joint->translation_times = (float*)malloc(time_size);
- joint->translation_values = (vec3_t*)malloc(value_size);
- for (i = 0; i < joint->num_translations; i++) {
- items = fscanf(file, " time: %f, value: [%f, %f, %f]",
- &joint->translation_times[i],
- &joint->translation_values[i].x,
- &joint->translation_values[i].y,
- &joint->translation_values[i].z);
- assert(items == 4);
- }
- } else {
- joint->translation_times = NULL;
- joint->translation_values = NULL;
- }
- UNUSED_VAR(items);
-}
-
-static void read_rotations(FILE *file, joint_t *joint) {
- int items;
- int i;
- items = fscanf(file, " rotations %d:", &joint->num_rotations);
- assert(items == 1 && joint->num_rotations >= 0);
- if (joint->num_rotations > 0) {
- int time_size = sizeof(float) * joint->num_rotations;
- int value_size = sizeof(quat_t) * joint->num_rotations;
- joint->rotation_times = (float*)malloc(time_size);
- joint->rotation_values = (quat_t*)malloc(value_size);
- for (i = 0; i < joint->num_rotations; i++) {
- items = fscanf(file, " time: %f, value: [%f, %f, %f, %f]",
- &joint->rotation_times[i],
- &joint->rotation_values[i].x,
- &joint->rotation_values[i].y,
- &joint->rotation_values[i].z,
- &joint->rotation_values[i].w);
- assert(items == 5);
- }
- } else {
- joint->rotation_times = NULL;
- joint->rotation_values = NULL;
- }
- UNUSED_VAR(items);
-}
-
-static void read_scales(FILE *file, joint_t *joint) {
- int items;
- int i;
- items = fscanf(file, " scales %d:", &joint->num_scales);
- assert(items == 1 && joint->num_scales >= 0);
- if (joint->num_scales > 0) {
- int time_size = sizeof(float) * joint->num_scales;
- int value_size = sizeof(vec3_t) * joint->num_scales;
- joint->scale_times = (float*)malloc(time_size);
- joint->scale_values = (vec3_t*)malloc(value_size);
- for (i = 0; i < joint->num_scales; i++) {
- items = fscanf(file, " time: %f, value: [%f, %f, %f]",
- &joint->scale_times[i],
- &joint->scale_values[i].x,
- &joint->scale_values[i].y,
- &joint->scale_values[i].z);
- assert(items == 4);
- }
- } else {
- joint->scale_times = NULL;
- joint->scale_values = NULL;
- }
- UNUSED_VAR(items);
-}
-
-static joint_t load_joint(FILE *file) {
- joint_t joint;
- int items;
-
- items = fscanf(file, " joint %d:", &joint.joint_index);
- assert(items == 1);
- items = fscanf(file, " parent-index: %d", &joint.parent_index);
- assert(items == 1);
-
- read_inverse_bind(file, &joint);
- read_translations(file, &joint);
- read_rotations(file, &joint);
- read_scales(file, &joint);
-
- UNUSED_VAR(items);
- return joint;
-}
-
-static void initialize_cache(skeleton_t *skeleton) {
- int joint_matrix_size = sizeof(mat4_t) * skeleton->num_joints;
- int normal_matrix_size = sizeof(mat3_t) * skeleton->num_joints;
- skeleton->joint_matrices = (mat4_t*)malloc(joint_matrix_size);
- skeleton->normal_matrices = (mat3_t*)malloc(normal_matrix_size);
- memset(skeleton->joint_matrices, 0, joint_matrix_size);
- memset(skeleton->normal_matrices, 0, normal_matrix_size);
- skeleton->last_time = -1;
-}
-
-static skeleton_t *load_ani(const char *filename) {
- skeleton_t *skeleton;
- FILE *file;
- int items;
- int i;
-
- skeleton = (skeleton_t*)malloc(sizeof(skeleton_t));
-
- file = fopen(filename, "rb");
- assert(file != NULL);
-
- items = fscanf(file, " joint-size: %d", &skeleton->num_joints);
- assert(items == 1 && skeleton->num_joints > 0);
- items = fscanf(file, " time-range: [%f, %f]",
- &skeleton->min_time, &skeleton->max_time);
- assert(items == 2 && skeleton->min_time < skeleton->max_time);
-
- skeleton->joints = (joint_t*)malloc(sizeof(joint_t) *
skeleton->num_joints);
- for (i = 0; i < skeleton->num_joints; i++) {
- joint_t joint = load_joint(file);
- assert(joint.joint_index == i);
- skeleton->joints[i] = joint;
- }
-
- fclose(file);
-
- initialize_cache(skeleton);
-
- UNUSED_VAR(items);
- return skeleton;
-}
-
-skeleton_t *skeleton_load(const char *filename) {
- const char *extension = private_get_extension(filename);
- if (strcmp(extension, "ani") == 0) {
- return load_ani(filename);
- } else {
- assert(0);
- return NULL;
- }
-}
-
-void skeleton_release(skeleton_t *skeleton) {
- int i;
- for (i = 0; i < skeleton->num_joints; i++) {
- joint_t *joint = &skeleton->joints[i];
- free(joint->translation_times);
- free(joint->translation_values);
- free(joint->rotation_times);
- free(joint->rotation_values);
- free(joint->scale_times);
- free(joint->scale_values);
- }
- free(skeleton->joints);
- free(skeleton->joint_matrices);
- free(skeleton->normal_matrices);
- free(skeleton);
-}
-
-/* joint updating/retrieving */
-
-static vec3_t get_translation(joint_t *joint, float frame_time) {
- int num_translations = joint->num_translations;
- float *translation_times = joint->translation_times;
- vec3_t *translation_values = joint->translation_values;
-
- if (num_translations == 0) {
- return vec3_new(0, 0, 0);
- } else if (frame_time <= translation_times[0]) {
- return translation_values[0];
- } else if (frame_time >= translation_times[num_translations - 1]) {
- return translation_values[num_translations - 1];
- } else {
- int i;
- for (i = 0; i < num_translations - 1; i++) {
- float curr_time = translation_times[i];
- float next_time = translation_times[i + 1];
- if (frame_time >= curr_time && frame_time < next_time) {
- float t = (frame_time - curr_time) / (next_time - curr_time);
- vec3_t curr_translation = translation_values[i];
- vec3_t next_translation = translation_values[i + 1];
- return vec3_lerp(curr_translation, next_translation, t);
- }
- }
- assert(0);
- return vec3_new(0, 0, 0);
- }
-}
-
-static quat_t get_rotation(joint_t *joint, float frame_time) {
- int num_rotations = joint->num_rotations;
- float *rotation_times = joint->rotation_times;
- quat_t *rotation_values = joint->rotation_values;
-
- if (num_rotations == 0) {
- return quat_new(0, 0, 0, 1);
- } else if (frame_time <= rotation_times[0]) {
- return rotation_values[0];
- } else if (frame_time >= rotation_times[num_rotations - 1]) {
- return rotation_values[num_rotations - 1];
- } else {
- int i;
- for (i = 0; i < num_rotations - 1; i++) {
- float curr_time = rotation_times[i];
- float next_time = rotation_times[i + 1];
- if (frame_time >= curr_time && frame_time < next_time) {
- float t = (frame_time - curr_time) / (next_time - curr_time);
- quat_t curr_rotation = rotation_values[i];
- quat_t next_rotation = rotation_values[i + 1];
- return quat_slerp(curr_rotation, next_rotation, t);
- }
- }
- assert(0);
- return quat_new(0, 0, 0, 1);
- }
-}
-
-static vec3_t get_scale(joint_t *joint, float frame_time) {
- int num_scales = joint->num_scales;
- float *scale_times = joint->scale_times;
- vec3_t *scale_values = joint->scale_values;
-
- if (num_scales == 0) {
- return vec3_new(1, 1, 1);
- } else if (frame_time <= scale_times[0]) {
- return scale_values[0];
- } else if (frame_time >= scale_times[num_scales - 1]) {
- return scale_values[num_scales - 1];
- } else {
- int i;
- for (i = 0; i < num_scales - 1; i++) {
- float curr_time = scale_times[i];
- float next_time = scale_times[i + 1];
- if (frame_time >= curr_time && frame_time < next_time) {
- float t = (frame_time - curr_time) / (next_time - curr_time);
- vec3_t curr_scale = scale_values[i];
- vec3_t next_scale = scale_values[i + 1];
- return vec3_lerp(curr_scale, next_scale, t);
- }
- }
- assert(0);
- return vec3_new(1, 1, 1);
- }
-}
-
-void skeleton_update_joints(skeleton_t *skeleton, float frame_time) {
- frame_time = (float)fmod(frame_time, skeleton->max_time);
- if (!NEAR_EQUAL(frame_time, skeleton->last_time, SMALL_FASTF)) {
- int i;
- for (i = 0; i < skeleton->num_joints; i++) {
- joint_t *joint = &skeleton->joints[i];
- vec3_t translation = get_translation(joint, frame_time);
- quat_t rotation = get_rotation(joint, frame_time);
- vec3_t scale = get_scale(joint, frame_time);
- mat4_t joint_matrix;
- mat3_t normal_matrix;
-
- joint->transform = mat4_from_trs(translation, rotation, scale);
- if (joint->parent_index >= 0) {
- joint_t *parent = &skeleton->joints[joint->parent_index];
- joint->transform = mat4_mul_mat4(parent->transform,
- joint->transform);
- }
-
- joint_matrix = mat4_mul_mat4(joint->transform,
joint->inverse_bind);
- normal_matrix =
mat3_inverse_transpose(mat3_from_mat4(joint_matrix));
- skeleton->joint_matrices[i] = joint_matrix;
- skeleton->normal_matrices[i] = normal_matrix;
- }
- skeleton->last_time = frame_time;
- }
-}
-
-mat4_t *skeleton_get_joint_matrices(skeleton_t *skeleton) {
- return skeleton->joint_matrices;
-}
-
-mat3_t *skeleton_get_normal_matrices(skeleton_t *skeleton) {
- return skeleton->normal_matrices;
-}
Deleted: brlcad/branches/swrast/src/libdm/tests/renderer/skeleton.h
===================================================================
--- brlcad/branches/swrast/src/libdm/tests/renderer/skeleton.h 2020-08-27
20:56:40 UTC (rev 76981)
+++ brlcad/branches/swrast/src/libdm/tests/renderer/skeleton.h 2020-08-28
12:48:26 UTC (rev 76982)
@@ -1,17 +0,0 @@
-#ifndef SKELETON_H
-#define SKELETON_H
-
-#include "maths.h"
-
-typedef struct skeleton skeleton_t;
-
-/* skeleton loading/releasing */
-skeleton_t *skeleton_load(const char *filename);
-void skeleton_release(skeleton_t *skeleton);
-
-/* joint updating/retrieving */
-void skeleton_update_joints(skeleton_t *skeleton, float frame_time);
-mat4_t *skeleton_get_joint_matrices(skeleton_t *skeleton);
-mat3_t *skeleton_get_normal_matrices(skeleton_t *skeleton);
-
-#endif
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits