Commit Graph

139 Commits

Author SHA1 Message Date
Jacques Lucke 396d0b5cd0 Particles: new Age Reached Event, Kill Particle and Random Float node
The hardcoded age limit is now gone. The behavior can be implemented
with an Age Reached Event and Kill Particle node. Other utility nodes
to handle age limits of particles can be added later. Adding an
Age Limit attribute to particles on birth will be useful for some effects,
e.g. when you want to control the color or size of a particle over its
life time.

The Random Float node takes a seed currently. Different nodes will
produce different values even with the same seed. However, the same
node will generate the same random number for the same seed every
time. The "Hash" of a particle can be used as seed. Later, we'd want
to have more modes in the node to make it more user friendly.
Modes could be: Per Particle, Per Time, Per Particle Per Time,
Per Node Instance, ...
Also a Random Vector node will be useful, as it currently has to be
build using three Random Float nodes.
2020-08-02 22:10:47 +02:00
Jacques Lucke 7cd2c1fd2e Particles: support custom particle events in solver
Previously, there were only particle-birth and time-step events.
Now the solver can handle custom events. On the user level
this does not change anything yet. This feature of the solver
will be used by an upcoming Age Reached Event node and
possibly others. When this node exists, I can finally remove
the hardcoded maximum particle age.
2020-08-01 21:56:05 +02:00
Jacques Lucke 9c807325dd Particles: rename Size attribute to Radius
Doing this change for consistency with the point cloud attributes.
2020-07-29 12:03:30 +02:00
Jacques Lucke 4cad74e589 Particles: add Size attribute 2020-07-29 10:05:27 +02:00
Jacques Lucke a0bc3596f0 Cleanup: class -> struct 2020-07-28 20:56:45 +02:00
Jacques Lucke 3b9e16a4f7 Particles: initial support for the Time input node 2020-07-28 12:10:37 +02:00
Jacques Lucke 38e65331a8 Particles: initial support for events and actions
The following nodes work now (although things can still be improved of course):
Particle Birth Event, Praticle Time Step Event, Set Particle Attribute and Execute Condition.

Multiple Set Particle Attribute nodes can be chained using the "Execute" sockets.
They will be executed from left to right.
2020-07-27 16:26:43 +02:00
Jacques Lucke 14326619a1 Cleanup: avoid using namespace name in many cases 2020-07-25 20:39:21 +02:00
Jacques Lucke 0ae2a1d12a Particles: improve emitter when object is animated 2020-07-25 14:51:15 +02:00
Jacques Lucke eeaa4379aa Simulation: cleanup dna data 2020-07-25 11:54:06 +02:00
Jacques Lucke 74fcb4d4c2 Particles: initial particle birth action
A particle action is some function that is triggered by some event.
Right now, users cannot control this. There is just a
randomize-velocity on-birth action. So the direction of spawned
particles is slightly randomized now.

This also adds a new integer attribute called "Hash" which is
useful for a number of things. Mainly for generating random numbers
for a specific particle. The ID of a particle is not necessarily a good source
of randomness.
2020-07-24 13:37:55 +02:00
Jacques Lucke b53c46d760 BLI: add MultiValueMap
This is a convenience wrapper for `Map<Key, Vector<Value>>`.
It does not provide any performance benefits (yet). I need this
kind of map in a couple of places and before I was duplicating
the lookup logic in many places.
2020-07-24 12:15:13 +02:00
Jacques Lucke 698af2e774 Try to fix build error
Not sure if this is the correct fix, because I can't reproduce the error.
2020-07-24 00:35:51 +02:00
Jacques Lucke 0b50ea51cc Particles: simulate partial time steps on newly emitted particles 2020-07-23 23:03:19 +02:00
Jacques Lucke f359672c35 Particles: spawn particles on mesh surface 2020-07-23 22:30:22 +02:00
Jacques Lucke 149bb0c26d Cleanup: unify naming between different spans 2020-07-23 18:07:44 +02:00
Jacques Lucke 766edbdf1f Particles: improve mesh emitter
Particles are now emitted from vertices of the mesh.
2020-07-23 17:57:11 +02:00
Jacques Lucke 634585aa68 Simulation: add depsgraph relations for ids referenced by node tree
I'll really have to refactor `ntreeUpdateTree` soon to avoid scanning
all node trees multiple times.
2020-07-23 12:09:36 +02:00
Jacques Lucke a51048a5d3 Simulation: add todo comment 2020-07-22 19:29:38 +02:00
Jacques Lucke e0400d0a1c Simulation: move responsibility of updating persistent data handles
This solver should not be responsible for updating the handles.
2020-07-22 19:16:33 +02:00
Jacques Lucke 0a5ef40c2c Simulation: fix memory leak 2020-07-22 19:16:33 +02:00
Jacques Lucke 750899fd31 Simulation: improve depsgraph integration
A simulation data block has an embedded node tree, which requires
special handling in a couple of places. Some of those places were
missing beforehand.

This also adds a relation to make sure that the simulation is evaluated
after animations on the embedded node tree are evaluated.
2020-07-22 19:16:33 +02:00
Jacques Lucke 980dd43bd4 Particles: give emitter its own state
High quality emitters need to maintain state themselves. For example,
this it needs to remember when it spawned the last particle.
This is especially important when the birth rate is changing over time.
Otherwise, there will be very visible artifacts.

It is quite likely that other components of the simulation need their own
state as well. Therefore, I refactored the `SimulationState` type a bit,
to make it more extensible. Instead of using hardcoded type numbers, a
string is used to identify the state type. Also, instead of having switch
statements in many places, there is a new `SimulationStateType` that
encapsulates information about how a specific state is created/freed/copied/...

I removed the integration with the point cache for now, because it was
not used anyway in it's current state.
2020-07-22 14:16:08 +02:00
Jacques Lucke 8369adabc0 Particles: initial object socket and emitter node support
Object sockets work now, but only the new Object Transforms and the
Particle Mesh Emitter node use it. The emitter does not actually
use the mesh surface yet. Instead, new particles are just emitted around
the origin of the object.

Internally, handles to object data blocks are passed around in the network,
instead of raw object pointers. Using handles has a couple of benefits:
* The caller of the function has control over which handles can be resolved
  and therefore limit access to specific data. The set of data blocks that
  is accessed by a node tree should be known statically. This is necessary
  for a proper integration with the dependency graph.
* When the pointer to an object changes (e.g. after restarting Blender),
  all handles are still valid.
* When an object is deleted, the handle is invalidated without causing crashes.
* The handle is just an integer that can be stored per particle and can be cached easily.

The mapping between handles and their corresponding data blocks is
stored in the Simulation data block.
2020-07-21 17:35:09 +02:00
Jacques Lucke 4f4af0cbe1 Particles: support removing particles during the simulation
This still cannot be controlled by the user. Currently, all particles are
killed after two seconds
2020-07-20 15:31:05 +02:00
Jacques Lucke 8cbbdedaf4 Refactor: Update integer type usage
This updates the usage of integer types in code I wrote according to our new style guides.

Major changes:
* Use signed instead of unsigned integers in many places.
* C++ containers in blenlib use `int64_t` for size and indices now (instead of `uint`).
* Hash values for C++ containers are 64 bit wide now (instead of 32 bit).

I do hope that I broke no builds, but it is quite likely that some compiler reports
slightly different errors. Please let me know when there are any errors. If the fix
is small, feel free to commit it yourself.
I compiled successfully on linux with gcc and on windows.
2020-07-20 12:16:20 +02:00
Jacques Lucke 3884d78e49 Particles: Make it easier to add attributes internally 2020-07-19 22:06:35 +02:00
Jacques Lucke 5063820c9b Particles: Emit particles over time
This adds a basic internal emitter for every particle simulation.
The emitter cannot be controlled by the user yet. That will
come next.
2020-07-19 13:58:58 +02:00
Jacques Lucke fe49e4139c Simulation: cleanup deduplicating attribute input nodes 2020-07-18 10:51:38 +02:00
Jacques Lucke 9eaa48f520 Simulation: cleanup how data inputs are handled 2020-07-18 10:19:26 +02:00
Jacques Lucke fd67b521b9 Simulation: deduplicate code that finds particle simulation names 2020-07-18 10:08:53 +02:00
Jacques Lucke aa8279648e Simulation: extract node tree parsing code to separate file 2020-07-17 21:20:51 +02:00
Jacques Lucke 25582aef61 Simulation: separate code from node tree parsing and solver 2020-07-17 21:20:51 +02:00
Jacques Lucke e3f8768d8a Refactor: move ParticleFunction to separate file 2020-07-17 14:23:57 +02:00
Jacques Lucke 2679236047 Cleanup: avoid static initialization order issues when accessing CPPTypes
Instead of depending on static initialization order of globals use
static variables within functions. Those are initialized on first use.
This is every so slighly less efficient, but avoids a full class of problems.
2020-07-17 14:15:06 +02:00
Jacques Lucke 3ef59121a4 Simulation: move initial simulation code from bf_blenkernel to bf_simulation
I removed bf_blenkernel from `nodes/CMakeLists.txt` again (added it yesterday),
because now this was causing me unresolved symbol errors... Without it, cmake
seems to link the libraries bf_simulation, bf_blenkernel and bf_nodes in the right
order. Not sure if that is just luck or if it is guaranteed.

It was possible to fix the issue by using cmakes `LINK_INTERFACE_MULTIPLICITY`,
but that is probably bad style.
2020-07-17 13:49:18 +02:00
Jacques Lucke 02a3720000 Simulation: rename bf_physics to bf_simulation
Also see {rB9363c4de0635394548fa2eb8d205581313029775}.
2020-07-16 18:49:59 +02:00
Jacques Lucke 9b6088cb9d Simulation: Change BPH prefix to SIM
In a previous commit the `physics` folder has been renamed to `simulation`.
This commit updates the function/file prefix accordingly.
2020-07-16 14:37:21 +02:00
Jacques Lucke 9363c4de06 Simulation: Rename `physics` directory to `simulation`
Function names will be updated in a separate commit.

This will be the place for the new particle system and other
code related to the Simulation data block. We don't want
to have all that code in blenkernel.

Approved by brecht.
2020-07-16 14:28:38 +02:00