Blender V4.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
9#include <climits>
10#include <cstddef>
11#include <cstdlib>
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_listbase.h"
16#include "BLI_math_vector.h"
17#include "BLI_string_utf8.h"
18
19#include "BLI_array.hh"
20#include "BLI_math_geom.h"
21#include "BLI_math_matrix.h"
22#include "BLI_math_rotation.h"
23#include "BLI_math_vector.hh"
24#include "BLI_rand.h"
25#include "BLI_span.hh"
26#include "BLI_vector.hh"
27
29#include "DNA_curves_types.h"
31#include "DNA_mesh_types.h"
32#include "DNA_modifier_types.h"
34#include "DNA_scene_types.h"
35#include "DNA_volume_types.h"
36
37#include "BKE_collection.hh"
38#include "BKE_duplilist.hh"
39#include "BKE_editmesh.hh"
40#include "BKE_editmesh_cache.hh"
41#include "BKE_geometry_set.hh"
43#include "BKE_global.hh"
44#include "BKE_idprop.hh"
45#include "BKE_instances.hh"
46#include "BKE_main.hh"
47#include "BKE_mesh.hh"
48#include "BKE_object.hh"
49#include "BKE_object_types.hh"
50#include "BKE_particle.h"
51#include "BKE_vfont.hh"
52
53#include "DEG_depsgraph.hh"
55
56#include "BLI_hash.h"
57#include "DNA_world_types.h"
58
60#include "RNA_access.hh"
61#include "RNA_path.hh"
62#include "RNA_prototypes.hh"
63
64#include "MOD_nodes.hh"
65
66using blender::Array;
67using blender::float2;
68using blender::float3;
70using blender::Span;
71using blender::Vector;
76
77/* -------------------------------------------------------------------- */
81static constexpr short GEOMETRY_SET_DUPLI_GENERATOR_TYPE = 1;
82
131
134 short type;
135 void (*make_duplis)(const DupliContext *ctx);
136};
137
138static const DupliGenerator *get_dupli_generator(const DupliContext *ctx);
139
143static void init_context(DupliContext *r_ctx,
144 Depsgraph *depsgraph,
145 Scene *scene,
146 Object *ob,
147 const float space_mat[4][4],
148 Vector<Object *> &instance_stack,
149 Vector<short> &dupli_gen_type_stack)
150{
151 r_ctx->depsgraph = depsgraph;
152 r_ctx->scene = scene;
153 r_ctx->collection = nullptr;
154
155 r_ctx->root_object = ob;
156 r_ctx->object = ob;
157 r_ctx->obedit = OBEDIT_FROM_OBACT(ob);
158 r_ctx->instance_stack = &instance_stack;
159 r_ctx->dupli_gen_type_stack = &dupli_gen_type_stack;
160 if (space_mat) {
161 copy_m4_m4(r_ctx->space_mat, space_mat);
162 }
163 else {
164 unit_m4(r_ctx->space_mat);
165 }
166 r_ctx->level = 0;
167
168 r_ctx->gen = get_dupli_generator(r_ctx);
169 if (r_ctx->gen && r_ctx->gen->type != GEOMETRY_SET_DUPLI_GENERATOR_TYPE) {
170 r_ctx->dupli_gen_type_stack->append(r_ctx->gen->type);
171 }
172
173 r_ctx->duplilist = nullptr;
174 r_ctx->preview_instance_index = -1;
175 r_ctx->preview_base_geometry = nullptr;
176}
177
182 const DupliContext *ctx,
183 Object *ob,
184 const float mat[4][4],
185 int index,
186 const GeometrySet *geometry = nullptr,
187 int64_t instance_index = 0)
188{
189 *r_ctx = *ctx;
190
191 /* XXX annoying, previously was done by passing an ID* argument,
192 * this at least is more explicit. */
193 if (ctx->gen && ctx->gen->type == OB_DUPLICOLLECTION) {
195 }
196
197 r_ctx->object = ob;
198 r_ctx->instance_stack = ctx->instance_stack;
199 if (mat) {
200 mul_m4_m4m4(r_ctx->space_mat, (float(*)[4])ctx->space_mat, mat);
201 }
202 r_ctx->persistent_id[r_ctx->level] = index;
203 r_ctx->instance_idx[r_ctx->level] = instance_index;
204 r_ctx->instance_data[r_ctx->level] = geometry;
205 ++r_ctx->level;
206
207 if (r_ctx->level == MAX_DUPLI_RECUR - 1) {
208 std::cerr << "Warning: Maximum instance recursion level reached.\n";
209 return false;
210 }
211
212 r_ctx->gen = get_dupli_generator(r_ctx);
213 if (r_ctx->gen && r_ctx->gen->type != GEOMETRY_SET_DUPLI_GENERATOR_TYPE) {
214 r_ctx->dupli_gen_type_stack->append(r_ctx->gen->type);
215 }
216 return true;
217}
218
226 Object *ob,
227 const ID *object_data,
228 const float mat[4][4],
229 int index,
230 const GeometrySet *geometry = nullptr,
231 int64_t instance_index = 0)
232{
233 DupliObject *dob;
234 int i;
235
236 /* Add a #DupliObject instance to the result container. */
237 if (ctx->duplilist) {
238 dob = MEM_cnew<DupliObject>("dupli object");
239 BLI_addtail(ctx->duplilist, dob);
240 }
241 else {
242 return nullptr;
243 }
244
245 dob->ob = ob;
246 dob->ob_data = const_cast<ID *>(object_data);
247 mul_m4_m4m4(dob->mat, (float(*)[4])ctx->space_mat, mat);
248 dob->type = ctx->gen == nullptr ? 0 : ctx->dupli_gen_type_stack->last();
251
252 /* Set persistent id, which is an array with a persistent index for each level
253 * (particle number, vertex number, ..). by comparing this we can find the same
254 * dupli-object between frames, which is needed for motion blur.
255 * The last level is ordered first in the array. */
256 dob->persistent_id[0] = index;
257 for (i = 1; i < ctx->level + 1; i++) {
258 dob->persistent_id[i] = ctx->persistent_id[ctx->level - i];
259 }
260 /* Fill rest of values with #INT_MAX which index will never have as value. */
261 for (; i < MAX_DUPLI_RECUR; i++) {
262 dob->persistent_id[i] = INT_MAX;
263 }
264
265 /* Store geometry set data for attribute lookup in innermost to outermost
266 * order, copying only non-null entries to save space. */
267 const int max_instance = ARRAY_SIZE(dob->instance_data);
268 int next_instance = 0;
269 if (geometry != nullptr) {
270 dob->instance_idx[next_instance] = int(instance_index);
271 dob->instance_data[next_instance] = geometry;
272 next_instance++;
273 }
274 for (i = ctx->level - 1; i >= 0 && next_instance < max_instance; i--) {
275 if (ctx->instance_data[i] != nullptr) {
276 dob->instance_idx[next_instance] = int(ctx->instance_idx[i]);
277 dob->instance_data[next_instance] = ctx->instance_data[i];
278 next_instance++;
279 }
280 }
281
282 /* Meta-balls never draw in duplis, they are instead merged into one by the basis
283 * meta-ball outside of the group. this does mean that if that meta-ball is not in the
284 * scene, they will not show up at all, limitation that should be solved once. */
285 if (object_data && GS(object_data->name) == ID_MB) {
286 dob->no_draw = true;
287 }
288
289 /* Random number per instance.
290 * The root object in the scene, persistent ID up to the instance object, and the instance object
291 * name together result in a unique random number. */
292 dob->random_id = BLI_hash_string(dob->ob->id.name + 2);
293
294 if (dob->persistent_id[0] != INT_MAX) {
295 for (i = 0; i < MAX_DUPLI_RECUR; i++) {
297 }
298 }
299 else {
300 dob->random_id = BLI_hash_int_2d(dob->random_id, 0);
301 }
302
303 if (ctx->root_object != ob) {
305 }
306
307 return dob;
308}
309
311 Object *ob,
312 const float mat[4][4],
313 int index,
314 const GeometrySet *geometry = nullptr,
315 int64_t instance_index = 0)
316{
317 return make_dupli(ctx, ob, static_cast<ID *>(ob->data), mat, index, geometry, instance_index);
318}
319
325static void make_recursive_duplis(const DupliContext *ctx,
326 Object *ob,
327 const float space_mat[4][4],
328 int index,
329 const GeometrySet *geometry = nullptr,
330 int64_t instance_index = 0)
331{
332 if (ctx->instance_stack->contains(ob)) {
333 /* Avoid recursive instances. */
334 printf("Warning: '%s' object is trying to instance itself.\n", ob->id.name + 2);
335 return;
336 }
337 /* Simple preventing of too deep nested collections with #MAX_DUPLI_RECUR. */
338 if (ctx->level < MAX_DUPLI_RECUR) {
339 DupliContext rctx;
340 if (!copy_dupli_context(&rctx, ctx, ob, space_mat, index, geometry, instance_index)) {
341 return;
342 }
343 if (rctx.gen) {
344 ctx->instance_stack->append(ob);
345 rctx.gen->make_duplis(&rctx);
346 ctx->instance_stack->remove_last();
348 if (!ctx->dupli_gen_type_stack->is_empty()) {
349 ctx->dupli_gen_type_stack->remove_last();
350 }
351 }
352 }
353 }
354}
355
358/* -------------------------------------------------------------------- */
362using MakeChildDuplisFunc = void (*)(const DupliContext *ctx, void *userdata, Object *child);
363
364static bool is_child(const Object *ob, const Object *parent)
365{
366 const Object *ob_parent = ob->parent;
367 while (ob_parent) {
368 if (ob_parent == parent) {
369 return true;
370 }
371 ob_parent = ob_parent->parent;
372 }
373 return false;
374}
375
379static void make_child_duplis(const DupliContext *ctx,
380 void *userdata,
381 MakeChildDuplisFunc make_child_duplis_cb)
382{
383 Object *parent = ctx->object;
384
385 if (ctx->collection) {
388 if ((ob != ctx->obedit) && is_child(ob, parent)) {
389 DupliContext pctx;
390 if (copy_dupli_context(&pctx, ctx, ctx->object, nullptr, _base_id)) {
391 /* Meta-balls have a different dupli handling. */
392 if (ob->type != OB_MBALL) {
393 ob->flag |= OB_DONE; /* Doesn't render. */
394 }
395 make_child_duplis_cb(&pctx, userdata, ob);
397 if (!ctx->dupli_gen_type_stack->is_empty()) {
398 ctx->dupli_gen_type_stack->remove_last();
399 }
400 }
401 }
402 }
403 }
405 }
406 else {
407 /* FIXME: using a mere counter to generate a 'persistent' dupli id is very weak. One possible
408 * better solution could be to use `session_uid` of ID's instead? */
409 int persistent_dupli_id = 0;
410 DEGObjectIterSettings deg_iter_settings{};
411 deg_iter_settings.depsgraph = ctx->depsgraph;
412 /* NOTE: this set of flags ensure we only iterate over objects that have a base in either the
413 * current scene, or the set (background) scene. */
414 deg_iter_settings.flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
416 DEG_OBJECT_ITER_BEGIN (&deg_iter_settings, ob) {
417 if ((ob != ctx->obedit) && is_child(ob, parent)) {
418 DupliContext pctx;
419 if (copy_dupli_context(&pctx, ctx, ctx->object, nullptr, persistent_dupli_id)) {
420 /* Meta-balls have a different dupli-handling. */
421 if (ob->type != OB_MBALL) {
422 ob->flag |= OB_DONE; /* Doesn't render. */
423 }
424
425 make_child_duplis_cb(&pctx, userdata, ob);
427 if (!ctx->dupli_gen_type_stack->is_empty()) {
428 ctx->dupli_gen_type_stack->remove_last();
429 }
430 }
431 }
432 }
433 persistent_dupli_id++;
434 }
436 }
437}
438
441/* -------------------------------------------------------------------- */
446 BMEditMesh **r_em,
447 Span<float3> *r_vert_coords,
448 Span<float3> *r_vert_normals)
449{
450 /* Gather mesh info. */
452 const Mesh *mesh_eval;
453
454 *r_em = nullptr;
455 *r_vert_coords = {};
456 if (r_vert_normals != nullptr) {
457 *r_vert_normals = {};
458 }
459
460 /* We do not need any render-specific handling anymore, depsgraph takes care of that. */
461 /* NOTE: Do direct access to the evaluated mesh: this function is used
462 * during meta balls evaluation. But even without those all the objects
463 * which are needed for correct instancing are already evaluated. */
464 if (em != nullptr) {
465 /* Note that this will only show deformation if #eModifierMode_OnCage is enabled.
466 * We could change this but it matches 2.7x behavior. */
467 mesh_eval = BKE_object_get_editmesh_eval_cage(ob);
468 if ((mesh_eval == nullptr) || (mesh_eval->runtime->wrapper_type == ME_WRAPPER_TYPE_BMESH)) {
469 blender::bke::EditMeshData *emd = mesh_eval ? mesh_eval->runtime->edit_data.get() : nullptr;
470
471 /* Only assign edit-mesh in the case we can't use `mesh_eval`. */
472 *r_em = em;
473 mesh_eval = nullptr;
474
475 if ((emd != nullptr) && !emd->vert_positions.is_empty()) {
476 *r_vert_coords = emd->vert_positions;
477 if (r_vert_normals != nullptr) {
478 *r_vert_normals = BKE_editmesh_cache_ensure_vert_normals(*em, *emd);
479 }
480 }
481 }
482 }
483 else {
484 mesh_eval = BKE_object_get_evaluated_mesh(ob);
485 }
486 return mesh_eval;
487}
488
491/* -------------------------------------------------------------------- */
496{
497 Object *ob = ctx->object;
498 Collection *collection;
499 float collection_mat[4][4];
500
501 if (ob->instance_collection == nullptr) {
502 return;
503 }
504 collection = ob->instance_collection;
505
506 /* Combine collection offset and `obmat`. */
507 unit_m4(collection_mat);
508 sub_v3_v3(collection_mat[3], collection->instance_offset);
509 mul_m4_m4m4(collection_mat, ob->object_to_world().ptr(), collection_mat);
510 /* Don't access 'ob->object_to_world().ptr()' from now on. */
511
514 if (cob != ob) {
515 float mat[4][4];
516
517 /* Collection dupli-offset, should apply after everything else. */
518 mul_m4_m4m4(mat, collection_mat, cob->object_to_world().ptr());
519
520 make_dupli(ctx, cob, mat, _base_id);
521
522 /* Recursion. */
523 make_recursive_duplis(ctx, cob, collection_mat, _base_id);
524 }
525 }
527}
528
530 /*type*/ OB_DUPLICOLLECTION,
531 /*make_duplis*/ make_duplis_collection};
532
535/* -------------------------------------------------------------------- */
549
559
578
584static void get_duplivert_transform(const float3 &co,
585 const float3 &no,
586 const bool use_rotation,
587 const short axis,
588 const short upflag,
589 float r_mat[4][4])
590{
591 float quat[4];
592 const float size[3] = {1.0f, 1.0f, 1.0f};
593
594 if (use_rotation) {
595 /* Construct rotation matrix from normals. */
596 float no_flip[3];
597 negate_v3_v3(no_flip, no);
598 vec_to_quat(quat, no_flip, axis, upflag);
599 }
600 else {
601 unit_qt(quat);
602 }
603
604 loc_quat_size_to_mat4(r_mat, co, quat, size);
605}
606
608 Object *inst_ob,
609 const float child_imat[4][4],
610 int index,
611 const float3 &co,
612 const float3 &no,
613 const bool use_rotation)
614{
615 /* `obmat` is transform to vertex. */
616 float obmat[4][4];
617 get_duplivert_transform(co, no, use_rotation, inst_ob->trackflag, inst_ob->upflag, obmat);
618
619 float space_mat[4][4];
620
621 /* Make offset relative to inst_ob using relative child transform. */
622 mul_mat3_m4_v3(child_imat, obmat[3]);
623 /* Apply `obmat` _after_ the local vertex transform. */
624 mul_m4_m4m4(obmat, inst_ob->object_to_world().ptr(), obmat);
625
626 /* Space matrix is constructed by removing `obmat` transform,
627 * this yields the world-space transform for recursive duplis. */
628 mul_m4_m4m4(space_mat, obmat, inst_ob->world_to_object().ptr());
629
630 DupliObject *dob = make_dupli(ctx, inst_ob, obmat, index);
631
632 /* Recursion. */
633 make_recursive_duplis(ctx, inst_ob, space_mat, index);
634
635 return dob;
636}
637
639 void *userdata,
640 Object *inst_ob)
641{
643 const bool use_rotation = vdd->params.use_rotation;
644
645 const int totvert = vdd->totvert;
646
647 invert_m4_m4(inst_ob->runtime->world_to_object.ptr(), inst_ob->object_to_world().ptr());
648 /* Relative transform from parent to child space. */
649 float child_imat[4][4];
650 mul_m4_m4m4(child_imat, inst_ob->world_to_object().ptr(), ctx->object->object_to_world().ptr());
651
652 for (int i = 0; i < totvert; i++) {
654 inst_ob,
655 child_imat,
656 i,
657 vdd->vert_positions[i],
658 vdd->vert_normals[i],
659 use_rotation);
660 if (vdd->orco) {
661 copy_v3_v3(dob->orco, vdd->orco[i]);
662 }
663 }
664}
665
667 void *userdata,
668 Object *inst_ob)
669{
671 BMEditMesh *em = vdd->em;
672 const bool use_rotation = vdd->params.use_rotation;
673
674 invert_m4_m4(inst_ob->runtime->world_to_object.ptr(), inst_ob->object_to_world().ptr());
675 /* Relative transform from parent to child space. */
676 float child_imat[4][4];
677 mul_m4_m4m4(child_imat, inst_ob->world_to_object().ptr(), ctx->object->object_to_world().ptr());
678
679 BMVert *v;
680 BMIter iter;
681 int i;
682
683 const Span<float3> vert_positions_deform = vdd->vert_positions_deform;
684 const Span<float3> vert_normals_deform = vdd->vert_normals_deform;
685 BM_ITER_MESH_INDEX (v, &iter, em->bm, BM_VERTS_OF_MESH, i) {
686 float3 co, no;
687 if (!vert_positions_deform.is_empty()) {
688 co = vert_positions_deform[i];
689 no = !vert_normals_deform.is_empty() ? vert_normals_deform[i] : float3(0);
690 }
691 else {
692 co = v->co;
693 no = v->no;
694 }
695
696 DupliObject *dob = vertex_dupli(vdd->params.ctx, inst_ob, child_imat, i, co, no, use_rotation);
697 if (vdd->has_orco) {
698 copy_v3_v3(dob->orco, v->co);
699 }
700 }
701}
702
703static void make_duplis_verts(const DupliContext *ctx)
704{
705 Object *parent = ctx->object;
706 const bool use_rotation = parent->transflag & OB_DUPLIROT;
707
708 /* Gather mesh info. */
709 BMEditMesh *em = nullptr;
710 Span<float3> vert_positions_deform;
711 Span<float3> vert_normals_deform;
712 const Mesh *mesh_eval = mesh_data_from_duplicator_object(
713 parent, &em, &vert_positions_deform, use_rotation ? &vert_normals_deform : nullptr);
714 if (em == nullptr && mesh_eval == nullptr) {
715 return;
716 }
717
718 VertexDupliData_Params vdd_params{ctx, use_rotation};
719
720 if (em != nullptr) {
722 vdd.params = vdd_params;
723 vdd.em = em;
724 vdd.vert_positions_deform = vert_positions_deform;
725 vdd.vert_normals_deform = vert_normals_deform;
726 vdd.has_orco = !vert_positions_deform.is_empty();
727
729 }
730 else {
732 vdd.params = vdd_params;
733 vdd.totvert = mesh_eval->verts_num;
734 vdd.vert_positions = mesh_eval->vert_positions();
735 vdd.vert_normals = mesh_eval->vert_normals();
736 vdd.orco = (const float(*)[3])CustomData_get_layer(&mesh_eval->vert_data, CD_ORCO);
737
739 }
740}
741
743 /*type*/ OB_DUPLIVERTS,
744 /*make_duplis*/ make_duplis_verts};
745
748/* -------------------------------------------------------------------- */
753 Main *bmain, const char *family, size_t family_len, uint ch, GHash *family_gh)
754{
755 void *ch_key = POINTER_FROM_UINT(ch);
756
757 Object **ob_pt;
758 if ((ob_pt = (Object **)BLI_ghash_lookup_p(family_gh, ch_key))) {
759 return *ob_pt;
760 }
761
762 char ch_utf8[BLI_UTF8_MAX + 1];
763 size_t ch_utf8_len;
764
765 ch_utf8_len = BLI_str_utf8_from_unicode(ch, ch_utf8, sizeof(ch_utf8) - 1);
766 ch_utf8[ch_utf8_len] = '\0';
767 ch_utf8_len += 1; /* Compare with null terminator. */
768
769 LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
770 if (STREQLEN(ob->id.name + 2 + family_len, ch_utf8, ch_utf8_len)) {
771 if (STREQLEN(ob->id.name + 2, family, family_len)) {
772 /* Inserted value can be nullptr, just to save searches in future. */
773 BLI_ghash_insert(family_gh, ch_key, ob);
774 return ob;
775 }
776 }
777 }
778
779 return nullptr;
780}
781
782static void make_duplis_font(const DupliContext *ctx)
783{
784 Object *par = ctx->object;
785 GHash *family_gh;
786 Object *ob;
787 Curve *cu;
788 CharTrans *ct, *chartransdata = nullptr;
789 float vec[3], obmat[4][4], pmat[4][4], fsize, xof, yof;
790 int text_len, a;
791 size_t family_len;
792 const char32_t *text = nullptr;
793 bool text_free = false;
794
795 /* Font dupli-verts not supported inside collections. */
796 if (ctx->collection) {
797 return;
798 }
799
800 copy_m4_m4(pmat, par->object_to_world().ptr());
801
802 /* In `par` the family name is stored, use this to find the other objects. */
803
805 par, (Curve *)par->data, FO_DUPLI, nullptr, &text, &text_len, &text_free, &chartransdata);
806
807 if (text == nullptr || chartransdata == nullptr) {
808 return;
809 }
810
811 cu = (Curve *)par->data;
812 fsize = cu->fsize;
813 xof = cu->xof;
814 yof = cu->yof;
815
816 ct = chartransdata;
817
818 /* Cache result. */
819 family_len = strlen(cu->family);
820 family_gh = BLI_ghash_int_new_ex(__func__, 256);
821
822 /* Safety check even if it might fail badly when called for original object. */
823 const bool is_eval_curve = DEG_is_evaluated_id(&cu->id);
824
825 /* Advance matching BLI_str_utf8_as_utf32. */
826 for (a = 0; a < text_len; a++, ct++) {
827
828 /* XXX That G.main is *really* ugly, but not sure what to do here.
829 * Definitively don't think it would be safe to put back `Main *bmain` pointer
830 * in #DupliContext as done in 2.7x? */
831 ob = find_family_object(G.main, cu->family, family_len, uint(text[a]), family_gh);
832
833 if (is_eval_curve) {
834 /* Workaround for the above hack. */
835 ob = DEG_get_evaluated_object(ctx->depsgraph, ob);
836 }
837
838 if (ob) {
839 vec[0] = fsize * (ct->xof - xof);
840 vec[1] = fsize * (ct->yof - yof);
841 vec[2] = 0.0;
842
843 mul_m4_v3(pmat, vec);
844
845 copy_m4_m4(obmat, par->object_to_world().ptr());
846
847 if (UNLIKELY(ct->rot != 0.0f)) {
848 float rmat[4][4];
849
850 zero_v3(obmat[3]);
851 axis_angle_to_mat4_single(rmat, 'Z', -ct->rot);
852 mul_m4_m4m4(obmat, obmat, rmat);
853 }
854
855 copy_v3_v3(obmat[3], vec);
856
857 make_dupli(ctx, ob, obmat, a);
858 }
859 }
860
861 if (text_free) {
862 MEM_freeN((void *)text);
863 }
864
865 BLI_ghash_free(family_gh, nullptr, nullptr);
866
867 MEM_freeN(chartransdata);
868}
869
871 /*type*/ OB_DUPLIVERTS,
872 /*make_duplis*/ make_duplis_font};
873
876/* -------------------------------------------------------------------- */
881 const GeometrySet &geometry_set,
882 const float parent_transform[4][4],
883 bool geometry_set_is_instance,
884 bool use_new_curves_type)
885{
886 int component_index = 0;
887 if (ctx->object->type != OB_MESH || geometry_set_is_instance) {
888 if (const Mesh *mesh = geometry_set.get_mesh()) {
889 make_dupli(ctx, ctx->object, &mesh->id, parent_transform, component_index++);
890 }
891 }
892 if (ctx->object->type != OB_VOLUME || geometry_set_is_instance) {
893 if (const Volume *volume = geometry_set.get_volume()) {
894 make_dupli(ctx, ctx->object, &volume->id, parent_transform, component_index++);
895 }
896 }
897 if (!ELEM(ctx->object->type, OB_CURVES_LEGACY, OB_FONT, OB_CURVES) || geometry_set_is_instance) {
898 if (const blender::bke::CurveComponent *component =
900 {
901 if (use_new_curves_type) {
902 if (const Curves *curves = component->get()) {
903 make_dupli(ctx, ctx->object, &curves->id, parent_transform, component_index++);
904 }
905 }
906 else {
907 if (const Curve *curve = component->get_curve_for_render()) {
908 make_dupli(ctx, ctx->object, &curve->id, parent_transform, component_index++);
909 }
910 }
911 }
912 }
913 if (ctx->object->type != OB_POINTCLOUD || geometry_set_is_instance) {
914 if (const PointCloud *pointcloud = geometry_set.get_pointcloud()) {
915 make_dupli(ctx, ctx->object, &pointcloud->id, parent_transform, component_index++);
916 }
917 }
918 if (ctx->object->type != OB_GREASE_PENCIL || geometry_set_is_instance) {
919 if (const GreasePencil *grease_pencil = geometry_set.get_grease_pencil()) {
920 make_dupli(ctx, ctx->object, &grease_pencil->id, parent_transform, component_index++);
921 }
922 }
923 const bool creates_duplis_for_components = component_index >= 1;
924
925 const Instances *instances = geometry_set.get_instances();
926 if (instances == nullptr) {
927 return;
928 }
929
930 const DupliContext *instances_ctx = ctx;
931 /* Create a sub-context if some duplis were created above. This is to avoid dupli id collisions
932 * between the instances component below and the other components above. */
933 DupliContext new_instances_ctx;
934 if (creates_duplis_for_components) {
935 if (!copy_dupli_context(&new_instances_ctx, ctx, ctx->object, nullptr, component_index)) {
936 return;
937 }
938 instances_ctx = &new_instances_ctx;
939 }
940
941 Span<float4x4> instance_offset_matrices = instances->transforms();
942 Span<int> reference_handles = instances->reference_handles();
943 Span<int> almost_unique_ids = instances->almost_unique_ids();
944 Span<InstanceReference> references = instances->references();
945
946 for (int64_t i : instance_offset_matrices.index_range()) {
947 const InstanceReference &reference = references[reference_handles[i]];
948 const int id = almost_unique_ids[i];
949
950 const DupliContext *ctx_for_instance = instances_ctx;
951 /* Set the #preview_instance_index when necessary. */
952 DupliContext tmp_ctx_for_instance;
953 if (instances_ctx->preview_base_geometry == &geometry_set) {
954 tmp_ctx_for_instance = *instances_ctx;
955 tmp_ctx_for_instance.preview_instance_index = i;
956 ctx_for_instance = &tmp_ctx_for_instance;
957 }
958
959 switch (reference.type()) {
961 Object &object = reference.object();
962 float matrix[4][4];
963 mul_m4_m4m4(matrix, parent_transform, instance_offset_matrices[i].ptr());
964 make_dupli(ctx_for_instance, &object, matrix, id, &geometry_set, i);
965
966 float space_matrix[4][4];
968 space_matrix, instance_offset_matrices[i].ptr(), object.world_to_object().ptr());
969 mul_m4_m4_pre(space_matrix, parent_transform);
970 make_recursive_duplis(ctx_for_instance, &object, space_matrix, id, &geometry_set, i);
971 break;
972 }
974 Collection &collection = reference.collection();
975 float collection_matrix[4][4];
976 unit_m4(collection_matrix);
977 sub_v3_v3(collection_matrix[3], collection.instance_offset);
978 mul_m4_m4_pre(collection_matrix, instance_offset_matrices[i].ptr());
979 mul_m4_m4_pre(collection_matrix, parent_transform);
980
981 DupliContext sub_ctx;
982 if (!copy_dupli_context(&sub_ctx,
983 ctx_for_instance,
984 ctx_for_instance->object,
985 nullptr,
986 id,
987 &geometry_set,
988 i))
989 {
990 break;
991 }
992
993 eEvaluationMode mode = DEG_get_mode(ctx_for_instance->depsgraph);
994 int object_id = 0;
995 FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (&collection, object, mode) {
996 if (object == ctx_for_instance->object) {
997 continue;
998 }
999
1000 float instance_matrix[4][4];
1001 mul_m4_m4m4(instance_matrix, collection_matrix, object->object_to_world().ptr());
1002
1003 make_dupli(&sub_ctx, object, instance_matrix, object_id++);
1004 make_recursive_duplis(&sub_ctx, object, collection_matrix, object_id++);
1005 }
1007 break;
1008 }
1010 float new_transform[4][4];
1011 mul_m4_m4m4(new_transform, parent_transform, instance_offset_matrices[i].ptr());
1012
1013 DupliContext sub_ctx;
1014 if (copy_dupli_context(&sub_ctx,
1015 ctx_for_instance,
1016 ctx_for_instance->object,
1017 nullptr,
1018 id,
1019 &geometry_set,
1020 i))
1021 {
1023 &sub_ctx, reference.geometry_set(), new_transform, true, false);
1024 }
1025 break;
1026 }
1028 break;
1029 }
1030 }
1031 }
1032}
1033
1035{
1036 const GeometrySet *geometry_set = ctx->object->runtime->geometry_set_eval;
1038 ctx, *geometry_set, ctx->object->object_to_world().ptr(), false, false);
1039}
1040
1045
1048/* -------------------------------------------------------------------- */
1062
1073
1084
1086 const bool use_scale,
1087 const float scale_fac,
1088 float r_mat[4][4])
1089{
1090 using namespace blender::math;
1091
1092 /* Location. */
1093 float3 location(0);
1094 for (const float3 &coord : coords) {
1095 location += coord;
1096 }
1097 location *= 1.0f / float(coords.size());
1098
1099 /* Rotation. */
1100 float quat[4];
1101
1102 float3 f_no = normalize(cross_poly(coords));
1103 tri_to_quat_ex(quat, coords[0], coords[1], coords[2], f_no);
1104
1105 /* Scale. */
1106 float scale;
1107 if (use_scale) {
1108 const float area = area_poly_v3((const float(*)[3])coords.data(), uint(coords.size()));
1109 scale = sqrtf(area) * scale_fac;
1110 }
1111 else {
1112 scale = 1.0f;
1113 }
1114
1115 loc_quat_size_to_mat4(r_mat, location, quat, float3(scale));
1116}
1117
1119 Object *inst_ob,
1120 const float child_imat[4][4],
1121 const int index,
1122 const bool use_scale,
1123 const float scale_fac,
1124 Span<float3> coords)
1125{
1126 float obmat[4][4];
1127 float space_mat[4][4];
1128
1129 /* `obmat` is transform to face. */
1130 get_dupliface_transform_from_coords(coords, use_scale, scale_fac, obmat);
1131
1132 /* Make offset relative to inst_ob using relative child transform. */
1133 mul_mat3_m4_v3(child_imat, obmat[3]);
1134
1135 /* XXX ugly hack to ensure same behavior as in master.
1136 * This should not be needed, #Object.parentinv is not consistent outside of parenting. */
1137 {
1138 float imat[3][3];
1139 copy_m3_m4(imat, inst_ob->parentinv);
1140 mul_m4_m3m4(obmat, imat, obmat);
1141 }
1142
1143 /* Apply `obmat` _after_ the local face transform. */
1144 mul_m4_m4m4(obmat, inst_ob->object_to_world().ptr(), obmat);
1145
1146 /* Space matrix is constructed by removing `obmat` transform,
1147 * this yields the world-space transform for recursive duplis. */
1148 mul_m4_m4m4(space_mat, obmat, inst_ob->world_to_object().ptr());
1149
1150 DupliObject *dob = make_dupli(ctx, inst_ob, obmat, index);
1151
1152 /* Recursion. */
1153 make_recursive_duplis(ctx, inst_ob, space_mat, index);
1154
1155 return dob;
1156}
1157
1159 Object *inst_ob,
1160 const float child_imat[4][4],
1161 const int index,
1162 const bool use_scale,
1163 const float scale_fac,
1164
1165 /* Mesh variables. */
1166 const Span<int> face_verts,
1167 const Span<float3> vert_positions)
1168{
1169 Array<float3, 64> coords(face_verts.size());
1170
1171 for (int i = 0; i < face_verts.size(); i++) {
1172 coords[i] = vert_positions[face_verts[i]];
1173 }
1174
1175 return face_dupli(ctx, inst_ob, child_imat, index, use_scale, scale_fac, coords);
1176}
1177
1179 Object *inst_ob,
1180 const float child_imat[4][4],
1181 const int index,
1182 const bool use_scale,
1183 const float scale_fac,
1184
1185 /* Mesh variables. */
1186 BMFace *f,
1187 const Span<float3> vert_positions_deform)
1188{
1189 const int coords_len = f->len;
1190 Array<float3, 64> coords(coords_len);
1191
1192 BMLoop *l_first, *l_iter;
1193 int i = 0;
1194 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1195 if (!vert_positions_deform.is_empty()) {
1196 do {
1197 copy_v3_v3(coords[i++], vert_positions_deform[BM_elem_index_get(l_iter->v)]);
1198 } while ((l_iter = l_iter->next) != l_first);
1199 }
1200 else {
1201 do {
1202 copy_v3_v3(coords[i++], l_iter->v->co);
1203 } while ((l_iter = l_iter->next) != l_first);
1204 }
1205
1206 return face_dupli(ctx, inst_ob, child_imat, index, use_scale, scale_fac, coords);
1207}
1208
1210 void *userdata,
1211 Object *inst_ob)
1212{
1213 FaceDupliData_Mesh *fdd = (FaceDupliData_Mesh *)userdata;
1214 const float(*orco)[3] = fdd->orco;
1215 const float2 *mloopuv = fdd->mloopuv;
1216 const int totface = fdd->totface;
1217 const bool use_scale = fdd->params.use_scale;
1218
1219 float child_imat[4][4];
1220
1221 invert_m4_m4(inst_ob->runtime->world_to_object.ptr(), inst_ob->object_to_world().ptr());
1222 /* Relative transform from parent to child space. */
1223 mul_m4_m4m4(child_imat, inst_ob->world_to_object().ptr(), ctx->object->object_to_world().ptr());
1224 const float scale_fac = ctx->object->instance_faces_scale;
1225
1226 for (const int a : blender::IndexRange(totface)) {
1227 const blender::IndexRange face = fdd->faces[a];
1228 const Span<int> face_verts = fdd->corner_verts.slice(face);
1230 inst_ob,
1231 child_imat,
1232 a,
1233 use_scale,
1234 scale_fac,
1235 face_verts,
1236 fdd->vert_positions);
1237
1238 const float w = 1.0f / float(face.size());
1239 if (orco) {
1240 for (int j = 0; j < face.size(); j++) {
1241 madd_v3_v3fl(dob->orco, orco[face_verts[j]], w);
1242 }
1243 }
1244 if (mloopuv) {
1245 for (int j = 0; j < face.size(); j++) {
1246 madd_v2_v2fl(dob->uv, mloopuv[face[j]], w);
1247 }
1248 }
1249 }
1250}
1251
1253 void *userdata,
1254 Object *inst_ob)
1255{
1257 BMEditMesh *em = fdd->em;
1258 float child_imat[4][4];
1259 int a;
1260 BMFace *f;
1261 BMIter iter;
1262 const bool use_scale = fdd->params.use_scale;
1263
1264 const Span<float3> vert_positions_deform = fdd->vert_positions_deform;
1265
1266 BLI_assert(vert_positions_deform.is_empty() || (em->bm->elem_index_dirty & BM_VERT) == 0);
1267
1268 invert_m4_m4(inst_ob->runtime->world_to_object.ptr(), inst_ob->object_to_world().ptr());
1269 /* Relative transform from parent to child space. */
1270 mul_m4_m4m4(child_imat, inst_ob->world_to_object().ptr(), ctx->object->object_to_world().ptr());
1271 const float scale_fac = ctx->object->instance_faces_scale;
1272
1273 BM_ITER_MESH_INDEX (f, &iter, em->bm, BM_FACES_OF_MESH, a) {
1275 fdd->params.ctx, inst_ob, child_imat, a, use_scale, scale_fac, f, vert_positions_deform);
1276
1277 if (fdd->has_orco) {
1278 const float w = 1.0f / float(f->len);
1279 BMLoop *l_first, *l_iter;
1280 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1281 do {
1282 madd_v3_v3fl(dob->orco, l_iter->v->co, w);
1283 } while ((l_iter = l_iter->next) != l_first);
1284 }
1285 if (fdd->has_uvs) {
1287 }
1288 }
1289}
1290
1291static void make_duplis_faces(const DupliContext *ctx)
1292{
1293 Object *parent = ctx->object;
1294
1295 /* Gather mesh info. */
1296 BMEditMesh *em = nullptr;
1297 Span<float3> vert_positions_deform;
1298 const Mesh *mesh_eval = mesh_data_from_duplicator_object(
1299 parent, &em, &vert_positions_deform, nullptr);
1300 if (em == nullptr && mesh_eval == nullptr) {
1301 return;
1302 }
1303
1304 FaceDupliData_Params fdd_params = {ctx, (parent->transflag & OB_DUPLIFACES_SCALE) != 0};
1305
1306 if (em != nullptr) {
1307 const int uv_idx = CustomData_get_render_layer(&em->bm->ldata, CD_PROP_FLOAT2);
1309 fdd.params = fdd_params;
1310 fdd.em = em;
1311 fdd.vert_positions_deform = vert_positions_deform;
1312 fdd.has_orco = !vert_positions_deform.is_empty();
1313 fdd.has_uvs = (uv_idx != -1);
1314 fdd.cd_loop_uv_offset = (uv_idx != -1) ?
1316 -1;
1318 }
1319 else {
1320 const int uv_idx = CustomData_get_render_layer(&mesh_eval->corner_data, CD_PROP_FLOAT2);
1321 FaceDupliData_Mesh fdd{};
1322 fdd.params = fdd_params;
1323 fdd.totface = mesh_eval->faces_num;
1324 fdd.faces = mesh_eval->faces();
1325 fdd.corner_verts = mesh_eval->corner_verts();
1326 fdd.vert_positions = mesh_eval->vert_positions();
1327 fdd.mloopuv = (uv_idx != -1) ? (const float2 *)CustomData_get_layer_n(
1328 &mesh_eval->corner_data, CD_PROP_FLOAT2, uv_idx) :
1329 nullptr;
1330 fdd.orco = (const float(*)[3])CustomData_get_layer(&mesh_eval->vert_data, CD_ORCO);
1331
1333 }
1334}
1335
1337 /*type*/ OB_DUPLIFACES,
1338 /*make_duplis*/ make_duplis_faces,
1339};
1340
1343/* -------------------------------------------------------------------- */
1348{
1349 Scene *scene = ctx->scene;
1350 Object *par = ctx->object;
1352 bool for_render = mode == DAG_EVAL_RENDER;
1353
1354 Object *ob = nullptr, **oblist = nullptr;
1355 DupliObject *dob;
1356 ParticleSettings *part;
1357 ParticleData *pa;
1358 ChildParticle *cpa = nullptr;
1360 ParticleCacheKey *cache;
1361 float ctime, scale = 1.0f;
1362 float tmat[4][4], mat[4][4], pamat[4][4], size = 0.0;
1363 int a, b, hair = 0;
1364 int totpart, totchild;
1365
1366 int no_draw_flag = PARS_UNEXIST;
1367
1368 if (psys == nullptr) {
1369 return;
1370 }
1371
1372 part = psys->part;
1373
1374 if (part == nullptr) {
1375 return;
1376 }
1377
1378 if (!psys_check_enabled(par, psys, for_render)) {
1379 return;
1380 }
1381
1382 if (!for_render) {
1383 no_draw_flag |= PARS_NO_DISP;
1384 }
1385
1386 /* NOTE: in old animation system, used parent object's time-offset. */
1387 ctime = DEG_get_ctime(ctx->depsgraph);
1388
1389 totpart = psys->totpart;
1390 totchild = psys->totchild;
1391
1392 if ((for_render || part->draw_as == PART_DRAW_REND) &&
1393 ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR))
1394 {
1395 ParticleSimulationData sim = {nullptr};
1396 sim.depsgraph = ctx->depsgraph;
1397 sim.scene = scene;
1398 sim.ob = par;
1399 sim.psys = psys;
1400 sim.psmd = psys_get_modifier(par, psys);
1401 /* Make sure emitter `world_to_object` is in global coordinates instead of render view
1402 * coordinates. */
1403 invert_m4_m4(par->runtime->world_to_object.ptr(), par->object_to_world().ptr());
1404
1405 /* First check for loops (particle system object used as dupli-object). */
1406 if (part->ren_as == PART_DRAW_OB) {
1407 if (ELEM(part->instance_object, nullptr, par)) {
1408 return;
1409 }
1410 }
1411 else { /* #PART_DRAW_GR. */
1412 if (part->instance_collection == nullptr) {
1413 return;
1414 }
1415
1416 const ListBase dup_collection_objects = BKE_collection_object_cache_get(
1417 part->instance_collection);
1418 if (BLI_listbase_is_empty(&dup_collection_objects)) {
1419 return;
1420 }
1421
1422 if (BLI_findptr(&dup_collection_objects, par, offsetof(Base, object))) {
1423 return;
1424 }
1425 }
1426
1427 /* If we have a hair particle system, use the path cache. */
1428 if (part->type == PART_HAIR) {
1429 if (psys->flag & PSYS_HAIR_DONE) {
1430 hair = (totchild == 0 || psys->childcache) && psys->pathcache;
1431 }
1432 if (!hair) {
1433 return;
1434 }
1435
1436 /* We use cache, update `totchild` according to cached data. */
1437 totchild = psys->totchildcache;
1438 totpart = psys->totcached;
1439 }
1440
1441 RNG *rng = BLI_rng_new_srandom(31415926u + uint(psys->seed));
1442
1443 psys_sim_data_init(&sim);
1444
1445 /* Gather list of objects or single object. */
1446 int totcollection = 0;
1447
1448 const bool use_whole_collection = part->draw & PART_DRAW_WHOLE_GR;
1449 const bool use_collection_count = part->draw & PART_DRAW_COUNT_GR && !use_whole_collection;
1450 if (part->ren_as == PART_DRAW_GR) {
1451 if (use_collection_count) {
1453 LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) {
1455 part->instance_collection, object, mode)
1456 {
1457 if (dw->ob == object) {
1458 totcollection += dw->count;
1459 break;
1460 }
1461 }
1463 }
1464 }
1465 else {
1466 FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (part->instance_collection, object, mode)
1467 {
1468 (void)object;
1469 totcollection++;
1470 }
1472 }
1473
1474 oblist = (Object **)MEM_callocN(size_t(totcollection) * sizeof(Object *),
1475 "dupcollection object list");
1476
1477 if (use_collection_count) {
1478 a = 0;
1479 LISTBASE_FOREACH (ParticleDupliWeight *, dw, &part->instance_weights) {
1481 part->instance_collection, object, mode)
1482 {
1483 if (dw->ob == object) {
1484 for (b = 0; b < dw->count; b++, a++) {
1485 oblist[a] = dw->ob;
1486 }
1487 break;
1488 }
1489 }
1491 }
1492 }
1493 else {
1494 a = 0;
1495 FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (part->instance_collection, object, mode)
1496 {
1497 oblist[a] = object;
1498 a++;
1499 }
1501 }
1502 }
1503 else {
1504 ob = part->instance_object;
1505 }
1506
1507 if (totchild == 0 || part->draw & PART_DRAW_PARENT) {
1508 a = 0;
1509 }
1510 else {
1511 a = totpart;
1512 }
1513
1514 for (pa = psys->particles; a < totpart + totchild; a++, pa++) {
1515 if (a < totpart) {
1516 /* Handle parent particle. */
1517 if (pa->flag & no_draw_flag) {
1518 continue;
1519 }
1520
1521#if 0 /* UNUSED */
1522 pa_num = pa->num;
1523#endif
1524 size = pa->size;
1525 }
1526 else {
1527 /* Handle child particle. */
1528 cpa = &psys->child[a - totpart];
1529
1530#if 0 /* UNUSED */
1531 pa_num = a;
1532#endif
1533 size = psys_get_child_size(psys, cpa, ctime, nullptr);
1534 }
1535
1536 /* Some hair paths might be non-existent so they can't be used for duplication. */
1537 if (hair && psys->pathcache &&
1538 ((a < totpart && psys->pathcache[a]->segments < 0) ||
1539 (a >= totpart && psys->childcache[a - totpart]->segments < 0)))
1540 {
1541 continue;
1542 }
1543
1544 if (part->ren_as == PART_DRAW_GR) {
1545 /* Prevent divide by zero below #28336. */
1546 if (totcollection == 0) {
1547 continue;
1548 }
1549
1550 /* For collections, pick the object based on settings. */
1551 if (part->draw & PART_DRAW_RAND_GR && !use_whole_collection) {
1552 b = BLI_rng_get_int(rng) % totcollection;
1553 }
1554 else {
1555 b = a % totcollection;
1556 }
1557
1558 ob = oblist[b];
1559 }
1560
1561 if (hair) {
1562 /* Hair we handle separate and compute transform based on hair keys. */
1563 if (a < totpart) {
1564 cache = psys->pathcache[a];
1565 psys_get_dupli_path_transform(&sim, pa, nullptr, cache, pamat, &scale);
1566 }
1567 else {
1568 cache = psys->childcache[a - totpart];
1569 psys_get_dupli_path_transform(&sim, nullptr, cpa, cache, pamat, &scale);
1570 }
1571
1572 copy_v3_v3(pamat[3], cache->co);
1573 pamat[3][3] = 1.0f;
1574 }
1575 else {
1576 /* First key. */
1577 state.time = ctime;
1578 if (psys_get_particle_state(&sim, a, &state, false) == 0) {
1579 continue;
1580 }
1581
1582 float tquat[4];
1583 normalize_qt_qt(tquat, state.rot);
1584 quat_to_mat4(pamat, tquat);
1585 copy_v3_v3(pamat[3], state.co);
1586 pamat[3][3] = 1.0f;
1587 }
1588
1589 if (part->ren_as == PART_DRAW_GR && psys->part->draw & PART_DRAW_WHOLE_GR) {
1590 b = 0;
1591 FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (part->instance_collection, object, mode)
1592 {
1593 copy_m4_m4(tmat, oblist[b]->object_to_world().ptr());
1594
1595 /* Apply collection instance offset. */
1596 sub_v3_v3(tmat[3], part->instance_collection->instance_offset);
1597
1598 /* Apply particle scale. */
1599 mul_mat3_m4_fl(tmat, size * scale);
1600 mul_v3_fl(tmat[3], size * scale);
1601
1602 /* Individual particle transform. */
1603 mul_m4_m4m4(mat, pamat, tmat);
1604
1605 dob = make_dupli(ctx, object, mat, a);
1606 dob->particle_system = psys;
1607
1608 psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
1609
1610 b++;
1611 }
1613 }
1614 else {
1615 float obmat[4][4];
1616 copy_m4_m4(obmat, ob->object_to_world().ptr());
1617
1618 float vec[3];
1619 copy_v3_v3(vec, obmat[3]);
1620 zero_v3(obmat[3]);
1621
1622 /* Particle rotation uses x-axis as the aligned axis,
1623 * so pre-rotate the object accordingly. */
1624 if ((part->draw & PART_DRAW_ROTATE_OB) == 0) {
1625 float xvec[3], q[4], size_mat[4][4], original_size[3];
1626
1627 mat4_to_size(original_size, obmat);
1628 size_to_mat4(size_mat, original_size);
1629
1630 xvec[0] = -1.0f;
1631 xvec[1] = xvec[2] = 0;
1632 vec_to_quat(q, xvec, ob->trackflag, ob->upflag);
1633 quat_to_mat4(obmat, q);
1634 obmat[3][3] = 1.0f;
1635
1636 /* Add scaling if requested. */
1637 if ((part->draw & PART_DRAW_NO_SCALE_OB) == 0) {
1638 mul_m4_m4m4(obmat, obmat, size_mat);
1639 }
1640 }
1641 else if (part->draw & PART_DRAW_NO_SCALE_OB) {
1642 /* Remove scaling. */
1643 float size_mat[4][4], original_size[3];
1644
1645 mat4_to_size(original_size, obmat);
1646 size_to_mat4(size_mat, original_size);
1647 invert_m4(size_mat);
1648
1649 mul_m4_m4m4(obmat, obmat, size_mat);
1650 }
1651
1652 mul_m4_m4m4(tmat, pamat, obmat);
1653 mul_mat3_m4_fl(tmat, size * scale);
1654
1655 copy_m4_m4(mat, tmat);
1656
1657 if (part->draw & PART_DRAW_GLOBAL_OB) {
1658 add_v3_v3v3(mat[3], mat[3], vec);
1659 }
1660
1661 dob = make_dupli(ctx, ob, mat, a);
1662 dob->particle_system = psys;
1663 psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
1664 }
1665 }
1666
1667 BLI_rng_free(rng);
1668 psys_sim_data_free(&sim);
1669 }
1670
1671 /* Clean up. */
1672 if (oblist) {
1673 MEM_freeN(oblist);
1674 }
1675}
1676
1678{
1679 /* Particle system take up one level in id, the particles another. */
1680 int psysid;
1682 /* Particles create one more level for persistent `psys` index. */
1683 DupliContext pctx;
1684 if (copy_dupli_context(&pctx, ctx, ctx->object, nullptr, psysid)) {
1685 make_duplis_particle_system(&pctx, psys);
1686 }
1687 }
1688}
1689
1691 /*type*/ OB_DUPLIPARTS,
1692 /*make_duplis*/ make_duplis_particles,
1693};
1694
1697/* -------------------------------------------------------------------- */
1702{
1703 int transflag = ctx->object->transflag;
1704 int visibility_flag = ctx->object->visibility_flag;
1705
1706 if ((transflag & OB_DUPLI) == 0 && ctx->object->runtime->geometry_set_eval == nullptr) {
1707 return nullptr;
1708 }
1709
1710 /* Meta-ball objects can't create instances, but the dupli system is used to "instance" their
1711 * evaluated mesh to render engines. We need to exit early to avoid recursively instancing the
1712 * evaluated meta-ball mesh on meta-ball instances that already contribute to the basis. */
1713 if (ctx->object->type == OB_MBALL && ctx->level > 0) {
1714 return nullptr;
1715 }
1716
1717 /* Should the dupli's be generated for this object? - Respect restrict flags. */
1718 if (DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER ? (visibility_flag & OB_HIDE_RENDER) :
1719 (visibility_flag & OB_HIDE_VIEWPORT))
1720 {
1721 return nullptr;
1722 }
1723
1724 /* Give "Object as Font" instances higher priority than geometry set instances, to retain
1725 * the behavior from before curve object meshes were processed as instances internally. */
1726 if (transflag & OB_DUPLIVERTS) {
1727 if (ctx->object->type == OB_FONT) {
1728 return &gen_dupli_verts_font;
1729 }
1730 }
1731
1732 if (ctx->object->runtime->geometry_set_eval != nullptr) {
1734 return &gen_dupli_geometry_set;
1735 }
1736 }
1737
1738 if (transflag & OB_DUPLIPARTS) {
1739 return &gen_dupli_particles;
1740 }
1741 if (transflag & OB_DUPLIVERTS) {
1742 if (ctx->object->type == OB_MESH) {
1743 return &gen_dupli_verts;
1744 }
1745 }
1746 else if (transflag & OB_DUPLIFACES) {
1747 if (ctx->object->type == OB_MESH) {
1748 return &gen_dupli_faces;
1749 }
1750 }
1751 else if (transflag & OB_DUPLICOLLECTION) {
1752 return &gen_dupli_collection;
1753 }
1754
1755 return nullptr;
1756}
1757
1760/* -------------------------------------------------------------------- */
1765{
1766 ListBase *duplilist = MEM_cnew<ListBase>("duplilist");
1767 DupliContext ctx;
1768 Vector<Object *> instance_stack;
1769 Vector<short> dupli_gen_type_stack({0});
1770 instance_stack.append(ob);
1771 init_context(&ctx, depsgraph, sce, ob, nullptr, instance_stack, dupli_gen_type_stack);
1772 if (ctx.gen) {
1773 ctx.duplilist = duplilist;
1774 ctx.gen->make_duplis(&ctx);
1775 }
1776
1777 return duplilist;
1778}
1779
1781 Scene *sce,
1782 Object *ob_eval,
1783 const ViewerPath *viewer_path)
1784{
1785 ListBase *duplilist = MEM_cnew<ListBase>("duplilist");
1786 DupliContext ctx;
1787 Vector<Object *> instance_stack;
1788 Vector<short> dupli_gen_type_stack({0});
1789 instance_stack.append(ob_eval);
1790 init_context(&ctx, depsgraph, sce, ob_eval, nullptr, instance_stack, dupli_gen_type_stack);
1791 ctx.duplilist = duplilist;
1792
1793 Object *ob_orig = DEG_get_original_object(ob_eval);
1794
1795 LISTBASE_FOREACH (ModifierData *, md_orig, &ob_orig->modifiers) {
1796 if (md_orig->type != eModifierType_Nodes) {
1797 continue;
1798 }
1799 NodesModifierData *nmd_orig = reinterpret_cast<NodesModifierData *>(md_orig);
1800 if (!nmd_orig->runtime->eval_log) {
1801 continue;
1802 }
1803 if (const geo_log::ViewerNodeLog *viewer_log =
1804 geo_log::GeoModifierLog::find_viewer_node_log_for_path(*viewer_path))
1805 {
1806 ctx.preview_base_geometry = &viewer_log->geometry;
1808 viewer_log->geometry,
1809 ob_eval->object_to_world().ptr(),
1810 true,
1811 ob_eval->type == OB_CURVES);
1812 }
1813 }
1814 return duplilist;
1815}
1816
1818{
1819 BLI_freelistN(lb);
1820 MEM_freeN(lb);
1821}
1822
1825/* -------------------------------------------------------------------- */
1831 const char *name,
1832 float r_value[4])
1833{
1834 using namespace blender;
1835 using namespace blender::bke;
1836
1837 /* Loop over layers from innermost to outermost. */
1838 for (const int i : IndexRange(ARRAY_SIZE(dupli->instance_data))) {
1839 /* Skip non-geonode layers. */
1840 if (dupli->instance_data[i] == nullptr) {
1841 continue;
1842 }
1843
1844 const InstancesComponent *component =
1846
1847 if (component == nullptr) {
1848 continue;
1849 }
1850
1851 /* Attempt to look up the attribute. */
1852 std::optional<bke::AttributeAccessor> attributes = component->attributes();
1853 const VArray data = *attributes->lookup<ColorGeometry4f>(name);
1854
1855 /* If the attribute was found and converted to float RGBA successfully, output it. */
1856 if (data) {
1857 copy_v4_v4(r_value, data[dupli->instance_idx[i]]);
1858 return true;
1859 }
1860 }
1861
1862 return false;
1863}
1864
1866static bool find_rna_property_rgba(PointerRNA *id_ptr, const char *name, float r_data[4])
1867{
1868 if (id_ptr->data == nullptr) {
1869 return false;
1870 }
1871
1872 /* First, check custom properties. */
1873 IDProperty *group = RNA_struct_idprops(id_ptr, false);
1874 PropertyRNA *prop = nullptr;
1875
1876 if (group && group->type == IDP_GROUP) {
1877 prop = (PropertyRNA *)IDP_GetPropertyFromGroup(group, name);
1878 }
1879
1880 /* If not found, do full path lookup. */
1882
1883 if (prop != nullptr) {
1884 ptr = *id_ptr;
1885 }
1886 else if (!RNA_path_resolve(id_ptr, name, &ptr, &prop)) {
1887 return false;
1888 }
1889
1890 if (prop == nullptr) {
1891 return false;
1892 }
1893
1894 /* Convert the value to RGBA if possible. */
1895 PropertyType type = RNA_property_type(prop);
1896 int array_len = RNA_property_array_length(&ptr, prop);
1897
1898 if (array_len == 0) {
1899 float value;
1900
1901 if (type == PROP_FLOAT) {
1902 value = RNA_property_float_get(&ptr, prop);
1903 }
1904 else if (type == PROP_INT) {
1905 value = float(RNA_property_int_get(&ptr, prop));
1906 }
1907 else if (type == PROP_BOOLEAN) {
1908 value = RNA_property_boolean_get(&ptr, prop) ? 1.0f : 0.0f;
1909 }
1910 else {
1911 return false;
1912 }
1913
1914 copy_v4_fl4(r_data, value, value, value, 1);
1915 return true;
1916 }
1917
1918 if (type == PROP_FLOAT && array_len <= 4) {
1919 copy_v4_fl4(r_data, 0, 0, 0, 1);
1920 RNA_property_float_get_array(&ptr, prop, r_data);
1921 return true;
1922 }
1923
1924 if (type == PROP_INT && array_len <= 4) {
1925 int tmp[4] = {0, 0, 0, 1};
1926 RNA_property_int_get_array(&ptr, prop, tmp);
1927 for (int i = 0; i < 4; i++) {
1928 r_data[i] = float(tmp[i]);
1929 }
1930 return true;
1931 }
1932
1933 return false;
1934}
1935
1936static bool find_rna_property_rgba(const ID *id, const char *name, float r_data[4])
1937{
1938 PointerRNA ptr = RNA_id_pointer_create(const_cast<ID *>(id));
1939 return find_rna_property_rgba(&ptr, name, r_data);
1940}
1941
1943 const DupliObject *dupli,
1944 const Object *dupli_parent,
1945 const char *name,
1946 float r_value[4])
1947{
1948 /* Check the dupli particle system. */
1949 if (dupli && dupli->particle_system) {
1950 const ParticleSettings *settings = dupli->particle_system->part;
1951
1952 if (find_rna_property_rgba(&settings->id, name, r_value)) {
1953 return true;
1954 }
1955 }
1956
1957 /* Check geometry node dupli instance attributes. */
1958 if (dupli && find_geonode_attribute_rgba(dupli, name, r_value)) {
1959 return true;
1960 }
1961
1962 /* Check the dupli parent object. */
1963 if (dupli_parent && find_rna_property_rgba(&dupli_parent->id, name, r_value)) {
1964 return true;
1965 }
1966
1967 /* Check the main object. */
1968 if (ob) {
1969 if (find_rna_property_rgba(&ob->id, name, r_value)) {
1970 return true;
1971 }
1972
1973 /* Check the main object data (e.g. mesh). */
1974 if (ob->data && find_rna_property_rgba((const ID *)ob->data, name, r_value)) {
1975 return true;
1976 }
1977 }
1978
1979 copy_v4_fl(r_value, 0.0f);
1980 return false;
1981}
1982
1984 const ViewLayer *layer,
1985 const char *name,
1986 float r_value[4])
1987{
1988 if (layer) {
1989 PointerRNA layer_ptr = RNA_pointer_create(
1990 &const_cast<ID &>(scene->id), &RNA_ViewLayer, const_cast<ViewLayer *>(layer));
1991
1992 if (find_rna_property_rgba(&layer_ptr, name, r_value)) {
1993 return true;
1994 }
1995 }
1996
1997 if (find_rna_property_rgba(&scene->id, name, r_value)) {
1998 return true;
1999 }
2000
2001 if (scene->world && find_rna_property_rgba(&scene->world->id, name, r_value)) {
2002 return true;
2003 }
2004
2005 copy_v4_fl(r_value, 0.0f);
2006 return false;
2007}
2008
#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)
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:63
blender::Span< blender::float3 > BKE_editmesh_cache_ensure_vert_normals(BMEditMesh &em, blender::bke::EditMeshData &emd)
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:763
@ 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:5159
struct ParticleSystemModifierData * psys_get_modifier(struct Object *ob, struct ParticleSystem *psys)
Definition particle.cc:2150
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:5056
bool psys_check_enabled(struct Object *ob, struct ParticleSystem *psys, bool use_render_params)
Definition particle.cc:706
void psys_sim_data_free(struct ParticleSimulationData *sim)
Definition particle.cc:629
void psys_find_group_weights(struct ParticleSettings *part)
Definition particle.cc:741
float psys_get_child_size(struct ParticleSystem *psys, struct ChildParticle *cpa, float cfra, float *pa_time)
Definition particle.cc:4510
void psys_sim_data_init(struct ParticleSimulationData *sim)
Definition particle.cc:588
bool psys_get_particle_state(struct ParticleSimulationData *sim, int p, struct ParticleKey *state, bool always)
Definition particle.cc:4886
@ FO_DUPLI
Definition BKE_vfont.hh:73
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)
Definition vfont.cc:1983
#define BLI_assert(a)
Definition BLI_assert.h:50
void ** BLI_ghash_lookup_p(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.c: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.c:707
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.c:860
BLI_INLINE unsigned int BLI_hash_int(unsigned int k)
Definition BLI_hash.h:91
BLI_INLINE unsigned int BLI_hash_string(const char *str)
Definition BLI_hash.h:71
BLI_INLINE unsigned int BLI_hash_int_2d(unsigned int kx, unsigned int ky)
Definition BLI_hash.h:55
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
#define LISTBASE_FOREACH(type, var, list)
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:496
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:110
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:131
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 unit_m4(float m[4][4])
Definition rct.c:1127
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 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:78
void BLI_rng_free(struct RNG *rng) ATTR_NONNULL(1)
Definition rand.cc:58
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_)
bool DEG_is_evaluated_id(const ID *id)
#define DEG_OBJECT_ITER_END
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
Object * DEG_get_original_object(Object *object)
Object * DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
@ 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
#define MAX_DUPLI_RECUR
@ 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
@ PART_DRAW_GR
@ PART_DRAW_OB
@ PART_DRAW_REND
@ PART_HAIR
@ PARS_NO_DISP
@ PARS_UNEXIST
@ 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
@ PSYS_HAIR_DONE
#define OBEDIT_FROM_OBACT(ob)
Read Guarded memory(de)allocation.
PropertyType
Definition RNA_types.hh:64
@ PROP_FLOAT
Definition RNA_types.hh:67
@ PROP_BOOLEAN
Definition RNA_types.hh:65
@ PROP_INT
Definition RNA_types.hh:66
#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
#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])
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
SIMD_FORCE_INLINE btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition btVector3.h:303
bool is_empty() const
Definition BLI_array.hh:253
constexpr const T * data() const
Definition BLI_span.hh:216
constexpr int64_t size() const
Definition BLI_span.hh:253
constexpr IndexRange index_range() const
Definition BLI_span.hh:402
constexpr bool is_empty() const
Definition BLI_span.hh:261
void append(const T &value)
std::optional< AttributeAccessor > attributes() const final
local_group_size(16, 16) .push_constant(Type b
#define printf
const Depsgraph * depsgraph
#define offsetof(t, d)
#define sqrtf(x)
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
#define GS(x)
Definition iris.cc:202
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
static ulong state[N]
#define G(x, y, z)
bool object_has_geometry_set_instances(const Object &object)
static void make_duplis_verts(const DupliContext *ctx)
static constexpr short GEOMETRY_SET_DUPLI_GENERATOR_TYPE
static Object * find_family_object(Main *bmain, const char *family, size_t family_len, uint ch, GHash *family_gh)
static void make_child_duplis(const DupliContext *ctx, void *userdata, MakeChildDuplisFunc make_child_duplis_cb)
static bool copy_dupli_context(DupliContext *r_ctx, const DupliContext *ctx, Object *ob, const float mat[4][4], int index, const GeometrySet *geometry=nullptr, int64_t instance_index=0)
static void make_duplis_collection(const DupliContext *ctx)
static void make_child_duplis_verts_from_mesh(const DupliContext *ctx, void *userdata, Object *inst_ob)
static DupliObject * face_dupli(const DupliContext *ctx, Object *inst_ob, const float child_imat[4][4], const int index, const bool use_scale, const float scale_fac, Span< float3 > coords)
static void make_duplis_font(const DupliContext *ctx)
bool BKE_object_dupli_find_rgba_attribute(const Object *ob, const DupliObject *dupli, const Object *dupli_parent, const char *name, float r_value[4])
static void make_child_duplis_faces_from_editmesh(const DupliContext *ctx, void *userdata, Object *inst_ob)
static const DupliGenerator gen_dupli_verts
static void make_duplis_particles(const DupliContext *ctx)
static const DupliGenerator gen_dupli_collection
static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem *psys)
static DupliObject * face_dupli_from_mesh(const DupliContext *ctx, Object *inst_ob, const float child_imat[4][4], const int index, const bool use_scale, const float scale_fac, const Span< int > face_verts, const Span< float3 > vert_positions)
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
ListBase * object_duplilist(Depsgraph *depsgraph, Scene *sce, Object *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])
void free_object_duplilist(ListBase *lb)
static void init_context(DupliContext *r_ctx, Depsgraph *depsgraph, Scene *scene, Object *ob, const float space_mat[4][4], Vector< Object * > &instance_stack, Vector< short > &dupli_gen_type_stack)
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)
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(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:525
static void text_free(SpaceLink *sl)
Definition space_text.cc:90
__int64 int64_t
Definition stdint.h:89
struct BMVert * v
struct BMLoop * next
float co[3]
float no[3]
char elem_index_dirty
CustomData ldata
float yof
Definition BKE_vfont.hh:19
float xof
Definition BKE_vfont.hh:19
float rot
Definition BKE_vfont.hh:20
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
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[8]
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
Definition DNA_ID.h:413
char name[66]
Definition DNA_ID.h:425
ListBase objects
Definition BKE_main.hh:212
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 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:42
Definition rand.cc:33
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
PointerRNA * ptr
Definition wm_files.cc:4126