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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Merging primitive meshes for better performance?

Discussion in 'Scripting' started by zotey, Sep 2, 2018.

  1. zotey

    zotey

    Joined:
    Nov 14, 2012
    Posts:
    26
    Hey all,

    I need to generate chemical structures. I've gotten some nice results as of now. Currently I create a primitive sphere and set the position and properties. This way its a no-go as with large molecules there will be issues due creation of alot of gameobjects wich will be batched seperatly etc...

    Are there any ideas how to go around it?
    Should I merge the meshes wonce I've created them, or rather build one big mesh right of the batt?

    Kind regards,

    Zotey
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,817
    How big are your molecules? My five-year-old macbook can render 1000 spheres easily.

    On a system with a "real" video card there should be no problem doing tens of thousands of spheres at once. If they share a material (or a few materials, one for each atom type), Unity will do pretty good batching for you. You'll run out of screen pixel resolution to tell them apart before you run out of rendering, probably.

    I recommend you proceed to solve your problem as if performance doesn't matter, but structure your code so that the visualization is entirely self-contained and can be swapped out if you need more performance. Tricks you can use include simpler spheres, LOD groups, simpler shaders, or just buying a faster video card.
     
  3. zotey

    zotey

    Joined:
    Nov 14, 2012
    Posts:
    26
    mmm, thats great to hear! I wanted to merge them as you would do in a voxel game. I did self-contain the code now. I'll go ahead as you said and see. Thank you for the answer.
     
  4. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    Unity batches dynamic and static meshes for you. There is a cost to this, but shouldnt be a problem. If it is you can use mesh baker for example to bake the meshes at runtime into a single mesh
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,000
  6. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
  7. zotey

    zotey

    Joined:
    Nov 14, 2012
    Posts:
    26
    Yes, im integrating ECS aswell as soon as I start with the simulation side of the project. Im stepping back from the merging idea, as I would need them to move seperatly later on. Thanks for the helpfull links guys.