- Home /
Is it possible to render a mesh from code?
I am currently looking to render a bunch of meshes without having to instantiate several game objects for them. Is it possible to render a mesh from code, supplying material and transform matrix to it? I don't have PRO, so the GL functions are out of the question.
I spent some time in the docs but I was unable to find anything while searching. Apparently my google skills are lacking today as well.
What I'd love is some method like:
UnknownClass.Render(mesh, material, worldmatrix);
Answer by FlyingOstriche · Oct 21, 2012 at 11:32 AM
Another way you can do it. (works in Indie)
you need to have a MeshFilter and MeshRenderer on object. << docs don't mention MeshRenderer.
Then set MeshFilter.mesh to the mesh.
I did it that way and it works. You just have to worry about giving vertex proper coordinates and then setting triangles, normals (if you need them), UV coordinates (if you need them)... It's kind of a shity work...
private Vector3[] newVertices;
private int[] newTriangles;
private $$anonymous$$esh my$$anonymous$$esh; //add this to the game object
private $$anonymous$$eshFilter my$$anonymous$$eshFilter; //add this to the game object
void Start {
my$$anonymous$$esh = new $$anonymous$$esh();
my$$anonymous$$eshFilter = ($$anonymous$$eshFilter) gameObject.GetComponent("$$anonymous$$eshFilter");
my$$anonymous$$eshFilter.mesh = my$$anonymous$$esh;
InitializeVertices(); //Do something with the vertex
my$$anonymous$$esh.vertices = newVertices;
InitializeTriangulation(); //Set the triangles index
my$$anonymous$$esh.triangles = newTriangles;
}
boring as hell...
This is probably the best way. If the docs say Graphics is pro-only it's probably a bug that it works in indie, so might not work in future versions. It a bitch to do this though :P
It seems the document doesn't say "pro only" anymore?
Your answer
Follow this Question
Related Questions
Vertex Colours flickering blue 0 Answers
Rendering with cubes/planes/matrices 2 Answers
Problem in rendering meshes 2 Answers
Better model? Use Mesh clipping or add more vertices? 0 Answers
Script rendering Mesh to Image with transparent background 1 Answer