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