2011-10-10 09:38:02 +00:00
|
|
|
/*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-01-07 19:13:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-27 20:40:57 +00:00
|
|
|
/** \file blender/blenkernel/intern/effect.c
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
2010-09-15 06:43:36 +00:00
|
|
|
#include <stddef.h>
|
2014-11-16 14:59:33 +01:00
|
|
|
#include <stdarg.h>
|
2009-06-22 18:19:18 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
Orange branch: Revived hidden treasure, the Groups!
Previous experiment (in 2000) didn't satisfy, it had even some primitive
NLA option in groups... so, cleaned up the old code (removed most) and
integrated it back in a more useful way.
Usage:
- CTRL+G gives menu to add group, add to existing group, or remove from
groups.
- In Object buttons, a new (should become first) Panel was added, showing
not only Object "ID button" and Parent, but also the Groups the Object
Belongs to. These buttons also allow rename, assigning or removing.
- To indicate Objects are grouped, they're drawn in a (not theme yet, so
temporal?) green wire color.
- Use ALT+SHIFT mouse-select to (de)select an entire group
But, the real power of groups is in the following features:
-> Particle Force field and Guide control
In the "Particle Motion" Panel, you can indicate a Group name, this then
limits force fields or guides to members of that Group. (Note that layers
still work on top of that... not sure about that).
-> Light Groups
In the Material "Shaders" Panel, you can indicate a Group name to limit
lighting for the Material to lamps in this group. The Lights in a Group do
need to be 'visible' for the Scene to be rendered (as usual).
-> Group Duplicator
In the Object "Anim" Panel, you can set any Object (use Empty!) to
duplicate an entire Group. It will make copies of all Objects in that Group.
Also works for animated Objects, but it will copy the current positions or
deforms. Control over 'local timing' (so we can do Massive anims!) will be
added later.
(Note; this commit won't render Group duplicators yet, a fix in bf-blender
will enable that, next commit will sync)
-> Library Appending
In the SHIFT-F1 or SHIFT+F4 browsers, you can also find the Groups listed.
By appending or linking the Group itself, and use the Group Duplicator, you
now can animate and position linked Objects. The nice thing is that the
local saved file itself will only store the Group name that was linked, so
on a next file read, the Group Objects will be re-read as stored (changed)
in the Library file.
(Note; current implementation also "gives a base" to linked Group Objects,
to show them as Objects in the current Scene. Need that now for testing
purposes, but probably will be removed later).
-> Outliner
Outliner now shows Groups as optio too, nice to organize your data a bit too!
In General, Groups have a very good potential... for example, it could
become default for MetaBall Objects too (jiri, I can help you later on how
this works). All current 'layer relationships' in Blender should be dropped
in time, I guess...
2005-12-06 10:55:30 +00:00
|
|
|
|
|
|
|
#include "DNA_curve_types.h"
|
|
|
|
#include "DNA_group_types.h"
|
|
|
|
#include "DNA_listBase.h"
|
2004-03-20 22:55:42 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
Orange branch: Revived hidden treasure, the Groups!
Previous experiment (in 2000) didn't satisfy, it had even some primitive
NLA option in groups... so, cleaned up the old code (removed most) and
integrated it back in a more useful way.
Usage:
- CTRL+G gives menu to add group, add to existing group, or remove from
groups.
- In Object buttons, a new (should become first) Panel was added, showing
not only Object "ID button" and Parent, but also the Groups the Object
Belongs to. These buttons also allow rename, assigning or removing.
- To indicate Objects are grouped, they're drawn in a (not theme yet, so
temporal?) green wire color.
- Use ALT+SHIFT mouse-select to (de)select an entire group
But, the real power of groups is in the following features:
-> Particle Force field and Guide control
In the "Particle Motion" Panel, you can indicate a Group name, this then
limits force fields or guides to members of that Group. (Note that layers
still work on top of that... not sure about that).
-> Light Groups
In the Material "Shaders" Panel, you can indicate a Group name to limit
lighting for the Material to lamps in this group. The Lights in a Group do
need to be 'visible' for the Scene to be rendered (as usual).
-> Group Duplicator
In the Object "Anim" Panel, you can set any Object (use Empty!) to
duplicate an entire Group. It will make copies of all Objects in that Group.
Also works for animated Objects, but it will copy the current positions or
deforms. Control over 'local timing' (so we can do Massive anims!) will be
added later.
(Note; this commit won't render Group duplicators yet, a fix in bf-blender
will enable that, next commit will sync)
-> Library Appending
In the SHIFT-F1 or SHIFT+F4 browsers, you can also find the Groups listed.
By appending or linking the Group itself, and use the Group Duplicator, you
now can animate and position linked Objects. The nice thing is that the
local saved file itself will only store the Group name that was linked, so
on a next file read, the Group Objects will be re-read as stored (changed)
in the Library file.
(Note; current implementation also "gives a base" to linked Group Objects,
to show them as Objects in the current Scene. Need that now for testing
purposes, but probably will be removed later).
-> Outliner
Outliner now shows Groups as optio too, nice to organize your data a bit too!
In General, Groups have a very good potential... for example, it could
become default for MetaBall Objects too (jiri, I can help you later on how
this works). All current 'layer relationships' in Blender should be dropped
in time, I guess...
2005-12-06 10:55:30 +00:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_object_force.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_texture_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 22:05:47 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2012-10-12 00:18:32 +00:00
|
|
|
#include "BLI_noise.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BLI_rand.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2014-08-30 17:54:36 +02:00
|
|
|
#include "BLI_ghash.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-07-02 19:41:31 +00:00
|
|
|
#include "PIL_time.h"
|
|
|
|
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
#include "BKE_anim.h" /* needed for where_on_path */
|
2008-08-18 14:41:24 +00:00
|
|
|
#include "BKE_collision.h"
|
2013-08-19 09:25:24 +00:00
|
|
|
#include "BKE_curve.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_displist.h"
|
2005-03-27 22:42:57 +00:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2009-10-22 23:22:05 +00:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
2004-12-03 20:22:37 +00:00
|
|
|
#include "BKE_effect.h"
|
2015-01-21 14:00:59 +01:00
|
|
|
#include "BKE_global.h"
|
2015-11-09 19:47:10 +01:00
|
|
|
#include "BKE_library.h"
|
2006-12-23 11:56:22 +00:00
|
|
|
#include "BKE_modifier.h"
|
2004-12-03 20:22:37 +00:00
|
|
|
#include "BKE_object.h"
|
2006-06-17 15:14:43 +00:00
|
|
|
#include "BKE_scene.h"
|
2012-10-10 13:18:07 +00:00
|
|
|
#include "BKE_smoke.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
Phew, a lot of work, and no new features...
Main target was to make the inner rendering loop using no globals anymore.
This is essential for proper usage while raytracing, it caused a lot of
hacks in the raycode as well, which even didn't work correctly for all
situations (textures especially).
Done this by creating a new local struct RenderInput, which replaces usage
of the global struct Render R. The latter now only is used to denote
image size, viewmatrix, and the like.
Making the inner render loops using no globals caused 1000s of vars to
be changed... but the result definitely is much nicer code, which enables
making 'real' shaders in a next stage.
It also enabled me to remove the hacks from ray.c
Then i went to the task of removing redundant code. Especially the calculus
of texture coords took place (identical) in three locations.
Most obvious is the change in the unified render part, which is much less
code now; it uses the same rendering routines as normal render now.
(Note; not for halos yet!)
I also removed 6 files called 'shadowbuffer' something. This was experimen-
tal stuff from NaN days. And again saved a lot of double used code.
Finally I went over the blenkernel and blender/src calls to render stuff.
Here the same local data is used now, resulting in less dependency.
I also moved render-texture to the render module, this was still in Kernel.
(new file: texture.c)
So! After this commit I will check on the autofiles, to try to fix that.
MSVC people have to do it themselves.
This commit will need quite some testing help, but I'm around!
2003-12-21 21:52:51 +00:00
|
|
|
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 22:05:47 +00:00
|
|
|
#include "RE_render_ext.h"
|
2009-10-22 23:22:05 +00:00
|
|
|
#include "RE_shader_ext.h"
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 22:05:47 +00:00
|
|
|
|
2006-08-22 11:18:00 +00:00
|
|
|
/* fluid sim particle import */
|
2011-10-29 23:56:07 +00:00
|
|
|
#ifdef WITH_MOD_FLUID
|
2006-08-22 11:18:00 +00:00
|
|
|
#include "LBM_fluidsim.h"
|
|
|
|
#include <zlib.h>
|
|
|
|
#include <string.h>
|
2011-10-29 23:56:07 +00:00
|
|
|
#endif // WITH_MOD_FLUID
|
2006-08-22 11:18:00 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
EffectorWeights *BKE_add_effector_weights(Group *group)
|
|
|
|
{
|
|
|
|
EffectorWeights *weights = MEM_callocN(sizeof(EffectorWeights), "EffectorWeights");
|
|
|
|
int i;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (i=0; i<NUM_PFIELD_TYPES; i++)
|
2009-10-22 23:22:05 +00:00
|
|
|
weights->weight[i] = 1.0f;
|
|
|
|
|
|
|
|
weights->global_gravity = 1.0f;
|
|
|
|
|
|
|
|
weights->group = group;
|
|
|
|
|
|
|
|
return weights;
|
|
|
|
}
|
|
|
|
PartDeflect *object_add_collision_fields(int type)
|
2009-07-02 19:41:31 +00:00
|
|
|
{
|
|
|
|
PartDeflect *pd;
|
|
|
|
|
|
|
|
pd= MEM_callocN(sizeof(PartDeflect), "PartDeflect");
|
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
pd->forcefield = type;
|
2009-07-02 19:41:31 +00:00
|
|
|
pd->pdef_sbdamp = 0.1f;
|
|
|
|
pd->pdef_sbift = 0.2f;
|
|
|
|
pd->pdef_sboft = 0.02f;
|
|
|
|
pd->seed = ((unsigned int)(ceil(PIL_check_seconds_timer()))+1) % 128;
|
2009-07-15 22:58:12 +00:00
|
|
|
pd->f_strength = 1.0f;
|
2009-10-22 23:22:05 +00:00
|
|
|
pd->f_damp = 1.0f;
|
|
|
|
|
|
|
|
/* set sensible defaults based on type */
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (type) {
|
2009-10-22 23:22:05 +00:00
|
|
|
case PFIELD_VORTEX:
|
|
|
|
pd->shape = PFIELD_SHAPE_PLANE;
|
|
|
|
break;
|
|
|
|
case PFIELD_WIND:
|
|
|
|
pd->shape = PFIELD_SHAPE_PLANE;
|
|
|
|
pd->f_flow = 1.0f; /* realistic wind behavior */
|
|
|
|
break;
|
2009-12-21 11:19:07 +00:00
|
|
|
case PFIELD_TEXTURE:
|
|
|
|
pd->f_size = 1.0f;
|
|
|
|
break;
|
2012-10-10 13:18:07 +00:00
|
|
|
case PFIELD_SMOKEFLOW:
|
|
|
|
pd->f_flow = 1.0f;
|
|
|
|
break;
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
pd->flag = PFIELD_DO_LOCATION|PFIELD_DO_ROTATION;
|
2009-07-02 19:41:31 +00:00
|
|
|
|
|
|
|
return pd;
|
|
|
|
}
|
|
|
|
|
2008-04-27 18:26:20 +00:00
|
|
|
/* ***************** PARTICLES ***************** */
|
|
|
|
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
/* -------------------------- Effectors ------------------ */
|
2009-10-22 23:22:05 +00:00
|
|
|
void free_partdeflect(PartDeflect *pd)
|
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!pd)
|
2009-10-22 23:22:05 +00:00
|
|
|
return;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pd->rng)
|
2012-10-23 13:50:44 +00:00
|
|
|
BLI_rng_free(pd->rng);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
|
|
|
MEM_freeN(pd);
|
|
|
|
}
|
|
|
|
|
2016-04-13 13:41:11 +02:00
|
|
|
static EffectorCache *new_effector_cache(Scene *scene, Object *ob, PartDeflect *pd)
|
2009-10-22 23:22:05 +00:00
|
|
|
{
|
|
|
|
EffectorCache *eff = MEM_callocN(sizeof(EffectorCache), "EffectorCache");
|
|
|
|
eff->scene = scene;
|
|
|
|
eff->ob = ob;
|
|
|
|
eff->pd = pd;
|
|
|
|
eff->frame = -1;
|
|
|
|
return eff;
|
|
|
|
}
|
Fix depsgraph to compute more accurate links for collision & force.
Current implementation more or less indiscriminately links physics
objects to colliders and forces, ignoring precise details of layer
checks and collider groups. The new depsgraph seemed to lack some
such links at all. The relevant code in modifiers suffers from a
lot of duplication.
Different physics simulations use independent implementations of
collision and similar things, which results in a lot of variance:
* Cloth collides with objects on same or visible layer with dupli.
* Softbody collides with objects on same layer without dupli.
* Non-hair particles collide on same layer with dupli.
* Smoke uses same code as cloth, but needs different modifier.
* Dynamic paint "collides" with brushes on any layer without dupli.
Force fields with absorption also imply dependency on colliders:
* For most systems, colliders are selected from same layer as field.
* For non-hair particles, it uses the same exact set as the particles.
As a special quirk, smoke ignores smoke flow force fields; on the other
hand dependency on such field implies dependency on the smoke domain.
This introduces two utility functions each for old and new depsgraph
that are flexible enough to handle all these variations, and uses them
to handle particles, cloth, smoke, softbody and dynpaint.
One thing to watch out for is that depsgraph code shouldn't rely on
any properties that don't cause a graph rebuild when changed. This
was violated in the original code that was building force field links,
while taking zero field weights into account.
This change may cause new dependency cycles in cases where necessary
dependencies were missing, but may also remove cycles in situations
where unnecessary links were previously created. It's also now possible
to solve some cycles by switching to explicit groups, since they are
now properly taken into account for dependencies.
Differential Revision: https://developer.blender.org/D2141
2016-08-12 18:23:29 +03:00
|
|
|
static void add_object_to_effectors(ListBase **effectors, Scene *scene, EffectorWeights *weights, Object *ob, Object *ob_src, bool for_simulation)
|
2009-10-22 23:22:05 +00:00
|
|
|
{
|
|
|
|
EffectorCache *eff = NULL;
|
|
|
|
|
Fix depsgraph to compute more accurate links for collision & force.
Current implementation more or less indiscriminately links physics
objects to colliders and forces, ignoring precise details of layer
checks and collider groups. The new depsgraph seemed to lack some
such links at all. The relevant code in modifiers suffers from a
lot of duplication.
Different physics simulations use independent implementations of
collision and similar things, which results in a lot of variance:
* Cloth collides with objects on same or visible layer with dupli.
* Softbody collides with objects on same layer without dupli.
* Non-hair particles collide on same layer with dupli.
* Smoke uses same code as cloth, but needs different modifier.
* Dynamic paint "collides" with brushes on any layer without dupli.
Force fields with absorption also imply dependency on colliders:
* For most systems, colliders are selected from same layer as field.
* For non-hair particles, it uses the same exact set as the particles.
As a special quirk, smoke ignores smoke flow force fields; on the other
hand dependency on such field implies dependency on the smoke domain.
This introduces two utility functions each for old and new depsgraph
that are flexible enough to handle all these variations, and uses them
to handle particles, cloth, smoke, softbody and dynpaint.
One thing to watch out for is that depsgraph code shouldn't rely on
any properties that don't cause a graph rebuild when changed. This
was violated in the original code that was building force field links,
while taking zero field weights into account.
This change may cause new dependency cycles in cases where necessary
dependencies were missing, but may also remove cycles in situations
where unnecessary links were previously created. It's also now possible
to solve some cycles by switching to explicit groups, since they are
now properly taken into account for dependencies.
Differential Revision: https://developer.blender.org/D2141
2016-08-12 18:23:29 +03:00
|
|
|
if ( ob == ob_src )
|
2009-10-22 23:22:05 +00:00
|
|
|
return;
|
|
|
|
|
Fix depsgraph to compute more accurate links for collision & force.
Current implementation more or less indiscriminately links physics
objects to colliders and forces, ignoring precise details of layer
checks and collider groups. The new depsgraph seemed to lack some
such links at all. The relevant code in modifiers suffers from a
lot of duplication.
Different physics simulations use independent implementations of
collision and similar things, which results in a lot of variance:
* Cloth collides with objects on same or visible layer with dupli.
* Softbody collides with objects on same layer without dupli.
* Non-hair particles collide on same layer with dupli.
* Smoke uses same code as cloth, but needs different modifier.
* Dynamic paint "collides" with brushes on any layer without dupli.
Force fields with absorption also imply dependency on colliders:
* For most systems, colliders are selected from same layer as field.
* For non-hair particles, it uses the same exact set as the particles.
As a special quirk, smoke ignores smoke flow force fields; on the other
hand dependency on such field implies dependency on the smoke domain.
This introduces two utility functions each for old and new depsgraph
that are flexible enough to handle all these variations, and uses them
to handle particles, cloth, smoke, softbody and dynpaint.
One thing to watch out for is that depsgraph code shouldn't rely on
any properties that don't cause a graph rebuild when changed. This
was violated in the original code that was building force field links,
while taking zero field weights into account.
This change may cause new dependency cycles in cases where necessary
dependencies were missing, but may also remove cycles in situations
where unnecessary links were previously created. It's also now possible
to solve some cycles by switching to explicit groups, since they are
now properly taken into account for dependencies.
Differential Revision: https://developer.blender.org/D2141
2016-08-12 18:23:29 +03:00
|
|
|
if (for_simulation) {
|
|
|
|
if (weights->weight[ob->pd->forcefield] == 0.0f )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ob->pd->shape == PFIELD_SHAPE_POINTS && !ob->derivedFinal )
|
|
|
|
return;
|
|
|
|
}
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (*effectors == NULL)
|
2009-10-22 23:22:05 +00:00
|
|
|
*effectors = MEM_callocN(sizeof(ListBase), "effectors list");
|
|
|
|
|
2016-04-13 13:41:11 +02:00
|
|
|
eff = new_effector_cache(scene, ob, ob->pd);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2010-10-18 08:17:04 +00:00
|
|
|
/* make sure imat is up to date */
|
|
|
|
invert_m4_m4(ob->imat, ob->obmat);
|
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
BLI_addtail(*effectors, eff);
|
|
|
|
}
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
|
|
|
|
/* returns ListBase handle with objects taking part in the effecting */
|
2016-04-13 13:41:11 +02:00
|
|
|
ListBase *pdInitEffectors(Scene *scene, Object *ob_src,
|
Fix depsgraph to compute more accurate links for collision & force.
Current implementation more or less indiscriminately links physics
objects to colliders and forces, ignoring precise details of layer
checks and collider groups. The new depsgraph seemed to lack some
such links at all. The relevant code in modifiers suffers from a
lot of duplication.
Different physics simulations use independent implementations of
collision and similar things, which results in a lot of variance:
* Cloth collides with objects on same or visible layer with dupli.
* Softbody collides with objects on same layer without dupli.
* Non-hair particles collide on same layer with dupli.
* Smoke uses same code as cloth, but needs different modifier.
* Dynamic paint "collides" with brushes on any layer without dupli.
Force fields with absorption also imply dependency on colliders:
* For most systems, colliders are selected from same layer as field.
* For non-hair particles, it uses the same exact set as the particles.
As a special quirk, smoke ignores smoke flow force fields; on the other
hand dependency on such field implies dependency on the smoke domain.
This introduces two utility functions each for old and new depsgraph
that are flexible enough to handle all these variations, and uses them
to handle particles, cloth, smoke, softbody and dynpaint.
One thing to watch out for is that depsgraph code shouldn't rely on
any properties that don't cause a graph rebuild when changed. This
was violated in the original code that was building force field links,
while taking zero field weights into account.
This change may cause new dependency cycles in cases where necessary
dependencies were missing, but may also remove cycles in situations
where unnecessary links were previously created. It's also now possible
to solve some cycles by switching to explicit groups, since they are
now properly taken into account for dependencies.
Differential Revision: https://developer.blender.org/D2141
2016-08-12 18:23:29 +03:00
|
|
|
EffectorWeights *weights, bool for_simulation)
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
{
|
|
|
|
Base *base;
|
2009-10-22 23:22:05 +00:00
|
|
|
unsigned int layer= ob_src->lay;
|
|
|
|
ListBase *effectors = NULL;
|
Orange branch: Revived hidden treasure, the Groups!
Previous experiment (in 2000) didn't satisfy, it had even some primitive
NLA option in groups... so, cleaned up the old code (removed most) and
integrated it back in a more useful way.
Usage:
- CTRL+G gives menu to add group, add to existing group, or remove from
groups.
- In Object buttons, a new (should become first) Panel was added, showing
not only Object "ID button" and Parent, but also the Groups the Object
Belongs to. These buttons also allow rename, assigning or removing.
- To indicate Objects are grouped, they're drawn in a (not theme yet, so
temporal?) green wire color.
- Use ALT+SHIFT mouse-select to (de)select an entire group
But, the real power of groups is in the following features:
-> Particle Force field and Guide control
In the "Particle Motion" Panel, you can indicate a Group name, this then
limits force fields or guides to members of that Group. (Note that layers
still work on top of that... not sure about that).
-> Light Groups
In the Material "Shaders" Panel, you can indicate a Group name to limit
lighting for the Material to lamps in this group. The Lights in a Group do
need to be 'visible' for the Scene to be rendered (as usual).
-> Group Duplicator
In the Object "Anim" Panel, you can set any Object (use Empty!) to
duplicate an entire Group. It will make copies of all Objects in that Group.
Also works for animated Objects, but it will copy the current positions or
deforms. Control over 'local timing' (so we can do Massive anims!) will be
added later.
(Note; this commit won't render Group duplicators yet, a fix in bf-blender
will enable that, next commit will sync)
-> Library Appending
In the SHIFT-F1 or SHIFT+F4 browsers, you can also find the Groups listed.
By appending or linking the Group itself, and use the Group Duplicator, you
now can animate and position linked Objects. The nice thing is that the
local saved file itself will only store the Group name that was linked, so
on a next file read, the Group Objects will be re-read as stored (changed)
in the Library file.
(Note; current implementation also "gives a base" to linked Group Objects,
to show them as Objects in the current Scene. Need that now for testing
purposes, but probably will be removed later).
-> Outliner
Outliner now shows Groups as optio too, nice to organize your data a bit too!
In General, Groups have a very good potential... for example, it could
become default for MetaBall Objects too (jiri, I can help you later on how
this works). All current 'layer relationships' in Blender should be dropped
in time, I guess...
2005-12-06 10:55:30 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (weights->group) {
|
Orange branch: Revived hidden treasure, the Groups!
Previous experiment (in 2000) didn't satisfy, it had even some primitive
NLA option in groups... so, cleaned up the old code (removed most) and
integrated it back in a more useful way.
Usage:
- CTRL+G gives menu to add group, add to existing group, or remove from
groups.
- In Object buttons, a new (should become first) Panel was added, showing
not only Object "ID button" and Parent, but also the Groups the Object
Belongs to. These buttons also allow rename, assigning or removing.
- To indicate Objects are grouped, they're drawn in a (not theme yet, so
temporal?) green wire color.
- Use ALT+SHIFT mouse-select to (de)select an entire group
But, the real power of groups is in the following features:
-> Particle Force field and Guide control
In the "Particle Motion" Panel, you can indicate a Group name, this then
limits force fields or guides to members of that Group. (Note that layers
still work on top of that... not sure about that).
-> Light Groups
In the Material "Shaders" Panel, you can indicate a Group name to limit
lighting for the Material to lamps in this group. The Lights in a Group do
need to be 'visible' for the Scene to be rendered (as usual).
-> Group Duplicator
In the Object "Anim" Panel, you can set any Object (use Empty!) to
duplicate an entire Group. It will make copies of all Objects in that Group.
Also works for animated Objects, but it will copy the current positions or
deforms. Control over 'local timing' (so we can do Massive anims!) will be
added later.
(Note; this commit won't render Group duplicators yet, a fix in bf-blender
will enable that, next commit will sync)
-> Library Appending
In the SHIFT-F1 or SHIFT+F4 browsers, you can also find the Groups listed.
By appending or linking the Group itself, and use the Group Duplicator, you
now can animate and position linked Objects. The nice thing is that the
local saved file itself will only store the Group name that was linked, so
on a next file read, the Group Objects will be re-read as stored (changed)
in the Library file.
(Note; current implementation also "gives a base" to linked Group Objects,
to show them as Objects in the current Scene. Need that now for testing
purposes, but probably will be removed later).
-> Outliner
Outliner now shows Groups as optio too, nice to organize your data a bit too!
In General, Groups have a very good potential... for example, it could
become default for MetaBall Objects too (jiri, I can help you later on how
this works). All current 'layer relationships' in Blender should be dropped
in time, I guess...
2005-12-06 10:55:30 +00:00
|
|
|
GroupObject *go;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (go= weights->group->gobject.first; go; go= go->next) {
|
|
|
|
if ( (go->ob->lay & layer) ) {
|
|
|
|
if ( go->ob->pd && go->ob->pd->forcefield )
|
Fix depsgraph to compute more accurate links for collision & force.
Current implementation more or less indiscriminately links physics
objects to colliders and forces, ignoring precise details of layer
checks and collider groups. The new depsgraph seemed to lack some
such links at all. The relevant code in modifiers suffers from a
lot of duplication.
Different physics simulations use independent implementations of
collision and similar things, which results in a lot of variance:
* Cloth collides with objects on same or visible layer with dupli.
* Softbody collides with objects on same layer without dupli.
* Non-hair particles collide on same layer with dupli.
* Smoke uses same code as cloth, but needs different modifier.
* Dynamic paint "collides" with brushes on any layer without dupli.
Force fields with absorption also imply dependency on colliders:
* For most systems, colliders are selected from same layer as field.
* For non-hair particles, it uses the same exact set as the particles.
As a special quirk, smoke ignores smoke flow force fields; on the other
hand dependency on such field implies dependency on the smoke domain.
This introduces two utility functions each for old and new depsgraph
that are flexible enough to handle all these variations, and uses them
to handle particles, cloth, smoke, softbody and dynpaint.
One thing to watch out for is that depsgraph code shouldn't rely on
any properties that don't cause a graph rebuild when changed. This
was violated in the original code that was building force field links,
while taking zero field weights into account.
This change may cause new dependency cycles in cases where necessary
dependencies were missing, but may also remove cycles in situations
where unnecessary links were previously created. It's also now possible
to solve some cycles by switching to explicit groups, since they are
now properly taken into account for dependencies.
Differential Revision: https://developer.blender.org/D2141
2016-08-12 18:23:29 +03:00
|
|
|
add_object_to_effectors(&effectors, scene, weights, go->ob, ob_src, for_simulation);
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
}
|
Orange branch: Revived hidden treasure, the Groups!
Previous experiment (in 2000) didn't satisfy, it had even some primitive
NLA option in groups... so, cleaned up the old code (removed most) and
integrated it back in a more useful way.
Usage:
- CTRL+G gives menu to add group, add to existing group, or remove from
groups.
- In Object buttons, a new (should become first) Panel was added, showing
not only Object "ID button" and Parent, but also the Groups the Object
Belongs to. These buttons also allow rename, assigning or removing.
- To indicate Objects are grouped, they're drawn in a (not theme yet, so
temporal?) green wire color.
- Use ALT+SHIFT mouse-select to (de)select an entire group
But, the real power of groups is in the following features:
-> Particle Force field and Guide control
In the "Particle Motion" Panel, you can indicate a Group name, this then
limits force fields or guides to members of that Group. (Note that layers
still work on top of that... not sure about that).
-> Light Groups
In the Material "Shaders" Panel, you can indicate a Group name to limit
lighting for the Material to lamps in this group. The Lights in a Group do
need to be 'visible' for the Scene to be rendered (as usual).
-> Group Duplicator
In the Object "Anim" Panel, you can set any Object (use Empty!) to
duplicate an entire Group. It will make copies of all Objects in that Group.
Also works for animated Objects, but it will copy the current positions or
deforms. Control over 'local timing' (so we can do Massive anims!) will be
added later.
(Note; this commit won't render Group duplicators yet, a fix in bf-blender
will enable that, next commit will sync)
-> Library Appending
In the SHIFT-F1 or SHIFT+F4 browsers, you can also find the Groups listed.
By appending or linking the Group itself, and use the Group Duplicator, you
now can animate and position linked Objects. The nice thing is that the
local saved file itself will only store the Group name that was linked, so
on a next file read, the Group Objects will be re-read as stored (changed)
in the Library file.
(Note; current implementation also "gives a base" to linked Group Objects,
to show them as Objects in the current Scene. Need that now for testing
purposes, but probably will be removed later).
-> Outliner
Outliner now shows Groups as optio too, nice to organize your data a bit too!
In General, Groups have a very good potential... for example, it could
become default for MetaBall Objects too (jiri, I can help you later on how
this works). All current 'layer relationships' in Blender should be dropped
in time, I guess...
2005-12-06 10:55:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-03-24 06:18:31 +00:00
|
|
|
for (base = scene->base.first; base; base= base->next) {
|
|
|
|
if ( (base->lay & layer) ) {
|
|
|
|
if ( base->object->pd && base->object->pd->forcefield )
|
Fix depsgraph to compute more accurate links for collision & force.
Current implementation more or less indiscriminately links physics
objects to colliders and forces, ignoring precise details of layer
checks and collider groups. The new depsgraph seemed to lack some
such links at all. The relevant code in modifiers suffers from a
lot of duplication.
Different physics simulations use independent implementations of
collision and similar things, which results in a lot of variance:
* Cloth collides with objects on same or visible layer with dupli.
* Softbody collides with objects on same layer without dupli.
* Non-hair particles collide on same layer with dupli.
* Smoke uses same code as cloth, but needs different modifier.
* Dynamic paint "collides" with brushes on any layer without dupli.
Force fields with absorption also imply dependency on colliders:
* For most systems, colliders are selected from same layer as field.
* For non-hair particles, it uses the same exact set as the particles.
As a special quirk, smoke ignores smoke flow force fields; on the other
hand dependency on such field implies dependency on the smoke domain.
This introduces two utility functions each for old and new depsgraph
that are flexible enough to handle all these variations, and uses them
to handle particles, cloth, smoke, softbody and dynpaint.
One thing to watch out for is that depsgraph code shouldn't rely on
any properties that don't cause a graph rebuild when changed. This
was violated in the original code that was building force field links,
while taking zero field weights into account.
This change may cause new dependency cycles in cases where necessary
dependencies were missing, but may also remove cycles in situations
where unnecessary links were previously created. It's also now possible
to solve some cycles by switching to explicit groups, since they are
now properly taken into account for dependencies.
Differential Revision: https://developer.blender.org/D2141
2016-08-12 18:23:29 +03:00
|
|
|
add_object_to_effectors(&effectors, scene, weights, base->object, ob_src, for_simulation);
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-14 12:54:42 +01:00
|
|
|
|
Fix depsgraph to compute more accurate links for collision & force.
Current implementation more or less indiscriminately links physics
objects to colliders and forces, ignoring precise details of layer
checks and collider groups. The new depsgraph seemed to lack some
such links at all. The relevant code in modifiers suffers from a
lot of duplication.
Different physics simulations use independent implementations of
collision and similar things, which results in a lot of variance:
* Cloth collides with objects on same or visible layer with dupli.
* Softbody collides with objects on same layer without dupli.
* Non-hair particles collide on same layer with dupli.
* Smoke uses same code as cloth, but needs different modifier.
* Dynamic paint "collides" with brushes on any layer without dupli.
Force fields with absorption also imply dependency on colliders:
* For most systems, colliders are selected from same layer as field.
* For non-hair particles, it uses the same exact set as the particles.
As a special quirk, smoke ignores smoke flow force fields; on the other
hand dependency on such field implies dependency on the smoke domain.
This introduces two utility functions each for old and new depsgraph
that are flexible enough to handle all these variations, and uses them
to handle particles, cloth, smoke, softbody and dynpaint.
One thing to watch out for is that depsgraph code shouldn't rely on
any properties that don't cause a graph rebuild when changed. This
was violated in the original code that was building force field links,
while taking zero field weights into account.
This change may cause new dependency cycles in cases where necessary
dependencies were missing, but may also remove cycles in situations
where unnecessary links were previously created. It's also now possible
to solve some cycles by switching to explicit groups, since they are
now properly taken into account for dependencies.
Differential Revision: https://developer.blender.org/D2141
2016-08-12 18:23:29 +03:00
|
|
|
if (for_simulation)
|
2014-02-14 12:54:42 +01:00
|
|
|
pdPrecalculateEffectors(effectors);
|
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
return effectors;
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
}
|
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
void pdEndEffectors(ListBase **effectors)
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (*effectors) {
|
2009-10-22 23:22:05 +00:00
|
|
|
EffectorCache *eff = (*effectors)->first;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (; eff; eff=eff->next) {
|
|
|
|
if (eff->guide_data)
|
2009-10-22 23:22:05 +00:00
|
|
|
MEM_freeN(eff->guide_data);
|
2008-08-18 11:09:27 +00:00
|
|
|
}
|
2005-11-17 21:10:16 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
BLI_freelistN(*effectors);
|
|
|
|
MEM_freeN(*effectors);
|
|
|
|
*effectors = NULL;
|
2005-11-17 21:10:16 +00:00
|
|
|
}
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
}
|
|
|
|
|
2014-02-14 12:54:42 +01:00
|
|
|
static void precalculate_effector(EffectorCache *eff)
|
|
|
|
{
|
|
|
|
unsigned int cfra = (unsigned int)(eff->scene->r.cfra >= 0 ? eff->scene->r.cfra : -eff->scene->r.cfra);
|
|
|
|
if (!eff->pd->rng)
|
|
|
|
eff->pd->rng = BLI_rng_new(eff->pd->seed + cfra);
|
|
|
|
else
|
|
|
|
BLI_rng_srandom(eff->pd->rng, eff->pd->seed + cfra);
|
|
|
|
|
|
|
|
if (eff->pd->forcefield == PFIELD_GUIDE && eff->ob->type==OB_CURVE) {
|
|
|
|
Curve *cu= eff->ob->data;
|
|
|
|
if (cu->flag & CU_PATH) {
|
|
|
|
if (eff->ob->curve_cache == NULL || eff->ob->curve_cache->path==NULL || eff->ob->curve_cache->path->data==NULL)
|
|
|
|
BKE_displist_make_curveTypes(eff->scene, eff->ob, 0);
|
|
|
|
|
|
|
|
if (eff->ob->curve_cache->path && eff->ob->curve_cache->path->data) {
|
|
|
|
where_on_path(eff->ob, 0.0, eff->guide_loc, eff->guide_dir, NULL, &eff->guide_radius, NULL);
|
|
|
|
mul_m4_v3(eff->ob->obmat, eff->guide_loc);
|
|
|
|
mul_mat3_m4_v3(eff->ob->obmat, eff->guide_dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (eff->pd->shape == PFIELD_SHAPE_SURFACE) {
|
|
|
|
eff->surmd = (SurfaceModifierData *)modifiers_findByType( eff->ob, eModifierType_Surface );
|
|
|
|
if (eff->ob->type == OB_CURVE)
|
|
|
|
eff->flag |= PE_USE_NORMAL_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store object velocity */
|
|
|
|
if (eff->ob) {
|
|
|
|
float old_vel[3];
|
|
|
|
|
|
|
|
BKE_object_where_is_calc_time(eff->scene, eff->ob, cfra - 1.0f);
|
|
|
|
copy_v3_v3(old_vel, eff->ob->obmat[3]);
|
|
|
|
BKE_object_where_is_calc_time(eff->scene, eff->ob, cfra);
|
|
|
|
sub_v3_v3v3(eff->velocity, eff->ob->obmat[3], old_vel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pdPrecalculateEffectors(ListBase *effectors)
|
|
|
|
{
|
|
|
|
if (effectors) {
|
|
|
|
EffectorCache *eff = effectors->first;
|
|
|
|
for (; eff; eff=eff->next)
|
|
|
|
precalculate_effector(eff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
void pd_point_from_loc(Scene *scene, float *loc, float *vel, int index, EffectedPoint *point)
|
|
|
|
{
|
|
|
|
point->loc = loc;
|
|
|
|
point->vel = vel;
|
|
|
|
point->index = index;
|
|
|
|
point->size = 0.0f;
|
|
|
|
|
|
|
|
point->vel_to_sec = (float)scene->r.frs_sec;
|
|
|
|
point->vel_to_frame = 1.0f;
|
|
|
|
|
|
|
|
point->flag = 0;
|
|
|
|
|
|
|
|
point->ave = point->rot = NULL;
|
|
|
|
}
|
|
|
|
void pd_point_from_soft(Scene *scene, float *loc, float *vel, int index, EffectedPoint *point)
|
|
|
|
{
|
|
|
|
point->loc = loc;
|
|
|
|
point->vel = vel;
|
|
|
|
point->index = index;
|
|
|
|
point->size = 0.0f;
|
|
|
|
|
|
|
|
point->vel_to_sec = (float)scene->r.frs_sec;
|
|
|
|
point->vel_to_frame = 1.0f;
|
|
|
|
|
|
|
|
point->flag = PE_WIND_AS_SPEED;
|
|
|
|
|
|
|
|
point->ave = point->rot = NULL;
|
|
|
|
}
|
2008-08-18 11:09:27 +00:00
|
|
|
/************************************************/
|
|
|
|
/* Effectors */
|
|
|
|
/************************************************/
|
|
|
|
|
2008-08-19 11:26:18 +00:00
|
|
|
// triangle - ray callback function
|
2010-10-16 14:32:17 +00:00
|
|
|
static void eff_tri_ray_hit(void *UNUSED(userData), int UNUSED(index), const BVHTreeRay *UNUSED(ray), BVHTreeRayHit *hit)
|
2008-08-19 11:26:18 +00:00
|
|
|
{
|
2012-07-07 22:51:57 +00:00
|
|
|
/* whenever we hit a bounding box, we don't check further */
|
2008-08-19 11:26:18 +00:00
|
|
|
hit->dist = -1;
|
|
|
|
hit->index = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get visibility of a wind ray
|
2009-10-22 23:22:05 +00:00
|
|
|
static float eff_calc_visibility(ListBase *colliders, EffectorCache *eff, EffectorData *efd, EffectedPoint *point)
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
{
|
2015-08-21 17:46:23 +10:00
|
|
|
const int raycast_flag = BVH_RAYCAST_DEFAULT & ~(BVH_RAYCAST_WATERTIGHT);
|
2009-10-22 23:22:05 +00:00
|
|
|
ListBase *colls = colliders;
|
|
|
|
ColliderCache *col;
|
2008-08-19 11:26:18 +00:00
|
|
|
float norm[3], len = 0.0;
|
2009-10-22 23:22:05 +00:00
|
|
|
float visibility = 1.0, absorption = 0.0;
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!(eff->pd->flag & PFIELD_VISIBILITY))
|
2009-10-22 23:22:05 +00:00
|
|
|
return visibility;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!colls)
|
2010-12-10 08:29:46 +00:00
|
|
|
colls = get_collider_cache(eff->scene, eff->ob, NULL);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!colls)
|
2009-10-22 23:22:05 +00:00
|
|
|
return visibility;
|
2010-07-26 06:34:56 +00:00
|
|
|
|
|
|
|
negate_v3_v3(norm, efd->vec_to_point);
|
2009-11-10 20:43:45 +00:00
|
|
|
len = normalize_v3(norm);
|
2008-08-19 11:26:18 +00:00
|
|
|
|
2012-07-07 22:51:57 +00:00
|
|
|
/* check all collision objects */
|
2012-04-28 06:31:57 +00:00
|
|
|
for (col = colls->first; col; col = col->next) {
|
2009-10-22 23:22:05 +00:00
|
|
|
CollisionModifierData *collmd = col->collmd;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (col->ob == eff->ob)
|
2009-10-22 23:22:05 +00:00
|
|
|
continue;
|
2012-07-07 22:51:57 +00:00
|
|
|
|
2012-03-06 18:40:15 +00:00
|
|
|
if (collmd->bvhtree) {
|
2008-08-19 11:26:18 +00:00
|
|
|
BVHTreeRayHit hit;
|
2012-07-07 22:51:57 +00:00
|
|
|
|
2008-08-19 11:26:18 +00:00
|
|
|
hit.index = -1;
|
|
|
|
hit.dist = len + FLT_EPSILON;
|
2012-07-07 22:51:57 +00:00
|
|
|
|
|
|
|
/* check if the way is blocked */
|
2015-08-21 17:46:23 +10:00
|
|
|
if (BLI_bvhtree_ray_cast_ex(
|
|
|
|
collmd->bvhtree, point->loc, norm, 0.0f, &hit,
|
|
|
|
eff_tri_ray_hit, NULL, raycast_flag) != -1)
|
|
|
|
{
|
2009-10-22 23:22:05 +00:00
|
|
|
absorption= col->ob->pd->absorption;
|
|
|
|
|
2012-07-07 22:51:57 +00:00
|
|
|
/* visibility is only between 0 and 1, calculated from 1-absorption */
|
2009-10-22 23:22:05 +00:00
|
|
|
visibility *= CLAMPIS(1.0f-absorption, 0.0f, 1.0f);
|
2008-08-19 11:26:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (visibility <= 0.0f)
|
2008-08-19 11:26:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!colliders)
|
2009-10-22 23:22:05 +00:00
|
|
|
free_collider_cache(&colls);
|
2008-08-19 11:26:18 +00:00
|
|
|
|
|
|
|
return visibility;
|
|
|
|
}
|
|
|
|
|
2008-08-18 11:09:27 +00:00
|
|
|
// noise function for wind e.g.
|
|
|
|
static float wind_func(struct RNG *rng, float strength)
|
|
|
|
{
|
2012-10-23 13:50:44 +00:00
|
|
|
int random = (BLI_rng_get_int(rng)+1) % 128; // max 2357
|
|
|
|
float force = BLI_rng_get_float(rng) + 1.0f;
|
2008-08-18 11:09:27 +00:00
|
|
|
float ret;
|
|
|
|
float sign = 0;
|
|
|
|
|
2011-04-02 02:08:33 +00:00
|
|
|
sign = ((float)random > 64.0f) ? 1.0f: -1.0f; // dividing by 2 is not giving equal sign distribution
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2009-06-08 20:08:19 +00:00
|
|
|
ret = sign*((float)random / force)*strength/128.0f;
|
2008-08-18 11:09:27 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
/* maxdist: zero effect from this distance outwards (if usemax) */
|
|
|
|
/* mindist: full effect up to this distance (if usemin) */
|
|
|
|
/* power: falloff with formula 1/r^power */
|
2008-08-18 11:09:27 +00:00
|
|
|
static float falloff_func(float fac, int usemin, float mindist, int usemax, float maxdist, float power)
|
|
|
|
{
|
2009-04-20 15:06:46 +00:00
|
|
|
/* first quick checks */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (usemax && fac > maxdist)
|
2009-04-20 15:06:46 +00:00
|
|
|
return 0.0f;
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (usemin && fac < mindist)
|
2008-08-18 11:09:27 +00:00
|
|
|
return 1.0f;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!usemin)
|
2009-04-20 15:06:46 +00:00
|
|
|
mindist = 0.0;
|
|
|
|
|
2011-04-02 02:08:33 +00:00
|
|
|
return pow((double)(1.0f+fac-mindist), (double)(-power));
|
2008-08-18 11:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static float falloff_func_dist(PartDeflect *pd, float fac)
|
|
|
|
{
|
|
|
|
return falloff_func(fac, pd->flag&PFIELD_USEMIN, pd->mindist, pd->flag&PFIELD_USEMAX, pd->maxdist, pd->f_power);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float falloff_func_rad(PartDeflect *pd, float fac)
|
|
|
|
{
|
|
|
|
return falloff_func(fac, pd->flag&PFIELD_USEMINR, pd->minrad, pd->flag&PFIELD_USEMAXR, pd->maxrad, pd->f_power_r);
|
|
|
|
}
|
|
|
|
|
2016-04-16 11:11:39 +02:00
|
|
|
static float effector_falloff(EffectorCache *eff, EffectorData *efd, EffectedPoint *UNUSED(point), EffectorWeights *weights)
|
2008-08-18 11:09:27 +00:00
|
|
|
{
|
2009-10-22 23:22:05 +00:00
|
|
|
float temp[3];
|
|
|
|
float falloff = weights ? weights->weight[0] * weights->weight[eff->pd->forcefield] : 1.0f;
|
|
|
|
float fac, r_fac;
|
2008-08-21 21:12:27 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
fac = dot_v3v3(efd->nor, efd->vec_to_point2);
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (eff->pd->zdir == PFIELD_Z_POS && fac < 0.0f)
|
2009-10-22 23:22:05 +00:00
|
|
|
falloff=0.0f;
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (eff->pd->zdir == PFIELD_Z_NEG && fac > 0.0f)
|
2008-08-18 11:09:27 +00:00
|
|
|
falloff=0.0f;
|
2012-04-28 06:31:57 +00:00
|
|
|
else {
|
|
|
|
switch (eff->pd->falloff) {
|
2008-08-18 11:09:27 +00:00
|
|
|
case PFIELD_FALL_SPHERE:
|
2009-10-22 23:22:05 +00:00
|
|
|
falloff*= falloff_func_dist(eff->pd, efd->distance);
|
2008-08-18 11:09:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PFIELD_FALL_TUBE:
|
2009-10-22 23:22:05 +00:00
|
|
|
falloff*= falloff_func_dist(eff->pd, ABS(fac));
|
2012-03-24 06:18:31 +00:00
|
|
|
if (falloff == 0.0f)
|
2008-08-18 11:09:27 +00:00
|
|
|
break;
|
|
|
|
|
2015-08-20 11:57:03 +02:00
|
|
|
madd_v3_v3v3fl(temp, efd->vec_to_point2, efd->nor, -fac);
|
2009-11-10 20:43:45 +00:00
|
|
|
r_fac= len_v3(temp);
|
2009-10-22 23:22:05 +00:00
|
|
|
falloff*= falloff_func_rad(eff->pd, r_fac);
|
2008-08-18 11:09:27 +00:00
|
|
|
break;
|
|
|
|
case PFIELD_FALL_CONE:
|
2009-10-22 23:22:05 +00:00
|
|
|
falloff*= falloff_func_dist(eff->pd, ABS(fac));
|
2012-03-24 06:18:31 +00:00
|
|
|
if (falloff == 0.0f)
|
2008-08-18 11:09:27 +00:00
|
|
|
break;
|
|
|
|
|
2011-09-17 09:43:51 +00:00
|
|
|
r_fac= RAD2DEGF(saacos(fac/len_v3(efd->vec_to_point)));
|
2009-10-22 23:22:05 +00:00
|
|
|
falloff*= falloff_func_rad(eff->pd, r_fac);
|
2008-08-18 11:09:27 +00:00
|
|
|
|
|
|
|
break;
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2008-08-18 11:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return falloff;
|
|
|
|
}
|
|
|
|
|
2011-11-06 15:39:20 +00:00
|
|
|
int closest_point_on_surface(SurfaceModifierData *surmd, const float co[3], float surface_co[3], float surface_nor[3], float surface_vel[3])
|
2008-08-18 11:09:27 +00:00
|
|
|
{
|
2009-10-22 23:22:05 +00:00
|
|
|
BVHTreeNearest nearest;
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
nearest.index = -1;
|
2014-02-03 02:46:45 +11:00
|
|
|
nearest.dist_sq = FLT_MAX;
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
BLI_bvhtree_find_nearest(surmd->bvhtree->tree, co, &nearest, surmd->bvhtree->nearest_callback, surmd->bvhtree);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nearest.index != -1) {
|
2011-09-12 04:14:12 +00:00
|
|
|
copy_v3_v3(surface_co, nearest.co);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (surface_nor) {
|
2011-09-12 04:14:12 +00:00
|
|
|
copy_v3_v3(surface_nor, nearest.no);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (surface_vel) {
|
2015-08-01 14:37:20 +10:00
|
|
|
const MLoop *mloop = surmd->bvhtree->loop;
|
|
|
|
const MLoopTri *lt = &surmd->bvhtree->looptri[nearest.index];
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
|
2015-08-01 14:37:20 +10:00
|
|
|
copy_v3_v3(surface_vel, surmd->v[mloop[lt->tri[0]].v].co);
|
|
|
|
add_v3_v3(surface_vel, surmd->v[mloop[lt->tri[1]].v].co);
|
|
|
|
add_v3_v3(surface_vel, surmd->v[mloop[lt->tri[2]].v].co);
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2015-08-01 14:37:20 +10:00
|
|
|
mul_v3_fl(surface_vel, (1.0f / 3.0f));
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *point, int real_velocity)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2008-08-25 11:46:55 +00:00
|
|
|
|
2016-06-01 15:26:58 +02:00
|
|
|
/* In case surface object is in Edit mode when loading the .blend, surface modifier is never executed
|
|
|
|
* and bvhtree never built, see T48415. */
|
|
|
|
if (eff->pd && eff->pd->shape==PFIELD_SHAPE_SURFACE && eff->surmd && eff->surmd->bvhtree) {
|
2009-10-22 23:22:05 +00:00
|
|
|
/* closest point in the object surface is an effector */
|
|
|
|
float vec[3];
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
/* using velocity corrected location allows for easier sliding over effector surface */
|
2009-11-10 20:43:45 +00:00
|
|
|
copy_v3_v3(vec, point->vel);
|
|
|
|
mul_v3_fl(vec, point->vel_to_frame);
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(vec, point->loc);
|
2008-08-25 11:46:55 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
ret = closest_point_on_surface(eff->surmd, vec, efd->loc, efd->nor, real_velocity ? efd->vel : NULL);
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
efd->size = 0.0f;
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (eff->pd && eff->pd->shape==PFIELD_SHAPE_POINTS) {
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (eff->ob->derivedFinal) {
|
2009-10-22 23:22:05 +00:00
|
|
|
DerivedMesh *dm = eff->ob->derivedFinal;
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
dm->getVertCo(dm, *efd->index, efd->loc);
|
|
|
|
dm->getVertNo(dm, *efd->index, efd->nor);
|
2008-08-25 11:46:55 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_m4_v3(eff->ob->obmat, efd->loc);
|
|
|
|
mul_mat3_m4_v3(eff->ob->obmat, efd->nor);
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
normalize_v3(efd->nor);
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
efd->size = 0.0f;
|
2008-08-18 11:09:27 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
/**/
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* use center of object for distance calculus */
|
2014-09-11 12:49:46 +10:00
|
|
|
const Object *ob = eff->ob;
|
2009-10-22 23:22:05 +00:00
|
|
|
|
|
|
|
/* use z-axis as normal*/
|
2010-08-15 15:14:08 +00:00
|
|
|
normalize_v3_v3(efd->nor, ob->obmat[2]);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (eff->pd && eff->pd->shape == PFIELD_SHAPE_PLANE) {
|
2010-09-09 07:52:35 +00:00
|
|
|
float temp[3], translate[3];
|
2009-11-10 20:43:45 +00:00
|
|
|
sub_v3_v3v3(temp, point->loc, ob->obmat[3]);
|
2010-09-09 07:52:35 +00:00
|
|
|
project_v3_v3v3(translate, temp, efd->nor);
|
2011-03-29 12:50:43 +00:00
|
|
|
|
|
|
|
/* for vortex the shape chooses between old / new force */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (eff->pd->forcefield == PFIELD_VORTEX)
|
2011-03-29 12:50:43 +00:00
|
|
|
add_v3_v3v3(efd->loc, ob->obmat[3], translate);
|
|
|
|
else /* normally efd->loc is closest point on effector xy-plane */
|
|
|
|
sub_v3_v3v3(efd->loc, point->loc, translate);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-09-12 04:14:12 +00:00
|
|
|
copy_v3_v3(efd->loc, ob->obmat[3]);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
2008-08-25 11:46:55 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (real_velocity)
|
2011-07-24 17:44:22 +00:00
|
|
|
copy_v3_v3(efd->vel, eff->velocity);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
|
|
|
efd->size = 0.0f;
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ret) {
|
2009-11-10 20:43:45 +00:00
|
|
|
sub_v3_v3v3(efd->vec_to_point, point->loc, efd->loc);
|
|
|
|
efd->distance = len_v3(efd->vec_to_point);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2009-12-21 11:19:07 +00:00
|
|
|
/* rest length for harmonic effector, will have to see later if this could be extended to other effectors */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (eff->pd && eff->pd->forcefield == PFIELD_HARMONIC && eff->pd->f_size)
|
2009-12-21 11:19:07 +00:00
|
|
|
mul_v3_fl(efd->vec_to_point, (efd->distance-eff->pd->f_size)/efd->distance);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (eff->flag & PE_USE_NORMAL_DATA) {
|
2011-09-12 04:14:12 +00:00
|
|
|
copy_v3_v3(efd->vec_to_point2, efd->vec_to_point);
|
|
|
|
copy_v3_v3(efd->nor2, efd->nor);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* for some effectors we need the object center every time */
|
2009-11-10 20:43:45 +00:00
|
|
|
sub_v3_v3v3(efd->vec_to_point2, point->loc, eff->ob->obmat[3]);
|
2010-08-15 15:14:08 +00:00
|
|
|
normalize_v3_v3(efd->nor2, eff->ob->obmat[2]);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2016-04-13 13:41:11 +02:00
|
|
|
static void get_effector_tot(EffectorCache *eff, EffectorData *efd, EffectedPoint *point, int *tot, int *p)
|
2009-10-22 23:22:05 +00:00
|
|
|
{
|
2015-09-25 15:51:33 +02:00
|
|
|
*p = 0;
|
|
|
|
efd->index = p;
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2015-09-25 15:51:33 +02:00
|
|
|
if (eff->pd->shape == PFIELD_SHAPE_POINTS) {
|
2009-10-22 23:22:05 +00:00
|
|
|
*tot = eff->ob->derivedFinal ? eff->ob->derivedFinal->numVertData : 1;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (*tot && eff->pd->forcefield == PFIELD_HARMONIC && point->index >= 0) {
|
2009-10-22 23:22:05 +00:00
|
|
|
*p = point->index % *tot;
|
|
|
|
*tot = *p+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*tot = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void do_texture_effector(EffectorCache *eff, EffectorData *efd, EffectedPoint *point, float *total_force)
|
|
|
|
{
|
|
|
|
TexResult result[4];
|
|
|
|
float tex_co[3], strength, force[3];
|
|
|
|
float nabla = eff->pd->tex_nabla;
|
|
|
|
int hasrgb;
|
|
|
|
short mode = eff->pd->tex_mode;
|
Fix #36058: Displace Modifier errors using a baked Image and displace baking inconsistency between 2.67/2.68RC and previous versions
This was in fact really nasty bug, caused by multitex_nodes
function using global variable R (which is a copy of current
renderer). this variable is not initialized to anything
meaningful for until first rendering (preview or final)
happened.
Since multitex_nodes might be used outside of render pipeline,
made it so whether CM is on or off as an argument to functions
multitex_ext_safe and multitex_ext. Now multitex_nodes() is
only shall be used for stuff happening from render pipeline!
Also needed to make some changes to other places, so all the
usages of texture sampling knows for the fact whether CM is
on or off.
And one more change is related on behavior of dispalcement,
wave, warp, weightvg modifiers and smoke. They'll be always
using CM off since texture is used for influence, not for
color.
It's rather bigger patch, but it's mostly straightforward
changes, which we really need to be done.
Reviewed by Brecht, thanks!
2013-07-15 14:47:58 +00:00
|
|
|
bool scene_color_manage;
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!eff->pd->tex)
|
2009-10-22 23:22:05 +00:00
|
|
|
return;
|
|
|
|
|
2011-02-13 10:52:18 +00:00
|
|
|
result[0].nor = result[1].nor = result[2].nor = result[3].nor = NULL;
|
2009-10-22 23:22:05 +00:00
|
|
|
|
|
|
|
strength= eff->pd->f_strength * efd->falloff;
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
copy_v3_v3(tex_co, point->loc);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (eff->pd->flag & PFIELD_TEX_OBJECT) {
|
2010-10-18 08:17:04 +00:00
|
|
|
mul_m4_v3(eff->ob->imat, tex_co);
|
2016-04-18 18:45:34 +03:00
|
|
|
|
|
|
|
if (eff->pd->flag & PFIELD_TEX_2D)
|
|
|
|
tex_co[2] = 0.0f;
|
|
|
|
}
|
|
|
|
else if (eff->pd->flag & PFIELD_TEX_2D) {
|
|
|
|
float fac=-dot_v3v3(tex_co, efd->nor);
|
|
|
|
madd_v3_v3fl(tex_co, efd->nor, fac);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
Fix #36058: Displace Modifier errors using a baked Image and displace baking inconsistency between 2.67/2.68RC and previous versions
This was in fact really nasty bug, caused by multitex_nodes
function using global variable R (which is a copy of current
renderer). this variable is not initialized to anything
meaningful for until first rendering (preview or final)
happened.
Since multitex_nodes might be used outside of render pipeline,
made it so whether CM is on or off as an argument to functions
multitex_ext_safe and multitex_ext. Now multitex_nodes() is
only shall be used for stuff happening from render pipeline!
Also needed to make some changes to other places, so all the
usages of texture sampling knows for the fact whether CM is
on or off.
And one more change is related on behavior of dispalcement,
wave, warp, weightvg modifiers and smoke. They'll be always
using CM off since texture is used for influence, not for
color.
It's rather bigger patch, but it's mostly straightforward
changes, which we really need to be done.
Reviewed by Brecht, thanks!
2013-07-15 14:47:58 +00:00
|
|
|
scene_color_manage = BKE_scene_check_color_management_enabled(eff->scene);
|
|
|
|
|
2016-03-03 15:59:20 +05:00
|
|
|
hasrgb = multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result, 0, NULL, scene_color_manage, false);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (hasrgb && mode==PFIELD_TEX_RGB) {
|
2009-10-22 23:22:05 +00:00
|
|
|
force[0] = (0.5f - result->tr) * strength;
|
|
|
|
force[1] = (0.5f - result->tg) * strength;
|
|
|
|
force[2] = (0.5f - result->tb) * strength;
|
|
|
|
}
|
2016-12-03 14:05:56 -02:00
|
|
|
else if (nabla != 0) {
|
2009-10-22 23:22:05 +00:00
|
|
|
strength/=nabla;
|
|
|
|
|
|
|
|
tex_co[0] += nabla;
|
2016-03-03 15:59:20 +05:00
|
|
|
multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+1, 0, NULL, scene_color_manage, false);
|
2008-08-21 21:12:27 +00:00
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
tex_co[0] -= nabla;
|
|
|
|
tex_co[1] += nabla;
|
2016-03-03 15:59:20 +05:00
|
|
|
multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+2, 0, NULL, scene_color_manage, false);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
|
|
|
tex_co[1] -= nabla;
|
|
|
|
tex_co[2] += nabla;
|
2016-03-03 15:59:20 +05:00
|
|
|
multitex_ext(eff->pd->tex, tex_co, NULL, NULL, 0, result+3, 0, NULL, scene_color_manage, false);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (mode == PFIELD_TEX_GRAD || !hasrgb) { /* if we don't have rgb fall back to grad */
|
2012-06-29 11:44:46 +00:00
|
|
|
/* generate intensity if texture only has rgb value */
|
|
|
|
if (hasrgb & TEX_RGB) {
|
|
|
|
int i;
|
|
|
|
for (i=0; i<4; i++)
|
|
|
|
result[i].tin = (1.0f / 3.0f) * (result[i].tr + result[i].tg + result[i].tb);
|
|
|
|
}
|
2009-10-22 23:22:05 +00:00
|
|
|
force[0] = (result[0].tin - result[1].tin) * strength;
|
|
|
|
force[1] = (result[0].tin - result[2].tin) * strength;
|
|
|
|
force[2] = (result[0].tin - result[3].tin) * strength;
|
|
|
|
}
|
|
|
|
else { /*PFIELD_TEX_CURL*/
|
|
|
|
float dbdy, dgdz, drdz, dbdx, dgdx, drdy;
|
|
|
|
|
|
|
|
dbdy = result[2].tb - result[0].tb;
|
|
|
|
dgdz = result[3].tg - result[0].tg;
|
|
|
|
drdz = result[3].tr - result[0].tr;
|
|
|
|
dbdx = result[1].tb - result[0].tb;
|
|
|
|
dgdx = result[1].tg - result[0].tg;
|
|
|
|
drdy = result[2].tr - result[0].tr;
|
|
|
|
|
|
|
|
force[0] = (dbdy - dgdz) * strength;
|
|
|
|
force[1] = (drdz - dbdx) * strength;
|
|
|
|
force[2] = (dgdx - drdy) * strength;
|
|
|
|
}
|
|
|
|
}
|
2016-12-03 14:05:56 -02:00
|
|
|
else {
|
|
|
|
zero_v3(force);
|
|
|
|
}
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (eff->pd->flag & PFIELD_TEX_2D) {
|
2009-11-10 20:43:45 +00:00
|
|
|
float fac = -dot_v3v3(force, efd->nor);
|
2011-11-06 15:39:20 +00:00
|
|
|
madd_v3_v3fl(force, efd->nor, fac);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(total_force, force);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
2011-02-13 10:52:18 +00:00
|
|
|
static void do_physical_effector(EffectorCache *eff, EffectorData *efd, EffectedPoint *point, float *total_force)
|
2009-10-22 23:22:05 +00:00
|
|
|
{
|
|
|
|
PartDeflect *pd = eff->pd;
|
|
|
|
RNG *rng = pd->rng;
|
2012-10-22 08:15:51 +00:00
|
|
|
float force[3] = {0, 0, 0};
|
2009-10-22 23:22:05 +00:00
|
|
|
float temp[3];
|
|
|
|
float fac;
|
|
|
|
float strength = pd->f_strength;
|
|
|
|
float damp = pd->f_damp;
|
|
|
|
float noise_factor = pd->f_noise;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (noise_factor > 0.0f) {
|
2009-10-22 23:22:05 +00:00
|
|
|
strength += wind_func(rng, noise_factor);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ELEM(pd->forcefield, PFIELD_HARMONIC, PFIELD_DRAG))
|
2009-10-22 23:22:05 +00:00
|
|
|
damp += wind_func(rng, noise_factor);
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:14:12 +00:00
|
|
|
copy_v3_v3(force, efd->vec_to_point);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (pd->forcefield) {
|
2009-10-22 23:22:05 +00:00
|
|
|
case PFIELD_WIND:
|
2011-09-12 04:14:12 +00:00
|
|
|
copy_v3_v3(force, efd->nor);
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_v3_fl(force, strength * efd->falloff);
|
2009-10-22 23:22:05 +00:00
|
|
|
break;
|
|
|
|
case PFIELD_FORCE:
|
2009-11-10 20:43:45 +00:00
|
|
|
normalize_v3(force);
|
|
|
|
mul_v3_fl(force, strength * efd->falloff);
|
2009-10-22 23:22:05 +00:00
|
|
|
break;
|
|
|
|
case PFIELD_VORTEX:
|
|
|
|
/* old vortex force */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pd->shape == PFIELD_SHAPE_POINT) {
|
2009-11-10 20:43:45 +00:00
|
|
|
cross_v3_v3v3(force, efd->nor, efd->vec_to_point);
|
|
|
|
normalize_v3(force);
|
|
|
|
mul_v3_fl(force, strength * efd->distance * efd->falloff);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* new vortex force */
|
2009-11-10 20:43:45 +00:00
|
|
|
cross_v3_v3v3(temp, efd->nor2, efd->vec_to_point2);
|
|
|
|
mul_v3_fl(temp, strength * efd->falloff);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
cross_v3_v3v3(force, efd->nor2, temp);
|
|
|
|
mul_v3_fl(force, strength * efd->falloff);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2011-11-06 15:39:20 +00:00
|
|
|
madd_v3_v3fl(temp, point->vel, -point->vel_to_sec);
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(force, temp);
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
}
|
2009-10-22 23:22:05 +00:00
|
|
|
break;
|
|
|
|
case PFIELD_MAGNET:
|
2012-03-24 06:18:31 +00:00
|
|
|
if (eff->pd->shape == PFIELD_SHAPE_POINT)
|
2009-10-22 23:22:05 +00:00
|
|
|
/* magnetic field of a moving charge */
|
2009-11-10 20:43:45 +00:00
|
|
|
cross_v3_v3v3(temp, efd->nor, efd->vec_to_point);
|
2008-08-21 21:12:27 +00:00
|
|
|
else
|
2009-11-10 20:43:45 +00:00
|
|
|
copy_v3_v3(temp, efd->nor);
|
2008-08-21 21:12:27 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
normalize_v3(temp);
|
|
|
|
mul_v3_fl(temp, strength * efd->falloff);
|
|
|
|
cross_v3_v3v3(force, point->vel, temp);
|
|
|
|
mul_v3_fl(force, point->vel_to_sec);
|
2009-10-22 23:22:05 +00:00
|
|
|
break;
|
|
|
|
case PFIELD_HARMONIC:
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_v3_fl(force, -strength * efd->falloff);
|
|
|
|
copy_v3_v3(temp, point->vel);
|
2014-09-17 14:11:37 +10:00
|
|
|
mul_v3_fl(temp, -damp * 2.0f * sqrtf(fabsf(strength)) * point->vel_to_sec);
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(force, temp);
|
2009-10-22 23:22:05 +00:00
|
|
|
break;
|
|
|
|
case PFIELD_CHARGE:
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_v3_fl(force, point->charge * strength * efd->falloff);
|
2009-10-22 23:22:05 +00:00
|
|
|
break;
|
|
|
|
case PFIELD_LENNARDJ:
|
|
|
|
fac = pow((efd->size + point->size) / efd->distance, 6.0);
|
2008-08-21 21:12:27 +00:00
|
|
|
|
2011-04-02 02:08:33 +00:00
|
|
|
fac = - fac * (1.0f - fac) / efd->distance;
|
2008-08-21 21:12:27 +00:00
|
|
|
|
|
|
|
/* limit the repulsive term drastically to avoid huge forces */
|
2011-04-02 02:08:33 +00:00
|
|
|
fac = ((fac>2.0f) ? 2.0f : fac);
|
2008-08-21 21:12:27 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_v3_fl(force, strength * fac);
|
2008-08-18 11:09:27 +00:00
|
|
|
break;
|
2009-07-20 23:52:53 +00:00
|
|
|
case PFIELD_BOID:
|
|
|
|
/* Boid field is handled completely in boids code. */
|
2009-10-22 23:22:05 +00:00
|
|
|
return;
|
|
|
|
case PFIELD_TURBULENCE:
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pd->flag & PFIELD_GLOBAL_CO) {
|
2011-09-12 04:14:12 +00:00
|
|
|
copy_v3_v3(temp, point->loc);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-11-06 15:39:20 +00:00
|
|
|
add_v3_v3v3(temp, efd->vec_to_point2, efd->nor2);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
2012-04-29 15:47:02 +00:00
|
|
|
force[0] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[0], temp[1], temp[2], 2, 0, 2);
|
|
|
|
force[1] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[1], temp[2], temp[0], 2, 0, 2);
|
|
|
|
force[2] = -1.0f + 2.0f * BLI_gTurbulence(pd->f_size, temp[2], temp[0], temp[1], 2, 0, 2);
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_v3_fl(force, strength * efd->falloff);
|
2009-10-22 23:22:05 +00:00
|
|
|
break;
|
|
|
|
case PFIELD_DRAG:
|
2011-09-12 04:14:12 +00:00
|
|
|
copy_v3_v3(force, point->vel);
|
2009-11-10 20:43:45 +00:00
|
|
|
fac = normalize_v3(force) * point->vel_to_sec;
|
2009-10-22 23:22:05 +00:00
|
|
|
|
|
|
|
strength = MIN2(strength, 2.0f);
|
|
|
|
damp = MIN2(damp, 2.0f);
|
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_v3_fl(force, -efd->falloff * fac * (strength * fac + damp));
|
2009-07-20 23:52:53 +00:00
|
|
|
break;
|
2012-10-10 13:18:07 +00:00
|
|
|
case PFIELD_SMOKEFLOW:
|
|
|
|
zero_v3(force);
|
|
|
|
if (pd->f_source) {
|
|
|
|
float density;
|
|
|
|
if ((density = smoke_get_velocity_at(pd->f_source, point->loc, force)) >= 0.0f) {
|
|
|
|
float influence = strength * efd->falloff;
|
|
|
|
if (pd->flag & PFIELD_SMOKE_DENSITY)
|
|
|
|
influence *= density;
|
|
|
|
mul_v3_fl(force, influence);
|
|
|
|
/* apply flow */
|
|
|
|
madd_v3_v3fl(total_force, point->vel, -pd->f_flow * influence);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
}
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pd->flag & PFIELD_DO_LOCATION) {
|
2011-11-06 15:39:20 +00:00
|
|
|
madd_v3_v3fl(total_force, force, 1.0f/point->vel_to_sec);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2014-07-20 01:30:29 +10:00
|
|
|
if (ELEM(pd->forcefield, PFIELD_HARMONIC, PFIELD_DRAG, PFIELD_SMOKEFLOW)==0 && pd->f_flow != 0.0f) {
|
2011-11-06 15:39:20 +00:00
|
|
|
madd_v3_v3fl(total_force, point->vel, -pd->f_flow * efd->falloff);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-28 19:10:57 +00:00
|
|
|
if (point->ave)
|
|
|
|
zero_v3(point->ave);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pd->flag & PFIELD_DO_ROTATION && point->ave && point->rot) {
|
2009-10-22 23:22:05 +00:00
|
|
|
float xvec[3] = {1.0f, 0.0f, 0.0f};
|
|
|
|
float dave[3];
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_qt_v3(point->rot, xvec);
|
|
|
|
cross_v3_v3v3(dave, xvec, force);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (pd->f_flow != 0.0f) {
|
2011-11-06 15:39:20 +00:00
|
|
|
madd_v3_v3fl(dave, point->ave, -pd->f_flow * efd->falloff);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(point->ave, dave);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------- pdDoEffectors() --------
|
2012-03-03 20:19:11 +00:00
|
|
|
* generic force/speed system, now used for particles and softbodies
|
|
|
|
* scene = scene where it runs in, for time and stuff
|
|
|
|
* lb = listbase with objects that take part in effecting
|
|
|
|
* opco = global coord, as input
|
|
|
|
* force = force accumulator
|
|
|
|
* speed = actual current speed which can be altered
|
|
|
|
* cur_time = "external" time in frames, is constant for static particles
|
|
|
|
* loc_time = "local" time in frames, range <0-1> for the lifetime of particle
|
|
|
|
* par_layer = layer the caller is in
|
|
|
|
* flags = only used for softbody wind now
|
|
|
|
* guide = old speed of particle
|
|
|
|
*/
|
2009-10-22 23:22:05 +00:00
|
|
|
void pdDoEffectors(ListBase *effectors, ListBase *colliders, EffectorWeights *weights, EffectedPoint *point, float *force, float *impulse)
|
2004-07-09 14:39:06 +00:00
|
|
|
{
|
2004-07-10 09:17:25 +00:00
|
|
|
/*
|
2012-03-03 20:19:11 +00:00
|
|
|
* Modifies the force on a particle according to its
|
|
|
|
* relation with the effector object
|
|
|
|
* Different kind of effectors include:
|
|
|
|
* Forcefields: Gravity-like attractor
|
|
|
|
* (force power is related to the inverse of distance to the power of a falloff value)
|
|
|
|
* Vortex fields: swirling effectors
|
|
|
|
* (particles rotate around Z-axis of the object. otherwise, same relation as)
|
|
|
|
* (Forcefields, but this is not done through a force/acceleration)
|
|
|
|
* Guide: particles on a path
|
|
|
|
* (particles are guided along a curve bezier or old nurbs)
|
|
|
|
* (is independent of other effectors)
|
|
|
|
*/
|
2009-10-22 23:22:05 +00:00
|
|
|
EffectorCache *eff;
|
|
|
|
EffectorData efd;
|
2016-04-13 13:41:11 +02:00
|
|
|
int p=0, tot = 1;
|
2004-07-09 14:39:06 +00:00
|
|
|
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
/* Cycle through collected objects, get total of (1/(gravity_strength * dist^gravity_power)) */
|
2005-04-04 18:09:47 +00:00
|
|
|
/* Check for min distance here? (yes would be cool to add that, ton) */
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (effectors) for (eff = effectors->first; eff; eff=eff->next) {
|
The long awaited Particle patch from Janne Karhu
http://www.blender3d.org/cms/New_Particle_options_a.721.0.html
There's no doubt this patch had a lot of good ideas for features, and I
want to compliment Janne again for getting it all to work even!
A more careful review of the features and code did show however quite some
flaws and bugs... partially because the current particle code was very much
polluted already, but also because of the implementation lacked quality.
However, the patch was too good to reject, so I've fixed and recoded the
parts that needed it most. :)
Here's a list of of most evident changes in the patch;
- Guides support recoded. It was implemented as a true 'force field',
checking all Curve path points for each particle to find the closest. Was
just far too slow, and didn't support looping or bends well.
The new implementation is fast (real time) and treats the paths as actual
trajectory for the particle.
- Guides didn't integrate in the physics/speed system either, was added as
exception. Now it's integrated and can be combined with other velocities
or forces
- Use of Fields was slow code in general, made it use a Cache instead.
- The "even" distribution didn't work for Jittered sample patterns.
- The "even" or "vertexgroup" code in the main loops were badly constructed,
giving too much cpu for a simple task. Instead of going over all faces
many times, it now only does it once.
Same part of the code used a lot of temporal unneeded mallocs.
- Use of DerivedMesh or Mesh was confused, didn't work for Subsurfs in all
cases
- Support for vertex groups was slow, evaluating vertexgroups too often
- When a vertexgroup failed to read, it was wrongly handled (set to zero).
VertexGroup support now is with a name.
- Split up the too huge build_particle() call in some parts (moving new code)
- The "texture re-timing" option failed for moving Objects. The old code used
the convention that particles were added with increasing time steps.
Solved by creating a object Matrix Cache.
Also: the texture coordinates had to be corrected to become "OrCo".
- The "Disp" option only was used to draw less particles. Changed it to
actually calculate fewer particles for 3D viewing, but render all still.
So now it can be used to keep editing realtime.
Removed;
The "speed threshold" and "Tight" features were not copied over. This
resembled too much to feature overkill. Needs re-evaluation.
Also the "Deform" option was not added, I prefer to first check if the
current particle system really works for the Modifier system.
And:
- Added integration for particle force fields in the dependency graph
- Added TAB completion for vertexgroup names!
- Made the 'wait cursor' only appear when particles take more than 0.5 sec
- The particle jitter table order now is randomized too, giving much
nicer emitting of particles in large faces.
- Vortex field didn't correctly use speed/forces, so it didn't work for
collisions.
- Triangle distribution was wrong
- Removed ancient bug that applied in a *very* weird way speed and forces.
(location changes got the half force, speed the full...???)
So much... might have forgotten some notes! :)
2005-11-10 16:01:56 +00:00
|
|
|
/* object effectors were fully checked to be OK to evaluate! */
|
2004-06-26 18:18:11 +00:00
|
|
|
|
2016-04-13 13:41:11 +02:00
|
|
|
get_effector_tot(eff, &efd, point, &tot, &p);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2016-04-13 13:41:11 +02:00
|
|
|
for (; p<tot; p++) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (get_effector_data(eff, &efd, point, 0)) {
|
2009-10-22 23:22:05 +00:00
|
|
|
efd.falloff= effector_falloff(eff, &efd, point, weights);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (efd.falloff > 0.0f)
|
2009-10-22 23:22:05 +00:00
|
|
|
efd.falloff *= eff_calc_visibility(colliders, eff, &efd, point);
|
|
|
|
|
2012-10-14 13:08:19 +00:00
|
|
|
if (efd.falloff <= 0.0f) {
|
|
|
|
/* don't do anything */
|
|
|
|
}
|
|
|
|
else if (eff->pd->forcefield == PFIELD_TEXTURE) {
|
2009-10-22 23:22:05 +00:00
|
|
|
do_texture_effector(eff, &efd, point, force);
|
2012-10-14 13:08:19 +00:00
|
|
|
}
|
2009-10-22 23:22:05 +00:00
|
|
|
else {
|
2012-10-22 08:15:51 +00:00
|
|
|
float temp1[3] = {0, 0, 0}, temp2[3];
|
2011-09-12 04:14:12 +00:00
|
|
|
copy_v3_v3(temp1, force);
|
2009-10-22 23:22:05 +00:00
|
|
|
|
|
|
|
do_physical_effector(eff, &efd, point, force);
|
|
|
|
|
2012-07-07 22:51:57 +00:00
|
|
|
/* for softbody backward compatibility */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (point->flag & PE_WIND_AS_SPEED && impulse) {
|
2011-11-06 15:39:20 +00:00
|
|
|
sub_v3_v3v3(temp2, force, temp1);
|
|
|
|
sub_v3_v3v3(impulse, impulse, temp2);
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (eff->flag & PE_VELOCITY_TO_IMPULSE && impulse) {
|
2009-10-22 23:22:05 +00:00
|
|
|
/* special case for harmonic effector */
|
2011-11-06 15:39:20 +00:00
|
|
|
add_v3_v3v3(impulse, impulse, efd.vel);
|
2004-06-26 18:18:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-30 17:54:36 +02:00
|
|
|
|
|
|
|
/* ======== Simulation Debugging ======== */
|
|
|
|
|
2015-01-20 18:29:31 +01:00
|
|
|
SimDebugData *_sim_debug_data = NULL;
|
|
|
|
|
2014-11-16 14:59:33 +01:00
|
|
|
unsigned int BKE_sim_debug_data_hash(int i)
|
|
|
|
{
|
|
|
|
return BLI_ghashutil_uinthash((unsigned int)i);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int BKE_sim_debug_data_hash_combine(unsigned int kx, unsigned int ky)
|
|
|
|
{
|
|
|
|
#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
|
|
|
|
|
|
|
|
unsigned int a, b, c;
|
|
|
|
|
|
|
|
a = b = c = 0xdeadbeef + (2 << 2) + 13;
|
|
|
|
a += kx;
|
|
|
|
b += ky;
|
|
|
|
|
|
|
|
c ^= b; c -= rot(b,14);
|
|
|
|
a ^= c; a -= rot(c,11);
|
|
|
|
b ^= a; b -= rot(a,25);
|
|
|
|
c ^= b; c -= rot(b,16);
|
|
|
|
a ^= c; a -= rot(c,4);
|
|
|
|
b ^= a; b -= rot(a,14);
|
|
|
|
c ^= b; c -= rot(b,24);
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
|
|
|
#undef rot
|
|
|
|
}
|
|
|
|
|
2014-08-30 17:54:36 +02:00
|
|
|
static unsigned int debug_element_hash(const void *key)
|
|
|
|
{
|
|
|
|
const SimDebugElement *elem = key;
|
|
|
|
return elem->hash;
|
|
|
|
}
|
|
|
|
|
2015-01-19 19:14:14 +01:00
|
|
|
static bool debug_element_compare(const void *a, const void *b)
|
2014-08-30 17:54:36 +02:00
|
|
|
{
|
|
|
|
const SimDebugElement *elem1 = a;
|
|
|
|
const SimDebugElement *elem2 = b;
|
|
|
|
|
|
|
|
if (elem1->hash == elem2->hash) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_element_free(void *val)
|
|
|
|
{
|
|
|
|
SimDebugElement *elem = val;
|
|
|
|
MEM_freeN(elem);
|
|
|
|
}
|
|
|
|
|
2015-01-20 18:29:31 +01:00
|
|
|
void BKE_sim_debug_data_set_enabled(bool enable)
|
2014-08-30 17:54:36 +02:00
|
|
|
{
|
2015-01-20 18:29:31 +01:00
|
|
|
if (enable) {
|
|
|
|
if (!_sim_debug_data) {
|
|
|
|
_sim_debug_data = MEM_callocN(sizeof(SimDebugData), "sim debug data");
|
|
|
|
_sim_debug_data->gh = BLI_ghash_new(debug_element_hash, debug_element_compare, "sim debug element hash");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_sim_debug_data_free();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BKE_sim_debug_data_get_enabled(void)
|
|
|
|
{
|
|
|
|
return _sim_debug_data != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_sim_debug_data_free(void)
|
|
|
|
{
|
|
|
|
if (_sim_debug_data) {
|
|
|
|
if (_sim_debug_data->gh)
|
|
|
|
BLI_ghash_free(_sim_debug_data->gh, NULL, debug_element_free);
|
|
|
|
MEM_freeN(_sim_debug_data);
|
|
|
|
}
|
2014-08-30 17:54:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void debug_data_insert(SimDebugData *debug_data, SimDebugElement *elem)
|
|
|
|
{
|
|
|
|
SimDebugElement *old_elem = BLI_ghash_lookup(debug_data->gh, elem);
|
|
|
|
if (old_elem) {
|
|
|
|
*old_elem = *elem;
|
|
|
|
MEM_freeN(elem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
BLI_ghash_insert(debug_data->gh, elem, elem);
|
|
|
|
}
|
|
|
|
|
2016-12-20 11:01:08 +01:00
|
|
|
void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3], const char *str, float r, float g, float b, const char *category, unsigned int hash)
|
2014-08-30 17:54:36 +02:00
|
|
|
{
|
2014-11-16 14:59:33 +01:00
|
|
|
unsigned int category_hash = BLI_ghashutil_strhash_p(category);
|
2014-09-01 17:46:17 +02:00
|
|
|
SimDebugElement *elem;
|
2015-01-21 14:00:59 +01:00
|
|
|
|
|
|
|
if (!_sim_debug_data) {
|
|
|
|
if (G.debug & G_DEBUG_SIMDATA)
|
|
|
|
BKE_sim_debug_data_set_enabled(true);
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
2014-09-01 17:46:17 +02:00
|
|
|
|
|
|
|
elem = MEM_callocN(sizeof(SimDebugElement), "sim debug data element");
|
2014-11-16 14:59:33 +01:00
|
|
|
elem->type = type;
|
2014-09-02 14:10:28 +02:00
|
|
|
elem->category_hash = category_hash;
|
2014-08-30 17:54:36 +02:00
|
|
|
elem->hash = hash;
|
|
|
|
elem->color[0] = r;
|
|
|
|
elem->color[1] = g;
|
|
|
|
elem->color[2] = b;
|
2016-12-20 11:01:08 +01:00
|
|
|
if (v1)
|
|
|
|
copy_v3_v3(elem->v1, v1);
|
|
|
|
else
|
|
|
|
zero_v3(elem->v1);
|
|
|
|
if (v2)
|
|
|
|
copy_v3_v3(elem->v2, v2);
|
|
|
|
else
|
|
|
|
zero_v3(elem->v2);
|
|
|
|
if (str)
|
|
|
|
BLI_strncpy(elem->str, str, sizeof(elem->str));
|
|
|
|
else
|
|
|
|
elem->str[0] = '\0';
|
2014-08-30 17:54:36 +02:00
|
|
|
|
2015-01-20 18:29:31 +01:00
|
|
|
debug_data_insert(_sim_debug_data, elem);
|
2014-08-30 17:54:36 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 18:29:31 +01:00
|
|
|
void BKE_sim_debug_data_remove_element(unsigned int hash)
|
2014-09-01 17:46:17 +02:00
|
|
|
{
|
|
|
|
SimDebugElement dummy;
|
2015-01-20 18:29:31 +01:00
|
|
|
if (!_sim_debug_data)
|
2014-09-01 17:46:17 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
dummy.hash = hash;
|
2015-01-20 18:29:31 +01:00
|
|
|
BLI_ghash_remove(_sim_debug_data->gh, &dummy, NULL, debug_element_free);
|
2014-09-01 17:46:17 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 18:29:31 +01:00
|
|
|
void BKE_sim_debug_data_clear(void)
|
2014-08-30 17:54:36 +02:00
|
|
|
{
|
2015-01-20 18:29:31 +01:00
|
|
|
if (!_sim_debug_data)
|
2014-08-30 17:54:36 +02:00
|
|
|
return;
|
|
|
|
|
2015-01-20 18:29:31 +01:00
|
|
|
if (_sim_debug_data->gh)
|
|
|
|
BLI_ghash_clear(_sim_debug_data->gh, NULL, debug_element_free);
|
2014-08-30 17:54:36 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 18:29:31 +01:00
|
|
|
void BKE_sim_debug_data_clear_category(const char *category)
|
2014-09-02 14:10:28 +02:00
|
|
|
{
|
|
|
|
int category_hash = (int)BLI_ghashutil_strhash_p(category);
|
|
|
|
|
2015-01-20 18:29:31 +01:00
|
|
|
if (!_sim_debug_data)
|
2014-09-02 14:10:28 +02:00
|
|
|
return;
|
|
|
|
|
2015-01-20 18:29:31 +01:00
|
|
|
if (_sim_debug_data->gh) {
|
2014-09-02 14:10:28 +02:00
|
|
|
GHashIterator iter;
|
2015-01-20 18:29:31 +01:00
|
|
|
BLI_ghashIterator_init(&iter, _sim_debug_data->gh);
|
2015-01-24 01:59:09 +11:00
|
|
|
while (!BLI_ghashIterator_done(&iter)) {
|
2015-05-11 12:39:39 +10:00
|
|
|
const SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
|
2014-09-02 14:10:28 +02:00
|
|
|
BLI_ghashIterator_step(&iter); /* removing invalidates the current iterator, so step before removing */
|
|
|
|
|
|
|
|
if (elem->category_hash == category_hash)
|
2015-01-20 18:29:31 +01:00
|
|
|
BLI_ghash_remove(_sim_debug_data->gh, elem, NULL, debug_element_free);
|
2014-09-02 14:10:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|