Removed debug
This commit is contained in:
@@ -29,22 +29,8 @@ static void _animation_process(flecs::entity_t entity, flecs::world &ecs,
|
|||||||
// static void _node_removed(struct AnimationPlayerData *player,
|
// static void _node_removed(struct AnimationPlayerData *player,
|
||||||
// Node *p_node);
|
// Node *p_node);
|
||||||
static void _stop_playing_caches(struct AnimationPlayerData *player);
|
static void _stop_playing_caches(struct AnimationPlayerData *player);
|
||||||
static void _animation_changed(struct AnimationPlayerData *player);
|
|
||||||
static void _ref_anim(
|
|
||||||
struct AnimationPlayerData *player, const Ref<Animation> &p_anim);
|
|
||||||
static void _unref_anim(
|
|
||||||
struct AnimationPlayerData *player, const Ref<Animation> &p_anim);
|
|
||||||
static void _set_process(struct AnimationPlayerData *player, bool p_process,
|
static void _set_process(struct AnimationPlayerData *player, bool p_process,
|
||||||
bool p_force = false);
|
bool p_force = false);
|
||||||
/* protected functions (need redesign) */
|
|
||||||
#if 0
|
|
||||||
bool _set(const StringName &p_name, const Variant &p_value);
|
|
||||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
||||||
virtual void _validate_property(PropertyInfo &property) const;
|
|
||||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
|
||||||
void _notification(int p_what);
|
|
||||||
static void _bind_methods();
|
|
||||||
#endif
|
|
||||||
} //namespace ECS
|
} //namespace ECS
|
||||||
void ECS::play(struct ECS::AnimationPlayerData *player,
|
void ECS::play(struct ECS::AnimationPlayerData *player,
|
||||||
const StringName &p_name, float p_custom_blend, float p_custom_scale,
|
const StringName &p_name, float p_custom_blend, float p_custom_scale,
|
||||||
@@ -154,18 +140,9 @@ static void ECS::_ensure_node_caches(struct ECS::AnimationPlayerData *player,
|
|||||||
{
|
{
|
||||||
// Already cached?
|
// Already cached?
|
||||||
assert(p_anim->animation.is_valid());
|
assert(p_anim->animation.is_valid());
|
||||||
flecs::log::trace("cached tracks %d", p_anim->node_cache_size);
|
|
||||||
flecs::log::trace(
|
|
||||||
"animation tracks %d", p_anim->animation->get_track_count());
|
|
||||||
flecs::log::trace("animation %p", p_anim->animation.ptr());
|
|
||||||
if (p_anim->node_cache_size == p_anim->animation->get_track_count()) {
|
if (p_anim->node_cache_size == p_anim->animation->get_track_count()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
Node *parent = p_root_override ? p_root_override : get_node(root);
|
|
||||||
|
|
||||||
ERR_FAIL_COND(!parent);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Animation *a = p_anim->animation.operator->();
|
Animation *a = p_anim->animation.operator->();
|
||||||
|
|
||||||
@@ -177,13 +154,6 @@ static void ECS::_ensure_node_caches(struct ECS::AnimationPlayerData *player,
|
|||||||
Vector<StringName> leftover_path;
|
Vector<StringName> leftover_path;
|
||||||
/* handle entities here instead */
|
/* handle entities here instead */
|
||||||
print_line("TRACK: " + itos(i));
|
print_line("TRACK: " + itos(i));
|
||||||
#if 0
|
|
||||||
Node *child = parent->get_node_and_resource(a->track_get_path(i), resource, leftover_path);
|
|
||||||
ERR_CONTINUE_MSG(!child, "On Animation: '" + p_anim->name + "', couldn't resolve track: '" + String(a->track_get_path(i)) + "'."); // couldn't find the child node
|
|
||||||
uint32_t id = resource.is_valid() ? resource->get_instance_id() : child->get_instance_id();
|
|
||||||
#endif
|
|
||||||
int bone_idx = -1;
|
|
||||||
int id = -1; /* supposed to be object id but... */
|
|
||||||
NodePath np = a->track_get_path(i);
|
NodePath np = a->track_get_path(i);
|
||||||
String vpath = np;
|
String vpath = np;
|
||||||
print_line("path: " + vpath);
|
print_line("path: " + vpath);
|
||||||
@@ -192,22 +162,7 @@ static void ECS::_ensure_node_caches(struct ECS::AnimationPlayerData *player,
|
|||||||
np.get_subname_count() ==
|
np.get_subname_count() ==
|
||||||
1 /* && Object::cast_to<Skeleton>(child) */) {
|
1 /* && Object::cast_to<Skeleton>(child) */) {
|
||||||
/* use entities */
|
/* use entities */
|
||||||
#if 0
|
|
||||||
Skeleton *sk = Object::cast_to<Skeleton>(child);
|
|
||||||
bone_idx = sk->find_bone(a->track_get_path(i).get_subname(0));
|
|
||||||
if (bone_idx == -1) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
{
|
|
||||||
if (!child->is_connected("tree_exiting", this, "_node_removed")) {
|
|
||||||
child->connect("tree_exiting", this, "_node_removed", make_binds(child), CONNECT_ONESHOT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ECS::TrackNodeCacheKey key;
|
ECS::TrackNodeCacheKey key;
|
||||||
key.id = entity;
|
key.id = entity;
|
||||||
@@ -217,75 +172,34 @@ static void ECS::_ensure_node_caches(struct ECS::AnimationPlayerData *player,
|
|||||||
flecs::entity_t bone_id = bone_e.id();
|
flecs::entity_t bone_id = bone_e.id();
|
||||||
key.bone_idx = bone_id;
|
key.bone_idx = bone_id;
|
||||||
String path = np.get_subname(0);
|
String path = np.get_subname(0);
|
||||||
print_line("TRACK: " + itos(i) +
|
|
||||||
" BONE IDX: " + itos(bone_id) +
|
|
||||||
" ID: " + itos(entity) + " PATH: " + path);
|
|
||||||
|
|
||||||
if (!player->node_cache_map.has(key))
|
if (!player->node_cache_map.has(key))
|
||||||
player->node_cache_map[key] = ECS::TrackNodeCache();
|
player->node_cache_map[key] = ECS::TrackNodeCache();
|
||||||
|
|
||||||
p_anim->node_cache[i] = &player->node_cache_map[key];
|
p_anim->node_cache[i] = &player->node_cache_map[key];
|
||||||
p_anim->node_cache[i]->path = a->track_get_path(i);
|
p_anim->node_cache[i]->path = a->track_get_path(i);
|
||||||
#if 0
|
|
||||||
p_anim->node_cache[i]->node = child;
|
|
||||||
#endif
|
|
||||||
p_anim->node_cache[i]->resource = resource;
|
p_anim->node_cache[i]->resource = resource;
|
||||||
#if 0
|
|
||||||
p_anim->node_cache[i]->node_2d = Object::cast_to<Node2D>(child);
|
|
||||||
#endif
|
|
||||||
if (a->track_get_type(i) == Animation::TYPE_TRANSFORM) {
|
if (a->track_get_type(i) == Animation::TYPE_TRANSFORM) {
|
||||||
// special cases and caches for transform tracks
|
// special cases and caches for transform tracks
|
||||||
#if 0
|
if (a->track_get_path(i).get_subname_count() == 1) {
|
||||||
// cache spatial
|
|
||||||
p_anim->node_cache[i]->spatial = Object::cast_to<Spatial>(child);
|
|
||||||
// cache skeleton
|
|
||||||
p_anim->node_cache[i]->skeleton = Object::cast_to<Skeleton>(child);
|
|
||||||
#endif
|
|
||||||
if (true /* || p_anim->node_cache[i]->skeleton */) {
|
|
||||||
if (a->track_get_path(i).get_subname_count() ==
|
|
||||||
1) {
|
|
||||||
StringName bone_name =
|
StringName bone_name =
|
||||||
a->track_get_path(i)
|
a->track_get_path(i).get_subname(0);
|
||||||
.get_subname(0);
|
|
||||||
|
|
||||||
/* use entities */
|
/* use entities */
|
||||||
p_anim->node_cache[i]->bone_idx =
|
p_anim->node_cache[i]->bone_idx = key.bone_idx;
|
||||||
key.bone_idx;
|
|
||||||
#if 0
|
|
||||||
p_anim->node_cache[i]->bone_idx = p_anim->node_cache[i]->skeleton->find_bone(bone_name);
|
|
||||||
#endif
|
|
||||||
#if 0
|
|
||||||
if (p_anim->node_cache[i]->bone_idx <
|
|
||||||
0) {
|
|
||||||
// broken track (nonexistent
|
|
||||||
// bone)
|
|
||||||
p_anim->node_cache[i]->skeleton = nullptr;
|
|
||||||
p_anim->node_cache[i]->spatial = nullptr;
|
|
||||||
ERR_CONTINUE(
|
|
||||||
p_anim->node_cache[i]
|
|
||||||
->bone_idx <
|
|
||||||
0);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
#if 0
|
|
||||||
// no property, just use spatialnode
|
|
||||||
p_anim->node_cache[i]->skeleton = nullptr;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#ifdef VALUE_TRACK_SUPPORT
|
||||||
if (a->track_get_type(i) == Animation::TYPE_VALUE) {
|
if (a->track_get_type(i) == Animation::TYPE_VALUE) {
|
||||||
if (!p_anim->node_cache[i]->property_anim.has(
|
if (!p_anim->node_cache[i]->property_anim.has(
|
||||||
a->track_get_path(i)
|
a->track_get_path(i)
|
||||||
.get_concatenated_subnames())) {
|
.get_concatenated_subnames())) {
|
||||||
TrackNodeCache::PropertyAnim pa;
|
TrackNodeCache::PropertyAnim pa;
|
||||||
pa.subpath = leftover_path;
|
pa.subpath = leftover_path;
|
||||||
#if 0
|
pa.object = resource.is_valid()
|
||||||
pa.object = resource.is_valid() ? (Object *)resource.ptr() : (Object *)child;
|
? (Object *)resource.ptr()
|
||||||
#endif
|
: (Object *)child;
|
||||||
pa.special = SP_NONE;
|
pa.special = SP_NONE;
|
||||||
pa.owner = p_anim->node_cache[i];
|
pa.owner = p_anim->node_cache[i];
|
||||||
p_anim->node_cache[i]->property_anim
|
p_anim->node_cache[i]->property_anim
|
||||||
@@ -294,7 +208,8 @@ static void ECS::_ensure_node_caches(struct ECS::AnimationPlayerData *player,
|
|||||||
pa;
|
pa;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef BEZIER_TRACK_SUPPORT
|
||||||
if (a->track_get_type(i) == Animation::TYPE_BEZIER &&
|
if (a->track_get_type(i) == Animation::TYPE_BEZIER &&
|
||||||
leftover_path.size()) {
|
leftover_path.size()) {
|
||||||
if (!p_anim->node_cache[i]->bezier_anim.has(
|
if (!p_anim->node_cache[i]->bezier_anim.has(
|
||||||
@@ -312,8 +227,8 @@ static void ECS::_ensure_node_caches(struct ECS::AnimationPlayerData *player,
|
|||||||
.get_concatenated_subnames()] =
|
.get_concatenated_subnames()] =
|
||||||
ba;
|
ba;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void ECS::_animation_process_animation(flecs::entity_t entity,
|
static void ECS::_animation_process_animation(flecs::entity_t entity,
|
||||||
@@ -326,9 +241,6 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
|
|||||||
p_anim->animation->get_track_count());
|
p_anim->animation->get_track_count());
|
||||||
|
|
||||||
Animation *a = p_anim->animation.ptr();
|
Animation *a = p_anim->animation.ptr();
|
||||||
#if 0
|
|
||||||
bool can_call = is_inside_tree() && !Engine::get_singleton()->is_editor_hint();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (int i = 0; i < a->get_track_count(); i++) {
|
for (int i = 0; i < a->get_track_count(); i++) {
|
||||||
// If an animation changes this animation (or it
|
// If an animation changes this animation (or it
|
||||||
@@ -349,18 +261,11 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
|
|||||||
continue; // do nothing if the track is
|
continue; // do nothing if the track is
|
||||||
// disabled
|
// disabled
|
||||||
}
|
}
|
||||||
flecs::log::trace("track keys: %d", i);
|
if (a->track_get_key_count(i) == 0)
|
||||||
if (a->track_get_key_count(i) == 0) {
|
|
||||||
continue; // do nothing if track is empty
|
continue; // do nothing if track is empty
|
||||||
}
|
|
||||||
|
|
||||||
switch (a->track_get_type(i)) {
|
switch (a->track_get_type(i)) {
|
||||||
case Animation::TYPE_TRANSFORM: {
|
case Animation::TYPE_TRANSFORM: {
|
||||||
#if 0
|
|
||||||
if (!nc->spatial) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
Vector3 loc;
|
Vector3 loc;
|
||||||
Quat rot;
|
Quat rot;
|
||||||
Vector3 scale;
|
Vector3 scale;
|
||||||
@@ -370,9 +275,8 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
|
|||||||
//ERR_CONTINUE(err!=OK); //used for
|
//ERR_CONTINUE(err!=OK); //used for
|
||||||
//testing, should be removed
|
//testing, should be removed
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (nc->accum_pass != player->accum_pass) {
|
if (nc->accum_pass != player->accum_pass) {
|
||||||
ERR_CONTINUE(
|
ERR_CONTINUE(
|
||||||
@@ -385,9 +289,6 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
|
|||||||
nc->loc_accum = loc;
|
nc->loc_accum = loc;
|
||||||
nc->rot_accum = rot;
|
nc->rot_accum = rot;
|
||||||
nc->scale_accum = scale;
|
nc->scale_accum = scale;
|
||||||
print_line("cache update: " +
|
|
||||||
itos(nc->bone_idx));
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
nc->loc_accum =
|
nc->loc_accum =
|
||||||
nc->loc_accum
|
nc->loc_accum
|
||||||
@@ -400,17 +301,11 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
|
|||||||
.linear_interpolate(
|
.linear_interpolate(
|
||||||
scale,
|
scale,
|
||||||
p_interp);
|
p_interp);
|
||||||
print_line("cache update2: " +
|
|
||||||
itos(nc->bone_idx));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case Animation::TYPE_VALUE: {
|
case Animation::TYPE_VALUE: {
|
||||||
#if 0
|
#ifdef VALUE_TRACK_SUPPORT
|
||||||
if (!nc->node) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
//StringName
|
//StringName
|
||||||
//property=a->track_get_path(i).get_property();
|
//property=a->track_get_path(i).get_property();
|
||||||
|
|
||||||
@@ -608,8 +503,10 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
} break;
|
} break;
|
||||||
case Animation::TYPE_METHOD: {
|
case Animation::TYPE_METHOD: {
|
||||||
|
#ifdef METHOD_TRACK_SUPPORT
|
||||||
#if 0
|
#if 0
|
||||||
if (!nc->node) {
|
if (!nc->node) {
|
||||||
continue;
|
continue;
|
||||||
@@ -683,8 +580,10 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
} break;
|
} break;
|
||||||
case Animation::TYPE_BEZIER: {
|
case Animation::TYPE_BEZIER: {
|
||||||
|
#ifdef BEZIER_TRACK_SUPPORT
|
||||||
#if 0
|
#if 0
|
||||||
if (!nc->node) {
|
if (!nc->node) {
|
||||||
continue;
|
continue;
|
||||||
@@ -717,9 +616,13 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
|
|||||||
bezier, p_interp);
|
bezier, p_interp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
} break;
|
} break;
|
||||||
case Animation::TYPE_AUDIO: {
|
case Animation::TYPE_AUDIO: {
|
||||||
|
#ifndef AUDIO_TRACK_SUPPORT
|
||||||
/* Convert audio support to "server" */
|
/* Convert audio support to "server" */
|
||||||
|
/* This requires node to be audio
|
||||||
|
* source? */
|
||||||
#if 0
|
#if 0
|
||||||
if (!nc->node) {
|
if (!nc->node) {
|
||||||
continue;
|
continue;
|
||||||
@@ -888,9 +791,10 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
} break;
|
} break;
|
||||||
case Animation::TYPE_ANIMATION: {
|
case Animation::TYPE_ANIMATION: {
|
||||||
|
#if 0
|
||||||
/* animations of animations - need
|
/* animations of animations - need
|
||||||
* rework */
|
* rework */
|
||||||
#if 0
|
#if 0
|
||||||
@@ -954,6 +858,7 @@ static void ECS::_animation_process_animation(flecs::entity_t entity,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
@@ -971,7 +876,6 @@ static void ECS::_animation_process_data(flecs::entity_t entity,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert(cd.from->animation.is_valid());
|
assert(cd.from->animation.is_valid());
|
||||||
flecs::log::trace("animation %p", cd.from->animation.ptr());
|
|
||||||
float len = cd.from->animation->get_length();
|
float len = cd.from->animation->get_length();
|
||||||
bool loop = cd.from->animation->has_loop();
|
bool loop = cd.from->animation->has_loop();
|
||||||
if (!loop) {
|
if (!loop) {
|
||||||
@@ -1025,8 +929,6 @@ static void ECS::_animation_process2(flecs::entity_t entity, flecs::world &ecs,
|
|||||||
ERR_PRINT("bad animation2");
|
ERR_PRINT("bad animation2");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
flecs::log::trace("length: %d",
|
|
||||||
player->playback.current.from->animation->get_length());
|
|
||||||
_animation_process_data(entity, ecs, player, c.current, p_delta, 1.0f,
|
_animation_process_data(entity, ecs, player, c.current, p_delta, 1.0f,
|
||||||
c.seeked && p_delta != 0, p_started);
|
c.seeked && p_delta != 0, p_started);
|
||||||
if (p_delta != 0)
|
if (p_delta != 0)
|
||||||
@@ -1069,19 +971,11 @@ static void ECS::_animation_update_transforms(flecs::entity_t entity,
|
|||||||
bone_entity.get_mut<ECS::BonePose>();
|
bone_entity.get_mut<ECS::BonePose>();
|
||||||
bone->pose = t;
|
bone->pose = t;
|
||||||
bone_entity.modified<ECS::BonePose>();
|
bone_entity.modified<ECS::BonePose>();
|
||||||
flecs::log::err("good bone %d", nc->bone_idx);
|
}
|
||||||
} else
|
|
||||||
flecs::log::err("bad bone %d", nc->bone_idx);
|
|
||||||
#if 0
|
|
||||||
/* update transform on skeleton or node */
|
|
||||||
if (nc->skeleton && nc->bone_idx >= 0)
|
|
||||||
nc->skeleton->set_bone_pose(nc->bone_idx, t);
|
|
||||||
else if (nc->spatial)
|
|
||||||
nc->spatial->set_transform(t);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
player->cache_update_size = 0;
|
player->cache_update_size = 0;
|
||||||
|
#ifdef VALUE_TRACK_SUPPORT
|
||||||
for (i = 0; i < player->cache_update_prop_size; i++) {
|
for (i = 0; i < player->cache_update_prop_size; i++) {
|
||||||
TrackNodeCache::PropertyAnim *pa =
|
TrackNodeCache::PropertyAnim *pa =
|
||||||
player->cache_update_prop[i];
|
player->cache_update_prop[i];
|
||||||
@@ -1120,12 +1014,15 @@ static void ECS::_animation_update_transforms(flecs::entity_t entity,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
player->cache_update_prop_size = 0;
|
player->cache_update_prop_size = 0;
|
||||||
|
#ifdef BEZIER_TRACK_SUPPORT
|
||||||
for (i = 0; i < player->cache_update_bezier_size; i++) {
|
for (i = 0; i < player->cache_update_bezier_size; i++) {
|
||||||
TrackNodeCache::BezierAnim *ba =
|
TrackNodeCache::BezierAnim *ba =
|
||||||
player->cache_update_bezier[i];
|
player->cache_update_bezier[i];
|
||||||
ba->object->set_indexed(ba->bezier_property, ba->bezier_accum);
|
ba->object->set_indexed(ba->bezier_property, ba->bezier_accum);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
player->cache_update_bezier_size = 0;
|
player->cache_update_bezier_size = 0;
|
||||||
}
|
}
|
||||||
static void ECS::_set_process(
|
static void ECS::_set_process(
|
||||||
@@ -1170,20 +1067,6 @@ static void ECS::_animation_process(flecs::entity_t entity, flecs::world &ecs,
|
|||||||
}
|
}
|
||||||
void ECS::_stop_playing_caches(struct ECS::AnimationPlayerData *player)
|
void ECS::_stop_playing_caches(struct ECS::AnimationPlayerData *player)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
for (Set<TrackNodeCache *>::Element *E = player->playing_caches.front(); E; E = E->next()) {
|
|
||||||
if (E->get()->node && E->get()->audio_playing) {
|
|
||||||
E->get()->node->call("stop");
|
|
||||||
}
|
|
||||||
if (E->get()->node && E->get()->animation_playing) {
|
|
||||||
AnimationPlayer *player = Object::cast_to<AnimationPlayer>(E->get()->node);
|
|
||||||
if (!player) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
player->stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
player->playing_caches.clear();
|
player->playing_caches.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1213,11 +1096,8 @@ Error ECS::add_animation(struct ECS::AnimationPlayerData *player,
|
|||||||
const StringName &p_name, const Ref<Animation> &p_animation)
|
const StringName &p_name, const Ref<Animation> &p_animation)
|
||||||
{
|
{
|
||||||
ERR_FAIL_COND_V(p_animation.is_null(), ERR_INVALID_PARAMETER);
|
ERR_FAIL_COND_V(p_animation.is_null(), ERR_INVALID_PARAMETER);
|
||||||
print_line("animation name: " + p_name);
|
|
||||||
print_line("animation length: " + itos(p_animation->get_length()));
|
|
||||||
|
|
||||||
if (player->animation_set.has(p_name)) {
|
if (player->animation_set.has(p_name)) {
|
||||||
_unref_anim(player, player->animation_set[p_name].animation);
|
|
||||||
player->animation_set[p_name].animation = p_animation;
|
player->animation_set[p_name].animation = p_animation;
|
||||||
clear_caches(player);
|
clear_caches(player);
|
||||||
} else {
|
} else {
|
||||||
@@ -1228,7 +1108,6 @@ Error ECS::add_animation(struct ECS::AnimationPlayerData *player,
|
|||||||
player->animation_set[p_name].animation = p_animation;
|
player->animation_set[p_name].animation = p_animation;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ref_anim(player, p_animation);
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
void ECS::remove_animation(
|
void ECS::remove_animation(
|
||||||
@@ -1236,26 +1115,11 @@ void ECS::remove_animation(
|
|||||||
{
|
{
|
||||||
ERR_FAIL_COND(!player->animation_set.has(p_name));
|
ERR_FAIL_COND(!player->animation_set.has(p_name));
|
||||||
|
|
||||||
#if 0
|
stop(player);
|
||||||
stop();
|
|
||||||
#endif
|
|
||||||
#if 0
|
|
||||||
_unref_anim(player, player->animation_set[p_name].animation);
|
|
||||||
#endif
|
|
||||||
player->animation_set.erase(p_name);
|
player->animation_set.erase(p_name);
|
||||||
|
|
||||||
clear_caches(player);
|
clear_caches(player);
|
||||||
}
|
}
|
||||||
static void ECS::_ref_anim(
|
|
||||||
struct ECS::AnimationPlayerData *player, const Ref<Animation> &p_anim)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ECS::_unref_anim(
|
|
||||||
struct ECS::AnimationPlayerData *player, const Ref<Animation> &p_anim)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ECS::clear_caches(struct ECS::AnimationPlayerData *player)
|
void ECS::clear_caches(struct ECS::AnimationPlayerData *player)
|
||||||
{
|
{
|
||||||
_stop_playing_caches(player);
|
_stop_playing_caches(player);
|
||||||
@@ -1272,11 +1136,19 @@ void ECS::clear_caches(struct ECS::AnimationPlayerData *player)
|
|||||||
void ECS::advance(flecs::entity_t entity, flecs::world &ecs,
|
void ECS::advance(flecs::entity_t entity, flecs::world &ecs,
|
||||||
ECS::AnimationPlayerData *player, float p_time)
|
ECS::AnimationPlayerData *player, float p_time)
|
||||||
{
|
{
|
||||||
if (player->playback.current.from) {
|
|
||||||
flecs::log::trace("length: %f",
|
|
||||||
player->playback.current.from->animation
|
|
||||||
->get_length());
|
|
||||||
}
|
|
||||||
ECS::_animation_process(entity, ecs, player, p_time);
|
ECS::_animation_process(entity, ecs, player, p_time);
|
||||||
player->playback.current.from = nullptr;
|
player->playback.current.from = nullptr;
|
||||||
}
|
}
|
||||||
|
void ECS::stop(struct ECS::AnimationPlayerData *player, bool p_reset)
|
||||||
|
{
|
||||||
|
_stop_playing_caches(player);
|
||||||
|
Playback &c = player->playback;
|
||||||
|
c.blend.clear();
|
||||||
|
if (p_reset) {
|
||||||
|
c.current.from = nullptr;
|
||||||
|
c.current.speed_scale = 1.0f;
|
||||||
|
c.current.pos = 0.0f;
|
||||||
|
}
|
||||||
|
_set_process(player, false);
|
||||||
|
player->queued.clear();
|
||||||
|
}
|
||||||
|
|||||||
@@ -186,9 +186,9 @@ struct BasicTrack : public Track {
|
|||||||
struct AnimationData {
|
struct AnimationData {
|
||||||
String name;
|
String name;
|
||||||
StringName next;
|
StringName next;
|
||||||
|
Ref<Animation> animation;
|
||||||
int node_cache_size;
|
int node_cache_size;
|
||||||
struct TrackNodeCache *node_cache[128];
|
struct TrackNodeCache *node_cache[128];
|
||||||
Ref<Animation> animation;
|
|
||||||
AnimationData(Ref<Animation> anim) :
|
AnimationData(Ref<Animation> anim) :
|
||||||
animation(anim), node_cache_size(0)
|
animation(anim), node_cache_size(0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ int Character::create_character(int id)
|
|||||||
.set<ECS::BonePose>({ index, Transform() });
|
.set<ECS::BonePose>({ index, Transform() });
|
||||||
}
|
}
|
||||||
for (i = 0; i < scene_data[id].meshes.size(); i++) {
|
for (i = 0; i < scene_data[id].meshes.size(); i++) {
|
||||||
// flecs::log::trace("creating slot -");
|
|
||||||
ecs.entity(scene_data[id]
|
ecs.entity(scene_data[id]
|
||||||
.meshes[i]
|
.meshes[i]
|
||||||
.slot_name.ascii()
|
.slot_name.ascii()
|
||||||
@@ -133,9 +132,7 @@ int Character::create_character(int id)
|
|||||||
scene_data[id].meshes[i].mesh,
|
scene_data[id].meshes[i].mesh,
|
||||||
scene_data[id].meshes[i].skin);
|
scene_data[id].meshes[i].skin);
|
||||||
}
|
}
|
||||||
// print_line("character created");
|
|
||||||
int xid = entities.size();
|
int xid = entities.size();
|
||||||
// print_line(itos(xid) + ":" + itos(root.id()));
|
|
||||||
entities[xid] = root.id();
|
entities[xid] = root.id();
|
||||||
return xid;
|
return xid;
|
||||||
}
|
}
|
||||||
@@ -296,8 +293,6 @@ void Character::init_bone()
|
|||||||
{
|
{
|
||||||
ecs.component<ECS::BoneComponent>()
|
ecs.component<ECS::BoneComponent>()
|
||||||
.on_add([](flecs::entity e, ECS::BoneComponent &s) {
|
.on_add([](flecs::entity e, ECS::BoneComponent &s) {
|
||||||
// flecs::log::trace("added bonecomponent %s",
|
|
||||||
// e.name().c_str());
|
|
||||||
flecs::entity parent = e.parent();
|
flecs::entity parent = e.parent();
|
||||||
parent.add<ECS::Dirty>();
|
parent.add<ECS::Dirty>();
|
||||||
if (parent.has<ECS::Bound>()) {
|
if (parent.has<ECS::Bound>()) {
|
||||||
@@ -323,25 +318,12 @@ void Character::init_bone()
|
|||||||
skel->dirty = true;
|
skel->dirty = true;
|
||||||
String out;
|
String out;
|
||||||
VariantWriter::write_to_string(s.rest, out);
|
VariantWriter::write_to_string(s.rest, out);
|
||||||
// flecs::log::trace("bonecomponent set %s (%d) [%s]",
|
|
||||||
// e.name().c_str(), skel->bone_count,
|
|
||||||
// out.ascii().get_data());
|
|
||||||
parent.remove<ECS::SkeletonOrderPrepared>();
|
parent.remove<ECS::SkeletonOrderPrepared>();
|
||||||
parent.add<ECS::Dirty>();
|
parent.add<ECS::Dirty>();
|
||||||
});
|
});
|
||||||
ecs.component<ECS::BonePose>()
|
ecs.component<ECS::BonePose>()
|
||||||
.on_add([](flecs::entity e, ECS::BonePose &s) {
|
.on_add([](flecs::entity e, ECS::BonePose &s) {})
|
||||||
// flecs::log::trace("added
|
|
||||||
//bonepose %s", e.name().c_str());
|
|
||||||
})
|
|
||||||
.on_set([](flecs::entity e, ECS::BonePose &s) {
|
.on_set([](flecs::entity e, ECS::BonePose &s) {
|
||||||
#if 0
|
|
||||||
const Transform &xform = s.pose;
|
|
||||||
String out;
|
|
||||||
VariantWriter::write_to_string(xform, out);
|
|
||||||
flecs::log::trace("bone pose set %s: %d %s",
|
|
||||||
e.name().c_str(), s.index, out.ascii().get_data());
|
|
||||||
#endif
|
|
||||||
e.add<ECS::Dirty>();
|
e.add<ECS::Dirty>();
|
||||||
});
|
});
|
||||||
ecs.system<ECS::BonePose, ECS::Dirty>()
|
ecs.system<ECS::BonePose, ECS::Dirty>()
|
||||||
@@ -363,8 +345,6 @@ void Character::init_bone()
|
|||||||
skel->dirty = true;
|
skel->dirty = true;
|
||||||
String out;
|
String out;
|
||||||
VariantWriter::write_to_string(s.pose, out);
|
VariantWriter::write_to_string(s.pose, out);
|
||||||
// flecs::log::trace("set bonepose %s %d %s",
|
|
||||||
// e.name().c_str(), s.index, out.ascii().get_data());
|
|
||||||
parent.modified<ECS::Skeleton>();
|
parent.modified<ECS::Skeleton>();
|
||||||
parent.add<ECS::Dirty>();
|
parent.add<ECS::Dirty>();
|
||||||
parent.remove<ECS::SkeletonTransformReady>();
|
parent.remove<ECS::SkeletonTransformReady>();
|
||||||
@@ -374,14 +354,12 @@ void Character::init_bone()
|
|||||||
void Character::animation_system_init()
|
void Character::animation_system_init()
|
||||||
{
|
{
|
||||||
ecs.component<ECS::AnimationPlayerData>().on_set(
|
ecs.component<ECS::AnimationPlayerData>().on_set(
|
||||||
[](flecs::entity e, ECS::AnimationPlayerData &s) {
|
[](flecs::entity e, ECS::AnimationPlayerData &s) {});
|
||||||
flecs::log::trace("created animation player");
|
|
||||||
});
|
|
||||||
ecs.system<ECS::AnimationPlayerData>("UpdateAnimation")
|
ecs.system<ECS::AnimationPlayerData>("UpdateAnimation")
|
||||||
.kind(flecs::OnUpdate)
|
.kind(flecs::OnUpdate)
|
||||||
.each([](flecs::entity e, ECS::AnimationPlayerData &player) {
|
.each([](flecs::entity e, ECS::AnimationPlayerData &player) {
|
||||||
if (!player.playing)
|
if (!player.playing)
|
||||||
ECS::play(&player, "stand1-loop");
|
ECS::play(&player, "male-mx-walk-loop");
|
||||||
flecs::world w = e.world();
|
flecs::world w = e.world();
|
||||||
ECS::advance(e.id(), w, &player,
|
ECS::advance(e.id(), w, &player,
|
||||||
SceneTree::get_singleton()
|
SceneTree::get_singleton()
|
||||||
@@ -420,24 +398,7 @@ void Character::initialize()
|
|||||||
if (err == OK && scene2.is_valid())
|
if (err == OK && scene2.is_valid())
|
||||||
set_scene(1, scene2);
|
set_scene(1, scene2);
|
||||||
initialized = true;
|
initialized = true;
|
||||||
ecs.system<ECS::Skeleton>("UpdateBone")
|
|
||||||
.with<ECS::Bound>()
|
|
||||||
.kind(flecs::OnUpdate)
|
|
||||||
.each([](flecs::entity e, ECS::Skeleton &sk) {
|
|
||||||
flecs::entity root = e.lookup("Root");
|
|
||||||
if (!root.is_valid() || !root.is_alive())
|
|
||||||
return;
|
|
||||||
if (!root.has<ECS::BonePose>())
|
|
||||||
return;
|
|
||||||
float delta = SceneTree::get_singleton()
|
|
||||||
->get_physics_process_time();
|
|
||||||
struct ECS::BonePose *bp =
|
|
||||||
root.get_mut<ECS::BonePose>();
|
|
||||||
// bp->pose.basis =
|
|
||||||
//bp->pose.basis.rotated(Vector3(0, 1, 0), 0.016f);
|
|
||||||
bp->pose.origin += Vector3(0.2f * delta, 0.0f, 0.0f);
|
|
||||||
root.modified<ECS::BonePose>();
|
|
||||||
});
|
|
||||||
animation_system_init();
|
animation_system_init();
|
||||||
if (!Engine::get_singleton()->is_editor_hint()) {
|
if (!Engine::get_singleton()->is_editor_hint()) {
|
||||||
err = st->connect("physics_frame", this, "_progress");
|
err = st->connect("physics_frame", this, "_progress");
|
||||||
|
|||||||
@@ -25,15 +25,9 @@ void Character::init_slot()
|
|||||||
vs->instance_set_base(s.instance, RID());
|
vs->instance_set_base(s.instance, RID());
|
||||||
vs->free(s.instance);
|
vs->free(s.instance);
|
||||||
s.instance = RID();
|
s.instance = RID();
|
||||||
// print_line("mesh
|
|
||||||
//instance slot removed " + s.name);
|
|
||||||
}
|
}
|
||||||
// flecs::log::trace("removed slot
|
|
||||||
//%s", e.name().c_str());
|
|
||||||
})
|
})
|
||||||
.on_set([st](flecs::entity e, ECS::CharacterSlot &s) {
|
.on_set([st](flecs::entity e, ECS::CharacterSlot &s) {
|
||||||
// flecs::log::trace("set slot
|
|
||||||
//%s", e.name().c_str());
|
|
||||||
if (s.mesh.is_null() || !s.mesh.is_valid())
|
if (s.mesh.is_null() || !s.mesh.is_valid())
|
||||||
flecs::log::err(
|
flecs::log::err(
|
||||||
"invalid mesh %s", e.name().c_str());
|
"invalid mesh %s", e.name().c_str());
|
||||||
@@ -55,8 +49,6 @@ void Character::init_slot()
|
|||||||
slot.instance, scenario);
|
slot.instance, scenario);
|
||||||
vs->instance_set_base(
|
vs->instance_set_base(
|
||||||
slot.instance, slot.mesh->get_rid());
|
slot.instance, slot.mesh->get_rid());
|
||||||
// flecs::log::trace("created
|
|
||||||
//instance for %s", e.name().c_str());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ecs.system<ECS::CharacterSlot>("AttachToSkeleton")
|
ecs.system<ECS::CharacterSlot>("AttachToSkeleton")
|
||||||
@@ -73,8 +65,6 @@ void Character::init_slot()
|
|||||||
const ECS::Skeleton *skel =
|
const ECS::Skeleton *skel =
|
||||||
parent.get<ECS::Skeleton>();
|
parent.get<ECS::Skeleton>();
|
||||||
assert(skel->skeleton.is_valid());
|
assert(skel->skeleton.is_valid());
|
||||||
// flecs::log::trace("binding slot
|
|
||||||
//for %s", e.name().c_str());
|
|
||||||
if (skel->skeleton.is_valid())
|
if (skel->skeleton.is_valid())
|
||||||
slot.skeleton = skel->skeleton;
|
slot.skeleton = skel->skeleton;
|
||||||
if (slot.skin.is_null() && !skel->skin.is_null())
|
if (slot.skin.is_null() && !skel->skin.is_null())
|
||||||
@@ -90,8 +80,6 @@ void Character::init_slot()
|
|||||||
slot.bound = true;
|
slot.bound = true;
|
||||||
e.add<ECS::Bound>();
|
e.add<ECS::Bound>();
|
||||||
parent.add<ECS::Bound>();
|
parent.add<ECS::Bound>();
|
||||||
// flecs::log::trace("bound
|
|
||||||
//slot for %s", e.name().c_str());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ecs.system<ECS::CharacterSlot>("BindSlotsToSkeleton")
|
ecs.system<ECS::CharacterSlot>("BindSlotsToSkeleton")
|
||||||
@@ -111,14 +99,10 @@ void Character::init_slot()
|
|||||||
const struct ECS::Skeleton::bone_data
|
const struct ECS::Skeleton::bone_data
|
||||||
*bonesptr = skel->bones.ptr();
|
*bonesptr = skel->bones.ptr();
|
||||||
const int *order = skel->process_order.ptr();
|
const int *order = skel->process_order.ptr();
|
||||||
// flecs::log::trace("binding
|
|
||||||
//slot for %s", e.name().c_str());
|
|
||||||
slot.skin_internal.instance();
|
slot.skin_internal.instance();
|
||||||
slot.skin_internal->set_bind_count(
|
slot.skin_internal->set_bind_count(
|
||||||
skel->bones.size());
|
skel->bones.size());
|
||||||
int len = skel->bones.size();
|
int len = skel->bones.size();
|
||||||
// flecs::log::trace("creating
|
|
||||||
//skin for %s", e.name().c_str());
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
const struct ECS::Skeleton::bone_data
|
const struct ECS::Skeleton::bone_data
|
||||||
&b = bonesptr[order[i]];
|
&b = bonesptr[order[i]];
|
||||||
@@ -143,8 +127,6 @@ void Character::init_slot()
|
|||||||
.affine_inverse());
|
.affine_inverse());
|
||||||
}
|
}
|
||||||
skel->skin = slot.skin_internal;
|
skel->skin = slot.skin_internal;
|
||||||
// flecs::log::trace("created
|
|
||||||
//skin for %s: %d", e.name().c_str(), len);
|
|
||||||
assert(skel->skeleton.is_valid());
|
assert(skel->skeleton.is_valid());
|
||||||
skel->skin = slot.skin_internal;
|
skel->skin = slot.skin_internal;
|
||||||
uint32_t bind_count =
|
uint32_t bind_count =
|
||||||
|
|||||||
Reference in New Issue
Block a user