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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Geometric Shape Recognition

Discussion in 'Scripting' started by v_chs_2, Dec 11, 2019.

  1. v_chs_2

    v_chs_2

    Joined:
    Nov 24, 2019
    Posts:
    12
    Is there any way to recognize geometric shapes in Unity? I suppose there is some properties of the object that can lead you to detect it's geometric shape with a script.
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    Geometric shapes are defined as a set of positions in space conformig to a rule usually expressed by math function. In unity geometric shapes defined via mesh class. You can check all vertices in mesh to conform that rule or not and see if that's the shape you want or not.
     
    v_chs_2 likes this.
  3. v_chs_2

    v_chs_2

    Joined:
    Nov 24, 2019
    Posts:
    12
    Thanks for the reply. I try to create a script to dynamically detect objects' geometric shapes. As i understood from your reply, i should create a script that takes as input the vertices an object and generate tha data of it's shape, that will give us the necessary information for recognizing it.
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,022
    do you have images of example shapes that you want to detect?
     
    v_chs_2 likes this.
  5. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    No. You need to take vertices of object and check if they conform an equation for that shape. You do not need to generate any data, just test existing data. Let's use simple ellipse as an example. The equation for ellispe is

    x*x / a*a + y*y / b*b = 1

    You need to check all points of the shape fits this equation.
     
    v_chs_2 likes this.
  6. v_chs_2

    v_chs_2

    Joined:
    Nov 24, 2019
    Posts:
    12
    The think is that the script should detect & recognize any object. Not a particular one. The script should be used in any scene and detect dyanamically any possible object.
     
  7. v_chs_2

    v_chs_2

    Joined:
    Nov 24, 2019
    Posts:
    12
    So with this approach, i could detect dynamically any kind of object (not only basic shapes, but more complex) that appears on the scene? Even if i the script has not been written for this particular scene (possibly a managed plugin)?

    Thanks for the replies :)
     
  8. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,022
    v_chs_2 likes this.
  9. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    Yep. Be careful though and do not forget about discrete nature of those shapes.
    For instance, ellipse approximated with 4 points is rectangle in computer graphics. You might have seen rectangular pipes in Half-Life 1. You need to define some kind of accuracy for shapes representation.
    Also It may turs out what some vertices do fit your equations for like a 0,001 so you should define some accuracy for comparsions when calculating functions.
     
    v_chs_2 likes this.
  10. v_chs_2

    v_chs_2

    Joined:
    Nov 24, 2019
    Posts:
    12
  11. v_chs_2

    v_chs_2

    Joined:
    Nov 24, 2019
    Posts:
    12
    Ok, i' ll try to implement this approach. Thanks a lot for all your replies. Amazing community :)
     
  12. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,022
    v_chs_2 likes this.
  13. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    Using AI to detect simple geometric shapes looks somewhat like overengineering, its more about detecting real life objects from textures that shapes from meshes.
     
    v_chs_2 likes this.
  14. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,022
    yeah, just suggesting alternatives, since its not clear whats the purpose here is (and where the objects come from etc)
     
    v_chs_2 likes this.
  15. v_chs_2

    v_chs_2

    Joined:
    Nov 24, 2019
    Posts:
    12
    I agree. It could be a solution using AI/ML, but i think it could be a simpler solution for somehting like this.
     
  16. v_chs_2

    v_chs_2

    Joined:
    Nov 24, 2019
    Posts:
    12
    The think here is that a fire should detect/recognize objects and spread according to the objects which getting in touch. So, i need to find a way recognize the geometry of every object, a scene could possible have.
     
  17. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,022
    ok if its for a game, and just for fire spreading.. then forget those AI stuff.

    Since its your scene, you should already know what objects are spawned/placed into level?

    those objects can already contain information about what material (or shape) they are, how well they burn etc.
    (can have data in attached script, or tagging objects, or saving data into mesh vertex colors/attributes, or having special burn_mask texture that it reads etc.)

    see also,
    https://forum.unity.com/threads/dynamic-fire-system-realistic-fire.138006/
    https://assetstore.unity.com/packages/tools/fire-propagation-92187
     
    Last edited: Dec 11, 2019
    v_chs_2 likes this.
  18. v_chs_2

    v_chs_2

    Joined:
    Nov 24, 2019
    Posts:
    12
    It’s not my scene. It should adapt in any scene. I 've already checked the fire propagation asset, but i think it has some issues with the new unity terrain. Although, it’s algorithms may be helpful.
     
  19. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,022
    so it could be used as a plugin that people might use anywhere, or could be used in moddable games with user generated content?

    just trying to get the idea how it will be used.. i mean normally people would know whats in their scenes,
    so they can tag objects or do other preprocessing to make object burning properties to work.

    what do you actually want to recognize from the object?
    i mean, you could have a 3d metal chair and 3d wooden chair (painted with wood color),
    where the mesh is pretty much same shape, but burning properties are different.. so thats why i'm suggesting some meta data in objects..

    sorry, more questions than answers :)
    (but its interesting topic, i need to implement free fire in one game later also)
     
    v_chs_2 likes this.
  20. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,745
    To spread a fire over unknown scene, I would bet on materials and polygons. I would require my users to configure list of burnable materials, their burning speed temperature and fire resistance. I would set mesh as particle emitter and add triangles to that mesh from neighbor objects when they start burning. I would give 1 burn point to every object touched by fire particle and start burning that object from most often touched triangle when the object got enough burning points based on material or materials used for that object.
     
    v_chs_2 likes this.
  21. v_chs_2

    v_chs_2

    Joined:
    Nov 24, 2019
    Posts:
    12
    I need to detect the geometric shapes for now. The objects will have some properties that will affect the fire propagation like density, humidity etc. But the first thing that bothers me right now, is how to detect the geometric shape dynamically.

    You got it. It should be used as a plugin in any scene. It's not totally formatted as an idea, but i work on it.

    No worries for the question, you 're helping me anyway, even if you ask. :)
     
  22. v_chs_2

    v_chs_2

    Joined:
    Nov 24, 2019
    Posts:
    12
    Seems like the right approach. I 'll stick to the mesh properties. I suppose it's easy to generate them; the same way you get the posiition or scale of all objects of a scene.
     
  23. deepbajaj

    deepbajaj

    Joined:
    Feb 27, 2018
    Posts:
    1
    I'm making a game in which I've some basic 12 shapes like circle, triangle, rectangle and square and I've four bags and I've to drop each in the right one how do I identify in which bag shape should go so that it could be a correct answer and in which should not so that it can give us a wrong answer signal please help me to solve it.