Tree Generator v1.23.0: Blattwerk auf die Zweige streuen

Blatt-Card waehlen -> wird auf die duennen Zweige gestreut (Filter ueber das
Radius-Attribut des Meshes) und als <Name>_Leaf mit identischem Ursprung abgelegt.
Regler fuer Dichte, Groesse, Streuung, Kippung, Zweig-Schwelle. Der Button meldet
Stamm + Blatt = Summe und warnt bei Ueberschreitung des Tri-Budgets.

Gemessen: Eiche 1428 + Blattwerk 1032 = 2460 von 2500 Tris bei Default-Dichte 150.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-30 11:42:52 +02:00
co-authored by Claude Opus 4.8
parent 1112797138
commit 833e929f82
7 changed files with 332 additions and 8 deletions
+61
View File
@@ -0,0 +1,61 @@
import bpy, sys, zipfile, os, tempfile, importlib.util, math, bmesh
ZIP=r"A:\eco\stylized_rock_generator\dist\stylized_tree_generator-1.23.0.zip"
tmp=tempfile.mkdtemp()
with zipfile.ZipFile(ZIP) as z: z.extractall(tmp)
init=[os.path.join(r,"__init__.py") for r,_,f in os.walk(tmp) if "__init__.py" in f][0]
spec=importlib.util.spec_from_file_location("stg",init)
m=importlib.util.module_from_spec(spec); sys.modules["stg"]=m; spec.loader.exec_module(m)
try: m.unregister()
except Exception: pass
m.register()
fails=[]
for o in list(bpy.data.objects): bpy.data.objects.remove(o,do_unlink=True)
# Card wie beim User
me=bpy.data.meshes.new("DiamondCard"); bm=bmesh.new()
for ang in (0.0, math.pi/3, 2*math.pi/3):
c,s_=math.cos(ang), math.sin(ang)
vs=[bm.verts.new(p) for p in [(-c,-s_,-1.41),(c,s_,-1.41),(c,s_,1.41),(-c,-s_,1.41)]]
bm.faces.new(vs)
bm.to_mesh(me); bm.free(); me.uv_layers.new(name="UVMap")
card=bpy.data.objects.new("Diamon Plane", me); bpy.context.collection.objects.link(card)
s=bpy.context.scene.tree_gen_settings
s.preset='eiche'; s.art_name="Eiche"; s.variant=1
s.leaf_card=card; s.leaf_size=0.22 # Dichte: Default verwenden
s.make_leaf=True; s.use_growth=False
r=bpy.ops.object.treegen_create()
names=sorted(o.name for o in bpy.context.scene.objects if o.type=='MESH')
print("OBJEKTE:", [n for n in names if n!="Diamon Plane"])
if "Eiche_01" not in names or "Eiche_01_Leaf" not in names: fails.append("objekte")
bpy.context.view_layer.update()
dg=bpy.context.evaluated_depsgraph_get()
def tris(n):
ob=bpy.context.scene.objects[n]
return sum(len(p.vertices)-2 for p in ob.evaluated_get(dg).data.polygons)
tt,tl=tris("Eiche_01"), tris("Eiche_01_Leaf")
print("TRIS Stamm=%d Blatt=%d Summe=%d / 2500 %s (Dichte %.0f)" % (tt,tl,tt+tl,"OK" if tt+tl<=2500 else "UEBER", s.leaf_density))
if tl==0: fails.append("blattwerk_leer")
if tt+tl>2500: fails.append("budget")
# Ursprung deckungsgleich
a=bpy.context.scene.objects["Eiche_01"]; b=bpy.context.scene.objects["Eiche_01_Leaf"]
d=(a.location-b.location).length
print("URSPRUNG-Abstand: %.6f" % d)
if d>1e-6: fails.append("ursprung")
# Operator auf Auswahl
for o in bpy.context.selected_objects: o.select_set(False)
a.select_set(True); bpy.context.view_layer.objects.active=a
r2=bpy.ops.object.treegen_leaves()
print("OPERATOR treegen_leaves:", list(r2))
if 'FINISHED' not in r2: fails.append("operator")
# Ohne Card -> leeres _Leaf
for o in list(bpy.data.objects):
if o.name.startswith("Eiche"): bpy.data.objects.remove(o,do_unlink=True)
s.leaf_card=None; s.art_name="Birke"; s.preset='birke'
bpy.ops.object.treegen_create()
lf=bpy.context.scene.objects.get("Birke_01_Leaf")
print("ohne Card -> _Leaf vorhanden:", lf is not None, "| leer:", lf and len(lf.data.polygons)==0)
if lf is None: fails.append("leer_leaf")
m.unregister()
print("ERGEBNIS:", "ALLE CHECKS OK" if not fails else "FEHLER: "+", ".join(fails))
sys.exit(1 if fails else 0)