Created
January 27, 2025 05:41
-
-
Save afkarxyz/c0bd0b9d518bd5ef552160d82e4be009 to your computer and use it in GitHub Desktop.
Helps scale objects and separate objects based on materials from PCSX2 Ripper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bl_info = { | |
"name": "PCSX2 Ripper", | |
"author": "afkarxyz", | |
"version": (1, 0), | |
"blender": (3, 6, 0), | |
"location": "View3D > N-Panel > PCSX2 Ripper", | |
"description": "Helps scale objects and separate objects based on materials from PCSX2 Ripper.", | |
"category": "Object", | |
} | |
import bpy | |
from mathutils import Vector | |
from bpy.types import (Panel, Operator, PropertyGroup) | |
from bpy.props import FloatProperty, PointerProperty | |
class PCSX2_properties(PropertyGroup): | |
target_size: FloatProperty( | |
name="Target Size", | |
description="Target size for scaling", | |
default=10.0, | |
min=0.1 | |
) | |
class PCSX2_OT_scale_to_size(Operator): | |
bl_idname = "pcsx2.scale_to_size" | |
bl_label = "Scale Objects" | |
bl_options = {'REGISTER', 'UNDO'} | |
def execute(self, context): | |
props = context.scene.pcsx2_props | |
obs = context.selected_objects | |
if obs: | |
bounds = [ob.matrix_world @ Vector(bound) for ob in obs for bound in ob.bound_box] | |
maxs = [max(bound[i] for bound in bounds) for i in range(3)] | |
mins = [min(bound[i] for bound in bounds) for i in range(3)] | |
max_axis = max(maxs[i] - mins[i] for i in range(3)) | |
for ob in obs: | |
ob.scale *= props.target_size / max_axis | |
return {'FINISHED'} | |
class PCSX2_OT_separate_materials(Operator): | |
bl_idname = "pcsx2.separate_materials" | |
bl_label = "Separate by Materials" | |
bl_options = {'REGISTER', 'UNDO'} | |
def execute(self, context): | |
if context.object and context.object.type == 'MESH' and context.mode == 'OBJECT': | |
bpy.ops.object.mode_set(mode='EDIT') | |
bpy.ops.mesh.separate(type='MATERIAL') | |
bpy.ops.object.mode_set(mode='OBJECT') | |
return {'FINISHED'} | |
class PCSX2_PT_panel(Panel): | |
bl_label = "PCSX2 Ripper" | |
bl_idname = "PCSX2_PT_main_panel" | |
bl_space_type = 'VIEW_3D' | |
bl_region_type = 'UI' | |
bl_category = 'PCSX2 Ripper' | |
def draw(self, context): | |
layout = self.layout | |
props = context.scene.pcsx2_props | |
row = layout.row() | |
row.label(text="PCSX2 Ripper", icon='MODIFIER') | |
box = layout.box() | |
box.label(text="Scaling Tools", icon='EMPTY_AXIS') | |
box.prop(props, "target_size") | |
box.operator("pcsx2.scale_to_size") | |
box = layout.box() | |
box.label(text="Material Tools", icon='MATERIAL') | |
box.operator("pcsx2.separate_materials") | |
classes = ( | |
PCSX2_properties, | |
PCSX2_OT_scale_to_size, | |
PCSX2_OT_separate_materials, | |
PCSX2_PT_panel | |
) | |
def register(): | |
for cls in classes: | |
bpy.utils.register_class(cls) | |
bpy.types.Scene.pcsx2_props = PointerProperty(type=PCSX2_properties) | |
def unregister(): | |
for cls in classes: | |
bpy.utils.unregister_class(cls) | |
del bpy.types.Scene.pcsx2_props | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment