Search Unity

Creating Transforms from Texture

Discussion in 'Scripting' started by vrchewal, Oct 23, 2018.

  1. vrchewal

    vrchewal

    Joined:
    May 30, 2014
    Posts:
    18
    I have a few dozen textures with transparent backgrounds and opaque lines that connect. I'm looking for a way to create empty gameobjects at the various points where the lines in the textures connect to each other. I attached a sample image for reference. In the following star example, there would be 10 empty gameobjects created. Any help in writing the texture read code to achieve this goal is appreciated.
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    If you have the data as SVG / Vector then you can use simple line intersection to find the points, or just use the source vector points.

    If your data is raster (JPEG, PNG, etc.), you will need something like OpenCV to analyze the image and break it into lines, then study the bends in those lines to see if they are a sharp enough bend to trigger one of your spawns.

    There is a handy Asset Store bundle that wraps OpenCV for Unity and I used it for line detection back in 2015 or so, and it worked well, but it still required some clever engineering to identify lines from ad-hoc imagery.
     
  3. vrchewal

    vrchewal

    Joined:
    May 30, 2014
    Posts:
    18
    Thanks for the reply. I'll look into it.