x


Best way to generate texture coordinates?

I'm generating some meshes at runtime (actually reading from a file), which may or may not have texture coords. I assign the Transparent/Specular map to the objects. In some cases I get this on my console:

Shader wants texture coordinates, but the mesh doesn't have them UnityEditor.DockArea:OnGUI() Shader wants secondary texture coordinates, but the mesh doesn't have any UnityEditor.DockArea:OnGUI()

So, do I have to generate texture coordinates?, and secondary ones (???) Is there any facility for this in Unity, if not, any good resources on how to generate these? Thanks

more ▼

asked Jan 27 '11 at 07:32 AM

DaveA gravatar image

DaveA
26.5k 151 171 256

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

The example shown at Mesh.uv does exactly what you want. You may need to assign .uv2 too.

ps. Read more Unity Script Reference ;)

more ▼

answered Jan 27 '11 at 08:58 AM

Bunny83 gravatar image

Bunny83
45.2k 11 49 207

Just to be clear on that: Doing what they did in the example will just add UVs to your mesh but they won't fit any unwrap you might have done for those meshes. As long as you don't use textures or when it's not important that they don't fit on the triangles, you'll be fine

Jan 27 '11 at 09:06 AM Bunny83

Ah I should have been more precise (and that script reference has been my daily bible this past year or more!). I would like to generate something of a default projection, such that any given face will have one 'tile' stretched across it (any direction, but not distorted). Or even better, if all faces had the same sized tile. Like if I'm importing a building with a brick texture, that those bricks would tile across all faces where uv's are undefined. I imagine this would entail a) getting the extents (bounds) of each face, b) (optional) determine tile size, c) generate uv per vertex, (more..)

Jan 27 '11 at 09:15 AM DaveA

probably aligning to either local or world x/z plane, or first segment on the face.

Jan 27 '11 at 09:17 AM DaveA

hmm you talk about buildings with simple geometry? If your faces are always quads (2 triangles) you could calculate the uvs according to the position of the vertices on the face-plane, but when you have unorderd triangles it's getting difficult. As long as your building is aligned to the 3 axis (parallel to the axis) you could try what you've just mentioned. Kinda project the geometry onto your texture to get the uvs ;)

Jan 27 '11 at 03:27 PM Bunny83

Yeah, that's what I was thinking. Simple case of a unit cube aligned to world axes, trivial. Same cube, rotated, there must be a simple transform I could use to get those UV's. On a non-unit cube, I'd be scaling the UV's according to the size of the bounding square in the plane of the triangle. I was hoping there was some handy utility for this, but if it needs to be written, by golly, that's what I'll do (I actually did something similar years ago for an Unreal Editor exporter)

Jan 29 '11 at 07:34 PM DaveA
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2196
x1651
x1357
x151
x36

asked: Jan 27 '11 at 07:32 AM

Seen: 5024 times

Last Updated: Jan 27 '11 at 07:32 AM