module PNG2Polygon

About Monkey 2 Forums Monkey 2 Projects module PNG2Polygon

This topic contains 6 replies, has 5 voices, and was last updated by  Ethernaut 1 month, 1 week ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #3728

    gcmartijn
    Participant

    Reserved topic for module

    #3733

    Mark Sibly
    Keymaster

    Sounds interesting!

    #3737

    gcmartijn
    Participant

    I ‘uploaded’ the module PNG2Polygon and made a screenshot to make it easy to understand what is does. (check this image first, and then read below)

    I use it in a situation like this.
    – a number of high quality transparent PNG files that need a check for a collision and/or user mouse

    First I use a PNG2Polygon inside a editor to convert all the PNG files to the smallest simplified x and y coordinates and save them in a json file. something like this:
    circle.png : [x,y,x,y,x,y]
    star.png : [x,y,x,y]

    Then where I need the collision in game I load the coordinates (verts) once.
    And use it something like this:

    As you can see, the simplified coordinates are way less x,y points then the total png2polygon.outline points.
    So there is less CPU/GPU needed to check for a collision.

    There are situations that simplifying not work in combination with a line collision.
    For example the figure below the circle.
    In that situation the PolyCollision() can’t detect line collision, but it can detect point inside collision
    If you want a perfect line collision using that figure, then you need the full png2polygon.outline

    This script uses
    https://en.wikipedia.org/wiki/Moore_neighborhood
    https://en.wikipedia.org/wiki/Ramer%E2%80%93Douglas%E2%80%93Peucker_algorithm

    Inside the module there is a [test] directory with examples.

    Attachments:
    #3896

    gcmartijn
    Participant

    The module is now online inside Ted2.

    #3898

    Richard Betson
    Participant

    I will check this out. This seems like the kind of solution I’m looking for in constructing polygons for in game collision. Neat.

    #15399

    Hezkore
    Participant

    I totally missed this, but it’s awesome!

    Is there a way to get some sort of data I could construct 3D shapes from?
    I just want a flat “3D mesh”/surface using the simplified outline this module produces.

    #15402

    Ethernaut
    Participant

    Hezkore, would this work for you? Needs Import/Using mojo3d. The “length” parameter is how deep the extrusion is. It extrudes in both directions (positive/negative Z axis), but this can be easily changed.

    (Untested outside the project I made this for).

    I’m using it to generate 3d colliders for a “2.5D” game.

    [edit] Just realized this doesn’t generate front and back caps, only the side walls. It would need a good mesh triangulation algorithm to do that well.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.