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