Can Copy Animation from SceneA to SceneB

if i have tow scene use same model (mesh, bones , … everything) just with différente animation
Can Copy Animations From SceneA To SceneB ?
Something like that

procedure CopySpecificAnimation(SceneA, SceneB: TCastleScene; const AnimationName: String);
var
  Ts: TTimeSensorNode;
  TsCopy: TTimeSensorNode;
begin
  Ts := SceneA.AnimationTimeSensor(AnimationName);
  if Ts = nil then Exit;

  TsCopy := Ts.DeepCopy as TTimeSensorNode;

  SceneB.RootNode.AddChildren(TsCopy, False);

  SceneB.AnimationsList.AddObject('test', TsCopy);

  SceneB.AnimationTimeSensor('test').Start(True);
end;

If this is a way to achieve this, I think it would be very useful in terms of RAM consumption, especially if you have many players who use a lot of animations. To achieve this, you only need to load the animation into memory once.

Now, I use another method: storing Scene.RootNode.DeepCopy as TX3DRootNode in an array and then using it when needed. This means each player has one animation in memory. However, this method doesn’t allow you to use AnimationTransition when changing animations. Each player must have two animations. Therefore, I’m looking for a way to add an animation to each player, if possible.

Copying the animations using CGE API → means you need to copy many more nodes. Not only TTimeSensorNode nodes, also all the interpolators and then setup “routes” connecting them. You can read Interpolation component | Castle Game Engine to understand how animations are described using X3D nodes in our engine. You need to copy/setup all things in that section to transfer a working animation from one model to another.

So, it is possible to copy the animations using the above approach (copying time sensor, interpolators, setting up routes), but:

  1. Admittedly it’s a bit difficult. You will need to understand many details about how X3D nodes are being used to animate. It’s not really something I recommend regular engine users to do :slight_smile:

    Practically speaking, it is easier to just copy animations at your model creation (e.g. in Blender) and have the same animation just exported to every 3D model.

  2. It doesn’t really give you an advantage in terms of memory consumption. The copies of animations are copies, then consume memory. For now, we have to work like this, as each scene must have separate nodes. In the future, maybe it will be possible to reuse nodes more (see roadmap: Allow animating selected node graph properties, without changing the graph, to be able to reuse graphs) and the skinned animation should definitely consume less memory in general (see roadmap: Efficient skinned animation on GPU (from glTF and more) using new SkinnedAnimation node).

  3. Also, it should not change if/how you can use animation transitions. If you can submit a testcase to illustrate the issue when you can / cannot use animation transitions, it would be helpful.

All in all, what you ask for is possible, but difficult and doesn’t address some problems you mention, at least as far as I understand it. Sorry for that, but it’s the honest answer, for now. There are a few things in the engine we could do better in this regard, including giving you easy API to transfer animations, but it’s not ready yet.

1 Like

hello

I don’t mean issue :slight_smile: . The method just doesn’t allow the use of animation transitions Because each gltf file contains only one animation.
With this method (I don’t know if it’s correct), if there are a large number of players (scene) with multiple animations, I have low memory consumption. Conversely, if I use a single gltf file containing all the animations and each player downloads this file, it will consume a lot of memory.

example of a method i think is useful in terms of memory consumption.