And now When pigs swim

Starting on getting my animals to do stuff, since my default pig location was starting underwater I started with swimming. Now it will swim up when under water level and then swim at 1/3 its walking speed until it reaches a shallow enough area to move normally.
It uses a walking animation for swimming. Simple LOD on pig drops it to 3 billboard faces when you get far enough away and frees all graphics when even farther. This lowpoly pig really takes a lot of memory. It only has 4 animations and they are almost all the same with different speed. I don’t know what can be done about that. It seems like one pig is more than all the clouds combined. This pig was part of a free lowpoly farm animal pack, so it should be ok to share here. Pig.glb (496.7 KB)

2 Likes

As for pig eating memory:

  • Our memory consumption of skinned mesh animations in CGE is indeed unoptimal. There are 2 roadmap items that will address this:

    1. Making skinned animation on GPU, without the need for extra memory/preprocessing at load: Roadmap | Manual | Castle Game Engine .
    2. Allowing to reuse an animated graph, with different animated poses at each instance, easily and efficiently. This is part of Roadmap | Manual | Castle Game Engine . For now , while you can reuse graphs ( Writing code to modify scenes and transformations | Manual | Castle Game Engine ) but it’s not a good solution when all instances need to be in different animation state.

    Both of those will decrease memory consumption of animated glTF models.

    There are no easy workarounds to this unfortunately for now. Except just having less and shorter animations, when you need to instantiate something a lot of times (like a lot of animals).

  • Your pig has 6 animations, and eats 16 MB memory when loaded. That’s usually not much. But I understand it matters for your case, since you want to have thousands of them.

1 Like

It seems like it takes more memory. But for the one I load the template and then clone it so maybe I really have two. Are you just using Task Manager or linux equivalent to determine memory usage? Is all the weight coming from the animation data?

For my low detail pig without the model, I use 3 faces mapped to pictures of the pig. Here is side.
PigLeft
I made these by hand in photoshop which was slow. Is there any easy way to quickly get side, top, front, rear images of a model to do this automatically?

Indeed, the “template” itself also takes memory.

Yes, for the above test – I just used htop ( https://htop.dev/ , a fancy terminal program on Linux that just exposes OS memory usage information). I looked at memory usage of castle-model-viewer (our new name for view3dscene) before and after loading the pig, and I subtracted the difference.

This tells me how much memory the FPC actually allocated from the OS for the purpose of loading everything necessary for the pig model. It may be more than necessary actually (FPC may allocate more memory to have a pool of memory for future use). Also it assumes that the “empty” model is effectively zero memory (it is almost zero, but not literally zero). So, there are some assumptions, but overall this method of measuring makes sure I’m not cheating or forgetting something :slight_smile:


Just tested to be sure – yes.

To be clear, so that you can test it too:

Sure, in Blender or in Castle Game Engine you can automate this. Just setup 3 cameras for making these 3 shots. You can render using Container.SaveScreen.

Or, to have more control, you can use CreateSpriteTexture approach from examples/viewport_and_scenes/render_3d_to_texture_and_use_as_quad/ example. You can even render with transparent background if you wish, see e.g. how castle-model-viewer does it: castle-model-viewer/castle_model_viewer.dpr at master · castle-engine/castle-model-viewer · GitHub .