- Home /
The question is answered, right answer was accepted
Tris and UVS mapping for mesh generation.
hi, I've been generating meshes via Mesh class. Regular planes are simple, since there geometer is a big loop with a single cut. but for more complex planes such as this im unsure how one would map the triangles or UVs.
reading this doc(http://docs.unity3d.com/Documentation/Manual/UsingtheMeshClass.html) tells me that the vertices follow a "clock-wise" rule, which is easy to implement on a 4 vert plane. but a 4 vert with an inset? there can anyone explain how one would work out which vert is which? assuming the lower left most is 0?
here is the mesh im trying to generate:
trial and error seems to be getting me nowhere as hopelessly deformed meshes pop up in front of my screen. why is this overlooked in the docs, it has regular one 4 vert plane and nothing else...All I know is that the triangles need to be a 30 sized array, with number ranging from 0-7.
the vertices themselves are there, after trial an error of seen the deformed geometry wap itself.
I don't understand how the UV's work either, with regular planes the vector values are 1 or 0. are they based on ratios between vertices? I don't even know where to start with these guys.
if it helps here is a snippet of plane-gen code
mesh.vertices = new Vector3[] {
Manager.GUI.ScreenToWorldPoint(new Vector3(0f,0f,0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3(padding,padding,0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3(width,padding,0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3(width + padding,0f,0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3(width, height, 0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3(width + padding, height + padding, 0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3 (padding, height,0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3 (0f, height + padding,0f)),
};
mesh.triangles = new int[] {
0, 5, 6,
0, 6, 2,
0, 4, 1,
0 ,4, 3,
0 ,3, 4,
7, 5, 2,
3, 4, 5,
5, 3, 2,
6, 0, 2,
3, 4, 1
};
mesh.uv = new Vector2[] {
new Vector2(0,0), new Vector2(1,0),
new Vector2(1,1), new Vector2(0,1),
new Vector2(0,0), new Vector2(1,0),
new Vector2(1,1), new Vector2(1,1)
};
mesh.RecalculateNormals();
I just punched random numbers for the triangles and UVs as you can tell. thanks in advance
Answer by Loius · May 09, 2013 at 10:26 PM
(Your padding isn't actual padding; it should be multiplied by two when finding the far right/bottom sides because there are two pads + widht/height to get to those; that may be throwing you off)
This is all standard 3D stuff, not unity-specific; that's why it's not detailed in the manual (I assume)
I see this pattern in your vertices:
7 5
64
12
0 3
You need to build all the triangles, and they all need to be wound the same way - CW triangles would be:
7,5,6,
6,5,4,
4,5,3,
2,4,3,
0,2,3,
0,1,2,
0,7,6,
0,6,1,
1,6,4,
1,4,2
UV is a ratio of what part of the image should show at the vertex. If you want the whole image to cover that set of triangles, then uv for the four corners is:
0,0,
.
.
1,0,
.
1,1,
.
0,1
The UV for the inner points is just some maths; point 6 would be (p/(p*2+w), (p+w)/(p*2+h))
thanks... I don't usually work with 3d stuff such as meshes like this, i usually build things like game play code. sorry if this was a long but annoying for you.
I tried looking this up with google but it kept co$$anonymous$$g up with the $$anonymous$$esh class itself any suggestions with fnding information like this?
thanks again...
As Loius said, none of this is Unity-specific, so when searching don't include "Unity".
thanks, I just thought that Unity handled them specifically this way... question closed
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
problem with MirrorReflection 1 Answer
Would like to hear the best way to make houses with interiors 0 Answers
Easy way to convert a bunch of vertices to triangles or uv's? 1 Answer
MMD How to export model and animations to Unity as 3rd person controller? 2 Answers