Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Guidance on how to create a mesh

Discussion in 'Scripting' started by pertholdth, May 17, 2024.

  1. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    196
    I know next to nothing about 3D, and I would really appreciate if someone could offer some guidance

    Basically what I want to do is to create a mesh fully through code
    ( I dont want to model it in blender for example )

    How do I create a plane like this for example, and then texture it using tiles from a texture2D?

    here is an image of what im looking for
    Untitled.png I want to achieve this purely by generating it through code ( the textures abcd already exist as texture2D)

    I realize this might me an extremely trivial ground level task

    so if you could send me to some appropriate tutorials I would greatly appreciate it.

    Thanks
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,934
    It sort of is, I mean it's more elaborate than "move a character" but sure, if you search for it you'll find plenty of examples and tutorials. Start with the manual example for instance.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,371
    I have a whole repository of random versions of procgen that I call MakeGeo:

    MakeGeo is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/makegeo

    https://github.com/kurtdekker/makegeo

    https://gitlab.com/kurtdekker/makegeo

    https://sourceforge.net/p/makegeo

    There's one to make a plane.

    Be patient: making procgen geometry is trivial to do, but to do it well takes a lifetime of learning. It is very detail oriented stuff.
     
  4. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    196
    thanks for the reply friends

    I feel like I am on the right track but just to check...

    so lets say that I wanted to do what I have on my example
    I cant do 4 vertices only, because of how I need to map the UV

    so I would need to do 9 vertices? and so also uv[9]
    am I wrong though since the same UV index would be repeated and that wouldnt work for my example

    so do I just need to doubleup every vertex? so 4x4 for 16 vertices in this mesh? and uv size [16] aswell

    and do I need to have all my tiles on the same texture or is there some way to sample from multiple textures on the same material?

    THANKS
     
  5. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    4,194
    No, you would need 16 vertices if you want to specify a different UV for each of your quads. A vertex is not just a point / position. The vertex includes all the other vertex parameters like normal, uv, ... If any of those parameters should be different, even though all the other attributes are the same, you need to split the vertex into separate ones.

    Note that when you want to create a single mesh and apply 4 separate textures, you would need to use 4 submeshes and 4 materials. This would be quite inefficient. You usually would create a texture atlas with all 4 textures in one texture and use uv coordinates to map individual parts of the texture to your quads.

    I once made this WebGL example which might help you to understand how UV mapping works.
     
    pertholdth likes this.
  6. pertholdth

    pertholdth

    Joined:
    Feb 28, 2024
    Posts:
    196
    thank you for the insight

    in the event that when I scale I dont have enough space in 1 texture, what is the prescription?

    I have seen something like feeding a texture array to the material and then also adding index on the UV that points to the index of the texture array

    is that valid?