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. Dismiss Notice

how do you detect the overlap of two meshes

Discussion in 'Scripting' started by adogsjunkmail, May 31, 2021.

  1. adogsjunkmail

    adogsjunkmail

    Joined:
    Sep 12, 2020
    Posts:
    22
    Is there a way to check how much (in percent) of a 3D mesh is within a different 3D mesh? If not, is there a way to see if two meshes overlap at all?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Have you looked into Colliders? MeshCollider specifically?
     
  3. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,630
    Can you explain what you're trying to do? We might have suggestions.
     
  4. adogsjunkmail

    adogsjunkmail

    Joined:
    Sep 12, 2020
    Posts:
    22
    I’m trying to create a 3d grid of invisible voxels all the same size. I want these voxels to appear when enough of a mesh surrounds them. This way I can have a character model that is in the voxel art style.
     
  5. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,589
    From your explanation i'm assuming you want to do something like, have an actual character model, check which coordinates it contains (or mostly contains), then enable these voxels, in order to have a sort of voxel-representation of your actual character 3D model?

    First of all, let me say that voxel games do only appear to be made of several voxels (be it blocks or other voxel types). In reality each chunk is one single mesh with an underlying data representation, which you edit and then re-render, when a player for example destroys a part of the mesh. These games are not made up of hundreds or thousands of individual objects. So an approach where you enable or disable your voxels based on whether they are inside some mesh, is likely bound to run into performance issues - but that depends a bit on what exactly you are envisioning.
     
  6. adogsjunkmail

    adogsjunkmail

    Joined:
    Sep 12, 2020
    Posts:
    22
    Well I was only planning on using this voxel enabling for the character, so that he could be procedurally animated in a voxel format, the rest of the game would likely use a mesh for the voxels, because like you said, it would be way to costly to do otherwise. Thanks for all the good advice!