0
$\begingroup$

Ok as the title says I am having some mega speed issues when unwrapping with smart project in python, like on a smaller project it took 30mins to unwrap inside the editor and when executed via the script took over 2 hours to do, with the unwrap parameters set to the same as in the UI, so am I missing something or made a really dumb mistake? Anyway, here is the script for my unwrapping:

def uv_map_create():
    """Create a UV Map for duplicate_obj using the smart_project method"""
    # start uv timer
    uv_time_start = time.time()

    # get current context mode
    current_context_mode = bpy.context.active_object.mode

    # switch to edit if not already
    if (current_context_mode != 'EDIT'):
        # set context mode to edit
        bpy.ops.object.mode_set(mode='EDIT')

    # log start
    print('\ncreating uv')

    bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
    bpy.ops.mesh.select_all(action='SELECT')
    bpy.ops.uv.smart_project(angle_limit=radians(big_angle), margin_method='SCALED', island_margin=0.0001, area_weight=0.0, correct_aspect=True, scale_to_bounds=False)
    bpy.ops.object.editmode_toggle()

    # switch to back to previous mode if not in edit
    if (current_context_mode != 'EDIT'):
        # back to whatever mode we were in
        bpy.ops.object.mode_set(mode=current_context_mode)

    # output uv timer
    print("\nIt Took uv_map_create:", time.strftime(
        "%H hours, %M minutes and %S seconds to Complete", time.gmtime(time.time()-uv_time_start)))

Ideally, I would love to implement this with BMesh as 90% of my script has been using BMesh, but I cannot find any documentation or questions with answers that help me here

Also this mesh has basically been converted to a max of 10 degrees by creating seams and planar dissolving and making faces planar etc.

On a quick side note I have left materials on this mesh as I will be using it to split the mesh with that so I can do a diffuse bake due to the size of the model requiring the need to split it.

Is this method of keeping the material unwrap split bake and rejoin a bad way to go and if so any suggestions on it would be helpful? I am considering doing the split then unwrap in the UI at this rate, but as I come from a software background, this seems really unintuitive to me and feel really defeated if I have to follow that route

Feeling a bit defeated here, so please try and not troll me too much (Modeling is not my field and had to mega crash course on it for my IT internship)

This is just a small snippet of the model I am working on, to put it in perspective this is an old low poly model I created from high poly data but won't be used in this project due to limitations I found. And some quick stats the new model of the high poly is 19,284,778 Vertices, 32,423,852 Edges and 15,929,753 Faces while the rest of my script has converted this number to 5,340,148 Vertices, 13,763,344 Edges and 8,334,206 Faces

Small low poly section of the model

$\endgroup$
7
  • $\begingroup$ Also is better to do the smart project with the mesh as triangles or quads? Ultimately the model will be triangulated at the end for exporting to Unreal due to engine requirements.. $\endgroup$ May 12, 2023 at 2:26
  • $\begingroup$ 8 million polygons (16M tris ?) is still a humongous amount of data for the unwrapper to crunch through. Usually the meshes are ten of thousands or maximum hundreds of thousands of polygons. Since you have such a high density of polygons, I suggest you use vertex color data which is supported by other softs. Btw 30 min to 2 hours is not 100 fold, it's 4 times as much :) Still a lot, but not as much. $\endgroup$
    – Gorgious
    May 12, 2023 at 6:48
  • $\begingroup$ You are right its 4 times was just trying to exaggerate a point of it taking much longer in script than in the editor as it seems very backwards at the different performance times like this seem ridiculous. Also, after the polys are triangulated into tris etc. it worked out at like 12mil, and i know this is a lot but as this is going into UE5 and nanite with appropriate hardware the count isn't really an issue. And when I do everything else, like getting it to this number in my script we are talking minutes like the last test to this point took 20mins. $\endgroup$ May 12, 2023 at 7:08
  • $\begingroup$ Well Nanite did solve crunching data for large meshes in Unreal, but not in other softwares. So I guess you still need to be cognizant of the workload you're asking Blender to go through. I guess your question is twofold : Why does it take so much time (and how can you speed it up), and why does using python take longer than using the interface. Is that correct ? Btw on thise site each thread should only really ask one question, which one is more important to you ? $\endgroup$
    – Gorgious
    May 12, 2023 at 7:29
  • $\begingroup$ Ultimately the script performance vs the editor, I will post the other questions in another thread. So why is it taking a lot longer in the script ultimately and logically the script should run faster? And if this a bug with my code or how I am implementing it vs how the UI implements this? $\endgroup$ May 12, 2023 at 7:40

2 Answers 2

0
$\begingroup$

Can look at the results of your UV unfolding

I think it was a slow time for you to spread all your UVs, because it places all the UVs in one quadrant, which requires a lot of computation

If possible, you can try to expand it into multiple models, just as your model is skewed data, you can expand it one by one according to the results after slicing, without selecting all to expand

$\endgroup$
6
  • $\begingroup$ Ok so what break it apart into say co-planer or something? And a lot of my methods create sharps to do various decimates and welds to get the mesh into a better shape, would adding seams at the various edge sharpness help? $\endgroup$ May 12, 2023 at 7:10
  • $\begingroup$ And as its been unwrapping for the last 6 hours I can show the results when I get them $\endgroup$ May 12, 2023 at 7:11
  • $\begingroup$ And a quick side note is it normal for UV unwrapping to use only 8% of a CPU, I have a Ryzen 5600g if that helps and I know the L3 caches sucks. but it seems like its in a very bad nested for loop that seems to be bottlenecking this process? $\endgroup$ May 12, 2023 at 7:14
  • $\begingroup$ Most likely single-threaded operation. You might want to try out the 3.6 beta version as it contains a sizeable overhaul of the whole UV packing algorithm. see wiki.blender.org/wiki/Reference/Release_Notes/3.6/Modeling $\endgroup$
    – Gorgious
    May 12, 2023 at 7:26
  • 1
    $\begingroup$ Ok I will look at that as side solution if its stable to build it in 3.5.1 and do the unwrap in 3.6 $\endgroup$ May 12, 2023 at 7:41
0
$\begingroup$

So after trialing Blender 3.6, I can confirm that this is a viable solution and the overhaul done by the developers is amazing!

I am able to run the same script on this mesh and unwrap it in an adequate amount of time without having to break apart the mesh is amazing and will sho the results when I get the wrap parameters right as only tested with default values and and a high angle and small margin so a lot of distortion from the bake.

But now the entire script takes less than an hour to run.

Shout out to Gorgious https://blender.stackexchange.com/users/86891/gorgious for pointing it out!

Blender Devs if you see this, well done and good job! Highly recommend people try it out if you are working with high polygon counts, this is amazing!

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .