pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
923 stars 152 forks source link

UV coordinates for polygon rendering #2125

Open ScriptLineStudios opened 1 year ago

ScriptLineStudios commented 1 year ago

Proposal

The ability to specify both a surface and uv coordinates when rendering a polygon, perhaps this would be best moved into a new function:

pygame.draw.polygon_uv(surf_render: pygame.Surface, color: pygame.Color, points: Sequence[Coordinate], uvs: points: Sequence[Coordinate], surf_blit: pygame.Surface)
gresm commented 1 year ago

I want a few clarifications: What is Coordinate exactly: a Vector2 compatible object? UV coordinates terminology is rather used in context about 3d, if that's the case, I believe that functions for drawing 2d should be in separate sub-module than functions for drawing 3d. What's the intent behind surf_render and surf_blit? It isn't obvious from just their names. points: Sequence[Coordinate], uvs: points: Sequence[Coordinate] I think something went wrong when typing this...

And likely the most important question for this proposal: use-case - when and how would you imagine that it would look (some example images).

simplyrohan commented 1 year ago

@gresm, I have discussed with ScriptLine about this PR, so I will try to clarify. While the terminology and use cases can be for 3D, this function should be thought about in 2D. Pygame is a 2D library, so a function like this (which works in 2D, not 3D) should stay in the normal library. The Coordinates XY pairs. So yes, you could consider them a Vector2 compatible object. From my understanding, surf_render is the source Surface that should be mapped, and surf_blit is the destination.

For use cases other than 3D, this could be useful for generating animation, and also any automatic polygon generation. I will also attach a video (from ScriptLine). Example

tigercoding56 commented 1 year ago

is there a way i can archive this effect right now ? i need it

simplyrohan commented 1 year ago

@tigercoding56 , I wrote a triangle rasterization algorithm that performs pretty well. I also noticed your other post about needing more than 4 points. You can achieve that by doing triangulation, which is pretty simple if your shape's vertices are in order of the shape. I think a discussion on this thread may be off-topic. Are you a member of the pygame community discord server? If so I can help you there. Simply open a help post and send me a link