Search Unity

Creating a mesh by texture

Discussion in 'General Graphics' started by serzoro, Mar 24, 2021.

?

Creating a mesh by texture

  1. Creating a grid by pixels

    0 vote(s)
    0.0%
  2. Creating a mesh by pixels

    0 vote(s)
    0.0%
  1. serzoro

    serzoro

    Joined:
    Sep 14, 2018
    Posts:
    3
    Hello. Please help me! I can't find any information on this topic anywhere. How to create a mesh by texture (by pixels). I have been in unity not so long ago, I still have a bad understanding.
     

    Attached Files:

    • 1.png
      1.png
      File size:
      17.8 KB
      Views:
      293
    • 2.PNG
      2.PNG
      File size:
      228.5 KB
      Views:
      293
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The usual answer is ... you don't do this. Usually if anything you're going the other way. Creating a mesh from a texture is an expensive and error prone operation.

    If you have a texture and you want a mesh to look like that shape, you use a mesh quad and an alpha test shader to hide the parts of the quad mesh that you don't want to see.

    Alternatively, depending on what you're trying to do, Unity's Sprite tools will automatically generate some form of tight bounds mesh for a texture with alpha. Or there are external tools that do an even better job at this as Unity's built in tool tends to be fairly loose in its bounds.
    https://github.com/sr4dev/Unity-SpriteAssist
     
    serzoro and Seromu like this.
  3. serzoro

    serzoro

    Joined:
    Sep 14, 2018
    Posts:
    3
    Thank you for advice. I used Unity-SpriteAssist. But it only works in the editor. I reworked it to make it work in real time. but there is an error when compiling the project, here is the code:
     

    Attached Files: