Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Uh.... what’s in a mesh?

Discussion in 'Asset Importing & Exporting' started by Piquan, Jun 4, 2021.

  1. Piquan

    Piquan

    Joined:
    May 27, 2017
    Posts:
    4
    I’m trying to work out exactly what is in a mesh, in Unity terms. Obviously, this is a core concept, but the details are a bit hard for me to work out.

    Most of my work has been in data visualization, so I tend to write in direct OpenGL. My meshes would often be just a list of vertices, and a list of triangles that referenced those vertices. If I wanted smoother lighting for better visual cues, I’d add normals to the vertices. This is pretty much what you might see in a Wavefront .obj file. If I needed to render textures on top, I’d also add UV coordinates to each vertex.

    But apparently, a Unity mesh includes a lot more. There is a reference to a material, which might have multiple textures (such as albedo, normal mapping, etc) so you’d have multiple UVs. And some meshes might have multiple materials, apparently, so I guess each poly has a material and must reference vertices with UVs that map to that material?

    And there might be… bones in the mesh? I mean, I understand bones as the main animatable property, and so you’d have each vertex indicate how strongly attached it is to each bone (the weight). But what are bones, inside the mesh? Are the bone poses initially part of the mesh (they’re a property of the Mesh object), or are they derived from the bone endpoints initially and then potentially changed by animation / physics at runtime?

    Are normals per-poly (quad or tri once it gets into Unity), or per-vertex, or what? Do you have a normal per-poly and rely on the normal map; or do you have a normal per-vertex, interpolate that, and then add the normal map?

    I haven’t yet worked out what’s in a mesh (that you’d typically import from an external modeling program), or a Mesh (as an on-disk imported Asset), or in a Mesh (as a C# UnityEngine.Mesh at runtime). Can you help me understand this essential concept?

    The bones are really what threw me, since I’m currently trying to record a Cloth sim’s animation data and then play it back with single-frame-forward and single-frame-back, and AFAICT Cloth will change a Mesh to a Skinned Mesh and add bones based on a triangulation of the vertices. But really, I’m trying to understand the concept of a Mesh well enough to use it in other problems in the future.
     
  2. arfish

    arfish

    Joined:
    Jan 28, 2017
    Posts:
    751
  3. Piquan

    Piquan

    Joined:
    May 27, 2017
    Posts:
    4
    Thanks for the link! Yes, I did look at that. Unfortunately, I wasn't clear on whether that documentation actually contains everything. For instance, there are properties for the bone weights and poses, but it's not clear to me whether bones are a part of the mesh or not. I mean, usually you have bones represented with transforms as children of the model, but the SkinnedMeshRenderer when used with Cloth makes it clear that this is not necessary. Since I realized that I hadn't previously known if bones were inherently part of a mesh, I started wondering what else I might be missing.
     
  4. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,282
    This cleared up the bones thing for me:
    "
    // this example creates a quad mesh from scratch, creates bones
    // and assigns them, and animates the bones motion to make the
    // quad animate based on a simple animation curve.
    "
    https://docs.unity3d.com/2017.4/Documentation/ScriptReference/Mesh-bindposes.html