Skip to content

Commit 9177eec

Browse files
committed
Packaging -> v0.1.0
1 parent dccf5b5 commit 9177eec

9 files changed

Lines changed: 233 additions & 202 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

Blender addon

Lines changed: 0 additions & 202 deletions
This file was deleted.

__init__.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import bpy
2+
3+
# Note from Skyrow : v0.1.0 changes
4+
# - Packaged addon into multiple files
5+
# - Panels and operators rename
6+
7+
bl_info = {
8+
"name": "NR_Cleanup",
9+
"author": "Bigthirsty & Skyrow",
10+
"version": (0, 1, 0), #<major>.<minor>.<patch>
11+
"blender": (4, 0, 1),
12+
"location": "3D Viewport > Sidebar > NR Cleanup",
13+
"description": "Cleans up NinjaRipped trackmania2020 maps to driving surfaces only",
14+
"category": "Trackmania",
15+
}
16+
17+
18+
# Import props
19+
20+
# Import operators
21+
from .operators.OT_select_collection_from_nr import COLLECTION_OT_select_collection_from_nr
22+
from .operators.OT_make_route_collection import OBJECT_OT_make_route_collection
23+
from .operators.OT_remove_vertical_faces import MESH_OT_delete_vertical_faces
24+
# Import panels
25+
from .panels.PT_select_collection_from_rip import VIEW3D_PT_nr_cleanup
26+
27+
28+
# Define register order
29+
classes = (
30+
# Props
31+
32+
# Operators
33+
COLLECTION_OT_select_collection_from_nr,
34+
OBJECT_OT_make_route_collection,
35+
MESH_OT_delete_vertical_faces,
36+
# Panels
37+
VIEW3D_PT_nr_cleanup,
38+
)
39+
40+
41+
# Register addon
42+
def register():
43+
for cls in classes:
44+
bpy.utils.register_class(cls)
45+
46+
# Unregister addon
47+
def unregister():
48+
for cls in reversed(classes):
49+
bpy.utils.register_class(cls)
50+
51+
52+
if __name__ == "__main__":
53+
register()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import bpy
2+
3+
4+
class OBJECT_OT_make_route_collection(bpy.types.Operator):
5+
bl_idname = "object.make_route_collection"
6+
bl_label = "Make Route Collection"
7+
bl_options = {'REGISTER', 'UNDO'}
8+
9+
def execute(self, context):
10+
cleaned_route_collection = bpy.data.collections.get("Cleaned Route")
11+
if not cleaned_route_collection:
12+
cleaned_route_collection = bpy.data.collections.new("Cleaned Route")
13+
bpy.context.scene.collection.children.link(cleaned_route_collection)
14+
15+
selected_objects = bpy.context.selected_objects
16+
for obj in selected_objects:
17+
cleaned_route_collection.objects.link(obj)
18+
19+
bpy.ops.object.select_all(action='DESELECT')
20+
21+
return {'FINISHED'}
22+
23+
def invoke(self, context, event):
24+
return context.window_manager.invoke_props_dialog(self)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import bpy
2+
3+
from ..utils.math import (
4+
cross,
5+
length
6+
)
7+
8+
9+
class MESH_OT_delete_vertical_faces(bpy.types.Operator):
10+
bl_idname = 'mesh.delete_vertical_faces'
11+
bl_label = 'Delete Vertical Faces'
12+
bl_options = {'REGISTER', 'UNDO'}
13+
14+
apply_rotation: bpy.props.BoolProperty(name='Apply rotation', default=False)
15+
16+
@classmethod
17+
def poll(cls, context):
18+
return context.object.type == 'MESH'
19+
20+
def invoke(self, context, event):
21+
return context.window_manager.invoke_props_dialog(self, width=300)
22+
23+
def execute(self, context):
24+
up_vector = [0., 0., 1.]
25+
26+
bpy.ops.object.mode_set(mode='EDIT')
27+
bpy.ops.mesh.select_mode(use_extend=False, use_expand=False, type='FACE')
28+
bpy.ops.object.mode_set(mode='OBJECT')
29+
30+
# Apply rotation if requested
31+
if self.apply_rotation:
32+
bpy.ops.object.transform_apply(location=False, rotation=True, scale=False)
33+
34+
# Mesh faces
35+
faces = [f for f in context.object.data.polygons]
36+
37+
# Selecting vertical faces
38+
for f in faces:
39+
normal_x_up = cross(f.normal, up_vector)
40+
# If the norm of cross profuct is 1., then the face is vertical
41+
if (length(normal_x_up) == 1.):
42+
f.select = True
43+
else:
44+
f.select = False
45+
46+
# Deleting selected faces
47+
bpy.ops.object.mode_set(mode='EDIT')
48+
bpy.ops.mesh.delete(type='FACE')
49+
bpy.ops.object.mode_set(mode='OBJECT')
50+
return {'FINISHED'}
51+
52+
def draw(self, context):
53+
layout = self.layout
54+
layout.label(text='It will delete vertical face in the local space.', icon='INFO')
55+
layout.label(text='If your object has a transformation of its rotation,')
56+
layout.label(text='You may want to apply it first')
57+
layout.prop(self, 'apply_rotation')

0 commit comments

Comments
 (0)