2010-04-11 22:12:30 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 by the Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Daniel Dunbar
|
|
|
|
* Ton Roosendaal,
|
|
|
|
* Ben Batt,
|
|
|
|
* Brecht Van Lommel,
|
|
|
|
* Campbell Barton
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-02-25 13:57:17 +00:00
|
|
|
/** \file blender/modifiers/intern/MOD_particleinstance.c
|
|
|
|
* \ingroup modifiers
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-08-16 05:46:10 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
#include "BLI_listbase.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BLI_rand.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
#include "BKE_cdderivedmesh.h"
|
2014-11-17 17:45:21 +01:00
|
|
|
#include "BKE_effect.h"
|
2014-11-17 14:16:35 +01:00
|
|
|
#include "BKE_global.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_lattice.h"
|
2015-10-08 14:21:11 +02:00
|
|
|
#include "BKE_library_query.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_modifier.h"
|
|
|
|
#include "BKE_particle.h"
|
|
|
|
#include "BKE_pointcache.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "depsgraph_private.h"
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
#include "DEG_depsgraph_build.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2017-08-01 09:06:34 +10:00
|
|
|
#include "MOD_modifiertypes.h"
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
pimd->flag = eParticleInstanceFlag_Parents | eParticleInstanceFlag_Unborn |
|
|
|
|
eParticleInstanceFlag_Alive | eParticleInstanceFlag_Dead;
|
2010-04-11 22:12:30 +00:00
|
|
|
pimd->psys = 1;
|
|
|
|
pimd->position = 1.0f;
|
|
|
|
pimd->axis = 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
static void copyData(ModifierData *md, ModifierData *target)
|
|
|
|
{
|
2013-12-22 04:35:52 +11:00
|
|
|
#if 0
|
2012-05-06 13:38:33 +00:00
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *) md;
|
|
|
|
ParticleInstanceModifierData *tpimd = (ParticleInstanceModifierData *) target;
|
2013-12-22 04:35:52 +11:00
|
|
|
#endif
|
|
|
|
modifier_copyData_generic(md, target);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 03:59:19 +00:00
|
|
|
static bool isDisabled(ModifierData *md, int useRenderParams)
|
2012-10-17 09:49:32 +00:00
|
|
|
{
|
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md;
|
|
|
|
ParticleSystem *psys;
|
|
|
|
ModifierData *ob_md;
|
|
|
|
|
|
|
|
if (!pimd->ob)
|
2014-03-20 22:56:28 +11:00
|
|
|
return true;
|
2012-10-17 09:49:32 +00:00
|
|
|
|
|
|
|
psys = BLI_findlink(&pimd->ob->particlesystem, pimd->psys - 1);
|
|
|
|
if (psys == NULL)
|
2014-03-20 22:56:28 +11:00
|
|
|
return true;
|
2012-10-17 09:49:32 +00:00
|
|
|
|
|
|
|
/* If the psys modifier is disabled we cannot use its data.
|
|
|
|
* First look up the psys modifier from the object, then check if it is enabled.
|
|
|
|
*/
|
|
|
|
for (ob_md = pimd->ob->modifiers.first; ob_md; ob_md = ob_md->next) {
|
|
|
|
if (ob_md->type == eModifierType_ParticleSystem) {
|
|
|
|
ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)ob_md;
|
|
|
|
if (psmd->psys == psys) {
|
|
|
|
int required_mode;
|
|
|
|
|
|
|
|
if (useRenderParams) required_mode = eModifierMode_Render;
|
|
|
|
else required_mode = eModifierMode_Realtime;
|
|
|
|
|
|
|
|
if (!modifier_isEnabled(md->scene, ob_md, required_mode))
|
2014-03-20 22:56:28 +11:00
|
|
|
return true;
|
2012-10-17 09:49:32 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 22:56:28 +11:00
|
|
|
return false;
|
2012-10-17 09:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
static void updateDepgraph(ModifierData *md, DagForest *forest,
|
2015-03-13 11:48:04 +05:00
|
|
|
struct Main *UNUSED(bmain),
|
2012-05-06 13:38:33 +00:00
|
|
|
struct Scene *UNUSED(scene),
|
|
|
|
Object *UNUSED(ob),
|
|
|
|
DagNode *obNode)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
if (pimd->ob) {
|
|
|
|
DagNode *curNode = dag_get_node(forest, pimd->ob);
|
|
|
|
|
|
|
|
dag_add_relation(forest, curNode, obNode,
|
2012-05-06 13:38:33 +00:00
|
|
|
DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
|
|
|
|
"Particle Instance Modifier");
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
static void updateDepsgraph(ModifierData *md,
|
|
|
|
struct Main *UNUSED(bmain),
|
|
|
|
struct Scene *UNUSED(scene),
|
|
|
|
Object *UNUSED(ob),
|
|
|
|
struct DepsNodeHandle *node)
|
|
|
|
{
|
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *) md;
|
|
|
|
if (pimd->ob != NULL) {
|
|
|
|
DEG_add_object_relation(node, pimd->ob, DEG_OB_COMP_TRANSFORM, "Particle Instance Modifier");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
static void foreachObjectLink(ModifierData *md, Object *ob,
|
2012-05-06 13:38:33 +00:00
|
|
|
ObjectWalkFunc walk, void *userData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2017-01-31 09:47:59 +01:00
|
|
|
walk(userData, ob, &pimd->ob, IDWALK_CB_NOP);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
static int particle_skip(ParticleInstanceModifierData *pimd, ParticleSystem *psys, int p)
|
|
|
|
{
|
|
|
|
ParticleData *pa;
|
|
|
|
|
|
|
|
if (pimd->flag & eParticleInstanceFlag_Parents) {
|
|
|
|
if (p >= psys->totpart) {
|
|
|
|
if (psys->part->childtype == PART_CHILD_PARTICLES) {
|
|
|
|
pa = psys->particles + (psys->child + p - psys->totpart)->parent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pa = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pa = psys->particles + p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (psys->part->childtype == PART_CHILD_PARTICLES) {
|
|
|
|
pa = psys->particles + (psys->child + p)->parent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pa = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pa) {
|
|
|
|
if (pa->alive == PARS_UNBORN && (pimd->flag & eParticleInstanceFlag_Unborn) == 0) return 1;
|
|
|
|
if (pa->alive == PARS_ALIVE && (pimd->flag & eParticleInstanceFlag_Alive) == 0) return 1;
|
|
|
|
if (pa->alive == PARS_DEAD && (pimd->flag & eParticleInstanceFlag_Dead) == 0) return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
|
|
|
|
DerivedMesh *derivedData,
|
2012-05-09 15:00:26 +00:00
|
|
|
ModifierApplyFlag UNUSED(flag))
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
DerivedMesh *dm = derivedData, *result;
|
2012-05-06 13:38:33 +00:00
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
ParticleSimulationData sim;
|
2012-05-06 13:38:33 +00:00
|
|
|
ParticleSystem *psys = NULL;
|
2012-09-12 16:42:24 +00:00
|
|
|
ParticleData *pa = NULL;
|
2012-07-06 10:03:27 +00:00
|
|
|
MPoly *mpoly, *orig_mpoly;
|
|
|
|
MLoop *mloop, *orig_mloop;
|
2010-04-11 22:12:30 +00:00
|
|
|
MVert *mvert, *orig_mvert;
|
2012-09-12 23:19:08 +00:00
|
|
|
int totvert, totpoly, totloop /* , totedge */;
|
2012-09-12 16:42:24 +00:00
|
|
|
int maxvert, maxpoly, maxloop, totpart = 0, first_particle = 0;
|
|
|
|
int k, p, p_skip;
|
2012-05-06 13:38:33 +00:00
|
|
|
short track = ob->trackflag % 3, trackneg, axis = pimd->axis;
|
2015-01-20 21:06:21 +11:00
|
|
|
float max_co = 0.0, min_co = 0.0, temp_co[3];
|
2012-05-06 13:38:33 +00:00
|
|
|
float *size = NULL;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
trackneg = ((ob->trackflag > 2) ? 1 : 0);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
if (pimd->ob == ob) {
|
|
|
|
pimd->ob = NULL;
|
2010-04-11 22:12:30 +00:00
|
|
|
return derivedData;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (pimd->ob) {
|
2012-05-06 13:38:33 +00:00
|
|
|
psys = BLI_findlink(&pimd->ob->particlesystem, pimd->psys - 1);
|
|
|
|
if (psys == NULL || psys->totpart == 0)
|
2010-04-11 22:12:30 +00:00
|
|
|
return derivedData;
|
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
return derivedData;
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (pimd->flag & eParticleInstanceFlag_Parents)
|
2012-05-06 13:38:33 +00:00
|
|
|
totpart += psys->totpart;
|
2012-03-24 06:24:53 +00:00
|
|
|
if (pimd->flag & eParticleInstanceFlag_Children) {
|
2012-05-06 13:38:33 +00:00
|
|
|
if (totpart == 0)
|
|
|
|
first_particle = psys->totpart;
|
|
|
|
totpart += psys->totchild;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
if (totpart == 0)
|
2010-04-11 22:12:30 +00:00
|
|
|
return derivedData;
|
|
|
|
|
|
|
|
sim.scene = md->scene;
|
|
|
|
sim.ob = pimd->ob;
|
|
|
|
sim.psys = psys;
|
|
|
|
sim.psmd = psys_get_modifier(pimd->ob, psys);
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (pimd->flag & eParticleInstanceFlag_UseSize) {
|
2010-04-11 22:12:30 +00:00
|
|
|
float *si;
|
|
|
|
si = size = MEM_callocN(totpart * sizeof(float), "particle size array");
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (pimd->flag & eParticleInstanceFlag_Parents) {
|
2012-05-06 13:38:33 +00:00
|
|
|
for (p = 0, pa = psys->particles; p < psys->totpart; p++, pa++, si++)
|
2010-04-11 22:12:30 +00:00
|
|
|
*si = pa->size;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (pimd->flag & eParticleInstanceFlag_Children) {
|
2010-04-11 22:12:30 +00:00
|
|
|
ChildParticle *cpa = psys->child;
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
for (p = 0; p < psys->totchild; p++, cpa++, si++) {
|
2010-04-11 22:12:30 +00:00
|
|
|
*si = psys_get_child_size(psys, cpa, 0.0f, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
totvert = dm->getNumVerts(dm);
|
2012-07-06 10:03:27 +00:00
|
|
|
totpoly = dm->getNumPolys(dm);
|
|
|
|
totloop = dm->getNumLoops(dm);
|
2012-09-12 23:19:08 +00:00
|
|
|
/* totedge = dm->getNumEdges(dm); */ /* UNUSED */
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
/* count particles */
|
|
|
|
maxvert = 0;
|
|
|
|
maxpoly = 0;
|
|
|
|
maxloop = 0;
|
|
|
|
|
|
|
|
for (p = 0; p < totpart; p++) {
|
|
|
|
if (particle_skip(pimd, psys, p))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
maxvert += totvert;
|
|
|
|
maxpoly += totpoly;
|
|
|
|
maxloop += totloop;
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2013-08-19 10:11:48 +00:00
|
|
|
psys->lattice_deform_data = psys_create_lattice_deform_data(&sim);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
if (psys->flag & (PSYS_HAIR_DONE | PSYS_KEYED) || psys->pointcache->flag & PTCACHE_BAKED) {
|
2014-03-16 03:24:05 +11:00
|
|
|
float min[3], max[3];
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
dm->getMinMax(dm, min, max);
|
|
|
|
min_co = min[track];
|
|
|
|
max_co = max[track];
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
result = CDDM_from_template(dm, maxvert, 0, 0, maxloop, maxpoly);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
mvert = result->getVertArray(result);
|
|
|
|
orig_mvert = dm->getVertArray(dm);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
mpoly = result->getPolyArray(result);
|
|
|
|
orig_mpoly = dm->getPolyArray(dm);
|
|
|
|
mloop = result->getLoopArray(result);
|
|
|
|
orig_mloop = dm->getLoopArray(dm);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
for (p = 0, p_skip = 0; p < totpart; p++) {
|
2014-11-17 14:16:35 +01:00
|
|
|
float prev_dir[3];
|
|
|
|
float frame[4]; /* frame orientation quaternion */
|
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
/* skip particle? */
|
|
|
|
if (particle_skip(pimd, psys, p))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* set vertices coordinates */
|
|
|
|
for (k = 0; k < totvert; k++) {
|
|
|
|
ParticleKey state;
|
|
|
|
MVert *inMV;
|
|
|
|
MVert *mv = mvert + p_skip * totvert + k;
|
|
|
|
|
|
|
|
inMV = orig_mvert + k;
|
|
|
|
DM_copy_vert_data(dm, result, k, p_skip * totvert + k, 1);
|
|
|
|
*mv = *inMV;
|
|
|
|
|
|
|
|
/*change orientation based on object trackflag*/
|
|
|
|
copy_v3_v3(temp_co, mv->co);
|
|
|
|
mv->co[axis] = temp_co[track];
|
|
|
|
mv->co[(axis + 1) % 3] = temp_co[(track + 1) % 3];
|
|
|
|
mv->co[(axis + 2) % 3] = temp_co[(track + 2) % 3];
|
|
|
|
|
|
|
|
/* get particle state */
|
|
|
|
if ((psys->flag & (PSYS_HAIR_DONE | PSYS_KEYED) || psys->pointcache->flag & PTCACHE_BAKED) &&
|
2014-01-12 22:05:24 +11:00
|
|
|
(pimd->flag & eParticleInstanceFlag_Path))
|
2012-09-12 16:42:24 +00:00
|
|
|
{
|
|
|
|
float ran = 0.0f;
|
|
|
|
if (pimd->random_position != 0.0f) {
|
2013-04-15 23:12:40 +00:00
|
|
|
ran = pimd->random_position * BLI_hash_frand(psys->seed + p);
|
2012-09-12 16:42:24 +00:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
if (pimd->flag & eParticleInstanceFlag_KeepShape) {
|
|
|
|
state.time = pimd->position * (1.0f - ran);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
state.time = (mv->co[axis] - min_co) / (max_co - min_co) * pimd->position * (1.0f - ran);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
if (trackneg)
|
|
|
|
state.time = 1.0f - state.time;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
mv->co[axis] = 0.0;
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
psys_get_particle_on_path(&sim, first_particle + p, &state, 1);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
normalize_v3(state.vel);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2014-11-17 14:16:35 +01:00
|
|
|
/* Incrementally Rotating Frame (Bishop Frame) */
|
|
|
|
if (k == 0) {
|
2014-11-17 17:45:21 +01:00
|
|
|
float hairmat[4][4];
|
2014-11-17 14:16:35 +01:00
|
|
|
float mat[3][3];
|
|
|
|
|
2014-11-20 17:15:16 +01:00
|
|
|
if (first_particle + p < psys->totpart)
|
|
|
|
pa = psys->particles + first_particle + p;
|
|
|
|
else {
|
2014-11-21 16:00:24 +01:00
|
|
|
ChildParticle *cpa = psys->child + (p - psys->totpart);
|
2014-11-20 17:15:16 +01:00
|
|
|
pa = psys->particles + cpa->parent;
|
|
|
|
}
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
psys_mat_hair_to_global(sim.ob, sim.psmd->dm_final, sim.psys->part->from, pa, hairmat);
|
2014-11-17 17:45:21 +01:00
|
|
|
copy_m3_m4(mat, hairmat);
|
2014-11-17 14:16:35 +01:00
|
|
|
/* to quaternion */
|
|
|
|
mat3_to_quat(frame, mat);
|
|
|
|
|
|
|
|
/* note: direction is same as normal vector currently,
|
|
|
|
* but best to keep this separate so the frame can be
|
|
|
|
* rotated later if necessary
|
|
|
|
*/
|
|
|
|
copy_v3_v3(prev_dir, state.vel);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float rot[4];
|
|
|
|
|
|
|
|
/* incrementally rotate along bend direction */
|
|
|
|
rotation_between_vecs_to_quat(rot, prev_dir, state.vel);
|
|
|
|
mul_qt_qtqt(frame, rot, frame);
|
|
|
|
|
|
|
|
copy_v3_v3(prev_dir, state.vel);
|
2014-11-17 17:45:21 +01:00
|
|
|
}
|
2014-11-17 14:16:35 +01:00
|
|
|
|
|
|
|
copy_qt_qt(state.rot, frame);
|
|
|
|
#if 0
|
|
|
|
/* Absolute Frame (Frenet Frame) */
|
2012-09-12 16:42:24 +00:00
|
|
|
if (state.vel[axis] < -0.9999f || state.vel[axis] > 0.9999f) {
|
|
|
|
unit_qt(state.rot);
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-01-20 21:06:21 +11:00
|
|
|
float cross[3];
|
2012-09-12 16:42:24 +00:00
|
|
|
float temp[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
temp[axis] = 1.0f;
|
2014-11-17 14:16:35 +01:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
cross_v3_v3v3(cross, temp, state.vel);
|
2014-11-17 14:16:35 +01:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
/* state.vel[axis] is the only component surviving from a dot product with the axis */
|
|
|
|
axis_angle_to_quat(state.rot, cross, saacos(state.vel[axis]));
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
2014-11-17 14:16:35 +01:00
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
else {
|
2012-09-12 16:42:24 +00:00
|
|
|
state.time = -1.0;
|
|
|
|
psys_get_particle_state(&sim, first_particle + p, &state, 1);
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
mul_qt_v3(state.rot, mv->co);
|
|
|
|
if (pimd->flag & eParticleInstanceFlag_UseSize)
|
|
|
|
mul_v3_fl(mv->co, size[p]);
|
|
|
|
add_v3_v3(mv->co, state.co);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
/* create polys and loops */
|
|
|
|
for (k = 0; k < totpoly; k++) {
|
|
|
|
MPoly *inMP = orig_mpoly + k;
|
|
|
|
MPoly *mp = mpoly + p_skip * totpoly + k;
|
|
|
|
|
|
|
|
DM_copy_poly_data(dm, result, k, p_skip * totpoly + k, 1);
|
|
|
|
*mp = *inMP;
|
|
|
|
mp->loopstart += p_skip * totloop;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
{
|
|
|
|
MLoop *inML = orig_mloop + inMP->loopstart;
|
|
|
|
MLoop *ml = mloop + mp->loopstart;
|
|
|
|
int j = mp->totloop;
|
2012-07-06 10:03:27 +00:00
|
|
|
|
2012-09-12 16:42:24 +00:00
|
|
|
DM_copy_loop_data(dm, result, inMP->loopstart, mp->loopstart, j);
|
|
|
|
for (; j; j--, ml++, inML++) {
|
|
|
|
ml->v = inML->v + (p_skip * totvert);
|
|
|
|
}
|
2012-07-06 10:03:27 +00:00
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
2012-09-12 16:42:24 +00:00
|
|
|
|
|
|
|
p_skip++;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2012-07-06 10:03:27 +00:00
|
|
|
CDDM_calc_edges(result);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2013-08-19 10:11:48 +00:00
|
|
|
if (psys->lattice_deform_data) {
|
|
|
|
end_latt_deform(psys->lattice_deform_data);
|
|
|
|
psys->lattice_deform_data = NULL;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (size)
|
2010-04-11 22:12:30 +00:00
|
|
|
MEM_freeN(size);
|
|
|
|
|
2013-05-30 17:36:43 +00:00
|
|
|
result->dirty |= DM_DIRTY_NORMALS;
|
2010-07-19 04:44:37 +00:00
|
|
|
|
2012-01-03 15:28:53 +00:00
|
|
|
return result;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
ModifierTypeInfo modifierType_ParticleInstance = {
|
2012-10-24 05:45:54 +00:00
|
|
|
/* name */ "ParticleInstance",
|
|
|
|
/* structName */ "ParticleInstanceModifierData",
|
|
|
|
/* structSize */ sizeof(ParticleInstanceModifierData),
|
|
|
|
/* type */ eModifierTypeType_Constructive,
|
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
|
|
|
eModifierTypeFlag_SupportsMapping |
|
|
|
|
eModifierTypeFlag_SupportsEditmode |
|
|
|
|
eModifierTypeFlag_EnableInEditmode,
|
|
|
|
|
|
|
|
/* copyData */ copyData,
|
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
|
|
|
/* applyModifier */ applyModifier,
|
2013-05-02 14:42:05 +00:00
|
|
|
/* applyModifierEM */ NULL,
|
2012-10-24 05:45:54 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ NULL,
|
|
|
|
/* freeData */ NULL,
|
|
|
|
/* isDisabled */ isDisabled,
|
|
|
|
/* updateDepgraph */ updateDepgraph,
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
/* updateDepsgraph */ updateDepsgraph,
|
2013-06-02 03:59:19 +00:00
|
|
|
/* dependsOnTime */ NULL,
|
2012-10-24 05:45:54 +00:00
|
|
|
/* dependsOnNormals */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* foreachObjectLink */ foreachObjectLink,
|
2012-10-24 05:45:54 +00:00
|
|
|
/* foreachIDLink */ NULL,
|
|
|
|
/* foreachTexLink */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|