Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new node ScSelectVertexByConnections #88

Merged
merged 2 commits into from
Dec 21, 2019
Merged

add new node ScSelectVertexByConnections #88

merged 2 commits into from
Dec 21, 2019

Conversation

zebus3d
Copy link
Contributor

@zebus3d zebus3d commented Dec 21, 2019

No description provided.

Copy link
Owner

@aachman98 aachman98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a few changes which can improve the code. It will be very useful once merged though.
There is also a simpler implementation for this:
Screenshot from 2019-12-21 20-11-27
where b is bmesh.from_edit_mesh(self.inputs["Object"].default_value.data) and comparison of length can be done with self.inputs["Connections"].default_value
Then the resulting array can be traversed and corresponding indices can be set to selected.

If you want me to change it accordingly, then let me know. I'll merge the PR and edit it before the next release.

bl_label = "Select Vertex By Connections"

in_connections: IntProperty(default=1, min=0, update=ScNode.update_value)
in_extend: BoolProperty(default=True, update=ScNode.update_value)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set default=False

self.inputs.new("ScNodeSocketBool", "Extend").init("in_extend")
# work in vertex mode:
# With this it is not necessary to manually force the mode to vertices mode:
self.in_selection_type = {'VERT'}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't set variables directly in init() function because it will call ScNode.update_value() and execute the nodetree for every variable. Either set their default values (like in in_extend above) or simply add an error condition.

# work in vertex mode:
# With this it is not necessary to manually force the mode to vertices mode:
self.in_selection_type = {'VERT'}
self.in_extend = False
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for this

super().error_condition()
or int(self.inputs["Connections"].default_value) < 0
# prevent other modes:
or self.in_selection_type != {'VERT'}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the in_selection_type is an input socket which can contain multiple values (set), the correct condition would be:
or (not 'VERT' in self.inputs["Selection Type"].default_value)

)

def functionality(self):
print(self)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No further need for debug logs


def functionality(self):
print(self)
connections = int(self.inputs["Connections"].default_value)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid initialising extra variables unless you want to use them multiple times

def functionality(self):
print(self)
connections = int(self.inputs["Connections"].default_value)
obj = self.inputs["Object"].default_value
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for this

connections = int(self.inputs["Connections"].default_value)
obj = self.inputs["Object"].default_value

mode = bpy.context.mode
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this

obj = self.inputs["Object"].default_value

mode = bpy.context.mode
if mode != 'EDIT':
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never required because the object will be selected AND in the edit mode before calling functionality().
See pre_execute() of parent class ScSelectionNode

Copy link
Owner

@aachman98 aachman98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good enough. I'll add a few lines of code from other selection nodes to improve on the deselect & extend feature.
Thanks!

@zebus3d
Copy link
Contributor Author

zebus3d commented Dec 21, 2019

I don't control github depth. I made most of the changes, however you can change whatever you want after you accept the change. I used a while to keep the first match and then look for similar ones, because I think that way the performance will be better, since you don't have to go through all the vertexs.

@aachman98
Copy link
Owner

I used a while to keep the first match and then look for similar ones, because I think that way the performance will be better, since you don't have to go through all the vertexs.

But it is only useful if bpy.ops.mesh.select_similar() doesn't iterate through all the vertices.

@aachman98 aachman98 merged commit f420b50 into aachman98:master Dec 21, 2019
@zebus3d
Copy link
Contributor Author

zebus3d commented Dec 21, 2019

I used a while to keep the first match and then look for similar ones, because I think that way the performance will be better, since you don't have to go through all the vertexs.

But it is only useful if bpy.ops.mesh.select_similar() doesn't iterate through all the vertices.

I guess select_similar is written in c or c++ and the performance will be better than in python, but these are just assumptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants