2013-01-23 05:56:56 +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,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2013 Blender Foundation
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): Sergej Reich
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file rigidbody_constraint.c
|
|
|
|
* \ingroup editor_physics
|
|
|
|
* \brief Rigid Body constraint editing operators
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_rigidbody_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_depsgraph.h"
|
2013-02-05 12:46:15 +00:00
|
|
|
#include "BKE_global.h"
|
2013-01-23 05:56:56 +00:00
|
|
|
#include "BKE_group.h"
|
2016-06-06 14:37:15 +02:00
|
|
|
#include "BKE_main.h"
|
2013-01-23 05:56:56 +00:00
|
|
|
#include "BKE_report.h"
|
|
|
|
#include "BKE_rigidbody.h"
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
#include "RNA_enum_types.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "ED_physics.h"
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
|
|
#include "physics_intern.h"
|
|
|
|
|
|
|
|
/* ********************************************** */
|
|
|
|
/* Helper API's for RigidBody Constraint Editing */
|
|
|
|
|
|
|
|
static int ED_operator_rigidbody_con_active_poll(bContext *C)
|
|
|
|
{
|
|
|
|
if (ED_operator_object_active_editable(C)) {
|
|
|
|
Object *ob = CTX_data_active_object(C);
|
|
|
|
return (ob && ob->rigidbody_constraint);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-06 14:37:15 +02:00
|
|
|
bool ED_rigidbody_constraint_add(Main *bmain, Scene *scene, Object *ob, int type, ReportList *reports)
|
2013-01-23 05:56:56 +00:00
|
|
|
{
|
2013-01-25 06:26:38 +00:00
|
|
|
RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
|
|
|
|
|
2013-01-23 05:56:56 +00:00
|
|
|
/* check that object doesn't already have a constraint */
|
|
|
|
if (ob->rigidbody_constraint) {
|
2013-04-09 01:36:44 +00:00
|
|
|
BKE_reportf(reports, RPT_INFO, "Object '%s' already has a Rigid Body Constraint", ob->id.name + 2);
|
|
|
|
return false;
|
2013-01-23 05:56:56 +00:00
|
|
|
}
|
2013-01-25 06:26:38 +00:00
|
|
|
/* create constraint group if it doesn't already exits */
|
|
|
|
if (rbw->constraints == NULL) {
|
2016-06-06 14:37:15 +02:00
|
|
|
rbw->constraints = BKE_group_add(bmain, "RigidBodyConstraints");
|
2013-01-25 06:26:38 +00:00
|
|
|
}
|
2013-01-23 05:56:56 +00:00
|
|
|
/* make rigidbody constraint settings */
|
|
|
|
ob->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, ob, type);
|
|
|
|
ob->rigidbody_constraint->flag |= RBC_FLAG_NEEDS_VALIDATE;
|
2013-01-25 06:26:38 +00:00
|
|
|
|
|
|
|
/* add constraint to rigid body constraint group */
|
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
|
|
|
BKE_group_object_add(rbw->constraints, ob);
|
2013-02-21 19:33:04 +00:00
|
|
|
|
2016-06-06 14:37:15 +02:00
|
|
|
DAG_relations_tag_update(bmain);
|
2013-02-21 19:33:04 +00:00
|
|
|
DAG_id_tag_update(&ob->id, OB_RECALC_OB);
|
2013-04-09 01:36:44 +00:00
|
|
|
return true;
|
2013-01-23 05:56:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-06 14:37:15 +02:00
|
|
|
void ED_rigidbody_constraint_remove(Main *bmain, Scene *scene, Object *ob)
|
2013-01-23 05:56:56 +00:00
|
|
|
{
|
2013-01-25 06:26:38 +00:00
|
|
|
RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
|
|
|
|
|
2013-01-23 05:56:56 +00:00
|
|
|
BKE_rigidbody_remove_constraint(scene, ob);
|
2013-01-25 06:26:38 +00:00
|
|
|
if (rbw)
|
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
|
|
|
BKE_group_object_unlink(rbw->constraints, ob);
|
2013-01-25 06:26:38 +00:00
|
|
|
|
2016-06-06 14:37:15 +02:00
|
|
|
DAG_relations_tag_update(bmain);
|
2013-01-23 05:56:56 +00:00
|
|
|
DAG_id_tag_update(&ob->id, OB_RECALC_OB);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ********************************************** */
|
|
|
|
/* Active Object Add/Remove Operators */
|
|
|
|
|
|
|
|
/* ************ Add Rigid Body Constraint ************** */
|
|
|
|
|
|
|
|
static int rigidbody_con_add_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2016-06-06 14:37:15 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2013-01-23 05:56:56 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2017-03-02 15:03:47 +01:00
|
|
|
SceneLayer *sl = CTX_data_scene_layer(C);
|
2013-01-23 05:56:56 +00:00
|
|
|
RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
|
2017-03-02 15:03:47 +01:00
|
|
|
Object *ob = OBACT_NEW;
|
2013-01-23 05:56:56 +00:00
|
|
|
int type = RNA_enum_get(op->ptr, "type");
|
2013-11-26 06:39:14 +11:00
|
|
|
bool changed;
|
2013-01-23 05:56:56 +00:00
|
|
|
|
|
|
|
/* sanity checks */
|
|
|
|
if (ELEM(NULL, scene, rbw)) {
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "No Rigid Body World to add Rigid Body Constraint to");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
/* apply to active object */
|
2016-06-06 14:37:15 +02:00
|
|
|
changed = ED_rigidbody_constraint_add(bmain, scene, ob, type, op->reports);
|
2013-01-23 05:56:56 +00:00
|
|
|
|
2013-11-26 06:39:14 +11:00
|
|
|
if (changed) {
|
2013-04-09 01:36:44 +00:00
|
|
|
/* send updates */
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
|
2013-01-23 05:56:56 +00:00
|
|
|
|
2013-04-09 01:36:44 +00:00
|
|
|
/* done */
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2013-01-23 05:56:56 +00:00
|
|
|
}
|
|
|
|
|
2013-01-25 06:26:38 +00:00
|
|
|
void RIGIDBODY_OT_constraint_add(wmOperatorType *ot)
|
2013-01-23 05:56:56 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2013-01-25 06:26:38 +00:00
|
|
|
ot->idname = "RIGIDBODY_OT_constraint_add";
|
2013-01-23 05:56:56 +00:00
|
|
|
ot->name = "Add Rigid Body Constraint";
|
2013-01-25 06:26:38 +00:00
|
|
|
ot->description = "Add Rigid Body Constraint to active object";
|
2013-01-23 05:56:56 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2013-01-25 06:26:38 +00:00
|
|
|
ot->exec = rigidbody_con_add_exec;
|
2013-01-23 05:56:56 +00:00
|
|
|
ot->poll = ED_operator_object_active_editable;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
|
|
|
|
/* properties */
|
2015-11-23 13:49:52 +11:00
|
|
|
ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_rigidbody_constraint_type_items, RBC_TYPE_FIXED, "Rigid Body Constraint Type", "");
|
2013-01-23 05:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************ Remove Rigid Body Constraint ************** */
|
|
|
|
|
|
|
|
static int rigidbody_con_remove_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2016-06-06 14:37:15 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2013-01-23 05:56:56 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2017-03-02 15:03:47 +01:00
|
|
|
SceneLayer *sl = CTX_data_scene_layer(C);
|
|
|
|
Object *ob = OBACT_NEW;
|
2013-01-23 05:56:56 +00:00
|
|
|
|
|
|
|
/* apply to active object */
|
|
|
|
if (ELEM(NULL, ob, ob->rigidbody_constraint)) {
|
|
|
|
BKE_report(op->reports, RPT_ERROR, "Object has no Rigid Body Constraint to remove");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
else {
|
2016-06-06 14:37:15 +02:00
|
|
|
ED_rigidbody_constraint_remove(bmain, scene, ob);
|
2013-01-23 05:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send updates */
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
|
|
|
|
|
|
|
|
/* done */
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RIGIDBODY_OT_constraint_remove(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->idname = "RIGIDBODY_OT_constraint_remove";
|
|
|
|
ot->name = "Remove Rigid Body Constraint";
|
|
|
|
ot->description = "Remove Rigid Body Constraint from Object";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->exec = rigidbody_con_remove_exec;
|
|
|
|
ot->poll = ED_operator_rigidbody_con_active_poll;
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
|
|
|
}
|