2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
2016-12-28 17:30:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BLI_listbase.h"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_matrix.h"
|
|
|
|
|
#include "BLI_math_rotation.h"
|
|
|
|
|
#include "BLI_math_vector.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BLI_rand.h"
|
2018-04-18 12:14:28 +02:00
|
|
|
#include "BLI_string.h"
|
2019-02-25 11:39:14 +01:00
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
#include "DNA_defaults.h"
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "DNA_screen_types.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "BKE_context.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_effect.h"
|
|
|
|
|
#include "BKE_lattice.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_query.h"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_modifier.h"
|
|
|
|
|
#include "BKE_particle.h"
|
|
|
|
|
#include "BKE_pointcache.h"
|
2023-09-25 17:48:21 -04:00
|
|
|
#include "BKE_screen.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
|
|
|
|
#include "UI_resources.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph_build.hh"
|
|
|
|
|
#include "DEG_depsgraph_query.hh"
|
2016-12-28 17:30:58 +01:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_modifiertypes.hh"
|
|
|
|
|
#include "MOD_ui_common.hh"
|
2018-12-30 15:14:00 +11:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void init_data(ModifierData *md)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(pimd, modifier));
|
|
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(pimd, DNA_struct_default_get(ParticleInstanceModifierData), modifier);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
|
2018-04-18 12:14:28 +02:00
|
|
|
{
|
|
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md;
|
|
|
|
|
|
|
|
|
|
if (pimd->index_layer_name[0] != '\0' || pimd->value_layer_name[0] != '\0') {
|
2022-04-20 09:10:10 -05:00
|
|
|
r_cddata_masks->lmask |= CD_MASK_PROP_BYTE_COLOR;
|
2018-04-18 12:14:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static bool is_disabled(const Scene *scene, ModifierData *md, bool use_render_params)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md;
|
|
|
|
|
ParticleSystem *psys;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-23 15:50:53 +02:00
|
|
|
/* The object type check is only needed here in case we have a placeholder
|
|
|
|
|
* object assigned (because the library containing the mesh is missing).
|
|
|
|
|
*
|
2019-08-31 01:19:22 +10:00
|
|
|
* In other cases it should be impossible to have a type mismatch.
|
2019-08-23 15:50:53 +02:00
|
|
|
*/
|
|
|
|
|
if (!pimd->ob || pimd->ob->type != OB_MESH) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return true;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
psys = static_cast<ParticleSystem *>(BLI_findlink(&pimd->ob->particlesystem, pimd->psys - 1));
|
|
|
|
|
if (psys == nullptr) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return true;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01: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.
|
|
|
|
|
*/
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (ModifierData *, ob_md, &pimd->ob->modifiers) {
|
2016-12-28 17:30:58 +01:00
|
|
|
if (ob_md->type == eModifierType_ParticleSystem) {
|
|
|
|
|
ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)ob_md;
|
|
|
|
|
if (psmd->psys == psys) {
|
|
|
|
|
int required_mode;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
if (use_render_params) {
|
2016-12-28 17:30:58 +01:00
|
|
|
required_mode = eModifierMode_Render;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2016-12-28 17:30:58 +01:00
|
|
|
required_mode = eModifierMode_Realtime;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-08 10:14:02 +02:00
|
|
|
if (!BKE_modifier_is_enabled(scene, ob_md, required_mode)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
return true;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void update_depsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md;
|
2023-01-19 15:54:47 -06:00
|
|
|
if (pimd->ob != nullptr) {
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(
|
|
|
|
|
ctx->node, pimd->ob, DEG_OB_COMP_TRANSFORM, "Particle Instance Modifier");
|
2018-04-18 13:54:02 +02:00
|
|
|
DEG_add_object_relation(
|
|
|
|
|
ctx->node, pimd->ob, DEG_OB_COMP_GEOMETRY, "Particle Instance Modifier");
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
|
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md;
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
walk(user_data, ob, (ID **)&pimd->ob, IDWALK_CB_NOP);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
static bool particle_skip(ParticleInstanceModifierData *pimd, ParticleSystem *psys, int p)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-04-18 12:14:28 +02:00
|
|
|
const bool between = (psys->part->childtype == PART_CHILD_FACES);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleData *pa;
|
2018-04-18 12:14:28 +02:00
|
|
|
int totpart, randp, minp, maxp;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
if (p >= psys->totpart) {
|
|
|
|
|
ChildParticle *cpa = psys->child + (p - psys->totpart);
|
2018-06-06 22:17:06 +02:00
|
|
|
pa = psys->particles + (between ? cpa->pa[0] : cpa->parent);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2018-04-18 12:14:28 +02:00
|
|
|
pa = psys->particles + p;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pa) {
|
2019-04-22 09:15:10 +10:00
|
|
|
if (pa->alive == PARS_UNBORN && (pimd->flag & eParticleInstanceFlag_Unborn) == 0) {
|
2018-04-18 12:14:28 +02:00
|
|
|
return true;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (pa->alive == PARS_ALIVE && (pimd->flag & eParticleInstanceFlag_Alive) == 0) {
|
2018-04-18 12:14:28 +02:00
|
|
|
return true;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (pa->alive == PARS_DEAD && (pimd->flag & eParticleInstanceFlag_Dead) == 0) {
|
2018-04-18 12:14:28 +02:00
|
|
|
return true;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2020-01-27 17:36:50 +01:00
|
|
|
if (pa->flag & (PARS_UNEXIST | PARS_NO_DISP)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
if (pimd->particle_amount == 1.0f) {
|
|
|
|
|
/* Early output, all particles are to be instanced. */
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
/* Randomly skip particles based on desired amount of visible particles. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
totpart = psys->totpart + psys->totchild;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-03 23:08:40 +10:00
|
|
|
/* TODO: make randomization optional? */
|
2023-01-19 15:54:47 -06:00
|
|
|
randp = int(psys_frand(psys, 3578 + p) * totpart) % totpart;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
minp = int(totpart * pimd->particle_offset) % (totpart + 1);
|
|
|
|
|
maxp = int(totpart * (pimd->particle_offset + pimd->particle_amount)) % (totpart + 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
if (maxp > minp) {
|
|
|
|
|
return randp < minp || randp >= maxp;
|
|
|
|
|
}
|
2020-08-07 12:40:29 +02:00
|
|
|
if (maxp < minp) {
|
2018-04-18 12:14:28 +02:00
|
|
|
return randp < minp && randp >= maxp;
|
|
|
|
|
}
|
2020-08-07 12:40:29 +02:00
|
|
|
|
|
|
|
|
return true;
|
2018-04-18 12:14:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void store_float_in_vcol(MLoopCol *vcol, float float_value)
|
|
|
|
|
{
|
2018-05-07 17:31:28 +02:00
|
|
|
const uchar value = unit_float_to_uchar_clamp(float_value);
|
2018-04-18 12:14:28 +02:00
|
|
|
vcol->r = vcol->g = vcol->b = value;
|
|
|
|
|
vcol->a = 1.0f;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2018-05-17 13:45:47 +02:00
|
|
|
Mesh *result;
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md;
|
2023-01-19 15:54:47 -06:00
|
|
|
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
|
2016-12-28 17:30:58 +01:00
|
|
|
ParticleSimulationData sim;
|
2023-01-19 15:54:47 -06:00
|
|
|
ParticleSystem *psys = nullptr;
|
|
|
|
|
ParticleData *pa = nullptr;
|
2023-07-24 22:06:55 +02:00
|
|
|
int totvert, faces_num, totloop, totedge;
|
2018-05-04 09:20:57 +02:00
|
|
|
int maxvert, maxpoly, maxloop, maxedge, part_end = 0, part_start;
|
2016-12-28 17:30:58 +01:00
|
|
|
int k, p, p_skip;
|
2018-05-01 17:33:04 +02:00
|
|
|
short track = ctx->object->trackflag % 3, trackneg, axis = pimd->axis;
|
2016-12-28 17:30:58 +01:00
|
|
|
float max_co = 0.0, min_co = 0.0, temp_co[3];
|
2023-01-19 15:54:47 -06:00
|
|
|
float *size = nullptr;
|
2018-04-18 12:14:28 +02:00
|
|
|
float spacemat[4][4];
|
|
|
|
|
const bool use_parents = pimd->flag & eParticleInstanceFlag_Parents;
|
|
|
|
|
const bool use_children = pimd->flag & eParticleInstanceFlag_Children;
|
|
|
|
|
bool between;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-01 17:33:04 +02:00
|
|
|
trackneg = ((ctx->object->trackflag > 2) ? 1 : 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-01 17:33:04 +02:00
|
|
|
if (pimd->ob == ctx->object) {
|
2023-01-19 15:54:47 -06:00
|
|
|
pimd->ob = nullptr;
|
2018-05-17 13:45:47 +02:00
|
|
|
return mesh;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pimd->ob) {
|
2023-01-19 15:54:47 -06:00
|
|
|
psys = static_cast<ParticleSystem *>(BLI_findlink(&pimd->ob->particlesystem, pimd->psys - 1));
|
|
|
|
|
if (psys == nullptr || psys->totpart == 0) {
|
2018-05-17 13:45:47 +02:00
|
|
|
return mesh;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2018-05-17 13:45:47 +02:00
|
|
|
return mesh;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
part_start = use_parents ? 0 : psys->totpart;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
part_end = 0;
|
2019-04-22 09:15:10 +10:00
|
|
|
if (use_parents) {
|
2018-04-18 12:14:28 +02:00
|
|
|
part_end += psys->totpart;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (use_children) {
|
2018-04-18 12:14:28 +02:00
|
|
|
part_end += psys->totchild;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (part_end == 0) {
|
2018-05-17 13:45:47 +02:00
|
|
|
return mesh;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-01 17:33:04 +02:00
|
|
|
sim.depsgraph = ctx->depsgraph;
|
2018-06-22 15:03:42 +02:00
|
|
|
sim.scene = scene;
|
2016-12-28 17:30:58 +01:00
|
|
|
sim.ob = pimd->ob;
|
|
|
|
|
sim.psys = psys;
|
|
|
|
|
sim.psmd = psys_get_modifier(pimd->ob, psys);
|
2018-04-18 12:14:28 +02:00
|
|
|
between = (psys->part->childtype == PART_CHILD_FACES);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pimd->flag & eParticleInstanceFlag_UseSize) {
|
|
|
|
|
float *si;
|
2023-01-19 15:54:47 -06:00
|
|
|
si = size = static_cast<float *>(MEM_calloc_arrayN(part_end, sizeof(float), __func__));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pimd->flag & eParticleInstanceFlag_Parents) {
|
2019-04-22 09:15:10 +10:00
|
|
|
for (p = 0, pa = psys->particles; p < psys->totpart; p++, pa++, si++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
*si = pa->size;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pimd->flag & eParticleInstanceFlag_Children) {
|
|
|
|
|
ChildParticle *cpa = psys->child;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
for (p = 0; p < psys->totchild; p++, cpa++, si++) {
|
2023-01-19 15:54:47 -06:00
|
|
|
*si = psys_get_child_size(psys, cpa, 0.0f, nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
switch (pimd->space) {
|
|
|
|
|
case eParticleInstanceSpace_World:
|
|
|
|
|
/* particle states are in world space already */
|
|
|
|
|
unit_m4(spacemat);
|
|
|
|
|
break;
|
|
|
|
|
case eParticleInstanceSpace_Local:
|
|
|
|
|
/* get particle states in the particle object's local space */
|
2022-10-24 14:16:37 +02:00
|
|
|
invert_m4_m4(spacemat, pimd->ob->object_to_world);
|
2018-04-18 12:14:28 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
/* should not happen */
|
|
|
|
|
BLI_assert(false);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-17 13:45:47 +02:00
|
|
|
totvert = mesh->totvert;
|
2023-07-24 22:06:55 +02:00
|
|
|
faces_num = mesh->faces_num;
|
2018-05-17 13:45:47 +02:00
|
|
|
totloop = mesh->totloop;
|
|
|
|
|
totedge = mesh->totedge;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* count particles */
|
|
|
|
|
maxvert = 0;
|
|
|
|
|
maxpoly = 0;
|
|
|
|
|
maxloop = 0;
|
2018-05-04 09:20:57 +02:00
|
|
|
maxedge = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
for (p = part_start; p < part_end; p++) {
|
2019-04-22 09:15:10 +10:00
|
|
|
if (particle_skip(pimd, psys, p)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
continue;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
maxvert += totvert;
|
2023-07-24 22:06:55 +02:00
|
|
|
maxpoly += faces_num;
|
2016-12-28 17:30:58 +01:00
|
|
|
maxloop += totloop;
|
2018-05-04 09:20:57 +02:00
|
|
|
maxedge += totedge;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-09 20:30:41 +01:00
|
|
|
psys_sim_data_init(&sim);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (psys->flag & (PSYS_HAIR_DONE | PSYS_KEYED) || psys->pointcache->flag & PTCACHE_BAKED) {
|
2023-06-16 08:08:18 -04:00
|
|
|
if (const std::optional<blender::Bounds<blender::float3>> bounds = mesh->bounds_min_max()) {
|
|
|
|
|
min_co = bounds->min[track];
|
|
|
|
|
max_co = bounds->max[track];
|
|
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-04-19 15:28:53 -04:00
|
|
|
result = BKE_mesh_new_nomain_from_template(mesh, maxvert, maxedge, maxpoly, maxloop);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
const blender::OffsetIndices orig_faces = mesh->faces();
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
const blender::Span<int> orig_corner_verts = mesh->corner_verts();
|
|
|
|
|
const blender::Span<int> orig_corner_edges = mesh->corner_edges();
|
2023-06-14 11:59:32 -04:00
|
|
|
blender::MutableSpan<blender::float3> positions = result->vert_positions_for_write();
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
blender::MutableSpan<blender::int2> edges = result->edges_for_write();
|
2023-07-24 22:06:55 +02:00
|
|
|
blender::MutableSpan<int> face_offsets = result->face_offsets_for_write();
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
blender::MutableSpan<int> corner_verts = result->corner_verts_for_write();
|
|
|
|
|
blender::MutableSpan<int> corner_edges = result->corner_edges_for_write();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
MLoopCol *mloopcols_index = static_cast<MLoopCol *>(CustomData_get_layer_named_for_write(
|
2023-07-25 21:15:52 +02:00
|
|
|
&result->loop_data, CD_PROP_BYTE_COLOR, pimd->index_layer_name, result->totloop));
|
2023-01-19 15:54:47 -06:00
|
|
|
MLoopCol *mloopcols_value = static_cast<MLoopCol *>(CustomData_get_layer_named_for_write(
|
2023-07-25 21:15:52 +02:00
|
|
|
&result->loop_data, CD_PROP_BYTE_COLOR, pimd->value_layer_name, result->totloop));
|
2023-01-19 15:54:47 -06:00
|
|
|
int *vert_part_index = nullptr;
|
|
|
|
|
float *vert_part_value = nullptr;
|
|
|
|
|
if (mloopcols_index != nullptr) {
|
|
|
|
|
vert_part_index = MEM_cnew_array<int>(maxvert, "vertex part index array");
|
2018-04-18 12:14:28 +02:00
|
|
|
}
|
|
|
|
|
if (mloopcols_value) {
|
2023-01-19 15:54:47 -06:00
|
|
|
vert_part_value = MEM_cnew_array<float>(maxvert, "vertex part value array");
|
2018-04-18 12:14:28 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
for (p = part_start, p_skip = 0; p < part_end; p++) {
|
2016-12-28 17:30:58 +01:00
|
|
|
float prev_dir[3];
|
|
|
|
|
float frame[4]; /* frame orientation quaternion */
|
2018-06-06 22:17:06 +02:00
|
|
|
float p_random = psys_frand(psys, 77091 + 283 * p);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* skip particle? */
|
2019-04-22 09:15:10 +10:00
|
|
|
if (particle_skip(pimd, psys, p)) {
|
2016-12-28 17:30:58 +01:00
|
|
|
continue;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* set vertices coordinates */
|
|
|
|
|
for (k = 0; k < totvert; k++) {
|
|
|
|
|
ParticleKey state;
|
2018-04-18 12:14:28 +02:00
|
|
|
int vindex = p_skip * totvert + k;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_copy_data(&mesh->vert_data, &result->vert_data, k, vindex, 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
if (vert_part_index != nullptr) {
|
2018-04-18 12:14:28 +02:00
|
|
|
vert_part_index[vindex] = p;
|
|
|
|
|
}
|
2023-01-19 15:54:47 -06:00
|
|
|
if (vert_part_value != nullptr) {
|
2018-04-18 12:14:28 +02:00
|
|
|
vert_part_value[vindex] = p_random;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-26 21:35:18 +10:00
|
|
|
/* Change orientation based on object trackflag. */
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
copy_v3_v3(temp_co, positions[vindex]);
|
|
|
|
|
positions[vindex][axis] = temp_co[track];
|
|
|
|
|
positions[vindex][(axis + 1) % 3] = temp_co[(track + 1) % 3];
|
|
|
|
|
positions[vindex][(axis + 2) % 3] = temp_co[(track + 2) % 3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* get particle state */
|
|
|
|
|
if ((psys->flag & (PSYS_HAIR_DONE | PSYS_KEYED) || psys->pointcache->flag & PTCACHE_BAKED) &&
|
|
|
|
|
(pimd->flag & eParticleInstanceFlag_Path))
|
|
|
|
|
{
|
|
|
|
|
float ran = 0.0f;
|
|
|
|
|
if (pimd->random_position != 0.0f) {
|
|
|
|
|
ran = pimd->random_position * BLI_hash_frand(psys->seed + p);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
if (pimd->flag & eParticleInstanceFlag_KeepShape) {
|
|
|
|
|
state.time = pimd->position * (1.0f - ran);
|
|
|
|
|
}
|
|
|
|
|
else {
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
state.time = (positions[vindex][axis] - min_co) / (max_co - min_co) * pimd->position *
|
|
|
|
|
(1.0f - ran);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (trackneg) {
|
2016-12-28 17:30:58 +01:00
|
|
|
state.time = 1.0f - state.time;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
positions[vindex][axis] = 0.0;
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-22 11:36:59 +10:00
|
|
|
psys_get_particle_on_path(&sim, p, &state, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
normalize_v3(state.vel);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* Incrementally Rotating Frame (Bishop Frame) */
|
|
|
|
|
if (k == 0) {
|
|
|
|
|
float hairmat[4][4];
|
|
|
|
|
float mat[3][3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (p < psys->totpart) {
|
2018-04-18 12:14:28 +02:00
|
|
|
pa = psys->particles + p;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
else {
|
|
|
|
|
ChildParticle *cpa = psys->child + (p - psys->totpart);
|
2018-06-06 22:17:06 +02:00
|
|
|
pa = psys->particles + (between ? cpa->pa[0] : cpa->parent);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-06-21 11:49:43 +02:00
|
|
|
psys_mat_hair_to_global(sim.ob, sim.psmd->mesh_final, sim.psys->part->from, pa, hairmat);
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_m3_m4(mat, hairmat);
|
|
|
|
|
/* to quaternion */
|
|
|
|
|
mat3_to_quat(frame, mat);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
if (pimd->rotation > 0.0f || pimd->random_rotation > 0.0f) {
|
2018-06-06 22:17:06 +02:00
|
|
|
float angle = 2.0f * M_PI *
|
|
|
|
|
(pimd->rotation +
|
|
|
|
|
pimd->random_rotation * (psys_frand(psys, 19957323 + p) - 0.5f));
|
2020-08-07 22:36:11 +10:00
|
|
|
const float eul[3] = {0.0f, 0.0f, angle};
|
2018-04-18 12:14:28 +02:00
|
|
|
float rot[4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
eul_to_quat(rot, eul);
|
|
|
|
|
mul_qt_qtqt(frame, frame, rot);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: direction is same as normal vector currently,
|
2016-12-28 17:30:58 +01:00
|
|
|
* 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];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
/* incrementally rotate along bend direction */
|
|
|
|
|
rotation_between_vecs_to_quat(rot, prev_dir, state.vel);
|
|
|
|
|
mul_qt_qtqt(frame, rot, frame);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_v3_v3(prev_dir, state.vel);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
copy_qt_qt(state.rot, frame);
|
|
|
|
|
#if 0
|
|
|
|
|
/* Absolute Frame (Frenet Frame) */
|
|
|
|
|
if (state.vel[axis] < -0.9999f || state.vel[axis] > 0.9999f) {
|
|
|
|
|
unit_qt(state.rot);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
float cross[3];
|
|
|
|
|
float temp[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
temp[axis] = 1.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
cross_v3_v3v3(cross, temp, state.vel);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01: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]));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
state.time = -1.0;
|
2023-07-22 11:36:59 +10:00
|
|
|
psys_get_particle_state(&sim, p, &state, true);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
mul_qt_v3(state.rot, positions[vindex]);
|
2019-04-22 09:15:10 +10:00
|
|
|
if (pimd->flag & eParticleInstanceFlag_UseSize) {
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
mul_v3_fl(positions[vindex], size[p]);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
add_v3_v3(positions[vindex], state.co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
mul_m4_v3(spacemat, positions[vindex]);
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-26 21:35:18 +10:00
|
|
|
/* Create edges and adjust edge vertex indices. */
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_copy_data(&mesh->edge_data, &result->edge_data, 0, p_skip * totedge, totedge);
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
blender::int2 *edge = &edges[p_skip * totedge];
|
2023-03-01 15:57:50 -05:00
|
|
|
for (k = 0; k < totedge; k++, edge++) {
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
(*edge)[0] += p_skip * totvert;
|
|
|
|
|
(*edge)[1] += p_skip * totvert;
|
2018-05-04 09:20:57 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
/* create faces and loops */
|
|
|
|
|
for (k = 0; k < faces_num; k++) {
|
|
|
|
|
const blender::IndexRange in_face = orig_faces[k];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_copy_data(&mesh->face_data, &result->face_data, k, p_skip * faces_num + k, 1);
|
2023-07-24 22:06:55 +02:00
|
|
|
const int dst_face_start = in_face.start() + p_skip * totloop;
|
|
|
|
|
face_offsets[p_skip * faces_num + k] = dst_face_start;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
{
|
2023-07-24 22:06:55 +02:00
|
|
|
int orig_corner_i = in_face.start();
|
|
|
|
|
int dst_corner_i = dst_face_start;
|
|
|
|
|
int j = in_face.size();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-07-25 15:23:56 -04:00
|
|
|
CustomData_copy_data(
|
|
|
|
|
&mesh->loop_data, &result->loop_data, in_face.start(), dst_face_start, j);
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
for (; j; j--, orig_corner_i++, dst_corner_i++) {
|
|
|
|
|
corner_verts[dst_corner_i] = orig_corner_verts[orig_corner_i] + (p_skip * totvert);
|
|
|
|
|
corner_edges[dst_corner_i] = orig_corner_edges[orig_corner_i] + (p_skip * totedge);
|
2023-09-14 10:24:29 +02:00
|
|
|
const int vert = corner_verts[dst_corner_i];
|
2023-01-19 15:54:47 -06:00
|
|
|
if (mloopcols_index != nullptr) {
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
const int part_index = vert_part_index[vert];
|
|
|
|
|
store_float_in_vcol(&mloopcols_index[dst_corner_i],
|
2023-01-19 15:54:47 -06:00
|
|
|
float(part_index) / float(psys->totpart - 1));
|
2018-04-18 12:14:28 +02:00
|
|
|
}
|
2023-01-19 15:54:47 -06:00
|
|
|
if (mloopcols_value != nullptr) {
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
const float part_value = vert_part_value[vert];
|
|
|
|
|
store_float_in_vcol(&mloopcols_value[dst_corner_i], part_value);
|
2018-04-18 12:14:28 +02:00
|
|
|
}
|
2016-12-28 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
p_skip++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-11-09 20:30:41 +01:00
|
|
|
psys_sim_data_free(&sim);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (size) {
|
2016-12-28 17:30:58 +01:00
|
|
|
MEM_freeN(size);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-04-18 12:14:28 +02:00
|
|
|
MEM_SAFE_FREE(vert_part_index);
|
|
|
|
|
MEM_SAFE_FREE(vert_part_value);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
return result;
|
|
|
|
|
}
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *row;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
2023-07-29 15:06:33 +10:00
|
|
|
const eUI_Item_Flag toggles_flag = UI_ITEM_R_TOGGLE | UI_ITEM_R_FORCE_BLANK_DECORATE;
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
PointerRNA ob_ptr;
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA particle_obj_ptr = RNA_pointer_get(ptr, "object");
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "object", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
if (!RNA_pointer_is_null(&particle_obj_ptr)) {
|
|
|
|
|
uiItemPointerR(layout,
|
2020-09-02 14:13:26 -05:00
|
|
|
ptr,
|
2020-06-05 10:41:03 -04:00
|
|
|
"particle_system",
|
|
|
|
|
&particle_obj_ptr,
|
|
|
|
|
"particle_systems",
|
2022-08-09 12:42:16 +02:00
|
|
|
IFACE_("Particle System"),
|
2020-06-05 10:41:03 -04:00
|
|
|
ICON_NONE);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(
|
|
|
|
|
layout, ptr, "particle_system_index", UI_ITEM_NONE, IFACE_("Particle System"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uiItemS(layout);
|
|
|
|
|
|
|
|
|
|
row = uiLayoutRowWithHeading(layout, true, IFACE_("Create Instances"));
|
2023-01-19 15:54:47 -06:00
|
|
|
uiItemR(row, ptr, "use_normal", toggles_flag, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(row, ptr, "use_children", toggles_flag, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(row, ptr, "use_size", toggles_flag, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
row = uiLayoutRowWithHeading(layout, true, IFACE_("Show"));
|
2023-01-19 15:54:47 -06:00
|
|
|
uiItemR(row, ptr, "show_alive", toggles_flag, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(row, ptr, "show_dead", toggles_flag, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(row, ptr, "show_unborn", toggles_flag, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "particle_amount", UI_ITEM_NONE, IFACE_("Amount"), ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "particle_offset", UI_ITEM_NONE, IFACE_("Offset"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiItemS(layout);
|
|
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "space", UI_ITEM_NONE, IFACE_("Coordinate Space"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
row = uiLayoutRow(layout, true);
|
2023-01-19 15:54:47 -06:00
|
|
|
uiItemR(row, ptr, "axis", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
modifier_panel_end(layout, ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
static void path_panel_draw_header(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, nullptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "use_path", UI_ITEM_NONE, IFACE_("Create Along Paths"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
static void path_panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *col;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
|
|
|
|
PointerRNA ob_ptr;
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
uiLayoutSetActive(layout, RNA_boolean_get(ptr, "use_path"));
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
col = uiLayoutColumn(layout, true);
|
2023-01-19 15:54:47 -06:00
|
|
|
uiItemR(col, ptr, "position", UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(col, ptr, "random_position", UI_ITEM_R_SLIDER, IFACE_("Random"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
col = uiLayoutColumn(layout, true);
|
2023-01-19 15:54:47 -06:00
|
|
|
uiItemR(col, ptr, "rotation", UI_ITEM_R_SLIDER, nullptr, ICON_NONE);
|
2020-09-02 14:13:26 -05:00
|
|
|
uiItemR(col, ptr, "random_rotation", UI_ITEM_R_SLIDER, IFACE_("Random"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "use_preserve_shape", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-19 15:54:47 -06:00
|
|
|
static void layers_panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
UI: Small Tweaks to Modifier Layouts for Consistency
These changes are smaller, made based on feedback and a pass on all
the layouts for clarity and consistency. The Multires modifier UI will
be addressed in a separate patch. Here is an overview of the changes:
Renaming Options:
- Build: "Start" -> "Start Frame"
- Curve: "From Radius" -> "Size from Radius"
- Screw: "Calc Order" -> "Calculate Order"
- Displace, Warp, Wave: "Texture Coordinates Object" -> "Object"
Move Mode Toggle to Top & Expand:
- Bevel, Boolean, Normal Edit, Subdivision
Use Columns for Tighter Spacing:
- Displace, Explode, Ocean, Particle Instance, Remesh, Shrinkwrap,
Solidify, Warp, Weighted Normal, Wave
Misc:
- Bevel: Set inactive properties for vertex bevel
- Mesh Sequence Cache: Remove box for cache file
- Skin: Don't align "Mark Loose" and "Clear Loose"
- Array: Expand relative offset subpanel by default
- Array: Move start cap, end cap to a new subpanel
- Bevel: Move width type above width
Differential Revision: https://developer.blender.org/D8115
2020-07-02 10:47:02 -04:00
|
|
|
uiLayout *col;
|
2020-06-05 10:41:03 -04:00
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
|
|
|
|
PointerRNA ob_ptr;
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
PointerRNA obj_data_ptr = RNA_pointer_get(&ob_ptr, "data");
|
|
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
UI: Small Tweaks to Modifier Layouts for Consistency
These changes are smaller, made based on feedback and a pass on all
the layouts for clarity and consistency. The Multires modifier UI will
be addressed in a separate patch. Here is an overview of the changes:
Renaming Options:
- Build: "Start" -> "Start Frame"
- Curve: "From Radius" -> "Size from Radius"
- Screw: "Calc Order" -> "Calculate Order"
- Displace, Warp, Wave: "Texture Coordinates Object" -> "Object"
Move Mode Toggle to Top & Expand:
- Bevel, Boolean, Normal Edit, Subdivision
Use Columns for Tighter Spacing:
- Displace, Explode, Ocean, Particle Instance, Remesh, Shrinkwrap,
Solidify, Warp, Weighted Normal, Wave
Misc:
- Bevel: Set inactive properties for vertex bevel
- Mesh Sequence Cache: Remove box for cache file
- Skin: Don't align "Mark Loose" and "Clear Loose"
- Array: Expand relative offset subpanel by default
- Array: Move start cap, end cap to a new subpanel
- Bevel: Move width type above width
Differential Revision: https://developer.blender.org/D8115
2020-07-02 10:47:02 -04:00
|
|
|
col = uiLayoutColumn(layout, false);
|
|
|
|
|
uiItemPointerR(
|
2020-09-02 14:13:26 -05:00
|
|
|
col, ptr, "index_layer_name", &obj_data_ptr, "vertex_colors", IFACE_("Index"), ICON_NONE);
|
UI: Small Tweaks to Modifier Layouts for Consistency
These changes are smaller, made based on feedback and a pass on all
the layouts for clarity and consistency. The Multires modifier UI will
be addressed in a separate patch. Here is an overview of the changes:
Renaming Options:
- Build: "Start" -> "Start Frame"
- Curve: "From Radius" -> "Size from Radius"
- Screw: "Calc Order" -> "Calculate Order"
- Displace, Warp, Wave: "Texture Coordinates Object" -> "Object"
Move Mode Toggle to Top & Expand:
- Bevel, Boolean, Normal Edit, Subdivision
Use Columns for Tighter Spacing:
- Displace, Explode, Ocean, Particle Instance, Remesh, Shrinkwrap,
Solidify, Warp, Weighted Normal, Wave
Misc:
- Bevel: Set inactive properties for vertex bevel
- Mesh Sequence Cache: Remove box for cache file
- Skin: Don't align "Mark Loose" and "Clear Loose"
- Array: Expand relative offset subpanel by default
- Array: Move start cap, end cap to a new subpanel
- Bevel: Move width type above width
Differential Revision: https://developer.blender.org/D8115
2020-07-02 10:47:02 -04:00
|
|
|
uiItemPointerR(
|
2020-09-02 14:13:26 -05:00
|
|
|
col, ptr, "value_layer_name", &obj_data_ptr, "vertex_colors", IFACE_("Value"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void panel_register(ARegionType *region_type)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
PanelType *panel_type = modifier_panel_register(
|
|
|
|
|
region_type, eModifierType_ParticleInstance, panel_draw);
|
|
|
|
|
modifier_subpanel_register(
|
|
|
|
|
region_type, "paths", "", path_panel_draw_header, path_panel_draw, panel_type);
|
2023-01-19 15:54:47 -06:00
|
|
|
modifier_subpanel_register(
|
|
|
|
|
region_type, "layers", "Layers", nullptr, layers_panel_draw, panel_type);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2016-12-28 17:30:58 +01:00
|
|
|
ModifierTypeInfo modifierType_ParticleInstance = {
|
2023-07-26 17:08:14 +02:00
|
|
|
/*idname*/ "ParticleInstance",
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("ParticleInstance"),
|
2023-07-27 12:04:18 +10:00
|
|
|
/*struct_name*/ "ParticleInstanceModifierData",
|
|
|
|
|
/*struct_size*/ sizeof(ParticleInstanceModifierData),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*srna*/ &RNA_ParticleInstanceModifier,
|
|
|
|
|
/*type*/ eModifierTypeType_Constructive,
|
|
|
|
|
/*flags*/ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsMapping |
|
2016-12-28 17:30:58 +01:00
|
|
|
eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_EnableInEditmode,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*icon*/ ICON_MOD_PARTICLE_INSTANCE,
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
/*copy_data*/ BKE_modifier_copydata_generic,
|
|
|
|
|
|
|
|
|
|
/*deform_verts*/ nullptr,
|
|
|
|
|
/*deform_matrices*/ nullptr,
|
|
|
|
|
/*deform_verts_EM*/ nullptr,
|
|
|
|
|
/*deform_matrices_EM*/ nullptr,
|
|
|
|
|
/*modify_mesh*/ modify_mesh,
|
|
|
|
|
/*modify_geometry_set*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*init_data*/ init_data,
|
|
|
|
|
/*required_data_mask*/ required_data_mask,
|
|
|
|
|
/*free_data*/ nullptr,
|
|
|
|
|
/*is_disabled*/ is_disabled,
|
|
|
|
|
/*update_depsgraph*/ update_depsgraph,
|
|
|
|
|
/*depends_on_time*/ nullptr,
|
|
|
|
|
/*depends_on_normals*/ nullptr,
|
|
|
|
|
/*foreach_ID_link*/ foreach_ID_link,
|
|
|
|
|
/*foreach_tex_link*/ nullptr,
|
|
|
|
|
/*free_runtime_data*/ nullptr,
|
|
|
|
|
/*panel_register*/ panel_register,
|
|
|
|
|
/*blend_write*/ nullptr,
|
|
|
|
|
/*blend_read*/ nullptr,
|
2016-12-28 17:30:58 +01:00
|
|
|
};
|