From 1e999c7bdb63576fd66815c1770d096d165b8281 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Sat, 25 Jul 2020 20:24:36 +0200 Subject: Particles: initial Quick Particles operator This operator automates the following steps: 1. Create a point cloud object. 2. Create a simulation data block. 3. Add a small particle simulation to the node tree. 4. Add a Simulation modifier to the point cloud object. 5. Reference the particle simulation from the modifier. You have to go back to frame 1 to start the simulation. The simulation is not yet cached and cannot be rendered. The bounding box of the point cloud object is enabled for now, because otherwise it is hard to select the object. --- .../startup/bl_operators/object_quick_effects.py | 52 ++++++++++++++++++++++ release/scripts/startup/bl_ui/space_view3d.py | 2 + .../nodes/node_sim_particle_mesh_emitter.cc | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/release/scripts/startup/bl_operators/object_quick_effects.py b/release/scripts/startup/bl_operators/object_quick_effects.py index 311631ac65f..d0344b88be8 100644 --- a/release/scripts/startup/bl_operators/object_quick_effects.py +++ b/release/scripts/startup/bl_operators/object_quick_effects.py @@ -561,9 +561,61 @@ class QuickLiquid(Operator): return {'FINISHED'} +class QuickParticles(Operator): + """Use active object as particle emitter""" + bl_idname = "object.quick_particles" + bl_label = "Quick Particles" + + @classmethod + def poll(cls, context): + if not context.preferences.experimental.use_new_particle_system: + return False + if context.mode != 'OBJECT': + return False + if context.active_object is None: + return False + if context.active_object.type != 'MESH': + return False + return True + + def execute(self, context): + pointcloud = bpy.data.pointclouds.new("Particles") + pointcloud_object = bpy.data.objects.new("Particles", pointcloud) + modifier = pointcloud_object.modifiers.new("Simulation", 'SIMULATION') + simulation = bpy.data.simulations.new("Particle Simulation") + tree = simulation.node_tree + + default_name = "Particles" + particle_simulation_node = tree.nodes.new('SimulationNodeParticleSimulation') + particle_simulation_node.name = default_name + emitter_node = tree.nodes.new('SimulationNodeParticleMeshEmitter') + emitter_node.location.x -= 200 + emitter_node.location.y += 50 + emitter_node.inputs["Object"].default_value = context.active_object + force_node = tree.nodes.new('SimulationNodeForce') + force_node.location.x -= 200 + force_node.location.y -= 100 + force_node.inputs["Force"].default_value = (0, 0, -1) + + tree.links.new(particle_simulation_node.inputs["Emitters"], emitter_node.outputs["Emitter"]) + tree.links.new(particle_simulation_node.inputs["Forces"], force_node.outputs["Force"]) + + modifier.simulation = simulation + modifier.data_path = default_name + + for obj in context.selected_objects: + obj.select_set(False) + + context.collection.objects.link(pointcloud_object) + pointcloud_object.select_set(True) + context.view_layer.objects.active = pointcloud_object + pointcloud_object.show_bounds = True + return {'FINISHED'} + classes = ( QuickExplode, QuickFur, QuickSmoke, QuickLiquid, + QuickParticles, ) diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index 8880d8c5378..0a1be2dc698 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -2751,6 +2751,8 @@ class VIEW3D_MT_object_quick_effects(Menu): layout.operator("object.quick_explode") layout.operator("object.quick_smoke") layout.operator("object.quick_liquid") + if _context.preferences.experimental.use_new_particle_system: + layout.operator("object.quick_particles") class VIEW3D_MT_object_showhide(Menu): diff --git a/source/blender/nodes/simulation/nodes/node_sim_particle_mesh_emitter.cc b/source/blender/nodes/simulation/nodes/node_sim_particle_mesh_emitter.cc index 2de7be2d3eb..859ad81656b 100644 --- a/source/blender/nodes/simulation/nodes/node_sim_particle_mesh_emitter.cc +++ b/source/blender/nodes/simulation/nodes/node_sim_particle_mesh_emitter.cc @@ -20,7 +20,7 @@ static bNodeSocketTemplate sim_node_particle_mesh_emitter_in[] = { {SOCK_OBJECT, N_("Object")}, - {SOCK_FLOAT, N_("Rate"), 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX}, + {SOCK_FLOAT, N_("Rate"), 100.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX}, {-1, ""}, }; -- cgit v1.2.3