Search Unity

vector3 list to image

Discussion in 'Scripting' started by elpuerco63, Nov 13, 2017.

  1. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    271
    I have a list of vector3 positions that my player creates as it walks through a scene and want to translate them into a image, png, jpeg etc.

    Is this possible in Unity? struggling to find a way to do this..
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,539
    In what manner do the Vector3s translate to a grid of colour'd pixels???
     
  3. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    271
    Mm maybe I should expand, sorry!

    Currently at the player moves I draw a trail renderer which shows where the player has walked. I want to record that route as an image. I used the trail renderer to confirm I was recording the path of the player so I save the vectors objects in a list. Now I want to draw that path on "something" and export it via code to a png etc
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,539
    OK...

    You can generate images in code. This is a completely doable thing.

    Using a Texture2d class you can create and set the pixels of a texture:
    https://docs.unity3d.com/550/Documentation/ScriptReference/Texture2D.html

    Then once done you can convert it to a png with EncodeToPNG:
    https://docs.unity3d.com/550/Documentation/ScriptReference/Texture2D.EncodeToPNG.html

    And then with the System.IO namespace, you can save that byte array to disk, as a png file.

    ...

    As for what to actually draw on said texture. You need to decide what that is. Is it something like where you have an image of your map in birdseye view and you want to map these Vector3's to their relative positions within said birdseye view map? Or some other weird variation of it.

    This choice is critical in the actual projection of your 3d vector positions into 2d plotting. There's all sorts of ways you may want to visualize this information... think of one up, then consider in what manner would you take said data and convert it. Where you get hung up, come back and ask specifics.
     
    elpuerco63 likes this.
  5. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    271

    Thanks :)

    It will basically use the x and z positions so when you view the resultant image it will be a square white image with a black line that depicts the route taken
     
  6. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    271
  7. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    271
    So have made progress today, but it is less than perfect but can't figure why unless it is down to set pixels using int rather than float?

    I attach the path as seen as a trail renderer in the editor and what I get when I use the vector positions to create a jpg file, see how jagged the path is?

    Any ideas how to smooth the line to look like the trail renderer? Is it possible to save the trail as it appear out to an image?



     
    Last edited: Nov 13, 2017