Advertisement
epitaque_

Unity mesh uploading

Mar 23rd, 2018
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. GameObject clone = UnityObjectPool.GetObject();
  2. Color c = UtilFuncs.SinColor(chunk.LOD * 3f);
  3. clone.GetComponent<MeshRenderer>().material.color = new Color(c.r, c.g, c.b, 0.9f);
  4. clone.GetComponent<MeshRenderer>().material.SetInt("_LOD", chunk.LOD);
  5. clone.GetComponent<MeshRenderer>().material.SetVector("_ChunkPosition", new Vector4(chunk.Position.x, chunk.Position.y, chunk.Position.z));
  6.  
  7. clone.name = "Node " + chunk.Key + ", LOD " + chunk.LOD;
  8.  
  9. MeshFilter mf = clone.GetComponent<MeshFilter>();
  10. mf.mesh.SetVertices(chunk.Vertices);
  11. mf.mesh.SetNormals(chunk.Normals);
  12. mf.mesh.SetUVs(0, chunk.LOD1Vertices);
  13. mf.mesh.SetUVs(1, chunk.LOD1Normals);
  14. mf.mesh.triangles = chunk.Triangles;
  15.  
  16. clone.GetComponent<Transform>().SetParent(Parent);
  17. clone.GetComponent<Transform>().SetPositionAndRotation(chunk.Position, Quaternion.identity);
  18. clone.GetComponent<Transform>().localScale = Vector3.one * ((float)MinimumChunkSize / (float)Resolution) * Mathf.Pow(2, chunk.LOD);
  19. chunk.State = ChunkState.Completed;
  20. chunk.UnityObject = clone;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement