UV coordinates for Mesh primitives
Closed, ResolvedPublic


Currently UV unwrapping some primitives doesn't work nicely, the option to add meshes with generated UVs would be useful.

Primitives that could have this are sphere, cone, cube, etc.

Brecht Van Lommel (brecht) raised the priority of this task from Low to Normal.Dec 19 2013, 4:59 PM
Brecht Van Lommel (brecht) lowered the priority of this task from Normal to Low.

This would be very, very useful.
Another place where auto-generated UV's make sense is on a path/bezier with Bevel above 0. I often use this for quick pipes, and wish I wouldn't have to convert to a mesh to unwrap. Not only is it destructive, but it's actually a somewhat tedious shape to unwrap perfectly straight.


What are exactly the files to change ? From looking at the source, changes are to be made to source/blender/editors/mesh/editmesh_add.c, right ? I believe source/blender/editors/uvedit/uvedit_unwrap_ops.c should be referenced at some point too.

If someone could point me in the right direction, that'd be lovely.

The option to add such UV coordinates should be added to the operators in source/blender/editors/mesh/editmesh_add.c.
The actual implementation should be in source/blender/bmesh/operators/bmo_primitive.c.
For reference on how to add UV coordinates to a mesh, source/blender/editors/uvedit/uvedit_unwrap_ops.c can be used, though it probably wouldn't be called directly.

I tried to figure this out before the Phabricator migration but was stumped after a while.
kevindietrich, if you tackled this task, please tell me what you tried, I would like to try this again.

@Tanel Tagaväli (theblu): I don't recall exactly what I tried because I'm currently studying hard for cinema (if that makes sense), I've been for the past weeks between my home and Paris where I am right now with a slow laptop on Windows, so no programming on that one :). And that's the main reason why I placed this task up for grabs.

Anyway, IIRC at first I added a simple if statement to evey operator in source/blender/editors/mesh/editmesh_add.c that adds a UV texture to the object upon creation of it. Look at "ensure uvs". By doing so every object had some uvs but every vertex was in the same place.

Then, taking source/blender/editors/uvedit/uvedit_unwrap_ops.c as reference, I tried to add some conditions to the functions in source/blender/bmesh/operators/bmo_primitive.c to iter through the vertices of the mesh after those were generated to get the uvs. I don't remember the name of it but I think the main element was BM_MESH_ITER, something like that.

Again I didn't really had time to deeply look at it due to my studies in Paris which started beginning of February, so anyway, I hope that this time you'll get it to work :).

Would it be unreasonable to do this by default instead of adding it as an option? I've never done any work on Blender and this seems like it could be an okay place to start over the next couple weeks.

Go ahead, I can't pick this up because I'm busy right now, but I would love to see this in Blender :)

Yes please!

Although eventually, I think the option should be provided when creating a primitive, primitives should have them by default.

Well, in my first attempt and as far as I understood what the option was (an if statement saying "if there is no UVs, add some"), primitives had UVs by default. But I failed at getting descent UVs fore each primitive. So the option is not something you would see in the UI.

I'm not sure what you're saying, sorry. If you're wondering where it would be in the interface, it would be an option in the Operator Panel after primitive creation.

So I've been playing around with it for a few days and managed to get default UVs for cubes working ok (yay! though they could be better... but we'll get there =D) - I guess I'll take this now. Hopefully I can get things working reasonably well in the next couple weeks =) this is my first time doing anything open source at all (much less Blender) so we'll see how it goes 0o

Patch submitted, feel free to check it out: D481 =)

I see UVs for the Sphere primitive are really not very useful.
The idea is very good, but I think you should try to improve the UV layout to really make it useful.

You can check the differences in the following images:
Current Blender UV layout: http://a.edu.uy/blender/UVsphere_blender.png
Maya UV layout: http://a.edu.uy/blender/UVsphere_maya.png


Yep, UV not really usefull for sphere...