Page MenuHome

Line Art: New object loading code
ClosedPublic

Authored by YimingWu (NicksBest) on Apr 12 2022, 1:05 PM.

Details

Summary

This patch makes object loading in line art into multithread, and it gets rid of the conversion to BMesh so it's significantly faster.

Shown here are the latest object loading time (in seconds):

Diff Detail

Repository
rB Blender

Event Timeline

YimingWu (NicksBest) requested review of this revision.Apr 12 2022, 1:05 PM
YimingWu (NicksBest) created this revision.

Updated to latest master... The mempool thing seems to be introduced by the original loading code, to avoid hanging in debug.

  • Removed remove_doubles option
  • Updated edge flag to 16 bits to be consistent with the line art branch and also for the loading flags to work correctly.
YimingWu (NicksBest) edited the summary of this revision. (Show Details)Apr 12 2022, 1:57 PM

Updated to use mlooptri index as adjacent triangle lookup method. Performance is generally better than edge hash method and a lot better than current master.

Shown here are the latest object loading time (in seconds):

Remove unused function

Remove unused functions and unused variables.

YimingWu (NicksBest) edited the summary of this revision. (Show Details)Apr 26 2022, 8:17 AM

Fixed back face culling.

Use parallel task to initialize edge neighbour arrays.

source/blender/blenlib/intern/BLI_mempool.c
358 ↗(On Diff #51119)

The changes in this file shouldn't be in the patch as they were only added to allow for easy testing in debug mode.

source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
17

This data type doesn't seem to be used anywhere after the move to the sorted array list, remove.

135

Use uint16_t instead.

174

uint16_t

192

I would probably rename this to LineartAdjacentEdge.
This is because I think Item is a bit fuzzy and this can't or shouldn't really be used for anything else than looking up adjacent edge loops.

source/blender/gpencil_modifiers/intern/lineart/lineart_cpp_bridge.cpp
9

Why do you cast to int here? The variables are already integers?
Doesn't seem like there are any warnings for removing these casts on my machine either.

11

I would add a comment here to clarify that this function returns true if p1 is smaller than p2.

The cmp in the function name made me first think that this would return true if p1 == p2.
So I think it is good to clarify this.

source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
320

This seems unrelated to this patch?

341

Same as above.

1505

I think moving this struct and the add_loose_edge function to be just above lineart_identify_loose_edges would be better.
This is so they are somewhat close together and they are then also nicely grouped together.

1512

You should split this method into two.

Now it takes way too long to figure out what it does because of the massive if statements.
Especially because the function is just either adding an edge to a dynamic array or joining two arrays.
You could split out the memory allocation into a helper function of course.

But now I feel that these should be two functions. One for joining two edge arrays (the reduce function) and one for adding and loose edge to an array.

1524–1529

It think this comment should be expanded. Now it doesn't really tell the reader why.

Something like:

/* Because the Edge Neighbour array contains loop edge pairs, we only need to process the first edge in the pair.
 * Otherwise we would add the same edge that the loops represent twice. */
1531–1532

Move this into the if statement below.
I would also probably rename them to f1 and f2.
Perhaps ff1, and ff2 would be better as well?
Basically I think that having numbers instead of "right" and "left" shortened to r and l is easier to understand at a glance.

1544–1545

Same reasoning as above. Why doesn't this handle the mesh boundary case?
Explain it in the comment! :)

1581

You don't need this else after the return statement above.
Remove it.

1607

Just declare the array this points to as view_vector and pass it with &view_vector to the functions below.
No need to create a helper pointer like this.

1907

I would rename these three variables, here and in the code where they are used:
en -> edge_nabr
ai -> adj_e
lt -> mlooptri (as it is named in other parts of the loading code

1916

I would drop the _use suffix here.

I think ai_use -> adj_e is clear enough.
(same for the other _use variables in the code.

1936

Keep these (start/end) PIL_ call behind G.debug_value == 4000 if statements if you want to keep them.

1945

These are not vertices, but edges?

1966–1978

As the old object load function doesn't exist anymore, we can rename this back to object_load, right?
That way you don't need to update comments in the code referring to the old function as well.

2025

I would rename this to crease_threshold as this is not a boolean but a threshold.

YimingWu (NicksBest) marked 22 inline comments as done.May 4 2022, 3:01 PM
YimingWu (NicksBest) added inline comments.
source/blender/gpencil_modifiers/intern/lineart/lineart_cpp_bridge.cpp
9

v1 and v2 are unsigned, so if not including the (int) there then the result of that equation won't actually be negative? (I didn't confirm this, it's just when I was trying to see where the problem is in the cmp function, might not need this after all.)

source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
1607

I'm doing this so view_vector being a pointer can also point to rb->view_vector when it's ortho camera. This way we don't need to copy or recalculate. And code can be the same.

1966–1978

I'll rename to lineart_geometry_object_load_single for now, because I want to have it distinguishable so it creates less problem on other branches when I pick commits. Maybe later when everything is in we can do a final clean up for names like this?

2025

I think here actual_crease is better.

YimingWu (NicksBest) marked 4 inline comments as done.

Fixed stuff in comments.

source/blender/gpencil_modifiers/intern/lineart/lineart_cpp_bridge.cpp
9

Looks like we don't (int) so removed.

Remove (int) in cmp_adjacent_items().

source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
1607

Then rename vv to view_vector_persp

1966–1978

It shouldn't matter what you have in the other branches as you deleted the old function.
So if you try to pull in this change you will get conflicts either way.

I don't think that implementing "hacks" for stuff that is not in the master branch is a good solution either.

2025

Perhaps just crease_angle ?

YimingWu (NicksBest) marked 3 inline comments as done.

Fixed minor naming stuff.

Last round of nitpicks.
I'll accept the patch so you don't need to put it up for review again after those are fixed.

source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
1521

rename to edge_nabr
Both in the feat_data and the variable name.

1710

I would add _arr at the end of the function so it is clear that we are joining two arrays together:
lineart_join_loose_edge_arr

1937

rename ai, en and lt in this function as well.

This revision is now accepted and ready to land.May 4 2022, 3:48 PM
YimingWu (NicksBest) marked 3 inline comments as done.

Fixed naming stuff

This revision was automatically updated to reflect the committed changes.