Apply random selection factor precisely for all operators #87228

Open
opened 2021-04-06 07:32:07 +02:00 by Campbell Barton · 16 comments

Support accurate random selection.

Recently 9c20228128 was committed that ensures the number of selected items meets the requested factor.

Before this change, the selection probability was controlled by the factor, however the actual number of selected items would vary.

This change was only made for edit-mesh, there are other random selection operators that should use the more accurate behavior.

    • PARTICLE_OT_select_random
    • MBALL_OT_select_random_metaelems

Adding this as a TODO, and marking as "Good First Issue", since following the logic in MESH_OT_select_random should be fairly straightforward.

Support accurate random selection. Recently 9c20228128 was committed that ensures the number of selected items meets the requested factor. Before this change, the selection probability was controlled by the factor, however the actual number of selected items would vary. This change was only made for edit-mesh, there are other random selection operators that should use the more accurate behavior. - - [x] `CURVE_OT_select_random` 1c8c91384c - - [x] `LATTICE_OT_select_random` 1c8c91384c - - [x] `OBJECT_OT_select_random` 1c8c91384c - - [ ] `PARTICLE_OT_select_random` - - [ ] `MBALL_OT_select_random_metaelems` Adding this as a TODO, and marking as "Good First Issue", since following the logic in `MESH_OT_select_random` should be fairly straightforward.
Author
Owner

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Author
Owner

Added subscriber: @ideasman42

Added subscriber: @ideasman42

Added subscriber: @nest

Added subscriber: @nest

Greetings. I'm interested in doing this issue. Maybe partially only as I'm still new in contributing here.
I used blender regularly before and I believe I understand what the problem is.

I have looked into the code mentioned, MESH_OT_select_random in editmesh_select.c and generally understood the logic, it randomizes the list of verts (or edges ,faces) and selects x items from it based on the random factor.
Then I took a look in object_select.c in object_select_random_exec but did not understand this line (1463) : CTX_DATA_BEGIN (C, Base *, base, selectable_bases) {
Is it doing a loop over all the objects selectable? If so, is selectabe_bases a list?

I apologize if my question is missing something or this is not the place to ask.
Thanks.

Greetings. I'm interested in doing this issue. Maybe partially only as I'm still new in contributing here. I used blender regularly before and I believe I understand what the problem is. I have looked into the code mentioned, MESH_OT_select_random in editmesh_select.c and generally understood the logic, it randomizes the list of verts (or edges ,faces) and selects x items from it based on the random factor. Then I took a look in object_select.c in object_select_random_exec but did not understand this line (1463) : CTX_DATA_BEGIN (C, Base *, base, selectable_bases) { Is it doing a loop over all the objects selectable? If so, is selectabe_bases a list? I apologize if my question is missing something or this is not the place to ask. Thanks.

Added subscriber: @dreymatic

Added subscriber: @dreymatic

Hi, I've been working on implementing this for OBJECT_OT_select_random. I believe that I am essentially done except for one part of the specification that was referenced here: https://developer.blender.org/D1927 by @ideasman42

The only part of the specification I have not quite figured out for the Object implementation is finding out the total number of bases:
Base **bases = MEM_mallocN(sizeof(*bases) * TOT_BASES, __func__); TOT_BASES is the value I need to figure out. After I figure this out I should be able to test and submit my diff :)

I was curious if anyone had any advice or recommendation for this?

Hi, I've been working on implementing this for OBJECT_OT_select_random. I believe that I am essentially done except for one part of the specification that was referenced here: https://developer.blender.org/D1927 by @ideasman42 The only part of the specification I have not quite figured out for the Object implementation is finding out the total number of bases: `Base **bases = MEM_mallocN(sizeof(*bases) * TOT_BASES, __func__);` TOT_BASES is the value I need to figure out. After I figure this out I should be able to test and submit my diff :) I was curious if anyone had any advice or recommendation for this?

Implemented a fix for OBJECT_OT_select_random. Here's the diff: https://developer.blender.org/D11017 Let me know if I can submit the diff in a better way!

Implemented a fix for OBJECT_OT_select_random. Here's the diff: https://developer.blender.org/D11017 Let me know if I can submit the diff in a better way!

Added subscriber: @pjc7287

Added subscriber: @pjc7287

Added subscriber: @pmakal

Added subscriber: @pmakal

Uploaded diff for a review: https://developer.blender.org/D11685
@ideasman42 I would really appreciate it if you would check it :)

I haven't touch particles since gathering both points and keys to a one container in pure C code was a little bit to much for me (allocating memory and stuff). Also metaballs are not part of my diff since I just couldn't understand the code and the metaball behavior during debugging when doing random selection. In my testing it seem like every metaball compound (a shape consisted of many touching metaballs) was having only one element thus this loop is pointless:

if (BLI_rng_get_float(rng) < randfac) {
  if (select) {
    ml->flag |= SELECT;
  }
  else {
    ml->flag &= ~SELECT;
  }
}

}```

But I'm not metaball expert and https://wiki.blender.org/wiki/Modules doesn't point out any person I could ask about it so I just left it as is.
Uploaded diff for a review: https://developer.blender.org/D11685 @ideasman42 I would really appreciate it if you would check it :) I haven't touch particles since gathering both points and keys to a one container in pure C code was a little bit to much for me (allocating memory and stuff). Also metaballs are not part of my diff since I just couldn't understand the code and the metaball behavior during debugging when doing random selection. In my testing it seem like every metaball compound (a shape consisted of many touching metaballs) was having only one element thus this loop is pointless: ``` LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) { ``` if (BLI_rng_get_float(rng) < randfac) { if (select) { ml->flag |= SELECT; } else { ml->flag &= ~SELECT; } } }``` ``` But I'm not metaball expert and https://wiki.blender.org/wiki/Modules doesn't point out any person I could ask about it so I just left it as is.

This issue was referenced by 1c8c91384c

This issue was referenced by 1c8c91384c8d7d23b9a966802182e3ef607103ac

This issue was referenced by 2d4ec90497

This issue was referenced by 2d4ec90497443dc28e342c539e65010c7f4a04bb

Added subscriber: @Matias-Piipari

Added subscriber: @Matias-Piipari

Hi there! I took a stab at addressing the PARTICLE_OT_select_random case of this issue with the following diff: https://developer.blender.org/D13758 -- this being my first Blender contribution, please excuse the various ways in which I must be failing at following intended conventions :-)

I'm also not sure if there's also some more efficient way of dealing with the point-wise selection (RAN_POINTS), in particular the 1st pass in that case through the visible keys of the visible points is done just to get the allocation size for the array of point / key pairs (in the other RAN_HAIR case I treated the total point count as an upper bound for that array size).

Also, should there be some test scenarios for all of this?

Hi there! I took a stab at addressing the `PARTICLE_OT_select_random` case of this issue with the following diff: https://developer.blender.org/D13758 -- this being my first Blender contribution, please excuse the various ways in which I must be failing at following intended conventions :-) I'm also not sure if there's also some more efficient way of dealing with the point-wise selection (RAN_POINTS), in particular the 1st pass in that case through the visible keys of the visible points is done just to get the allocation size for the array of point / key pairs (in the other RAN_HAIR case I treated the total point count as an upper bound for that array size). Also, should there be some test scenarios for all of this?

Added subscriber: @Rin-San

Added subscriber: @Rin-San

Hi! I upload a diff to supplement MBALL_OT_select_random_metaelems : https://developer.blender.org/D14545
hope it will help

Hi! I upload a diff to supplement `MBALL_OT_select_random_metaelems` : https://developer.blender.org/D14545 hope it will help
Philipp Oeser removed the
Interest
Modeling
label 2023-02-09 15:28:36 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
8 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#87228
No description provided.