|
When you're making a mesh from hand, (see here), how does the mesh.uv buisness work? Because if you've got an array, which you've got from generating thousands of vertices, then I'm not writing out Vector2(x,y) thousands of times! What am I meant to do? How can I split up my array, perhaps? EDIT: That wasn't very clear. What I mean is, I have this compiler error: Mesh.uv is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array. In the mesh example, you appear to have to write out the Vector2 statement as many times as there are vertics. I'm looking for a way to do this on the fly.
(comments are locked)
|
|
The Mesh class gives you 6 arrays: to specify your vertex-data. Each of those array, if they are used, have to have the same size as the vertices array. So Those 6 arrays work as one array and define your vertices. The triangles array hold indices to those arrays above to form triangles. The size must always be a multiple of 3 (since a triangle have 3 corners). I'm not quite sure what's your actual problem... Do you have trouble to fill your uvs? Noone can help you here. UVs are normally created by the artist during unwrapping. If you create all dynamically you have to know how you need them... An example to use the x,y coordinates as UVs: It doesn't make much sense in most cases to use the x,y values directly (except they are within 0..1 or you have a tiled texture) Ohh and make sure you assign your vertices array first! If you assign the UV array to your mesh before you've set the vertices array you will get an out-of-bounds error like explained in the docs...
Jun 13 '11 at 09:39 PM
Bunny83
Sorry if I'm being really n00bish today, but don't I need to iterate through the array first? Because otherwise I'll get the 'x is not a member of Vector3[]' error?
Jun 13 '11 at 09:46 PM
Muzz5
My bad! I've changed it ;)
Jun 13 '11 at 10:42 PM
Bunny83
Thanks! Upvoted.
Jun 14 '11 at 07:21 AM
Muzz5
(comments are locked)
|
|
Just use a for loop (assuming you have some kind of way of generating your uv coordinates for a given x,y,z vertex location). I just used Sin and Cos here. Nice example but Mathf.Sin/Cos takes an angle in radian not a value between 0 and 1 ;)
Jun 13 '11 at 08:58 PM
Bunny83
Ah, but a value between 0 and 1 still is a radian :) I was just trying to make some smoothly varying values for u and v.
Jun 14 '11 at 02:16 AM
hellcats
:D sure it is but doesn't make much sense :D Of course it's just a sample ;)
Jun 15 '11 at 12:43 AM
Bunny83
(comments are locked)
|

What are you talking about, "mesh.uv business"? Every case is going to be different. You generate the UVs in the cleanest way possible. The array is generally going to be procedurally generated, with you feeding it some kind of ruleset which generates the Vector2's in at least one loop. This isn't unique to UVs; this happens with any kind of substantial array.
What do you mean by "on the fly". You have to create a Vector2[] with the same size of your vertices array. Do you want to use the x ans y vertex coordinates as UVs? Just use a for loop and copy them....
I've added an example to my answer if that's what you wanted to do.