0

This question has been in my mind for a while now, especially in the context of high performance, interactive 3d applications. Just want to find out what is the general practices in DoD for referencing other objects.

Let's take an example: Animations that need to update skeletons and an ECS that knows which animation to trigger for the skeleton:

struct Skeleton {
  vector<vec3> jointPositions;
  vector<quat> jointRotations;
  vector<vec3> jointScales;
  vector<mat4> jointTransforms;
};

struct Animator {
  uint32_t currentAnimation = 0;
};

struct Keyframe {
  vector<float> times;
  vector<vec4> values;
  uint32_t joint;
  Target target; // Rotation|Position|Scale;
};

struct Animation {
  vector<Keyframe> keyframes;
}

void AnimationSystem::update(float dt) {
  for (auto &[skeleton, animator]: entityContext.iterate<Skeleton, Animator>()) {
    auto &animation = getAnimation(animator.currentAnimation); // <-- How do I get this?
    
    for (auto &keyframe: animation.getKeyframes()) {
      // linear interpolation
      auto interpolatedValue = interpolate(keyframe, dt);
      applyToJoint(skeleton.joints[keyframe.joint], interpolatedValue, keyframe.target);
    }
  }
}

My question is, how do I access the real object if I have an ID? Easiest solution is storing all the animations in a hash map but hash maps are not really cache friendly unless it is specifically built with that in mind. Another approach that I have seen a lot is using vectors for the animations and using references as the ID but then can one deal with deletions. Will deletion mean to add a dummy animation in place of the deleted one and let it run, which won't do anything since it is an empty animation? What if a dummy element cannot replace the hole (e.g binding vertex buffers for rendering meshes)?

These are the questions that I constantly as when comes to Data oriented design and data oriented ECS but unfortunately I do not know how to make references work in a way that cache hits can be improved.

EDIT: Updated the code snippet

An animation consists of multiple keyframes and each keyframe stores times and values. The system needs to go through every single keyframe, calculate the interpolated value, and update the skeleton joint data.

3
  • Animation has keyframes that can change the contents of a specific joint in a skeleton. So, keyframe 0 = change rotation property of joint 5, keyframe 1 changes position property of joint 2 etc. The system reads the keyframes of an animayion and updates the skeleton joints.
    – Gasim
    Apr 29 at 12:26
  • Updated the component! Let me know if the description and the new code snippet is sufficient.
    – Gasim
    Apr 29 at 12:37
  • I think there is still too much context missing (not more code). I cannot see anything about the lifetime and scope of those animations in your system - where are they coming from, how are they managed, how do they change? You ask about getAnimation - "how do I get this" - but how can we know, if you don't?
    – Doc Brown
    Apr 30 at 8:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.