Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity 3D Finding Vertices Location and Re sizing Mesh

Discussion in 'AR/VR (XR) Discussion' started by mrahsan, May 6, 2015.

  1. mrahsan

    mrahsan

    Joined:
    Oct 12, 2014
    Posts:
    2
    I want to find the vertices location in a mesh and then scale the vertices of a custom mesh on run-time.

    To be precise, I have a 3d model of shirt and measurements of various body parts (like chest, belly, waist etc) as floating point numbers. Now I want to scale the mesh with these measurements.

    I have got vertices of a mesh in unity, but when i re-size them in a for loop it obviously effects all the vertices. I need different scale on different locations, I don't know how to differentiate the vertices, like to locate which vertices are for chest and which are for belly etc. Please Help.
     
  2. Cosmodrome

    Cosmodrome

    Joined:
    Aug 3, 2012
    Posts:
    6
    A possible solution is to rig the shirt model with bones, import it in Unity as Skinned Mesh, then scale the bones independently.
    Let's say you have a waist bone, a belly bone, then chest, shoulders, arms and forearms. Assuming that z-axis is the bones' main direction, to obtain a "fat guy" shirt you should just scale the belly bone on x- and y-axes. To modify the chest you'll scale the corresponding bone, and so on.

    Anyway, if you put the bones in a hiearchy you'll have to do some script work to counterscale the child bones, otherwise scaling the "belly" will also scale the "chest" and every other bone in the chain.
    Another approach could be having all the bones at the same hiearchy level so you can scale one of them without affecting the others, but in this case you'll have to use script to correct bones location when needed (for instance, scaling the shoulders requires a translation to correct the arms position).
     
  3. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    What you are asking is not a trivial task to pull off with great results. You could break your custom mesh into a grid, Then for your shirt each vertex finds the grid cell to work in does some ray triangle collision calculations on the target grid cells geometry and then is moved along the vertex normal ( or another direction vector ) in a positive or negative direction ( with some padding ). There are several ways in which the ray casting can be done. You will see these kind of options in a shrink wrap modifier in 3D software like blender. It works but not always as planned due to the complexity of the problem. Also this shrink wrapping does not try keep the shirt geometry smooth with varying padding based on the drapping nature of cloth.

    How many variations do you need to calculate at run time .. if its 5 or 10 different sizes then you can rather just model different shirts .. or use shapekey modifications which are now supported in Unity.
     
  4. ThomasCreate

    ThomasCreate

    Joined:
    Feb 23, 2015
    Posts:
    81
    Couldn't you simply define a morph target (aka blend shape) for each parameter in your modeling software?