Skip to content

Commit

Permalink
Merge pull request #5056 from nortikin/fix_5055_Append_quick_method_t…
Browse files Browse the repository at this point in the history
…o_display_type_and_hide_render_of_selected_objects_in_the_node_Get_Objects_Data

fix #5055. Append quick method to display_type and hide_render of selected objects in the node "Get Objects Data"
  • Loading branch information
satabol authored Nov 10, 2023
2 parents 6b256f7 + 63bd2bd commit 18b6b21
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 17 deletions.
43 changes: 30 additions & 13 deletions docs/nodes/scene/get_objects_data.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Get Objects Data
================

.. image:: https://github.com/nortikin/sverchok/assets/14288520/b24e7fbc-3383-49ca-bc96-ae5ff823fee3
:target: https://github.com/nortikin/sverchok/assets/14288520/b24e7fbc-3383-49ca-bc96-ae5ff823fee3
.. image:: https://github.com/nortikin/sverchok/assets/14288520/d7662f9f-d398-4b73-8337-d0d228f104bc
:target: https://github.com/nortikin/sverchok/assets/14288520/d7662f9f-d398-4b73-8337-d0d228f104bc

Functionality
-------------
Expand All @@ -21,6 +21,18 @@ A few points worth stating explicitly.
limitations:

- When you use the ``Post`` mode Sverchok/Blender expect Objects to be visible. If you want to "hide" the original Objects in the scene to avoid visual clutter, you can place them into a Collection and hide the collection. This is a current Blender API limitation.
- Another method to work with objects - select wireframe mode and hide objects in Render by buttons:

.. image:: https://github.com/nortikin/sverchok/assets/14288520/30158800-3cd8-483d-a162-2d13ddfdc289
:target: https://github.com/nortikin/sverchok/assets/14288520/30158800-3cd8-483d-a162-2d13ddfdc289

.. raw:: html

<video width="700" controls>
<source src="https://github.com/nortikin/sverchok/assets/14288520/7a158c33-814a-43be-9a9c-929096495354" type="video/mp4">
Your browser does not support the video tag.
</video>

- We have Bezier-in and NURBS-in nodes if you want to get Curve data from Scene objects, instead of Mesh.

Inputs
Expand All @@ -32,17 +44,22 @@ Objects Socket
Parameters
----------

+-----------------+---------------+--------------------------------------------------------------------------+
| Param | Type | Description |
+=================+===============+==========================================================================+
| **G E T** | Button | Button to get selected objects from scene. |
+-----------------+---------------+--------------------------------------------------------------------------+
| **sorting** | Bool, toggle | Sorting inserted objects by name |
+-----------------+---------------+--------------------------------------------------------------------------+
| **post** | Bool, toggle | Postprocessing, if activated, modifiers applied to mesh before importing |
+-----------------+---------------+--------------------------------------------------------------------------+
| **vert groups** | Bool, toggle | Import all vertex groups that in object's data. just import indexes |
+-----------------+---------------+--------------------------------------------------------------------------+
+----------------------+---------------+--------------------------------------------------------------------------+
| Param | Type | Description |
+======================+===============+==========================================================================+
| **G E T** | Button | Button to get selected objects from scene. |
+----------------------+---------------+--------------------------------------------------------------------------+
| **Apply_Matrix** | Bool,toggle | Apply object Matrix to output sockets (Vertices, Vertex Normals, |
| | | Poligon Centers, Polygon Normals). Has no infuence for Matrix and Object |
+----------------------+---------------+--------------------------------------------------------------------------+
| **Merge** | Bool,toggle | Merge Meshes into one mesh |
+----------------------+---------------+--------------------------------------------------------------------------+
| **sorting** | Bool,toggle | Sorting inserted objects by name |
+----------------------+---------------+--------------------------------------------------------------------------+
| **post** | Bool,toggle | Postprocessing, if activated, modifiers applied to mesh before importing |
+----------------------+---------------+--------------------------------------------------------------------------+
| **vert groups** | Bool,toggle | Import all vertex groups that in object's data. just import indexes |
+----------------------+---------------+--------------------------------------------------------------------------+

3D panel
--------
Expand Down
100 changes: 96 additions & 4 deletions nodes/scene/get_objects_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# License-Filename: LICENSE

import bpy
from bpy.props import BoolProperty, StringProperty, IntProperty
from bpy.props import BoolProperty, StringProperty, IntProperty, EnumProperty
import bmesh
from mathutils import Vector, Matrix

Expand All @@ -16,6 +16,7 @@
from sverchok.utils.sv_bmesh_utils import pydata_from_bmesh
from sverchok.utils.sv_mesh_utils import mesh_join
from sverchok.utils.nodes_mixins.show_3d_properties import Show3DProperties
from sverchok.ui.sv_icons import custom_icon
from sverchok.utils.blender_mesh import (
read_verts, read_edges, read_verts_normal,
read_face_normal, read_face_center, read_face_area, read_materials_idx)
Expand Down Expand Up @@ -77,7 +78,6 @@ def sv_execute(self, context, node):
"""
getattr(node, self.fn_name)(self)


def get_vertgroups(mesh):
return [k for k,v in enumerate(mesh.vertices) if v.groups.values()]

Expand Down Expand Up @@ -137,12 +137,12 @@ def hide_show_versgroups(self, context):
name="Output Numpy",
description="Output NumPy arrays (makes node faster)",
size=7, update=updateNode)

output_np_all: BoolProperty(
name='Output all numpy',
description='Output numpy arrays if possible',
default=False, update=updateNode)


apply_matrix: BoolProperty(
name = "Apply matrices",
description = "Apply objects matrices",
Expand All @@ -155,6 +155,91 @@ def hide_show_versgroups(self, context):
default = False,
update = updateNode)

display_types = [
('BOUNDS', "", "BOUNDS: Display the bounds of the object", "MATPLANE", 0),
('WIRE', "", "WIRE: Display the object as a wireframe", "MESH_CUBE", 1),
('SOLID', "", "SOLID: Display the object as a solid (if solid drawing is enabled in the viewport)", "SNAP_VOLUME", 2), #custom_icon("SV_MAKE_SOLID")
('TEXTURED', "", "TEXTURED: Display the object with textures (if textures are enabled in the viewport)", "TEXTURE", 3),
]

def update_display_type(self, context):
for obj in self.object_names:
bpy.data.objects[obj.name].display_type=self.display_type
return

display_type : EnumProperty(
name = "Display Types",
items = display_types,
default = 'WIRE',
update = update_display_type)

hide_render_types = [
('RESTRICT_RENDER_ON', "", "Render objects", "RESTRICT_RENDER_ON", 0),
('RESTRICT_RENDER_OFF', "", "Do not render objects", "RESTRICT_RENDER_OFF", 1),
]

def update_render_type(self, context):
for obj in self.object_names:
bpy.data.objects[obj.name].hide_render = True if self.hide_render_type=='RESTRICT_RENDER_ON' else False
return

hide_render_type : EnumProperty(
name = "Render Types",
items = hide_render_types,
default = 'RESTRICT_RENDER_OFF',
update = update_render_type)

align_3dview_types = [
('ISOLATE_CURRENT', "", "Toggle local view with only current selected object in the list\nPress again to restore view", "PIVOT_CURSOR", 0),
('ISOLATE_ALL', "", "Toggle local view with all objects in the list\nPress again to restore view", "PIVOT_INDIVIDUAL", 1),
]

def update_align_3dview(self, context):
obj_in_list = self.object_names[self.active_obj_index]
if obj_in_list:
# reset all selections
for obj in bpy.context.selected_objects:
obj.select_set(False)

# select all objects in list of this node
if self.align_3dview_type=='ISOLATE_ALL':
for obj in self.object_names:
if obj.name in bpy.data.objects:
bpy.data.objects[obj.name].select_set(True)

if obj_in_list.name in bpy.data.objects:
obj_in_scene = bpy.data.objects[obj_in_list.name]
obj_in_scene.select_set(True)
bpy.context.view_layer.objects.active = obj_in_scene

for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
ctx = bpy.context.copy()
ctx['area'] = area
ctx['region'] = area.regions[-1]
# test if current mode is local view: https://blender.stackexchange.com/questions/290669/checking-for-object-being-in-local-view
if self.align_3dview_type_previous_value!=self.align_3dview_type and area.spaces.active.local_view:
bpy.ops.view3d.localview(ctx, frame_selected=False)
self.align_3dview_type_previous_value = self.align_3dview_type
bpy.ops.view3d.localview(ctx, frame_selected=False)
#bpy.ops.view3d.view_selected(ctx)
break

pass
return

align_3dview_type : EnumProperty(
name = "Local View",
items = align_3dview_types,
default = 'ISOLATE_CURRENT',
update = update_align_3dview)

align_3dview_type_previous_value : EnumProperty(
name = "Local View",
items = align_3dview_types,
default = 'ISOLATE_CURRENT')


def sv_init(self, context):
new = self.outputs.new
self.width = 170
Expand Down Expand Up @@ -193,7 +278,6 @@ def get_objects_from_scene(self, ops):

self.process_node(None)


def select_objs(self, ops):
"""select all objects referenced by node"""
for item in self.object_names:
Expand Down Expand Up @@ -228,6 +312,14 @@ def sv_draw_buttons(self, context, layout):

self.wrapper_tracked_ui_draw_op(row, callback, text=op_text).fn_name = 'get_objects_from_scene'

row = col.row()
col = row.column()
col.row().prop(self, 'display_type', expand=True)
col = row.column()
col.row().prop(self, 'hide_render_type', expand=True)
col = row.column()
col.row().prop(self, 'align_3dview_type', expand=True)

col = layout.column(align=True)
row = col.row(align=True)
row.prop(self, "apply_matrix", text="Apply matrix", toggle=True)
Expand Down

0 comments on commit 18b6b21

Please sign in to comment.