Update
This commit is contained in:
commit
2d6a8a867d
1093 files changed
+2424571
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import bpy, os
|
||||
from mathutils import Vector
|
||||
src=bpy.context.scene
|
||||
sc=bpy.data.scenes.new('Spirit_No_Intersections')
|
||||
for o in src.objects:
|
||||
cp=o.copy()
|
||||
if o.data: cp.data=o.data.copy()
|
||||
sc.collection.objects.link(cp)
|
||||
bpy.context.window.scene=sc
|
||||
sc.world=src.world
|
||||
sc.camera=next(o for o in sc.objects if o.type=='CAMERA')
|
||||
meshes=[]
|
||||
for o in list(sc.objects):
|
||||
if o.type!='MESH': continue
|
||||
bpy.context.view_layer.objects.active=o
|
||||
o.select_set(True)
|
||||
# Recalculate coherent face winding before exact solid operations.
|
||||
import bmesh
|
||||
bm=bmesh.new(); bm.from_mesh(o.data)
|
||||
bmesh.ops.recalc_face_normals(bm,faces=list(bm.faces)); bm.to_mesh(o.data); bm.free()
|
||||
for m in list(o.modifiers):
|
||||
if m.type=='WEIGHTED_NORMAL': o.modifiers.remove(m)
|
||||
else:
|
||||
try: bpy.ops.object.modifier_apply(modifier=m.name)
|
||||
except RuntimeError: pass
|
||||
o.select_set(False); meshes.append(o)
|
||||
def bounds(o):
|
||||
pts=[o.matrix_world@Vector(p) for p in o.bound_box]
|
||||
return ([min(p[i] for p in pts) for i in range(3)],[max(p[i] for p in pts) for i in range(3)])
|
||||
bpy.context.view_layer.update()
|
||||
# Frontmost details retain their shapes; the covered geometry is trimmed away.
|
||||
meshes.sort(key=lambda o:bounds(o)[0][1])
|
||||
count=0
|
||||
for i,o in enumerate(meshes):
|
||||
a,b=bounds(o)
|
||||
for cutter in meshes[:i]:
|
||||
c,d=bounds(cutter)
|
||||
if not all(min(b[k],d[k])-max(a[k],c[k])>.002 for k in range(3)): continue
|
||||
mod=o.modifiers.new('Remove internal intersection','BOOLEAN')
|
||||
mod.operation='DIFFERENCE'; mod.solver='EXACT'; mod.object=cutter
|
||||
bpy.context.view_layer.objects.active=o
|
||||
try:
|
||||
bpy.ops.object.modifier_apply(modifier=mod.name); count+=1
|
||||
except RuntimeError:
|
||||
o.modifiers.remove(mod)
|
||||
sc.render.engine='CYCLES'; sc.cycles.samples=48; sc.cycles.use_denoising=True
|
||||
sc.view_settings.view_transform='AgX'
|
||||
sc.render.resolution_x=900; sc.render.resolution_y=1100; sc.render.resolution_percentage=100
|
||||
out=r'C:\roblox\Ornament Generator RNG\blender\spirit_clean'
|
||||
sc.render.image_settings.file_format='PNG'; sc.render.filepath=out+'.png'
|
||||
bpy.ops.wm.save_as_mainfile(filepath=out+'.blend')
|
||||
bpy.ops.render.render(write_still=True)
|
||||
print('Trim operations:',count)
|
||||
print(out)
|
||||
Reference in new issue
Block a user