Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add model[] formspec element #10320

Merged
merged 6 commits into from
Nov 4, 2020
Merged

Conversation

SmallJoker
Copy link
Member

Copypasta from #10261 because I see potential in this feature.

To do

This PR is Ready for Review.

How to test

  1. Devtest world
  2. /test_formspec

@SmallJoker SmallJoker added @ Script API Feature ✨ PRs that add or enhance a feature labels Aug 24, 2020
@Andrey2470T
Copy link
Contributor

XD. I have just created the same PR, too.

Jean-Patrick Guerrero and others added 3 commits August 24, 2020 15:06
Includes minor code style changes.
1) Get rid of static 'rotation_bound'
2) Shorten and tweak the documentation a bit
3) Rename to "model[]"
4) Correct devtest, add license
src/gui/guiFormSpecMenu.cpp Outdated Show resolved Hide resolved
doc/lua_api.txt Outdated Show resolved Hide resolved
src/gui/guiScene.h Outdated Show resolved Hide resolved
src/gui/guiScene.cpp Outdated Show resolved Hide resolved
@SmallJoker
Copy link
Member Author

PS: Ready for re-review.

Copy link
Contributor

@pyrollo pyrollo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start with current formspec version and clearly sufficient to see how it will be used in mods.

I see a lot of future possibilities. But having a JSON or table formspec parser would be much better to handle multiple needed options:

  • x, y and z initial rotation;
  • x, y and z rotation speed;
  • x, y and z rotation limitations;
  • frame or sequence picking (use still character model, or show only the walk...);
  • mouse events, drag and drop...

src/gui/guiFormSpecMenu.cpp Outdated Show resolved Hide resolved
if (vec_rot.size() >= 2)
e->setRotation(v2f(stof(vec_rot[0]), stof(vec_rot[1])));

e->enableContinuousRotation(inf_rotation);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be great to be able to control rotation speed around three axes. Anyway, I thinks it's good for now and that could be implemented later with future table or JSON formspec parser.

m_last_time = new_time;

core::rect<s32> oldViewPort = m_driver->getViewPort();
m_driver->setViewPort(getAbsoluteClippingRect());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes some unintended size reduction of the model if element clipped. It could be weird in scrollable containers.
Scene should be drawn in a view port sized as AbsoluteRect and clipped to getAbsoluteClippingRect(), a bit like in drawItemStack.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please update the code according to your plans? I don't know what to do there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit more complicated than I thought. I'm having a look.

@rubenwardy
Copy link
Member

But having a JSON or table formspec parser would be much better to handle multiple needed options:

Could use properties for this, ie: key-value like used by style[]

@pyrollo
Copy link
Contributor

pyrollo commented Aug 31, 2020

style[] is going to be the next language for Minetest GUI development :)

@rubenwardy
Copy link
Member

Soon it'll be turing complete

@Andrey2470T
Copy link
Contributor

Hmm, is it already commit-finished and therefore ready for merging?

@Andrey2470T
Copy link
Contributor

Please, don't leave and merge it if it is ready for now. I'm so eager to see this feature already in the game engine.

Copy link
Member

@v-rob v-rob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having a weird issue (on Windows) where, when using the devtest formspec, the game will segfault if both models are present at the same time, but only when this was the first world to be entered after opening the Minetest window. If one model is removed, it works fine, and if the other model is added back in without closing the Minetest window after using the one model, no segfault occurs. It's very strange.

I'm no expert on the model stuff, but it looks OK. If this segfault issue (whatever it is) and pyrollo's model reduction issue are addressed, then 👍.

src/gui/guiScene.cpp Outdated Show resolved Hide resolved
src/gui/guiScene.cpp Outdated Show resolved Hide resolved
@kilbith
Copy link
Contributor

kilbith commented Oct 6, 2020

the game will segfault if both models are present at the same time

Cannot reproduce (with my previous PR code).

pyrollo's model reduction issue

Offset-ing the mesh when the element is clipped is easy but the camera position is necessarily centered inside the element bounds (thus the model must also be centered to have consistent rotation). I see 2 solutions:

  • Leave it as is. I don't see the point to let the possibility to show a cut-off view of the model while having full camera control.
  • Overriding the behavior of updateAbsolutePosition called in setNotClipped

@v-rob
Copy link
Member

v-rob commented Oct 6, 2020

Leave it as is. I don't see the point to let the possibility to show a cut-off view of the model while having full camera control.

Unfortunately, not really an option. The current behaviour would be weird with scroll_container because the model would move around when scrolling. Perhaps temporarily setting the rect to the not clipped size each frame, setting the camera position, and then resetting the rect before drawing would work, but I really don't know how the 3D code actually works.

Cannot reproduce (with my previous PR code).

With this current PR, I have had the problem on both Windows and Linux. So, it's probably newly introduced.

@SmallJoker
Copy link
Member Author

With this current PR, I have had the problem on both Windows and Linux. So, it's probably newly introduced.

Could you please provide a gdb/windbg backtrace? I didn't experience any segfault with this branch.

src/gui/guiFormSpecMenu.cpp Outdated Show resolved Hide resolved
@SmallJoker
Copy link
Member Author

Thanks for the review. I updated and retested the PR accordingly.

@v-rob
Copy link
Member

v-rob commented Oct 11, 2020

OK, it has my approval if @pyrollo's issue can be addressed. If it actually is impossible to fix (that seems unlikely, but I'm no expert), then I'll still approve.

@v-rob
Copy link
Member

v-rob commented Nov 4, 2020

I'm just going to say that waiting for a solution to the clipping problem really isn't too important. It may look funny in scroll containers for now, but I think the benefits outweigh the problem. So, 👍

@SmallJoker SmallJoker merged commit 3356da0 into minetest:master Nov 4, 2020
@ghost
Copy link

ghost commented Nov 7, 2020

I check it. Some problems:

  • The "3d_armor_character.b3d" of the 3d_armor mod is blank textured. I think because of transparencies = not set the textures as a table.
  • A chance to set the loop frames range for entities, so set the pose animation?

@kilbith
Copy link
Contributor

kilbith commented Nov 7, 2020

That's because you're a bad modder.

model[0.5,6;4,4;m1;3d_armor_character.b3d;testformspec_character.png,3d_armor_trans.png^3d_armor_helmet_diamond.png^3d_armor_chestplate_diamond.png^3d_armor_boots_diamond.png^3d_armor_leggings_diamond.png,default_chest_front.png]

Capture d’écran de 2020-11-07 14-04-21

kthxbye.

@ghost
Copy link

ghost commented Nov 8, 2020

That's because you're a bad modder.

model[0.5,6;4,4;m1;3d_armor_character.b3d;testformspec_character.png,3d_armor_trans.png^3d_armor_helmet_diamond.png^3d_armor_chestplate_diamond.png^3d_armor_boots_diamond.png^3d_armor_leggings_diamond.png,default_chest_front.png]

Capture d’écran de 2020-11-07 14-04-21

kthxbye.

stop fooling around and fix the animations.

Thankz.

@SmallJoker
Copy link
Member Author

@runsy Please open a new bug report for the transparency issue and a new feature request for the frame range thing.

@ghost
Copy link

ghost commented Nov 8, 2020

@runsy Please open a new bug report for the transparency issue and a new feature request for the frame range thing.
The transparency thing was not an issue.

I did it:
#10615
#10614

HybridDog pushed a commit to HybridDog/minetest that referenced this pull request Dec 17, 2020
Formspec element to display models, written by @kilbith, rebased and tweaked.

Co-authored-by: Jean-Patrick Guerrero <[email protected]>
Co-authored-by: sfan5 <[email protected]>
@SmallJoker SmallJoker deleted the guiscene2 branch June 4, 2022 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants