Link to home
Create AccountLog in
Computer Games

Computer Games

--

Questions

--

Followers

Top Experts

Avatar of Ganga Raju Suru
Ganga Raju Suru

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.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Dan Violet Sagmiller (He/Him)Dan Violet Sagmiller (He/Him)🇺🇸

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 :)

This question needs an answer!
Looks like this question is still being worked on. Think you can help?
Create your account and start contributing!
Create Account

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Computer Games

Computer Games

--

Questions

--

Followers

Top Experts

Computer games are video games played on a personal computer, mobile device or video game console. Their defining characteristics include a lack of any centralized controlling authority, a greater degree of user control over the video-gaming hardware and software used and a generally greater capacity in input, processing, and output.