Commit: 22e102efae70cd50f5f49d93c8df22185cb4dc76 Author: Julian Eisel Date: Thu Apr 7 15:03:42 2022 +0200 Branches: temp-collection-assets https://developer.blender.org/rB22e102efae70cd50f5f49d93c8df22185cb4dc76
Merge branch 'master' into temp-collection-assets =================================================================== =================================================================== diff --cc source/blender/editors/object/object_add.cc index 00000000000,b3c5879b4d0..8cad98ab4ae mode 000000,100644..100644 --- a/source/blender/editors/object/object_add.cc +++ b/source/blender/editors/object/object_add.cc @@@ -1,0 -1,4089 +1,4089 @@@ + /* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright 2001-2002 NaN Holding BV. All rights reserved. */ + + /** \file + * \ingroup edobj + */ + + #include <cctype> + #include <cstdlib> + #include <cstring> + #include <optional> + + #include "MEM_guardedalloc.h" + + #include "DNA_anim_types.h" + #include "DNA_camera_types.h" + #include "DNA_collection_types.h" + #include "DNA_curve_types.h" + #include "DNA_gpencil_modifier_types.h" + #include "DNA_gpencil_types.h" + #include "DNA_key_types.h" + #include "DNA_light_types.h" + #include "DNA_lightprobe_types.h" + #include "DNA_material_types.h" + #include "DNA_mesh_types.h" + #include "DNA_meta_types.h" + #include "DNA_object_fluidsim_types.h" + #include "DNA_object_force_types.h" + #include "DNA_object_types.h" + #include "DNA_pointcloud_types.h" + #include "DNA_scene_types.h" + #include "DNA_vfont_types.h" + + #include "BLI_ghash.h" + #include "BLI_listbase.h" + #include "BLI_math.h" + #include "BLI_string.h" + #include "BLI_utildefines.h" + + #include "BLT_translation.h" + + #include "BKE_action.h" + #include "BKE_anim_data.h" + #include "BKE_armature.h" + #include "BKE_camera.h" + #include "BKE_collection.h" + #include "BKE_constraint.h" + #include "BKE_context.h" + #include "BKE_curve.h" + #include "BKE_curves.h" + #include "BKE_displist.h" + #include "BKE_duplilist.h" + #include "BKE_effect.h" + #include "BKE_geometry_set.h" + #include "BKE_gpencil_curve.h" + #include "BKE_gpencil_geom.h" + #include "BKE_gpencil_modifier.h" + #include "BKE_key.h" + #include "BKE_lattice.h" + #include "BKE_layer.h" + #include "BKE_lib_id.h" + #include "BKE_lib_override.h" + #include "BKE_lib_query.h" + #include "BKE_lib_remap.h" + #include "BKE_light.h" + #include "BKE_lightprobe.h" + #include "BKE_main.h" + #include "BKE_material.h" + #include "BKE_mball.h" + #include "BKE_mesh.h" + #include "BKE_mesh_runtime.h" + #include "BKE_nla.h" + #include "BKE_object.h" + #include "BKE_particle.h" + #include "BKE_pointcloud.h" + #include "BKE_report.h" + #include "BKE_scene.h" + #include "BKE_speaker.h" + #include "BKE_vfont.h" + #include "BKE_volume.h" + + #include "DEG_depsgraph.h" + #include "DEG_depsgraph_build.h" + #include "DEG_depsgraph_query.h" + + #include "RNA_access.h" + #include "RNA_define.h" + #include "RNA_enum_types.h" + + #include "UI_interface.h" + + #include "WM_api.h" + #include "WM_types.h" + + #include "ED_armature.h" + #include "ED_curve.h" + #include "ED_curves.h" + #include "ED_gpencil.h" + #include "ED_mball.h" + #include "ED_mesh.h" + #include "ED_node.h" + #include "ED_object.h" + #include "ED_outliner.h" + #include "ED_physics.h" + #include "ED_render.h" + #include "ED_screen.h" + #include "ED_select_utils.h" + #include "ED_transform.h" + #include "ED_view3d.h" + + #include "UI_resources.h" + + #include "object_intern.h" + + /* -------------------------------------------------------------------- */ + /** \name Local Enum Declarations + * \{ */ + + /* This is an exact copy of the define in `rna_light.c` + * kept here because of linking order. + * Icons are only defined here */ + const EnumPropertyItem rna_enum_light_type_items[] = { + {LA_LOCAL, "POINT", ICON_LIGHT_POINT, "Point", "Omnidirectional point light source"}, + {LA_SUN, "SUN", ICON_LIGHT_SUN, "Sun", "Constant direction parallel ray light source"}, + {LA_SPOT, "SPOT", ICON_LIGHT_SPOT, "Spot", "Directional cone light source"}, + {LA_AREA, "AREA", ICON_LIGHT_AREA, "Area", "Directional area light source"}, + {0, nullptr, 0, nullptr, nullptr}, + }; + + /* copy from rna_object_force.c */ + static const EnumPropertyItem field_type_items[] = { + {PFIELD_FORCE, "FORCE", ICON_FORCE_FORCE, "Force", ""}, + {PFIELD_WIND, "WIND", ICON_FORCE_WIND, "Wind", ""}, + {PFIELD_VORTEX, "VORTEX", ICON_FORCE_VORTEX, "Vortex", ""}, + {PFIELD_MAGNET, "MAGNET", ICON_FORCE_MAGNETIC, "Magnetic", ""}, + {PFIELD_HARMONIC, "HARMONIC", ICON_FORCE_HARMONIC, "Harmonic", ""}, + {PFIELD_CHARGE, "CHARGE", ICON_FORCE_CHARGE, "Charge", ""}, + {PFIELD_LENNARDJ, "LENNARDJ", ICON_FORCE_LENNARDJONES, "Lennard-Jones", ""}, + {PFIELD_TEXTURE, "TEXTURE", ICON_FORCE_TEXTURE, "Texture", ""}, + {PFIELD_GUIDE, "GUIDE", ICON_FORCE_CURVE, "Curve Guide", ""}, + {PFIELD_BOID, "BOID", ICON_FORCE_BOID, "Boid", ""}, + {PFIELD_TURBULENCE, "TURBULENCE", ICON_FORCE_TURBULENCE, "Turbulence", ""}, + {PFIELD_DRAG, "DRAG", ICON_FORCE_DRAG, "Drag", ""}, + {PFIELD_FLUIDFLOW, "FLUID", ICON_FORCE_FLUIDFLOW, "Fluid Flow", ""}, + {0, nullptr, 0, nullptr, nullptr}, + }; + + static EnumPropertyItem lightprobe_type_items[] = { + {LIGHTPROBE_TYPE_CUBE, + "CUBEMAP", + ICON_LIGHTPROBE_CUBEMAP, + "Reflection Cubemap", + "Reflection probe with spherical or cubic attenuation"}, + {LIGHTPROBE_TYPE_PLANAR, + "PLANAR", + ICON_LIGHTPROBE_PLANAR, + "Reflection Plane", + "Planar reflection probe"}, + {LIGHTPROBE_TYPE_GRID, + "GRID", + ICON_LIGHTPROBE_GRID, + "Irradiance Volume", + "Irradiance probe to capture diffuse indirect lighting"}, + {0, nullptr, 0, nullptr, nullptr}, + }; + + enum { + ALIGN_WORLD = 0, + ALIGN_VIEW, + ALIGN_CURSOR, + }; + + static const EnumPropertyItem align_options[] = { + {ALIGN_WORLD, "WORLD", 0, "World", "Align the new object to the world"}, + {ALIGN_VIEW, "VIEW", 0, "View", "Align the new object to the view"}, + {ALIGN_CURSOR, "CURSOR", 0, "3D Cursor", "Use the 3D cursor orientation for the new object"}, + {0, nullptr, 0, nullptr, nullptr}, + }; + + /** \} */ + + /* -------------------------------------------------------------------- */ + /** \name Local Helpers + * \{ */ + + /** + * Operator properties for creating an object under a screen space (2D) coordinate. + * Used for object dropping like behavior (drag object and drop into 3D View). + */ + static void object_add_drop_xy_props(wmOperatorType *ot) + { + PropertyRNA *prop; + + prop = RNA_def_int(ot->srna, + "drop_x", + 0, + INT_MIN, + INT_MAX, + "Drop X", + "X-coordinate (screen space) to place the new object under", + INT_MIN, + INT_MAX); + RNA_def_property_flag(prop, (PropertyFlag)(PROP_HIDDEN | PROP_SKIP_SAVE)); + prop = RNA_def_int(ot->srna, + "drop_y", + 0, + INT_MIN, + INT_MAX, + "Drop Y", + "Y-coordinate (screen space) to place the new object under", + INT_MIN, + INT_MAX); + RNA_def_property_flag(prop, (PropertyFlag)(PROP_HIDDEN | PROP_SKIP_SAVE)); + } + + static bool object_add_drop_xy_is_set(const wmOperator *op) + { + return RNA_struct_property_is_set(op->ptr, "drop_x") && + RNA_struct_property_is_set(op->ptr, "drop_y"); + } + + /** + * Query the currently set X- and Y-coordinate to position the new object under. + * \param r_mval: Returned pointer to the coordinate in region-space. + */ + static bool object_add_drop_xy_get(bContext *C, wmOperator *op, int (*r_mval)[2]) + { + if (!object_add_drop_xy_is_set(op)) { + (*r_mval)[0] = 0.0f; + (*r_mval)[1] = 0.0f; + return false; + } + + const ARegion *region = CTX_wm_region(C); + (*r_mval)[0] = RNA_int_get(op->ptr, "drop_x") - region->winrct.xmin; + (*r_mval)[1] = RNA_int_get(op->ptr, "drop_y") - region->winrct.ymin; + + return true; + } + + /** + * Set the drop coordinate to the mouse position (if not already set) and call the operator's + * `exec()` callback. + */ + static int object_add_drop_xy_generic_invoke(bContext *C, wmOperator *op, const wmEvent *event) + { + if (!object_add_drop_xy_is_set(op)) { + RNA_int_set(op->ptr, "drop_x", event->xy[0]); + RNA_int_set(op->ptr, "drop_y", event->xy[1]); + } + return op->type->exec(C, op); + } + + /** \} */ + + /* -------------------------------------------------------------------- */ + /** \name Public Add Object API + * \{ */ + + void ED_object_location_from_view(bContext *C, float loc[3]) + { + const Scene *scene = CTX_data_scene(C); + copy_v3_v3(loc, scene->cursor.location); + } + + void ED_object_rotation_from_quat(float rot[3], const float viewquat[4], const char align_axis) + { + BLI_assert(align_axis >= 'X' && align_axis <= 'Z'); + + switch (align_axis) { + case 'X': { + /* Same as 'rv3d->viewinv[1]' */ + const float axis_y[4] = {0.0f, 1.0f, 0.0f}; + float quat_y[4], quat[4]; + axis_angle_to_quat(quat_y, axis_y, M_PI_2); + mul_qt_qtqt(quat, viewquat, quat_y); + quat_to_eul(rot, quat); + break; + } + case 'Y': { + quat_to_eul(rot, viewquat); + rot[0] -= (float)M_PI_2; + break; + } + case 'Z': { + quat_to_eul(rot, viewquat); + break; + } + } + } + + void ED_object_rotation_from_view(bContext *C, float rot[3], const char align_axis) + { + RegionView3D *rv3d = CTX_wm_region_view3d(C); + BLI_assert(align_axis >= 'X' && align_axis <= 'Z'); + if (rv3d) { + float viewquat[4]; + copy_qt_qt(viewquat, rv3d->viewquat); + viewquat[0] *= -1.0f; + ED_object_rotation_from_quat(rot, viewquat, align_axis); + } + else { + zero_v3(rot); + } + } + + void ED_object_base_init_transform_on_add(Object *object, const float loc[3], const float rot[3]) + { + if (loc) { + copy_v3_v3(object->loc, loc); + } + + if (rot) { + copy_v3_v3(object->rot, rot); + } + + BKE_object_to_mat4(object, object->obmat); + } + + float ED_object_new_primitive_matrix(bContext *C, + Object *obedit, + const float loc[3], + const float rot[3], + @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs