Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/object_dupli.c
| Show First 20 Lines • Show All 810 Lines • ▼ Show 20 Lines | |||||
| /** \name Instances Geometry Component Implementation | /** \name Instances Geometry Component Implementation | ||||
| * \{ */ | * \{ */ | ||||
| static void make_duplis_instances_component(const DupliContext *ctx) | static void make_duplis_instances_component(const DupliContext *ctx) | ||||
| { | { | ||||
| float(*positions)[3]; | float(*positions)[3]; | ||||
| float(*rotations)[3]; | float(*rotations)[3]; | ||||
| float(*scales)[3]; | float(*scales)[3]; | ||||
| int *ids; | |||||
| InstancedData *instanced_data; | InstancedData *instanced_data; | ||||
| const int amount = BKE_geometry_set_instances( | const int amount = BKE_geometry_set_instances(ctx->object->runtime.geometry_set_eval, | ||||
| ctx->object->runtime.geometry_set_eval, &positions, &rotations, &scales, &instanced_data); | &positions, | ||||
| &rotations, | |||||
| &scales, | |||||
| &ids, | |||||
| &instanced_data); | |||||
| for (int i = 0; i < amount; i++) { | for (int i = 0; i < amount; i++) { | ||||
| InstancedData *data = &instanced_data[i]; | InstancedData *data = &instanced_data[i]; | ||||
| float scale_matrix[4][4]; | float scale_matrix[4][4]; | ||||
| size_to_mat4(scale_matrix, scales[i]); | size_to_mat4(scale_matrix, scales[i]); | ||||
| float rotation_matrix[4][4]; | float rotation_matrix[4][4]; | ||||
| eul_to_mat4(rotation_matrix, rotations[i]); | eul_to_mat4(rotation_matrix, rotations[i]); | ||||
| float instance_offset_matrix[4][4]; | float instance_offset_matrix[4][4]; | ||||
| mul_m4_m4m4(instance_offset_matrix, rotation_matrix, scale_matrix); | mul_m4_m4m4(instance_offset_matrix, rotation_matrix, scale_matrix); | ||||
| copy_v3_v3(instance_offset_matrix[3], positions[i]); | copy_v3_v3(instance_offset_matrix[3], positions[i]); | ||||
| const int id = ids[i] != -1 ? ids[i] : i; | |||||
| if (data->type == INSTANCE_DATA_TYPE_OBJECT) { | if (data->type == INSTANCE_DATA_TYPE_OBJECT) { | ||||
| Object *object = data->data.object; | Object *object = data->data.object; | ||||
| if (object != NULL) { | if (object != NULL) { | ||||
| float matrix[4][4]; | float matrix[4][4]; | ||||
| mul_m4_m4m4(matrix, ctx->object->obmat, instance_offset_matrix); | mul_m4_m4m4(matrix, ctx->object->obmat, instance_offset_matrix); | ||||
| make_dupli(ctx, object, matrix, i); | make_dupli(ctx, object, matrix, id); | ||||
| float space_matrix[4][4]; | float space_matrix[4][4]; | ||||
| mul_m4_m4m4(space_matrix, instance_offset_matrix, object->imat); | mul_m4_m4m4(space_matrix, instance_offset_matrix, object->imat); | ||||
| mul_m4_m4_pre(space_matrix, ctx->object->obmat); | mul_m4_m4_pre(space_matrix, ctx->object->obmat); | ||||
| make_recursive_duplis(ctx, object, space_matrix, i); | make_recursive_duplis(ctx, object, space_matrix, id); | ||||
| } | } | ||||
| } | } | ||||
| else if (data->type == INSTANCE_DATA_TYPE_COLLECTION) { | else if (data->type == INSTANCE_DATA_TYPE_COLLECTION) { | ||||
| Collection *collection = data->data.collection; | Collection *collection = data->data.collection; | ||||
| if (collection != NULL) { | if (collection != NULL) { | ||||
| float collection_matrix[4][4]; | float collection_matrix[4][4]; | ||||
| unit_m4(collection_matrix); | unit_m4(collection_matrix); | ||||
| sub_v3_v3(collection_matrix[3], collection->instance_offset); | sub_v3_v3(collection_matrix[3], collection->instance_offset); | ||||
| mul_m4_m4_pre(collection_matrix, instance_offset_matrix); | mul_m4_m4_pre(collection_matrix, instance_offset_matrix); | ||||
| mul_m4_m4_pre(collection_matrix, ctx->object->obmat); | mul_m4_m4_pre(collection_matrix, ctx->object->obmat); | ||||
| eEvaluationMode mode = DEG_get_mode(ctx->depsgraph); | eEvaluationMode mode = DEG_get_mode(ctx->depsgraph); | ||||
| FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (collection, object, mode) { | FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (collection, object, mode) { | ||||
| if (object == ctx->object) { | if (object == ctx->object) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| float instance_matrix[4][4]; | float instance_matrix[4][4]; | ||||
| mul_m4_m4m4(instance_matrix, collection_matrix, object->obmat); | mul_m4_m4m4(instance_matrix, collection_matrix, object->obmat); | ||||
| make_dupli(ctx, object, instance_matrix, i); | make_dupli(ctx, object, instance_matrix, id); | ||||
| make_recursive_duplis(ctx, object, collection_matrix, i); | make_recursive_duplis(ctx, object, collection_matrix, id); | ||||
| } | } | ||||
| FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END; | FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static const DupliGenerator gen_dupli_instances_component = { | static const DupliGenerator gen_dupli_instances_component = { | ||||
| ▲ Show 20 Lines • Show All 744 Lines • Show Last 20 Lines | |||||