Skip to content

Commit d7593e2

Browse files
committed
Update v0.5.0
- New button to collapse all collections easily - When creating route collection, new options available to automatically exclude/hide/unlink original collections and objects (enabled by default)
1 parent aabe130 commit d7593e2

7 files changed

Lines changed: 70 additions & 12 deletions

File tree

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ You can use this addon at the very start of a blender map project.
4040

4141
### Select Map Collection
4242
1. Once it is imported, you have to find the collection that contains the textured meshes<br>
43-
You can `ctrl+left-click` on the visibility toggle of the collection to hide everything else (in the outliner)
43+
- You can use the small button right to the collection input to collapse all collections in the outliner (or press `shift+A` when hovering in the outliner)
44+
- In the outliner too, you can `ctrl+left-click` on the visibility toggle of the collection to hide everything else
4445
2. Select this collection in the addon panel, and click on the `Clean Map Collection` button
4546
3. Depending on how you imported the NR files, you might want to disable `Flip vertically` and `Flip faces` in the popup window
4647
4. Delete manually things that are not wanted and away from the route
@@ -49,7 +50,5 @@ You can use this addon at the very start of a blender map project.
4950
Now you have one object per material in the resulting collection.
5051
1. Select the ones that are part of the route with `shift+left-click`
5152
2. Click on the `Create Route Collection`
52-
3. If you don't want the resulting objects to be linked to the first collection:
53-
- Select them in the first collection
54-
- `right-click` -> `Unlink`
53+
3. By default, it will hide and exclude the original collection, and unlink the objects in there so they only exist in the newly created collection. You can disable this in the popup window.
5554
4. Now you can make use of the `Cleaning Tools` to help you with the finishing touches

__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
bl_info = {
22
"name": "NR_Cleanup",
33
"author": "Bigthirsty & Skyrow",
4-
"version": (0, 4, 1), #<major>.<minor>.<patch>
4+
"version": (0, 5, 0), #<major>.<minor>.<patch>
55
"blender": (3, 6, 0),
66
"location": "3D Viewport > Sidebar > NR Cleanup",
77
"description": "Cleans up NinjaRipped trackmania2020 maps to driving surfaces only",

operators/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
# clean_imported_nr
44
from .clean_imported_nr.OT_clean_nr_collection import (
5-
OBJECT_OT_clean_nr_collection,
5+
COLLECTION_OT_clean_nr_collection,
6+
)
7+
from .clean_imported_nr.OT_collapse_all_collections import (
8+
COLLECTION_OT_collapse_all_collections,
69
)
710
from .clean_imported_nr.OT_make_route_collection import (
811
OBJECT_OT_make_route_collection,
@@ -45,7 +48,8 @@
4548
# Props and UIList must be registered before operators
4649
_MaterialSelection,
4750
_MATERIAL_UL_material_selection,
48-
OBJECT_OT_clean_nr_collection,
51+
COLLECTION_OT_clean_nr_collection,
52+
COLLECTION_OT_collapse_all_collections,
4953
OBJECT_OT_make_route_collection,
5054
OBJECT_OT_delete_faces_by_material,
5155
OBJECT_OT_delete_vertical_faces,

operators/clean_imported_nr/OT_clean_nr_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import bpy
22

33

4-
class OBJECT_OT_clean_nr_collection(bpy.types.Operator):
4+
class COLLECTION_OT_clean_nr_collection(bpy.types.Operator):
55
"""Join all objects in the selected collection and remove other collections"""
66
bl_idname = 'collection.clean_nr_collection'
77
bl_label = 'Clean NR Collection'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import bpy
2+
3+
4+
class COLLECTION_OT_collapse_all_collections(bpy.types.Operator):
5+
"""Collapse all collections in the outliner"""
6+
bl_idname = 'collection.collapse_all_collections'
7+
bl_label = 'Collapse All Collections'
8+
bl_options = {'REGISTER', 'UNDO'}
9+
10+
@classmethod
11+
def poll(cls, context):
12+
return True
13+
14+
def execute(self, context):
15+
16+
areaOverride = context.area
17+
for area in bpy.context.screen.areas:
18+
if area.type == 'OUTLINER':
19+
areaOverride=area
20+
21+
with bpy.context.temp_override(area=areaOverride):
22+
bpy.ops.outliner.show_one_level(open=False)
23+
24+
areaOverride.tag_redraw()
25+
26+
return {'FINISHED'}

operators/clean_imported_nr/OT_make_route_collection.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ class OBJECT_OT_make_route_collection(bpy.types.Operator):
77
bl_label = 'Make Route Collection'
88
bl_options = {'REGISTER', 'UNDO'}
99

10+
exclude_original_collections: bpy.props.BoolProperty(name='Exclude original collections', default=True)
11+
hide_original_collections: bpy.props.BoolProperty(name='Hide original collections', default=True)
12+
unlink_original_objexts: bpy.props.BoolProperty(name='Unlink original objects', default=True)
13+
1014
@classmethod
1115
def poll(cls, context):
1216
return (
@@ -15,15 +19,37 @@ def poll(cls, context):
1519
)
1620

1721
def execute(self, context):
22+
selected_objects = bpy.context.selected_objects
23+
24+
# Create a new collection for the selected objects
1825
cleaned_route_collection = bpy.data.collections.get('Cleaned Route')
1926
if not cleaned_route_collection:
2027
cleaned_route_collection = bpy.data.collections.new('Cleaned Route')
2128
bpy.context.scene.collection.children.link(cleaned_route_collection)
2229

23-
selected_objects = bpy.context.selected_objects
30+
# Get the original collections of selected objects
31+
original_collections = set()
2432
for obj in selected_objects:
33+
for collection in obj.users_collection:
34+
original_collections.add(collection)
35+
36+
# Link the selected objects to the new collection
37+
for obj in selected_objects:
38+
if self.unlink_original_objexts:
39+
for col in obj.users_collection:
40+
col.objects.unlink(obj)
2541
cleaned_route_collection.objects.link(obj)
2642

43+
# Exclude all collections and enable only new collection
44+
for layer_collection in context.view_layer.layer_collection.children:
45+
if self.exclude_original_collections:
46+
layer_collection.exclude = True
47+
if self.hide_original_collections:
48+
layer_collection.hide_viewport = True
49+
context.view_layer.layer_collection.children[cleaned_route_collection.name].exclude = False
50+
context.view_layer.layer_collection.children[cleaned_route_collection.name].hide_viewport = False
51+
52+
# Deselect all objects
2753
bpy.ops.object.select_all(action='DESELECT')
2854

2955
return {'FINISHED'}

panels/PT_clean_imported_nr.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
from ..operators import (
66
UI_OT_message_popup,
7-
OBJECT_OT_clean_nr_collection,
7+
COLLECTION_OT_clean_nr_collection,
8+
COLLECTION_OT_collapse_all_collections,
89
OBJECT_OT_make_route_collection,
910
)
1011

@@ -28,8 +29,10 @@ def draw(self, context):
2829
+ 'It will join all objects inside of the selected collection\n' \
2930
+ 'and then separate it by material.\n' \
3031
+ 'EVERYTHING ELSE IN THE SCENE WILL BE DELETED !'
31-
box.prop(nrc_props, 'nr_collection', text='')
32-
box.operator(OBJECT_OT_clean_nr_collection.bl_idname, text='Clean Map Collection')
32+
row = box.row(align=True)
33+
row.prop(nrc_props, 'nr_collection', text='')
34+
row.operator(COLLECTION_OT_collapse_all_collections.bl_idname, text='', icon='FULLSCREEN_EXIT')
35+
box.operator(COLLECTION_OT_clean_nr_collection.bl_idname, text='Clean Map Collection')
3336
# Create route collection
3437
box = layout.box()
3538
row = box.row()

0 commit comments

Comments
 (0)