Blender V5.0
object_dupli.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <climits>
10#include <cstddef>
11#include <cstdlib>
12#include <iostream>
13
14#include <fmt/format.h>
15
16#include "MEM_guardedalloc.h"
17
18#include "BLI_listbase.h"
19#include "BLI_math_vector.h"
20#include "BLI_string_utf8.h"
21
22#include "BLI_array.hh"
23#include "BLI_hash.h"
24#include "BLI_math_geom.h"
25#include "BLI_math_matrix.h"
26#include "BLI_math_rotation.h"
27#include "BLI_math_vector.hh"
28#include "BLI_rand.h"
29#include "BLI_set.hh"
30#include "BLI_span.hh"
31#include "BLI_string_ref.hh"
32#include "BLI_vector_list.hh"
33
35#include "DNA_curves_types.h"
37#include "DNA_mesh_types.h"
38#include "DNA_modifier_types.h"
40#include "DNA_scene_types.h"
41#include "DNA_volume_types.h"
42#include "DNA_world_types.h"
43
44#include "BKE_collection.hh"
45#include "BKE_duplilist.hh"
46#include "BKE_editmesh.hh"
47#include "BKE_editmesh_cache.hh"
48#include "BKE_geometry_set.hh"
50#include "BKE_global.hh"
51#include "BKE_idprop.hh"
52#include "BKE_instances.hh"
53#include "BKE_main.hh"
54#include "BKE_mesh.hh"
55#include "BKE_object.hh"
56#include "BKE_object_types.hh"
57#include "BKE_particle.h"
58#include "BKE_vfont.hh"
59
60#include "DEG_depsgraph.hh"
62
64
65#include "RNA_access.hh"
66#include "RNA_path.hh"
67#include "RNA_prototypes.hh"
68
69#include "MOD_nodes.hh"
70
71using blender::Array;
72using blender::float2;
73using blender::float3;
75using blender::Set;
76using blender::Span;
77using blender::Vector;
83
84/* -------------------------------------------------------------------- */
87
88static constexpr short GEOMETRY_SET_DUPLI_GENERATOR_TYPE = 1;
89
143
146 short type;
147 void (*make_duplis)(const DupliContext *ctx);
148};
149
150static const DupliGenerator *get_dupli_generator(const DupliContext *ctx);
151
155static void init_context(DupliContext *r_ctx,
156 Depsgraph *depsgraph,
157 Scene *scene,
158 Object *ob,
159 const float space_mat[4][4],
160 blender::Set<const Object *> *include_objects,
161 Vector<Object *> &instance_stack,
162 Vector<short> &dupli_gen_type_stack,
163 DupliList &duplilist)
164{
165 r_ctx->depsgraph = depsgraph;
166 r_ctx->scene = scene;
167 r_ctx->collection = nullptr;
168
169 r_ctx->root_object = ob;
170 r_ctx->object = ob;
171 r_ctx->obedit = OBEDIT_FROM_OBACT(ob);
172 r_ctx->instance_stack = &instance_stack;
173 r_ctx->dupli_gen_type_stack = &dupli_gen_type_stack;
174 r_ctx->duplilist = &duplilist;
175 if (space_mat) {
176 copy_m4_m4(r_ctx->space_mat, space_mat);
177 }
178 else {
179 unit_m4(r_ctx->space_mat);
180 }
181 r_ctx->level = 0;
182
183 r_ctx->gen = get_dupli_generator(r_ctx);
184 if (r_ctx->gen && r_ctx->gen->type != GEOMETRY_SET_DUPLI_GENERATOR_TYPE) {
185 r_ctx->dupli_gen_type_stack->append(r_ctx->gen->type);
186 }
187
188 r_ctx->preview_instance_index = -1;
189 r_ctx->preview_base_geometry = nullptr;
190
191 r_ctx->include_objects = include_objects;
192}
193
198 const DupliContext *ctx,
199 Object *ob,
200 const float mat[4][4],
201 int index,
202 const GeometrySet *geometry = nullptr,
203 int64_t instance_index = 0)
204{
205 *r_ctx = *ctx;
206
207 /* XXX annoying, previously was done by passing an ID* argument,
208 * this at least is more explicit. */
209 if (ctx->gen && ctx->gen->type == OB_DUPLICOLLECTION) {
211 }
212
213 r_ctx->object = ob;
214 r_ctx->instance_stack = ctx->instance_stack;
215 if (mat) {
216 mul_m4_m4m4(r_ctx->space_mat, (float (*)[4])ctx->space_mat, mat);
217 }
218 r_ctx->persistent_id[r_ctx->level] = index;
219 r_ctx->instance_idx[r_ctx->level] = instance_index;
220 r_ctx->instance_data[r_ctx->level] = geometry;
221 ++r_ctx->level;
222
223 if (r_ctx->level == MAX_DUPLI_RECUR - 1) {
224 const blender::StringRef object_name = ob ? ob->id.name + 2 : "";
225 const blender::StringRef geometry_name = geometry ? geometry->name : "";
226
227 if (geometry_name.is_empty() && !object_name.is_empty()) {
228 std::cerr << fmt::format(
229 "Warning: Maximum instance recursion level reached in \"{}\" object.\n", object_name);
230 }
231 if (!geometry_name.is_empty() && object_name.is_empty()) {
232 std::cerr << fmt::format(
233 "Warning: Maximum instance recursion level reached at \"{}\" geometry.\n",
234 geometry_name);
235 }
236 if (!geometry_name.is_empty() && !object_name.is_empty()) {
237 std::cerr << fmt::format(
238 "Warning: Maximum instance recursion level reached at \"{}\" geometry in \"{}\" "
239 "object.\n",
240 geometry_name,
241 object_name);
242 }
243
244 return false;
245 }
246
247 r_ctx->gen = get_dupli_generator(r_ctx);
248 if (r_ctx->gen && r_ctx->gen->type != GEOMETRY_SET_DUPLI_GENERATOR_TYPE) {
249 r_ctx->dupli_gen_type_stack->append(r_ctx->gen->type);
250 }
251 return true;
252}
253
261 Object *ob,
262 const ID *object_data,
263 const float mat[4][4],
264 int index,
265 const GeometrySet *geometry = nullptr,
266 int64_t instance_index = 0)
267{
268 DupliObject *dob;
269 int i;
270
271 /* Add a #DupliObject instance to the result container. */
272 if (ctx->duplilist) {
273 ctx->duplilist->append({});
274 dob = &ctx->duplilist->last();
275 }
276 else {
277 return nullptr;
278 }
279
280 dob->ob = ob;
281 dob->ob_data = const_cast<ID *>(object_data);
282 mul_m4_m4m4(dob->mat, (float (*)[4])ctx->space_mat, mat);
283 dob->type = ctx->gen == nullptr ? 0 : ctx->dupli_gen_type_stack->last();
286 dob->level = ctx->level;
287
288 /* Set persistent id, which is an array with a persistent index for each level
289 * (particle number, vertex number, ..). by comparing this we can find the same
290 * dupli-object between frames, which is needed for motion blur.
291 * The last level is ordered first in the array. */
292 dob->persistent_id[0] = index;
293 for (i = 1; i < ctx->level + 1; i++) {
294 dob->persistent_id[i] = ctx->persistent_id[ctx->level - i];
295 }
296 /* Fill rest of values with #INT_MAX which index will never have as value. */
297 for (; i < MAX_DUPLI_RECUR; i++) {
298 dob->persistent_id[i] = INT_MAX;
299 }
300
301 /* Store geometry set data for attribute lookup in innermost to outermost
302 * order, copying only non-null entries to save space. */
303 const int max_instance = ARRAY_SIZE(dob->instance_data);
304 int next_instance = 0;
305 if (geometry != nullptr) {
306 dob->instance_idx[next_instance] = int(instance_index);
307 dob->instance_data[next_instance] = geometry;
308 next_instance++;
309 }
310 for (i = ctx->level - 1; i >= 0 && next_instance < max_instance; i--) {
311 if (ctx->instance_data[i] != nullptr) {
312 dob->instance_idx[next_instance] = int(ctx->instance_idx[i]);
313 dob->instance_data[next_instance] = ctx->instance_data[i];
314 next_instance++;
315 }
316 }
317
318 /* Meta-balls never draw in duplis, they are instead merged into one by the basis
319 * meta-ball outside of the group. this does mean that if that meta-ball is not in the
320 * scene, they will not show up at all, limitation that should be solved once. */
321 if (object_data && GS(object_data->name) == ID_MB) {
322 dob->no_draw = true;
323 }
324
325 /* Random number per instance.
326 * The root object in the scene, persistent ID up to the instance object, and the instance object
327 * name together result in a unique random number. */
328 dob->random_id = BLI_hash_string(dob->ob->id.name + 2);
329
330 if (dob->persistent_id[0] != INT_MAX) {
331 for (i = 0; i < ctx->level + 1; i++) {
333 }
334 }
335 else {
336 dob->random_id = BLI_hash_int_2d(dob->random_id, 0);
337 }
338
339 if (ctx->root_object != ob) {
341 }
342
343 return dob;
344}
345
347 Object *ob,
348 const float mat[4][4],
349 int index,
350 const GeometrySet *geometry = nullptr,
351 int64_t instance_index = 0)
352{
353 return make_dupli(ctx, ob, static_cast<ID *>(ob->data), mat, index, geometry, instance_index);
354}
355
361static void make_recursive_duplis(const DupliContext *ctx,
362 Object *ob,
363 const float space_mat[4][4],
364 int index,
365 const GeometrySet *geometry = nullptr,
366 int64_t instance_index = 0)
367{
368 if (ctx->instance_stack->contains(ob)) {
369 /* Avoid recursive instances. */
370 printf("Warning: '%s' object is trying to instance itself.\n", ob->id.name + 2);
371 return;
372 }
373 /* Simple preventing of too deep nested collections with #MAX_DUPLI_RECUR. */
374 if (ctx->level < MAX_DUPLI_RECUR) {
375 DupliContext rctx;
376 if (!copy_dupli_context(&rctx, ctx, ob, space_mat, index, geometry, instance_index)) {
377 return;
378 }
379 if (rctx.gen) {
380 ctx->instance_stack->append(ob);
381 rctx.gen->make_duplis(&rctx);
382 ctx->instance_stack->remove_last();
384 if (!ctx->dupli_gen_type_stack->is_empty()) {
385 ctx->dupli_gen_type_stack->remove_last();
386 }
387 }
388 }
389 }
390}
391
393
394/* -------------------------------------------------------------------- */
397
398using MakeChildDuplisFunc = void (*)(const DupliContext *ctx, void *userdata, Object *child);
399
400static bool is_child(const Object *ob, const Object *parent)
401{
402 const Object *ob_parent = ob->parent;
403 while (ob_parent) {
404 if (ob_parent == parent) {
405 return true;
406 }
407 ob_parent = ob_parent->parent;
408 }
409 return false;
410}
411
415static void make_child_duplis(const DupliContext *ctx,
416 void *userdata,
417 MakeChildDuplisFunc make_child_duplis_cb)
418{
419 Object *parent = ctx->object;
420
421 if (ctx->collection) {
424 if ((ob != ctx->obedit) && is_child(ob, parent)) {
425 DupliContext pctx;
426 if (copy_dupli_context(&pctx, ctx, ctx->object, nullptr, _base_id)) {
427 /* Meta-balls have a different dupli handling. */
428 if (ob->type != OB_MBALL) {
429 ob->flag |= OB_DONE; /* Doesn't render. */
430 }
431 make_child_duplis_cb(&pctx, userdata, ob);
433 if (!ctx->dupli_gen_type_stack->is_empty()) {
434 ctx->dupli_gen_type_stack->remove_last();
435 }
436 }
437 }
438 }
439 }
441 }
442 else {
443 /* FIXME: using a mere counter to generate a 'persistent' dupli id is very weak. One possible
444 * better solution could be to use `session_uid` of ID's instead? */
445 int persistent_dupli_id = 0;
446 DEGObjectIterSettings deg_iter_settings{};
447 deg_iter_settings.depsgraph = ctx->depsgraph;
448 /* NOTE: this set of flags ensure we only iterate over objects that have a base in either the
449 * current scene, or the set (background) scene. */
450 deg_iter_settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
452 DEG_OBJECT_ITER_BEGIN (&deg_iter_settings, ob) {
453 if ((ob != ctx->obedit) && is_child(ob, parent)) {
454 DupliContext pctx;
455 if (copy_dupli_context(&pctx, ctx, ctx->object, nullptr, persistent_dupli_id)) {
456 /* Meta-balls have a different dupli-handling. */
457 if (ob->type != OB_MBALL) {
458 ob->flag |= OB_DONE; /* Doesn't render. */
459 }
460
461 make_child_duplis_cb(&pctx, userdata, ob);
463 if (!ctx->dupli_gen_type_stack->is_empty()) {
464 ctx->dupli_gen_type_stack->remove_last();
465 }
466 }
467 }
468 }
469 persistent_dupli_id++;
470 }
472 }
473}
474
476
477/* -------------------------------------------------------------------- */
480
482 BMEditMesh **r_em,
483 Span<float3> *r_vert_coords,
484 Span<float3> *r_vert_normals)
485{
486 /* Gather mesh info. */
488 const Mesh *mesh_eval;
489
490 *r_em = nullptr;
491 *r_vert_coords = {};
492 if (r_vert_normals != nullptr) {
493 *r_vert_normals = {};
494 }
495
496 /* We do not need any render-specific handling anymore, depsgraph takes care of that. */
497 /* NOTE: Do direct access to the evaluated mesh: this function is used
498 * during meta balls evaluation. But even without those all the objects
499 * which are needed for correct instancing are already evaluated. */
500 if (em != nullptr) {
501 /* Note that this will only show deformation if #eModifierMode_OnCage is enabled.
502 * We could change this but it matches 2.7x behavior. */
503 mesh_eval = BKE_object_get_editmesh_eval_cage(ob);
504 if ((mesh_eval == nullptr) || (mesh_eval->runtime->wrapper_type == ME_WRAPPER_TYPE_BMESH)) {
505 blender::bke::EditMeshData *emd = mesh_eval ? mesh_eval->runtime->edit_data.get() : nullptr;
506
507 /* Only assign edit-mesh in the case we can't use `mesh_eval`. */
508 *r_em = em;
509 mesh_eval = nullptr;
510
511 if ((emd != nullptr) && !emd->vert_positions.is_empty()) {
512 *r_vert_coords = emd->vert_positions;
513 if (r_vert_normals != nullptr) {
514 *r_vert_normals = BKE_editmesh_cache_ensure_vert_normals(*em, *emd);
515 }
516 }
517 }
518 }
519 else {
520 mesh_eval = BKE_object_get_evaluated_mesh(ob);
521 }
522 return mesh_eval;
523}
524
526
527/* -------------------------------------------------------------------- */
530
532{
533 Object *ob = ctx->object;
534 Collection *collection;
535 float collection_mat[4][4];
536
537 if (ob->instance_collection == nullptr) {
538 return;
539 }
540 collection = ob->instance_collection;
541
542 /* Combine collection offset and `obmat`. */
543 unit_m4(collection_mat);
544 sub_v3_v3(collection_mat[3], collection->instance_offset);
545 mul_m4_m4m4(collection_mat, ob->object_to_world().ptr(), collection_mat);
546 /* Don't access 'ob->object_to_world().ptr()' from now on. */
547
550 if (cob == ob) {
551 continue;
552 }
553
554 if (ctx->include_objects) {
555 Object *original_object = cob->id.orig_id ? reinterpret_cast<Object *>(cob->id.orig_id) :
556 cob;
557 if (!ctx->include_objects->contains(original_object)) {
558 continue;
559 }
560 }
561
562 float mat[4][4];
563
564 /* Collection dupli-offset, should apply after everything else. */
565 mul_m4_m4m4(mat, collection_mat, cob->object_to_world().ptr());
566
567 make_dupli(ctx, cob, mat, _base_id);
568
569 /* Recursion. */
570 make_recursive_duplis(ctx, cob, collection_mat, _base_id);
571 }
573}
574
576 /*type*/ OB_DUPLICOLLECTION,
577 /*make_duplis*/ make_duplis_collection};
578
580
581/* -------------------------------------------------------------------- */
584
595
605
624
630static void get_duplivert_transform(const float3 &co,
631 const float3 &no,
632 const bool use_rotation,
633 const short axis,
634 const short upflag,
635 float r_mat[4][4])
636{
637 float quat[4];
638 const float size[3] = {1.0f, 1.0f, 1.0f};
639
640 if (use_rotation) {
641 /* Construct rotation matrix from normals. */
642 float no_flip[3];
643 negate_v3_v3(no_flip, no);
644 vec_to_quat(quat, no_flip, axis, upflag);
645 }
646 else {
647 unit_qt(quat);
648 }
649
650 loc_quat_size_to_mat4(r_mat, co, quat, size);
651}
652
654 Object *inst_ob,
655 const float child_imat[4][4],
656 int index,
657 const float3 &co,
658 const float3 &no,
659 const bool use_rotation)
660{
661 /* `obmat` is transform to vertex. */
662 float obmat[4][4];
663 get_duplivert_transform(co, no, use_rotation, inst_ob->trackflag, inst_ob->upflag, obmat);
664
665 float space_mat[4][4];
666
667 /* Make offset relative to inst_ob using relative child transform. */
668 mul_mat3_m4_v3(child_imat, obmat[3]);
669 /* Apply `obmat` _after_ the local vertex transform. */
670 mul_m4_m4m4(obmat, inst_ob->object_to_world().ptr(), obmat);
671
672 /* Space matrix is constructed by removing `obmat` transform,
673 * this yields the world-space transform for recursive duplis. */
674 mul_m4_m4m4(space_mat, obmat, inst_ob->world_to_object().ptr());
675
676 DupliObject *dob = make_dupli(ctx, inst_ob, obmat, index);
677
678 /* Recursion. */
679 make_recursive_duplis(ctx, inst_ob, space_mat, index);
680
681 return dob;
682}
683
685 void *userdata,
686 Object *inst_ob)
687{
689 const bool use_rotation = vdd->params.use_rotation;
690
691 const int totvert = vdd->totvert;
692
693 invert_m4_m4(inst_ob->runtime->world_to_object.ptr(), inst_ob->object_to_world().ptr());
694 /* Relative transform from parent to child space. */
695 float child_imat[4][4];
696 mul_m4_m4m4(child_imat, inst_ob->world_to_object().ptr(), ctx->object->object_to_world().ptr());
697
698 for (int i = 0; i < totvert; i++) {
700 inst_ob,
701 child_imat,
702 i,
703 vdd->vert_positions[i],
704 vdd->vert_normals[i],
705 use_rotation);
706 if (vdd->orco) {
707 copy_v3_v3(dob->orco, vdd->orco[i]);
708 }
709 }
710}
711
713 void *userdata,
714 Object *inst_ob)
715{
717 BMEditMesh *em = vdd->em;
718 const bool use_rotation = vdd->params.use_rotation;
719
720 invert_m4_m4(inst_ob->runtime->world_to_object.ptr(), inst_ob->object_to_world().ptr());
721 /* Relative transform from parent to child space. */
722 float child_imat[4][4];
723 mul_m4_m4m4(child_imat, inst_ob->world_to_object().ptr(), ctx->object->object_to_world().ptr());
724
725 BMVert *v;
726 BMIter iter;
727 int i;
728
729 const Span<float3> vert_positions_deform = vdd->vert_positions_deform;
730 const Span<float3> vert_normals_deform = vdd->vert_normals_deform;
731 BM_ITER_MESH_INDEX (v, &iter, em->bm, BM_VERTS_OF_MESH, i) {
732 float3 co, no;
733 if (!vert_positions_deform.is_empty()) {
734 co = vert_positions_deform[i];
735 no = !vert_normals_deform.is_empty() ? vert_normals_deform[i] : float3(0);
736 }
737 else {
738 co = v->co;
739 no = v->no;
740 }
741
742 DupliObject *dob = vertex_dupli(vdd->params.ctx, inst_ob, child_imat, i, co, no, use_rotation);
743 if (vdd->has_orco) {
744 copy_v3_v3(dob->orco, v->co);
745 }
746 }
747}
748
749static void make_duplis_verts(const DupliContext *ctx)
750{
751 Object *parent = ctx->object;
752 const bool use_rotation = parent->transflag & OB_DUPLIROT;
753
754 /* Gather mesh info. */
755 BMEditMesh *em = nullptr;
756 Span<float3> vert_positions_deform;
757 Span<float3> vert_normals_deform;
758 const Mesh *mesh_eval = mesh_data_from_duplicator_object(
759 parent, &em, &vert_positions_deform, use_rotation ? &vert_normals_deform : nullptr);
760 if (em == nullptr && mesh_eval == nullptr) {
761 return;
762 }
763
764 VertexDupliData_Params vdd_params{ctx, use_rotation};
765
766 if (em != nullptr) {
768 vdd.params = vdd_params;
769 vdd.em = em;
770 vdd.vert_positions_deform = vert_positions_deform;
771 vdd.vert_normals_deform = vert_normals_deform;
772 vdd.has_orco = !vert_positions_deform.is_empty();
773
775 }
776 else {
778 vdd.params = vdd_params;
779 vdd.totvert = mesh_eval->verts_num;
780 vdd.vert_positions = mesh_eval->vert_positions();
781 vdd.vert_normals = mesh_eval->vert_normals();
782 vdd.orco = (const float (*)[3])CustomData_get_layer(&mesh_eval->vert_data, CD_ORCO);
783
785 }
786}
787
789 /*type*/ OB_DUPLIVERTS,
790 /*make_duplis*/ make_duplis_verts};
791
793
794/* -------------------------------------------------------------------- */
797
799 Main *bmain, const char *family, size_t family_len, uint ch, GHash *family_gh)
800{
801 void *ch_key = POINTER_FROM_UINT(ch);
802
803 Object **ob_pt = (Object **)BLI_ghash_lookup_p(family_gh, ch_key);
804 if (ob_pt) {
805 return *ob_pt;
806 }
807
808 char ch_utf8[BLI_UTF8_MAX + 1];
809 size_t ch_utf8_len;
810
811 ch_utf8_len = BLI_str_utf8_from_unicode(ch, ch_utf8, sizeof(ch_utf8) - 1);
812 ch_utf8[ch_utf8_len] = '\0';
813 ch_utf8_len += 1; /* Compare with null terminator. */
814
815 LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
816 if (STREQLEN(ob->id.name + 2 + family_len, ch_utf8, ch_utf8_len)) {
817 if (STREQLEN(ob->id.name + 2, family, family_len)) {
818 /* Inserted value can be nullptr, just to save searches in future. */
819 BLI_ghash_insert(family_gh, ch_key, ob);
820 return ob;
821 }
822 }
823 }
824
825 return nullptr;
826}
827
828static void make_duplis_font(const DupliContext *ctx)
829{
830 /* Font dupli-verts not supported inside collections. */
831 if (ctx->collection) {
832 return;
833 }
834
835 Object *par = ctx->object;
836 GHash *family_gh;
837 Object *ob;
838 Curve *cu = (Curve *)par->data;
839 CharTrans *ct, *chartransdata = nullptr;
840 float vec[3], obmat[4][4], pmat[4][4];
841 int text_len, a;
842 size_t family_len;
843 const char32_t *text = nullptr;
844 bool text_free = false;
845
846 copy_m4_m4(pmat, par->object_to_world().ptr());
847
848 /* In `par` the family name is stored, use this to find the other objects. */
849
851 par, *cu, FO_DUPLI, nullptr, &text, &text_len, &text_free, &chartransdata, nullptr);
852
853 if (text == nullptr || chartransdata == nullptr) {
854 return;
855 }
856
857 const float fsize = cu->fsize;
858 const blender::float2 cu_offset = {cu->xof, cu->yof};
859
860 ct = chartransdata;
861
862 /* Cache result. */
863 family_len = strlen(cu->family);
864 family_gh = BLI_ghash_int_new_ex(__func__, 256);
865
866 /* Safety check even if it might fail badly when called for original object. */
867 const bool is_eval_curve = DEG_is_evaluated(cu);
868
869 /* Advance matching BLI_str_utf8_as_utf32. */
870 for (a = 0; a < text_len; a++, ct++) {
871
872 /* XXX That G.main is *really* ugly, but not sure what to do here.
873 * Definitively don't think it would be safe to put back `Main *bmain` pointer
874 * in #DupliContext as done in 2.7x? */
875 ob = find_family_object(G.main, cu->family, family_len, uint(text[a]), family_gh);
876
877 if (is_eval_curve) {
878 /* Workaround for the above hack. */
879 ob = DEG_get_evaluated(ctx->depsgraph, ob);
880 }
881
882 if (ob) {
883 vec[0] = fsize * (ct->offset.x - cu_offset.x);
884 vec[1] = fsize * (ct->offset.y - cu_offset.y);
885 vec[2] = 0.0;
886
887 mul_m4_v3(pmat, vec);
888
889 copy_m4_m4(obmat, par->object_to_world().ptr());
890
891 if (UNLIKELY(ct->rotate != 0.0f)) {
892 float rmat[4][4];
893
894 zero_v3(obmat[3]);
895 axis_angle_to_mat4_single(rmat, 'Z', -ct->rotate);
896 mul_m4_m4m4(obmat, obmat, rmat);
897 }
898
899 copy_v3_v3(obmat[3], vec);
900
901 make_dupli(ctx, ob, obmat, a);
902 }
903 }
904
905 if (text_free) {
906 MEM_freeN(text);
907 }
908
909 BLI_ghash_free(family_gh, nullptr, nullptr);
910
911 MEM_freeN(chartransdata);
912}
913
915 /*type*/ OB_DUPLIVERTS,
916 /*make_duplis*/ make_duplis_font};
917
919
920/* -------------------------------------------------------------------- */
923
925 const GeometrySet &geometry_set,
926 const float parent_transform[4][4],
927 bool geometry_set_is_instance,
928 bool use_new_curves_type)
929{
930 int component_index = 0;
931 if (ctx->object->type != OB_MESH || geometry_set_is_instance) {
932 if (const Mesh *mesh = geometry_set.get_mesh()) {
933 make_dupli(ctx, ctx->object, &mesh->id, parent_transform, component_index++);
934 }
935 }
936 if (ctx->object->type != OB_VOLUME || geometry_set_is_instance) {
937 if (const Volume *volume = geometry_set.get_volume()) {
938 make_dupli(ctx, ctx->object, &volume->id, parent_transform, component_index++);
939 }
940 }
941 if (!ELEM(ctx->object->type, OB_CURVES_LEGACY, OB_FONT, OB_CURVES) || geometry_set_is_instance) {
942 if (const blender::bke::CurveComponent *component =
944 {
945 if (use_new_curves_type) {
946 if (const Curves *curves = component->get()) {
947 make_dupli(ctx, ctx->object, &curves->id, parent_transform, component_index++);
948 }
949 }
950 else {
951 if (const Curve *curve = component->get_curve_for_render()) {
952 make_dupli(ctx, ctx->object, &curve->id, parent_transform, component_index++);
953 }
954 }
955 }
956 }
957 if (ctx->object->type != OB_POINTCLOUD || geometry_set_is_instance) {
958 if (const PointCloud *pointcloud = geometry_set.get_pointcloud()) {
959 make_dupli(ctx, ctx->object, &pointcloud->id, parent_transform, component_index++);
960 }
961 }
962 if (ctx->object->type != OB_GREASE_PENCIL || geometry_set_is_instance) {
963 if (const GreasePencil *grease_pencil = geometry_set.get_grease_pencil()) {
964 make_dupli(ctx, ctx->object, &grease_pencil->id, parent_transform, component_index++);
965 }
966 }
967 const bool creates_duplis_for_components = component_index >= 1;
968
969 const Instances *instances = geometry_set.get_instances();
970 if (instances == nullptr) {
971 return;
972 }
973
974 const DupliContext *instances_ctx = ctx;
975 /* Create a sub-context if some duplis were created above. This is to avoid dupli id collisions
976 * between the instances component below and the other components above. */
977 DupliContext new_instances_ctx;
978 if (creates_duplis_for_components) {
979 if (!copy_dupli_context(&new_instances_ctx, ctx, ctx->object, nullptr, component_index)) {
980 return;
981 }
982 instances_ctx = &new_instances_ctx;
983 }
984
985 Span<float4x4> instance_offset_matrices = instances->transforms();
986 Span<int> reference_handles = instances->reference_handles();
987 Span<int> unique_ids = instances->unique_ids();
988 Span<InstanceReference> references = instances->references();
989
990 for (int64_t i : instance_offset_matrices.index_range()) {
991 const InstanceReference &reference = references[reference_handles[i]];
992 const int id = unique_ids[i];
993
994 const DupliContext *ctx_for_instance = instances_ctx;
995 /* Set the #preview_instance_index when necessary. */
996 DupliContext tmp_ctx_for_instance;
997 if (instances_ctx->preview_base_geometry == &geometry_set) {
998 tmp_ctx_for_instance = *instances_ctx;
999 tmp_ctx_for_instance.preview_instance_index = i;
1000 ctx_for_instance = &tmp_ctx_for_instance;
1001 }
1002
1003 switch (reference.type()) {
1004 case InstanceReference::Type::Object: {
1005 Object &object = reference.object();
1006 float matrix[4][4];
1007 mul_m4_m4m4(matrix, parent_transform, instance_offset_matrices[i].ptr());
1008 make_dupli(ctx_for_instance, &object, matrix, id, &geometry_set, i);
1009
1010 float space_matrix[4][4];
1012 space_matrix, instance_offset_matrices[i].ptr(), object.world_to_object().ptr());
1013 mul_m4_m4_pre(space_matrix, parent_transform);
1014 make_recursive_duplis(ctx_for_instance, &object, space_matrix, id, &geometry_set, i);
1015 break;
1016 }
1017 case InstanceReference::Type::Collection: {
1018 Collection &collection = reference.collection();
1019 float collection_matrix[4][4];
1020 unit_m4(collection_matrix);
1021 sub_v3_v3(collection_matrix[3], collection.instance_offset);
1022 mul_m4_m4_pre(collection_matrix, instance_offset_matrices[i].ptr());
1023 mul_m4_m4_pre(collection_matrix, parent_transform);
1024
1025 DupliContext sub_ctx;
1026 if (!copy_dupli_context(&sub_ctx,
1027 ctx_for_instance,
1028 ctx_for_instance->object,
1029 nullptr,
1030 id,
1031 &geometry_set,
1032 i))
1033 {
1034 break;
1035 }
1036
1037 eEvaluationMode mode = DEG_get_mode(ctx_for_instance->depsgraph);
1038 int object_id = 0;
1039 FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (&collection, object, mode) {
1040 if (object == ctx_for_instance->object) {
1041 continue;
1042 }
1043
1044 float instance_matrix[4][4];
1045 mul_m4_m4m4(instance_matrix, collection_matrix, object->object_to_world().ptr());
1046
1047 make_dupli(&sub_ctx, object, instance_matrix, object_id++);
1048 make_recursive_duplis(&sub_ctx, object, collection_matrix, object_id++);
1049 }
1051 break;
1052 }
1053 case InstanceReference::Type::GeometrySet: {
1054 float new_transform[4][4];
1055 mul_m4_m4m4(new_transform, parent_transform, instance_offset_matrices[i].ptr());
1056
1057 DupliContext sub_ctx;
1058 if (copy_dupli_context(&sub_ctx,
1059 ctx_for_instance,
1060 ctx_for_instance->object,
1061 nullptr,
1062 id,
1063 &geometry_set,
1064 i))
1065 {
1067 &sub_ctx, reference.geometry_set(), new_transform, true, false);
1068 }
1069 break;
1070 }
1071 case InstanceReference::Type::None: {
1072 break;
1073 }
1074 }
1075 }
1076}
1077
1079{
1080 const GeometrySet *geometry_set = ctx->object->runtime->geometry_set_eval;
1082 ctx, *geometry_set, ctx->object->object_to_world().ptr(), false, false);
1083}
1084
1089
1091
1092/* -------------------------------------------------------------------- */
1095
1106
1117
1128
1130 const bool use_scale,
1131 const float scale_fac,
1132 float r_mat[4][4])
1133{
1134 using namespace blender::math;
1135
1136 /* Location. */
1137 float3 location(0);
1138 for (const float3 &coord : coords) {
1139 location += coord;
1140 }
1141 location *= 1.0f / float(coords.size());
1142
1143 /* Rotation. */
1144 float quat[4];
1145
1146 float3 f_no = normalize(cross_poly(coords));
1147 tri_to_quat_ex(quat, coords[0], coords[1], coords[2], f_no);
1148
1149 /* Scale. */
1150 float scale;
1151 if (use_scale) {
1152 const float area = area_poly_v3((const float (*)[3])coords.data(), uint(coords.size()));
1153 scale = sqrtf(area) * scale_fac;
1154 }
1155 else {
1156 scale = 1.0f;
1157 }
1158
1159 loc_quat_size_to_mat4(r_mat, location, quat, float3(scale));
1160}
1161
1163 Object *inst_ob,
1164 const float child_imat[4][4],
1165 const int index,
1166 const bool use_scale,
1167 const float scale_fac,
1168 Span<float3> coords)
1169{
1170 float obmat[4][4];
1171 float space_mat[4][4];
1172
1173 /* `obmat` is transform to face. */
1174 get_dupliface_transform_from_coords(coords, use_scale, scale_fac, obmat);
1175
1176 /* Make offset relative to inst_ob using relative child transform. */
1177 mul_mat3_m4_v3(child_imat, obmat[3]);
1178
1179 /* XXX ugly hack to ensure same behavior as in master.
1180 * This should not be needed, #Object.parentinv is not consistent outside of parenting. */
1181 {
1182 float imat[3][3];
1183 copy_m3_m4(imat, inst_ob->parentinv);
1184 mul_m4_m3m4(obmat, imat, obmat);
1185 }
1186
1187 /* Apply `obmat` _after_ the local face transform. */
1188 mul_m4_m4m4(obmat, inst_ob->object_to_world().ptr(), obmat);
1189
1190 /* Space matrix is constructed by removing `obmat` transform,
1191 * this yields the world-space transform for recursive duplis. */
1192 mul_m4_m4m4(space_mat, obmat, inst_ob->world_to_object().ptr());
1193
1194 DupliObject *dob = make_dupli(ctx, inst_ob, obmat, index);
1195
1196 /* Recursion. */
1197 make_recursive_duplis(ctx, inst_ob, space_mat, index);
1198
1199 return dob;
1200}
1201
1203 Object *inst_ob,
1204 const float child_imat[4][4],
1205 const int index,
1206 const bool use_scale,
1207 const float scale_fac,
1208
1209 /* Mesh variables. */
1210 const Span<int> face_verts,
1211 const Span<float3> vert_positions)
1212{
1213 Array<float3, 64> coords(face_verts.size());
1214
1215 for (int i = 0; i < face_verts.size(); i++) {
1216 coords[i] = vert_positions[face_verts[i]];
1217 }
1218
1219 return face_dupli(ctx, inst_ob, child_imat, index, use_scale, scale_fac, coords);
1220}
1221
1223 Object *inst_ob,
1224 const float child_imat[4][4],
1225 const int index,
1226 const bool use_scale,
1227 const float scale_fac,
1228
1229 /* Mesh variables. */
1230 BMFace *f,
1231 const Span<float3> vert_positions_deform)
1232{
1233 const int coords_len = f->len;
1234 Array<float3, 64> coords(coords_len);
1235
1236 BMLoop *l_first, *l_iter;
1237 int i = 0;
1238 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1239 if (!vert_positions_deform.is_empty()) {
1240 do {
1241 copy_v3_v3(coords[i++], vert_positions_deform[BM_elem_index_get(l_iter->v)]);
1242 } while ((l_iter = l_iter->next) != l_first);
1243 }
1244 else {
1245 do {
1246 copy_v3_v3(coords[i++], l_iter->v->co);
1247 } while ((l_iter = l_iter->next) != l_first);
1248 }
1249
1250 return face_dupli(ctx, inst_ob, child_imat, index, use_scale, scale_fac, coords);
1251}
1252
1254 void *userdata,
1255 Object *inst_ob)
1256{
1257 FaceDupliData_Mesh *fdd = (FaceDupliData_Mesh *)userdata;
1258 const float (*orco)[3] = fdd->orco;
1259 const float2 *uv_map = fdd->uv_map;
1260 const int totface = fdd->totface;
1261 const bool use_scale = fdd->params.use_scale;
1262
1263 float child_imat[4][4];
1264
1265 invert_m4_m4(inst_ob->runtime->world_to_object.ptr(), inst_ob->object_to_world().ptr());
1266 /* Relative transform from parent to child space. */
1267 mul_m4_m4m4(child_imat, inst_ob->world_to_object().ptr(), ctx->object->object_to_world().ptr());
1268 const float scale_fac = ctx->object->instance_faces_scale;
1269
1270 for (const int a : blender::IndexRange(totface)) {
1271 const blender::IndexRange face = fdd->faces[a];
1272 const Span<int> face_verts = fdd->corner_verts.slice(face);
1274 inst_ob,
1275 child_imat,
1276 a,
1277 use_scale,
1278 scale_fac,
1279 face_verts,
1280 fdd->vert_positions);
1281
1282 const float w = 1.0f / float(face.size());
1283 if (orco) {
1284 for (int j = 0; j < face.size(); j++) {
1285 madd_v3_v3fl(dob->orco, orco[face_verts[j]], w);
1286 }
1287 }
1288 if (uv_map) {
1289 for (int j = 0; j < face.size(); j++) {
1290 madd_v2_v2fl(dob->uv, uv_map[face[j]], w);
1291 }
1292 }
1293 }
1294}
1295
1297 void *userdata,
1298 Object *inst_ob)
1299{
1301 BMEditMesh *em = fdd->em;
1302 float child_imat[4][4];
1303 int a;
1304 BMFace *f;
1305 BMIter iter;
1306 const bool use_scale = fdd->params.use_scale;
1307
1308 const Span<float3> vert_positions_deform = fdd->vert_positions_deform;
1309
1310 BLI_assert(vert_positions_deform.is_empty() || (em->bm->elem_index_dirty & BM_VERT) == 0);
1311
1312 invert_m4_m4(inst_ob->runtime->world_to_object.ptr(), inst_ob->object_to_world().ptr());
1313 /* Relative transform from parent to child space. */
1314 mul_m4_m4m4(child_imat, inst_ob->world_to_object().ptr(), ctx->object->object_to_world().ptr());
1315 const float scale_fac = ctx->object->instance_faces_scale;
1316
1317 BM_ITER_MESH_INDEX (f, &iter, em->bm, BM_FACES_OF_MESH, a) {
1319 fdd->params.ctx, inst_ob, child_imat, a, use_scale, scale_fac, f, vert_positions_deform);
1320
1321 if (fdd->has_orco) {
1322 const float w = 1.0f / float(f->len);
1323 BMLoop *l_first, *l_iter;
1324 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1325 do {
1326 madd_v3_v3fl(dob->orco, l_iter->v->co, w);
1327 } while ((l_iter = l_iter->next) != l_first);
1328 }
1329 if (fdd->has_uvs) {
1331 }
1332 }
1333}
1334
1335static void make_duplis_faces(const DupliContext *ctx)
1336{
1337 Object *parent = ctx->object;
1338
1339 /* Gather mesh info. */
1340 BMEditMesh *em = nullptr;
1341 Span<float3> vert_positions_deform;
1342 const Mesh *mesh_eval = mesh_data_from_duplicator_object(
1343 parent, &em, &vert_positions_deform, nullptr);
1344 if (em == nullptr && mesh_eval == nullptr) {
1345 return;
1346 }
1347
1348 FaceDupliData_Params fdd_params = {ctx, (parent->transflag & OB_DUPLIFACES_SCALE) != 0};
1349
1350 if (em != nullptr) {
1351 const int uv_idx = CustomData_get_render_layer(&em->bm->ldata, CD_PROP_FLOAT2);
1353 fdd.params = fdd_params;
1354 fdd.em = em;
1355 fdd.vert_positions_deform = vert_positions_deform;
1356 fdd.has_orco = !vert_positions_deform.is_empty();
1357 fdd.has_uvs = (uv_idx != -1);
1358 fdd.cd_loop_uv_offset = (uv_idx != -1) ?
1360 -1;
1362 }
1363 else {
1364 const int uv_idx = CustomData_get_render_layer(&mesh_eval->corner_data, CD_PROP_FLOAT2);
1365 FaceDupliData_Mesh fdd{};
1366 fdd.params = fdd_params;
1367 fdd.totface = mesh_eval->faces_num;
1368 fdd.faces = mesh_eval->faces();
1369 fdd.corner_verts = mesh_eval->corner_verts();
1370 fdd.vert_positions = mesh_eval->vert_positions();
1371 fdd.uv_map = (uv_idx != -1) ? (const float2 *)CustomData_get_layer_n(
1372 &mesh_eval->corner_data, CD_PROP_FLOAT2, uv_idx) :
1373 nullptr;
1374 fdd.orco = (const float (*)[3])CustomData_get_layer(&mesh_eval->vert_data, CD_ORCO);
1375
1377 }
1378}
1379
1381 /*type*/ OB_DUPLIFACES,
1382 /*make_duplis*/ make_duplis_faces,
1383};
1384
1386
1387/* -------------------------------------------------------------------- */
1390
1392{
1393 Scene *scene = ctx->scene;
1394 Object *par = ctx->object;
1396 bool for_render = mode == DAG_EVAL_RENDER;
1397
1398 Object *ob = nullptr, **oblist = nullptr;
1399 DupliObject *dob;
1400 ParticleSettings *part;
1401 ParticleData *pa;
1402 ChildParticle *cpa = nullptr;
1404 ParticleCacheKey *cache;
1405 float ctime, scale = 1.0f;
1406 float tmat[4][4], mat[4][4], pamat[4][4], size = 0.0;
1407 int a, b, hair = 0;
1408 int totpart, totchild;
1409
1410 int no_draw_flag = PARS_UNEXIST;
1411
1412 if (psys == nullptr) {
1413 return;
1414 }
1415
1416 part = psys->part;
1417
1418 if (part == nullptr) {
1419 return;
1420 }
1421
1422 if (!psys_check_enabled(par, psys, for_render)) {
1423 return;
1424 }
1425
1426 if (!for_render) {
1427 no_draw_flag |= PARS_NO_DISP;
1428 }
1429
1430 /* NOTE: in old animation system, used parent object's time-offset. */
1431 ctime = DEG_get_ctime(ctx->depsgraph);
1432
1433 totpart = psys->totpart;
1434 totchild = psys->totchild;
1435
1436 if ((for_render || part->draw_as == PART_DRAW_REND) &&
1438 {
1439 ParticleSimulationData sim = {nullptr};
1440 sim.depsgraph = ctx->depsgraph;
1441 sim.scene = scene;
1442 sim.ob = par;
1443 sim.psys = psys;
1444 sim.psmd = psys_get_modifier(par, psys);
1445 /* Make sure emitter `world_to_object` is in global coordinates instead of render view
1446 * coordinates. */
1447 invert_m4_m4(par->runtime->world_to_object.ptr(), par->object_to_world().ptr());
1448
1449 /* First check for loops (particle system object used as dupli-object). */
1450 if (part->ren_as == PART_DRAW_OB) {
1451 if (ELEM(part->instance_object, nullptr, par)) {
1452 return;
1453 }
1454 }
1455 else { /* #PART_DRAW_GR. */
1456 if (part->instance_collection == nullptr) {
1457 return;
1458 }
1459
1460 const ListBase dup_collection_objects = BKE_collection_object_cache_get(
1461 part->instance_collection);
1462 if (BLI_listbase_is_empty(&dup_collection_objects)) {
1463 return;
1464 }
1465
1466 if (BLI_findptr(&dup_collection_objects, par, offsetof(Base, object))) {
1467 return;
1468 }
1469 }
1470
1471 /* If we have a hair particle system, use the path cache. */
1472 if (part->type == PART_HAIR) {
1473 if (psys->flag & PSYS_HAIR_DONE) {
1474 hair = (totchild == 0 || psys->childcache) && psys->pathcache;
1475 }
1476 if (!hair) {
1477 return;
1478 }
1479
1480 /* We use cache, update `totchild` according to cached data. */
1481 totchild = psys->totchildcache;
1482 totpart = psys->totcached;
1483 }
1484
1485 RNG *rng = BLI_rng_new_srandom(31415926u + uint(psys->seed));
1486
1487 psys_sim_data_init(&sim);
1488
1489 /* Gather list of objects or single object. */
1490 int totcollection = 0;
1491
1492 const bool use_whole_collection = part->draw & PART_DRAW_WHOLE_GR;
1493 const bool use_collection_count = part->draw & PART_DRAW_COUNT_GR && !use_whole_collection;
1494 if (part->ren_as == PART_DRAW_GR) {
1495 if (use_collection_count) {
1499 part->instance_collection, object, mode)
1500 {
1501 if (dw->ob == object) {
1502 totcollection += dw->count;
1503 break;
1504 }
1505 }
1507 }
1508 }
1509 else {
1511 {
1512 (void)object;
1513 totcollection++;
1514 }
1516 }
1517
1518 oblist = MEM_calloc_arrayN<Object *>(totcollection, "dupcollection object list");
1519
1520 if (use_collection_count) {
1521 a = 0;
1524 part->instance_collection, object, mode)
1525 {
1526 if (dw->ob == object) {
1527 for (b = 0; b < dw->count; b++, a++) {
1528 oblist[a] = dw->ob;
1529 }
1530 break;
1531 }
1532 }
1534 }
1535 }
1536 else {
1537 a = 0;
1539 {
1540 oblist[a] = object;
1541 a++;
1542 }
1544 }
1545 }
1546 else {
1547 ob = part->instance_object;
1548 }
1549
1550 if (totchild == 0 || part->draw & PART_DRAW_PARENT) {
1551 a = 0;
1552 }
1553 else {
1554 a = totpart;
1555 }
1556
1557 for (pa = psys->particles; a < totpart + totchild; a++, pa++) {
1558 if (a < totpart) {
1559 /* Handle parent particle. */
1560 if (pa->flag & no_draw_flag) {
1561 continue;
1562 }
1563
1564#if 0 /* UNUSED */
1565 pa_num = pa->num;
1566#endif
1567 size = pa->size;
1568 }
1569 else {
1570 /* Handle child particle. */
1571 cpa = &psys->child[a - totpart];
1572
1573#if 0 /* UNUSED */
1574 pa_num = a;
1575#endif
1576 size = psys_get_child_size(psys, cpa, ctime, nullptr);
1577 }
1578
1579 /* Some hair paths might be non-existent so they can't be used for duplication. */
1580 if (hair && psys->pathcache &&
1581 ((a < totpart && psys->pathcache[a]->segments < 0) ||
1582 (a >= totpart && psys->childcache[a - totpart]->segments < 0)))
1583 {
1584 continue;
1585 }
1586
1587 if (part->ren_as == PART_DRAW_GR) {
1588 /* Prevent divide by zero below #28336. */
1589 if (totcollection == 0) {
1590 continue;
1591 }
1592
1593 /* For collections, pick the object based on settings. */
1594 if (part->draw & PART_DRAW_RAND_GR && !use_whole_collection) {
1595 b = BLI_rng_get_int(rng) % totcollection;
1596 }
1597 else {
1598 b = a % totcollection;
1599 }
1600
1601 ob = oblist[b];
1602 }
1603
1604 if (hair) {
1605 /* Hair we handle separate and compute transform based on hair keys. */
1606 if (a < totpart) {
1607 cache = psys->pathcache[a];
1608 psys_get_dupli_path_transform(&sim, pa, nullptr, cache, pamat, &scale);
1609 }
1610 else {
1611 cache = psys->childcache[a - totpart];
1612 psys_get_dupli_path_transform(&sim, nullptr, cpa, cache, pamat, &scale);
1613 }
1614
1615 copy_v3_v3(pamat[3], cache->co);
1616 pamat[3][3] = 1.0f;
1617 }
1618 else {
1619 /* First key. */
1620 state.time = ctime;
1621 if (psys_get_particle_state(&sim, a, &state, false) == 0) {
1622 continue;
1623 }
1624
1625 float tquat[4];
1626 normalize_qt_qt(tquat, state.rot);
1627 quat_to_mat4(pamat, tquat);
1628 copy_v3_v3(pamat[3], state.co);
1629 pamat[3][3] = 1.0f;
1630 }
1631
1632 if (part->ren_as == PART_DRAW_GR && psys->part->draw & PART_DRAW_WHOLE_GR) {
1633 b = 0;
1635 {
1636 copy_m4_m4(tmat, oblist[b]->object_to_world().ptr());
1637
1638 /* Apply collection instance offset. */
1640
1641 /* Apply particle scale. */
1642 mul_mat3_m4_fl(tmat, size * scale);
1643 mul_v3_fl(tmat[3], size * scale);
1644
1645 /* Individual particle transform. */
1646 mul_m4_m4m4(mat, pamat, tmat);
1647
1648 dob = make_dupli(ctx, object, mat, a);
1649 dob->particle_system = psys;
1650
1651 psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
1652
1653 b++;
1654 }
1656 }
1657 else {
1658 float obmat[4][4];
1659 copy_m4_m4(obmat, ob->object_to_world().ptr());
1660
1661 float vec[3];
1662 copy_v3_v3(vec, obmat[3]);
1663 zero_v3(obmat[3]);
1664
1665 /* Particle rotation uses x-axis as the aligned axis,
1666 * so pre-rotate the object accordingly. */
1667 if ((part->draw & PART_DRAW_ROTATE_OB) == 0) {
1668 float xvec[3], q[4], size_mat[4][4], original_size[3];
1669
1670 mat4_to_size(original_size, obmat);
1671 size_to_mat4(size_mat, original_size);
1672
1673 xvec[0] = -1.0f;
1674 xvec[1] = xvec[2] = 0;
1675 vec_to_quat(q, xvec, ob->trackflag, ob->upflag);
1676 quat_to_mat4(obmat, q);
1677 obmat[3][3] = 1.0f;
1678
1679 /* Add scaling if requested. */
1680 if ((part->draw & PART_DRAW_NO_SCALE_OB) == 0) {
1681 mul_m4_m4m4(obmat, obmat, size_mat);
1682 }
1683 }
1684 else if (part->draw & PART_DRAW_NO_SCALE_OB) {
1685 /* Remove scaling. */
1686 float size_mat[4][4], original_size[3];
1687
1688 mat4_to_size(original_size, obmat);
1689 size_to_mat4(size_mat, original_size);
1690 invert_m4(size_mat);
1691
1692 mul_m4_m4m4(obmat, obmat, size_mat);
1693 }
1694
1695 mul_m4_m4m4(tmat, pamat, obmat);
1696 mul_mat3_m4_fl(tmat, size * scale);
1697
1698 copy_m4_m4(mat, tmat);
1699
1700 if (part->draw & PART_DRAW_GLOBAL_OB) {
1701 add_v3_v3v3(mat[3], mat[3], vec);
1702 }
1703
1704 dob = make_dupli(ctx, ob, mat, a);
1705 dob->particle_system = psys;
1706 psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
1707 }
1708 }
1709
1710 BLI_rng_free(rng);
1711 psys_sim_data_free(&sim);
1712 }
1713
1714 /* Clean up. */
1715 if (oblist) {
1716 MEM_freeN(oblist);
1717 }
1718}
1719
1721{
1722 /* Particle system take up one level in id, the particles another. */
1723 int psysid;
1725 /* Particles create one more level for persistent `psys` index. */
1726 DupliContext pctx;
1727 if (copy_dupli_context(&pctx, ctx, ctx->object, nullptr, psysid)) {
1728 make_duplis_particle_system(&pctx, psys);
1729 }
1730 }
1731}
1732
1734 /*type*/ OB_DUPLIPARTS,
1735 /*make_duplis*/ make_duplis_particles,
1736};
1737
1739
1740/* -------------------------------------------------------------------- */
1743
1745{
1746 int transflag = ctx->object->transflag;
1747 int visibility_flag = ctx->object->visibility_flag;
1748
1749 if ((transflag & OB_DUPLI) == 0 && ctx->object->runtime->geometry_set_eval == nullptr) {
1750 return nullptr;
1751 }
1752
1753 /* Meta-ball objects can't create instances, but the dupli system is used to "instance" their
1754 * evaluated mesh to render engines. We need to exit early to avoid recursively instancing the
1755 * evaluated meta-ball mesh on meta-ball instances that already contribute to the basis. */
1756 if (ctx->object->type == OB_MBALL && ctx->level > 0) {
1757 return nullptr;
1758 }
1759
1760 /* Should the dupli's be generated for this object? - Respect restrict flags. */
1761 if (DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER ? (visibility_flag & OB_HIDE_RENDER) :
1762 (visibility_flag & OB_HIDE_VIEWPORT))
1763 {
1764 return nullptr;
1765 }
1766
1767 /* Give "Object as Font" instances higher priority than geometry set instances, to retain
1768 * the behavior from before curve object meshes were processed as instances internally. */
1769 if (transflag & OB_DUPLIVERTS) {
1770 if (ctx->object->type == OB_FONT) {
1771 return &gen_dupli_verts_font;
1772 }
1773 }
1774
1775 if (ctx->object->runtime->geometry_set_eval != nullptr) {
1777 return &gen_dupli_geometry_set;
1778 }
1779 }
1780
1781 if (transflag & OB_DUPLIPARTS) {
1782 return &gen_dupli_particles;
1783 }
1784 if (transflag & OB_DUPLIVERTS) {
1785 if (ctx->object->type == OB_MESH) {
1786 return &gen_dupli_verts;
1787 }
1788 }
1789 else if (transflag & OB_DUPLIFACES) {
1790 if (ctx->object->type == OB_MESH) {
1791 return &gen_dupli_faces;
1792 }
1793 }
1794 else if (transflag & OB_DUPLICOLLECTION) {
1795 return &gen_dupli_collection;
1796 }
1797
1798 return nullptr;
1799}
1800
1802
1803/* -------------------------------------------------------------------- */
1806
1808 Scene *sce,
1809 Object *ob,
1810 Set<const Object *> *include_objects,
1811 DupliList &r_duplilist)
1812{
1813 DupliContext ctx;
1814 Vector<Object *> instance_stack;
1815 Vector<short> dupli_gen_type_stack({0});
1816 instance_stack.append(ob);
1817 init_context(&ctx,
1818 depsgraph,
1819 sce,
1820 ob,
1821 nullptr,
1822 include_objects,
1823 instance_stack,
1824 dupli_gen_type_stack,
1825 r_duplilist);
1826 if (ctx.gen) {
1827 ctx.gen->make_duplis(&ctx);
1828 }
1829}
1830
1832 Scene *sce,
1833 Object *ob_eval,
1834 const ViewerPath *viewer_path,
1835 DupliList &r_duplilist)
1836{
1837 DupliContext ctx;
1838 Vector<Object *> instance_stack;
1839 Vector<short> dupli_gen_type_stack({0});
1840 instance_stack.append(ob_eval);
1841 init_context(&ctx,
1842 depsgraph,
1843 sce,
1844 ob_eval,
1845 nullptr,
1846 nullptr,
1847 instance_stack,
1848 dupli_gen_type_stack,
1849 r_duplilist);
1850
1851 Object *ob_orig = DEG_get_original(ob_eval);
1852
1853 LISTBASE_FOREACH (ModifierData *, md_orig, &ob_orig->modifiers) {
1854 if (md_orig->type != eModifierType_Nodes) {
1855 continue;
1856 }
1857 NodesModifierData *nmd_orig = reinterpret_cast<NodesModifierData *>(md_orig);
1858 if (!nmd_orig->runtime->eval_log) {
1859 continue;
1860 }
1861 if (const geo_log::ViewerNodeLog *viewer_log =
1863 {
1864 if (const blender::bke::GeometrySet *viewer_geometry = viewer_log->main_geometry()) {
1865 ctx.preview_base_geometry = &*viewer_geometry;
1867 *viewer_geometry,
1868 ob_eval->object_to_world().ptr(),
1869 true,
1870 ob_eval->type == OB_CURVES);
1871 }
1872 }
1873 }
1874}
1875
1877 Scene &scene,
1878 Object &ob)
1879{
1880 using namespace blender;
1881
1882 DupliContext ctx;
1883 DupliList duplilist;
1884 Vector<Object *> instance_stack({&ob});
1885 Vector<short> dupli_gen_type_stack({0});
1886
1887 init_context(&ctx,
1888 &depsgraph,
1889 &scene,
1890 &ob,
1891 nullptr,
1892 nullptr,
1893 instance_stack,
1894 dupli_gen_type_stack,
1895 duplilist);
1896 if (ctx.gen == &gen_dupli_geometry_set) {
1897 /* These are not legacy instances. */
1898 return {};
1899 }
1900 if (ctx.gen) {
1901 ctx.gen->make_duplis(&ctx);
1902 }
1903 const bool is_particle_duplis = ctx.gen == &gen_dupli_particles;
1904 /* Particle instances are on the second level, because the first level is the particle system
1905 * itself. */
1906 const int level_to_use = is_particle_duplis ? 1 : 0;
1907
1908 Vector<DupliObject *> top_level_duplis;
1909 for (DupliObject &dob : duplilist) {
1910 BLI_assert(dob.ob != &ob);
1911 /* We only need the top level instances in the end, because when #Instances references an
1912 * object, it implicitly also references all instances of that object. */
1913 if (dob.level == level_to_use) {
1914 top_level_duplis.append(&dob);
1915 }
1916 }
1917
1918 bke::Instances top_level_instances;
1919 const float4x4 &world_to_object = ob.world_to_object();
1920
1921 VectorSet<Object *> referenced_objects;
1922 const int instances_num = top_level_duplis.size();
1923 top_level_instances.resize(instances_num);
1924 MutableSpan<float4x4> instances_transforms = top_level_instances.transforms_for_write();
1925 MutableSpan<int> instances_reference_handles = top_level_instances.reference_handles_for_write();
1926 bke::SpanAttributeWriter<int> instances_ids =
1929 for (const int i : IndexRange(instances_num)) {
1930 DupliObject &dob = *top_level_duplis[i];
1931 Object &instanced_object = *dob.ob;
1932 if (referenced_objects.add(&instanced_object)) {
1933 top_level_instances.add_new_reference(instanced_object);
1934 }
1935 const int handle = referenced_objects.index_of(&instanced_object);
1936 instances_transforms[i] = world_to_object * float4x4(dob.mat);
1937 instances_reference_handles[i] = handle;
1938
1939 int id = dob.persistent_id[0];
1940 if (is_particle_duplis) {
1941 const int particle_system_i = dob.persistent_id[0];
1942 const int particle_i = dob.persistent_id[1];
1943 /* Attempt to build a unique ID for each particle. This allows for unique ids as long as
1944 * there are not more than <= 2^26 = 67.108.864 particles per particle system and there are
1945 * <= 2^6 = 64 particle systems. Otherwise there will be duplicate IDs but this is quite
1946 * unlikely in the legacy particle system. */
1947 id = (particle_system_i << 26) + particle_i;
1948 }
1949 instances_ids.span[i] = id;
1950 }
1951 instances_ids.finish();
1952
1953 return top_level_instances;
1954}
1955
1957
1958/* -------------------------------------------------------------------- */
1961
1964 const char *name,
1965 float r_value[4])
1966{
1967 using namespace blender;
1968 using namespace blender::bke;
1969
1970 /* Loop over layers from innermost to outermost. */
1971 for (const int i : IndexRange(ARRAY_SIZE(dupli->instance_data))) {
1972 /* Skip non-geonode layers. */
1973 if (dupli->instance_data[i] == nullptr) {
1974 continue;
1975 }
1976
1977 const InstancesComponent *component =
1979
1980 if (component == nullptr) {
1981 continue;
1982 }
1983
1984 /* Attempt to look up the attribute. */
1985 std::optional<bke::AttributeAccessor> attributes = component->attributes();
1986 const VArray data = *attributes->lookup<ColorGeometry4f>(name);
1987
1988 /* If the attribute was found and converted to float RGBA successfully, output it. */
1989 if (data) {
1990 copy_v4_v4(r_value, data[dupli->instance_idx[i]]);
1991 return true;
1992 }
1993 }
1994
1995 return false;
1996}
1997
1999static bool find_property_rgba(PointerRNA *id_ptr, const char *name, float r_data[4])
2000{
2001 if (id_ptr->data == nullptr) {
2002 return false;
2003 }
2004
2005 /* First, check custom properties. */
2006 IDProperty *group = RNA_struct_idprops(id_ptr, false);
2007 PropertyRNA *prop = nullptr;
2008
2009 if (group && group->type == IDP_GROUP) {
2010 prop = (PropertyRNA *)IDP_GetPropertyFromGroup(group, name);
2011 }
2012
2013 /* If not found, do full path lookup. */
2015
2016 if (prop != nullptr) {
2017 ptr = *id_ptr;
2018 }
2019 else if (!RNA_path_resolve(id_ptr, name, &ptr, &prop)) {
2020 return false;
2021 }
2022
2023 if (prop == nullptr) {
2024 return false;
2025 }
2026
2027 /* Convert the value to RGBA if possible. */
2028 PropertyType type = RNA_property_type(prop);
2029 int array_len = RNA_property_array_length(&ptr, prop);
2030
2031 if (array_len == 0) {
2032 float value;
2033
2034 if (type == PROP_FLOAT) {
2035 value = RNA_property_float_get(&ptr, prop);
2036 }
2037 else if (type == PROP_INT) {
2038 value = float(RNA_property_int_get(&ptr, prop));
2039 }
2040 else if (type == PROP_BOOLEAN) {
2041 value = RNA_property_boolean_get(&ptr, prop) ? 1.0f : 0.0f;
2042 }
2043 else {
2044 return false;
2045 }
2046
2047 copy_v4_fl4(r_data, value, value, value, 1);
2048 return true;
2049 }
2050
2051 if (type == PROP_FLOAT && array_len <= 4) {
2052 copy_v4_fl4(r_data, 0, 0, 0, 1);
2053 RNA_property_float_get_array(&ptr, prop, r_data);
2054 return true;
2055 }
2056
2057 if (type == PROP_INT && array_len <= 4) {
2058 int tmp[4] = {0, 0, 0, 1};
2059 RNA_property_int_get_array(&ptr, prop, tmp);
2060 for (int i = 0; i < 4; i++) {
2061 r_data[i] = float(tmp[i]);
2062 }
2063 return true;
2064 }
2065
2066 return false;
2067}
2068
2069static bool find_property_rgba(const ID *id, const char *name, float r_data[4])
2070{
2071 PointerRNA ptr = RNA_id_pointer_create(const_cast<ID *>(id));
2072 return find_property_rgba(&ptr, name, r_data);
2073}
2074
2076 const DupliObject *dupli,
2077 const Object *dupli_parent,
2078 const char *name,
2079 float r_value[4])
2080{
2081 /* Check the dupli particle system. */
2082 if (dupli && dupli->particle_system) {
2083 const ParticleSettings *settings = dupli->particle_system->part;
2084
2085 if (find_property_rgba(&settings->id, name, r_value)) {
2086 return true;
2087 }
2088 }
2089
2090 /* Check geometry node dupli instance attributes. */
2091 if (dupli && find_geonode_attribute_rgba(dupli, name, r_value)) {
2092 return true;
2093 }
2094
2095 /* Check the dupli parent object. */
2096 if (dupli_parent && find_property_rgba(&dupli_parent->id, name, r_value)) {
2097 return true;
2098 }
2099
2100 /* Check the main object. */
2101 if (ob) {
2102 if (find_property_rgba(&ob->id, name, r_value)) {
2103 return true;
2104 }
2105
2106 /* Check the main object data (e.g. mesh). */
2107 if (ob->data && find_property_rgba((const ID *)ob->data, name, r_value)) {
2108 return true;
2109 }
2110 }
2111
2112 copy_v4_fl(r_value, 0.0f);
2113 return false;
2114}
2115
2117 const ViewLayer *layer,
2118 const char *name,
2119 float r_value[4])
2120{
2121 if (layer) {
2123 &const_cast<ID &>(scene->id), &RNA_ViewLayer, const_cast<ViewLayer *>(layer));
2124
2125 if (find_property_rgba(&layer_ptr, name, r_value)) {
2126 return true;
2127 }
2128 }
2129
2130 if (find_property_rgba(&scene->id, name, r_value)) {
2131 return true;
2132 }
2133
2134 if (scene->world && find_property_rgba(&scene->world->id, name, r_value)) {
2135 return true;
2136 }
2137
2138 copy_v4_fl(r_value, 0.0f);
2139 return false;
2140}
2141
#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN(_collection, _object, _mode)
ListBase BKE_collection_object_cache_get(Collection *collection)
#define FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END
const void * CustomData_get_layer_n(const CustomData *data, eCustomDataType type, int n)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
int CustomData_get_n_offset(const CustomData *data, eCustomDataType type, int n)
int CustomData_get_render_layer(const CustomData *data, eCustomDataType type)
blender::VectorList< DupliObject > DupliList
constexpr int MAX_DUPLI_RECUR
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:61
blender::Span< blender::float3 > BKE_editmesh_cache_ensure_vert_normals(BMEditMesh &em, blender::bke::EditMeshData &emd)
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, blender::StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:747
@ ME_WRAPPER_TYPE_BMESH
General operations, lookup, etc. for blender objects.
const Mesh * BKE_object_get_editmesh_eval_cage(const Object *object)
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
void psys_get_dupli_path_transform(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ChildParticle *cpa, struct ParticleCacheKey *cache, float mat[4][4], float *scale)
Definition particle.cc:5152
struct ParticleSystemModifierData * psys_get_modifier(struct Object *ob, struct ParticleSystem *psys)
Definition particle.cc:2155
void psys_get_dupli_texture(struct ParticleSystem *psys, struct ParticleSettings *part, struct ParticleSystemModifierData *psmd, struct ParticleData *pa, struct ChildParticle *cpa, float uv[2], float orco[3])
Definition particle.cc:5049
bool psys_check_enabled(struct Object *ob, struct ParticleSystem *psys, bool use_render_params)
Definition particle.cc:710
void psys_sim_data_free(struct ParticleSimulationData *sim)
Definition particle.cc:633
void psys_find_group_weights(struct ParticleSettings *part)
Definition particle.cc:745
float psys_get_child_size(struct ParticleSystem *psys, struct ChildParticle *cpa, float cfra, float *pa_time)
Definition particle.cc:4503
void psys_sim_data_init(struct ParticleSimulationData *sim)
Definition particle.cc:592
bool psys_get_particle_state(struct ParticleSimulationData *sim, int p, struct ParticleKey *state, bool always)
Definition particle.cc:4879
@ FO_DUPLI
Definition BKE_vfont.hh:82
bool BKE_vfont_to_curve_ex(Object *ob, const Curve &cu, eEditFontMode mode, ListBase *r_nubase, const char32_t **r_text, int *r_text_len, bool *r_text_free, CharTrans **r_chartransdata, float *r_font_size_eval)
#define BLI_assert(a)
Definition BLI_assert.h:46
void ** BLI_ghash_lookup_p(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.cc:745
GHash * BLI_ghash_int_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition BLI_ghash.cc:707
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.cc:860
BLI_INLINE unsigned int BLI_hash_int(unsigned int k)
Definition BLI_hash.h:87
BLI_INLINE unsigned int BLI_hash_string(const char *str)
Definition BLI_hash.h:67
BLI_INLINE unsigned int BLI_hash_int_2d(unsigned int kx, unsigned int ky)
Definition BLI_hash.h:51
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
void * BLI_findptr(const struct ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
float area_poly_v3(const float verts[][3], unsigned int nr)
Definition math_geom.cc:133
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void mul_mat3_m4_fl(float R[4][4], float f)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void mul_m4_m4_pre(float R[4][4], const float A[4][4])
void size_to_mat4(float R[4][4], const float size[3])
void mul_m4_v3(const float M[4][4], float r[3])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void loc_quat_size_to_mat4(float R[4][4], const float loc[3], const float quat[4], const float size[3])
bool invert_m4(float mat[4][4])
void mat4_to_size(float size[3], const float M[4][4])
void mul_m4_m3m4(float R[4][4], const float A[3][3], const float B[4][4])
void mul_mat3_m4_v3(const float mat[4][4], float r[3])
void unit_m4(float m[4][4])
void vec_to_quat(float q[4], const float vec[3], short axis, short upflag)
void quat_to_mat4(float m[4][4], const float q[4])
void unit_qt(float q[4])
float normalize_qt_qt(float r[4], const float q[4])
void tri_to_quat_ex(float quat[4], const float v1[3], const float v2[3], const float v3[3], const float no_orig[3])
void axis_angle_to_mat4_single(float R[4][4], char axis, float angle)
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
MINLINE void copy_v4_fl4(float v[4], float x, float y, float z, float w)
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void zero_v3(float r[3])
MINLINE void copy_v4_fl(float r[4], float f)
Random number functions.
void int BLI_rng_get_int(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition rand.cc:73
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
Definition rand.cc:53
struct RNG * BLI_rng_new_srandom(unsigned int seed)
Definition rand.cc:46
#define BLI_UTF8_MAX
size_t BLI_str_utf8_from_unicode(unsigned int c, char *dst, size_t dst_maxncpy) ATTR_NONNULL(2)
unsigned int uint
#define ARRAY_SIZE(arr)
#define STREQLEN(a, b, n)
#define UNLIKELY(x)
#define ELEM(...)
#define POINTER_FROM_UINT(i)
eEvaluationMode
@ DAG_EVAL_RENDER
float DEG_get_ctime(const Depsgraph *graph)
#define DEG_OBJECT_ITER_BEGIN(settings_, instance_)
#define DEG_OBJECT_ITER_END
bool DEG_is_evaluated(const T *id)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
T * DEG_get_original(T *id)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
@ ID_MB
@ IDP_GROUP
Object groups, one object can be in many groups at once.
@ CD_PROP_FLOAT2
@ eModifierType_Nodes
@ OB_HIDE_RENDER
@ OB_HIDE_VIEWPORT
@ OB_MBALL
@ OB_FONT
@ OB_GREASE_PENCIL
@ OB_MESH
@ OB_POINTCLOUD
@ OB_VOLUME
@ OB_CURVES_LEGACY
@ OB_CURVES
@ OB_DONE
@ OB_DUPLIFACES
@ OB_DUPLI
@ OB_DUPLIPARTS
@ OB_DUPLIVERTS
@ OB_DUPLICOLLECTION
@ OB_DUPLIROT
@ OB_DUPLIFACES_SCALE
@ PSYS_HAIR_DONE
@ PART_DRAW_WHOLE_GR
@ PART_DRAW_GLOBAL_OB
@ PART_DRAW_PARENT
@ PART_DRAW_NO_SCALE_OB
@ PART_DRAW_COUNT_GR
@ PART_DRAW_RAND_GR
@ PART_DRAW_ROTATE_OB
@ PART_HAIR
@ PART_DRAW_GR
@ PART_DRAW_OB
@ PART_DRAW_REND
@ PARS_NO_DISP
@ PARS_UNEXIST
#define OBEDIT_FROM_OBACT(ob)
Read Guarded memory(de)allocation.
PropertyType
Definition RNA_types.hh:161
@ PROP_FLOAT
Definition RNA_types.hh:164
@ PROP_BOOLEAN
Definition RNA_types.hh:162
@ PROP_INT
Definition RNA_types.hh:163
#define BM_FACE_FIRST_LOOP(p)
#define BM_elem_index_get(ele)
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
@ BM_VERTS_OF_MESH
@ BM_FACES_OF_MESH
BMesh const char void * data
#define BM_VERT
ATTR_WARN_UNUSED_RESULT const BMVert * v
void BM_face_uv_calc_center_median(const BMFace *f, const int cd_loop_uv_offset, float r_cent[2])
BPy_StructRNA * depsgraph
long long int int64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
bool add(const Key &key)
int64_t index_of(const Key &key) const
constexpr int64_t size() const
constexpr const T * data() const
Definition BLI_span.hh:215
constexpr int64_t size() const
Definition BLI_span.hh:252
constexpr IndexRange index_range() const
Definition BLI_span.hh:401
constexpr bool is_empty() const
Definition BLI_span.hh:260
constexpr bool is_empty() const
void append(const T &value)
int64_t size() const
void append(const T &value)
Collection & collection() const
std::optional< AttributeAccessor > attributes() const final
Span< int > reference_handles() const
Definition instances.cc:215
MutableSpan< int > reference_handles_for_write()
Definition instances.cc:222
int add_new_reference(const InstanceReference &reference)
Definition instances.cc:269
Span< float4x4 > transforms() const
Definition instances.cc:228
Span< InstanceReference > references() const
Definition instances.cc:275
void resize(int capacity)
Definition instances.cc:191
bke::MutableAttributeAccessor attributes_for_write()
Definition instances.cc:69
MutableSpan< float4x4 > transforms_for_write()
Definition instances.cc:235
Span< int > unique_ids() const
Definition instances.cc:505
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef attribute_id, AttrDomain domain, AttrType data_type)
static const ViewerNodeLog * find_viewer_node_log_for_path(const ViewerPath &viewer_path)
nullptr float
#define offsetof(t, d)
#define GS(x)
#define printf(...)
VecBase< float, D > normalize(VecOp< float, D >) RET
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:123
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
static ulong state[N]
#define G(x, y, z)
bool object_has_geometry_set_instances(const Object &object)
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
VecBase< T, 3 > cross_poly(Span< VecBase< T, 3 > > poly)
MatBase< float, 4, 4 > float4x4
VecBase< float, 2 > float2
VecBase< float, 3 > float3
static void make_duplis_verts(const DupliContext *ctx)
static constexpr short GEOMETRY_SET_DUPLI_GENERATOR_TYPE
static Object * find_family_object(Main *bmain, const char *family, size_t family_len, uint ch, GHash *family_gh)
static void make_child_duplis(const DupliContext *ctx, void *userdata, MakeChildDuplisFunc make_child_duplis_cb)
static bool copy_dupli_context(DupliContext *r_ctx, const DupliContext *ctx, Object *ob, const float mat[4][4], int index, const GeometrySet *geometry=nullptr, int64_t instance_index=0)
static void make_duplis_collection(const DupliContext *ctx)
static void make_child_duplis_verts_from_mesh(const DupliContext *ctx, void *userdata, Object *inst_ob)
static DupliObject * face_dupli(const DupliContext *ctx, Object *inst_ob, const float child_imat[4][4], const int index, const bool use_scale, const float scale_fac, Span< float3 > coords)
static void make_duplis_font(const DupliContext *ctx)
bool BKE_object_dupli_find_rgba_attribute(const Object *ob, const DupliObject *dupli, const Object *dupli_parent, const char *name, float r_value[4])
static void make_child_duplis_faces_from_editmesh(const DupliContext *ctx, void *userdata, Object *inst_ob)
static const DupliGenerator gen_dupli_verts
static void make_duplis_particles(const DupliContext *ctx)
static const DupliGenerator gen_dupli_collection
static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem *psys)
static DupliObject * face_dupli_from_mesh(const DupliContext *ctx, Object *inst_ob, const float child_imat[4][4], const int index, const bool use_scale, const float scale_fac, const Span< int > face_verts, const Span< float3 > vert_positions)
void object_duplilist(Depsgraph *depsgraph, Scene *sce, Object *ob, Set< const Object * > *include_objects, DupliList &r_duplilist)
static void make_child_duplis_faces_from_mesh(const DupliContext *ctx, void *userdata, Object *inst_ob)
void(*)(const DupliContext *ctx, void *userdata, Object *child) MakeChildDuplisFunc
static void get_duplivert_transform(const float3 &co, const float3 &no, const bool use_rotation, const short axis, const short upflag, float r_mat[4][4])
void object_duplilist_preview(Depsgraph *depsgraph, Scene *sce, Object *ob_eval, const ViewerPath *viewer_path, DupliList &r_duplilist)
static const DupliGenerator * get_dupli_generator(const DupliContext *ctx)
static bool find_geonode_attribute_rgba(const DupliObject *dupli, const char *name, float r_value[4])
static DupliObject * vertex_dupli(const DupliContext *ctx, Object *inst_ob, const float child_imat[4][4], int index, const float3 &co, const float3 &no, const bool use_rotation)
static void make_duplis_geometry_set_impl(const DupliContext *ctx, const GeometrySet &geometry_set, const float parent_transform[4][4], bool geometry_set_is_instance, bool use_new_curves_type)
static bool find_property_rgba(PointerRNA *id_ptr, const char *name, float r_data[4])
bool BKE_view_layer_find_rgba_attribute(const Scene *scene, const ViewLayer *layer, const char *name, float r_value[4])
static bool is_child(const Object *ob, const Object *parent)
static const Mesh * mesh_data_from_duplicator_object(Object *ob, BMEditMesh **r_em, Span< float3 > *r_vert_coords, Span< float3 > *r_vert_normals)
static DupliObject * face_dupli_from_editmesh(const DupliContext *ctx, Object *inst_ob, const float child_imat[4][4], const int index, const bool use_scale, const float scale_fac, BMFace *f, const Span< float3 > vert_positions_deform)
static const DupliGenerator gen_dupli_particles
static void init_context(DupliContext *r_ctx, Depsgraph *depsgraph, Scene *scene, Object *ob, const float space_mat[4][4], blender::Set< const Object * > *include_objects, Vector< Object * > &instance_stack, Vector< short > &dupli_gen_type_stack, DupliList &duplilist)
static const DupliGenerator gen_dupli_faces
static void make_recursive_duplis(const DupliContext *ctx, Object *ob, const float space_mat[4][4], int index, const GeometrySet *geometry=nullptr, int64_t instance_index=0)
static void make_child_duplis_verts_from_editmesh(const DupliContext *ctx, void *userdata, Object *inst_ob)
static const DupliGenerator gen_dupli_geometry_set
static DupliObject * make_dupli(const DupliContext *ctx, Object *ob, const ID *object_data, const float mat[4][4], int index, const GeometrySet *geometry=nullptr, int64_t instance_index=0)
static const DupliGenerator gen_dupli_verts_font
static void get_dupliface_transform_from_coords(Span< float3 > coords, const bool use_scale, const float scale_fac, float r_mat[4][4])
static void make_duplis_faces(const DupliContext *ctx)
static void make_duplis_geometry_set(const DupliContext *ctx)
blender::bke::Instances object_duplilist_legacy_instances(Depsgraph &depsgraph, Scene &scene, Object &ob)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
const char * name
#define sqrtf
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
PropertyType RNA_property_type(PropertyRNA *prop)
IDProperty * RNA_struct_idprops(PointerRNA *ptr, bool create)
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
PointerRNA RNA_id_pointer_create(ID *id)
bool RNA_path_resolve(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:532
static void text_free(SpaceLink *sl)
Definition space_text.cc:91
struct BMVert * v
struct BMLoop * next
float co[3]
char elem_index_dirty
CustomData ldata
blender::float2 offset
Definition BKE_vfont.hh:21
float rotate
Definition BKE_vfont.hh:22
char family[64]
float fsize
Collection * collection
const GeometrySet * instance_data[MAX_DUPLI_RECUR]
int64_t instance_idx[MAX_DUPLI_RECUR]
Object * obedit
const GeometrySet * preview_base_geometry
float space_mat[4][4]
Vector< short > * dupli_gen_type_stack
DupliList * duplilist
Object * root_object
Object * object
int preview_instance_index
int persistent_id[MAX_DUPLI_RECUR]
Set< const Object * > * include_objects
Depsgraph * depsgraph
const struct DupliGenerator * gen
Vector< Object * > * instance_stack
void(* make_duplis)(const DupliContext *ctx)
const blender::bke::GeometrySet * preview_base_geometry
int preview_instance_index
float mat[4][4]
int instance_idx[4]
const blender::bke::GeometrySet * instance_data[4]
ParticleSystem * particle_system
int persistent_id[MAX_DUPLI_RECUR]
float orco[3]
unsigned int random_id
Span< float3 > vert_positions_deform
FaceDupliData_Params params
Span< int > corner_verts
blender::OffsetIndices< int > faces
FaceDupliData_Params params
const float2 * uv_map
const float(* orco)[3]
Span< float3 > vert_positions
const DupliContext * ctx
char type
Definition DNA_ID.h:156
Definition DNA_ID.h:414
char name[258]
Definition DNA_ID.h:432
struct ID * orig_id
Definition DNA_ID.h:501
ListBase objects
Definition BKE_main.hh:280
MeshRuntimeHandle * runtime
CustomData corner_data
CustomData vert_data
int faces_num
int verts_num
NodesModifierRuntimeHandle * runtime
ListBase particlesystem
short transflag
struct Collection * instance_collection
ObjectRuntimeHandle * runtime
ListBase modifiers
float parentinv[4][4]
short visibility_flag
float instance_faces_scale
struct Object * parent
short trackflag
struct Collection * instance_collection
struct ListBase instance_weights
struct Object * instance_object
struct Depsgraph * depsgraph
struct ParticleSystemModifierData * psmd
struct Scene * scene
struct ParticleSystem * psys
struct Object * ob
ChildParticle * child
ParticleData * particles
ParticleSettings * part
struct ParticleCacheKey ** childcache
struct ParticleCacheKey ** pathcache
void * data
Definition RNA_types.hh:53
Definition rand.cc:33
struct World * world
Span< float3 > vert_positions_deform
VertexDupliData_Params params
Span< float3 > vert_normals_deform
VertexDupliData_Params params
const float(* orco)[3]
Span< float3 > vert_positions
Span< float3 > vert_normals
const DupliContext * ctx
const GreasePencil * get_grease_pencil() const
const Volume * get_volume() const
const GeometryComponent * get_component(GeometryComponent::Type component_type) const
const Instances * get_instances() const
const PointCloud * get_pointcloud() const
const Mesh * get_mesh() const
i
Definition text_draw.cc:230
PointerRNA * ptr
Definition wm_files.cc:4238