2.5: Object module

* Split object_edit.c into multiple files:
  object_add.c, object_edit.c, object_hook.c, object_relations.c,
  object_select.c, object_transform.c.
* Rename files to have consistent object_ and mball_ prefix:
  object_shapekey.c, object_lattice.c, object_vgroup.c, mball_edit.c.
* Added operators:
  * vertex group menu and set active
  * apply location, rotation, scale, visual transform (location is new)
  * make local
  * make vertex parent
  * move to layer
  * convert to curve/mesh (not finished yet)
* Many small fixes for marked issues, but still much code to be cleaned
  up here...
This commit is contained in:
2009-09-09 11:52:56 +00:00
parent 8878c30b9b
commit 3daa283604
38 changed files with 6844 additions and 6450 deletions

View File

@@ -1075,19 +1075,19 @@
Name="object"
>
<File
RelativePath="..\..\..\source\blender\editors\object\editconstraint.c"
RelativePath="..\..\..\source\blender\editors\object\object_constraint.c"
>
</File>
<File
RelativePath="..\..\..\source\blender\editors\object\editgroup.c"
RelativePath="..\..\..\source\blender\editors\object\object_group.c"
>
</File>
<File
RelativePath="..\..\..\source\blender\editors\object\editkey.c"
RelativePath="..\..\..\source\blender\editors\object\object_shapekey.c"
>
</File>
<File
RelativePath="..\..\..\source\blender\editors\object\editlattice.c"
RelativePath="..\..\..\source\blender\editors\object\object_lattice.c"
>
</File>
<File
@@ -1110,6 +1110,10 @@
RelativePath="..\..\..\source\blender\editors\object\object_vgroup.c"
>
</File>
<File
RelativePath="..\..\..\source\blender\editors\object\object_hook.c"
>
</File>
</Filter>
<Filter
Name="transform"
@@ -1479,7 +1483,7 @@
Name="metaball"
>
<File
RelativePath="..\..\..\source\blender\editors\metaball\editmball.c"
RelativePath="..\..\..\source\blender\editors\metaball\mball_edit.c"
>
</File>
<File

View File

@@ -117,22 +117,22 @@ class INFO_MT_add(bpy.types.Menu):
layout.operator_context = "EXEC_SCREEN"
layout.item_menu_enumO( "object.mesh_add", "type", text="Mesh", icon='ICON_OUTLINER_OB_MESH')
layout.item_menu_enumO( "object.curve_add", "type", text="Curve", icon='ICON_OUTLINER_OB_CURVE')
layout.item_menu_enumO( "object.surface_add", "type", text="Surface", icon='ICON_OUTLINER_OB_SURFACE')
layout.item_menu_enumO( "object.metaball_add", "type", 'META', icon='ICON_OUTLINER_OB_META')
layout.item_menu_enumO("object.mesh_add", "type", text="Mesh", icon='ICON_OUTLINER_OB_MESH')
layout.item_menu_enumO("object.curve_add", "type", text="Curve", icon='ICON_OUTLINER_OB_CURVE')
layout.item_menu_enumO("object.surface_add", "type", text="Surface", icon='ICON_OUTLINER_OB_SURFACE')
layout.item_menu_enumO("object.metaball_add", "type", 'META', icon='ICON_OUTLINER_OB_META')
layout.itemO("object.text_add", text="Text", icon='ICON_OUTLINER_OB_FONT')
layout.itemS()
layout.itemO("object.armature_add", text="Armature", icon='ICON_OUTLINER_OB_ARMATURE')
layout.item_enumO("object.object_add", "type", 'LATTICE', icon='ICON_OUTLINER_OB_LATTICE')
layout.item_enumO("object.object_add", "type", 'EMPTY', icon='ICON_OUTLINER_OB_EMPTY')
layout.item_enumO("object.add", "type", 'LATTICE', icon='ICON_OUTLINER_OB_LATTICE')
layout.item_enumO("object.add", "type", 'EMPTY', icon='ICON_OUTLINER_OB_EMPTY')
layout.itemS()
layout.item_enumO("object.object_add", "type", 'CAMERA', icon='ICON_OUTLINER_OB_CAMERA')
layout.item_enumO("object.object_add", "type", 'LAMP', icon='ICON_OUTLINER_OB_LAMP')
layout.item_enumO("object.add", "type", 'CAMERA', icon='ICON_OUTLINER_OB_CAMERA')
layout.item_enumO("object.add", "type", 'LAMP', icon='ICON_OUTLINER_OB_LAMP')
class INFO_MT_game(bpy.types.Menu):
__space_type__ = 'INFO'

View File

@@ -55,6 +55,9 @@ void BKE_free_animdata(struct ID *id);
/* Copy AnimData */
struct AnimData *BKE_copy_animdata(struct AnimData *adt);
/* Make Local */
void BKE_animdata_make_local(struct AnimData *adt);
/* ************************************* */
/* KeyingSets API */

View File

@@ -204,6 +204,32 @@ AnimData *BKE_copy_animdata (AnimData *adt)
return dadt;
}
/* Make Local -------------------------------------------- */
static void make_local_strips(ListBase *strips)
{
NlaStrip *strip;
for(strip=strips->first; strip; strip=strip->next) {
if(strip->act) make_local_action(strip->act);
if(strip->remap && strip->remap->target) make_local_action(strip->remap->target);
make_local_strips(&strip->strips);
}
}
void BKE_animdata_make_local(AnimData *adt)
{
NlaTrack *nlt;
if(adt->action) make_local_action(adt->action);
if(adt->tmpact) make_local_action(adt->tmpact);
if(adt->remap && adt->remap->target) make_local_action(adt->remap->target);
for(nlt=adt->nla_tracks.first; nlt; nlt=nlt->next)
make_local_strips(&nlt->strips);
}
/* *********************************** */
/* KeyingSet API */

View File

@@ -194,7 +194,10 @@ int id_make_local(ID *id, int test)
case ID_WV:
return 0; /* deprecated */
case ID_LT:
if(!test) make_local_lattice((Lattice*)id);
if(!test) {
make_local_lattice((Lattice*)id);
make_local_key(((Lattice*)id)->key);
}
return 1;
case ID_LA:
if(!test) make_local_lamp((Lamp*)id);

View File

@@ -77,11 +77,6 @@
#include "BLI_winstuff.h"
/* for duplicate_defgroup */
#if !(defined vsnprintf)
#define vsnprintf _vsnprintf
#endif
#endif

View File

@@ -239,7 +239,7 @@ static void fix_bonelist_roll (ListBase *bonelist, ListBase *editbonelist)
}
/* put EditMode back in Object */
void ED_armature_from_edit(Scene *scene, Object *obedit)
void ED_armature_from_edit(Object *obedit)
{
bArmature *arm= obedit->data;
EditBone *eBone, *neBone;
@@ -343,21 +343,19 @@ void ED_armature_from_edit(Scene *scene, Object *obedit)
DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
}
void apply_rot_armature (Scene *scene, Object *ob, float mat[3][3])
void ED_armature_apply_transform(Object *ob, float mat[4][4])
{
EditBone *ebone;
bArmature *arm= ob->data;
float scale = Mat3ToScalef(mat); /* store the scale of the matrix here to use on envelopes */
float scale = Mat4ToScalef(mat); /* store the scale of the matrix here to use on envelopes */
/* Put the armature into editmode */
ED_armature_to_edit(ob);
/* Do the rotations */
for (ebone = arm->edbo->first; ebone; ebone=ebone->next){
Mat3MulVecfl(mat, ebone->head);
Mat3MulVecfl(mat, ebone->tail);
Mat4MulVecfl(mat, ebone->head);
Mat4MulVecfl(mat, ebone->tail);
ebone->rad_head *= scale;
ebone->rad_tail *= scale;
@@ -365,7 +363,7 @@ void apply_rot_armature (Scene *scene, Object *ob, float mat[3][3])
}
/* Turn the list into an armature */
ED_armature_from_edit(scene, ob);
ED_armature_from_edit(ob);
ED_armature_edit_free(ob);
}
@@ -411,7 +409,7 @@ void docenter_armature (Scene *scene, View3D *v3d, Object *ob, int centermode)
}
/* Turn the list into an armature */
ED_armature_from_edit(scene, ob);
ED_armature_from_edit(ob);
/* Adjust object location for new centerpoint */
if(centermode && obedit==NULL) {
@@ -557,7 +555,7 @@ static int apply_armature_pose2bones_exec (bContext *C, wmOperator *op)
}
/* convert editbones back to bones */
ED_armature_from_edit(scene, ob);
ED_armature_from_edit(ob);
/* flush positions of posebones */
where_is_pose(scene, ob);
@@ -791,7 +789,7 @@ int join_armature_exec(bContext *C, wmOperator *op)
DAG_scene_sort(scene); // because we removed object(s)
ED_armature_from_edit(scene, ob);
ED_armature_from_edit(ob);
ED_armature_edit_free(ob);
WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
@@ -994,7 +992,7 @@ static void separate_armature_bones (Scene *scene, Object *ob, short sel)
}
/* exit editmode (recalculates pchans too) */
ED_armature_from_edit(scene, ob);
ED_armature_from_edit(ob);
ED_armature_edit_free(ob);
}
@@ -1037,7 +1035,7 @@ static int separate_armature_exec (bContext *C, wmOperator *op)
oldob->mode &= ~OB_MODE_POSE;
//oldbase->flag &= ~OB_POSEMODE;
ED_armature_from_edit(scene, obedit);
ED_armature_from_edit(obedit);
ED_armature_edit_free(obedit);
/* 2) duplicate base */
@@ -4334,7 +4332,7 @@ int ED_do_pose_selectbuffer(Scene *scene, Base *base, unsigned int *buffer, shor
/* in weightpaint we select the associated vertex group too */
if (ob->mode & OB_MODE_WEIGHT_PAINT) {
if (nearBone->flag & BONE_ACTIVE) {
vertexgroup_select_by_name(OBACT, nearBone->name);
ED_vgroup_select_by_name(OBACT, nearBone->name);
DAG_id_flush_update(&OBACT->id, OB_RECALC_DATA);
}
}
@@ -4445,7 +4443,7 @@ static int bone_skinnable(Object *ob, Bone *bone, void *datap)
return 0;
}
static int add_defgroup_unique_bone(Object *ob, Bone *bone, void *data)
static int ED_vgroup_add_unique_bone(Object *ob, Bone *bone, void *data)
{
/* This group creates a vertex group to ob that has the
* same name as bone (provided the bone is skinnable).
@@ -4453,7 +4451,7 @@ static int add_defgroup_unique_bone(Object *ob, Bone *bone, void *data)
*/
if (!(bone->flag & BONE_NO_DEFORM)) {
if (!get_named_vertexgroup(ob,bone->name)) {
add_defgroup_name(ob, bone->name);
ED_vgroup_add_name(ob, bone->name);
return 1;
}
}
@@ -4497,7 +4495,7 @@ static int dgroup_skinnable(Object *ob, Bone *bone, void *datap)
segments = 1;
if (!(defgroup = get_named_vertexgroup(ob, bone->name)))
defgroup = add_defgroup_name(ob, bone->name);
defgroup = ED_vgroup_add_name(ob, bone->name);
if (data->list != NULL) {
hgroup = (bDeformGroup ***) &data->list;
@@ -4548,17 +4546,17 @@ static void envelope_bone_weighting(Object *ob, Mesh *mesh, float (*verts)[3], i
/* add the vert to the deform group if weight!=0.0 */
if (distance!=0.0)
add_vert_to_defgroup (ob, dgroup, i, distance, WEIGHT_REPLACE);
ED_vgroup_vert_add (ob, dgroup, i, distance, WEIGHT_REPLACE);
else
remove_vert_defgroup (ob, dgroup, i);
ED_vgroup_vert_remove (ob, dgroup, i);
/* do same for mirror */
if (dgroupflip && dgroupflip[j] && iflip >= 0) {
if (distance!=0.0)
add_vert_to_defgroup (ob, dgroupflip[j], iflip, distance,
ED_vgroup_vert_add (ob, dgroupflip[j], iflip, distance,
WEIGHT_REPLACE);
else
remove_vert_defgroup (ob, dgroupflip[j], iflip);
ED_vgroup_vert_remove (ob, dgroupflip[j], iflip);
}
}
}
@@ -4748,10 +4746,10 @@ void create_vgroups_from_armature(Scene *scene, Object *ob, Object *par, int mod
/* Traverse the bone list, trying to create empty vertex
* groups cooresponding to the bone.
*/
bone_looper(ob, arm->bonebase.first, NULL, add_defgroup_unique_bone);
bone_looper(ob, arm->bonebase.first, NULL, ED_vgroup_add_unique_bone);
if (ob->type == OB_MESH)
create_dverts(ob->data);
ED_vgroup_data_create(ob->data);
}
else if(mode == ARM_GROUPS_ENVELOPE || mode == ARM_GROUPS_AUTO) {
/* Traverse the bone list, trying to create vertex groups
@@ -5659,7 +5657,7 @@ void generateSkeletonFromReebGraph(Scene *scene, ReebGraph *rg)
if (obedit != NULL)
{
ED_armature_from_edit(scene, obedit);
ED_armature_from_edit(obedit);
ED_armature_edit_free(obedit);
}

View File

@@ -2732,7 +2732,7 @@ static void adjustGraphs(bContext *C, RigGraph *rigg)
/* Turn the list into an armature */
arm->edbo = rigg->editbones;
ED_armature_from_edit(scene, rigg->ob);
ED_armature_from_edit(rigg->ob);
ED_undo_push(C, "Retarget Skeleton");
}
@@ -2762,7 +2762,7 @@ static void retargetGraphs(bContext *C, RigGraph *rigg)
/* Turn the list into an armature */
arm->edbo = rigg->editbones;
ED_armature_from_edit(scene, rigg->ob);
ED_armature_from_edit(rigg->ob);
}
char *RIG_nameBone(RigGraph *rg, int arc_index, int bone_index)

View File

@@ -672,9 +672,9 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numbones,
/* clear weights */
if(bbone && firstsegment) {
for(a=0; a<me->totvert; a++) {
remove_vert_defgroup(ob, dgrouplist[j], a);
ED_vgroup_vert_remove(ob, dgrouplist[j], a);
if(vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0)
remove_vert_defgroup(ob, dgroupflip[j], vertsflipped[a]);
ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]);
}
}
@@ -694,32 +694,32 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numbones,
if(bbone) {
if(solution > 0.0f)
add_vert_to_defgroup(ob, dgrouplist[j], a, solution,
ED_vgroup_vert_add(ob, dgrouplist[j], a, solution,
WEIGHT_ADD);
}
else {
weight= heat_limit_weight(solution);
if(weight > 0.0f)
add_vert_to_defgroup(ob, dgrouplist[j], a, weight,
ED_vgroup_vert_add(ob, dgrouplist[j], a, weight,
WEIGHT_REPLACE);
else
remove_vert_defgroup(ob, dgrouplist[j], a);
ED_vgroup_vert_remove(ob, dgrouplist[j], a);
}
/* do same for mirror */
if(vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) {
if(bbone) {
if(solution > 0.0f)
add_vert_to_defgroup(ob, dgroupflip[j], vertsflipped[a],
ED_vgroup_vert_add(ob, dgroupflip[j], vertsflipped[a],
solution, WEIGHT_ADD);
}
else {
weight= heat_limit_weight(solution);
if(weight > 0.0f)
add_vert_to_defgroup(ob, dgroupflip[j], vertsflipped[a],
ED_vgroup_vert_add(ob, dgroupflip[j], vertsflipped[a],
weight, WEIGHT_REPLACE);
else
remove_vert_defgroup(ob, dgroupflip[j], vertsflipped[a]);
ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]);
}
}
}
@@ -734,16 +734,16 @@ void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numbones,
/* remove too small vertex weights */
if(bbone && lastsegment) {
for(a=0; a<me->totvert; a++) {
weight= get_vert_defgroup(ob, dgrouplist[j], a);
weight= ED_vgroup_vert_weight(ob, dgrouplist[j], a);
weight= heat_limit_weight(weight);
if(weight <= 0.0f)
remove_vert_defgroup(ob, dgrouplist[j], a);
ED_vgroup_vert_remove(ob, dgrouplist[j], a);
if(vertsflipped && dgroupflip[j] && vertsflipped[a] >= 0) {
weight= get_vert_defgroup(ob, dgroupflip[j], vertsflipped[a]);
weight= ED_vgroup_vert_weight(ob, dgroupflip[j], vertsflipped[a]);
weight= heat_limit_weight(weight);
if(weight <= 0.0f)
remove_vert_defgroup(ob, dgroupflip[j], vertsflipped[a]);
ED_vgroup_vert_remove(ob, dgroupflip[j], vertsflipped[a]);
}
}
}

View File

@@ -1673,7 +1673,7 @@ void pose_activate_flipped_bone(Scene *scene)
/* in weightpaint we select the associated vertex group too */
if(ob->mode & OB_MODE_WEIGHT_PAINT) {
vertexgroup_select_by_name(OBACT, name);
ED_vgroup_select_by_name(OBACT, name);
DAG_id_flush_update(&OBACT->id, OB_RECALC_DATA);
}

View File

@@ -95,7 +95,7 @@ void ED_operatortypes_armature(void);
void ED_keymap_armature(struct wmWindowManager *wm);
/* editarmature.c */
void ED_armature_from_edit(struct Scene *scene, struct Object *obedit);
void ED_armature_from_edit(struct Object *obedit);
void ED_armature_to_edit(struct Object *ob);
void ED_armature_edit_free(struct Object *ob);
void ED_armature_edit_remake(struct Object *obedit);
@@ -116,6 +116,8 @@ void transform_armature_mirror_update(struct Object *obedit);
void clear_armature(struct Scene *scene, struct Object *ob, char mode);
void docenter_armature (struct Scene *scene, struct View3D *v3d, struct Object *ob, int centermode);
void ED_armature_apply_transform(struct Object *ob, float mat[4][4]);
#define ARM_GROUPS_NAME 1
#define ARM_GROUPS_ENVELOPE 2
#define ARM_GROUPS_AUTO 3

View File

@@ -26,6 +26,10 @@
* ***** END GPL LICENSE BLOCK *****
*/
struct bContext;
struct Object;
struct wmWindowManager;
void ED_operatortypes_metaball(void);
void ED_keymap_metaball(struct wmWindowManager *wm);
@@ -37,3 +41,5 @@ void free_editMball(struct Object *obedit);
void make_editMball(struct Object *obedit);
void load_editMball(struct Object *obedit);
void undo_push_mball(struct bContext *C, char *name);

View File

@@ -157,25 +157,23 @@ void EM_deselect_by_material(struct EditMesh *em, int index);
/* editface.c */
struct MTFace *EM_get_active_mtface(struct EditMesh *em, struct EditFace **act_efa, struct MCol **mcol, int sloppy);
/* editdeform.c XXX rename functions? */
/* object_vgroup.c */
#define WEIGHT_REPLACE 1
#define WEIGHT_ADD 2
#define WEIGHT_SUBTRACT 3
void add_defgroup (Object *ob);
void create_dverts(struct ID *id);
float get_vert_defgroup (Object *ob, struct bDeformGroup *dg, int vertnum);
void remove_vert_defgroup (Object *ob, struct bDeformGroup *dg, int vertnum);
void remove_verts_defgroup (Object *obedit, int allverts);
void vertexgroup_select_by_name(Object *ob, char *name);
void add_vert_to_defgroup (Object *ob, struct bDeformGroup *dg, int vertnum,
float weight, int assignmode);
struct bDeformGroup *ED_vgroup_add(struct Object *ob);
struct bDeformGroup *ED_vgroup_add_name(struct Object *ob, char *name);
void ED_vgroup_select_by_name(struct Object *ob, char *name);
void ED_vgroup_data_create(struct ID *id);
struct bDeformGroup *add_defgroup_name (Object *ob, char *name);
struct MDeformWeight *verify_defweight (struct MDeformVert *dv, int defgroup);
struct MDeformWeight *get_defweight (struct MDeformVert *dv, int defgroup);
void ED_vgroup_vert_add(struct Object *ob, struct bDeformGroup *dg, int vertnum, float weight, int assignmode);
void ED_vgroup_vert_remove(struct Object *ob, struct bDeformGroup *dg, int vertnum);
float ED_vgroup_vert_weight(struct Object *ob, struct bDeformGroup *dg, int vertnum);
struct MDeformWeight *ED_vgroup_weight_verify(struct MDeformVert *dv, int defgroup);
struct MDeformWeight *ED_vgroup_weight_get(struct MDeformVert *dv, int defgroup);
#endif /* ED_MESH_H */

View File

@@ -89,14 +89,11 @@ void object_test_constraints(struct Object *ob);
void ED_object_constraint_rename(struct Object *ob, struct bConstraint *con, char *oldname);
void ED_object_constraint_set_active(struct Object *ob, struct bConstraint *con);
/* editlattice.c */
/* object_lattice.c */
void mouse_lattice(struct bContext *C, short mval[2], int extend);
void undo_push_lattice(struct bContext *C, char *name);
/* editmball.c */
void undo_push_mball(struct bContext *C, char *name);
/* editkey.c */
/* object_shapekey.c */
void insert_shapekey(struct Scene *scene, struct Object *ob);
void delete_key(struct Scene *scene, struct Object *ob);
void key_to_mesh(struct KeyBlock *kb, struct Mesh *me);

File diff suppressed because it is too large Load Diff

View File

@@ -76,9 +76,6 @@
#include "object_intern.h"
/* XXX */
static int pupmenu() {return 0;}
/* -------------- Get Active Constraint Data ---------------------- */
/* if object in posemode, active bone constraints, else object constraints */
@@ -1107,7 +1104,7 @@ static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase
#ifndef DISABLE_PYTHON
/* popup a list of usable scripts */
menustr = buildmenu_pyconstraints(NULL, &scriptint);
scriptint = pupmenu(menustr);
// XXX scriptint = pupmenu(menustr);
MEM_freeN(menustr);
/* only add constraint if a script was chosen */
@@ -1416,3 +1413,4 @@ void POSE_OT_ik_clear(wmOperatorType *ot)
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}

File diff suppressed because it is too large Load Diff

View File

@@ -32,28 +32,20 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "DNA_group_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_view3d_types.h"
#include "BKE_depsgraph.h"
#include "BKE_group.h"
#include "BKE_global.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_group.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "ED_view3d.h"
#include "ED_space_api.h"
#include "ED_screen.h"
#include "ED_types.h"
#include "ED_util.h"
#include "UI_interface.h"
#include "UI_resources.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -63,6 +55,8 @@
#include "object_intern.h"
/********************* 3d view operators ***********************/
static int objects_add_active_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
@@ -70,13 +64,12 @@ static int objects_add_active_exec(bContext *C, wmOperator *op)
Group *group;
int ok = 0;
if (!ob) return OPERATOR_CANCELLED;
if(!ob) return OPERATOR_CANCELLED;
/* linking to same group requires its own loop so we can avoid
looking up the active objects groups each time */
group= G.main->group.first;
while(group) {
for(group= G.main->group.first; group; group=group->id.next) {
if(object_in_group(ob, group)) {
/* Assign groups to selected objects */
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
@@ -89,22 +82,18 @@ static int objects_add_active_exec(bContext *C, wmOperator *op)
}
CTX_DATA_END;
}
group= group->id.next;
}
if (!ok) BKE_report(op->reports, RPT_ERROR, "Active Object contains no groups");
if(!ok) BKE_report(op->reports, RPT_ERROR, "Active Object contains no groups");
DAG_scene_sort(CTX_data_scene(C));
DAG_scene_sort(scene);
WM_event_add_notifier(C, NC_GROUP|NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void GROUP_OT_objects_add_active(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Add Selected To Active Group";
ot->description = "Add the object to an object group that contains the active object.";
@@ -125,13 +114,12 @@ static int objects_remove_active_exec(bContext *C, wmOperator *op)
Group *group;
int ok = 0;
if (!ob) return OPERATOR_CANCELLED;
if(!ob) return OPERATOR_CANCELLED;
/* linking to same group requires its own loop so we can avoid
looking up the active objects groups each time */
group= G.main->group.first;
while(group) {
for(group= G.main->group.first; group; group=group->id.next) {
if(object_in_group(ob, group)) {
/* Assign groups to selected objects */
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
@@ -144,22 +132,18 @@ static int objects_remove_active_exec(bContext *C, wmOperator *op)
}
CTX_DATA_END;
}
group= group->id.next;
}
if (!ok) BKE_report(op->reports, RPT_ERROR, "Active Object contains no groups");
if(!ok) BKE_report(op->reports, RPT_ERROR, "Active Object contains no groups");
DAG_scene_sort(CTX_data_scene(C));
DAG_scene_sort(scene);
WM_event_add_notifier(C, NC_GROUP|NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void GROUP_OT_objects_remove_active(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Remove Selected From Active Group";
ot->description = "Remove the object from an object group that contains the active object.";
@@ -173,39 +157,37 @@ void GROUP_OT_objects_remove_active(wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
static int group_remove_exec(bContext *C, wmOperator *op)
static int group_objects_remove_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
Group *group= NULL;
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
group = NULL;
while( (group = find_group(base->object, group)) ) {
while((group = find_group(base->object, group)))
rem_from_group(group, base->object);
}
base->object->flag &= ~OB_FROMGROUP;
base->flag &= ~OB_FROMGROUP;
base->object->recalc= OB_RECALC_OB;
}
CTX_DATA_END;
DAG_scene_sort(CTX_data_scene(C));
DAG_scene_sort(scene);
WM_event_add_notifier(C, NC_GROUP|NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void GROUP_OT_objects_remove(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Remove From Groups";
ot->description = "Remove selected objects from all groups.";
ot->idname= "GROUP_OT_objects_remove";
/* api callbacks */
ot->exec= group_remove_exec;
ot->exec= group_objects_remove_exec;
ot->poll= ED_operator_scene_editable;
/* flags */
@@ -214,6 +196,7 @@ void GROUP_OT_objects_remove(wmOperatorType *ot)
static int group_create_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
Group *group= NULL;
char gid[32]; //group id
@@ -229,17 +212,14 @@ static int group_create_exec(bContext *C, wmOperator *op)
}
CTX_DATA_END;
DAG_scene_sort(CTX_data_scene(C));
DAG_scene_sort(scene);
WM_event_add_notifier(C, NC_GROUP|NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void GROUP_OT_group_create(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Create New Group";
ot->description = "Create an object group.";
@@ -255,3 +235,130 @@ void GROUP_OT_group_create(wmOperatorType *ot)
RNA_def_string(ot->srna, "GID", "Group", 32, "Name", "Name of the new group");
}
/****************** properties window operators *********************/
static int group_add_exec(bContext *C, wmOperator *op)
{
Main *bmain= CTX_data_main(C);
Scene *scene= CTX_data_scene(C);
Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
Base *base;
Group *group;
int value= RNA_enum_get(op->ptr, "group");
if(!ob)
return OPERATOR_CANCELLED;
base= object_in_scene(ob, scene);
if(!base)
return OPERATOR_CANCELLED;
if(value == -1)
group= add_group( "Group" );
else
group= BLI_findlink(&bmain->group, value);
if(group) {
add_to_group(group, ob);
ob->flag |= OB_FROMGROUP;
base->flag |= OB_FROMGROUP;
}
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
return OPERATOR_FINISHED;
}
static EnumPropertyItem group_items[]= {
{-1, "ADD_NEW", 0, "Add New Group", ""},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem *group_itemf(bContext *C, PointerRNA *ptr, int *free)
{
EnumPropertyItem tmp = {0, "", 0, "", ""};
EnumPropertyItem *item= NULL;
Main *bmain;
Group *group;
int a, totitem= 0;
if(!C) /* needed for docs */
return group_items;
RNA_enum_items_add_value(&item, &totitem, group_items, -1);
bmain= CTX_data_main(C);
if(bmain->group.first)
RNA_enum_item_add_separator(&item, &totitem);
for(a=0, group=bmain->group.first; group; group=group->id.next, a++) {
tmp.value= a;
tmp.identifier= group->id.name+2;
tmp.name= group->id.name+2;
RNA_enum_item_add(&item, &totitem, &tmp);
}
RNA_enum_item_end(&item, &totitem);
*free= 1;
return item;
}
void OBJECT_OT_group_add(wmOperatorType *ot)
{
PropertyRNA *prop;
/* identifiers */
ot->name= "Add Group";
ot->idname= "OBJECT_OT_group_add";
/* api callbacks */
ot->exec= group_add_exec;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* properties */
prop= RNA_def_enum(ot->srna, "group", group_items, -1, "Group", "Group to add object to.");
RNA_def_enum_funcs(prop, group_itemf);
}
static int group_remove_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
Group *group= CTX_data_pointer_get_type(C, "group", &RNA_Group).data;
Base *base;
if(!ob || !group)
return OPERATOR_CANCELLED;
base= object_in_scene(ob, scene);
if(!base)
return OPERATOR_CANCELLED;
rem_from_group(group, ob);
if(find_group(ob, NULL) == NULL) {
ob->flag &= ~OB_FROMGROUP;
base->flag &= ~OB_FROMGROUP;
}
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
return OPERATOR_FINISHED;
}
void OBJECT_OT_group_remove(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Remove Group";
ot->idname= "OBJECT_OT_group_remove";
/* api callbacks */
ot->exec= group_remove_exec;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}

View File

@@ -0,0 +1,608 @@
/**
* $Id$
*
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* 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 *****
*/
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_arithb.h"
#include "BLI_editVert.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "DNA_curve_types.h"
#include "DNA_lattice_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_view3d_types.h"
#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_object.h"
#include "ED_curve.h"
#include "ED_mesh.h"
#include "ED_object.h"
#include "ED_view3d.h"
#include "object_intern.h"
/* XXX operators for this are not implemented yet */
static int return_editmesh_indexar(EditMesh *em, int *tot, int **indexar, float *cent)
{
EditVert *eve;
int *index, nr, totvert=0;
for(eve= em->verts.first; eve; eve= eve->next) {
if(eve->f & SELECT) totvert++;
}
if(totvert==0) return 0;
*indexar= index= MEM_mallocN(4*totvert, "hook indexar");
*tot= totvert;
nr= 0;
cent[0]= cent[1]= cent[2]= 0.0;
for(eve= em->verts.first; eve; eve= eve->next) {
if(eve->f & SELECT) {
*index= nr; index++;
VecAddf(cent, cent, eve->co);
}
nr++;
}
VecMulf(cent, 1.0f/(float)totvert);
return totvert;
}
static int return_editmesh_vgroup(Object *obedit, EditMesh *em, char *name, float *cent)
{
MDeformVert *dvert;
EditVert *eve;
int i, totvert=0;
cent[0]= cent[1]= cent[2]= 0.0;
if(obedit->actdef) {
/* find the vertices */
for(eve= em->verts.first; eve; eve= eve->next) {
dvert= CustomData_em_get(&em->vdata, eve->data, CD_MDEFORMVERT);
if(dvert) {
for(i=0; i<dvert->totweight; i++){
if(dvert->dw[i].def_nr == (obedit->actdef-1)) {
totvert++;
VecAddf(cent, cent, eve->co);
}
}
}
}
if(totvert) {
bDeformGroup *defGroup = BLI_findlink(&obedit->defbase, obedit->actdef-1);
strcpy(name, defGroup->name);
VecMulf(cent, 1.0f/(float)totvert);
return 1;
}
}
return 0;
}
static void select_editmesh_hook(Object *ob, HookModifierData *hmd)
{
Mesh *me= ob->data;
EditMesh *em= BKE_mesh_get_editmesh(me);
EditVert *eve;
int index=0, nr=0;
if (hmd->indexar == NULL)
return;
for(eve= em->verts.first; eve; eve= eve->next, nr++) {
if(nr==hmd->indexar[index]) {
eve->f |= SELECT;
if(index < hmd->totindex-1) index++;
}
}
EM_select_flush(em);
BKE_mesh_end_editmesh(me, em);
}
static int return_editlattice_indexar(Lattice *editlatt, int *tot, int **indexar, float *cent)
{
BPoint *bp;
int *index, nr, totvert=0, a;
/* count */
a= editlatt->pntsu*editlatt->pntsv*editlatt->pntsw;
bp= editlatt->def;
while(a--) {
if(bp->f1 & SELECT) {
if(bp->hide==0) totvert++;
}
bp++;
}
if(totvert==0) return 0;
*indexar= index= MEM_mallocN(4*totvert, "hook indexar");
*tot= totvert;
nr= 0;
cent[0]= cent[1]= cent[2]= 0.0;
a= editlatt->pntsu*editlatt->pntsv*editlatt->pntsw;
bp= editlatt->def;
while(a--) {
if(bp->f1 & SELECT) {
if(bp->hide==0) {
*index= nr; index++;
VecAddf(cent, cent, bp->vec);
}
}
bp++;
nr++;
}
VecMulf(cent, 1.0f/(float)totvert);
return totvert;
}
static void select_editlattice_hook(Object *obedit, HookModifierData *hmd)
{
Lattice *lt= obedit->data;
BPoint *bp;
int index=0, nr=0, a;
/* count */
a= lt->editlatt->pntsu*lt->editlatt->pntsv*lt->editlatt->pntsw;
bp= lt->editlatt->def;
while(a--) {
if(hmd->indexar[index]==nr) {
bp->f1 |= SELECT;
if(index < hmd->totindex-1) index++;
}
nr++;
bp++;
}
}
static int return_editcurve_indexar(Object *obedit, int *tot, int **indexar, float *cent)
{
ListBase *editnurb= curve_get_editcurve(obedit);
Nurb *nu;
BPoint *bp;
BezTriple *bezt;
int *index, a, nr, totvert=0;
for(nu= editnurb->first; nu; nu= nu->next) {
if(nu->type == CU_BEZIER) {
bezt= nu->bezt;
a= nu->pntsu;
while(a--) {
if(bezt->f1 & SELECT) totvert++;
if(bezt->f2 & SELECT) totvert++;
if(bezt->f3 & SELECT) totvert++;
bezt++;
}
}
else {
bp= nu->bp;
a= nu->pntsu*nu->pntsv;
while(a--) {
if(bp->f1 & SELECT) totvert++;
bp++;
}
}
}
if(totvert==0) return 0;
*indexar= index= MEM_mallocN(4*totvert, "hook indexar");
*tot= totvert;
nr= 0;
cent[0]= cent[1]= cent[2]= 0.0;
for(nu= editnurb->first; nu; nu= nu->next) {
if(nu->type == CU_BEZIER) {
bezt= nu->bezt;
a= nu->pntsu;
while(a--) {
if(bezt->f1 & SELECT) {
*index= nr; index++;
VecAddf(cent, cent, bezt->vec[0]);
}
nr++;
if(bezt->f2 & SELECT) {
*index= nr; index++;
VecAddf(cent, cent, bezt->vec[1]);
}
nr++;
if(bezt->f3 & SELECT) {
*index= nr; index++;
VecAddf(cent, cent, bezt->vec[2]);
}
nr++;
bezt++;
}
}
else {
bp= nu->bp;
a= nu->pntsu*nu->pntsv;
while(a--) {
if(bp->f1 & SELECT) {
*index= nr; index++;
VecAddf(cent, cent, bp->vec);
}
nr++;
bp++;
}
}
}
VecMulf(cent, 1.0f/(float)totvert);
return totvert;
}
int object_hook_index_array(Object *obedit, int *tot, int **indexar, char *name, float *cent_r)
{
*indexar= NULL;
*tot= 0;
name[0]= 0;
switch(obedit->type) {
case OB_MESH:
{
Mesh *me= obedit->data;
EditMesh *em = BKE_mesh_get_editmesh(me);
/* check selected vertices first */
if( return_editmesh_indexar(em, tot, indexar, cent_r)) {
BKE_mesh_end_editmesh(me, em);
return 1;
} else {
int ret = return_editmesh_vgroup(obedit, em, name, cent_r);
BKE_mesh_end_editmesh(me, em);
return ret;
}
}
case OB_CURVE:
case OB_SURF:
return return_editcurve_indexar(obedit, tot, indexar, cent_r);
case OB_LATTICE:
{
Lattice *lt= obedit->data;
return return_editlattice_indexar(lt->editlatt, tot, indexar, cent_r);
}
default:
return 0;
}
}
static void select_editcurve_hook(Object *obedit, HookModifierData *hmd)
{
ListBase *editnurb= curve_get_editcurve(obedit);
Nurb *nu;
BPoint *bp;
BezTriple *bezt;
int index=0, a, nr=0;
for(nu= editnurb->first; nu; nu= nu->next) {
if(nu->type == CU_BEZIER) {
bezt= nu->bezt;
a= nu->pntsu;
while(a--) {
if(nr == hmd->indexar[index]) {
bezt->f1 |= SELECT;
if(index<hmd->totindex-1) index++;
}
nr++;
if(nr == hmd->indexar[index]) {
bezt->f2 |= SELECT;
if(index<hmd->totindex-1) index++;
}
nr++;
if(nr == hmd->indexar[index]) {
bezt->f3 |= SELECT;
if(index<hmd->totindex-1) index++;
}
nr++;
bezt++;
}
}
else {
bp= nu->bp;
a= nu->pntsu*nu->pntsv;
while(a--) {
if(nr == hmd->indexar[index]) {
bp->f1 |= SELECT;
if(index<hmd->totindex-1) index++;
}
nr++;
bp++;
}
}
}
}
void object_hook_select(Object *ob, HookModifierData *hmd)
{
if(ob->type==OB_MESH) select_editmesh_hook(ob, hmd);
else if(ob->type==OB_LATTICE) select_editlattice_hook(ob, hmd);
else if(ob->type==OB_CURVE) select_editcurve_hook(ob, hmd);
else if(ob->type==OB_SURF) select_editcurve_hook(ob, hmd);
}
void add_hook(Scene *scene, View3D *v3d, int mode)
{
ModifierData *md = NULL;
HookModifierData *hmd = NULL;
Object *ob=NULL;
Object *obedit= scene->obedit; // XXX get from context
if(obedit==NULL) return;
/* preconditions */
if(mode==2) { /* selected object */
Base *base;
for(base= FIRSTBASE; base; base= base->next) {
if(TESTBASELIB(v3d, base)) {
if(base!=BASACT) {
ob= base->object;
break;
}
}
}
if(ob==NULL) {
// XXX error("Requires selected Object");
return;
}
}
else if(mode!=1) {
int maxlen=0, a, nr;
char *cp;
/* make pupmenu with hooks */
for(md=obedit->modifiers.first; md; md= md->next) {
if (md->type==eModifierType_Hook)
maxlen+=32;
}
if(maxlen==0) {
// XXX error("Object has no hooks yet");
return;
}
cp= MEM_callocN(maxlen+32, "temp string");
if(mode==3) strcpy(cp, "Remove %t|");
else if(mode==4) strcpy(cp, "Reassign %t|");
else if(mode==5) strcpy(cp, "Select %t|");
else if(mode==6) strcpy(cp, "Clear Offset %t|");
for(md=obedit->modifiers.first; md; md= md->next) {
if (md->type==eModifierType_Hook) {
strcat(cp, md->name);
strcat(cp, " |");
}
}
nr= 0; // XXX pupmenu(cp);
MEM_freeN(cp);
if(nr<1) return;
a= 1;
for(md=obedit->modifiers.first; md; md=md->next) {
if (md->type==eModifierType_Hook) {
if(a==nr) break;
a++;
}
}
hmd = (HookModifierData*) md;
ob= hmd->object;
}
/* do it, new hooks or reassign */
if(mode==1 || mode==2 || mode==4) {
float cent[3];
int tot, ok, *indexar;
char name[32];
ok = object_hook_index_array(obedit, &tot, &indexar, name, cent);
if(ok==0) {
// XXX error("Requires selected vertices or active Vertex Group");
}
else {
if(mode==1) {
Base *base= BASACT, *newbase;
ob= add_object(scene, OB_EMPTY);
/* set layers OK */
newbase= BASACT;
newbase->lay= base->lay;
ob->lay= newbase->lay;
/* transform cent to global coords for loc */
VecMat4MulVecfl(ob->loc, obedit->obmat, cent);
/* restore, add_object sets active */
BASACT= base;
}
/* if mode is 2 or 4, ob has been set */
/* new hook */
if(mode==1 || mode==2) {
ModifierData *md = obedit->modifiers.first;
while (md && modifierType_getInfo(md->type)->type==eModifierTypeType_OnlyDeform) {
md = md->next;
}
hmd = (HookModifierData*) modifier_new(eModifierType_Hook);
BLI_insertlinkbefore(&obedit->modifiers, md, hmd);
sprintf(hmd->modifier.name, "Hook-%s", ob->id.name+2);
}
else if (hmd->indexar) MEM_freeN(hmd->indexar); /* reassign, hook was set */
hmd->object= ob;
hmd->indexar= indexar;
VecCopyf(hmd->cent, cent);
hmd->totindex= tot;
BLI_strncpy(hmd->name, name, 32);
// TODO: need to take into account bone targets here too now...
if(mode==1 || mode==2) {
/* matrix calculus */
/* vert x (obmat x hook->imat) x hook->obmat x ob->imat */
/* (parentinv ) */
where_is_object(scene, ob);
Mat4Invert(ob->imat, ob->obmat);
/* apparently this call goes from right to left... */
Mat4MulSerie(hmd->parentinv, ob->imat, obedit->obmat, NULL,
NULL, NULL, NULL, NULL, NULL);
}
}
}
else if(mode==3) { /* remove */
BLI_remlink(&obedit->modifiers, md);
modifier_free(md);
}
else if(mode==5) { /* select */
// FIXME: this is now OBJECT_OT_hook_select
object_hook_select(obedit, hmd);
}
else if(mode==6) { /* clear offset */
// FIXME: this is now OBJECT_OT_hook_reset operator
where_is_object(scene, ob); /* ob is hook->parent */
Mat4Invert(ob->imat, ob->obmat);
/* this call goes from right to left... */
Mat4MulSerie(hmd->parentinv, ob->imat, obedit->obmat, NULL,
NULL, NULL, NULL, NULL, NULL);
}
DAG_scene_sort(scene);
}
void add_hook_menu(Scene *scene, View3D *v3d)
{
Object *obedit= scene->obedit; // XXX get from context
int mode;
if(obedit==NULL) return;
if(modifiers_findByType(obedit, eModifierType_Hook))
mode= 0; // XXX pupmenu("Hooks %t|Add, To New Empty %x1|Add, To Selected Object %x2|Remove... %x3|Reassign... %x4|Select... %x5|Clear Offset...%x6");
else
mode= 0; // XXX pupmenu("Hooks %t|Add, New Empty %x1|Add, To Selected Object %x2");
if(mode<1) return;
/* do operations */
add_hook(scene, v3d, mode);
}
void hookmenu(Scene *scene, View3D *v3d)
{
/* only called in object mode */
short event, changed=0;
Object *ob;
Base *base;
ModifierData *md;
HookModifierData *hmd;
event= 0; // XXX pupmenu("Modify Hooks for Selected...%t|Reset Offset%x1|Recenter at Cursor%x2");
if (event==-1) return;
if (event==2 && !(v3d)) {
// XXX error("Cannot perform this operation without a 3d view");
return;
}
for (base= FIRSTBASE; base; base= base->next) {
if(TESTBASELIB(v3d, base)) {
for (md = base->object->modifiers.first; md; md=md->next) {
if (md->type==eModifierType_Hook) {
ob = base->object;
hmd = (HookModifierData*) md;
/*
* Copied from modifiers_cursorHookCenter and
* modifiers_clearHookOffset, should consolidate
* */
if (event==1) {
if(hmd->object) {
Mat4Invert(hmd->object->imat, hmd->object->obmat);
Mat4MulSerie(hmd->parentinv, hmd->object->imat, ob->obmat, NULL, NULL, NULL, NULL, NULL, NULL);
changed= 1;
DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
}
} else {
float *curs = give_cursor(scene, v3d);
float bmat[3][3], imat[3][3];
where_is_object(scene, ob);
Mat3CpyMat4(bmat, ob->obmat);
Mat3Inv(imat, bmat);
curs= give_cursor(scene, v3d);
hmd->cent[0]= curs[0]-ob->obmat[3][0];
hmd->cent[1]= curs[1]-ob->obmat[3][1];
hmd->cent[2]= curs[2]-ob->obmat[3][2];
Mat3MulVecfl(imat, hmd->cent);
changed= 1;
DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
}
}
}
}
}
if (changed) {
}
}

View File

@@ -38,15 +38,39 @@ struct HookModifierData;
/* internal exports only */
/* object_transform.c */
void OBJECT_OT_location_clear(struct wmOperatorType *ot);
void OBJECT_OT_rotation_clear(struct wmOperatorType *ot);
void OBJECT_OT_scale_clear(struct wmOperatorType *ot);
void OBJECT_OT_origin_clear(struct wmOperatorType *ot);
void OBJECT_OT_visual_transform_apply(struct wmOperatorType *ot);
void OBJECT_OT_location_apply(struct wmOperatorType *ot);
void OBJECT_OT_scale_apply(struct wmOperatorType *ot);
void OBJECT_OT_rotation_apply(struct wmOperatorType *ot);
void OBJECT_OT_center_set(struct wmOperatorType *ot);
/* object_relations.c */
void OBJECT_OT_parent_set(struct wmOperatorType *ot);
void OBJECT_OT_parent_clear(struct wmOperatorType *ot);
void OBJECT_OT_vertex_parent_set(struct wmOperatorType *ot);
void OBJECT_OT_track_set(struct wmOperatorType *ot);
void OBJECT_OT_track_clear(struct wmOperatorType *ot);
void OBJECT_OT_slow_parent_set(struct wmOperatorType *ot);
void OBJECT_OT_slow_parent_clear(struct wmOperatorType *ot);
void OBJECT_OT_make_local(struct wmOperatorType *ot);
void OBJECT_OT_move_to_layer(struct wmOperatorType *ot);
/* object_edit.c */
void OBJECT_OT_mode_set(struct wmOperatorType *ot);
void OBJECT_OT_editmode_toggle(struct wmOperatorType *ot);
void OBJECT_OT_posemode_toggle(struct wmOperatorType *ot);
void OBJECT_OT_parent_set(struct wmOperatorType *ot);
void OBJECT_OT_parent_clear(struct wmOperatorType *ot);
void OBJECT_OT_track_set(struct wmOperatorType *ot);
void OBJECT_OT_track_clear(struct wmOperatorType *ot);
void OBJECT_OT_restrictview_set(struct wmOperatorType *ot);
void OBJECT_OT_restrictview_clear(struct wmOperatorType *ot);
void OBJECT_OT_proxy_make(struct wmOperatorType *ot);
void OBJECT_OT_shade_smooth(struct wmOperatorType *ot);
void OBJECT_OT_shade_flat(struct wmOperatorType *ot);
/* object_select.c */
void OBJECT_OT_select_all_toggle(struct wmOperatorType *ot);
void OBJECT_OT_select_inverse(struct wmOperatorType *ot);
void OBJECT_OT_select_random(struct wmOperatorType *ot);
@@ -55,37 +79,28 @@ void OBJECT_OT_select_by_layer(struct wmOperatorType *ot);
void OBJECT_OT_select_linked(struct wmOperatorType *ot);
void OBJECT_OT_select_grouped(struct wmOperatorType *ot);
void OBJECT_OT_select_mirror(struct wmOperatorType *ot);
void OBJECT_OT_location_clear(struct wmOperatorType *ot);
void OBJECT_OT_rotation_clear(struct wmOperatorType *ot);
void OBJECT_OT_scale_clear(struct wmOperatorType *ot);
void OBJECT_OT_origin_clear(struct wmOperatorType *ot);
void OBJECT_OT_restrictview_set(struct wmOperatorType *ot);
void OBJECT_OT_restrictview_clear(struct wmOperatorType *ot);
void OBJECT_OT_slowparent_set(struct wmOperatorType *ot);
void OBJECT_OT_slowparent_clear(struct wmOperatorType *ot);
void OBJECT_OT_center_set(struct wmOperatorType *ot);
void OBJECT_OT_duplicates_make_real(struct wmOperatorType *ot);
void OBJECT_OT_object_add(struct wmOperatorType *ot);
void OBJECT_OT_duplicate(struct wmOperatorType *ot);
void OBJECT_OT_delete(struct wmOperatorType *ot);
void OBJECT_OT_join(struct wmOperatorType *ot);
void OBJECT_OT_proxy_make(struct wmOperatorType *ot);
void OBJECT_OT_shade_smooth(struct wmOperatorType *ot);
void OBJECT_OT_shade_flat(struct wmOperatorType *ot);
/* object_add.c */
void OBJECT_OT_add(struct wmOperatorType *ot);
void OBJECT_OT_mesh_add(struct wmOperatorType *ot);
void OBJECT_OT_curve_add(struct wmOperatorType *ot);
void OBJECT_OT_surface_add(struct wmOperatorType *ot);
void OBJECT_OT_metaball_add(wmOperatorType *ot);
void OBJECT_OT_metaball_add(struct wmOperatorType *ot);
void OBJECT_OT_text_add(struct wmOperatorType *ot);
void OBJECT_OT_armature_add(struct wmOperatorType *ot);
/* only used as menu */
void OBJECT_OT_primitive_add(struct wmOperatorType *ot);
void OBJECT_OT_primitive_add(struct wmOperatorType *ot); /* only used as menu */
void OBJECT_OT_duplicates_make_real(struct wmOperatorType *ot);
void OBJECT_OT_duplicate(struct wmOperatorType *ot);
void OBJECT_OT_delete(struct wmOperatorType *ot);
void OBJECT_OT_join(struct wmOperatorType *ot);
void OBJECT_OT_convert(struct wmOperatorType *ot);
/* object_hook.c */
int object_hook_index_array(Object *obedit, int *tot, int **indexar, char *name, float *cent_r);
void object_hook_select(Object *obedit, struct HookModifierData *hmd);
/* editlattice.c */
/* object_lattice.c */
void free_editLatt(Object *ob);
void make_editLatt(Object *obedit);
void load_editLatt(Object *obedit);
@@ -94,7 +109,7 @@ void remake_editLatt(Object *obedit);
void LATTICE_OT_select_all_toggle(struct wmOperatorType *ot);
void LATTICE_OT_make_regular(struct wmOperatorType *ot);
/* editgroup.c */
/* object_group.c */
void GROUP_OT_group_create(struct wmOperatorType *ot);
void GROUP_OT_objects_remove(struct wmOperatorType *ot);
void GROUP_OT_objects_add_active(struct wmOperatorType *ot);
@@ -117,7 +132,7 @@ void OBJECT_OT_hook_select(struct wmOperatorType *ot);
void OBJECT_OT_hook_assign(struct wmOperatorType *ot);
void OBJECT_OT_explode_refresh(struct wmOperatorType *ot);
/* editconstraint.c */
/* object_constraint.c */
void OBJECT_OT_constraint_add(struct wmOperatorType *ot);
void OBJECT_OT_constraint_add_with_targets(struct wmOperatorType *ot);
void POSE_OT_constraint_add(struct wmOperatorType *ot);
@@ -148,11 +163,13 @@ void OBJECT_OT_vertex_group_select(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_deselect(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_copy_to_linked(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_copy(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_menu(struct wmOperatorType *ot);
void OBJECT_OT_vertex_group_set_active(struct wmOperatorType *ot);
void OBJECT_OT_game_property_new(struct wmOperatorType *ot);
void OBJECT_OT_game_property_remove(struct wmOperatorType *ot);
/* editkey.c */
/* object_shapekey.c */
void OBJECT_OT_shape_key_add(struct wmOperatorType *ot);
void OBJECT_OT_shape_key_remove(struct wmOperatorType *ot);

View File

@@ -31,21 +31,15 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
#include "DNA_curve_types.h"
#include "DNA_key_types.h"
#include "DNA_lattice_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_view3d_types.h"
#include "BKE_armature.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_key.h"
#include "BKE_lattice.h"
#include "BKE_mesh.h"

View File

@@ -809,58 +809,6 @@ void OBJECT_OT_meshdeform_bind(wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
#if 0
typedef struct MenuEntry {
char *name;
int ID;
} MenuEntry;
static int menuEntry_compare_names(const void *entry1, const void *entry2)
{
return strcmp(((MenuEntry *)entry1)->name, ((MenuEntry *)entry2)->name);
}
static uiBlock *modifiers_add_menu(void *ob_v)
{
Object *ob = ob_v;
uiBlock *block;
int i, yco=0;
int numEntries = 0;
MenuEntry entries[NUM_MODIFIER_TYPES];
block= uiNewBlock(&curarea->uiblocks, "modifier_add_menu",
UI_EMBOSSP, UI_HELV, curarea->win);
uiBlockSetButmFunc(block, modifiers_add, ob);
for (i=eModifierType_None+1; i<NUM_MODIFIER_TYPES; i++) {
ModifierTypeInfo *mti = modifierType_getInfo(i);
/* Only allow adding through appropriate other interfaces */
if(ELEM(i, eModifierType_ParticleSystem, eModifierType_Surface)) continue;
if((mti->flags&eModifierTypeFlag_AcceptsCVs) ||
(ob->type==OB_MESH && (mti->flags&eModifierTypeFlag_AcceptsMesh))) {
entries[numEntries].name = mti->name;
entries[numEntries].ID = i;
++numEntries;
}
}
qsort(entries, numEntries, sizeof(*entries), menuEntry_compare_names);
for(i = 0; i < numEntries; ++i)
uiDefBut(block, BUTM, B_MODIFIER_RECALC, entries[i].name,
0, yco -= 20, 160, 19, NULL, 0, 0, 1, entries[i].ID, "");
uiTextBoundsBlock(block, 50);
uiBlockSetDirection(block, UI_DOWN);
return block;
}
#endif
/******************** hook operators ************************/
static int hook_poll(bContext *C)

View File

@@ -64,14 +64,36 @@
void ED_operatortypes_object(void)
{
wmOperatorType *ot;
WM_operatortype_append(OBJECT_OT_location_clear);
WM_operatortype_append(OBJECT_OT_rotation_clear);
WM_operatortype_append(OBJECT_OT_scale_clear);
WM_operatortype_append(OBJECT_OT_origin_clear);
WM_operatortype_append(OBJECT_OT_visual_transform_apply);
WM_operatortype_append(OBJECT_OT_location_apply);
WM_operatortype_append(OBJECT_OT_scale_apply);
WM_operatortype_append(OBJECT_OT_rotation_apply);
WM_operatortype_append(OBJECT_OT_center_set);
WM_operatortype_append(OBJECT_OT_mode_set);
WM_operatortype_append(OBJECT_OT_editmode_toggle);
WM_operatortype_append(OBJECT_OT_posemode_toggle);
WM_operatortype_append(OBJECT_OT_proxy_make);
WM_operatortype_append(OBJECT_OT_restrictview_clear);
WM_operatortype_append(OBJECT_OT_restrictview_set);
WM_operatortype_append(OBJECT_OT_shade_smooth);
WM_operatortype_append(OBJECT_OT_shade_flat);
WM_operatortype_append(OBJECT_OT_parent_set);
WM_operatortype_append(OBJECT_OT_parent_clear);
WM_operatortype_append(OBJECT_OT_vertex_parent_set);
WM_operatortype_append(OBJECT_OT_track_set);
WM_operatortype_append(OBJECT_OT_track_clear);
WM_operatortype_append(OBJECT_OT_slow_parent_set);
WM_operatortype_append(OBJECT_OT_slow_parent_clear);
WM_operatortype_append(OBJECT_OT_make_local);
WM_operatortype_append(OBJECT_OT_move_to_layer);
WM_operatortype_append(OBJECT_OT_select_inverse);
WM_operatortype_append(OBJECT_OT_select_random);
WM_operatortype_append(OBJECT_OT_select_all_toggle);
@@ -80,21 +102,7 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_select_linked);
WM_operatortype_append(OBJECT_OT_select_grouped);
WM_operatortype_append(OBJECT_OT_select_mirror);
WM_operatortype_append(OBJECT_OT_location_clear);
WM_operatortype_append(OBJECT_OT_rotation_clear);
WM_operatortype_append(OBJECT_OT_scale_clear);
WM_operatortype_append(OBJECT_OT_origin_clear);
WM_operatortype_append(OBJECT_OT_restrictview_clear);
WM_operatortype_append(OBJECT_OT_restrictview_set);
WM_operatortype_append(OBJECT_OT_slowparent_set);
WM_operatortype_append(OBJECT_OT_slowparent_clear);
WM_operatortype_append(OBJECT_OT_center_set);
WM_operatortype_append(OBJECT_OT_duplicates_make_real);
WM_operatortype_append(OBJECT_OT_duplicate);
WM_operatortype_append(OBJECT_OT_join);
WM_operatortype_append(OBJECT_OT_proxy_make);
WM_operatortype_append(OBJECT_OT_shade_smooth);
WM_operatortype_append(OBJECT_OT_shade_flat);
WM_operatortype_append(GROUP_OT_group_create);
WM_operatortype_append(GROUP_OT_objects_remove);
WM_operatortype_append(GROUP_OT_objects_add_active);
@@ -106,10 +114,14 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_text_add);
WM_operatortype_append(OBJECT_OT_surface_add);
WM_operatortype_append(OBJECT_OT_armature_add);
WM_operatortype_append(OBJECT_OT_object_add);
WM_operatortype_append(OBJECT_OT_add);
WM_operatortype_append(OBJECT_OT_primitive_add);
WM_operatortype_append(OBJECT_OT_mesh_add);
WM_operatortype_append(OBJECT_OT_metaball_add);
WM_operatortype_append(OBJECT_OT_duplicates_make_real);
WM_operatortype_append(OBJECT_OT_duplicate);
WM_operatortype_append(OBJECT_OT_join);
WM_operatortype_append(OBJECT_OT_convert);
WM_operatortype_append(OBJECT_OT_modifier_add);
WM_operatortype_append(OBJECT_OT_modifier_remove);
@@ -151,6 +163,8 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_vertex_group_deselect);
WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_linked);
WM_operatortype_append(OBJECT_OT_vertex_group_copy);
WM_operatortype_append(OBJECT_OT_vertex_group_menu);
WM_operatortype_append(OBJECT_OT_vertex_group_set_active);
WM_operatortype_append(OBJECT_OT_game_property_new);
WM_operatortype_append(OBJECT_OT_game_property_remove);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,974 @@
/**
* $Id$
*
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* 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 *****
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "DNA_group_types.h"
#include "DNA_material_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "DNA_property_types.h"
#include "DNA_scene_types.h"
#include "DNA_texture_types.h"
#include "BLI_arithb.h"
#include "BLI_listbase.h"
#include "BLI_rand.h"
#include "BLI_string.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_group.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_particle.h"
#include "BKE_property.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "WM_api.h"
#include "WM_types.h"
#include "ED_object.h"
#include "ED_screen.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
#include "object_intern.h"
/************************ Exported **************************/
/* simple API for object selection, rather than just using the flag
* this takes into account the 'restrict selection in 3d view' flag.
* deselect works always, the restriction just prevents selection */
/* Note: send a NC_SCENE|ND_OB_SELECT notifier yourself! */
void ED_base_object_select(Base *base, short mode)
{
if (base) {
if (mode==BA_SELECT) {
if (!(base->object->restrictflag & OB_RESTRICT_SELECT))
if (mode==BA_SELECT) base->flag |= SELECT;
}
else if (mode==BA_DESELECT) {
base->flag &= ~SELECT;
}
base->object->flag= base->flag;
}
}
/* also to set active NULL */
void ED_base_object_activate(bContext *C, Base *base)
{
Scene *scene= CTX_data_scene(C);
Base *tbase;
/* sets scene->basact */
BASACT= base;
if(base) {
/* XXX old signals, remember to handle notifiers now! */
// select_actionchannel_by_name(base->object->action, "Object", 1);
/* disable temporal locks */
for(tbase=FIRSTBASE; tbase; tbase= tbase->next) {
if(base!=tbase && (tbase->object->shapeflag & OB_SHAPE_TEMPLOCK)) {
tbase->object->shapeflag &= ~OB_SHAPE_TEMPLOCK;
DAG_id_flush_update(&tbase->object->id, OB_RECALC_DATA);
}
}
WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
}
else
WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, NULL);
}
/********************** Selection Operators **********************/
static EnumPropertyItem prop_select_types[] = {
{0, "EXCLUSIVE", 0, "Exclusive", ""},
{1, "EXTEND", 0, "Extend", ""},
{0, NULL, 0, NULL, NULL}
};
/************************ Select by Type *************************/
static int object_select_by_type_exec(bContext *C, wmOperator *op)
{
short obtype, seltype;
obtype = RNA_enum_get(op->ptr, "type");
seltype = RNA_enum_get(op->ptr, "seltype");
if (seltype == 0) {
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
ED_base_object_select(base, BA_DESELECT);
}
CTX_DATA_END;
}
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if(base->object->type==obtype) {
ED_base_object_select(base, BA_SELECT);
}
}
CTX_DATA_END;
WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
void OBJECT_OT_select_by_type(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select By Type";
ot->description = "Select all visible objects that are of a type.";
ot->idname= "OBJECT_OT_select_by_type";
/* api callbacks */
ot->invoke= WM_menu_invoke;
ot->exec= object_select_by_type_exec;
ot->poll= ED_operator_scene_editable;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
RNA_def_enum(ot->srna, "seltype", prop_select_types, 0, "Selection", "Extend selection or clear selection then select");
RNA_def_enum(ot->srna, "type", object_type_items, 1, "Type", "");
}
/*********************** Selection by Links *********************/
static EnumPropertyItem prop_select_linked_types[] = {
{1, "IPO", 0, "Object IPO", ""}, // XXX depreceated animation system stuff...
{2, "OBDATA", 0, "Ob Data", ""},
{3, "MATERIAL", 0, "Material", ""},
{4, "TEXTURE", 0, "Texture", ""},
{5, "DUPGROUP", 0, "Dupligroup", ""},
{6, "PARTICLE", 0, "Particle System", ""},
{0, NULL, 0, NULL, NULL}
};
static int object_select_linked_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
Object *ob;
void *obdata = NULL;
Material *mat = NULL, *mat1;
Tex *tex=0;
int a, b;
int nr = RNA_enum_get(op->ptr, "type");
short changed = 0, seltype;
/* events (nr):
* Object Ipo: 1
* ObData: 2
* Current Material: 3
* Current Texture: 4
* DupliGroup: 5
* PSys: 6
*/
seltype = RNA_enum_get(op->ptr, "seltype");
if (seltype == 0) {
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
ED_base_object_select(base, BA_DESELECT);
}
CTX_DATA_END;
}
ob= OBACT;
if(ob==0){
BKE_report(op->reports, RPT_ERROR, "No Active Object");
return OPERATOR_CANCELLED;
}
if(nr==1) {
// XXX old animation system
//ipo= ob->ipo;
//if(ipo==0) return OPERATOR_CANCELLED;
return OPERATOR_CANCELLED;
}
else if(nr==2) {
if(ob->data==0) return OPERATOR_CANCELLED;
obdata= ob->data;
}
else if(nr==3 || nr==4) {
mat= give_current_material(ob, ob->actcol);
if(mat==0) return OPERATOR_CANCELLED;
if(nr==4) {
if(mat->mtex[ (int)mat->texact ]) tex= mat->mtex[ (int)mat->texact ]->tex;
if(tex==0) return OPERATOR_CANCELLED;
}
}
else if(nr==5) {
if(ob->dup_group==NULL) return OPERATOR_CANCELLED;
}
else if(nr==6) {
if(ob->particlesystem.first==NULL) return OPERATOR_CANCELLED;
}
else return OPERATOR_CANCELLED;
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if(nr==1) {
// XXX old animation system
//if(base->object->ipo==ipo) base->flag |= SELECT;
//changed = 1;
}
else if(nr==2) {
if(base->object->data==obdata) base->flag |= SELECT;
changed = 1;
}
else if(nr==3 || nr==4) {
ob= base->object;
for(a=1; a<=ob->totcol; a++) {
mat1= give_current_material(ob, a);
if(nr==3) {
if(mat1==mat) base->flag |= SELECT;
changed = 1;
}
else if(mat1 && nr==4) {
for(b=0; b<MAX_MTEX; b++) {
if(mat1->mtex[b]) {
if(tex==mat1->mtex[b]->tex) {
base->flag |= SELECT;
changed = 1;
break;
}
}
}
}
}
}
else if(nr==5) {
if(base->object->dup_group==ob->dup_group) {
base->flag |= SELECT;
changed = 1;
}
}
else if(nr==6) {
/* loop through other, then actives particles*/
ParticleSystem *psys;
ParticleSystem *psys_act;
for(psys=base->object->particlesystem.first; psys; psys=psys->next) {
for(psys_act=ob->particlesystem.first; psys_act; psys_act=psys_act->next) {
if (psys->part == psys_act->part) {
base->flag |= SELECT;
changed = 1;
break;
}
}
if (base->flag & SELECT) {
break;
}
}
}
base->object->flag= base->flag;
}
CTX_DATA_END;
if (changed) {
WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;
}
void OBJECT_OT_select_linked(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select Linked";
ot->description = "Select all visible objects that are linked.";
ot->idname= "OBJECT_OT_select_linked";
/* api callbacks */
ot->invoke= WM_menu_invoke;
ot->exec= object_select_linked_exec;
ot->poll= ED_operator_scene_editable;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
RNA_def_enum(ot->srna, "type", prop_select_linked_types, 0, "Type", "");
RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
}
/*********************** Selected Grouped ********************/
static EnumPropertyItem prop_select_grouped_types[] = {
{1, "CHILDREN_RECURSIVE", 0, "Children", ""},
{2, "CHILDREN", 0, "Immediate Children", ""},
{3, "PARENT", 0, "Parent", ""},
{4, "SIBLINGS", 0, "Siblings", "Shared Parent"},
{5, "TYPE", 0, "Type", "Shared object type"},
{6, "LAYER", 0, "Layer", "Shared layers"},
{7, "GROUP", 0, "Group", "Shared group"},
{8, "HOOK", 0, "Hook", ""},
{9, "PASS", 0, "Pass", "Render pass Index"},
{10, "COLOR", 0, "Color", "Object Color"},
{11, "PROPERTIES", 0, "Properties", "Game Properties"},
{0, NULL, 0, NULL, NULL}
};
static short select_grouped_children(bContext *C, Object *ob, int recursive)
{
short changed = 0;
CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
if (ob == base->object->parent) {
if (!(base->flag & SELECT)) {
ED_base_object_select(base, BA_SELECT);
changed = 1;
}
if (recursive)
changed |= select_grouped_children(C, base->object, 1);
}
}
CTX_DATA_END;
return changed;
}
static short select_grouped_parent(bContext *C) /* Makes parent active and de-selected OBACT */
{
Scene *scene= CTX_data_scene(C);
View3D *v3d= CTX_wm_view3d(C);
short changed = 0;
Base *baspar, *basact= CTX_data_active_base(C);
if (!basact || !(basact->object->parent)) return 0; /* we know OBACT is valid */
baspar= object_in_scene(basact->object->parent, scene);
/* can be NULL if parent in other scene */
if(baspar && BASE_SELECTABLE(v3d, baspar)) {
ED_base_object_select(basact, BA_DESELECT);
ED_base_object_select(baspar, BA_SELECT);
ED_base_object_activate(C, baspar);
changed = 1;
}
return changed;
}
#define GROUP_MENU_MAX 24
static short select_grouped_group(bContext *C, Object *ob) /* Select objects in the same group as the active */
{
short changed = 0;
Group *group, *ob_groups[GROUP_MENU_MAX];
//char str[10 + (24*GROUP_MENU_MAX)];
//char *p = str;
int group_count=0; //, menu, i;
for ( group=G.main->group.first;
group && group_count < GROUP_MENU_MAX;
group=group->id.next
) {
if (object_in_group (ob, group)) {
ob_groups[group_count] = group;
group_count++;
}
}
if (!group_count)
return 0;
else if (group_count == 1) {
group = ob_groups[0];
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if (!(base->flag & SELECT) && object_in_group(base->object, group)) {
ED_base_object_select(base, BA_SELECT);
changed = 1;
}
}
CTX_DATA_END;
return changed;
}
#if 0 // XXX hows this work in 2.5?
/* build the menu. */
p += sprintf(str, "Groups%%t");
for (i=0; i<group_count; i++) {
group = ob_groups[i];
p += sprintf (p, "|%s%%x%i", group->id.name+2, i);
}
menu = pupmenu (str);
if (menu == -1)
return 0;
group = ob_groups[menu];
for (base= FIRSTBASE; base; base= base->next) {
if (!(base->flag & SELECT) && object_in_group(base->object, group)) {
ED_base_object_select(base, BA_SELECT);
changed = 1;
}
}
#endif
return changed;
}
static short select_grouped_object_hooks(bContext *C, Object *ob)
{
Scene *scene= CTX_data_scene(C);
View3D *v3d= CTX_wm_view3d(C);
short changed = 0;
Base *base;
ModifierData *md;
HookModifierData *hmd;
for (md = ob->modifiers.first; md; md=md->next) {
if (md->type==eModifierType_Hook) {
hmd= (HookModifierData*) md;
if (hmd->object && !(hmd->object->flag & SELECT)) {
base= object_in_scene(hmd->object, scene);
if (base && (BASE_SELECTABLE(v3d, base))) {
ED_base_object_select(base, BA_SELECT);
changed = 1;
}
}
}
}
return changed;
}
/* Select objects woth the same parent as the active (siblings),
* parent can be NULL also */
static short select_grouped_siblings(bContext *C, Object *ob)
{
short changed = 0;
CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
if ((base->object->parent==ob->parent) && !(base->flag & SELECT)) {
ED_base_object_select(base, BA_SELECT);
changed = 1;
}
}
CTX_DATA_END;
return changed;
}
static short select_grouped_type(bContext *C, Object *ob)
{
short changed = 0;
CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
if ((base->object->type == ob->type) && !(base->flag & SELECT)) {
ED_base_object_select(base, BA_SELECT);
changed = 1;
}
}
CTX_DATA_END;
return changed;
}
static short select_grouped_layer(bContext *C, Object *ob)
{
char changed = 0;
CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
if ((base->lay & ob->lay) && !(base->flag & SELECT)) {
ED_base_object_select(base, BA_SELECT);
changed = 1;
}
}
CTX_DATA_END;
return changed;
}
static short select_grouped_index_object(bContext *C, Object *ob)
{
char changed = 0;
CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
if ((base->object->index == ob->index) && !(base->flag & SELECT)) {
ED_base_object_select(base, BA_SELECT);
changed = 1;
}
}
CTX_DATA_END;
return changed;
}
static short select_grouped_color(bContext *C, Object *ob)
{
char changed = 0;
CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
if (!(base->flag & SELECT) && (FloatCompare(base->object->col, ob->col, 0.005f))) {
ED_base_object_select(base, BA_SELECT);
changed = 1;
}
}
CTX_DATA_END;
return changed;
}
static short objects_share_gameprop(Object *a, Object *b)
{
bProperty *prop;
/*make a copy of all its properties*/
for( prop= a->prop.first; prop; prop = prop->next ) {
if ( get_ob_property(b, prop->name) )
return 1;
}
return 0;
}
static short select_grouped_gameprops(bContext *C, Object *ob)
{
char changed = 0;
CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
if (!(base->flag & SELECT) && (objects_share_gameprop(base->object, ob))) {
ED_base_object_select(base, BA_SELECT);
changed = 1;
}
}
CTX_DATA_END;
return changed;
}
static int object_select_grouped_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
Object *ob;
int nr = RNA_enum_get(op->ptr, "type");
short changed = 0, seltype;
seltype = RNA_enum_get(op->ptr, "seltype");
if (seltype == 0) {
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
ED_base_object_select(base, BA_DESELECT);
}
CTX_DATA_END;
}
ob= OBACT;
if(ob==0){
BKE_report(op->reports, RPT_ERROR, "No Active Object");
return OPERATOR_CANCELLED;
}
if(nr==1) changed = select_grouped_children(C, ob, 1);
else if(nr==2) changed = select_grouped_children(C, ob, 0);
else if(nr==3) changed = select_grouped_parent(C);
else if(nr==4) changed = select_grouped_siblings(C, ob);
else if(nr==5) changed = select_grouped_type(C, ob);
else if(nr==6) changed = select_grouped_layer(C, ob);
else if(nr==7) changed = select_grouped_group(C, ob);
else if(nr==8) changed = select_grouped_object_hooks(C, ob);
else if(nr==9) changed = select_grouped_index_object(C, ob);
else if(nr==10) changed = select_grouped_color(C, ob);
else if(nr==11) changed = select_grouped_gameprops(C, ob);
if (changed) {
WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;
}
void OBJECT_OT_select_grouped(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select Grouped";
ot->description = "Select all visible objects grouped by various properties.";
ot->idname= "OBJECT_OT_select_grouped";
/* api callbacks */
ot->invoke= WM_menu_invoke;
ot->exec= object_select_grouped_exec;
ot->poll= ED_operator_scene_editable;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* properties */
RNA_def_enum(ot->srna, "type", prop_select_grouped_types, 0, "Type", "");
RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
}
/************************* Select by Layer **********************/
static int object_select_by_layer_exec(bContext *C, wmOperator *op)
{
unsigned int layernum;
short seltype;
seltype = RNA_enum_get(op->ptr, "seltype");
layernum = RNA_int_get(op->ptr, "layer");
if (seltype == 0) {
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
ED_base_object_select(base, BA_DESELECT);
}
CTX_DATA_END;
}
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if(base->lay == (1<< (layernum -1)))
ED_base_object_select(base, BA_SELECT);
}
CTX_DATA_END;
/* undo? */
WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
void OBJECT_OT_select_by_layer(wmOperatorType *ot)
{
/* identifiers */
ot->name= "select by layer";
ot->description = "Select all visible objects on a layer.";
ot->idname= "OBJECT_OT_select_by_layer";
/* api callbacks */
/*ot->invoke = XXX - need a int grid popup*/
ot->exec= object_select_by_layer_exec;
ot->poll= ED_operator_scene_editable;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
RNA_def_int(ot->srna, "layer", 1, 1, 20, "Layer", "", 1, 20);
RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
}
/************************** Select Inverse *************************/
static int object_select_inverse_exec(bContext *C, wmOperator *op)
{
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if (base->flag & SELECT)
ED_base_object_select(base, BA_DESELECT);
else
ED_base_object_select(base, BA_SELECT);
}
CTX_DATA_END;
/* undo? */
WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
void OBJECT_OT_select_inverse(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select Inverse";
ot->description = "Invert selection of all visible objects.";
ot->idname= "OBJECT_OT_select_inverse";
/* api callbacks */
ot->exec= object_select_inverse_exec;
ot->poll= ED_operator_scene_editable;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/**************************** (De)select All ****************************/
static int object_select_de_select_all_exec(bContext *C, wmOperator *op)
{
int a=0, ok=0;
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if (base->flag & SELECT) {
ok= a= 1;
break;
}
else ok=1;
}
CTX_DATA_END;
if (!ok) return OPERATOR_PASS_THROUGH;
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if (a) ED_base_object_select(base, BA_DESELECT);
else ED_base_object_select(base, BA_SELECT);
}
CTX_DATA_END;
/* undo? */
WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
void OBJECT_OT_select_all_toggle(wmOperatorType *ot)
{
/* identifiers */
ot->name= "deselect all";
ot->description = "(de)select all visible objects in scene.";
ot->idname= "OBJECT_OT_select_all_toggle";
/* api callbacks */
ot->exec= object_select_de_select_all_exec;
ot->poll= ED_operator_scene_editable;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/**************************** Select Mirror ****************************/
/* finds the best possible flipped name. For renaming; check for unique names afterwards */
/* if strip_number: removes number extensions */
void object_flip_name (char *name)
{
int len;
char prefix[128]={""}; /* The part before the facing */
char suffix[128]={""}; /* The part after the facing */
char replace[128]={""}; /* The replacement string */
char number[128]={""}; /* The number extension string */
char *index=NULL;
len= strlen(name);
if(len<3) return; // we don't do names like .R or .L
/* We first check the case with a .### extension, let's find the last period */
if(isdigit(name[len-1])) {
index= strrchr(name, '.'); // last occurrance
if (index && isdigit(index[1]) ) { // doesnt handle case bone.1abc2 correct..., whatever!
strcpy(number, index);
*index= 0;
len= strlen(name);
}
}
strcpy (prefix, name);
#define IS_SEPARATOR(a) ((a)=='.' || (a)==' ' || (a)=='-' || (a)=='_')
/* first case; separator . - _ with extensions r R l L */
if( IS_SEPARATOR(name[len-2]) ) {
switch(name[len-1]) {
case 'l':
prefix[len-1]= 0;
strcpy(replace, "r");
break;
case 'r':
prefix[len-1]= 0;
strcpy(replace, "l");
break;
case 'L':
prefix[len-1]= 0;
strcpy(replace, "R");
break;
case 'R':
prefix[len-1]= 0;
strcpy(replace, "L");
break;
}
}
/* case; beginning with r R l L , with separator after it */
else if( IS_SEPARATOR(name[1]) ) {
switch(name[0]) {
case 'l':
strcpy(replace, "r");
strcpy(suffix, name+1);
prefix[0]= 0;
break;
case 'r':
strcpy(replace, "l");
strcpy(suffix, name+1);
prefix[0]= 0;
break;
case 'L':
strcpy(replace, "R");
strcpy(suffix, name+1);
prefix[0]= 0;
break;
case 'R':
strcpy(replace, "L");
strcpy(suffix, name+1);
prefix[0]= 0;
break;
}
}
else if(len > 5) {
/* hrms, why test for a separator? lets do the rule 'ultimate left or right' */
index = BLI_strcasestr(prefix, "right");
if (index==prefix || index==prefix+len-5) {
if(index[0]=='r')
strcpy (replace, "left");
else {
if(index[1]=='I')
strcpy (replace, "LEFT");
else
strcpy (replace, "Left");
}
*index= 0;
strcpy (suffix, index+5);
}
else {
index = BLI_strcasestr(prefix, "left");
if (index==prefix || index==prefix+len-4) {
if(index[0]=='l')
strcpy (replace, "right");
else {
if(index[1]=='E')
strcpy (replace, "RIGHT");
else
strcpy (replace, "Right");
}
*index= 0;
strcpy (suffix, index+4);
}
}
}
#undef IS_SEPARATOR
sprintf (name, "%s%s%s%s", prefix, replace, suffix, number);
}
static int object_select_mirror_exec(bContext *C, wmOperator *op)
{
char tmpname[32];
short seltype;
seltype = RNA_enum_get(op->ptr, "seltype");
CTX_DATA_BEGIN(C, Base*, primbase, selected_bases) {
strcpy(tmpname, primbase->object->id.name+2);
object_flip_name(tmpname);
CTX_DATA_BEGIN(C, Base*, secbase, visible_bases) {
if(!strcmp(secbase->object->id.name+2, tmpname)) {
ED_base_object_select(secbase, BA_SELECT);
}
}
CTX_DATA_END;
if (seltype == 0) ED_base_object_select(primbase, BA_DESELECT);
}
CTX_DATA_END;
/* undo? */
WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
void OBJECT_OT_select_mirror(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select Mirror";
ot->description = "Select the Mirror objects of the selected object eg. L.sword -> R.sword";
ot->idname= "OBJECT_OT_select_mirror";
/* api callbacks */
ot->exec= object_select_mirror_exec;
ot->poll= ED_operator_scene_editable;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
}
/**************************** Select Random ****************************/
static int object_select_random_exec(bContext *C, wmOperator *op)
{
float percent;
short seltype;
seltype = RNA_enum_get(op->ptr, "seltype");
if (seltype == 0) {
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
ED_base_object_select(base, BA_DESELECT);
}
CTX_DATA_END;
}
percent = RNA_float_get(op->ptr, "percent");
CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
if (BLI_frand() < percent) {
ED_base_object_select(base, BA_SELECT);
}
}
CTX_DATA_END;
WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
return OPERATOR_FINISHED;
}
void OBJECT_OT_select_random(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Random select";
ot->description = "Set select on random visible objects.";
ot->idname= "OBJECT_OT_select_random";
/* api callbacks */
/*ot->invoke= object_select_random_invoke XXX - need a number popup ;*/
ot->exec = object_select_random_exec;
ot->poll= ED_operator_scene_editable;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
RNA_def_float_percentage(ot->srna, "percent", 0.5f, 0.0f, 1.0f, "Percent", "percentage of objects to randomly select", 0.0001f, 1.0f);
RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
}

View File

@@ -0,0 +1,926 @@
/**
* $Id$
*
* ***** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* 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 *****
*/
#include <stdlib.h>
#include "DNA_armature_types.h"
#include "DNA_curve_types.h"
#include "DNA_key_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_view3d_types.h"
#include "BLI_arithb.h"
#include "BLI_editVert.h"
#include "BLI_listbase.h"
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_object.h"
#include "BKE_report.h"
#include "BKE_utildefines.h"
#include "RNA_define.h"
#include "RNA_access.h"
#include "WM_api.h"
#include "WM_types.h"
#include "ED_anim_api.h"
#include "ED_armature.h"
#include "ED_curve.h"
#include "ED_mesh.h"
#include "ED_object.h"
#include "ED_screen.h"
#include "ED_view3d.h"
#include "object_intern.h"
/*************************** Clear Transformation ****************************/
static int object_location_clear_exec(bContext *C, wmOperator *op)
{
int armature_clear= 0;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
if((ob->protectflag & OB_LOCK_LOCX)==0)
ob->loc[0]= ob->dloc[0]= 0.0f;
if((ob->protectflag & OB_LOCK_LOCY)==0)
ob->loc[1]= ob->dloc[1]= 0.0f;
if((ob->protectflag & OB_LOCK_LOCZ)==0)
ob->loc[2]= ob->dloc[2]= 0.0f;
}
ob->recalc |= OB_RECALC_OB;
}
CTX_DATA_END;
if(armature_clear==0) /* in this case flush was done */
ED_anim_dag_flush_update(C);
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
return OPERATOR_FINISHED;
}
void OBJECT_OT_location_clear(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Clear Location";
ot->description = "Clear the object's location.";
ot->idname= "OBJECT_OT_location_clear";
/* api callbacks */
ot->exec= object_location_clear_exec;
ot->poll= ED_operator_object_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
static int object_rotation_clear_exec(bContext *C, wmOperator *op)
{
int armature_clear= 0;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
/* eulers can only get cleared if they are not protected */
if((ob->protectflag & OB_LOCK_ROTX)==0)
ob->rot[0]= ob->drot[0]= 0.0f;
if((ob->protectflag & OB_LOCK_ROTY)==0)
ob->rot[1]= ob->drot[1]= 0.0f;
if((ob->protectflag & OB_LOCK_ROTZ)==0)
ob->rot[2]= ob->drot[2]= 0.0f;
}
ob->recalc |= OB_RECALC_OB;
}
CTX_DATA_END;
if(armature_clear==0) /* in this case flush was done */
ED_anim_dag_flush_update(C);
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
return OPERATOR_FINISHED;
}
void OBJECT_OT_rotation_clear(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Clear Rotation";
ot->description = "Clear the object's rotation.";
ot->idname= "OBJECT_OT_rotation_clear";
/* api callbacks */
ot->exec= object_rotation_clear_exec;
ot->poll= ED_operator_object_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
static int object_scale_clear_exec(bContext *C, wmOperator *op)
{
int armature_clear= 0;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
if((ob->protectflag & OB_LOCK_SCALEX)==0) {
ob->dsize[0]= 0.0f;
ob->size[0]= 1.0f;
}
if((ob->protectflag & OB_LOCK_SCALEY)==0) {
ob->dsize[1]= 0.0f;
ob->size[1]= 1.0f;
}
if((ob->protectflag & OB_LOCK_SCALEZ)==0) {
ob->dsize[2]= 0.0f;
ob->size[2]= 1.0f;
}
}
ob->recalc |= OB_RECALC_OB;
}
CTX_DATA_END;
if(armature_clear==0) /* in this case flush was done */
ED_anim_dag_flush_update(C);
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
return OPERATOR_FINISHED;
}
void OBJECT_OT_scale_clear(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Clear Scale";
ot->description = "Clear the object's scale.";
ot->idname= "OBJECT_OT_scale_clear";
/* api callbacks */
ot->exec= object_scale_clear_exec;
ot->poll= ED_operator_object_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
static int object_origin_clear_exec(bContext *C, wmOperator *op)
{
float *v1, *v3, mat[3][3];
int armature_clear= 0;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
if(ob->parent) {
v1= ob->loc;
v3= ob->parentinv[3];
Mat3CpyMat4(mat, ob->parentinv);
VECCOPY(v3, v1);
v3[0]= -v3[0];
v3[1]= -v3[1];
v3[2]= -v3[2];
Mat3MulVecfl(mat, v3);
}
ob->recalc |= OB_RECALC_OB;
}
CTX_DATA_END;
if(armature_clear==0) /* in this case flush was done */
ED_anim_dag_flush_update(C);
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
return OPERATOR_FINISHED;
}
void OBJECT_OT_origin_clear(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Clear Origin";
ot->description = "Clear the object's origin.";
ot->idname= "OBJECT_OT_origin_clear";
/* api callbacks */
ot->exec= object_origin_clear_exec;
ot->poll= ED_operator_object_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/*************************** Apply Transformation ****************************/
/* use this when the loc/size/rot of the parent has changed but the children
* should stay in the same place, e.g. for apply-size-rot or object center */
static void ignore_parent_tx(Main *bmain, Scene *scene, Object *ob )
{
Object workob;
Object *ob_child;
/* a change was made, adjust the children to compensate */
for(ob_child=bmain->object.first; ob_child; ob_child=ob_child->id.next) {
if(ob_child->parent == ob) {
ED_object_apply_obmat(ob_child);
what_does_parent(scene, ob_child, &workob);
Mat4Invert(ob_child->parentinv, workob.obmat);
}
}
}
static int apply_objects_internal(bContext *C, ReportList *reports, int apply_loc, int apply_scale, int apply_rot)
{
Main *bmain= CTX_data_main(C);
Scene *scene= CTX_data_scene(C);
Object *ob;
bArmature *arm;
Mesh *me;
Curve *cu;
Nurb *nu;
BPoint *bp;
BezTriple *bezt;
MVert *mvert;
float rsmat[3][3], tmat[3][3], obmat[3][3], iobmat[3][3], mat[4][4], scale;
int a, change = 0;
/* first check if we can execute */
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
ob= base->object;
if(ob->type==OB_MESH) {
me= ob->data;
if(me->id.us>1) {
BKE_report(reports, RPT_ERROR, "Can't apply to a multi user mesh, doing nothing.");
return OPERATOR_CANCELLED;
}
}
else if(ob->type==OB_ARMATURE) {
arm= ob->data;
if(arm->id.us>1) {
BKE_report(reports, RPT_ERROR, "Can't apply to a multi user armature, doing nothing.");
return OPERATOR_CANCELLED;
}
}
else if(ELEM(ob->type, OB_CURVE, OB_SURF)) {
cu= ob->data;
if(cu->id.us>1) {
BKE_report(reports, RPT_ERROR, "Can't apply to a multi user curve, doing nothing.");
return OPERATOR_CANCELLED;
}
if(cu->key) {
BKE_report(reports, RPT_ERROR, "Can't apply to a curve with vertex keys, doing nothing.");
return OPERATOR_CANCELLED;
}
}
}
CTX_DATA_END;
/* now execute */
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
ob= base->object;
/* calculate rotation/scale matrix */
if(apply_scale && apply_rot)
object_to_mat3(ob, rsmat);
else if(apply_scale)
object_scale_to_mat3(ob, rsmat);
else if(apply_rot)
object_rot_to_mat3(ob, rsmat);
else
Mat3One(rsmat);
Mat4CpyMat3(mat, rsmat);
/* calculate translation */
if(apply_loc) {
VecCopyf(mat[3], ob->loc);
if(!(apply_scale && apply_rot)) {
/* correct for scale and rotation that is still applied */
object_to_mat3(ob, obmat);
Mat3Inv(iobmat, obmat);
Mat3MulMat3(tmat, rsmat, iobmat);
Mat3MulVecfl(tmat, mat[3]);
}
}
/* apply to object data */
if(ob->type==OB_MESH) {
me= ob->data;
/* adjust data */
mvert= me->mvert;
for(a=0; a<me->totvert; a++, mvert++)
Mat4MulVecfl(mat, mvert->co);
if(me->key) {
KeyBlock *kb;
for(kb=me->key->block.first; kb; kb=kb->next) {
float *fp= kb->data;
for(a=0; a<kb->totelem; a++, fp+=3)
Mat4MulVecfl(mat, fp);
}
}
/* update normals */
mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
}
else if (ob->type==OB_ARMATURE) {
ED_armature_apply_transform(ob, mat);
}
else if(ELEM(ob->type, OB_CURVE, OB_SURF)) {
cu= ob->data;
scale = Mat3ToScalef(rsmat);
for(nu=cu->nurb.first; nu; nu=nu->next) {
if(nu->type == CU_BEZIER) {
a= nu->pntsu;
for(bezt= nu->bezt; a--; bezt++) {
Mat4MulVecfl(mat, bezt->vec[0]);
Mat4MulVecfl(mat, bezt->vec[1]);
Mat4MulVecfl(mat, bezt->vec[2]);
bezt->radius *= scale;
bezt++;
}
}
else {
a= nu->pntsu*nu->pntsv;
for(bp= nu->bp; a--; bp++)
Mat4MulVecfl(mat, bp->vec);
}
}
}
else
continue;
if(apply_loc)
ob->loc[0]= ob->loc[1]= ob->loc[2]= 0.0f;
if(apply_scale)
ob->size[0]= ob->size[1]= ob->size[2]= 1.0f;
if(apply_rot)
ob->rot[0]= ob->rot[1]= ob->rot[2]= 0.0f;
where_is_object(scene, ob);
ignore_parent_tx(bmain, scene, ob);
DAG_id_flush_update(&ob->id, OB_RECALC_OB|OB_RECALC_DATA);
change = 1;
}
CTX_DATA_END;
if(!change)
return OPERATOR_CANCELLED;
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
return OPERATOR_FINISHED;
}
static int visual_transform_apply_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
int change = 0;
CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
where_is_object(scene, ob);
VECCOPY(ob->loc, ob->obmat[3]);
Mat4ToSize(ob->obmat, ob->size);
Mat4ToEul(ob->obmat, ob->rot);
where_is_object(scene, ob);
change = 1;
}
CTX_DATA_END;
if(!change)
return OPERATOR_CANCELLED;
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
return OPERATOR_FINISHED;
}
void OBJECT_OT_visual_transform_apply(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Apply Visual Transform";
ot->description = "Apply the object's visual transformation to its data.";
ot->idname= "OBJECT_OT_visual_transform_apply";
/* api callbacks */
ot->exec= visual_transform_apply_exec;
ot->poll= ED_operator_object_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
static int location_apply_exec(bContext *C, wmOperator *op)
{
return apply_objects_internal(C, op->reports, 1, 0, 0);
}
void OBJECT_OT_location_apply(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Apply Location";
ot->description = "Apply the object's location to its data.";
ot->idname= "OBJECT_OT_location_apply";
/* api callbacks */
ot->exec= location_apply_exec;
ot->poll= ED_operator_object_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
static int scale_apply_exec(bContext *C, wmOperator *op)
{
return apply_objects_internal(C, op->reports, 0, 1, 0);
}
void OBJECT_OT_scale_apply(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Apply Scale";
ot->description = "Apply the object's scale to its data.";
ot->idname= "OBJECT_OT_scale_apply";
/* api callbacks */
ot->exec= scale_apply_exec;
ot->poll= ED_operator_object_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
static int rotation_apply_exec(bContext *C, wmOperator *op)
{
return apply_objects_internal(C, op->reports, 0, 0, 1);
}
void OBJECT_OT_rotation_apply(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Apply Rotation";
ot->description = "Apply the object's rotation to its data.";
ot->idname= "OBJECT_OT_rotation_apply";
/* api callbacks */
ot->exec= rotation_apply_exec;
ot->poll= ED_operator_object_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/************************ Texture Space Transform ****************************/
void texspace_edit(Scene *scene, View3D *v3d)
{
Base *base;
int nr=0;
/* first test if from visible and selected objects
* texspacedraw is set:
*/
if(scene->obedit) return; // XXX get from context
for(base= FIRSTBASE; base; base= base->next) {
if(TESTBASELIB(v3d, base)) {
break;
}
}
if(base==0) {
return;
}
nr= 0; // XXX pupmenu("Texture Space %t|Grab/Move%x1|Size%x2");
if(nr<1) return;
for(base= FIRSTBASE; base; base= base->next) {
if(TESTBASELIB(v3d, base)) {
base->object->dtx |= OB_TEXSPACE;
}
}
if(nr==1) {
// XXX initTransform(TFM_TRANSLATION, CTX_TEXTURE);
// XXX Transform();
}
else if(nr==2) {
// XXX initTransform(TFM_RESIZE, CTX_TEXTURE);
// XXX Transform();
}
else if(nr==3) {
// XXX initTransform(TFM_ROTATION, CTX_TEXTURE);
// XXX Transform();
}
}
/************************ Mirror Menu ****************************/
void mirrormenu(void)
{
// XXX initTransform(TFM_MIRROR, CTX_NO_PET);
// XXX Transform();
}
/********************* Set Object Center ************************/
static EnumPropertyItem prop_set_center_types[] = {
{0, "CENTER", 0, "ObData to Center", "Move object data around Object center"},
{1, "CENTERNEW", 0, "Center New", "Move Object center to center of object data"},
{2, "CENTERCURSOR", 0, "Center Cursor", "Move Object Center to position of the 3d cursor"},
{0, NULL, 0, NULL, NULL}
};
/* 0 == do center, 1 == center new, 2 == center cursor */
static int object_center_set_exec(bContext *C, wmOperator *op)
{
Main *bmain= CTX_data_main(C);
Scene *scene= CTX_data_scene(C);
ScrArea *sa= CTX_wm_area(C);
View3D *v3d= sa->spacedata.first;
Object *obedit= CTX_data_edit_object(C);
Object *ob;
Mesh *me, *tme;
Curve *cu;
/* BezTriple *bezt;
BPoint *bp; */
Nurb *nu, *nu1;
EditVert *eve;
float cent[3], centn[3], min[3], max[3], omat[3][3];
int a, total= 0;
int centermode = RNA_enum_get(op->ptr, "type");
/* keep track of what is changed */
int tot_change=0, tot_lib_error=0, tot_multiuser_arm_error=0;
MVert *mvert;
if(scene->id.lib || v3d==NULL){
BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed on Lib data");
return OPERATOR_CANCELLED;
}
if (obedit && centermode > 0) {
BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in EditMode");
return OPERATOR_CANCELLED;
}
cent[0]= cent[1]= cent[2]= 0.0;
if(obedit) {
INIT_MINMAX(min, max);
if(obedit->type==OB_MESH) {
Mesh *me= obedit->data;
EditMesh *em = BKE_mesh_get_editmesh(me);
for(eve= em->verts.first; eve; eve= eve->next) {
if(v3d->around==V3D_CENTROID) {
total++;
VECADD(cent, cent, eve->co);
}
else {
DO_MINMAX(eve->co, min, max);
}
}
if(v3d->around==V3D_CENTROID) {
VecMulf(cent, 1.0f/(float)total);
}
else {
cent[0]= (min[0]+max[0])/2.0f;
cent[1]= (min[1]+max[1])/2.0f;
cent[2]= (min[2]+max[2])/2.0f;
}
for(eve= em->verts.first; eve; eve= eve->next) {
VecSubf(eve->co, eve->co, cent);
}
recalc_editnormals(em);
tot_change++;
DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
BKE_mesh_end_editmesh(me, em);
}
}
/* reset flags */
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
base->object->flag &= ~OB_DONE;
}
CTX_DATA_END;
for (me= G.main->mesh.first; me; me= me->id.next) {
me->flag &= ~ME_ISDONE;
}
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
if((base->object->flag & OB_DONE)==0) {
base->object->flag |= OB_DONE;
if(obedit==NULL && (me=get_mesh(base->object)) ) {
if (me->id.lib) {
tot_lib_error++;
} else {
if(centermode==2) {
VECCOPY(cent, give_cursor(scene, v3d));
Mat4Invert(base->object->imat, base->object->obmat);
Mat4MulVecfl(base->object->imat, cent);
} else {
INIT_MINMAX(min, max);
mvert= me->mvert;
for(a=0; a<me->totvert; a++, mvert++) {
DO_MINMAX(mvert->co, min, max);
}
cent[0]= (min[0]+max[0])/2.0f;
cent[1]= (min[1]+max[1])/2.0f;
cent[2]= (min[2]+max[2])/2.0f;
}
mvert= me->mvert;
for(a=0; a<me->totvert; a++, mvert++) {
VecSubf(mvert->co, mvert->co, cent);
}
if (me->key) {
KeyBlock *kb;
for (kb=me->key->block.first; kb; kb=kb->next) {
float *fp= kb->data;
for (a=0; a<kb->totelem; a++, fp+=3) {
VecSubf(fp, fp, cent);
}
}
}
me->flag |= ME_ISDONE;
if(centermode) {
Mat3CpyMat4(omat, base->object->obmat);
VECCOPY(centn, cent);
Mat3MulVecfl(omat, centn);
base->object->loc[0]+= centn[0];
base->object->loc[1]+= centn[1];
base->object->loc[2]+= centn[2];
where_is_object(scene, base->object);
ignore_parent_tx(bmain, scene, base->object);
/* other users? */
CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
ob = base->object;
if((ob->flag & OB_DONE)==0) {
tme= get_mesh(ob);
if(tme==me) {
ob->flag |= OB_DONE;
ob->recalc= OB_RECALC_OB|OB_RECALC_DATA;
Mat3CpyMat4(omat, ob->obmat);
VECCOPY(centn, cent);
Mat3MulVecfl(omat, centn);
ob->loc[0]+= centn[0];
ob->loc[1]+= centn[1];
ob->loc[2]+= centn[2];
where_is_object(scene, ob);
ignore_parent_tx(bmain, scene, ob);
if(tme && (tme->flag & ME_ISDONE)==0) {
mvert= tme->mvert;
for(a=0; a<tme->totvert; a++, mvert++) {
VecSubf(mvert->co, mvert->co, cent);
}
if (tme->key) {
KeyBlock *kb;
for (kb=tme->key->block.first; kb; kb=kb->next) {
float *fp= kb->data;
for (a=0; a<kb->totelem; a++, fp+=3) {
VecSubf(fp, fp, cent);
}
}
}
tme->flag |= ME_ISDONE;
}
}
}
ob= ob->id.next;
}
CTX_DATA_END;
}
tot_change++;
}
}
else if (ELEM(base->object->type, OB_CURVE, OB_SURF)) {
/* weak code here... (ton) */
if(obedit==base->object) {
ListBase *editnurb= curve_get_editcurve(obedit);
nu1= editnurb->first;
cu= obedit->data;
}
else {
cu= base->object->data;
nu1= cu->nurb.first;
}
if (cu->id.lib) {
tot_lib_error++;
} else {
if(centermode==2) {
VECCOPY(cent, give_cursor(scene, v3d));
Mat4Invert(base->object->imat, base->object->obmat);
Mat4MulVecfl(base->object->imat, cent);
/* don't allow Z change if curve is 2D */
if( !( cu->flag & CU_3D ) )
cent[2] = 0.0;
}
else {
INIT_MINMAX(min, max);
nu= nu1;
while(nu) {
minmaxNurb(nu, min, max);
nu= nu->next;
}
cent[0]= (min[0]+max[0])/2.0f;
cent[1]= (min[1]+max[1])/2.0f;
cent[2]= (min[2]+max[2])/2.0f;
}
nu= nu1;
while(nu) {
if(nu->type == CU_BEZIER) {
a= nu->pntsu;
while (a--) {
VecSubf(nu->bezt[a].vec[0], nu->bezt[a].vec[0], cent);
VecSubf(nu->bezt[a].vec[1], nu->bezt[a].vec[1], cent);
VecSubf(nu->bezt[a].vec[2], nu->bezt[a].vec[2], cent);
}
}
else {
a= nu->pntsu*nu->pntsv;
while (a--)
VecSubf(nu->bp[a].vec, nu->bp[a].vec, cent);
}
nu= nu->next;
}
if(centermode && obedit==0) {
Mat3CpyMat4(omat, base->object->obmat);
Mat3MulVecfl(omat, cent);
base->object->loc[0]+= cent[0];
base->object->loc[1]+= cent[1];
base->object->loc[2]+= cent[2];
where_is_object(scene, base->object);
ignore_parent_tx(bmain, scene, base->object);
}
tot_change++;
if(obedit) {
if (centermode==0) {
DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
}
break;
}
}
}
else if(base->object->type==OB_FONT) {
/* get from bb */
cu= base->object->data;
if(cu->bb==0) {
/* do nothing*/
} else if (cu->id.lib) {
tot_lib_error++;
} else {
cu->xof= -0.5f*( cu->bb->vec[4][0] - cu->bb->vec[0][0]);
cu->yof= -0.5f -0.5f*( cu->bb->vec[0][1] - cu->bb->vec[2][1]); /* extra 0.5 is the height o above line */
/* not really ok, do this better once! */
cu->xof /= cu->fsize;
cu->yof /= cu->fsize;
tot_change++;
}
}
else if(base->object->type==OB_ARMATURE) {
bArmature *arm = base->object->data;
if (arm->id.lib) {
tot_lib_error++;
} else if(arm->id.us>1) {
/*BKE_report(op->reports, RPT_ERROR, "Can't apply to a multi user armature");
return;*/
tot_multiuser_arm_error++;
} else {
/* Function to recenter armatures in editarmature.c
* Bone + object locations are handled there.
*/
docenter_armature(scene, v3d, base->object, centermode);
tot_change++;
where_is_object(scene, base->object);
ignore_parent_tx(bmain, scene, base->object);
if(obedit)
break;
}
}
base->object->recalc= OB_RECALC_OB|OB_RECALC_DATA;
}
}
CTX_DATA_END;
if (tot_change) {
ED_anim_dag_flush_update(C);
}
/* Warn if any errors occured */
if (tot_lib_error+tot_multiuser_arm_error) {
BKE_reportf(op->reports, RPT_WARNING, "%i Object(s) Not Centered, %i Changed:",tot_lib_error+tot_multiuser_arm_error, tot_change);
if (tot_lib_error)
BKE_reportf(op->reports, RPT_WARNING, "|%i linked library objects",tot_lib_error);
if (tot_multiuser_arm_error)
BKE_reportf(op->reports, RPT_WARNING, "|%i multiuser armature object(s)",tot_multiuser_arm_error);
}
return OPERATOR_FINISHED;
}
void OBJECT_OT_center_set(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Set Center";
ot->description = "Set the object's center, by either moving the data, or set to center of data, or use 3d cursor";
ot->idname= "OBJECT_OT_center_set";
/* api callbacks */
ot->invoke= WM_menu_invoke;
ot->exec= object_center_set_exec;
ot->poll= ED_operator_view3d_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
RNA_def_enum(ot->srna, "type", prop_set_center_types, 0, "Type", "");
}

File diff suppressed because it is too large Load Diff

View File

@@ -108,6 +108,12 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
return 1;
}
else if(CTX_data_equals(member, "object")) {
if(scene->basact)
CTX_data_id_pointer_set(result, &scene->basact->object->id);
return 1;
}
else if(CTX_data_equals(member, "edit_object")) {
/* convenience for now, 1 object per scene in editmode */
if(scene->obedit)

View File

@@ -408,8 +408,8 @@ void clear_wpaint_selectedfaces(Scene *scene)
if (!strcmp(curdef->name, name))
break;
if(curdef==NULL) {
int olddef= ob->actdef; /* tsk, add_defgroup sets the active defgroup */
curdef= add_defgroup_name (ob, name);
int olddef= ob->actdef; /* tsk, ED_vgroup_add sets the active defgroup */
curdef= ED_vgroup_add_name (ob, name);
ob->actdef= olddef;
}
@@ -431,9 +431,9 @@ void clear_wpaint_selectedfaces(Scene *scene)
faceverts[3]= mface->v4;
for (i=0; i<3 || faceverts[i]; i++) {
if(!((me->dvert+faceverts[i])->flag)) {
dw= verify_defweight(me->dvert+faceverts[i], vgroup);
dw= ED_vgroup_weight_verify(me->dvert+faceverts[i], vgroup);
if(dw) {
uw= verify_defweight(wp->wpaint_prev+faceverts[i], vgroup);
uw= ED_vgroup_weight_verify(wp->wpaint_prev+faceverts[i], vgroup);
uw->weight= dw->weight; /* set the undo weight */
dw->weight= paintweight;
@@ -442,11 +442,11 @@ void clear_wpaint_selectedfaces(Scene *scene)
if(j>=0) {
/* copy, not paint again */
if(vgroup_mirror != -1) {
dw= verify_defweight(me->dvert+j, vgroup_mirror);
uw= verify_defweight(wp->wpaint_prev+j, vgroup_mirror);
dw= ED_vgroup_weight_verify(me->dvert+j, vgroup_mirror);
uw= ED_vgroup_weight_verify(wp->wpaint_prev+j, vgroup_mirror);
} else {
dw= verify_defweight(me->dvert+j, vgroup);
uw= verify_defweight(wp->wpaint_prev+j, vgroup);
dw= ED_vgroup_weight_verify(me->dvert+j, vgroup);
uw= ED_vgroup_weight_verify(wp->wpaint_prev+j, vgroup);
}
uw->weight= dw->weight; /* set the undo weight */
dw->weight= paintweight;
@@ -963,20 +963,20 @@ void sample_wpaint(Scene *scene, ARegion *ar, View3D *v3d, int mode)
fac= MIN4(w1, w2, w3, w4);
if(w1==fac) {
dw= get_defweight(me->dvert+mface->v1, ob->actdef-1);
dw= ED_vgroup_weight_get(me->dvert+mface->v1, ob->actdef-1);
if(dw) ts->vgroup_weight= dw->weight; else ts->vgroup_weight= 0.0f;
}
else if(w2==fac) {
dw= get_defweight(me->dvert+mface->v2, ob->actdef-1);
dw= ED_vgroup_weight_get(me->dvert+mface->v2, ob->actdef-1);
if(dw) ts->vgroup_weight= dw->weight; else ts->vgroup_weight= 0.0f;
}
else if(w3==fac) {
dw= get_defweight(me->dvert+mface->v3, ob->actdef-1);
dw= ED_vgroup_weight_get(me->dvert+mface->v3, ob->actdef-1);
if(dw) ts->vgroup_weight= dw->weight; else ts->vgroup_weight= 0.0f;
}
else if(w4==fac) {
if(mface->v4) {
dw= get_defweight(me->dvert+mface->v4, ob->actdef-1);
dw= ED_vgroup_weight_get(me->dvert+mface->v4, ob->actdef-1);
if(dw) ts->vgroup_weight= dw->weight; else ts->vgroup_weight= 0.0f;
}
}
@@ -995,12 +995,12 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int alpha,
int vgroup= ob->actdef-1;
if(wp->flag & VP_ONLYVGROUP) {
dw= get_defweight(me->dvert+index, vgroup);
uw= get_defweight(wp->wpaint_prev+index, vgroup);
dw= ED_vgroup_weight_get(me->dvert+index, vgroup);
uw= ED_vgroup_weight_get(wp->wpaint_prev+index, vgroup);
}
else {
dw= verify_defweight(me->dvert+index, vgroup);
uw= verify_defweight(wp->wpaint_prev+index, vgroup);
dw= ED_vgroup_weight_verify(me->dvert+index, vgroup);
uw= ED_vgroup_weight_verify(wp->wpaint_prev+index, vgroup);
}
if(dw==NULL || uw==NULL)
return;
@@ -1012,9 +1012,9 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int alpha,
if(j>=0) {
/* copy, not paint again */
if(vgroup_mirror != -1)
uw= verify_defweight(me->dvert+j, vgroup_mirror);
uw= ED_vgroup_weight_verify(me->dvert+j, vgroup_mirror);
else
uw= verify_defweight(me->dvert+j, vgroup);
uw= ED_vgroup_weight_verify(me->dvert+j, vgroup);
uw->weight= dw->weight;
}
@@ -1070,7 +1070,7 @@ static int set_wpaint(bContext *C, wmOperator *op) /* toggle */
if(pchan->bone->flag & BONE_ACTIVE)
break;
if(pchan)
vertexgroup_select_by_name(ob, pchan->name);
ED_vgroup_select_by_name(ob, pchan->name);
}
}
else {
@@ -1222,7 +1222,7 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *event)
/* if nothing was added yet, we make dverts and a vertex deform group */
if (!me->dvert)
create_dverts(&me->id);
ED_vgroup_data_create(&me->id);
/* make mode data storage */
wpd= MEM_callocN(sizeof(struct WPaintData), "WPaintData");
@@ -1256,14 +1256,14 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *event)
if(pchan) {
bDeformGroup *dg= get_named_vertexgroup(ob, pchan->name);
if(dg==NULL)
dg= add_defgroup_name(ob, pchan->name); /* sets actdef */
dg= ED_vgroup_add_name(ob, pchan->name); /* sets actdef */
else
ob->actdef= get_defgroup_num(ob, dg);
}
}
}
if(ob->defbase.first==NULL) {
add_defgroup(ob);
ED_vgroup_add(ob);
}
// if(ob->lay & v3d->lay); else error("Active object is not in this layer");
@@ -1288,8 +1288,8 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *event)
if (!strcmp(curdef->name, name))
break;
if(curdef==NULL) {
int olddef= ob->actdef; /* tsk, add_defgroup sets the active defgroup */
curdef= add_defgroup_name (ob, name);
int olddef= ob->actdef; /* tsk, ED_vgroup_add sets the active defgroup */
curdef= ED_vgroup_add_name (ob, name);
ob->actdef= olddef;
}
@@ -1381,10 +1381,10 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
if(mface->v4) (me->dvert+mface->v4)->flag= 1;
if(wp->mode==VP_BLUR) {
MDeformWeight *dw, *(*dw_func)(MDeformVert *, int) = verify_defweight;
MDeformWeight *dw, *(*dw_func)(MDeformVert *, int) = ED_vgroup_weight_verify;
if(wp->flag & VP_ONLYVGROUP)
dw_func= get_defweight;
dw_func= ED_vgroup_weight_get;
dw= dw_func(me->dvert+mface->v1, ob->actdef-1);
if(dw) {paintweight+= dw->weight; totw++;}

View File

@@ -85,133 +85,6 @@
#include "buttons_intern.h" // own include
/********************** group operators *********************/
static int group_add_exec(bContext *C, wmOperator *op)
{
Main *bmain= CTX_data_main(C);
Scene *scene= CTX_data_scene(C);
Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
Base *base;
Group *group;
int value= RNA_enum_get(op->ptr, "group");
if(!ob)
return OPERATOR_CANCELLED;
base= object_in_scene(ob, scene);
if(!base)
return OPERATOR_CANCELLED;
if(value == -1)
group= add_group( "Group" );
else
group= BLI_findlink(&bmain->group, value);
if(group) {
add_to_group(group, ob);
ob->flag |= OB_FROMGROUP;
base->flag |= OB_FROMGROUP;
}
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
return OPERATOR_FINISHED;
}
static EnumPropertyItem group_items[]= {
{-1, "ADD_NEW", 0, "Add New Group", ""},
{0, NULL, 0, NULL, NULL}};
static EnumPropertyItem *group_itemf(bContext *C, PointerRNA *ptr, int *free)
{
EnumPropertyItem tmp = {0, "", 0, "", ""};
EnumPropertyItem *item= NULL;
Main *bmain;
Group *group;
int a, totitem= 0;
if(!C) /* needed for docs */
return group_items;
RNA_enum_items_add_value(&item, &totitem, group_items, -1);
bmain= CTX_data_main(C);
if(bmain->group.first)
RNA_enum_item_add_separator(&item, &totitem);
for(a=0, group=bmain->group.first; group; group=group->id.next, a++) {
tmp.value= a;
tmp.identifier= group->id.name+2;
tmp.name= group->id.name+2;
RNA_enum_item_add(&item, &totitem, &tmp);
}
RNA_enum_item_end(&item, &totitem);
*free= 1;
return item;
}
void OBJECT_OT_group_add(wmOperatorType *ot)
{
PropertyRNA *prop;
/* identifiers */
ot->name= "Add Group";
ot->idname= "OBJECT_OT_group_add";
/* api callbacks */
ot->exec= group_add_exec;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* properties */
prop= RNA_def_enum(ot->srna, "group", group_items, -1, "Group", "Group to add object to.");
RNA_def_enum_funcs(prop, group_itemf);
}
static int group_remove_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
Group *group= CTX_data_pointer_get_type(C, "group", &RNA_Group).data;
Base *base;
if(!ob || !group)
return OPERATOR_CANCELLED;
base= object_in_scene(ob, scene);
if(!base)
return OPERATOR_CANCELLED;
rem_from_group(group, ob);
if(find_group(ob, NULL) == NULL) {
ob->flag &= ~OB_FROMGROUP;
base->flag &= ~OB_FROMGROUP;
}
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
return OPERATOR_FINISHED;
}
void OBJECT_OT_group_remove(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Remove Group";
ot->idname= "OBJECT_OT_group_remove";
/* api callbacks */
ot->exec= group_remove_exec;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/********************** material slot operators *********************/
static int material_slot_add_exec(bContext *C, wmOperator *op)

View File

@@ -1198,7 +1198,7 @@ static void drawlattice__point(Lattice *lt, DispList *dl, int u, int v, int w, i
if(use_wcol) {
float col[3];
MDeformWeight *mdw= get_defweight (lt->dvert+index, use_wcol-1);
MDeformWeight *mdw= ED_vgroup_weight_get (lt->dvert+index, use_wcol-1);
weight_to_rgb(mdw?mdw->weight:0.0f, col, col+1, col+2);
glColor3fv(col);

View File

@@ -899,7 +899,7 @@ static void do_view3d_region_buttons(bContext *C, void *arg, int event)
Mesh *me= ob->data;
int a;
for(a=0; a<me->totvert; a++)
remove_vert_defgroup (ob, defGroup, a);
ED_vgroup_vert_remove (ob, defGroup, a);
DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
}
}

View File

@@ -58,6 +58,7 @@
#include "ED_armature.h"
#include "ED_particle.h"
#include "ED_curve.h"
#include "ED_mball.h"
#include "ED_mesh.h"
#include "ED_object.h"
#include "ED_screen.h"

View File

@@ -56,6 +56,8 @@ extern EnumPropertyItem brush_sculpt_tool_items[];
extern EnumPropertyItem unpack_method_items[];
extern EnumPropertyItem object_type_items[];
#endif /* RNA_ENUM_TYPES */

View File

@@ -64,6 +64,22 @@ static EnumPropertyItem parent_type_items[] = {
{PARBONE, "BONE", 0, "Bone", ""},
{0, NULL, 0, NULL, NULL}};
EnumPropertyItem object_type_items[] = {
{OB_MESH, "MESH", 0, "Mesh", ""},
{OB_CURVE, "CURVE", 0, "Curve", ""},
{OB_SURF, "SURFACE", 0, "Surface", ""},
{OB_MBALL, "META", 0, "Meta", ""},
{OB_FONT, "TEXT", 0, "Text", ""},
{0, "", 0, NULL, NULL},
{OB_ARMATURE, "ARMATURE", 0, "Armature", ""},
{OB_LATTICE, "LATTICE", 0, "Lattice", ""},
{OB_EMPTY, "EMPTY", 0, "Empty", ""},
{0, "", 0, NULL, NULL},
{OB_CAMERA, "CAMERA", 0, "Camera", ""},
{OB_LAMP, "LAMP", 0, "Lamp", ""},
{0, NULL, 0, NULL, NULL}
};
#ifdef RNA_RUNTIME
#include "DNA_key_types.h"

View File

@@ -177,7 +177,7 @@ void wm_event_do_notifiers(bContext *C)
do_anim= 1;
}
}
if(ELEM3(note->category, NC_SCENE, NC_OBJECT, NC_GEOM)) {
if(ELEM4(note->category, NC_SCENE, NC_OBJECT, NC_GEOM, NC_SCENE)) {
ED_info_stats_clear(CTX_data_scene(C));
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_INFO, NULL);
}