Wie teile ich eine OBJ -Datei mit Blender 2.90 in drei Teile aufPython

Python-Programme
Guest
 Wie teile ich eine OBJ -Datei mit Blender 2.90 in drei Teile auf

Post by Guest »

Ich habe ein Objekt, das ich in 3 Segmente teilen und speichern möchte in einzelne OBJ -Dateien. Das Objekt wird in der Mitte und in der X-Y-Ebene platziert. Ich möchte sie entlang der Y-Achse schneiden. Ich habe ein Beispielbild von Free3D zur Visualisierung angehängt. Die Hauptzieldatei befindet sich in der Mitte und die 3 geteilten OBJ -Dateien sind unterhalb der Hauptdateien angezeigt. Ich habe versucht, BISECT im Python -Skript zu verwenden, aber offensichtlich spaltet das die Datei nur in zwei Teile auf. Gibt es eine Möglichkeit, sie in drei aufzuteilen und einzeln zu retten? Das Python -Skript, das ich ausprobiert habe, wird hier angegeben: < /p>

Code: Select all

import bpy
import os
import mathutils

input_path = "skull.obj"
output_path = os.path.join(os.path.dirname(input_path), "cut.obj")

bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
bpy.ops.import_scene.obj(filepath=input_path)
obj = bpy.context.selected_objects[0]
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
bbox_min = min([mathutils.Vector(v) for v in obj.bound_box])
bbox_max = max([mathutils.Vector(v) for v in obj.bound_box])
length_y = bbox_max.y - bbox_min.y
cut_min_y = bbox_min.y + 0.25 * length_y
cut_max_y = bbox_max.y - 0.25 * length_y
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.bisect(plane_co=(0, cut_min_y, 0), plane_no=(0, 1, 0), clear_inner=True)
bpy.ops.mesh.bisect(plane_co=(0, cut_max_y, 0), plane_no=(0, -1, 0), clear_outer=True)
bpy.ops.object.mode_set(mode='OBJECT')

bpy.ops.export_scene.obj(filepath=output_path, use_selection=True)

print(f"File saved as: {output_path}")

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post