2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-23 19:47:33 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-23 19:47:33 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation, 2002-2008 full recode
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
2011-02-27 20:29:51 +00:00
|
|
|
|
|
|
|
/** \file blender/editors/object/object_edit.c
|
|
|
|
* \ingroup edobj
|
|
|
|
*/
|
|
|
|
|
2008-12-23 19:47:33 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <time.h>
|
2009-09-16 17:43:09 +00:00
|
|
|
#include <float.h>
|
|
|
|
#include <ctype.h>
|
2010-05-19 09:40:45 +00:00
|
|
|
#include <stddef.h> //for offsetof
|
2008-12-23 19:47:33 +00:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2010-08-16 05:46:10 +00:00
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2010-08-16 05:46:10 +00:00
|
|
|
#include "BLI_ghash.h"
|
2017-01-16 17:33:34 +01:00
|
|
|
#include "BLI_string_utils.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2015-01-29 16:03:19 +11:00
|
|
|
|
2008-12-23 19:47:33 +00:00
|
|
|
#include "DNA_armature_types.h"
|
|
|
|
#include "DNA_curve_types.h"
|
2015-12-13 21:03:13 +13:00
|
|
|
#include "DNA_gpencil_types.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
#include "DNA_group_types.h"
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
#include "DNA_meta_types.h"
|
|
|
|
#include "DNA_property_types.h"
|
2010-08-10 05:41:51 +00:00
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
2018-02-07 11:14:08 +11:00
|
|
|
#include "DNA_object_force_types.h"
|
2010-08-10 05:41:51 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
#include "DNA_vfont_types.h"
|
2012-02-19 22:17:30 +00:00
|
|
|
#include "DNA_mesh_types.h"
|
2018-02-06 15:47:51 +11:00
|
|
|
#include "DNA_lattice_types.h"
|
2017-06-13 12:02:08 +02:00
|
|
|
#include "DNA_workspace_types.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2010-08-16 05:46:10 +00:00
|
|
|
#include "IMB_imbuf_types.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
|
|
|
|
#include "BKE_anim.h"
|
|
|
|
#include "BKE_constraint.h"
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_curve.h"
|
2011-01-23 14:04:31 +00:00
|
|
|
#include "BKE_effect.h"
|
2015-05-12 13:29:00 +05:00
|
|
|
#include "BKE_global.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
#include "BKE_image.h"
|
2015-02-23 23:05:54 +11:00
|
|
|
#include "BKE_lattice.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
#include "BKE_library.h"
|
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_material.h"
|
|
|
|
#include "BKE_mball.h"
|
|
|
|
#include "BKE_mesh.h"
|
|
|
|
#include "BKE_object.h"
|
2009-09-16 17:43:09 +00:00
|
|
|
#include "BKE_pointcache.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
#include "BKE_property.h"
|
|
|
|
#include "BKE_sca.h"
|
|
|
|
#include "BKE_softbody.h"
|
|
|
|
#include "BKE_modifier.h"
|
2013-04-13 20:31:52 +00:00
|
|
|
#include "BKE_editmesh.h"
|
2013-08-29 10:34:09 +00:00
|
|
|
#include "BKE_report.h"
|
2018-02-13 20:35:29 +11:00
|
|
|
#include "BKE_object.h"
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
#include "BKE_workspace.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
#include "DEG_depsgraph_build.h"
|
|
|
|
|
2009-01-05 19:32:04 +00:00
|
|
|
#include "ED_armature.h"
|
2009-01-14 12:26:45 +00:00
|
|
|
#include "ED_curve.h"
|
2008-12-31 17:11:42 +00:00
|
|
|
#include "ED_mesh.h"
|
2009-07-29 12:35:09 +00:00
|
|
|
#include "ED_mball.h"
|
2010-08-10 06:36:42 +00:00
|
|
|
#include "ED_lattice.h"
|
2009-01-01 18:05:12 +00:00
|
|
|
#include "ED_object.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
#include "ED_screen.h"
|
|
|
|
#include "ED_util.h"
|
2012-01-17 16:31:13 +00:00
|
|
|
#include "ED_image.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
2009-08-16 05:48:07 +00:00
|
|
|
#include "RNA_enum_types.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2009-01-02 03:16:38 +00:00
|
|
|
/* for menu/popup icons etc etc*/
|
|
|
|
|
2010-05-19 09:40:45 +00:00
|
|
|
#include "UI_interface.h"
|
2008-12-23 19:47:33 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
#include "object_intern.h" // own include
|
2008-12-23 19:47:33 +00:00
|
|
|
|
|
|
|
/* ************* XXX **************** */
|
2010-10-16 14:32:17 +00:00
|
|
|
static void error(const char *UNUSED(arg)) {}
|
|
|
|
static void waitcursor(int UNUSED(val)) {}
|
2012-06-25 07:24:48 +00:00
|
|
|
static int pupmenu(const char *UNUSED(msg)) { return 0; }
|
2008-12-23 19:47:33 +00:00
|
|
|
|
|
|
|
/* port over here */
|
2012-05-27 00:36:50 +00:00
|
|
|
static void error_libdata(void) {}
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2012-01-02 17:15:24 +00:00
|
|
|
Object *ED_object_context(bContext *C)
|
|
|
|
{
|
|
|
|
return CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
|
|
|
|
}
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2010-04-21 07:56:34 +00:00
|
|
|
/* find the correct active object per context
|
|
|
|
* note: context can be NULL when called from a enum with PROP_ENUM_NO_CONTEXT */
|
2010-03-31 00:55:01 +00:00
|
|
|
Object *ED_object_active_context(bContext *C)
|
2008-12-29 12:15:42 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Object *ob = NULL;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (C) {
|
2012-04-28 15:42:27 +00:00
|
|
|
ob = ED_object_context(C);
|
|
|
|
if (!ob) ob = CTX_data_active_object(C);
|
2010-04-21 07:56:34 +00:00
|
|
|
}
|
2010-03-31 00:55:01 +00:00
|
|
|
return ob;
|
2009-01-15 16:07:39 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 00:55:01 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
/* ******************* toggle editmode operator ***************** */
|
|
|
|
|
2016-04-29 22:33:06 +10:00
|
|
|
static bool mesh_needs_keyindex(const Mesh *me)
|
|
|
|
{
|
|
|
|
if (me->key) {
|
|
|
|
return false; /* will be added */
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const Object *ob = G.main->object.first; ob; ob = ob->id.next) {
|
|
|
|
if ((ob->parent) && (ob->parent->data == me) && ELEM(ob->partype, PARVERT1, PARVERT3)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (ob->data == me) {
|
|
|
|
for (const ModifierData *md = ob->modifiers.first; md; md = md->next) {
|
|
|
|
if (md->type == eModifierType_Hook) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-21 14:12:04 +00:00
|
|
|
/**
|
|
|
|
* Load EditMode data back into the object,
|
|
|
|
* optionally freeing the editmode data.
|
|
|
|
*/
|
2015-05-12 13:29:00 +05:00
|
|
|
static bool ED_object_editmode_load_ex(Main *bmain, Object *obedit, const bool freedata)
|
2009-01-25 20:22:05 +00:00
|
|
|
{
|
2013-03-21 14:12:04 +00:00
|
|
|
if (obedit == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-10-22 23:22:05 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (obedit->type == OB_MESH) {
|
|
|
|
Mesh *me = obedit->data;
|
2018-02-06 15:47:51 +11:00
|
|
|
if (me->edit_btmesh == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-21 14:12:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (me->edit_btmesh->bm->totvert > MESH_MAX_VERTS) {
|
2009-09-16 17:43:09 +00:00
|
|
|
error("Too many vertices");
|
2013-03-21 14:12:04 +00:00
|
|
|
return false;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2013-03-21 14:12:04 +00:00
|
|
|
|
2012-03-29 01:41:56 +00:00
|
|
|
EDBM_mesh_load(obedit);
|
2013-03-21 14:12:04 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (freedata) {
|
2012-03-27 04:46:52 +00:00
|
|
|
EDBM_mesh_free(me->edit_btmesh);
|
2009-09-16 17:43:09 +00:00
|
|
|
MEM_freeN(me->edit_btmesh);
|
2012-04-28 15:42:27 +00:00
|
|
|
me->edit_btmesh = NULL;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2018-02-06 15:47:51 +11:00
|
|
|
/* will be recalculated as needed. */
|
|
|
|
{
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
ED_mesh_mirror_spatial_table(NULL, NULL, NULL, NULL, 'e');
|
|
|
|
ED_mesh_mirror_topo_table(NULL, NULL, 'e');
|
2010-03-31 07:22:18 +00:00
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (obedit->type == OB_ARMATURE) {
|
2018-02-06 15:47:51 +11:00
|
|
|
const bArmature *arm = obedit->data;
|
|
|
|
if (arm->edbo == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-17 22:13:15 +11:00
|
|
|
ED_armature_from_edit(obedit->data);
|
2018-02-06 15:47:51 +11:00
|
|
|
if (freedata) {
|
2013-12-17 22:13:15 +11:00
|
|
|
ED_armature_edit_free(obedit->data);
|
2018-02-06 15:47:51 +11:00
|
|
|
}
|
2015-05-12 13:29:00 +05:00
|
|
|
/* TODO(sergey): Pose channels might have been changed, so need
|
|
|
|
* to inform dependency graph about this. But is it really the
|
|
|
|
* best place to do this?
|
|
|
|
*/
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
|
2018-02-06 15:47:51 +11:00
|
|
|
const Curve *cu = obedit->data;
|
|
|
|
if (cu->editnurb == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-18 12:20:28 +11:00
|
|
|
ED_curve_editnurb_load(obedit);
|
2018-02-06 15:47:51 +11:00
|
|
|
if (freedata) {
|
|
|
|
ED_curve_editnurb_free(obedit);
|
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2013-11-21 04:32:28 +11:00
|
|
|
else if (obedit->type == OB_FONT) {
|
2018-02-06 15:47:51 +11:00
|
|
|
const Curve *cu = obedit->data;
|
|
|
|
if (cu->editfont == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-18 12:20:28 +11:00
|
|
|
ED_curve_editfont_load(obedit);
|
2018-02-06 15:47:51 +11:00
|
|
|
if (freedata) {
|
|
|
|
ED_curve_editfont_free(obedit);
|
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (obedit->type == OB_LATTICE) {
|
2018-02-06 15:47:51 +11:00
|
|
|
const Lattice *lt = obedit->data;
|
|
|
|
if (lt->editlatt == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-18 12:20:28 +11:00
|
|
|
ED_lattice_editlatt_load(obedit);
|
2018-02-06 15:47:51 +11:00
|
|
|
if (freedata) {
|
|
|
|
ED_lattice_editlatt_free(obedit);
|
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (obedit->type == OB_MBALL) {
|
2018-02-06 15:47:51 +11:00
|
|
|
const MetaBall *mb = obedit->data;
|
|
|
|
if (mb->editelems == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-18 12:20:28 +11:00
|
|
|
ED_mball_editmball_load(obedit);
|
2018-02-06 15:47:51 +11:00
|
|
|
if (freedata) {
|
|
|
|
ED_mball_editmball_free(obedit);
|
|
|
|
}
|
2009-01-26 15:23:29 +00:00
|
|
|
}
|
2009-02-13 17:37:01 +00:00
|
|
|
|
2013-03-21 14:12:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ED_object_editmode_load(Object *obedit)
|
|
|
|
{
|
2015-05-12 13:29:00 +05:00
|
|
|
/* TODO(sergey): use proper main here? */
|
|
|
|
return ED_object_editmode_load_ex(G.main, obedit, false);
|
2013-03-21 14:12:04 +00:00
|
|
|
}
|
|
|
|
|
2013-03-21 14:18:17 +00:00
|
|
|
void ED_object_editmode_exit(bContext *C, int flag)
|
2013-03-21 14:12:04 +00:00
|
|
|
{
|
|
|
|
/* Note! only in exceptional cases should 'EM_DO_UNDO' NOT be in the flag */
|
|
|
|
/* Note! if 'EM_FREEDATA' isn't in the flag, use ED_object_editmode_load directly */
|
2018-02-08 21:14:26 +11:00
|
|
|
WorkSpace *workspace = CTX_wm_workspace(C);
|
2013-03-21 14:12:04 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
Object *obedit = CTX_data_edit_object(C);
|
|
|
|
const bool freedata = (flag & EM_FREEDATA) != 0;
|
|
|
|
|
|
|
|
if (flag & EM_WAITCURSOR) waitcursor(1);
|
|
|
|
|
2015-05-12 13:29:00 +05:00
|
|
|
if (ED_object_editmode_load_ex(CTX_data_main(C), obedit, freedata) == false) {
|
2013-06-02 22:21:45 +00:00
|
|
|
/* in rare cases (background mode) its possible active object
|
|
|
|
* is flagged for editmode, without 'obedit' being set [#35489] */
|
2018-02-08 21:14:26 +11:00
|
|
|
workspace->object_mode &= ~OB_MODE_EDIT;
|
2013-03-21 14:12:04 +00:00
|
|
|
if (flag & EM_WAITCURSOR) waitcursor(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-22 23:22:05 +00:00
|
|
|
/* freedata only 0 now on file saves and render */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (freedata) {
|
2009-09-12 20:47:53 +00:00
|
|
|
ListBase pidlist;
|
|
|
|
PTCacheID *pid;
|
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
/* for example; displist make is different in editmode */
|
2012-04-28 15:42:27 +00:00
|
|
|
scene->obedit = NULL; // XXX for context
|
2009-09-12 20:47:53 +00:00
|
|
|
|
|
|
|
/* flag object caches as outdated */
|
2013-01-23 05:56:34 +00:00
|
|
|
BKE_ptcache_ids_from_object(&pidlist, obedit, scene, 0);
|
2012-04-28 15:42:27 +00:00
|
|
|
for (pid = pidlist.first; pid; pid = pid->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (pid->type != PTCACHE_TYPE_PARTICLES) /* particles don't need reset on geometry change */
|
2009-09-12 20:47:53 +00:00
|
|
|
pid->cache->flag |= PTCACHE_OUTDATED;
|
|
|
|
}
|
Unified effector functionality for particles, cloth and softbody
* Unified scene wide gravity (currently in scene buttons)
instead of each simulation having it's own gravity.
* Weight parameters for all effectors and an effector group
setting.
* Every effector can use noise.
* Most effectors have "shapes" point, plane, surface, every point.
- "Point" is most like the old effectors and uses the
effector location as the effector point.
- "Plane" uses the closest point on effectors local xy-plane
as the effector point.
- "Surface" uses the closest point on an effector object's
surface as the effector point.
- "Every Point" uses every point in a mesh effector object
as an effector point.
- The falloff is calculated from this point, so for example
with "surface" shape and "use only negative z axis" it's
possible to apply force only "inside" the effector object.
* Spherical effector is now renamed as "force" as it's no longer
just spherical.
* New effector parameter "flow", which makes the effector act as
surrounding air velocity, so the resulting force is
proportional to the velocity difference of the point and "air
velocity". For example a wind field with flow=1.0 results in
proper non-accelerating wind.
* New effector fields "turbulence", which creates nice random
flow paths, and "drag", which slows the points down.
* Much improved vortex field.
* Effectors can now effect particle rotation as well as location.
* Use full, or only positive/negative z-axis to apply force
(note. the z-axis is the surface normal in the case of
effector shape "surface")
* New "force field" submenu in add menu, which adds an empty
with the chosen effector (curve object for corve guides).
* Other dynamics should be quite easy to add to the effector
system too if wanted.
* "Unified" doesn't mean that force fields give the exact same results for
particles, softbody & cloth, since their final effect depends on many external
factors, like for example the surface area of the effected faces.
Code changes
* Subversion bump for correct handling of global gravity.
* Separate ui py file for common dynamics stuff.
* Particle settings updating is flushed with it's id through
DAG_id_flush_update(..).
Known issues
* Curve guides don't yet have all ui buttons in place, but they
should work none the less.
* Hair dynamics don't yet respect force fields.
Other changes
* Particle emission defaults now to frames 1-200 with life of 50
frames to fill the whole default timeline.
* Many particles drawing related crashes fixed.
* Sometimes particles didn't update on first frame properly.
* Hair with object/group visualization didn't work properly.
* Memory leaks with PointCacheID lists (Genscher, remember to
free pidlists after use :).
2009-09-30 22:10:14 +00:00
|
|
|
BLI_freelistN(&pidlist);
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2011-09-24 11:42:11 +00:00
|
|
|
BKE_ptcache_object_reset(scene, obedit, PTCACHE_RESET_OUTDATED);
|
2009-01-25 20:22:05 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
/* also flush ob recalc, doesn't take much overhead, but used for particles */
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(&obedit->id, OB_RECALC_OB | OB_RECALC_DATA);
|
2009-02-13 17:37:01 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (flag & EM_DO_UNDO)
|
2009-10-22 23:22:05 +00:00
|
|
|
ED_undo_push(C, "Editmode");
|
2013-03-21 14:12:04 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2018-02-08 21:14:26 +11:00
|
|
|
workspace->object_mode &= ~OB_MODE_EDIT;
|
2009-10-22 23:22:05 +00:00
|
|
|
}
|
2013-03-21 14:12:04 +00:00
|
|
|
|
|
|
|
if (flag & EM_WAITCURSOR) waitcursor(0);
|
Depsgraph: Initial groundwork for copy-on-write support
< Dependency graph Copy-on-Write >
--------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
This is an initial commit of Copy-on-write support added to dependency graph.
Main priority for now: get playback (Alt-A) and all operators (selection,
transform etc) to work with the new concept of clear separation between
evaluated data coming from dependency graph and original data coming from
.blend file (and stored in bmain).
= How does this work? =
The idea is to support Copy-on-Write on the ID level. This means, we duplicate
the whole ID before we cann it's evaluaiton function. This is currently done
in the following way:
- At the depsgraph construction time we create "shallow" copy of the ID
datablock, just so we know it's pointer in memory and can use for function
bindings.
- At the evaluaiton time, the copy of ID get's "expanded" (needs a better
name internally, so it does not conflict with expanding datablocks during
library linking), which means the content of the datablock is being
copied over and all IDs are getting remapped to the copied ones.
Currently we do the whole copy, in the future we will support some tricks
here to prevent duplicating geometry arrays (verts, edges, loops, faces
and polys) when we don't need that.
- Evaluation functions are operating on copied datablocks and never touching
original datablock.
- There are some cases when we need to know non-ID pointers for function
bindings. This mainly applies to scene collections and armatures. The
idea of dealing with this is to "expand" copy-on-write datablock at
the dependency graph build time. This might introduce some slowdown to the
dependency graph construction time, but allows us to have minimal changes
in the code and avoid any hash look-up from evaluation function (one of
the ideas to avoid using pointers as function bindings is to pass name
of layer or a bone to the evaluation function and look up actual data based
on that name).
Currently there is a special function in depsgraph which does such a
synchronization, in the future we might want to make it more generic.
At some point we need to synchronize copy-on-write version of datablock with
the original version. This happens, i.e., when we change active object or
change selection. We don't want any actual evaluation of update flush happening
for such thins, so now we have a special update tag:
DEG_id_tag_update((id, DEG_TAG_COPY_ON_WRITE)
- For the render engines we now have special call for the dependency graph to
give evaluated datablock for the given original one. This isn't fully ideal
but allows to have Cycles viewport render.
This is definitely a subject for further investigation / improvement.
This call will tag copy-on-write component tagged for update without causing
updates to be flushed to any other objects, causing chain reaction of updates.
This tag is handy when selection in the scene changes.
This basically summarizes ideas underneath this commit. The code should be
reasonably documented.
Here is a demo of dependency graph with all copy-on-write stuff in it:
https://developer.blender.org/F635468
= What to expect to (not) work? =
- Only meshes are properly-ish aware of copy-on-write currently, Non-mesh
geometry will probably crash or will not work at all.
- Armatures will need similar depsgraph built-time expansion of the copied
datablock.
- There are some extra tags / relations added, to keep things demo-able but
which are slowing things down for evaluation.
- Edit mode works for until click selection is used (due to the selection
code using EditDerivedMesh created ad-hoc).
- Lots of tools will lack tagging synchronization of copied datablock for
sync with original ID.
= How to move forward? =
There is some tedious work related on going over all the tools, checking
whether they need to work with original or final evaluated object and make
the required changes.
Additionally, there need synchronization tag done in fair amount of tools
and operators as well. For example, currently it's not possible to change
render engine without re-opening the file or forcing dependency graph for
re-build via python console.
There is also now some thoughts required about copying evaluated properties
between objects or from collection to a new object. Perhaps easiest way
would be to move base flag flush to Object ID node and tag new objects for
update instead of doing manual copy.
here is some WIP patch which moves such evaluaiton / flush:
https://developer.blender.org/F635479
Lots of TODOs in the code, with possible optimization.
= How to test? =
This is a feature under heavy development, so obviously it is disabled by
default. The only reason it goes to 2.8 branch is to avoid possible merge
hell.
In order to enable this feature use WITH_DEPSGRAPH_COPY_ON_WRITE CMake
configuration option.
2017-06-14 10:26:24 +02:00
|
|
|
|
|
|
|
/* This way we ensure scene's obedit is copied into all CoW scenes. */
|
|
|
|
DEG_id_tag_update(&scene->id, 0);
|
2009-02-13 17:37:01 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2013-03-21 14:18:17 +00:00
|
|
|
void ED_object_editmode_enter(bContext *C, int flag)
|
2009-02-13 17:37:01 +00:00
|
|
|
{
|
2018-02-08 21:14:26 +11:00
|
|
|
WorkSpace *workspace = CTX_wm_workspace(C);
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2017-11-23 13:51:49 -02:00
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
2009-09-16 17:43:09 +00:00
|
|
|
Object *ob;
|
2014-04-11 11:25:41 +10:00
|
|
|
bool ok = false;
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2017-11-06 17:17:10 +01:00
|
|
|
if (ID_IS_LINKED(scene)) return;
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if ((flag & EM_IGNORE_LAYER) == 0) {
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
ob = CTX_data_active_object(C); /* active layer checked here for view3d */
|
2009-11-05 14:42:39 +00:00
|
|
|
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
if (ob == NULL) return;
|
2009-11-05 14:25:08 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-11-23 13:51:49 -02:00
|
|
|
ob = view_layer->basact->object;
|
2009-11-05 14:25:08 +00:00
|
|
|
}
|
2009-01-25 20:22:05 +00:00
|
|
|
|
Render Layers and Collections (merge from render-layers)
Design Documents
----------------
* https://wiki.blender.org/index.php/Dev:2.8/Source/Layers
* https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised
User Commit Log
---------------
* New Layer and Collection system to replace render layers and viewport layers.
* A layer is a set of collections of objects (and their drawing options) required for specific tasks.
* A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers.
* All Scenes have a master collection that all other collections are children of.
* New collection "context" tab (in Properties Editor)
* New temporary viewport "collections" panel to control per-collection
visibility
Missing User Features
---------------------
* Collection "Filter"
Option to add objects based on their names
* Collection Manager operators
The existing buttons are placeholders
* Collection Manager drawing
The editor main region is empty
* Collection Override
* Per-Collection engine settings
This will come as a separate commit, as part of the clay-engine branch
Dev Commit Log
--------------
* New DNA file (DNA_layer_types.h) with the new structs
We are replacing Base by a new extended Base while keeping it backward
compatible with some legacy settings (i.e., lay, flag_legacy).
Renamed all Base to BaseLegacy to make it clear the areas of code that
still need to be converted
Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp
* Unittesting for main syncronization requirements
- read, write, add/copy/remove objects, copy scene, collection
link/unlinking, context)
* New Editor: Collection Manager
Based on patch by Julian Eisel
This is extracted from the layer-manager branch. With the following changes:
- Renamed references of layer manager to collections manager
- I doesn't include the editors/space_collections/ draw and util files
- The drawing code itself will be implemented separately by Julian
* Base / Object:
A little note about them. Original Blender code would try to keep them
in sync through the code, juggling flags back and forth. This will now
be handled by Depsgraph, keeping Object and Bases more separated
throughout the non-rendering code.
Scene.base is being cleared in doversion, and the old viewport drawing
code was poorly converted to use the new bases while the new viewport
code doesn't get merged and replace the old one.
Python API Changes
------------------
```
- scene.layers
+ # no longer exists
- scene.objects
+ scene.scene_layers.active.objects
- scene.objects.active
+ scene.render_layers.active.objects.active
- bpy.context.scene.objects.link()
+ bpy.context.scene_collection.objects.link()
- bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None)
+ bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None)
- bpy.context.object.select
+ bpy.context.object.select = True
+ bpy.context.object.select = False
+ bpy.context.object.select_get()
+ bpy.context.object.select_set(action='SELECT')
+ bpy.context.object.select_set(action='DESELECT')
-AddObjectHelper.layers
+ # no longer exists
```
2017-02-07 10:18:38 +01:00
|
|
|
if (ELEM(NULL, ob, ob->data)) return;
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2012-12-17 14:51:06 +00:00
|
|
|
/* this checks actual object->data, for cases when other scenes have it in editmode context */
|
2014-01-16 19:15:53 +11:00
|
|
|
if (BKE_object_is_in_editmode(ob))
|
2012-12-17 14:51:06 +00:00
|
|
|
return;
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
if (BKE_object_obdata_is_libdata(ob)) {
|
2009-09-16 17:43:09 +00:00
|
|
|
error_libdata();
|
|
|
|
return;
|
2009-07-29 12:35:09 +00:00
|
|
|
}
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (flag & EM_WAITCURSOR) waitcursor(1);
|
2009-07-29 12:35:09 +00:00
|
|
|
|
2018-02-08 21:14:26 +11:00
|
|
|
workspace->object_mode_restore = workspace->object_mode;
|
2010-07-23 18:30:14 +00:00
|
|
|
|
|
|
|
/* note, when switching scenes the object can have editmode data but
|
|
|
|
* not be scene->obedit: bug 22954, this avoids calling self eternally */
|
2018-02-08 21:14:26 +11:00
|
|
|
if ((workspace->object_mode_restore & OB_MODE_EDIT) == 0)
|
|
|
|
ED_object_toggle_modes(C, workspace->object_mode);
|
2010-07-23 18:30:14 +00:00
|
|
|
|
2018-02-08 21:14:26 +11:00
|
|
|
workspace->object_mode = OB_MODE_EDIT;
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (ob->type == OB_MESH) {
|
2012-03-27 00:01:35 +00:00
|
|
|
BMEditMesh *em;
|
2012-04-28 15:42:27 +00:00
|
|
|
ok = 1;
|
2012-03-27 00:01:35 +00:00
|
|
|
scene->obedit = ob; /* context sees this */
|
|
|
|
|
2016-04-29 22:33:06 +10:00
|
|
|
const bool use_key_index = mesh_needs_keyindex(ob->data);
|
|
|
|
|
|
|
|
EDBM_mesh_make(scene->toolsettings, ob, use_key_index);
|
2.5: Text edit mode operators back. Took me a while getting
them nicely repeatable, and splitting up the big edit_text
operator into individual operator so it's all nicely scriptable,
documented, configurable, etc..
* Insert Text, Line Break, Insert Lorem
* Toggle Case, Set Case, Toggle Style, Set Style, Set Material
* Copy Text, Cut Text, Paste Text, Paste File, Paste Buffer
* Move, Move Select, Delete
* Change Spacing, Change Character
Notes
* Text (datablock) to Object doesn't work yet, will need to
implement text editor context for that.
* Some shortcut keys don't work because screen/wm overrides them,
ctrl+x, ctrl+left/right. That override goes top down which works
well for some cases, but here we need to override in the other
direction.
* There's no unicode support in RNA, or the user interface code
for that matter, but text strings can contain these characters.
At the moment it stores a UTF-8 string in char arrays, which is
supposed to be nicely compatible with ascii. Seems reasonable to
add support for UTF-8 in the interface code, python bindings, ..
eventually?
2009-02-17 19:55:20 +00:00
|
|
|
|
2013-04-16 05:59:48 +00:00
|
|
|
em = BKE_editmesh_from_object(ob);
|
2012-03-27 00:01:35 +00:00
|
|
|
if (LIKELY(em)) {
|
2012-03-29 03:06:42 +00:00
|
|
|
/* order doesn't matter */
|
|
|
|
EDBM_mesh_normals_update(em);
|
2013-04-16 05:59:48 +00:00
|
|
|
BKE_editmesh_tessface_calc(em);
|
2012-03-27 00:01:35 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_MESH, scene);
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (ob->type == OB_ARMATURE) {
|
2013-12-17 22:13:15 +11:00
|
|
|
bArmature *arm = ob->data;
|
2009-09-16 17:43:09 +00:00
|
|
|
if (!arm) return;
|
|
|
|
/*
|
2012-05-05 14:03:12 +00:00
|
|
|
* The function BKE_object_obdata_is_libdata make a problem here, the
|
2009-09-16 17:43:09 +00:00
|
|
|
* check for ob->proxy return 0 and let blender enter to edit mode
|
2012-03-04 04:35:12 +00:00
|
|
|
* this causes a crash when you try leave the edit mode.
|
2009-09-16 17:43:09 +00:00
|
|
|
* The problem is that i can't remove the ob->proxy check from
|
2012-05-05 14:03:12 +00:00
|
|
|
* BKE_object_obdata_is_libdata that prevent the bugfix #6614, so
|
2009-09-16 17:43:09 +00:00
|
|
|
* i add this little hack here.
|
|
|
|
*/
|
2017-11-06 17:17:10 +01:00
|
|
|
if (ID_IS_LINKED(arm)) {
|
2009-09-16 17:43:09 +00:00
|
|
|
error_libdata();
|
|
|
|
return;
|
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
ok = 1;
|
|
|
|
scene->obedit = ob;
|
2013-12-17 22:13:15 +11:00
|
|
|
ED_armature_to_edit(arm);
|
2009-09-16 17:43:09 +00:00
|
|
|
/* to ensure all goes in restposition and without striding */
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); /* XXX: should this be OB_RECALC_DATA? */
|
2.5: Text edit mode operators back. Took me a while getting
them nicely repeatable, and splitting up the big edit_text
operator into individual operator so it's all nicely scriptable,
documented, configurable, etc..
* Insert Text, Line Break, Insert Lorem
* Toggle Case, Set Case, Toggle Style, Set Style, Set Material
* Copy Text, Cut Text, Paste Text, Paste File, Paste Buffer
* Move, Move Select, Delete
* Change Spacing, Change Character
Notes
* Text (datablock) to Object doesn't work yet, will need to
implement text editor context for that.
* Some shortcut keys don't work because screen/wm overrides them,
ctrl+x, ctrl+left/right. That override goes top down which works
well for some cases, but here we need to override in the other
direction.
* There's no unicode support in RNA, or the user interface code
for that matter, but text strings can contain these characters.
At the moment it stores a UTF-8 string in char arrays, which is
supposed to be nicely compatible with ascii. Seems reasonable to
add support for UTF-8 in the interface code, python bindings, ..
eventually?
2009-02-17 19:55:20 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_ARMATURE, scene);
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (ob->type == OB_FONT) {
|
2012-07-06 23:56:59 +00:00
|
|
|
scene->obedit = ob; /* XXX for context */
|
2012-04-28 15:42:27 +00:00
|
|
|
ok = 1;
|
2015-11-18 12:20:28 +11:00
|
|
|
ED_curve_editfont_make(ob);
|
2.5: Text edit mode operators back. Took me a while getting
them nicely repeatable, and splitting up the big edit_text
operator into individual operator so it's all nicely scriptable,
documented, configurable, etc..
* Insert Text, Line Break, Insert Lorem
* Toggle Case, Set Case, Toggle Style, Set Style, Set Material
* Copy Text, Cut Text, Paste Text, Paste File, Paste Buffer
* Move, Move Select, Delete
* Change Spacing, Change Character
Notes
* Text (datablock) to Object doesn't work yet, will need to
implement text editor context for that.
* Some shortcut keys don't work because screen/wm overrides them,
ctrl+x, ctrl+left/right. That override goes top down which works
well for some cases, but here we need to override in the other
direction.
* There's no unicode support in RNA, or the user interface code
for that matter, but text strings can contain these characters.
At the moment it stores a UTF-8 string in char arrays, which is
supposed to be nicely compatible with ascii. Seems reasonable to
add support for UTF-8 in the interface code, python bindings, ..
eventually?
2009-02-17 19:55:20 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_TEXT, scene);
|
2009-02-10 22:45:20 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (ob->type == OB_MBALL) {
|
2012-07-06 23:56:59 +00:00
|
|
|
scene->obedit = ob; /* XXX for context */
|
2012-04-28 15:42:27 +00:00
|
|
|
ok = 1;
|
2015-11-18 12:20:28 +11:00
|
|
|
ED_mball_editmball_make(ob);
|
2009-02-25 14:50:40 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_MBALL, scene);
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (ob->type == OB_LATTICE) {
|
2012-07-06 23:56:59 +00:00
|
|
|
scene->obedit = ob; /* XXX for context */
|
2012-04-28 15:42:27 +00:00
|
|
|
ok = 1;
|
2015-11-18 12:20:28 +11:00
|
|
|
ED_lattice_editlatt_make(ob);
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_LATTICE, scene);
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (ob->type == OB_SURF || ob->type == OB_CURVE) {
|
|
|
|
ok = 1;
|
2012-07-06 23:56:59 +00:00
|
|
|
scene->obedit = ob; /* XXX for context */
|
2015-11-18 12:20:28 +11:00
|
|
|
ED_curve_editnurb_make(ob);
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_CURVE, scene);
|
2009-02-10 22:45:20 +00:00
|
|
|
}
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ok) {
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
|
Depsgraph: Initial groundwork for copy-on-write support
< Dependency graph Copy-on-Write >
--------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
This is an initial commit of Copy-on-write support added to dependency graph.
Main priority for now: get playback (Alt-A) and all operators (selection,
transform etc) to work with the new concept of clear separation between
evaluated data coming from dependency graph and original data coming from
.blend file (and stored in bmain).
= How does this work? =
The idea is to support Copy-on-Write on the ID level. This means, we duplicate
the whole ID before we cann it's evaluaiton function. This is currently done
in the following way:
- At the depsgraph construction time we create "shallow" copy of the ID
datablock, just so we know it's pointer in memory and can use for function
bindings.
- At the evaluaiton time, the copy of ID get's "expanded" (needs a better
name internally, so it does not conflict with expanding datablocks during
library linking), which means the content of the datablock is being
copied over and all IDs are getting remapped to the copied ones.
Currently we do the whole copy, in the future we will support some tricks
here to prevent duplicating geometry arrays (verts, edges, loops, faces
and polys) when we don't need that.
- Evaluation functions are operating on copied datablocks and never touching
original datablock.
- There are some cases when we need to know non-ID pointers for function
bindings. This mainly applies to scene collections and armatures. The
idea of dealing with this is to "expand" copy-on-write datablock at
the dependency graph build time. This might introduce some slowdown to the
dependency graph construction time, but allows us to have minimal changes
in the code and avoid any hash look-up from evaluation function (one of
the ideas to avoid using pointers as function bindings is to pass name
of layer or a bone to the evaluation function and look up actual data based
on that name).
Currently there is a special function in depsgraph which does such a
synchronization, in the future we might want to make it more generic.
At some point we need to synchronize copy-on-write version of datablock with
the original version. This happens, i.e., when we change active object or
change selection. We don't want any actual evaluation of update flush happening
for such thins, so now we have a special update tag:
DEG_id_tag_update((id, DEG_TAG_COPY_ON_WRITE)
- For the render engines we now have special call for the dependency graph to
give evaluated datablock for the given original one. This isn't fully ideal
but allows to have Cycles viewport render.
This is definitely a subject for further investigation / improvement.
This call will tag copy-on-write component tagged for update without causing
updates to be flushed to any other objects, causing chain reaction of updates.
This tag is handy when selection in the scene changes.
This basically summarizes ideas underneath this commit. The code should be
reasonably documented.
Here is a demo of dependency graph with all copy-on-write stuff in it:
https://developer.blender.org/F635468
= What to expect to (not) work? =
- Only meshes are properly-ish aware of copy-on-write currently, Non-mesh
geometry will probably crash or will not work at all.
- Armatures will need similar depsgraph built-time expansion of the copied
datablock.
- There are some extra tags / relations added, to keep things demo-able but
which are slowing things down for evaluation.
- Edit mode works for until click selection is used (due to the selection
code using EditDerivedMesh created ad-hoc).
- Lots of tools will lack tagging synchronization of copied datablock for
sync with original ID.
= How to move forward? =
There is some tedious work related on going over all the tools, checking
whether they need to work with original or final evaluated object and make
the required changes.
Additionally, there need synchronization tag done in fair amount of tools
and operators as well. For example, currently it's not possible to change
render engine without re-opening the file or forcing dependency graph for
re-build via python console.
There is also now some thoughts required about copying evaluated properties
between objects or from collection to a new object. Perhaps easiest way
would be to move base flag flush to Object ID node and tag new objects for
update instead of doing manual copy.
here is some WIP patch which moves such evaluaiton / flush:
https://developer.blender.org/F635479
Lots of TODOs in the code, with possible optimization.
= How to test? =
This is a feature under heavy development, so obviously it is disabled by
default. The only reason it goes to 2.8 branch is to avoid possible merge
hell.
In order to enable this feature use WITH_DEPSGRAPH_COPY_ON_WRITE CMake
configuration option.
2017-06-14 10:26:24 +02:00
|
|
|
/* This way we ensure scene's obedit is copied into all CoW scenes. */
|
|
|
|
DEG_id_tag_update(&scene->id, 0);
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-07-06 23:56:59 +00:00
|
|
|
scene->obedit = NULL; /* XXX for context */
|
2018-02-08 21:14:26 +11:00
|
|
|
workspace->object_mode &= ~OB_MODE_EDIT;
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-07-06 23:56:59 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
|
|
|
|
if (flag & EM_WAITCURSOR) waitcursor(0);
|
2009-02-10 22:45:20 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 10:34:09 +00:00
|
|
|
static int editmode_toggle_exec(bContext *C, wmOperator *op)
|
2009-09-16 17:43:09 +00:00
|
|
|
{
|
2018-02-08 21:14:26 +11:00
|
|
|
WorkSpace *workspace = CTX_wm_workspace(C);
|
2013-08-29 10:34:09 +00:00
|
|
|
const int mode_flag = OB_MODE_EDIT;
|
2013-09-08 06:05:42 +00:00
|
|
|
const bool is_mode_set = (CTX_data_edit_object(C) != NULL);
|
2015-08-31 21:37:38 +03:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2012-01-17 16:31:13 +00:00
|
|
|
|
2013-08-29 10:34:09 +00:00
|
|
|
if (!is_mode_set) {
|
2018-02-08 21:14:26 +11:00
|
|
|
if (!ED_object_mode_compat_set(C, workspace, mode_flag, op->reports)) {
|
2013-08-29 10:34:09 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_mode_set)
|
2013-03-21 14:18:17 +00:00
|
|
|
ED_object_editmode_enter(C, EM_WAITCURSOR);
|
2009-09-16 17:43:09 +00:00
|
|
|
else
|
2013-03-21 14:18:17 +00:00
|
|
|
ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR); /* had EM_DO_UNDO but op flag calls undo too [#24685] */
|
2009-02-10 22:45:20 +00:00
|
|
|
|
2015-08-31 21:37:38 +03:00
|
|
|
ED_space_image_uv_sculpt_update(CTX_wm_manager(C), scene);
|
2012-01-17 16:31:13 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2009-02-10 22:45:20 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
static int editmode_toggle_poll(bContext *C)
|
2009-01-25 20:22:05 +00:00
|
|
|
{
|
2009-09-16 17:43:09 +00:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
|
2010-01-10 20:01:13 +00:00
|
|
|
/* covers proxies too */
|
2017-11-06 17:17:10 +01:00
|
|
|
if (ELEM(NULL, ob, ob->data) || ID_IS_LINKED(ob->data))
|
2010-01-10 20:01:13 +00:00
|
|
|
return 0;
|
|
|
|
|
2018-02-09 22:14:17 +11:00
|
|
|
const WorkSpace *workspace = CTX_wm_workspace(C);
|
2018-02-06 19:34:36 +11:00
|
|
|
|
2012-11-21 03:33:34 +00:00
|
|
|
/* if hidden but in edit mode, we still display */
|
2018-02-09 22:14:17 +11:00
|
|
|
if ((ob->restrictflag & OB_RESTRICT_VIEW) && !(workspace->object_mode & OB_MODE_EDIT)) {
|
2011-01-05 18:12:54 +00:00
|
|
|
return 0;
|
2018-02-06 19:34:36 +11:00
|
|
|
}
|
2010-01-10 20:01:13 +00:00
|
|
|
|
2014-08-05 10:57:54 -04:00
|
|
|
return OB_TYPE_SUPPORT_EDITMODE(ob->type);
|
2009-01-25 20:22:05 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
|
2009-01-25 20:22:05 +00:00
|
|
|
{
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2009-01-25 20:22:05 +00:00
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Editmode";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Toggle object's editmode";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "OBJECT_OT_editmode_toggle";
|
2009-01-25 20:22:05 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = editmode_toggle_exec;
|
|
|
|
ot->poll = editmode_toggle_poll;
|
2009-01-31 19:40:40 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-01-25 20:22:05 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
/* *************************** */
|
2009-01-15 16:07:39 +00:00
|
|
|
|
2013-08-29 10:34:09 +00:00
|
|
|
static int posemode_exec(bContext *C, wmOperator *op)
|
2008-12-23 19:47:33 +00:00
|
|
|
{
|
2018-02-08 21:14:26 +11:00
|
|
|
WorkSpace *workspace = CTX_wm_workspace(C);
|
2012-04-28 15:42:27 +00:00
|
|
|
Base *base = CTX_data_active_base(C);
|
2013-08-29 10:34:09 +00:00
|
|
|
Object *ob = base->object;
|
|
|
|
const int mode_flag = OB_MODE_POSE;
|
2018-02-08 21:14:26 +11:00
|
|
|
const bool is_mode_set = (workspace->object_mode & mode_flag) != 0;
|
|
|
|
|
2013-08-29 10:34:09 +00:00
|
|
|
if (!is_mode_set) {
|
2018-02-08 21:14:26 +11:00
|
|
|
if (!ED_object_mode_compat_set(C, workspace, mode_flag, op->reports)) {
|
2013-08-29 10:34:09 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ob->type == OB_ARMATURE) {
|
|
|
|
if (ob == CTX_data_edit_object(C)) {
|
2013-03-21 14:18:17 +00:00
|
|
|
ED_object_editmode_exit(C, EM_FREEDATA | EM_DO_UNDO);
|
2009-09-16 17:43:09 +00:00
|
|
|
ED_armature_enter_posemode(C, base);
|
|
|
|
}
|
2013-08-29 10:34:09 +00:00
|
|
|
else if (is_mode_set)
|
2009-09-16 17:43:09 +00:00
|
|
|
ED_armature_exit_posemode(C, base);
|
|
|
|
else
|
|
|
|
ED_armature_enter_posemode(C, base);
|
2009-02-04 17:40:50 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
return OPERATOR_PASS_THROUGH;
|
2009-02-04 17:40:50 +00:00
|
|
|
}
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
void OBJECT_OT_posemode_toggle(wmOperatorType *ot)
|
2009-02-04 17:40:50 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Pose Mode";
|
|
|
|
ot->idname = "OBJECT_OT_posemode_toggle";
|
|
|
|
ot->description = "Enable or disable posing/selecting bones";
|
2009-02-04 17:40:50 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = posemode_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2009-02-04 17:40:50 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
/* flag */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 13:51:49 -02:00
|
|
|
static void copymenu_properties(ViewLayer *view_layer, Object *ob)
|
2009-09-16 17:43:09 +00:00
|
|
|
{
|
2010-05-19 09:40:45 +00:00
|
|
|
//XXX no longer used - to be removed - replaced by game_properties_copy_exec
|
2009-09-16 17:43:09 +00:00
|
|
|
bProperty *prop;
|
2017-03-29 21:19:07 +02:00
|
|
|
Base *base;
|
2012-04-28 15:42:27 +00:00
|
|
|
int nr, tot = 0;
|
2009-09-16 17:43:09 +00:00
|
|
|
char *str;
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
prop = ob->prop.first;
|
2012-03-24 06:38:07 +00:00
|
|
|
while (prop) {
|
2009-09-16 17:43:09 +00:00
|
|
|
tot++;
|
2012-04-28 15:42:27 +00:00
|
|
|
prop = prop->next;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
str = MEM_callocN(50 + 33 * tot, "copymenu prop");
|
2009-09-16 17:43:09 +00:00
|
|
|
|
|
|
|
if (tot)
|
|
|
|
strcpy(str, "Copy Property %t|Replace All|Merge All|%l");
|
|
|
|
else
|
|
|
|
strcpy(str, "Copy Property %t|Clear All (no properties on active)");
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
tot = 0;
|
|
|
|
prop = ob->prop.first;
|
2012-03-24 06:38:07 +00:00
|
|
|
while (prop) {
|
2009-09-16 17:43:09 +00:00
|
|
|
tot++;
|
|
|
|
strcat(str, "|");
|
|
|
|
strcat(str, prop->name);
|
2012-04-28 15:42:27 +00:00
|
|
|
prop = prop->next;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
nr = pupmenu(str);
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (nr == 1 || nr == 2) {
|
2017-11-23 13:51:49 -02:00
|
|
|
for (base = FIRSTBASE(view_layer); base; base = base->next) {
|
|
|
|
if ((base != BASACT(view_layer)) && (TESTBASELIB(base))) {
|
2012-04-28 15:42:27 +00:00
|
|
|
if (nr == 1) { /* replace */
|
2012-09-18 04:35:30 +00:00
|
|
|
BKE_bproperty_copy_list(&base->object->prop, &ob->prop);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-04-28 15:42:27 +00:00
|
|
|
for (prop = ob->prop.first; prop; prop = prop->next) {
|
2012-09-18 04:35:30 +00:00
|
|
|
BKE_bproperty_object_set(base->object, prop);
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (nr > 0) {
|
|
|
|
prop = BLI_findlink(&ob->prop, nr - 4); /* account for first 3 menu items & menu index starting at 1*/
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (prop) {
|
2017-11-23 13:51:49 -02:00
|
|
|
for (base = FIRSTBASE(view_layer); base; base = base->next) {
|
|
|
|
if ((base != BASACT(view_layer)) && (TESTBASELIB(base))) {
|
2012-09-18 04:35:30 +00:00
|
|
|
BKE_bproperty_object_set(base->object, prop);
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
MEM_freeN(str);
|
2008-12-23 19:47:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-11-23 13:51:49 -02:00
|
|
|
static void copymenu_logicbricks(ViewLayer *view_layer, Object *ob)
|
2008-12-23 19:47:33 +00:00
|
|
|
{
|
2010-05-19 09:40:45 +00:00
|
|
|
//XXX no longer used - to be removed - replaced by logicbricks_copy_exec
|
2017-03-29 21:19:07 +02:00
|
|
|
Base *base;
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2017-11-23 13:51:49 -02:00
|
|
|
for (base = FIRSTBASE(view_layer); base; base = base->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (base->object != ob) {
|
2017-11-09 13:23:01 -02:00
|
|
|
if (TESTBASELIB(base)) {
|
2009-09-16 17:43:09 +00:00
|
|
|
|
|
|
|
/* first: free all logic */
|
2012-10-21 05:46:41 +00:00
|
|
|
free_sensors(&base->object->sensors);
|
2009-09-16 17:43:09 +00:00
|
|
|
unlink_controllers(&base->object->controllers);
|
|
|
|
free_controllers(&base->object->controllers);
|
|
|
|
unlink_actuators(&base->object->actuators);
|
|
|
|
free_actuators(&base->object->actuators);
|
|
|
|
|
|
|
|
/* now copy it, this also works without logicbricks! */
|
|
|
|
clear_sca_new_poins_ob(ob);
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
copy_sensors(&base->object->sensors, &ob->sensors, 0);
|
|
|
|
copy_controllers(&base->object->controllers, &ob->controllers, 0);
|
|
|
|
copy_actuators(&base->object->actuators, &ob->actuators, 0);
|
2009-09-16 17:43:09 +00:00
|
|
|
set_sca_new_poins_ob(base->object);
|
|
|
|
|
|
|
|
/* some menu settings */
|
2012-04-28 15:42:27 +00:00
|
|
|
base->object->scavisflag = ob->scavisflag;
|
|
|
|
base->object->scaflag = ob->scaflag;
|
2009-09-16 17:43:09 +00:00
|
|
|
|
|
|
|
/* set the initial state */
|
2012-04-28 15:42:27 +00:00
|
|
|
base->object->state = ob->state;
|
|
|
|
base->object->init_state = ob->init_state;
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
/* both pointers should exist */
|
|
|
|
static void copy_texture_space(Object *to, Object *ob)
|
2008-12-23 19:47:33 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
float *poin1 = NULL, *poin2 = NULL;
|
|
|
|
short texflag = 0;
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (ob->type == OB_MESH) {
|
|
|
|
texflag = ((Mesh *)ob->data)->texflag;
|
|
|
|
poin2 = ((Mesh *)ob->data)->loc;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2014-07-20 01:30:29 +10:00
|
|
|
else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
|
2012-04-28 15:42:27 +00:00
|
|
|
texflag = ((Curve *)ob->data)->texflag;
|
|
|
|
poin2 = ((Curve *)ob->data)->loc;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (ob->type == OB_MBALL) {
|
|
|
|
texflag = ((MetaBall *)ob->data)->texflag;
|
|
|
|
poin2 = ((MetaBall *)ob->data)->loc;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (to->type == OB_MESH) {
|
|
|
|
((Mesh *)to->data)->texflag = texflag;
|
|
|
|
poin1 = ((Mesh *)to->data)->loc;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2014-07-20 01:30:29 +10:00
|
|
|
else if (ELEM(to->type, OB_CURVE, OB_SURF, OB_FONT)) {
|
2012-04-28 15:42:27 +00:00
|
|
|
((Curve *)to->data)->texflag = texflag;
|
|
|
|
poin1 = ((Curve *)to->data)->loc;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (to->type == OB_MBALL) {
|
|
|
|
((MetaBall *)to->data)->texflag = texflag;
|
|
|
|
poin1 = ((MetaBall *)to->data)->loc;
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
else
|
|
|
|
return;
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
memcpy(poin1, poin2, 9 * sizeof(float)); /* this was noted in DNA_mesh, curve, mball */
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (to->type == OB_MESH) {
|
2012-02-27 10:35:39 +00:00
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
else if (to->type == OB_MBALL) {
|
2012-05-07 06:38:41 +00:00
|
|
|
BKE_mball_texspace_calc(to);
|
2012-02-27 10:35:39 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-05 21:28:12 +00:00
|
|
|
BKE_curve_texspace_calc(to->data);
|
2012-02-27 10:35:39 +00:00
|
|
|
}
|
2008-12-23 19:47:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-09 00:41:09 +00:00
|
|
|
/* UNUSED, keep in case we want to copy functionality for use elsewhere */
|
2017-11-23 13:51:49 -02:00
|
|
|
static void copy_attr(Main *bmain, Scene *scene, ViewLayer *view_layer, short event)
|
2008-12-23 19:47:33 +00:00
|
|
|
{
|
|
|
|
Object *ob;
|
2017-03-02 15:03:02 +01:00
|
|
|
Base *base;
|
2009-09-16 17:43:09 +00:00
|
|
|
Curve *cu, *cu1;
|
|
|
|
Nurb *nu;
|
2013-02-21 19:33:04 +00:00
|
|
|
bool do_depgraph_update = false;
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2017-11-06 17:17:10 +01:00
|
|
|
if (ID_IS_LINKED(scene)) return;
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2017-11-23 13:51:49 -02:00
|
|
|
if (!(ob = OBACT(view_layer))) return;
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2018-02-13 20:35:29 +11:00
|
|
|
if (BKE_object_is_in_editmode(ob)) {
|
2009-09-16 17:43:09 +00:00
|
|
|
/* obedit_copymenu(); */
|
2008-12-23 19:47:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
if (event == 9) {
|
2017-11-23 13:51:49 -02:00
|
|
|
copymenu_properties(view_layer, ob);
|
2009-09-16 17:43:09 +00:00
|
|
|
return;
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 10) {
|
2017-11-23 13:51:49 -02:00
|
|
|
copymenu_logicbricks(view_layer, ob);
|
2009-09-16 17:43:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 24) {
|
2012-05-05 14:03:12 +00:00
|
|
|
/* moved to BKE_object_link_modifiers */
|
2011-08-06 04:19:30 +00:00
|
|
|
/* copymenu_modifiers(bmain, scene, v3d, ob); */
|
2009-09-16 17:43:09 +00:00
|
|
|
return;
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 13:51:49 -02:00
|
|
|
for (base = FIRSTBASE(view_layer); base; base = base->next) {
|
|
|
|
if (base != BASACT(view_layer)) {
|
2017-11-09 13:23:01 -02:00
|
|
|
if (TESTBASELIB(base)) {
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (event == 1) { /* loc */
|
2011-11-06 16:34:44 +00:00
|
|
|
copy_v3_v3(base->object->loc, ob->loc);
|
|
|
|
copy_v3_v3(base->object->dloc, ob->dloc);
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 2) { /* rot */
|
2011-11-06 16:34:44 +00:00
|
|
|
copy_v3_v3(base->object->rot, ob->rot);
|
|
|
|
copy_v3_v3(base->object->drot, ob->drot);
|
2011-02-02 00:40:55 +00:00
|
|
|
|
2011-11-06 16:34:44 +00:00
|
|
|
copy_qt_qt(base->object->quat, ob->quat);
|
|
|
|
copy_qt_qt(base->object->dquat, ob->dquat);
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 3) { /* size */
|
2011-11-06 16:34:44 +00:00
|
|
|
copy_v3_v3(base->object->size, ob->size);
|
2011-12-04 03:35:54 +00:00
|
|
|
copy_v3_v3(base->object->dscale, ob->dscale);
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 4) { /* drawtype */
|
|
|
|
base->object->dt = ob->dt;
|
|
|
|
base->object->dtx = ob->dtx;
|
|
|
|
base->object->empty_drawtype = ob->empty_drawtype;
|
|
|
|
base->object->empty_drawsize = ob->empty_drawsize;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 5) { /* time offs */
|
|
|
|
base->object->sf = ob->sf;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 6) { /* dupli */
|
|
|
|
base->object->dupon = ob->dupon;
|
|
|
|
base->object->dupoff = ob->dupoff;
|
|
|
|
base->object->dupsta = ob->dupsta;
|
|
|
|
base->object->dupend = ob->dupend;
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
base->object->transflag &= ~OB_DUPLI;
|
|
|
|
base->object->transflag |= (ob->transflag & OB_DUPLI);
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
base->object->dup_group = ob->dup_group;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob->dup_group)
|
2016-09-03 11:47:17 +02:00
|
|
|
id_us_plus(&ob->dup_group->id);
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 7) { /* mass */
|
|
|
|
base->object->mass = ob->mass;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 8) { /* damping */
|
|
|
|
base->object->damping = ob->damping;
|
|
|
|
base->object->rdamping = ob->rdamping;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 11) { /* all physical attributes */
|
2009-09-16 17:43:09 +00:00
|
|
|
base->object->gameflag = ob->gameflag;
|
|
|
|
base->object->inertia = ob->inertia;
|
|
|
|
base->object->formfactor = ob->formfactor;
|
2012-04-28 15:42:27 +00:00
|
|
|
base->object->damping = ob->damping;
|
|
|
|
base->object->rdamping = ob->rdamping;
|
|
|
|
base->object->min_vel = ob->min_vel;
|
|
|
|
base->object->max_vel = ob->max_vel;
|
2015-06-23 15:02:28 +02:00
|
|
|
base->object->min_angvel = ob->min_angvel;
|
|
|
|
base->object->max_angvel = ob->max_angvel;
|
2009-09-16 17:43:09 +00:00
|
|
|
if (ob->gameflag & OB_BOUNDS) {
|
2011-11-05 02:30:25 +00:00
|
|
|
base->object->collision_boundtype = ob->collision_boundtype;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
base->object->margin = ob->margin;
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
base->object->bsoft = copy_bulletsoftbody(ob->bsoft, 0);
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 17) { /* tex space */
|
2009-09-16 17:43:09 +00:00
|
|
|
copy_texture_space(base->object, ob);
|
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 18) { /* font settings */
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (base->object->type == ob->type) {
|
|
|
|
cu = ob->data;
|
|
|
|
cu1 = base->object->data;
|
|
|
|
|
|
|
|
cu1->spacemode = cu->spacemode;
|
2016-06-20 23:21:24 -03:00
|
|
|
cu1->align_y = cu->align_y;
|
2012-04-28 15:42:27 +00:00
|
|
|
cu1->spacing = cu->spacing;
|
|
|
|
cu1->linedist = cu->linedist;
|
|
|
|
cu1->shear = cu->shear;
|
|
|
|
cu1->fsize = cu->fsize;
|
|
|
|
cu1->xof = cu->xof;
|
|
|
|
cu1->yof = cu->yof;
|
|
|
|
cu1->textoncurve = cu->textoncurve;
|
|
|
|
cu1->wordspace = cu->wordspace;
|
|
|
|
cu1->ulpos = cu->ulpos;
|
|
|
|
cu1->ulheight = cu->ulheight;
|
2015-11-09 19:47:10 +01:00
|
|
|
if (cu1->vfont)
|
|
|
|
id_us_min(&cu1->vfont->id);
|
2012-04-28 15:42:27 +00:00
|
|
|
cu1->vfont = cu->vfont;
|
2009-09-16 17:43:09 +00:00
|
|
|
id_us_plus((ID *)cu1->vfont);
|
2015-11-09 19:47:10 +01:00
|
|
|
if (cu1->vfontb)
|
|
|
|
id_us_min(&cu1->vfontb->id);
|
2012-04-28 15:42:27 +00:00
|
|
|
cu1->vfontb = cu->vfontb;
|
2009-09-16 17:43:09 +00:00
|
|
|
id_us_plus((ID *)cu1->vfontb);
|
2015-11-09 19:47:10 +01:00
|
|
|
if (cu1->vfonti)
|
|
|
|
id_us_min(&cu1->vfonti->id);
|
2012-04-28 15:42:27 +00:00
|
|
|
cu1->vfonti = cu->vfonti;
|
2009-09-16 17:43:09 +00:00
|
|
|
id_us_plus((ID *)cu1->vfonti);
|
2015-11-09 19:47:10 +01:00
|
|
|
if (cu1->vfontbi)
|
|
|
|
id_us_min(&cu1->vfontbi->id);
|
2012-04-28 15:42:27 +00:00
|
|
|
cu1->vfontbi = cu->vfontbi;
|
2012-10-21 05:46:41 +00:00
|
|
|
id_us_plus((ID *)cu1->vfontbi);
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2010-11-05 07:35:21 +00:00
|
|
|
BLI_strncpy(cu1->family, cu->family, sizeof(cu1->family));
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 19) { /* bevel settings */
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ELEM(base->object->type, OB_CURVE, OB_FONT)) {
|
2012-04-28 15:42:27 +00:00
|
|
|
cu = ob->data;
|
|
|
|
cu1 = base->object->data;
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
cu1->bevobj = cu->bevobj;
|
|
|
|
cu1->taperobj = cu->taperobj;
|
|
|
|
cu1->width = cu->width;
|
|
|
|
cu1->bevresol = cu->bevresol;
|
|
|
|
cu1->ext1 = cu->ext1;
|
|
|
|
cu1->ext2 = cu->ext2;
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 25) { /* curve resolution */
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ELEM(base->object->type, OB_CURVE, OB_FONT)) {
|
2012-04-28 15:42:27 +00:00
|
|
|
cu = ob->data;
|
|
|
|
cu1 = base->object->data;
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
cu1->resolu = cu->resolu;
|
|
|
|
cu1->resolu_ren = cu->resolu_ren;
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
nu = cu1->nurb.first;
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
while (nu) {
|
2012-04-28 15:42:27 +00:00
|
|
|
nu->resolu = cu1->resolu;
|
|
|
|
nu = nu->next;
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 21) {
|
|
|
|
if (base->object->type == OB_MESH) {
|
2009-09-16 17:43:09 +00:00
|
|
|
ModifierData *md = modifiers_findByType(ob, eModifierType_Subsurf);
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
if (md) {
|
|
|
|
ModifierData *tmd = modifiers_findByType(base->object, eModifierType_Subsurf);
|
2009-01-17 18:35:33 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
if (!tmd) {
|
|
|
|
tmd = modifier_new(eModifierType_Subsurf);
|
|
|
|
BLI_addtail(&base->object->modifiers, tmd);
|
|
|
|
}
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
modifier_copyData(md, tmd);
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-17 18:35:33 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 22) {
|
2009-09-16 17:43:09 +00:00
|
|
|
/* Copy the constraint channels over */
|
2014-04-11 11:47:07 +10:00
|
|
|
BKE_constraints_copy(&base->object->constraints, &ob->constraints, true);
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2013-02-21 19:33:04 +00:00
|
|
|
do_depgraph_update = true;
|
2009-01-17 18:35:33 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 23) {
|
|
|
|
base->object->softflag = ob->softflag;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (base->object->soft) sbFree(base->object->soft);
|
2009-09-16 17:43:09 +00:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
base->object->soft = copy_softbody(ob->soft, 0);
|
2009-09-16 17:43:09 +00:00
|
|
|
|
|
|
|
if (!modifiers_findByType(base->object, eModifierType_Softbody)) {
|
|
|
|
BLI_addhead(&base->object->modifiers, modifier_new(eModifierType_Softbody));
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
2009-01-17 18:35:33 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 26) {
|
2009-09-16 17:43:09 +00:00
|
|
|
#if 0 // XXX old animation system
|
|
|
|
copy_nlastrips(&base->object->nlastrips, &ob->nlastrips);
|
|
|
|
#endif // XXX old animation system
|
2009-01-17 18:35:33 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 27) { /* autosmooth */
|
|
|
|
if (base->object->type == OB_MESH) {
|
|
|
|
Mesh *me = ob->data;
|
|
|
|
Mesh *cme = base->object->data;
|
|
|
|
cme->smoothresh = me->smoothresh;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (me->flag & ME_AUTOSMOOTH)
|
2009-09-16 17:43:09 +00:00
|
|
|
cme->flag |= ME_AUTOSMOOTH;
|
|
|
|
else
|
|
|
|
cme->flag &= ~ME_AUTOSMOOTH;
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
2009-01-17 18:35:33 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 28) { /* UV orco */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ELEM(base->object->type, OB_CURVE, OB_SURF)) {
|
2012-04-28 15:42:27 +00:00
|
|
|
cu = ob->data;
|
|
|
|
cu1 = base->object->data;
|
2009-01-30 15:01:14 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (cu->flag & CU_UV_ORCO)
|
2009-09-16 17:43:09 +00:00
|
|
|
cu1->flag |= CU_UV_ORCO;
|
|
|
|
else
|
|
|
|
cu1->flag &= ~CU_UV_ORCO;
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2009-01-17 18:35:33 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 29) { /* protected bits */
|
|
|
|
base->object->protectflag = ob->protectflag;
|
2009-01-17 18:35:33 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 30) { /* index object */
|
|
|
|
base->object->index = ob->index;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-28 15:42:27 +00:00
|
|
|
else if (event == 31) { /* object color */
|
2011-11-06 16:34:44 +00:00
|
|
|
copy_v4_v4(base->object->col, ob->col);
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2013-02-21 19:33:04 +00:00
|
|
|
if (do_depgraph_update)
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_relations_tag_update(bmain);
|
2009-01-30 15:01:14 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 20:35:29 +11:00
|
|
|
static void UNUSED_FUNCTION(copy_attr_menu) (Main *bmain, Scene *scene, ViewLayer *view_layer, Object *obedit)
|
2009-01-30 15:01:14 +00:00
|
|
|
{
|
2009-09-16 17:43:09 +00:00
|
|
|
Object *ob;
|
|
|
|
short event;
|
|
|
|
char str[512];
|
2009-01-30 15:01:14 +00:00
|
|
|
|
2017-11-23 13:51:49 -02:00
|
|
|
if (!(ob = OBACT(view_layer))) return;
|
2009-01-30 15:01:14 +00:00
|
|
|
|
2018-02-13 20:35:29 +11:00
|
|
|
if (obedit) {
|
2012-10-04 13:59:14 +00:00
|
|
|
/* if (ob->type == OB_MESH) */
|
|
|
|
/* XXX mesh_copy_menu(); */
|
2009-09-16 17:43:09 +00:00
|
|
|
return;
|
2009-01-30 15:01:14 +00:00
|
|
|
}
|
2009-01-17 18:35:33 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
/* Object Mode */
|
2009-01-17 18:35:33 +00:00
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
/* If you change this menu, don't forget to update the menu in header_view3d.c
|
|
|
|
* view3d_edit_object_copyattrmenu() and in toolbox.c
|
|
|
|
*/
|
2009-01-17 18:35:33 +00:00
|
|
|
|
2012-02-19 06:00:20 +00:00
|
|
|
strcpy(str,
|
2012-10-04 13:59:14 +00:00
|
|
|
"Copy Attributes %t|Location %x1|Rotation %x2|Size %x3|Draw Options %x4|"
|
|
|
|
"Time Offset %x5|Dupli %x6|Object Color %x31|%l|Mass %x7|Damping %x8|All Physical Attributes %x11|Properties %x9|"
|
|
|
|
"Logic Bricks %x10|Protected Transform %x29|%l");
|
2009-01-17 18:35:33 +00:00
|
|
|
|
2012-10-04 13:59:14 +00:00
|
|
|
strcat(str, "|Object Constraints %x22");
|
|
|
|
strcat(str, "|NLA Strips %x26");
|
2009-01-17 18:35:33 +00:00
|
|
|
|
2012-10-04 13:59:14 +00:00
|
|
|
/* XXX if (OB_TYPE_SUPPORT_MATERIAL(ob->type)) { */
|
|
|
|
/* strcat(str, "|Texture Space %x17"); */
|
|
|
|
/* } */
|
2009-01-31 19:40:40 +00:00
|
|
|
|
2012-10-04 13:59:14 +00:00
|
|
|
if (ob->type == OB_FONT) strcat(str, "|Font Settings %x18|Bevel Settings %x19");
|
|
|
|
if (ob->type == OB_CURVE) strcat(str, "|Bevel Settings %x19|UV Orco %x28");
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((ob->type == OB_FONT) || (ob->type == OB_CURVE)) {
|
2012-10-04 13:59:14 +00:00
|
|
|
strcat(str, "|Curve Resolution %x25");
|
2009-07-13 00:40:20 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (ob->type == OB_MESH) {
|
2012-10-04 13:59:14 +00:00
|
|
|
strcat(str, "|Subsurf Settings %x21|AutoSmooth %x27");
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2009-07-13 00:40:20 +00:00
|
|
|
|
2012-10-04 13:59:14 +00:00
|
|
|
if (ob->soft) strcat(str, "|Soft Body Settings %x23");
|
2009-07-13 00:40:20 +00:00
|
|
|
|
2012-10-04 13:59:14 +00:00
|
|
|
strcat(str, "|Pass Index %x30");
|
2009-07-13 00:40:20 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (ob->type == OB_MESH || ob->type == OB_CURVE || ob->type == OB_LATTICE || ob->type == OB_SURF) {
|
2012-10-04 13:59:14 +00:00
|
|
|
strcat(str, "|Modifiers ... %x24");
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
event = pupmenu(str);
|
|
|
|
if (event <= 0) return;
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2017-11-23 13:51:49 -02:00
|
|
|
copy_attr(bmain, scene, view_layer, event);
|
2009-07-13 00:40:20 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 14:04:31 +00:00
|
|
|
/* ******************* force field toggle operator ***************** */
|
|
|
|
|
2018-02-08 21:14:26 +11:00
|
|
|
void ED_object_check_force_modifiers(Main *bmain, Scene *scene, Object *object, eObjectMode object_mode)
|
2013-11-19 17:19:06 +06:00
|
|
|
{
|
|
|
|
PartDeflect *pd = object->pd;
|
|
|
|
ModifierData *md = modifiers_findByType(object, eModifierType_Surface);
|
|
|
|
|
|
|
|
/* add/remove modifier as needed */
|
|
|
|
if (!md) {
|
2017-08-27 12:20:21 +02:00
|
|
|
if (pd && (pd->shape == PFIELD_SHAPE_SURFACE) && !ELEM(pd->forcefield, 0, PFIELD_GUIDE, PFIELD_TEXTURE)) {
|
|
|
|
if (ELEM(object->type, OB_MESH, OB_SURF, OB_FONT, OB_CURVE)) {
|
2018-02-08 21:14:26 +11:00
|
|
|
ED_object_modifier_add(NULL, bmain, scene, object, object_mode, NULL, eModifierType_Surface);
|
2017-08-27 12:20:21 +02:00
|
|
|
}
|
|
|
|
}
|
2013-11-19 17:19:06 +06:00
|
|
|
}
|
|
|
|
else {
|
2017-08-27 12:20:21 +02:00
|
|
|
if (!pd || (pd->shape != PFIELD_SHAPE_SURFACE) || ELEM(pd->forcefield, 0, PFIELD_GUIDE, PFIELD_TEXTURE)) {
|
2013-11-19 17:19:06 +06:00
|
|
|
ED_object_modifier_remove(NULL, bmain, object, md);
|
2017-08-27 12:20:21 +02:00
|
|
|
}
|
2013-11-19 17:19:06 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-23 14:04:31 +00:00
|
|
|
static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob->pd == NULL)
|
2011-01-23 14:04:31 +00:00
|
|
|
ob->pd = object_add_collision_fields(PFIELD_FORCE);
|
2014-05-08 08:11:53 +02:00
|
|
|
else if (ob->pd->forcefield == 0)
|
2011-01-23 14:04:31 +00:00
|
|
|
ob->pd->forcefield = PFIELD_FORCE;
|
|
|
|
else
|
|
|
|
ob->pd->forcefield = 0;
|
2018-02-09 22:14:17 +11:00
|
|
|
|
|
|
|
const WorkSpace *workspace = CTX_wm_workspace(C);
|
|
|
|
ED_object_check_force_modifiers(CTX_data_main(C), CTX_data_scene(C), ob, workspace->object_mode);
|
2013-11-19 17:19:06 +06:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
|
2011-09-02 18:05:07 +00:00
|
|
|
|
2011-01-23 14:04:31 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBJECT_OT_forcefield_toggle(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Force Field";
|
2011-01-23 14:04:31 +00:00
|
|
|
ot->description = "Toggle object's force field";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "OBJECT_OT_forcefield_toggle";
|
2011-01-23 14:04:31 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = forcefield_toggle_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2011-01-23 14:04:31 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-01-23 14:04:31 +00:00
|
|
|
}
|
|
|
|
|
2010-01-19 11:31:49 +00:00
|
|
|
/* ********************************************** */
|
|
|
|
/* Motion Paths */
|
|
|
|
|
2012-05-01 13:51:50 +00:00
|
|
|
/* For the objects with animation: update paths for those that have got them
|
2010-01-19 11:31:49 +00:00
|
|
|
* This should selectively update paths that exist...
|
|
|
|
*
|
|
|
|
* To be called from various tools that do incremental updates
|
|
|
|
*/
|
|
|
|
void ED_objects_recalculate_paths(bContext *C, Scene *scene)
|
|
|
|
{
|
2017-11-20 22:33:16 +11:00
|
|
|
struct Main *bmain = CTX_data_main(C);
|
|
|
|
EvaluationContext eval_ctx;
|
|
|
|
CTX_data_eval_ctx(C, &eval_ctx);
|
2010-01-19 11:31:49 +00:00
|
|
|
ListBase targets = {NULL, NULL};
|
|
|
|
|
|
|
|
/* loop over objects in scene */
|
2012-06-05 21:54:21 +00:00
|
|
|
CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
|
2012-04-30 16:22:40 +00:00
|
|
|
{
|
2012-05-01 13:51:50 +00:00
|
|
|
/* set flag to force recalc, then grab path(s) from object */
|
2010-01-19 11:31:49 +00:00
|
|
|
ob->avs.recalc |= ANIMVIZ_RECALC_PATHS;
|
|
|
|
animviz_get_object_motionpaths(ob, &targets);
|
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
|
|
|
/* recalculate paths, then free */
|
2017-11-20 22:33:16 +11:00
|
|
|
animviz_calc_motionpaths(&eval_ctx, bmain, scene, &targets);
|
2010-01-19 11:31:49 +00:00
|
|
|
BLI_freelistN(&targets);
|
|
|
|
}
|
|
|
|
|
2012-05-06 04:18:13 +00:00
|
|
|
|
2012-05-01 16:19:13 +00:00
|
|
|
/* show popup to determine settings */
|
2013-03-13 09:03:46 +00:00
|
|
|
static int object_calculate_paths_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
2012-05-01 16:19:13 +00:00
|
|
|
{
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
|
|
|
|
if (ob == NULL)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
/* set default settings from existing/stored settings */
|
|
|
|
{
|
|
|
|
bAnimVizSettings *avs = &ob->avs;
|
|
|
|
|
|
|
|
RNA_int_set(op->ptr, "start_frame", avs->path_sf);
|
|
|
|
RNA_int_set(op->ptr, "end_frame", avs->path_ef);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* show popup dialog to allow editing of range... */
|
2012-07-07 22:51:57 +00:00
|
|
|
/* FIXME: hardcoded dimensions here are just arbitrary */
|
2013-02-19 02:30:02 +00:00
|
|
|
return WM_operator_props_dialog_popup(C, op, 10 * UI_UNIT_X, 10 * UI_UNIT_Y);
|
2012-05-01 16:19:13 +00:00
|
|
|
}
|
|
|
|
|
2012-05-01 13:51:50 +00:00
|
|
|
/* Calculate/recalculate whole paths (avs.path_sf to avs.path_ef) */
|
2012-04-28 15:42:27 +00:00
|
|
|
static int object_calculate_paths_exec(bContext *C, wmOperator *op)
|
2010-01-19 11:31:49 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2012-05-01 16:19:13 +00:00
|
|
|
int start = RNA_int_get(op->ptr, "start_frame");
|
|
|
|
int end = RNA_int_get(op->ptr, "end_frame");
|
2010-01-19 11:31:49 +00:00
|
|
|
|
|
|
|
/* set up path data for bones being calculated */
|
2012-06-05 21:54:21 +00:00
|
|
|
CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
|
2010-01-19 11:31:49 +00:00
|
|
|
{
|
2012-05-01 16:19:13 +00:00
|
|
|
bAnimVizSettings *avs = &ob->avs;
|
|
|
|
|
|
|
|
/* grab baking settings from operator settings */
|
|
|
|
avs->path_sf = start;
|
|
|
|
avs->path_ef = end;
|
|
|
|
|
2012-05-01 13:51:50 +00:00
|
|
|
/* verify that the selected object has the appropriate settings */
|
2011-11-12 04:40:53 +00:00
|
|
|
animviz_verify_motionpaths(op->reports, scene, ob, NULL);
|
2010-01-19 11:31:49 +00:00
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
2012-05-01 13:51:50 +00:00
|
|
|
/* calculate the paths for objects that have them (and are tagged to get refreshed) */
|
2010-01-19 11:31:49 +00:00
|
|
|
ED_objects_recalculate_paths(C, scene);
|
|
|
|
|
|
|
|
/* notifiers for updates */
|
2012-05-01 13:51:50 +00:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
|
2010-01-19 11:31:49 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
void OBJECT_OT_paths_calculate(wmOperatorType *ot)
|
2010-01-19 11:31:49 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Calculate Object Paths";
|
|
|
|
ot->idname = "OBJECT_OT_paths_calculate";
|
2012-05-01 13:51:50 +00:00
|
|
|
ot->description = "Calculate motion paths for the selected objects";
|
2010-01-19 11:31:49 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-05-01 16:19:13 +00:00
|
|
|
ot->invoke = object_calculate_paths_invoke;
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = object_calculate_paths_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2010-01-19 11:31:49 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-05-01 16:19:13 +00:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
RNA_def_int(ot->srna, "start_frame", 1, MINAFRAME, MAXFRAME, "Start",
|
2012-06-05 21:54:21 +00:00
|
|
|
"First frame to calculate object paths on", MINFRAME, MAXFRAME / 2.0);
|
2012-05-01 16:19:13 +00:00
|
|
|
RNA_def_int(ot->srna, "end_frame", 250, MINAFRAME, MAXFRAME, "End",
|
2012-06-05 21:54:21 +00:00
|
|
|
"Last frame to calculate object paths on", MINFRAME, MAXFRAME / 2.0);
|
2010-01-19 11:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------- */
|
|
|
|
|
2016-02-06 17:57:50 +13:00
|
|
|
static int object_update_paths_poll(bContext *C)
|
|
|
|
{
|
|
|
|
if (ED_operator_object_active_editable(C)) {
|
2016-02-27 11:30:23 +01:00
|
|
|
Object *ob = ED_object_active_context(C);
|
2016-02-06 17:57:50 +13:00
|
|
|
return (ob->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-06 04:18:13 +00:00
|
|
|
static int object_update_paths_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
|
|
|
if (scene == NULL)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
/* calculate the paths for objects that have them (and are tagged to get refreshed) */
|
|
|
|
ED_objects_recalculate_paths(C, scene);
|
|
|
|
|
|
|
|
/* notifiers for updates */
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBJECT_OT_paths_update(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Update Object Paths";
|
|
|
|
ot->idname = "OBJECT_OT_paths_update";
|
|
|
|
ot->description = "Recalculate paths for selected objects";
|
|
|
|
|
|
|
|
/* api callbakcs */
|
|
|
|
ot->exec = object_update_paths_exec;
|
2016-02-06 17:57:50 +13:00
|
|
|
ot->poll = object_update_paths_poll;
|
2012-05-06 04:18:13 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-05 21:54:21 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-05-06 04:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------- */
|
|
|
|
|
2016-02-26 01:07:26 +13:00
|
|
|
/* Helper for ED_objects_clear_paths() */
|
|
|
|
static void object_clear_mpath(Object *ob)
|
|
|
|
{
|
|
|
|
if (ob->mpath) {
|
|
|
|
animviz_free_motionpath(ob->mpath);
|
|
|
|
ob->mpath = NULL;
|
|
|
|
ob->avs.path_bakeflag &= ~MOTIONPATH_BAKE_HAS_PATHS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-06 13:04:20 +13:00
|
|
|
/* Clear motion paths for all objects */
|
2016-02-26 01:07:26 +13:00
|
|
|
void ED_objects_clear_paths(bContext *C, bool only_selected)
|
2010-01-19 11:31:49 +00:00
|
|
|
{
|
2016-02-26 01:07:26 +13:00
|
|
|
if (only_selected) {
|
|
|
|
/* loop over all selected + sedtiable objects in scene */
|
|
|
|
CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
|
|
|
|
{
|
|
|
|
object_clear_mpath(ob);
|
2010-01-19 11:31:49 +00:00
|
|
|
}
|
2016-02-26 01:07:26 +13:00
|
|
|
CTX_DATA_END;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* loop over all edtiable objects in scene */
|
|
|
|
CTX_DATA_BEGIN(C, Object *, ob, editable_objects)
|
|
|
|
{
|
|
|
|
object_clear_mpath(ob);
|
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
2010-01-19 11:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* operator callback for this */
|
2016-02-26 01:07:26 +13:00
|
|
|
static int object_clear_paths_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
bool only_selected = RNA_boolean_get(op->ptr, "only_selected");
|
|
|
|
|
2010-01-19 11:31:49 +00:00
|
|
|
/* use the backend function for this */
|
2016-02-26 01:07:26 +13:00
|
|
|
ED_objects_clear_paths(C, only_selected);
|
2010-01-19 11:31:49 +00:00
|
|
|
|
|
|
|
/* notifiers for updates */
|
2012-05-01 13:51:50 +00:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
|
2010-01-19 11:31:49 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2016-02-26 01:07:26 +13:00
|
|
|
/* operator callback/wrapper */
|
|
|
|
static int object_clear_paths_invoke(bContext *C, wmOperator *op, const wmEvent *evt)
|
|
|
|
{
|
|
|
|
if ((evt->shift) && !RNA_struct_property_is_set(op->ptr, "only_selected")) {
|
|
|
|
RNA_boolean_set(op->ptr, "only_selected", true);
|
|
|
|
}
|
|
|
|
return object_clear_paths_exec(C, op);
|
|
|
|
}
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
void OBJECT_OT_paths_clear(wmOperatorType *ot)
|
2010-01-19 11:31:49 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Clear Object Paths";
|
|
|
|
ot->idname = "OBJECT_OT_paths_clear";
|
2016-02-26 01:07:26 +13:00
|
|
|
ot->description = "Clear path caches for all objects, hold Shift key for selected objects only";
|
2010-01-19 11:31:49 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2016-02-26 01:07:26 +13:00
|
|
|
ot->invoke = object_clear_paths_invoke;
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = object_clear_paths_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2010-01-19 11:31:49 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2016-02-26 01:07:26 +13:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
ot->prop = RNA_def_boolean(ot->srna, "only_selected", false, "Only Selected",
|
|
|
|
"Only clear paths from selected objects");
|
|
|
|
RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE);
|
2010-01-19 11:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-21 00:36:07 +00:00
|
|
|
/********************** Smooth/Flat *********************/
|
|
|
|
|
|
|
|
static int shade_smooth_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2014-01-15 16:01:40 +01:00
|
|
|
ID *data;
|
2009-07-21 00:36:07 +00:00
|
|
|
Curve *cu;
|
|
|
|
Nurb *nu;
|
2015-01-26 16:03:11 +01:00
|
|
|
int clear = (STREQ(op->idname, "OBJECT_OT_shade_flat"));
|
2014-01-15 16:01:40 +01:00
|
|
|
bool done = false, linked_data = false;
|
2009-07-21 00:36:07 +00:00
|
|
|
|
2012-06-05 21:54:21 +00:00
|
|
|
CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
|
2012-04-30 16:22:40 +00:00
|
|
|
{
|
2014-01-15 16:01:40 +01:00
|
|
|
data = ob->data;
|
|
|
|
|
2017-11-06 17:17:10 +01:00
|
|
|
if (data && ID_IS_LINKED(data)) {
|
2014-01-15 16:01:40 +01:00
|
|
|
linked_data = true;
|
|
|
|
continue;
|
|
|
|
}
|
2009-07-21 00:36:07 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (ob->type == OB_MESH) {
|
2012-05-05 21:28:12 +00:00
|
|
|
BKE_mesh_smooth_flag_set(ob, !clear);
|
2009-07-21 00:36:07 +00:00
|
|
|
|
2017-08-22 22:04:40 +10:00
|
|
|
BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL);
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
|
2009-07-21 00:36:07 +00:00
|
|
|
|
2014-01-15 16:01:40 +01:00
|
|
|
done = true;
|
2009-07-21 00:36:07 +00:00
|
|
|
}
|
2012-03-25 22:35:18 +00:00
|
|
|
else if (ELEM(ob->type, OB_SURF, OB_CURVE)) {
|
2012-04-28 15:42:27 +00:00
|
|
|
cu = ob->data;
|
2009-07-21 00:36:07 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
for (nu = cu->nurb.first; nu; nu = nu->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!clear) nu->flag |= ME_SMOOTH;
|
2009-07-21 00:36:07 +00:00
|
|
|
else nu->flag &= ~ME_SMOOTH;
|
|
|
|
}
|
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
|
2012-04-28 15:42:27 +00:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
|
2009-07-21 00:36:07 +00:00
|
|
|
|
2014-01-15 16:01:40 +01:00
|
|
|
done = true;
|
2009-07-21 00:36:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
2014-01-15 16:01:40 +01:00
|
|
|
if (linked_data)
|
2014-01-21 20:18:07 +01:00
|
|
|
BKE_report(op->reports, RPT_WARNING, "Can't edit linked mesh or curve data");
|
2014-01-15 16:01:40 +01:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
return (done) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
2009-07-21 00:36:07 +00:00
|
|
|
}
|
|
|
|
|
2010-06-27 06:15:36 +00:00
|
|
|
static int shade_poll(bContext *C)
|
|
|
|
{
|
2013-08-12 06:10:29 +00:00
|
|
|
return (CTX_data_edit_object(C) == NULL);
|
2010-06-27 06:15:36 +00:00
|
|
|
}
|
|
|
|
|
2009-07-21 00:36:07 +00:00
|
|
|
void OBJECT_OT_shade_flat(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Shade Flat";
|
2013-04-13 09:32:27 +00:00
|
|
|
ot->description = "Render and display faces uniform, using Face Normals";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "OBJECT_OT_shade_flat";
|
2009-07-21 00:36:07 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = shade_poll;
|
|
|
|
ot->exec = shade_smooth_exec;
|
2009-07-21 00:36:07 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-07-21 00:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBJECT_OT_shade_smooth(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Shade Smooth";
|
2013-04-13 09:32:27 +00:00
|
|
|
ot->description = "Render and display faces smooth, using interpolated Vertex Normals";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "OBJECT_OT_shade_smooth";
|
2009-07-21 00:36:07 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = shade_poll;
|
|
|
|
ot->exec = shade_smooth_exec;
|
2009-12-04 06:33:01 +00:00
|
|
|
|
2009-07-21 00:36:07 +00:00
|
|
|
/* flags */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-07-21 00:36:07 +00:00
|
|
|
}
|
|
|
|
|
2009-01-17 18:35:33 +00:00
|
|
|
/* ********************** */
|
|
|
|
|
2018-02-13 20:35:29 +11:00
|
|
|
static void UNUSED_FUNCTION(image_aspect) (Scene *scene, ViewLayer *view_layer, Object *obedit)
|
2008-12-23 19:47:33 +00:00
|
|
|
{
|
|
|
|
/* all selected objects with an image map: scale in image aspect */
|
2017-03-29 21:19:07 +02:00
|
|
|
Base *base;
|
2008-12-23 19:47:33 +00:00
|
|
|
Object *ob;
|
|
|
|
Material *ma;
|
|
|
|
Tex *tex;
|
|
|
|
float x, y, space;
|
|
|
|
int a, b, done;
|
|
|
|
|
2018-02-13 20:35:29 +11:00
|
|
|
if (obedit) return;
|
2017-11-06 17:17:10 +01:00
|
|
|
if (ID_IS_LINKED(scene)) return;
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2017-11-23 13:51:49 -02:00
|
|
|
for (base = FIRSTBASE(view_layer); base; base = base->next) {
|
2017-11-09 13:23:01 -02:00
|
|
|
if (TESTBASELIB(base)) {
|
2012-04-28 15:42:27 +00:00
|
|
|
ob = base->object;
|
2014-04-01 11:34:00 +11:00
|
|
|
done = false;
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
for (a = 1; a <= ob->totcol; a++) {
|
|
|
|
ma = give_current_material(ob, a);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ma) {
|
2012-04-28 15:42:27 +00:00
|
|
|
for (b = 0; b < MAX_MTEX; b++) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ma->mtex[b] && ma->mtex[b]->tex) {
|
2012-04-28 15:42:27 +00:00
|
|
|
tex = ma->mtex[b]->tex;
|
|
|
|
if (tex->type == TEX_IMAGE && tex->ima) {
|
2012-11-15 15:59:58 +00:00
|
|
|
ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, NULL, NULL);
|
2008-12-23 19:47:33 +00:00
|
|
|
|
|
|
|
/* texturespace */
|
2012-04-28 15:42:27 +00:00
|
|
|
space = 1.0;
|
|
|
|
if (ob->type == OB_MESH) {
|
2008-12-23 19:47:33 +00:00
|
|
|
float size[3];
|
2012-05-05 21:28:12 +00:00
|
|
|
BKE_mesh_texspace_get(ob->data, NULL, NULL, size);
|
2012-04-28 15:42:27 +00:00
|
|
|
space = size[0] / size[1];
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
2014-07-20 01:30:29 +10:00
|
|
|
else if (ELEM(ob->type, OB_CURVE, OB_FONT, OB_SURF)) {
|
2013-08-21 07:40:19 +00:00
|
|
|
float size[3];
|
|
|
|
BKE_curve_texspace_get(ob->data, NULL, NULL, size);
|
|
|
|
space = size[0] / size[1];
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
x = ibuf->x / space;
|
|
|
|
y = ibuf->y;
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (x > y) ob->size[0] = ob->size[1] * x / y;
|
|
|
|
else ob->size[1] = ob->size[0] * y / x;
|
2008-12-23 19:47:33 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
done = true;
|
2017-06-08 10:14:53 +02:00
|
|
|
DEG_id_tag_update(&ob->id, OB_RECALC_OB);
|
2012-11-15 15:59:58 +00:00
|
|
|
|
|
|
|
BKE_image_release_ibuf(tex->ima, ibuf, NULL);
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (done) break;
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (done) break;
|
2008-12-23 19:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem *object_mode_set_itemsf(
|
|
|
|
bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
|
Fix for [#35224] Transform Orientation - order inconsistency
Fix turned out to remove as much "manual UI" from 3D view header as possible. Mode selector and all transform manipulators/orientations stuff are now RNA-based UI (leaving basically only edit mesh select modes with custom handlers, as they have some quite specific features).
To achieve this, four main modifications were done:
* enum-operator-generated menus are now MENU (i.e. dropdown lists) in headers too.
* All bit-flag enums expanded in ROW buttons now have a handling consistent with e.g. layers, or what we already have for transform manipulators, i.e. clicking select only one element, shift-click to select multiple ones.
* Consequently, the three RNA booleans manipulators flags are merged into a single bit-flag enum (yes, this is also an API change, though I doubt many scripts use it).
* Now the width of enum-based dropdown lists is computed from longest item name in enum, no more from a dummy place holder string (when no label/name is given).
All this allows to remove some code from 3DView/transform areas, that was actually mostly duplicating RNA/operator one.
Also done a few optimizations here and there (among others, do not pass &numitems to RNA_property_enum_items() when you do not need it, saves at least an iteration over enum items to count them).
Many thanks to Brecht for the reviews!
2013-05-12 13:16:11 +00:00
|
|
|
{
|
2017-10-18 15:07:26 +11:00
|
|
|
const EnumPropertyItem *input = rna_enum_object_mode_items;
|
2012-04-28 15:42:27 +00:00
|
|
|
EnumPropertyItem *item = NULL;
|
2009-08-16 16:35:14 +00:00
|
|
|
Object *ob;
|
2015-12-13 21:03:13 +13:00
|
|
|
bGPdata *gpd;
|
2012-04-28 15:42:27 +00:00
|
|
|
int totitem = 0;
|
Fix for [#35224] Transform Orientation - order inconsistency
Fix turned out to remove as much "manual UI" from 3D view header as possible. Mode selector and all transform manipulators/orientations stuff are now RNA-based UI (leaving basically only edit mesh select modes with custom handlers, as they have some quite specific features).
To achieve this, four main modifications were done:
* enum-operator-generated menus are now MENU (i.e. dropdown lists) in headers too.
* All bit-flag enums expanded in ROW buttons now have a handling consistent with e.g. layers, or what we already have for transform manipulators, i.e. clicking select only one element, shift-click to select multiple ones.
* Consequently, the three RNA booleans manipulators flags are merged into a single bit-flag enum (yes, this is also an API change, though I doubt many scripts use it).
* Now the width of enum-based dropdown lists is computed from longest item name in enum, no more from a dummy place holder string (when no label/name is given).
All this allows to remove some code from 3DView/transform areas, that was actually mostly duplicating RNA/operator one.
Also done a few optimizations here and there (among others, do not pass &numitems to RNA_property_enum_items() when you do not need it, saves at least an iteration over enum items to count them).
Many thanks to Brecht for the reviews!
2013-05-12 13:16:11 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!C) /* needed for docs */
|
2015-11-23 13:49:52 +11:00
|
|
|
return rna_enum_object_mode_items;
|
2009-08-16 05:48:07 +00:00
|
|
|
|
2009-08-16 16:35:14 +00:00
|
|
|
ob = CTX_data_active_object(C);
|
Fix for [#35224] Transform Orientation - order inconsistency
Fix turned out to remove as much "manual UI" from 3D view header as possible. Mode selector and all transform manipulators/orientations stuff are now RNA-based UI (leaving basically only edit mesh select modes with custom handlers, as they have some quite specific features).
To achieve this, four main modifications were done:
* enum-operator-generated menus are now MENU (i.e. dropdown lists) in headers too.
* All bit-flag enums expanded in ROW buttons now have a handling consistent with e.g. layers, or what we already have for transform manipulators, i.e. clicking select only one element, shift-click to select multiple ones.
* Consequently, the three RNA booleans manipulators flags are merged into a single bit-flag enum (yes, this is also an API change, though I doubt many scripts use it).
* Now the width of enum-based dropdown lists is computed from longest item name in enum, no more from a dummy place holder string (when no label/name is given).
All this allows to remove some code from 3DView/transform areas, that was actually mostly duplicating RNA/operator one.
Also done a few optimizations here and there (among others, do not pass &numitems to RNA_property_enum_items() when you do not need it, saves at least an iteration over enum items to count them).
Many thanks to Brecht for the reviews!
2013-05-12 13:16:11 +00:00
|
|
|
if (ob) {
|
2014-02-08 06:07:10 +11:00
|
|
|
const bool use_mode_particle_edit = (BLI_listbase_is_empty(&ob->particlesystem) == false) ||
|
|
|
|
(ob->soft != NULL) ||
|
2013-09-30 10:20:54 +00:00
|
|
|
(modifiers_findByType(ob, eModifierType_Cloth) != NULL);
|
Fix for [#35224] Transform Orientation - order inconsistency
Fix turned out to remove as much "manual UI" from 3D view header as possible. Mode selector and all transform manipulators/orientations stuff are now RNA-based UI (leaving basically only edit mesh select modes with custom handlers, as they have some quite specific features).
To achieve this, four main modifications were done:
* enum-operator-generated menus are now MENU (i.e. dropdown lists) in headers too.
* All bit-flag enums expanded in ROW buttons now have a handling consistent with e.g. layers, or what we already have for transform manipulators, i.e. clicking select only one element, shift-click to select multiple ones.
* Consequently, the three RNA booleans manipulators flags are merged into a single bit-flag enum (yes, this is also an API change, though I doubt many scripts use it).
* Now the width of enum-based dropdown lists is computed from longest item name in enum, no more from a dummy place holder string (when no label/name is given).
All this allows to remove some code from 3DView/transform areas, that was actually mostly duplicating RNA/operator one.
Also done a few optimizations here and there (among others, do not pass &numitems to RNA_property_enum_items() when you do not need it, saves at least an iteration over enum items to count them).
Many thanks to Brecht for the reviews!
2013-05-12 13:16:11 +00:00
|
|
|
while (input->identifier) {
|
|
|
|
if ((input->value == OB_MODE_EDIT && OB_TYPE_SUPPORT_EDITMODE(ob->type)) ||
|
|
|
|
(input->value == OB_MODE_POSE && (ob->type == OB_ARMATURE)) ||
|
2013-09-30 10:20:54 +00:00
|
|
|
(input->value == OB_MODE_PARTICLE_EDIT && use_mode_particle_edit) ||
|
2014-07-20 01:30:29 +10:00
|
|
|
(ELEM(input->value, OB_MODE_SCULPT, OB_MODE_VERTEX_PAINT,
|
2013-09-30 10:20:54 +00:00
|
|
|
OB_MODE_WEIGHT_PAINT, OB_MODE_TEXTURE_PAINT) && (ob->type == OB_MESH)) ||
|
Fix for [#35224] Transform Orientation - order inconsistency
Fix turned out to remove as much "manual UI" from 3D view header as possible. Mode selector and all transform manipulators/orientations stuff are now RNA-based UI (leaving basically only edit mesh select modes with custom handlers, as they have some quite specific features).
To achieve this, four main modifications were done:
* enum-operator-generated menus are now MENU (i.e. dropdown lists) in headers too.
* All bit-flag enums expanded in ROW buttons now have a handling consistent with e.g. layers, or what we already have for transform manipulators, i.e. clicking select only one element, shift-click to select multiple ones.
* Consequently, the three RNA booleans manipulators flags are merged into a single bit-flag enum (yes, this is also an API change, though I doubt many scripts use it).
* Now the width of enum-based dropdown lists is computed from longest item name in enum, no more from a dummy place holder string (when no label/name is given).
All this allows to remove some code from 3DView/transform areas, that was actually mostly duplicating RNA/operator one.
Also done a few optimizations here and there (among others, do not pass &numitems to RNA_property_enum_items() when you do not need it, saves at least an iteration over enum items to count them).
Many thanks to Brecht for the reviews!
2013-05-12 13:16:11 +00:00
|
|
|
(input->value == OB_MODE_OBJECT))
|
|
|
|
{
|
|
|
|
RNA_enum_item_add(&item, &totitem, input);
|
|
|
|
}
|
|
|
|
input++;
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
Fix for [#35224] Transform Orientation - order inconsistency
Fix turned out to remove as much "manual UI" from 3D view header as possible. Mode selector and all transform manipulators/orientations stuff are now RNA-based UI (leaving basically only edit mesh select modes with custom handlers, as they have some quite specific features).
To achieve this, four main modifications were done:
* enum-operator-generated menus are now MENU (i.e. dropdown lists) in headers too.
* All bit-flag enums expanded in ROW buttons now have a handling consistent with e.g. layers, or what we already have for transform manipulators, i.e. clicking select only one element, shift-click to select multiple ones.
* Consequently, the three RNA booleans manipulators flags are merged into a single bit-flag enum (yes, this is also an API change, though I doubt many scripts use it).
* Now the width of enum-based dropdown lists is computed from longest item name in enum, no more from a dummy place holder string (when no label/name is given).
All this allows to remove some code from 3DView/transform areas, that was actually mostly duplicating RNA/operator one.
Also done a few optimizations here and there (among others, do not pass &numitems to RNA_property_enum_items() when you do not need it, saves at least an iteration over enum items to count them).
Many thanks to Brecht for the reviews!
2013-05-12 13:16:11 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* We need at least this one! */
|
|
|
|
RNA_enum_items_add_value(&item, &totitem, input, OB_MODE_OBJECT);
|
2009-08-16 05:48:07 +00:00
|
|
|
}
|
2015-12-13 21:03:13 +13:00
|
|
|
|
|
|
|
/* On top of all the rest, GPencil Stroke Edit Mode
|
|
|
|
* is available if there's a valid gp datablock...
|
|
|
|
*/
|
|
|
|
gpd = CTX_data_gpencil_data(C);
|
|
|
|
if (gpd) {
|
|
|
|
RNA_enum_items_add_value(&item, &totitem, rna_enum_object_mode_items, OB_MODE_GPENCIL);
|
|
|
|
}
|
2009-08-16 05:48:07 +00:00
|
|
|
|
|
|
|
RNA_enum_item_end(&item, &totitem);
|
|
|
|
|
2014-01-04 18:08:43 +11:00
|
|
|
*r_free = true;
|
2009-08-16 05:48:07 +00:00
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2018-02-06 22:53:09 +11:00
|
|
|
static const char *object_mode_op_string(eObjectMode mode)
|
2009-08-20 05:13:07 +00:00
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (mode & OB_MODE_EDIT)
|
2009-08-20 05:13:07 +00:00
|
|
|
return "OBJECT_OT_editmode_toggle";
|
2012-03-24 06:38:07 +00:00
|
|
|
if (mode == OB_MODE_SCULPT)
|
2009-08-20 05:13:07 +00:00
|
|
|
return "SCULPT_OT_sculptmode_toggle";
|
2012-03-24 06:38:07 +00:00
|
|
|
if (mode == OB_MODE_VERTEX_PAINT)
|
2009-08-20 05:13:07 +00:00
|
|
|
return "PAINT_OT_vertex_paint_toggle";
|
2012-03-24 06:38:07 +00:00
|
|
|
if (mode == OB_MODE_WEIGHT_PAINT)
|
2009-08-20 05:13:07 +00:00
|
|
|
return "PAINT_OT_weight_paint_toggle";
|
2012-03-24 06:38:07 +00:00
|
|
|
if (mode == OB_MODE_TEXTURE_PAINT)
|
2009-08-20 05:13:07 +00:00
|
|
|
return "PAINT_OT_texture_paint_toggle";
|
2012-03-24 06:38:07 +00:00
|
|
|
if (mode == OB_MODE_PARTICLE_EDIT)
|
2009-08-20 05:13:07 +00:00
|
|
|
return "PARTICLE_OT_particle_edit_toggle";
|
2012-03-24 06:38:07 +00:00
|
|
|
if (mode == OB_MODE_POSE)
|
2009-08-20 05:13:07 +00:00
|
|
|
return "OBJECT_OT_posemode_toggle";
|
2015-12-13 21:03:13 +13:00
|
|
|
if (mode == OB_MODE_GPENCIL)
|
|
|
|
return "GPENCIL_OT_editmode_toggle";
|
2009-08-20 05:13:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-16 17:43:09 +00:00
|
|
|
/* checks the mode to be set is compatible with the object
|
2013-08-26 15:43:34 +00:00
|
|
|
* should be made into a generic function
|
|
|
|
*/
|
2017-10-17 13:43:10 +11:00
|
|
|
static bool object_mode_compat_test(Object *ob, eObjectMode mode)
|
2009-09-16 17:43:09 +00:00
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob) {
|
|
|
|
if (mode == OB_MODE_OBJECT)
|
2013-07-21 08:16:37 +00:00
|
|
|
return true;
|
2015-12-13 21:03:13 +13:00
|
|
|
else if (mode == OB_MODE_GPENCIL)
|
|
|
|
return true; /* XXX: assume this is the case for now... */
|
2010-01-13 07:26:11 +00:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (ob->type) {
|
2012-04-28 15:42:27 +00:00
|
|
|
case OB_MESH:
|
2013-08-26 15:43:34 +00:00
|
|
|
if (mode & (OB_MODE_EDIT | OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT |
|
|
|
|
OB_MODE_TEXTURE_PAINT | OB_MODE_PARTICLE_EDIT))
|
|
|
|
{
|
2013-07-21 08:16:37 +00:00
|
|
|
return true;
|
2013-08-26 15:43:34 +00:00
|
|
|
}
|
2013-07-21 08:16:37 +00:00
|
|
|
break;
|
2012-04-28 15:42:27 +00:00
|
|
|
case OB_CURVE:
|
|
|
|
case OB_SURF:
|
|
|
|
case OB_FONT:
|
|
|
|
case OB_MBALL:
|
|
|
|
if (mode & (OB_MODE_EDIT))
|
2013-07-21 08:16:37 +00:00
|
|
|
return true;
|
|
|
|
break;
|
2012-04-28 15:42:27 +00:00
|
|
|
case OB_LATTICE:
|
|
|
|
if (mode & (OB_MODE_EDIT | OB_MODE_WEIGHT_PAINT))
|
2013-07-21 08:16:37 +00:00
|
|
|
return true;
|
|
|
|
break;
|
2012-04-28 15:42:27 +00:00
|
|
|
case OB_ARMATURE:
|
|
|
|
if (mode & (OB_MODE_EDIT | OB_MODE_POSE))
|
2013-07-21 08:16:37 +00:00
|
|
|
return true;
|
|
|
|
break;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-21 08:16:37 +00:00
|
|
|
return false;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 10:34:09 +00:00
|
|
|
/**
|
|
|
|
* Sets the mode to a compatible state (use before entering the mode).
|
|
|
|
*
|
|
|
|
* This is so each mode's exec function can call
|
|
|
|
*/
|
2018-02-08 21:14:26 +11:00
|
|
|
bool ED_object_mode_compat_set(bContext *C, WorkSpace *workspace, eObjectMode mode, ReportList *reports)
|
2013-08-29 10:34:09 +00:00
|
|
|
{
|
|
|
|
bool ok;
|
2018-02-08 21:14:26 +11:00
|
|
|
if (!ELEM(workspace->object_mode, mode, OB_MODE_OBJECT)) {
|
|
|
|
const char *opstring = object_mode_op_string(workspace->object_mode);
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
|
2013-08-29 10:34:09 +00:00
|
|
|
WM_operator_name_call(C, opstring, WM_OP_EXEC_REGION_WIN, NULL);
|
2018-02-08 21:14:26 +11:00
|
|
|
ok = ELEM(workspace->object_mode, mode, OB_MODE_OBJECT);
|
2013-08-29 10:34:09 +00:00
|
|
|
if (!ok) {
|
|
|
|
wmOperatorType *ot = WM_operatortype_find(opstring, false);
|
|
|
|
BKE_reportf(reports, RPT_ERROR, "Unable to execute '%s', error changing modes", ot->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2015-12-13 21:03:13 +13:00
|
|
|
static int object_mode_set_poll(bContext *C)
|
|
|
|
{
|
|
|
|
/* Since Grease Pencil editmode is also handled here,
|
|
|
|
* we have a special exception for allowing this operator
|
|
|
|
* to still work in that case when there's no active object
|
|
|
|
* so that users can exit editmode this way as per normal.
|
|
|
|
*/
|
|
|
|
if (ED_operator_object_active_editable(C))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return (CTX_data_gpencil_data(C) != NULL);
|
|
|
|
}
|
|
|
|
|
2009-08-16 05:48:07 +00:00
|
|
|
static int object_mode_set_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2018-02-08 21:14:26 +11:00
|
|
|
WorkSpace *workspace = CTX_wm_workspace(C);
|
2012-04-28 15:42:27 +00:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2015-12-13 21:03:13 +13:00
|
|
|
bGPdata *gpd = CTX_data_gpencil_data(C);
|
2017-10-17 13:43:10 +11:00
|
|
|
eObjectMode mode = RNA_enum_get(op->ptr, "mode");
|
2018-02-08 21:14:26 +11:00
|
|
|
eObjectMode restore_mode = workspace->object_mode;
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool toggle = RNA_boolean_get(op->ptr, "toggle");
|
2015-12-13 21:03:13 +13:00
|
|
|
|
|
|
|
if (gpd) {
|
|
|
|
/* GP Mode is not bound to a specific object. Therefore,
|
|
|
|
* we don't want it to be actually saved on any objects,
|
|
|
|
* as weirdness can happen if you select other objects,
|
|
|
|
* or load old files.
|
|
|
|
*
|
|
|
|
* Instead, we use the following 2 rules to ensure that
|
|
|
|
* the mode selector works as expected:
|
|
|
|
* 1) If there's no object, we want to enter editmode.
|
|
|
|
* (i.e. with no object, we're in object mode)
|
|
|
|
* 2) Otherwise, exit stroke editmode, so that we can
|
|
|
|
* enter another mode...
|
|
|
|
*/
|
|
|
|
if (!ob || (gpd->flag & GP_DATA_STROKE_EDITMODE)) {
|
|
|
|
WM_operator_name_call(C, "GPENCIL_OT_editmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-29 10:34:09 +00:00
|
|
|
if (!ob || !object_mode_compat_test(ob, mode))
|
2011-09-24 11:42:11 +00:00
|
|
|
return OPERATOR_PASS_THROUGH;
|
2009-08-16 05:48:07 +00:00
|
|
|
|
2018-02-08 21:14:26 +11:00
|
|
|
if (workspace->object_mode != mode) {
|
2013-08-29 10:34:09 +00:00
|
|
|
/* we should be able to remove this call, each operator calls */
|
2018-02-08 21:14:26 +11:00
|
|
|
ED_object_mode_compat_set(C, workspace, mode, op->reports);
|
2013-08-26 15:43:34 +00:00
|
|
|
}
|
2009-08-20 05:13:07 +00:00
|
|
|
|
2013-08-29 10:34:09 +00:00
|
|
|
/* Exit current mode if it's not the mode we're setting */
|
2018-02-08 21:14:26 +11:00
|
|
|
if (mode != OB_MODE_OBJECT && (workspace->object_mode != mode || toggle)) {
|
2009-08-21 17:35:35 +00:00
|
|
|
/* Enter new mode */
|
2014-06-18 16:29:03 +10:00
|
|
|
ED_object_toggle_modes(C, mode);
|
2013-08-26 15:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (toggle) {
|
|
|
|
/* Special case for Object mode! */
|
2018-02-08 21:14:26 +11:00
|
|
|
if ((mode == OB_MODE_OBJECT) &&
|
|
|
|
(restore_mode == OB_MODE_OBJECT) &&
|
|
|
|
(workspace->object_mode_restore != OB_MODE_OBJECT))
|
|
|
|
{
|
|
|
|
ED_object_toggle_modes(C, workspace->object_mode_restore);
|
2013-08-26 15:43:34 +00:00
|
|
|
}
|
2018-02-08 21:14:26 +11:00
|
|
|
else if (workspace->object_mode == mode) {
|
2013-08-26 15:43:34 +00:00
|
|
|
/* For toggling, store old mode so we know what to go back to */
|
2018-02-08 21:14:26 +11:00
|
|
|
workspace->object_mode_restore = restore_mode;
|
2013-08-26 15:43:34 +00:00
|
|
|
}
|
2018-02-08 21:14:26 +11:00
|
|
|
else if (!ELEM(workspace->object_mode_restore, mode, OB_MODE_OBJECT)) {
|
|
|
|
ED_object_toggle_modes(C, workspace->object_mode_restore);
|
2009-08-21 17:35:35 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-16 05:48:07 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBJECT_OT_mode_set(wmOperatorType *ot)
|
|
|
|
{
|
2013-08-26 15:43:34 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2009-08-16 05:48:07 +00:00
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Set Object Mode";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Sets the object interaction mode";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "OBJECT_OT_mode_set";
|
2009-08-16 05:48:07 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = object_mode_set_exec;
|
2009-08-16 05:48:07 +00:00
|
|
|
|
2015-12-13 21:03:13 +13:00
|
|
|
ot->poll = object_mode_set_poll; //ED_operator_object_active_editable;
|
2009-08-16 05:48:07 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = 0; /* no register/undo here, leave it to operators being called */
|
2009-08-16 05:48:07 +00:00
|
|
|
|
2015-11-23 13:49:52 +11:00
|
|
|
ot->prop = RNA_def_enum(ot->srna, "mode", rna_enum_object_mode_items, OB_MODE_OBJECT, "Mode", "");
|
Fix for [#35224] Transform Orientation - order inconsistency
Fix turned out to remove as much "manual UI" from 3D view header as possible. Mode selector and all transform manipulators/orientations stuff are now RNA-based UI (leaving basically only edit mesh select modes with custom handlers, as they have some quite specific features).
To achieve this, four main modifications were done:
* enum-operator-generated menus are now MENU (i.e. dropdown lists) in headers too.
* All bit-flag enums expanded in ROW buttons now have a handling consistent with e.g. layers, or what we already have for transform manipulators, i.e. clicking select only one element, shift-click to select multiple ones.
* Consequently, the three RNA booleans manipulators flags are merged into a single bit-flag enum (yes, this is also an API change, though I doubt many scripts use it).
* Now the width of enum-based dropdown lists is computed from longest item name in enum, no more from a dummy place holder string (when no label/name is given).
All this allows to remove some code from 3DView/transform areas, that was actually mostly duplicating RNA/operator one.
Also done a few optimizations here and there (among others, do not pass &numitems to RNA_property_enum_items() when you do not need it, saves at least an iteration over enum items to count them).
Many thanks to Brecht for the reviews!
2013-05-12 13:16:11 +00:00
|
|
|
RNA_def_enum_funcs(ot->prop, object_mode_set_itemsf);
|
2013-08-26 15:43:34 +00:00
|
|
|
RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE);
|
2009-08-21 17:35:35 +00:00
|
|
|
|
2013-08-26 15:43:34 +00:00
|
|
|
prop = RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "");
|
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
2009-08-16 05:48:07 +00:00
|
|
|
}
|
|
|
|
|
2018-02-06 22:53:09 +11:00
|
|
|
void ED_object_toggle_modes(bContext *C, eObjectMode mode)
|
2009-08-15 18:58:01 +00:00
|
|
|
{
|
2014-06-18 16:23:50 +10:00
|
|
|
if (mode != OB_MODE_OBJECT) {
|
|
|
|
const char *opstring = object_mode_op_string(mode);
|
Main Workspace Integration
This commit does the main integration of workspaces, which is a design we agreed on during the 2.8 UI workshop (see https://wiki.blender.org/index.php/Dev:2.8/UI/Workshop_Writeup)
Workspaces should generally be stable, I'm not aware of any remaining bugs (or I've forgotten them :) ). If you find any, let me know!
(Exception: mode switching button might get out of sync with actual mode in some cases, would consider that a limitation/ToDo. Needs to be resolved at some point.)
== Main Changes/Features
* Introduces the new Workspaces as data-blocks.
* Allow storing a number of custom workspaces as part of the user configuration. Needs further work to allow adding and deleting individual workspaces.
* Bundle a default workspace configuration with Blender (current screen-layouts converted to workspaces).
* Pressing button to add a workspace spawns a menu to select between "Duplicate Current" and the workspaces from the user configuration. If no workspaces are stored in the user configuration, the default workspaces are listed instead.
* Store screen-layouts (`bScreen`) per workspace.
* Store an active screen-layout per workspace. Changing the workspace will enable this layout.
* Store active mode in workspace. Changing the workspace will also enter the mode of the new workspace. (Note that we still store the active mode in the object, moving this completely to workspaces is a separate project.)
* Store an active render layer per workspace.
* Moved mode switch from 3D View header to Info Editor header.
* Store active scene in window (not directly workspace related, but overlaps quite a bit).
* Removed 'Use Global Scene' User Preference option.
* Compatibility with old files - a new workspace is created for every screen-layout of old files. Old Blender versions should be able to read files saved with workspace support as well.
* Default .blend only contains one workspace ("General").
* Support appending workspaces.
Opening files without UI and commandline rendering should work fine.
Note that the UI is temporary! We plan to introduce a new global topbar
that contains the workspace options and tabs for switching workspaces.
== Technical Notes
* Workspaces are data-blocks.
* Adding and removing `bScreen`s should be done through `ED_workspace_layout` API now.
* A workspace can be active in multiple windows at the same time.
* The mode menu (which is now in the Info Editor header) doesn't display "Grease Pencil Edit" mode anymore since its availability depends on the active editor. Will be fixed by making Grease Pencil an own object type (as planned).
* The button to change the active workspace object mode may get out of sync with the mode of the active object. Will either be resolved by moving mode out of object data, or we'll disable workspace modes again (there's a `#define USE_WORKSPACE_MODE` for that).
* Screen-layouts (`bScreen`) are IDs and thus stored in a main list-base. Had to add a wrapper `WorkSpaceLayout` so we can store them in a list-base within workspaces, too. On the long run we could completely replace `bScreen` by workspace structs.
* `WorkSpace` types use some special compiler trickery to allow marking structs and struct members as private. BKE_workspace API should be used for accessing those.
* Added scene operators `SCENE_OT_`. Was previously done through screen operators.
== BPY API Changes
* Removed `Screen.scene`, added `Window.scene`
* Removed `UserPreferencesView.use_global_scene`
* Added `Context.workspace`, `Window.workspace` and `BlendData.workspaces`
* Added `bpy.types.WorkSpace` containing `screens`, `object_mode` and `render_layer`
* Added Screen.layout_name for the layout name that'll be displayed in the UI (may differ from internal name)
== What's left?
* There are a few open design questions (T50521). We should find the needed answers and implement them.
* Allow adding and removing individual workspaces from workspace configuration (needs UI design).
* Get the override system ready and support overrides per workspace.
* Support custom UI setups as part of workspaces (hidden panels, hidden buttons, customizable toolbars, etc).
* Allow enabling add-ons per workspace.
* Support custom workspace keymaps.
* Remove special exception for workspaces in linking code (so they're always appended, never linked). Depends on a few things, so best to solve later.
* Get the topbar done.
* Workspaces need a proper icon, current one is just a placeholder :)
Reviewed By: campbellbarton, mont29
Tags: #user_interface, #bf_blender_2.8
Maniphest Tasks: T50521
Differential Revision: https://developer.blender.org/D2451
2017-06-01 19:56:58 +02:00
|
|
|
|
2014-06-18 16:23:50 +10:00
|
|
|
if (opstring) {
|
|
|
|
WM_operator_name_call(C, opstring, WM_OP_EXEC_REGION_WIN, NULL);
|
|
|
|
}
|
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************ Game Properties ***********************/
|
|
|
|
|
2013-07-28 17:06:31 +00:00
|
|
|
static int game_property_new_exec(bContext *C, wmOperator *op)
|
2009-09-16 17:43:09 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2009-09-16 17:43:09 +00:00
|
|
|
bProperty *prop;
|
2012-01-11 08:51:06 +00:00
|
|
|
char name[MAX_NAME];
|
2012-04-28 15:42:27 +00:00
|
|
|
int type = RNA_enum_get(op->ptr, "type");
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-09-18 04:35:30 +00:00
|
|
|
prop = BKE_bproperty_new(type);
|
2009-09-16 17:43:09 +00:00
|
|
|
BLI_addtail(&ob->prop, prop);
|
2012-01-04 21:40:00 +00:00
|
|
|
|
|
|
|
RNA_string_get(op->ptr, "name", name);
|
2012-01-05 06:34:14 +00:00
|
|
|
if (name[0] != '\0') {
|
2012-01-04 21:40:00 +00:00
|
|
|
BLI_strncpy(prop->name, name, sizeof(prop->name));
|
2012-01-05 06:34:14 +00:00
|
|
|
}
|
2012-01-04 21:40:00 +00:00
|
|
|
|
2015-01-29 16:03:19 +11:00
|
|
|
BLI_uniquename(&ob->prop, prop, DATA_("Property"), '.', offsetof(bProperty, name), sizeof(prop->name));
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2010-06-03 06:41:24 +00:00
|
|
|
WM_event_add_notifier(C, NC_LOGIC, NULL);
|
2009-09-16 17:43:09 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OBJECT_OT_game_property_new(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "New Game Property";
|
|
|
|
ot->description = "Create a new property available to the game engine";
|
|
|
|
ot->idname = "OBJECT_OT_game_property_new";
|
2009-09-16 17:43:09 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2013-07-28 17:06:31 +00:00
|
|
|
ot->exec = game_property_new_exec;
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2009-09-16 17:43:09 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-01-04 21:40:00 +00:00
|
|
|
|
2015-11-23 13:49:52 +11:00
|
|
|
RNA_def_enum(ot->srna, "type", rna_enum_gameproperty_type_items, GPROP_FLOAT, "Type", "Type of game property to add");
|
2014-01-16 21:43:22 +11:00
|
|
|
RNA_def_string(ot->srna, "name", NULL, MAX_NAME, "Name", "Name of the game property to add");
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
|
|
|
|
2013-07-28 17:06:31 +00:00
|
|
|
static int game_property_remove_exec(bContext *C, wmOperator *op)
|
2009-09-16 17:43:09 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Object *ob = CTX_data_active_object(C);
|
2009-09-16 17:43:09 +00:00
|
|
|
bProperty *prop;
|
2012-04-28 15:42:27 +00:00
|
|
|
int index = RNA_int_get(op->ptr, "index");
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ob)
|
2009-09-16 17:43:09 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
prop = BLI_findlink(&ob->prop, index);
|
2009-09-16 17:43:09 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (prop) {
|
2009-09-16 17:43:09 +00:00
|
|
|
BLI_remlink(&ob->prop, prop);
|
2012-09-18 04:35:30 +00:00
|
|
|
BKE_bproperty_free(prop);
|
2010-06-03 06:41:24 +00:00
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_LOGIC, NULL);
|
2009-09-16 17:43:09 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2010-03-22 09:30:00 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBJECT_OT_game_property_remove(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Remove Game Property";
|
|
|
|
ot->description = "Remove game property";
|
|
|
|
ot->idname = "OBJECT_OT_game_property_remove";
|
2009-09-16 17:43:09 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2013-07-28 17:06:31 +00:00
|
|
|
ot->exec = game_property_remove_exec;
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2009-09-16 17:43:09 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-09-16 17:43:09 +00:00
|
|
|
|
|
|
|
RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index to remove ", 0, INT_MAX);
|
2009-08-15 18:58:01 +00:00
|
|
|
}
|
2010-05-19 09:40:45 +00:00
|
|
|
|
2015-04-21 23:33:24 +02:00
|
|
|
#define GAME_PROPERTY_MOVE_UP 1
|
|
|
|
#define GAME_PROPERTY_MOVE_DOWN -1
|
|
|
|
|
|
|
|
static int game_property_move(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
bProperty *prop;
|
|
|
|
bProperty *otherprop = NULL;
|
|
|
|
const int index = RNA_int_get(op->ptr, "index");
|
2015-05-24 23:49:54 +10:00
|
|
|
const int dir = RNA_enum_get(op->ptr, "direction");
|
2015-04-21 23:33:24 +02:00
|
|
|
|
|
|
|
if (ob == NULL)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
prop = BLI_findlink(&ob->prop, index);
|
2015-04-22 17:19:23 +02:00
|
|
|
/* invalid index */
|
|
|
|
if (prop == NULL)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2015-04-21 23:33:24 +02:00
|
|
|
if (dir == GAME_PROPERTY_MOVE_UP) {
|
|
|
|
otherprop = prop->prev;
|
|
|
|
}
|
|
|
|
else if (dir == GAME_PROPERTY_MOVE_DOWN) {
|
|
|
|
otherprop = prop->next;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prop && otherprop) {
|
|
|
|
BLI_listbase_swaplinks(&ob->prop, prop, otherprop);
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_LOGIC, NULL);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBJECT_OT_game_property_move(wmOperatorType *ot)
|
|
|
|
{
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem direction_property_move[] = {
|
2015-04-21 23:33:24 +02:00
|
|
|
{GAME_PROPERTY_MOVE_UP, "UP", 0, "Up", ""},
|
|
|
|
{GAME_PROPERTY_MOVE_DOWN, "DOWN", 0, "Down", ""},
|
|
|
|
{0, NULL, 0, NULL, NULL}
|
|
|
|
};
|
2015-04-22 17:19:23 +02:00
|
|
|
PropertyRNA *prop;
|
2015-04-21 23:33:24 +02:00
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Move Game Property";
|
2015-04-22 17:19:23 +02:00
|
|
|
ot->description = "Move game property";
|
2015-04-21 23:33:24 +02:00
|
|
|
ot->idname = "OBJECT_OT_game_property_move";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = game_property_move;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
2015-04-22 17:19:23 +02:00
|
|
|
/* properties */
|
|
|
|
prop = RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index to move", 0, INT_MAX);
|
|
|
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
2015-04-21 23:33:24 +02:00
|
|
|
RNA_def_enum(ot->srna, "direction", direction_property_move, 0, "Direction",
|
|
|
|
"Direction for moving the property");
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef GAME_PROPERTY_MOVE_UP
|
|
|
|
#undef GAME_PROPERTY_MOVE_DOWN
|
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
#define COPY_PROPERTIES_REPLACE 1
|
|
|
|
#define COPY_PROPERTIES_MERGE 2
|
|
|
|
#define COPY_PROPERTIES_COPY 3
|
2010-05-19 09:40:45 +00:00
|
|
|
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem game_properties_copy_operations[] = {
|
2010-05-25 06:24:45 +00:00
|
|
|
{COPY_PROPERTIES_REPLACE, "REPLACE", 0, "Replace Properties", ""},
|
|
|
|
{COPY_PROPERTIES_MERGE, "MERGE", 0, "Merge Properties", ""},
|
|
|
|
{COPY_PROPERTIES_COPY, "COPY", 0, "Copy a Property", ""},
|
2012-06-05 21:54:21 +00:00
|
|
|
{0, NULL, 0, NULL, NULL}
|
|
|
|
};
|
2010-05-19 09:40:45 +00:00
|
|
|
|
2017-10-18 15:07:26 +11:00
|
|
|
static const EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
|
2010-05-24 10:38:05 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Object *ob = ED_object_active_context(C);
|
2010-05-24 10:38:05 +00:00
|
|
|
EnumPropertyItem tmp = {0, "", 0, "", ""};
|
2012-04-28 15:42:27 +00:00
|
|
|
EnumPropertyItem *item = NULL;
|
2010-05-24 10:38:05 +00:00
|
|
|
bProperty *prop;
|
2012-04-28 15:42:27 +00:00
|
|
|
int a, totitem = 0;
|
2010-05-24 10:38:05 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ob)
|
2012-12-22 01:08:42 +00:00
|
|
|
return DummyRNA_NULL_items;
|
2010-05-24 10:38:05 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
for (a = 1, prop = ob->prop.first; prop; prop = prop->next, a++) {
|
|
|
|
tmp.value = a;
|
|
|
|
tmp.identifier = prop->name;
|
|
|
|
tmp.name = prop->name;
|
2010-05-24 10:38:05 +00:00
|
|
|
RNA_enum_item_add(&item, &totitem, &tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
RNA_enum_item_end(&item, &totitem);
|
2014-01-04 18:08:43 +11:00
|
|
|
*r_free = true;
|
2010-05-24 10:38:05 +00:00
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2010-05-19 09:40:45 +00:00
|
|
|
static int game_property_copy_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Object *ob = ED_object_active_context(C);
|
2010-05-19 09:40:45 +00:00
|
|
|
bProperty *prop;
|
2010-05-25 06:24:45 +00:00
|
|
|
int type = RNA_enum_get(op->ptr, "operation");
|
2012-04-28 15:42:27 +00:00
|
|
|
int propid = RNA_enum_get(op->ptr, "property");
|
2010-05-24 10:38:05 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (propid > 0) { /* copy */
|
2012-04-28 15:42:27 +00:00
|
|
|
prop = BLI_findlink(&ob->prop, propid - 1);
|
2010-05-25 06:24:45 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (prop) {
|
2012-06-05 21:54:21 +00:00
|
|
|
CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
|
2012-04-30 16:22:40 +00:00
|
|
|
{
|
2011-11-21 20:08:16 +00:00
|
|
|
if (ob != ob_iter)
|
2012-09-18 04:35:30 +00:00
|
|
|
BKE_bproperty_object_set(ob_iter, prop);
|
2010-05-25 06:24:45 +00:00
|
|
|
} CTX_DATA_END;
|
|
|
|
}
|
|
|
|
}
|
2011-07-23 18:03:01 +00:00
|
|
|
|
|
|
|
else {
|
2012-06-05 21:54:21 +00:00
|
|
|
CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
|
2012-04-30 16:22:40 +00:00
|
|
|
{
|
2010-05-19 09:40:45 +00:00
|
|
|
if (ob != ob_iter) {
|
2012-08-18 16:16:13 +00:00
|
|
|
if (type == COPY_PROPERTIES_REPLACE) {
|
2012-09-18 04:35:30 +00:00
|
|
|
BKE_bproperty_copy_list(&ob_iter->prop, &ob->prop);
|
2012-08-18 16:16:13 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* merge - the default when calling with no argument */
|
|
|
|
for (prop = ob->prop.first; prop; prop = prop->next) {
|
2012-09-18 04:35:30 +00:00
|
|
|
BKE_bproperty_object_set(ob_iter, prop);
|
2012-08-18 16:16:13 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-19 09:40:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
}
|
2010-05-25 06:24:45 +00:00
|
|
|
|
2010-05-19 09:40:45 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBJECT_OT_game_property_copy(wmOperatorType *ot)
|
|
|
|
{
|
2010-05-24 10:38:05 +00:00
|
|
|
PropertyRNA *prop;
|
2010-05-19 09:40:45 +00:00
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Copy Game Property";
|
|
|
|
ot->idname = "OBJECT_OT_game_property_copy";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Copy/merge/replace a game property from active object to all selected objects";
|
2010-05-19 09:40:45 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = game_property_copy_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2010-05-19 09:40:45 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2010-05-19 09:40:45 +00:00
|
|
|
|
2010-06-03 08:41:40 +00:00
|
|
|
RNA_def_enum(ot->srna, "operation", game_properties_copy_operations, 3, "Operation", "");
|
2012-12-22 01:08:42 +00:00
|
|
|
prop = RNA_def_enum(ot->srna, "property", DummyRNA_NULL_items, 0, "Property", "Properties to copy");
|
2014-05-05 15:22:36 +10:00
|
|
|
RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_ENUM_NO_TRANSLATE);
|
2010-05-24 10:38:05 +00:00
|
|
|
RNA_def_enum_funcs(prop, gameprops_itemf);
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->prop = prop;
|
2010-05-19 09:40:45 +00:00
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int game_property_clear_exec(bContext *C, wmOperator *UNUSED(op))
|
2010-06-03 06:41:24 +00:00
|
|
|
{
|
2012-06-05 21:54:21 +00:00
|
|
|
CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
|
2012-04-30 16:22:40 +00:00
|
|
|
{
|
2012-09-18 04:35:30 +00:00
|
|
|
BKE_bproperty_free_list(&ob_iter->prop);
|
2010-06-03 06:41:24 +00:00
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_LOGIC, NULL);
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
void OBJECT_OT_game_property_clear(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-06-14 14:02:15 +00:00
|
|
|
ot->name = "Clear Game Properties";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "OBJECT_OT_game_property_clear";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Remove all game properties from all selected objects";
|
2010-06-03 06:41:24 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = game_property_clear_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2010-06-03 06:41:24 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2010-06-03 06:41:24 +00:00
|
|
|
}
|
|
|
|
|
2010-05-19 09:40:45 +00:00
|
|
|
/************************ Copy Logic Bricks ***********************/
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int logicbricks_copy_exec(bContext *C, wmOperator *UNUSED(op))
|
2010-05-19 09:40:45 +00:00
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Object *ob = ED_object_active_context(C);
|
2010-05-19 09:40:45 +00:00
|
|
|
|
2012-06-05 21:54:21 +00:00
|
|
|
CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
|
2012-04-30 16:22:40 +00:00
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob != ob_iter) {
|
2010-10-02 14:08:09 +00:00
|
|
|
/* first: free all logic */
|
2012-10-21 05:46:41 +00:00
|
|
|
free_sensors(&ob_iter->sensors);
|
2010-10-02 14:08:09 +00:00
|
|
|
unlink_controllers(&ob_iter->controllers);
|
|
|
|
free_controllers(&ob_iter->controllers);
|
|
|
|
unlink_actuators(&ob_iter->actuators);
|
|
|
|
free_actuators(&ob_iter->actuators);
|
|
|
|
|
|
|
|
/* now copy it, this also works without logicbricks! */
|
|
|
|
clear_sca_new_poins_ob(ob);
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
copy_sensors(&ob_iter->sensors, &ob->sensors, 0);
|
|
|
|
copy_controllers(&ob_iter->controllers, &ob->controllers, 0);
|
|
|
|
copy_actuators(&ob_iter->actuators, &ob->actuators, 0);
|
2010-10-02 14:08:09 +00:00
|
|
|
set_sca_new_poins_ob(ob_iter);
|
|
|
|
|
|
|
|
/* some menu settings */
|
2012-04-28 15:42:27 +00:00
|
|
|
ob_iter->scavisflag = ob->scavisflag;
|
|
|
|
ob_iter->scaflag = ob->scaflag;
|
2010-10-02 14:08:09 +00:00
|
|
|
|
|
|
|
/* set the initial state */
|
2012-04-28 15:42:27 +00:00
|
|
|
ob_iter->state = ob->state;
|
|
|
|
ob_iter->init_state = ob->init_state;
|
2010-10-02 14:08:09 +00:00
|
|
|
|
2012-04-28 15:42:27 +00:00
|
|
|
if (ob_iter->totcol == ob->totcol) {
|
|
|
|
ob_iter->actcol = ob->actcol;
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob_iter);
|
2010-05-19 09:40:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_LOGIC, NULL);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBJECT_OT_logic_bricks_copy(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Copy Logic Bricks to Selected";
|
2011-09-19 12:26:20 +00:00
|
|
|
ot->description = "Copy logic bricks to other selected objects";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "OBJECT_OT_logic_bricks_copy";
|
2010-05-19 09:40:45 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = logicbricks_copy_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2010-05-19 09:40:45 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2010-05-19 09:40:45 +00:00
|
|
|
}
|
2011-12-21 02:41:27 +00:00
|
|
|
|
|
|
|
static int game_physics_copy_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2012-04-28 15:42:27 +00:00
|
|
|
Object *ob = ED_object_active_context(C);
|
2011-12-21 02:41:27 +00:00
|
|
|
|
2012-06-05 21:54:21 +00:00
|
|
|
CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
|
2012-04-30 16:22:40 +00:00
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob != ob_iter) {
|
2011-12-21 02:41:27 +00:00
|
|
|
ob_iter->gameflag = ob->gameflag;
|
|
|
|
ob_iter->gameflag2 = ob->gameflag2;
|
|
|
|
ob_iter->inertia = ob->inertia;
|
2012-02-25 16:04:03 +00:00
|
|
|
ob_iter->formfactor = ob->formfactor;
|
2011-12-21 02:41:27 +00:00
|
|
|
ob_iter->damping = ob->damping;
|
|
|
|
ob_iter->rdamping = ob->rdamping;
|
|
|
|
ob_iter->min_vel = ob->min_vel;
|
|
|
|
ob_iter->max_vel = ob->max_vel;
|
2015-06-23 15:02:28 +02:00
|
|
|
ob_iter->min_angvel = ob->min_angvel;
|
|
|
|
ob_iter->max_angvel = ob->max_angvel;
|
2011-12-21 02:41:27 +00:00
|
|
|
ob_iter->obstacleRad = ob->obstacleRad;
|
|
|
|
ob_iter->mass = ob->mass;
|
2013-01-28 06:56:47 +00:00
|
|
|
copy_v3_v3(ob_iter->anisotropicFriction, ob->anisotropicFriction);
|
2012-10-21 05:46:41 +00:00
|
|
|
ob_iter->collision_boundtype = ob->collision_boundtype;
|
2011-12-21 02:41:27 +00:00
|
|
|
ob_iter->margin = ob->margin;
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
ob_iter->bsoft = copy_bulletsoftbody(ob->bsoft, 0);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob->restrictflag & OB_RESTRICT_RENDER)
|
2011-12-21 02:41:27 +00:00
|
|
|
ob_iter->restrictflag |= OB_RESTRICT_RENDER;
|
2012-04-28 15:42:27 +00:00
|
|
|
else
|
2011-12-21 02:41:27 +00:00
|
|
|
ob_iter->restrictflag &= ~OB_RESTRICT_RENDER;
|
2013-01-28 06:56:47 +00:00
|
|
|
|
|
|
|
ob_iter->col_group = ob->col_group;
|
|
|
|
ob_iter->col_mask = ob->col_mask;
|
2011-12-21 02:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CTX_DATA_END;
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBJECT_OT_game_physics_copy(struct wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Copy Game Physics Properties to Selected";
|
2011-12-21 02:41:27 +00:00
|
|
|
ot->description = "Copy game physics properties to other selected objects";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "OBJECT_OT_game_physics_copy";
|
2011-12-21 02:41:27 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = game_physics_copy_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2011-12-21 02:41:27 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-04-28 15:42:27 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-12-21 02:41:27 +00:00
|
|
|
}
|
2015-02-23 23:05:54 +11:00
|
|
|
|
|
|
|
/* generic utility function */
|
|
|
|
|
|
|
|
bool ED_object_editmode_calc_active_center(Object *obedit, const bool select_only, float r_center[3])
|
|
|
|
{
|
|
|
|
switch (obedit->type) {
|
|
|
|
case OB_MESH:
|
|
|
|
{
|
|
|
|
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
|
|
|
BMEditSelection ese;
|
|
|
|
|
|
|
|
if (BM_select_history_active_get(em->bm, &ese)) {
|
|
|
|
BM_editselection_center(&ese, r_center);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_ARMATURE:
|
|
|
|
{
|
|
|
|
bArmature *arm = obedit->data;
|
|
|
|
EditBone *ebo = arm->act_edbone;
|
|
|
|
|
|
|
|
if (ebo && (!select_only || (ebo->flag & (BONE_SELECTED | BONE_ROOTSEL)))) {
|
|
|
|
copy_v3_v3(r_center, ebo->head);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_CURVE:
|
|
|
|
case OB_SURF:
|
|
|
|
{
|
|
|
|
Curve *cu = obedit->data;
|
|
|
|
|
|
|
|
if (ED_curve_active_center(cu, r_center)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_MBALL:
|
|
|
|
{
|
|
|
|
MetaBall *mb = obedit->data;
|
|
|
|
MetaElem *ml_act = mb->lastelem;
|
|
|
|
|
|
|
|
if (ml_act && (!select_only || (ml_act->flag & SELECT))) {
|
|
|
|
copy_v3_v3(r_center, &ml_act->x);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OB_LATTICE:
|
|
|
|
{
|
|
|
|
BPoint *actbp = BKE_lattice_active_point_get(obedit->data);
|
|
|
|
|
|
|
|
if (actbp) {
|
|
|
|
copy_v3_v3(r_center, actbp->vec);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-03-11 13:14:24 +11:00
|
|
|
}
|