|
BTD /
Modul5BTD/Modul 5: Geometry Nodes & Simulation Inhalte:
Vorlesung 5Geometry Nodes & Simulation – Prozedurale Tools und Simulations-PipelinesDiese Vorlesung behandelt die Automatisierung und Pipeline-Integration von Simulationen sowie prozedurale Tool-Erstellung mit Geometry Nodes. Ziel ist es, reproduzierbare, skalierbare Systeme für Produktion und technische Qualitätssicherung zu entwickeln. 1. Einführung in Geometry NodesGeometry Nodes ermöglichen:
import bpy
# Prüfen, ob das aktive Objekt einen Geometry Nodes Modifier hat
obj = bpy.context.active_object
for mod in obj.modifiers:
if mod.type == 'NODES':
print("Geometry Nodes Modifier gefunden:", mod.name)
2. Geometry Nodes – Node Tree GrundlagenJeder Geometry Nodes Modifier besitzt einen Node Tree:
mod = bpy.context.object.modifiers.get("GeometryNodes")
if mod:
tree = mod.node_group
print("Nodes im Modifier:", [node.name for node in tree.nodes])
3. Erstellen eines parametrischen Tools (Grundlage Aufgabe 1)
import bpy
obj = bpy.context.active_object
geo_mod = obj.modifiers.new(name="ProceduralWall", type='NODES')
geo_mod.node_group = bpy.data.node_groups.new("WallGenerator", 'GeometryNodeTree')
tree = geo_mod.node_group
nodes = tree.nodes
links = tree.links
group_input = nodes.new('NodeGroupInput')
group_output = nodes.new('NodeGroupOutput')
tree.inputs.new('NodeSocketFloat', 'Length')
tree.inputs.new('NodeSocketFloat', 'Height')
tree.inputs.new('NodeSocketInt', 'Segments')
tree.outputs.new('NodeSocketGeometry', 'Geometry')
cube_node = nodes.new('GeometryNodeMeshCube')
links.new(cube_node.outputs['Mesh'], group_output.inputs['Geometry'])
Parameter wie Größe, Segmente und Material können über Inputs gesteuert werden. 4. Partikel- und Fluid-Simulation (Aufgabe 2)
import bpy
obj = bpy.context.active_object
psys = obj.modifiers.new("Particles", type='PARTICLE_SYSTEM')
psys_settings = bpy.data.particles.new(name="ParticleSettings")
psys.particle_system.settings = psys_settings
print("Partikel-System erstellt:", psys.name)
import bpy
obj = bpy.context.active_object
fluid_mod = obj.modifiers.new(name="FluidSim", type='FLUID_SIMULATION')
fluid_mod.fluid_type = 'DOMAIN'
print("Fluid-Simulation Modifier angelegt:", fluid_mod.name)
Hinweis: Für Domain & Flow müssen zusätzliche Objekte konfiguriert werden.
import bpy
bpy.ops.wm.alembic_export(filepath="//cache/particle.abc", selected_objects=True)
print("Simulation als Alembic exportiert")
import bpy
for obj in bpy.data.objects:
for mod in obj.modifiers:
if mod.type in {'FLUID_SIMULATION', 'PARTICLE_SYSTEM'}:
bpy.context.view_layer.objects.active = obj
bpy.ops.ptcache.bake_all()
print("Baked:", obj.name, mod.name)
5. Simulation Cache Management (Aufgabe 3)
import bpy
import os
for obj in bpy.data.objects:
for mod in obj.modifiers:
if mod.type in {'FLUID_SIMULATION', 'PARTICLE_SYSTEM'}:
path = mod.point_cache.filepath if hasattr(mod, 'point_cache') else "n/a"
size = os.path.getsize(path) if os.path.exists(path) else 0
print(obj.name, mod.name, "Cache:", path, "Größe:", size)
6. Node Groups dokumentieren und versionierenNode Groups erleichtern:
import bpy
for ng in bpy.data.node_groups:
print("Node Group:", ng.name)
Versionierung kann über Namenskonventionen wie ToolName_v001` erfolgen. 7. Performance-Optimierung bei SimulationenWichtige Maßnahmen:
import bpy
for obj in bpy.data.objects:
for mod in obj.modifiers:
if mod.type in {'FLUID_SIMULATION', 'PARTICLE_SYSTEM'}:
mod.show_viewport = False # Performance beim Arbeiten verbessern
8. Pipeline-Integration von SimulationenSimulationen sollten standardisiert exportiert werden:
import bpy bpy.ops.wm.alembic_export(filepath="//cache/sim_cache.abc", selected_objects=True) 9. Verbindung zu den ÜbungenDie Übungen dieses Moduls bauen direkt auf den vorgestellten Konzepten auf:
Die Aufgaben finden Sie unter Modul 5 – Übungen. |