Assembling 3d model programmatically in unity

How to assemble 3d models( individual 3d components) in unity or any game engine, programmatically, with out structural positions.
Ganga Raju SuruAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan Violet SagmillerCIS/Game Development AdvisorCommented:
I had done similar, with a terrain engine in Unity.  I had created a noise engine to produce different numbers for heights at various positions.  Then I passed in an array of vertice positions based on that.  Attach a MeshFilter, and meshRenderer.  And then in code, you can reset the mesh vertices.

Something like

  // insert function to generate an array of Vector3 positions for your model
  var verts = GenerateMeshVertices(); 
  
  // apply the vertices
  GetComponent<MeshFilter>().mesh.vertices = verts;

Open in new window


In my code I had a 2D array of 100x100 positions, each 1 meter apart on x/y, and then a noise engine set the height.  that's pretty easy.  

I.e.
  // insert function to generate an array of Vector3 positions for your model
  Vector3[] GenerateMeshVertices()
  {
     var verts = new Vector3[100,100];
     for (int x; x < 100; x++)
     {
       for (int z; z < 100; z++)
       {
         var y = Random.Value;
         verts[x, z] = new Vector3(x,y,z);
       }
     }
     return verts;
  }

Open in new window


please note, this is pseudo code I just sketched here, so it may not compile.  But it might as well.  (hopefully I didn't forget anything :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Computer Games

From novice to tech pro — start learning today.