[merge requested] Sprite enhancements

For people working on the C++ code.
Post Reply
User avatar
karamel
Member
Posts: 56
Joined: Wed Jul 19, 2017 21:51
Contact:

[merge requested] Sprite enhancements

by karamel » Post

Sprites (aka Dungeon Master style) seems to have been set aside in favor of 3D model animations. But I like the look and would like to use them again, and the code is still there, just a bit buggy and not well documented.

https://github.com/karamel59/minetest/tree/sprites

Current changelog:

Added:
  • Allow to use visual="sprite" for players (moved set_sprite to Object instead of Lua Entity only so you could set a sprite animation for a player, either self or an other one)
  • Allow to use get/set_texture_mod for players (moved to Object instead of Lua Entity only)
  • Add set_local_sprite and get_local_sprite for local animation management like it is done with set_local_animations.
  • Add some details about the spritesheet in lua_api.txt
  • Add set_sprite_framelength, sprite counterpart of set_animation_frame_speed for sprite animations
  • Add get_sprite, sprite counterpart of get_animation for sprite animations
Changes:
  • The texture of sprites and upright sprites are placed around the middle of the collision box instead of putting the center of the texture at 0,0,0
Fixes:
  • Fix the Y position of a player's sprite to display correctly (like it was done for "upright_sprite" to prevent them being displayed half in the ground) (see above)
  • Fix changing texture making the sprite visually pointing at world coordinate {0,0,0} for 1 frame
  • Fix sprite animation data not being sent when initializing an entity (when connecting to an existing game).
Roadmap before merge request
  • $>git merge master
  • Recheck
  • Write the request
Long term modification (aka wishlist but may probably never happen):
  • Add an hotpoint to sprites wich will be placed at {0,0} so you could choose if the texture is aligned with the middle of the entity, the bottom or anywhere else according to the bounding boxes (and avoid hardcoding player sprite offsets). With alignment with the collision box, a display offset could be sufficient.
  • Change select_horiz_by_yawpitch to be more flexible about the number of faces instead of 1 or 6 faces. Like setting the number of horizontal faces (4 for now, could be 8, 12, 16 etc for projects which have a full time working 2D artist).Vertical faces should be set in other spritesheets because they probably have a different frame size because of the perspective (could be 1, 3, 5, 7 etc and the top and bottom perspectives are the only one not affected by the number of vertical faces).
  • Allow to use a 2D image and "punch", "select", "unselect" animations for wielded items. 3D models could have those too.
Last edited by karamel on Tue Mar 24, 2020 19:34, edited 3 times in total.

User avatar
karamel
Member
Posts: 56
Joined: Wed Jul 19, 2017 21:51
Contact:

Re: Sprite enhancements

by karamel » Post

Things seem to work rather fine but I'm stuck with a strange behaviour that I don't understand now regarding "Fix a one-frame bug when assigning a sprite before setting the right frame instead of the first one"

The player's sprite is shown well but when moving and stopping the sprite node is set during one game frame at {x = 0, y = 0, z = 0} and recovers it's position the next game frame. This results in a visual glitch assigning the wrong sprite direction for a very short time. It also happens regularly and frequently when not in 3rd-person view but it has no visual effect.

Starting/stopping movements calls set_sprite but it doesn't seem to affect the position of m_spritenode at all. If someone is aware of something I missed that could be relevant in that case it could help me a lot. Something about visibility ?

Also a detail about consistency, "basepos" in set_sprite(basepos, frames, framelength, yawpitch) is 0-indexed while almost all Minetest values are 1-indexed. I won't change it because it would break some existing sprites and I wrote it in lua_api.txt. Maybe for Minetest 6 if it even has to be changed.

User avatar
karamel
Member
Posts: 56
Joined: Wed Jul 19, 2017 21:51
Contact:

Re: Sprite enhancements

by karamel » Post

I'm almost there.

The one-frame bug is fixed, It was just because getAbsolutePosition is not updated by Irrlicht in real time but at rendering time.

Local sprite animation is there and the "1 node in the ground" issue is fixed for everybody (not just players) by centering the texture inside the collisionbox. Even if by default the visual_size of a player is slightly larger than the collision box it appears a little bit in the ground.

I don't really know why but the "face" selection is 90° rotated for the player in 3rd person view compared to other entities. Probably because of some camera axes... But anyway is it now visually fixed.

I've done what I've planned for the first part. Which was mostly fixes and making sprites useable. There is more to come but it will require more planning and some changes in the lua api (not just additions). So it will be for later.

Now let's prepare the merge request.
You may now play freedoomtest
You may now play freedoomtest
freedoomtest.jpg (62.93 KiB) Viewed 726 times

User avatar
karamel
Member
Posts: 56
Joined: Wed Jul 19, 2017 21:51
Contact:

Re: Sprite enhancements

by karamel » Post

The branch is rebased, the merge request is here: https://github.com/minetest/minetest/pull/9544

Feature freeze is the best moment to get the review delayed :) And here is a mod that set sprites.

It sets visual= "sprite" for the players, sets a local sprite animation, defines an entity and has a few chatcommands to do some stuff:
/spawnsprite spawns a entity with a visual sprite.
/clearsprites clears the existing entities
/setupright changes the visual to upright_sprite for the players and entities
/setsprite change the visual to sprite for the players and entities
Attachments
sprite_anim_test.zip
Mod to test sprites
(43.06 KiB) Downloaded 88 times

User avatar
v-rob
Developer
Posts: 970
Joined: Thu Mar 24, 2016 03:19
GitHub: v-rob
IRC: v-rob
Location: Right behind you.

Re: [merge requested] Sprite enhancements

by v-rob » Post

I'm very glad to see sprites getting some love. I thought briefly about improving sprites, but you seem to have done many thing I wouldn't have thought of.

I would love to see a variable number of faces for select_horiz_by_yawpitch because four seems a little limiting, and most games I've seen with sprites like this use eight.

I personally don't like sprites at the moment because, not only do they follow you horizontally, but also vertically. This makes sprites look like they are tilting if you look at them from above or below. I think the best would be to make a new visual that is a cross between upright_sprite and sprite that always faces the player horizontally but stays upright vertically. I don't know if you have any plans for that, but I think it would be very nice to have.
Core Developer | My Best Mods: Bridger - Slats - Stained Glass

User avatar
karamel
Member
Posts: 56
Joined: Wed Jul 19, 2017 21:51
Contact:

Re: [merge requested] Sprite enhancements

by karamel » Post

v-rob wrote:I think the best would be to make a new visual that is a cross between upright_sprite and sprite that always faces the player horizontally but stays upright vertically.
I thought about something like that. Most old FPS worked like that (at least those I played) and it looks like a good compromise between having something visually acceptable and adding a ton of artistic work to support vertical angle(s) of view.

A flag for sprite to control the vertical tilting may be better than a new visual mode upright_sprite_but_not_really

But as for setting a variable amount of horizontal angles, I'll wait for this patches to be merged. Because they are somewhat only fixes to something that was already there, whereas the rest are new (potentially breaking) features and some discussion would be better before implementing something.

I'll think I will open a new thread to prepare a blueprint in the future. There is a lot to say on sprites…

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests