static bool edbm_bevel_calc(wmOperator *op) { BevelData *opdata = op->customdata; BMEditMesh *em = opdata->em; BMOperator bmop; const float offset = RNA_float_get(op->ptr, "offset"); const int offset_type = RNA_enum_get(op->ptr, "offset_type"); const int segments = RNA_int_get(op->ptr, "segments"); const bool vertex_only = RNA_boolean_get(op->ptr, "vertex_only"); /* revert to original mesh */ if (opdata->is_modal) { EDBM_redo_state_restore(opdata->mesh_backup, em, false); } EDBM_op_init(em, &bmop, op, "bevel geom=%hev offset=%f segments=%i vertex_only=%b offset_type=%i", BM_ELEM_SELECT, offset, segments, vertex_only, offset_type); BMO_op_exec(em->bm, &bmop); if (offset != 0.0f) { /* not essential, but we may have some loose geometry that * won't get bevel'd and better not leave it selected */ EDBM_flag_disable_all(em, BM_ELEM_SELECT); BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true); } /* no need to de-select existing geometry */ if (!EDBM_op_finish(em, &bmop, op, true)) return false; EDBM_mesh_normals_update(opdata->em); EDBM_update_generic(opdata->em, true, true); return true; }
static int gpencil_select_all_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); int action = RNA_enum_get(op->ptr, "action"); if (gpd == NULL) { BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data"); return OPERATOR_CANCELLED; } /* for "toggle", test for existing selected strokes */ if (action == SEL_TOGGLE) { action = SEL_SELECT; CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes) { if (gps->flag & GP_STROKE_SELECT) { action = SEL_DESELECT; break; // XXX: this only gets out of the inner loop... } } CTX_DATA_END; }
static int rigidbody_object_add_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_active_context(C); int type = RNA_enum_get(op->ptr, "type"); bool changed; /* apply to active object */ changed = ED_rigidbody_object_add(bmain, scene, ob, type, op->reports); if (changed) { /* send updates */ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); WM_event_add_notifier(C, NC_OBJECT | ND_POINTCACHE, NULL); /* done */ return OPERATOR_FINISHED; } else { return OPERATOR_CANCELLED; } }
static void bake_init_api_data(wmOperator *op, bContext *C, BakeAPIRender *bkr) { bool is_save_internal; bkr->ob = CTX_data_active_object(C); bkr->main = CTX_data_main(C); bkr->scene = CTX_data_scene(C); bkr->pass_type = RNA_enum_get(op->ptr, "type"); bkr->margin = RNA_int_get(op->ptr, "margin"); bkr->save_mode = RNA_enum_get(op->ptr, "save_mode"); is_save_internal = (bkr->save_mode == R_BAKE_SAVE_INTERNAL); bkr->is_clear = RNA_boolean_get(op->ptr, "use_clear"); bkr->is_split_materials = (!is_save_internal) && RNA_boolean_get(op->ptr, "use_split_materials"); bkr->is_automatic_name = RNA_boolean_get(op->ptr, "use_automatic_name"); bkr->use_selected_to_active = RNA_boolean_get(op->ptr, "use_selected_to_active"); bkr->cage_extrusion = RNA_float_get(op->ptr, "cage_extrusion"); bkr->normal_space = RNA_enum_get(op->ptr, "normal_space"); bkr->normal_swizzle[0] = RNA_enum_get(op->ptr, "normal_r"); bkr->normal_swizzle[1] = RNA_enum_get(op->ptr, "normal_g"); bkr->normal_swizzle[2] = RNA_enum_get(op->ptr, "normal_b"); bkr->width = RNA_int_get(op->ptr, "width"); bkr->height = RNA_int_get(op->ptr, "height"); bkr->identifier = ""; RNA_string_get(op->ptr, "cage", bkr->custom_cage); if ((!is_save_internal) && bkr->is_automatic_name) { PropertyRNA *prop = RNA_struct_find_property(op->ptr, "type"); RNA_property_enum_identifier(C, op->ptr, prop, bkr->pass_type, &bkr->identifier); } if (bkr->use_selected_to_active) CTX_data_selected_objects(C, &bkr->selected_objects); bkr->reports = op->reports; /* XXX hack to force saving to always be internal. Whether (and how) to support * external saving will be addressed later */ bkr->save_mode = R_BAKE_SAVE_INTERNAL; }
static int parent_drop_exec(bContext *C, wmOperator *op) { Object *par = NULL, *ob = NULL; Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); int partype = -1; char parname[MAX_ID_NAME], childname[MAX_ID_NAME]; partype = RNA_enum_get(op->ptr, "type"); RNA_string_get(op->ptr, "parent", parname); par = (Object *)BKE_libblock_find_name(ID_OB, parname); RNA_string_get(op->ptr, "child", childname); ob = (Object *)BKE_libblock_find_name(ID_OB, childname); ED_object_parent_set(op->reports, bmain, scene, ob, par, partype); DAG_scene_sort(bmain, scene); DAG_ids_flush_update(bmain, 0); WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL); return OPERATOR_FINISHED; }
static int unpack_item_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); ID *id; char idname[MAX_ID_NAME - 2]; int type = RNA_int_get(op->ptr, "id_type"); int method = RNA_enum_get(op->ptr, "method"); RNA_string_get(op->ptr, "id_name", idname); id = BKE_libblock_find_name(type, idname); if (id == NULL) { BKE_report(op->reports, RPT_WARNING, "No packed file"); return OPERATOR_CANCELLED; } if (method != PF_KEEP) BKE_unpack_id(bmain, id, op->reports, method); /* XXX PF_ASK can't work here */ G.fileflags &= ~G_AUTOPACK; return OPERATOR_FINISHED; }
static int actkeys_mirror_exec(bContext *C, wmOperator *op) { bAnimContext ac; short mode; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; /* get mirroring mode */ mode= RNA_enum_get(op->ptr, "type"); /* mirror keyframes */ mirror_action_keys(&ac, mode); /* validate keyframes after editing */ ANIM_editkeyframes_refresh(&ac); /* set notifier that keyframes have changed */ WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL); return OPERATOR_FINISHED; }
/* show popup to determine settings */ static int pose_calculate_paths_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); if (ELEM(NULL, ob, ob->pose)) return OPERATOR_CANCELLED; /* set default settings from existing/stored settings */ { bAnimVizSettings *avs = &ob->pose->avs; PointerRNA avs_ptr; RNA_int_set(op->ptr, "start_frame", avs->path_sf); RNA_int_set(op->ptr, "end_frame", avs->path_ef); RNA_pointer_create(NULL, &RNA_AnimVizMotionPaths, avs, &avs_ptr); RNA_enum_set(op->ptr, "bake_location", RNA_enum_get(&avs_ptr, "bake_location")); } /* show popup dialog to allow editing of range... */ // FIXME: hardcoded dimensions here are just arbitrary return WM_operator_props_dialog_popup(C, op, 10 * UI_UNIT_X, 10 * UI_UNIT_Y); }
static int sensor_add_exec(bContext *C, wmOperator *op) { Object *ob; bSensor *sens; PointerRNA sens_ptr; PropertyRNA *prop; const char *sens_name; char name[MAX_NAME]; int type = RNA_enum_get(op->ptr, "type"); ob = edit_object_property_get(C, op); if (!ob) return OPERATOR_CANCELLED; sens = new_sensor(type); BLI_addtail(&(ob->sensors), sens); /* set the sensor name based on rna type enum */ RNA_pointer_create((ID *)ob, &RNA_Sensor, sens, &sens_ptr); prop = RNA_struct_find_property(&sens_ptr, "type"); RNA_string_get(op->ptr, "name", name); if (*name) { BLI_strncpy(sens->name, name, sizeof(sens->name)); } else { RNA_property_enum_name(C, &sens_ptr, prop, RNA_property_enum_get(&sens_ptr, prop), &sens_name); BLI_strncpy(sens->name, sens_name, sizeof(sens->name)); } BLI_uniquename(&ob->sensors, sens, DATA_("Sensor"), '.', offsetof(bSensor, name), sizeof(sens->name)); ob->scaflag |= OB_SHOWSENS; WM_event_add_notifier(C, NC_LOGIC, NULL); return OPERATOR_FINISHED; }
static int actuator_add_exec(bContext *C, wmOperator *op) { Object *ob; bActuator *act; PointerRNA act_ptr; PropertyRNA *prop; const char *act_name; char name[MAX_NAME]; int type = RNA_enum_get(op->ptr, "type"); ob = edit_object_property_get(C, op); if (!ob) return OPERATOR_CANCELLED; act = new_actuator(type); BLI_addtail(&(ob->actuators), act); /* set the actuator name based on rna type enum */ RNA_pointer_create((ID *)ob, &RNA_Actuator, act, &act_ptr); prop = RNA_struct_find_property(&act_ptr, "type"); RNA_string_get(op->ptr, "name", name); if (*name) { BLI_strncpy(act->name, name, sizeof(act->name)); } else { RNA_property_enum_name(C, &act_ptr, prop, RNA_property_enum_get(&act_ptr, prop), &act_name); BLI_strncpy(act->name, act_name, sizeof(act->name)); } make_unique_prop_names(C, act->name); ob->scaflag |= OB_SHOWACT; WM_event_add_notifier(C, NC_LOGIC, NULL); return OPERATOR_FINISHED; }
static int transformops_data(bContext *C, wmOperator *op, wmEvent *event) { int retval = 1; if (op->customdata == NULL) { TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data2"); TransformModeItem *tmode; int mode = -1; for (tmode = transform_modes; tmode->idname; tmode++) { if (op->type->idname == tmode->idname) { mode = tmode->mode; break; } } if (mode == -1) { mode = RNA_enum_get(op->ptr, "mode"); } retval = initTransform(C, t, op, event, mode); G.moving = 1; /* store data */ if(retval) { op->customdata = t; } else { MEM_freeN(t); } } return retval; /* return 0 on error */ }
static int outliner_group_operation_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); SpaceOops *soops = CTX_wm_space_outliner(C); int event; /* check for invalid states */ if (soops == NULL) return OPERATOR_CANCELLED; event = RNA_enum_get(op->ptr, "type"); switch (event) { case 0: outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_group_cb); break; case 1: outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_local_cb); break; case 2: outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_linkobs2scene_cb); break; case 3: outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_instance_cb); break; case 4: outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_visibility_cb); break; case 5: outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_selectability_cb); break; case 6: outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_toggle_renderability_cb); break; case 7: outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_rename_cb); break; default: BLI_assert(0); return OPERATOR_CANCELLED; } if (event == 3) { /* instance */ /* works without this except if you try render right after, see: 22027 */ DAG_relations_tag_update(CTX_data_main(C)); } ED_undo_push(C, prop_group_op_types[event].name); WM_event_add_notifier(C, NC_GROUP, NULL); return OPERATOR_FINISHED; }
/* Select or deselect all MetaElements */ static int mball_select_all_exec(bContext *C, wmOperator *op) { Object *obedit = CTX_data_edit_object(C); MetaBall *mb = (MetaBall *)obedit->data; MetaElem *ml; int action = RNA_enum_get(op->ptr, "action"); if (mb->editelems->first == NULL) return OPERATOR_CANCELLED; if (action == SEL_TOGGLE) { action = SEL_SELECT; for (ml = mb->editelems->first; ml; ml = ml->next) { if (ml->flag & SELECT) { action = SEL_DESELECT; break; } } } switch (action) { case SEL_SELECT: BKE_mball_select_all(mb); break; case SEL_DESELECT: BKE_mball_deselect_all(mb); break; case SEL_INVERT: BKE_mball_select_swap(mb); break; } WM_event_add_notifier(C, NC_GEOM | ND_SELECT, mb); return OPERATOR_FINISHED; }
static int object_hook_remove_exec(bContext *C, wmOperator *op) { int num= RNA_enum_get(op->ptr, "modifier"); Object *ob=NULL; HookModifierData *hmd=NULL; ob = CTX_data_edit_object(C); hmd = (HookModifierData *)BLI_findlink(&ob->modifiers, num); if (!ob || !hmd) { BKE_report(op->reports, RPT_ERROR, "Couldn't find hook modifier"); return OPERATOR_CANCELLED; } /* remove functionality */ BLI_remlink(&ob->modifiers, (ModifierData *)hmd); modifier_free((ModifierData *)hmd); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob); return OPERATOR_FINISHED; }
static int actkeys_mirror_exec(bContext *C, wmOperator *op) { bAnimContext ac; short mode; /* get editor data */ if (ANIM_animdata_get_context(C, &ac) == 0) return OPERATOR_CANCELLED; /* XXX... */ if (ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) return OPERATOR_PASS_THROUGH; /* get mirroring mode */ mode = RNA_enum_get(op->ptr, "type"); /* mirror keyframes */ mirror_action_keys(&ac, mode); /* set notifier that keyframes have changed */ WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); return OPERATOR_FINISHED; }
/* Note: DT_layers_select_dst_items enum is from rna_modifier.c */ static EnumPropertyItem *dt_layers_select_dst_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free) { EnumPropertyItem *item = NULL; int totitem = 0; const int layers_select_src = RNA_enum_get(ptr, "layers_select_src"); if (!C) { /* needed for docs and i18n tools */ return DT_layers_select_dst_items; } if (layers_select_src == DT_LAYERS_ACTIVE_SRC || layers_select_src >= 0) { RNA_enum_items_add_value(&item, &totitem, DT_layers_select_dst_items, DT_LAYERS_ACTIVE_DST); } RNA_enum_items_add_value(&item, &totitem, DT_layers_select_dst_items, DT_LAYERS_NAME_DST); RNA_enum_items_add_value(&item, &totitem, DT_layers_select_dst_items, DT_LAYERS_INDEX_DST); /* No 'specific' to-layers here, since we may transfer to several objects at once! */ RNA_enum_item_end(&item, &totitem); *r_free = true; return item; }
static int add_primitive_cylinder_exec(bContext *C, wmOperator *op) { Object *obedit; Mesh *me; BMEditMesh *em; float loc[3], rot[3], mat[4][4], dia; int enter_editmode; int state, cap_end, cap_tri; unsigned int layer; cap_end = RNA_enum_get(op->ptr, "end_fill_type"); cap_tri = (cap_end == 2); ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, NULL); make_prim_init(C, "Cylinder", &dia, mat, &state, loc, rot, layer); obedit = CTX_data_edit_object(C); me = obedit->data; em = me->edit_btmesh; if (!EDBM_op_call_and_selectf( em, op, "vertout", "create_cone segments=%i diameter1=%f diameter2=%f cap_ends=%b cap_tris=%b depth=%f mat=%m4", RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius"), RNA_float_get(op->ptr, "radius"), cap_end, cap_tri, RNA_float_get(op->ptr, "depth"), mat)) { return OPERATOR_CANCELLED; } make_prim_finish(C, &state, enter_editmode); return OPERATOR_FINISHED; }
static int outliner_id_operation_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); SpaceOops *soops = CTX_wm_space_outliner(C); int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; eOutlinerIdOpTypes event; /* check for invalid states */ if (soops == NULL) return OPERATOR_CANCELLED; set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); event = RNA_enum_get(op->ptr, "type"); switch (event) { case OUTLINER_IDOP_UNLINK: { /* unlink datablock from its parent */ switch (idlevel) { case ID_AC: outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_action_cb); WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL); ED_undo_push(C, "Unlink action"); break; case ID_MA: outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_material_cb); WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, NULL); ED_undo_push(C, "Unlink material"); break; case ID_TE: outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_texture_cb); WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, NULL); ED_undo_push(C, "Unlink texture"); break; case ID_WO: outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_world_cb); WM_event_add_notifier(C, NC_SCENE | ND_WORLD, NULL); ED_undo_push(C, "Unlink world"); break; default: BKE_report(op->reports, RPT_WARNING, "Not yet implemented"); break; } } break; case OUTLINER_IDOP_LOCAL: { /* make local */ outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_local_cb); ED_undo_push(C, "Localized Data"); } break; case OUTLINER_IDOP_SINGLE: { /* make single user */ switch (idlevel) { case ID_AC: outliner_do_libdata_operation(C, scene, soops, &soops->tree, singleuser_action_cb); WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, NULL); ED_undo_push(C, "Single-User Action"); break; case ID_WO: outliner_do_libdata_operation(C, scene, soops, &soops->tree, singleuser_world_cb); WM_event_add_notifier(C, NC_SCENE | ND_WORLD, NULL); ED_undo_push(C, "Single-User World"); break; default: BKE_report(op->reports, RPT_WARNING, "Not yet implemented"); break; } } break; case OUTLINER_IDOP_FAKE_ADD: { /* set fake user */ outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_fake_user_set_cb); WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL); ED_undo_push(C, "Add Fake User"); } break; case OUTLINER_IDOP_FAKE_CLEAR: { /* clear fake user */ outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_fake_user_clear_cb); WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL); ED_undo_push(C, "Clear Fake User"); } break; case OUTLINER_IDOP_RENAME: { /* rename */ outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_rename_cb); WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL); ED_undo_push(C, "Rename"); } break; case OUTLINER_IDOP_SELECT_LINKED: outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_select_linked_cb); ED_undo_push(C, "Select"); break; default: // invalid - unhandled break; } /* wrong notifier still... */ WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL); // XXX: this is just so that outliner is always up to date WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL); return OPERATOR_FINISHED; }
static int outliner_object_operation_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); SpaceOops *soops = CTX_wm_space_outliner(C); int event; const char *str = NULL; /* check for invalid states */ if (soops == NULL) return OPERATOR_CANCELLED; event = RNA_enum_get(op->ptr, "type"); if (event == OL_OP_SELECT) { Scene *sce = scene; // to be able to delete, scenes are set... outliner_do_object_operation(C, scene, soops, &soops->tree, object_select_cb); if (scene != sce) { ED_screen_set_scene(C, CTX_wm_screen(C), sce); } str = "Select Objects"; WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } else if (event == OL_OP_SELECT_HIERARCHY) { Scene *sce = scene; // to be able to delete, scenes are set... outliner_do_object_operation(C, scene, soops, &soops->tree, object_select_hierarchy_cb); if (scene != sce) { ED_screen_set_scene(C, CTX_wm_screen(C), sce); } str = "Select Object Hierarchy"; WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } else if (event == OL_OP_DESELECT) { outliner_do_object_operation(C, scene, soops, &soops->tree, object_deselect_cb); str = "Deselect Objects"; WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } else if (event == OL_OP_DELETE) { outliner_do_object_operation(C, scene, soops, &soops->tree, object_delete_cb); /* XXX: tree management normally happens from draw_outliner(), but when * you're clicking to fast on Delete object from context menu in * outliner several mouse events can be handled in one cycle without * handling notifiers/redraw which leads to deleting the same object twice. * cleanup tree here to prevent such cases. */ outliner_cleanup_tree(soops); DAG_relations_tag_update(bmain); str = "Delete Objects"; WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); } else if (event == OL_OP_LOCALIZED) { /* disabled, see above enum (ton) */ outliner_do_object_operation(C, scene, soops, &soops->tree, id_local_cb); str = "Localized Objects"; } else if (event == OL_OP_TOGVIS) { outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_visibility_cb); str = "Toggle Visibility"; WM_event_add_notifier(C, NC_SCENE | ND_OB_VISIBLE, scene); } else if (event == OL_OP_TOGSEL) { outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_selectability_cb); str = "Toggle Selectability"; WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); } else if (event == OL_OP_TOGREN) { outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_renderability_cb); str = "Toggle Renderability"; WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, scene); } else if (event == OL_OP_RENAME) { outliner_do_object_operation(C, scene, soops, &soops->tree, item_rename_cb); str = "Rename Object"; } ED_undo_push(C, str); return OPERATOR_FINISHED; }
static int outliner_data_operation_exec(bContext *C, wmOperator *op) { SpaceOops *soops = CTX_wm_space_outliner(C); int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; int event; /* check for invalid states */ if (soops == NULL) return OPERATOR_CANCELLED; event = RNA_enum_get(op->ptr, "type"); set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel); if (event <= 0) return OPERATOR_CANCELLED; switch (datalevel) { case TSE_POSE_CHANNEL: { outliner_do_data_operation(soops, datalevel, event, &soops->tree, pchan_cb, NULL); WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL); ED_undo_push(C, "PoseChannel operation"); } break; case TSE_BONE: { outliner_do_data_operation(soops, datalevel, event, &soops->tree, bone_cb, NULL); WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL); ED_undo_push(C, "Bone operation"); } break; case TSE_EBONE: { outliner_do_data_operation(soops, datalevel, event, &soops->tree, ebone_cb, NULL); WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL); ED_undo_push(C, "EditBone operation"); } break; case TSE_SEQUENCE: { Scene *scene = CTX_data_scene(C); outliner_do_data_operation(soops, datalevel, event, &soops->tree, sequence_cb, scene); } break; case TSE_RNA_STRUCT: if (event == 5) { outliner_do_data_operation(soops, datalevel, event, &soops->tree, data_select_linked_cb, C); } break; default: BKE_report(op->reports, RPT_WARNING, "Not yet implemented"); break; } return OPERATOR_FINISHED; }
/* Used by both OBJECT_OT_data_transfer and OBJECT_OT_datalayout_transfer */ static bool data_transfer_draw_check_prop(PointerRNA *ptr, PropertyRNA *prop) { PropertyRNA *prop_other; const char *prop_id = RNA_property_identifier(prop); const int data_type = RNA_enum_get(ptr, "data_type"); bool use_auto_transform = false; bool use_max_distance = false; bool use_modifier = false; if ((prop_other = RNA_struct_find_property(ptr, "use_auto_transform"))) { use_auto_transform = RNA_property_boolean_get(ptr, prop_other); } if ((prop_other = RNA_struct_find_property(ptr, "use_max_distance"))) { use_max_distance = RNA_property_boolean_get(ptr, prop_other); } if ((prop_other = RNA_struct_find_property(ptr, "modifier"))) { use_modifier = RNA_property_is_set(ptr, prop_other); } if (STREQ(prop_id, "modifier")) { return use_modifier; } if (use_modifier) { /* Hide everything but 'modifier' property, if set. */ return false; } if (STREQ(prop_id, "use_object_transform") && use_auto_transform) { return false; } if (STREQ(prop_id, "max_distance") && !use_max_distance) { return false; } if (STREQ(prop_id, "islands_precision") && !DT_DATATYPE_IS_LOOP(data_type)) { return false; } if (STREQ(prop_id, "vert_mapping") && !DT_DATATYPE_IS_VERT(data_type)) { return false; } if (STREQ(prop_id, "edge_mapping") && !DT_DATATYPE_IS_EDGE(data_type)) { return false; } if (STREQ(prop_id, "loop_mapping") && !DT_DATATYPE_IS_LOOP(data_type)) { return false; } if (STREQ(prop_id, "poly_mapping") && !DT_DATATYPE_IS_POLY(data_type)) { return false; } if ((STREQ(prop_id, "layers_select_src") || STREQ(prop_id, "layers_select_dst")) && !DT_DATATYPE_IS_MULTILAYERS(data_type)) { return false; } /* Else, show it! */ return true; }
void BlenderSync::sync_camera(BL::RenderSettings& b_render, BL::Object& b_override, int width, int height) { BlenderCamera bcam; blender_camera_init(&bcam, b_render); /* pixel aspect */ bcam.pixelaspect.x = b_render.pixel_aspect_x(); bcam.pixelaspect.y = b_render.pixel_aspect_y(); bcam.shuttertime = b_render.motion_blur_shutter(); BL::CurveMapping b_shutter_curve(b_render.motion_blur_shutter_curve()); curvemapping_to_array(b_shutter_curve, bcam.shutter_curve, RAMP_TABLE_SIZE); PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles"); switch(RNA_enum_get(&cscene, "motion_blur_position")) { case 0: bcam.motion_position = Camera::MOTION_POSITION_START; break; case 1: bcam.motion_position = Camera::MOTION_POSITION_CENTER; break; case 2: bcam.motion_position = Camera::MOTION_POSITION_END; break; default: bcam.motion_position = Camera::MOTION_POSITION_CENTER; break; } switch(RNA_enum_get(&cscene, "rolling_shutter_type")) { case 0: bcam.rolling_shutter_type = Camera::ROLLING_SHUTTER_NONE; break; case 1: bcam.rolling_shutter_type = Camera::ROLLING_SHUTTER_TOP; break; default: bcam.rolling_shutter_type = Camera::ROLLING_SHUTTER_NONE; break; } bcam.rolling_shutter_duration = RNA_float_get(&cscene, "rolling_shutter_duration"); /* border */ if(b_render.use_border()) { bcam.border.left = b_render.border_min_x(); bcam.border.right = b_render.border_max_x(); bcam.border.bottom = b_render.border_min_y(); bcam.border.top = b_render.border_max_y(); } /* camera object */ BL::Object b_ob = b_scene.camera(); if(b_override) b_ob = b_override; if(b_ob) { BL::Array<float, 16> b_ob_matrix; blender_camera_from_object(&bcam, b_engine, b_ob); b_engine.camera_model_matrix(b_ob, b_ob_matrix); bcam.matrix = get_transform(b_ob_matrix); } /* sync */ Camera *cam = scene->camera; blender_camera_sync(cam, &bcam, width, height); }
static int pose_select_hierarchy_exec(bContext *C, wmOperator *op) { Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); bArmature *arm = ob->data; Bone *curbone, *pabone, *chbone; int direction = RNA_enum_get(op->ptr, "direction"); const bool add_to_sel = RNA_boolean_get(op->ptr, "extend"); bool found = false; CTX_DATA_BEGIN (C, bPoseChannel *, pchan, visible_pose_bones) { curbone = pchan->bone; if ((curbone->flag & BONE_UNSELECTABLE) == 0) { if (curbone == arm->act_bone) { if (direction == BONE_SELECT_PARENT) { if (pchan->parent == NULL) continue; else pabone = pchan->parent->bone; if (PBONE_SELECTABLE(arm, pabone)) { if (!add_to_sel) curbone->flag &= ~BONE_SELECTED; pabone->flag |= BONE_SELECTED; arm->act_bone = pabone; found = 1; break; } } else { /* direction == BONE_SELECT_CHILD */ /* the child member is only assigned to connected bones, see [#30340] */ #if 0 if (pchan->child == NULL) continue; else chbone = pchan->child->bone; #else /* instead. find _any_ visible child bone, using the first one is a little arbitrary - campbell */ chbone = pchan->child ? pchan->child->bone : NULL; if (chbone == NULL) { bPoseChannel *pchan_child; for (pchan_child = ob->pose->chanbase.first; pchan_child; pchan_child = pchan_child->next) { /* possible we have multiple children, some invisible */ if (PBONE_SELECTABLE(arm, pchan_child->bone)) { if (pchan_child->parent == pchan) { chbone = pchan_child->bone; break; } } } } if (chbone == NULL) continue; #endif if (PBONE_SELECTABLE(arm, chbone)) { if (!add_to_sel) curbone->flag &= ~BONE_SELECTED; chbone->flag |= BONE_SELECTED; arm->act_bone = chbone; found = 1; break; } } } } }
/* function used for WM_OT_save_mainfile too */ static int wm_collada_export_exec(bContext *C, wmOperator *op) { char filepath[FILE_MAX]; int apply_modifiers; int export_mesh_type; int selected; int include_children; int include_armatures; int include_shapekeys; int deform_bones_only; int include_uv_textures; int include_material_textures; int use_texture_copies; int active_uv_only; int triangulate; int use_object_instantiation; int sort_by_name; int export_transformation_type; int open_sim; int export_count; if (!RNA_struct_property_is_set(op->ptr, "filepath")) { BKE_report(op->reports, RPT_ERROR, "No filename given"); return OPERATOR_CANCELLED; } RNA_string_get(op->ptr, "filepath", filepath); BLI_ensure_extension(filepath, sizeof(filepath), ".dae"); /* Avoid File write exceptions in Collada */ if (!BLI_exists(filepath)) { BLI_make_existing_file(filepath); if (!BLI_file_touch(filepath)) { BKE_report(op->reports, RPT_ERROR, "Can't create export file"); fprintf(stdout, "Collada export: Can not create: %s\n", filepath); return OPERATOR_CANCELLED; } } else if (!BLI_file_is_writable(filepath)) { BKE_report(op->reports, RPT_ERROR, "Can't overwrite export file"); fprintf(stdout, "Collada export: Can not modify: %s\n", filepath); return OPERATOR_CANCELLED; } /* Now the exporter can create and write the export file */ /* Options panel */ apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers"); export_mesh_type = RNA_enum_get(op->ptr, "export_mesh_type_selection"); selected = RNA_boolean_get(op->ptr, "selected"); include_children = RNA_boolean_get(op->ptr, "include_children"); include_armatures = RNA_boolean_get(op->ptr, "include_armatures"); include_shapekeys = RNA_boolean_get(op->ptr, "include_shapekeys"); deform_bones_only = RNA_boolean_get(op->ptr, "deform_bones_only"); include_uv_textures = RNA_boolean_get(op->ptr, "include_uv_textures"); include_material_textures = RNA_boolean_get(op->ptr, "include_material_textures"); use_texture_copies = RNA_boolean_get(op->ptr, "use_texture_copies"); active_uv_only = RNA_boolean_get(op->ptr, "active_uv_only"); triangulate = RNA_boolean_get(op->ptr, "triangulate"); use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation"); sort_by_name = RNA_boolean_get(op->ptr, "sort_by_name"); export_transformation_type = RNA_enum_get(op->ptr, "export_transformation_type_selection"); open_sim = RNA_boolean_get(op->ptr, "open_sim"); /* get editmode results */ ED_object_editmode_load(CTX_data_edit_object(C)); export_count = collada_export(CTX_data_scene(C), filepath, apply_modifiers, export_mesh_type, selected, include_children, include_armatures, include_shapekeys, deform_bones_only, active_uv_only, include_uv_textures, include_material_textures, use_texture_copies, triangulate, use_object_instantiation, sort_by_name, export_transformation_type, open_sim); if (export_count == 0) { BKE_report(op->reports, RPT_WARNING, "Export file is empty"); return OPERATOR_CANCELLED; } else { char buff[100]; sprintf(buff, "Exported %d Objects", export_count); BKE_report(op->reports, RPT_INFO, buff); return OPERATOR_FINISHED; } }
/* Note: rna_enum_dt_layers_select_src_items enum is from rna_modifier.c */ static EnumPropertyItem *dt_layers_select_src_itemf( bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free) { EnumPropertyItem *item = NULL, tmp_item = {0}; int totitem = 0; const int data_type = RNA_enum_get(ptr, "data_type"); if (!C) { /* needed for docs and i18n tools */ return rna_enum_dt_layers_select_src_items; } RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_ACTIVE_SRC); RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_ALL_SRC); if (data_type == DT_TYPE_MDEFORMVERT) { Object *ob_src = CTX_data_active_object(C); if (BKE_object_pose_armature_get(ob_src)) { RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_VGROUP_SRC_BONE_SELECT); RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_VGROUP_SRC_BONE_DEFORM); } if (ob_src) { bDeformGroup *dg; int i; RNA_enum_item_add_separator(&item, &totitem); for (i = 0, dg = ob_src->defbase.first; dg; i++, dg = dg->next) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = dg->name; RNA_enum_item_add(&item, &totitem, &tmp_item); } } } else if (data_type == DT_TYPE_SHAPEKEY) { /* TODO */ } else if (data_type == DT_TYPE_UV) { Object *ob_src = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); if (ob_src) { DerivedMesh *dm_src; CustomData *pdata; int num_data, i; /* XXX Is this OK? */ dm_src = mesh_get_derived_final(scene, ob_src, CD_MASK_BAREMESH | CD_MTEXPOLY); pdata = dm_src->getPolyDataLayout(dm_src); num_data = CustomData_number_of_layers(pdata, CD_MTEXPOLY); RNA_enum_item_add_separator(&item, &totitem); for (i = 0; i < num_data; i++) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(pdata, CD_MTEXPOLY, i); RNA_enum_item_add(&item, &totitem, &tmp_item); } } } else if (data_type == DT_TYPE_VCOL) { Object *ob_src = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); if (ob_src) { DerivedMesh *dm_src; CustomData *ldata; int num_data, i; /* XXX Is this OK? */ dm_src = mesh_get_derived_final(scene, ob_src, CD_MASK_BAREMESH | CD_MLOOPCOL); ldata = dm_src->getLoopDataLayout(dm_src); num_data = CustomData_number_of_layers(ldata, CD_MLOOPCOL); RNA_enum_item_add_separator(&item, &totitem); for (i = 0; i < num_data; i++) { tmp_item.value = i; tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(ldata, CD_MLOOPCOL, i); RNA_enum_item_add(&item, &totitem, &tmp_item); } } } RNA_enum_item_end(&item, &totitem); *r_free = true; return item; }
static int datalayout_transfer_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob_act = ED_object_active_context(C); DataTransferModifierData *dtmd; dtmd = (DataTransferModifierData *)edit_modifier_property_get(op, ob_act, eModifierType_DataTransfer); /* If we have a modifier, we transfer data layout from this modifier's source object to active one. * Else, we transfer data layout from active object to all selected ones. */ if (dtmd) { Object *ob_src = dtmd->ob_source; Object *ob_dst = ob_act; const bool use_delete = false; /* Never when used from modifier, for now. */ if (!ob_src) { return OPERATOR_CANCELLED; } BKE_object_data_transfer_layout(scene, ob_src, ob_dst, dtmd->data_types, use_delete, dtmd->layers_select_src, dtmd->layers_select_dst); DAG_id_tag_update(&ob_dst->id, OB_RECALC_DATA); } else { Object *ob_src = ob_act; ListBase ctx_objects; CollectionPointerLink *ctx_ob_dst; const int data_type = RNA_enum_get(op->ptr, "data_type"); const bool use_delete = RNA_boolean_get(op->ptr, "use_delete"); const int layers_src = RNA_enum_get(op->ptr, "layers_select_src"); const int layers_dst = RNA_enum_get(op->ptr, "layers_select_dst"); int layers_select_src[DT_MULTILAYER_INDEX_MAX] = {0}; int layers_select_dst[DT_MULTILAYER_INDEX_MAX] = {0}; const int fromto_idx = BKE_object_data_transfer_dttype_to_srcdst_index(data_type); if (fromto_idx != DT_MULTILAYER_INDEX_INVALID) { layers_select_src[fromto_idx] = layers_src; layers_select_dst[fromto_idx] = layers_dst; } data_transfer_exec_preprocess_objects(C, op, ob_src, &ctx_objects, false); for (ctx_ob_dst = ctx_objects.first; ctx_ob_dst; ctx_ob_dst = ctx_ob_dst->next) { Object *ob_dst = ctx_ob_dst->ptr.data; if (data_transfer_exec_is_object_valid(op, ob_src, ob_dst, false)) { BKE_object_data_transfer_layout(scene, ob_src, ob_dst, data_type, use_delete, layers_select_src, layers_select_dst); } DAG_id_tag_update(&ob_dst->id, OB_RECALC_DATA); } BLI_freelistN(&ctx_objects); } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, NULL); return OPERATOR_FINISHED; }
static void blender_camera_from_object(BlenderCamera *bcam, BL::RenderEngine& b_engine, BL::Object& b_ob, bool skip_panorama = false) { BL::ID b_ob_data = b_ob.data(); if(b_ob_data.is_a(&RNA_Camera)) { BL::Camera b_camera(b_ob_data); PointerRNA ccamera = RNA_pointer_get(&b_camera.ptr, "cycles"); bcam->nearclip = b_camera.clip_start(); bcam->farclip = b_camera.clip_end(); switch(b_camera.type()) { case BL::Camera::type_ORTHO: bcam->type = CAMERA_ORTHOGRAPHIC; break; case BL::Camera::type_PANO: if(!skip_panorama) bcam->type = CAMERA_PANORAMA; else bcam->type = CAMERA_PERSPECTIVE; break; case BL::Camera::type_PERSP: default: bcam->type = CAMERA_PERSPECTIVE; break; } switch(RNA_enum_get(&ccamera, "panorama_type")) { case 1: bcam->panorama_type = PANORAMA_FISHEYE_EQUIDISTANT; break; case 2: bcam->panorama_type = PANORAMA_FISHEYE_EQUISOLID; break; case 3: bcam->panorama_type = PANORAMA_MIRRORBALL; break; case 0: default: bcam->panorama_type = PANORAMA_EQUIRECTANGULAR; break; } bcam->fisheye_fov = RNA_float_get(&ccamera, "fisheye_fov"); bcam->fisheye_lens = RNA_float_get(&ccamera, "fisheye_lens"); bcam->latitude_min = RNA_float_get(&ccamera, "latitude_min"); bcam->latitude_max = RNA_float_get(&ccamera, "latitude_max"); bcam->longitude_min = RNA_float_get(&ccamera, "longitude_min"); bcam->longitude_max = RNA_float_get(&ccamera, "longitude_max"); bcam->ortho_scale = b_camera.ortho_scale(); bcam->lens = b_camera.lens(); /* allow f/stop number to change aperture_size but still * give manual control over aperture radius */ int aperture_type = RNA_enum_get(&ccamera, "aperture_type"); if(aperture_type == 1) { float fstop = RNA_float_get(&ccamera, "aperture_fstop"); fstop = max(fstop, 1e-5f); if(bcam->type == CAMERA_ORTHOGRAPHIC) bcam->aperturesize = 1.0f/(2.0f*fstop); else bcam->aperturesize = (bcam->lens*1e-3f)/(2.0f*fstop); } else bcam->aperturesize = RNA_float_get(&ccamera, "aperture_size"); bcam->apertureblades = RNA_int_get(&ccamera, "aperture_blades"); bcam->aperturerotation = RNA_float_get(&ccamera, "aperture_rotation"); bcam->focaldistance = blender_camera_focal_distance(b_engine, b_ob, b_camera); bcam->aperture_ratio = RNA_float_get(&ccamera, "aperture_ratio"); bcam->shift.x = b_engine.camera_shift_x(b_ob); bcam->shift.y = b_camera.shift_y(); bcam->sensor_width = b_camera.sensor_width(); bcam->sensor_height = b_camera.sensor_height(); if(b_camera.sensor_fit() == BL::Camera::sensor_fit_AUTO) bcam->sensor_fit = BlenderCamera::AUTO; else if(b_camera.sensor_fit() == BL::Camera::sensor_fit_HORIZONTAL) bcam->sensor_fit = BlenderCamera::HORIZONTAL; else bcam->sensor_fit = BlenderCamera::VERTICAL; } else { /* from lamp not implemented yet */ } }
void BL_ConvertActuators(const char* maggiename, struct Object* blenderobject, KX_GameObject* gameobj, SCA_LogicManager* logicmgr, KX_Scene* scene, KX_KetsjiEngine* ketsjiEngine, int activeLayerBitInfo, bool isInActiveLayer, KX_BlenderSceneConverter* converter ) { int uniqueint = 0; int actcount = 0; int executePriority = 0; bActuator* bact = (bActuator*) blenderobject->actuators.first; while (bact) { actcount++; bact = bact->next; } gameobj->ReserveActuator(actcount); bact = (bActuator*) blenderobject->actuators.first; while (bact) { STR_String uniquename = bact->name; STR_String& objectname = gameobj->GetName(); SCA_IActuator* baseact = NULL; switch (bact->type) { case ACT_OBJECT: { bObjectActuator* obact = (bObjectActuator*) bact->data; KX_GameObject* obref = NULL; MT_Vector3 forcevec(KX_flt_trunc(obact->forceloc[0]), KX_flt_trunc(obact->forceloc[1]), KX_flt_trunc(obact->forceloc[2])); MT_Vector3 torquevec(obact->forcerot[0], obact->forcerot[1], obact->forcerot[2]); MT_Vector3 dlocvec(KX_flt_trunc(obact->dloc[0]), KX_flt_trunc(obact->dloc[1]), KX_flt_trunc(obact->dloc[2])); MT_Vector3 drotvec(KX_flt_trunc(obact->drot[0]), obact->drot[1],obact->drot[2]); MT_Vector3 linvelvec(KX_flt_trunc(obact->linearvelocity[0]), KX_flt_trunc(obact->linearvelocity[1]), KX_flt_trunc(obact->linearvelocity[2])); MT_Vector3 angvelvec(KX_flt_trunc(obact->angularvelocity[0]), KX_flt_trunc(obact->angularvelocity[1]), KX_flt_trunc(obact->angularvelocity[2])); short damping = obact->damping; /* Blender uses a bit vector internally for the local-flags. In */ /* KX, we have four bools. The compiler should be smart enough */ /* to do the right thing. We need to explicitly convert here! */ KX_LocalFlags bitLocalFlag; bitLocalFlag.Force = bool((obact->flag & ACT_FORCE_LOCAL)!=0); bitLocalFlag.Torque = bool((obact->flag & ACT_TORQUE_LOCAL) !=0);//rlocal; bitLocalFlag.DLoc = bool((obact->flag & ACT_DLOC_LOCAL)!=0); bitLocalFlag.DRot = bool((obact->flag & ACT_DROT_LOCAL)!=0); bitLocalFlag.LinearVelocity = bool((obact->flag & ACT_LIN_VEL_LOCAL)!=0); bitLocalFlag.AngularVelocity = bool((obact->flag & ACT_ANG_VEL_LOCAL)!=0); bitLocalFlag.ServoControl = bool(obact->type == ACT_OBJECT_SERVO); bitLocalFlag.CharacterMotion = bool(obact->type == ACT_OBJECT_CHARACTER); bitLocalFlag.CharacterJump = bool((obact->flag & ACT_CHAR_JUMP)!=0); bitLocalFlag.AddOrSetLinV = bool((obact->flag & ACT_ADD_LIN_VEL)!=0); bitLocalFlag.AddOrSetCharLoc = bool((obact->flag & ACT_ADD_CHAR_LOC)!=0); if (obact->reference && bitLocalFlag.ServoControl) { obref = converter->FindGameObject(obact->reference); } KX_ObjectActuator* tmpbaseact = new KX_ObjectActuator( gameobj, obref, forcevec.getValue(), torquevec.getValue(), dlocvec.getValue(), drotvec.getValue(), linvelvec.getValue(), angvelvec.getValue(), damping, bitLocalFlag); baseact = tmpbaseact; break; } case ACT_ACTION: { bActionActuator* actact = (bActionActuator*) bact->data; STR_String propname = actact->name; STR_String propframe = actact->frameProp; short ipo_flags = 0; // Convert flags if (actact->flag & ACT_IPOFORCE) ipo_flags |= BL_Action::ACT_IPOFLAG_FORCE; if (actact->flag & ACT_IPOLOCAL) ipo_flags |= BL_Action::ACT_IPOFLAG_LOCAL; if (actact->flag & ACT_IPOADD) ipo_flags |= BL_Action::ACT_IPOFLAG_ADD; if (actact->flag & ACT_IPOCHILD) ipo_flags |= BL_Action::ACT_IPOFLAG_CHILD; BL_ActionActuator* tmpbaseact = new BL_ActionActuator( gameobj, propname, propframe, actact->sta, actact->end, actact->act, actact->type, // + 1, because Blender starts to count at zero, actact->blend_mode, actact->blendin, actact->priority, actact->layer, actact->layer_weight, ipo_flags, actact->end_reset, actact->stridelength // Ketsji at 1, because zero is reserved for "NoDef" ); baseact= tmpbaseact; break; } case ACT_SHAPEACTION: { if (blenderobject->type==OB_MESH) { bActionActuator* actact = (bActionActuator*) bact->data; STR_String propname = actact->name; STR_String propframe = actact->frameProp; BL_ShapeActionActuator* tmpbaseact = new BL_ShapeActionActuator( gameobj, propname, propframe, actact->sta, actact->end, actact->act, actact->type, // + 1, because Blender starts to count at zero, actact->blendin, actact->priority, actact->stridelength); // Ketsji at 1, because zero is reserved for "NoDef" baseact= tmpbaseact; break; } else printf ("Discarded shape action actuator from non-mesh object [%s]\n", blenderobject->id.name+2); } case ACT_LAMP: { break; } case ACT_CAMERA: { bCameraActuator *camact = (bCameraActuator *) bact->data; if (camact->ob) { KX_GameObject *tmpgob = converter->FindGameObject(camact->ob); /* visifac, fac and axis are not copied from the struct... */ /* that's some internal state... */ KX_CameraActuator *tmpcamact = new KX_CameraActuator( gameobj, tmpgob, camact->height, camact->min, camact->max, camact->axis, camact->damping); baseact = tmpcamact; } break; } case ACT_MESSAGE: { bMessageActuator *msgAct = (bMessageActuator *) bact->data; /* Get the name of the properties that objects must own that * we're sending to, if present */ STR_String toPropName = msgAct->toPropName; /* Get the Message Subject to send. */ STR_String subject = msgAct->subject; /* Get the bodyType */ int bodyType = msgAct->bodyType; /* Get the body (text message or property name whose value * we'll be sending, might be empty */ const STR_String body = msgAct->body; KX_NetworkMessageActuator *tmpmsgact = new KX_NetworkMessageActuator( gameobj, // actuator controlling object scene->GetNetworkScene(), // needed for replication toPropName, subject, bodyType, body); baseact = tmpmsgact; break; } case ACT_MATERIAL: { break; } case ACT_SOUND: { bSoundActuator* soundact = (bSoundActuator*) bact->data; /* get type, and possibly a start and end frame */ KX_SoundActuator::KX_SOUNDACT_TYPE soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF; switch (soundact->type) { case ACT_SND_PLAY_STOP_SOUND: soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYSTOP; break; case ACT_SND_PLAY_END_SOUND: soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYEND; break; case ACT_SND_LOOP_STOP_SOUND: soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPSTOP; break; case ACT_SND_LOOP_END_SOUND: soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPEND; break; case ACT_SND_LOOP_BIDIRECTIONAL_SOUND: soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL; break; case ACT_SND_LOOP_BIDIRECTIONAL_STOP_SOUND: soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP; break; default: /* This is an error!!! */ soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF; } if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF) { bSound* sound = soundact->sound; bool is3d = soundact->flag & ACT_SND_3D_SOUND ? true : false; AUD_Sound* snd_sound = NULL; KX_3DSoundSettings settings; settings.cone_inner_angle = RAD2DEGF(soundact->sound3D.cone_inner_angle); settings.cone_outer_angle = RAD2DEGF(soundact->sound3D.cone_outer_angle); settings.cone_outer_gain = soundact->sound3D.cone_outer_gain; settings.max_distance = soundact->sound3D.max_distance; settings.max_gain = soundact->sound3D.max_gain; settings.min_gain = soundact->sound3D.min_gain; settings.reference_distance = soundact->sound3D.reference_distance; settings.rolloff_factor = soundact->sound3D.rolloff_factor; if (!sound) { std::cout << "WARNING: Sound actuator \"" << bact->name << "\" from object \"" << blenderobject->id.name+2 << "\" has no sound datablock." << std::endl; } else { snd_sound = sound->playback_handle; // if sound shall be 3D but isn't mono, we have to make it mono! if (is3d) { snd_sound = AUD_Sound_rechannel(snd_sound, AUD_CHANNELS_MONO); } } KX_SoundActuator* tmpsoundact = new KX_SoundActuator(gameobj, snd_sound, soundact->volume, (float)(expf((soundact->pitch / 12.0f) * (float)M_LN2)), is3d, settings, soundActuatorType); // if we made it mono, we have to free it if(sound && snd_sound && snd_sound != sound->playback_handle) AUD_Sound_free(snd_sound); tmpsoundact->SetName(bact->name); baseact = tmpsoundact; } break; } case ACT_PROPERTY: { bPropertyActuator* propact = (bPropertyActuator*) bact->data; SCA_IObject* destinationObj = NULL; /* * here the destinationobject is searched. problem with multiple scenes: other scenes * have not been converted yet, so the destobj will not be found, so the prop will * not be copied. * possible solutions: * - convert everything when possible and not realtime only when needed. * - let the object-with-property report itself to the act when converted */ if (propact->ob) destinationObj = converter->FindGameObject(propact->ob); SCA_PropertyActuator* tmppropact = new SCA_PropertyActuator( gameobj, destinationObj, propact->name, propact->value, propact->type + 1); // + 1 because Ketsji Logic starts // with 0 for KX_ACT_PROP_NODEF baseact = tmppropact; break; } case ACT_EDIT_OBJECT: { bEditObjectActuator *editobact = (bEditObjectActuator *) bact->data; /* There are four different kinds of 'edit object' thingies */ /* The alternative to this lengthy conversion is packing */ /* several actuators in one, which is not very nice design.. */ switch (editobact->type) { case ACT_EDOB_ADD_OBJECT: { // does the 'original' for replication exists, and // is it in a non-active layer ? SCA_IObject* originalval = NULL; if (editobact->ob) { if (editobact->ob->lay & activeLayerBitInfo) { fprintf(stderr, "Warning, object \"%s\" from AddObject actuator \"%s\" is not in a hidden layer.\n", objectname.Ptr(), uniquename.Ptr()); } else { originalval = converter->FindGameObject(editobact->ob); } } KX_SCA_AddObjectActuator* tmpaddact = new KX_SCA_AddObjectActuator( gameobj, originalval, editobact->time, scene, editobact->linVelocity, (editobact->localflag & ACT_EDOB_LOCAL_LINV) != 0, editobact->angVelocity, (editobact->localflag & ACT_EDOB_LOCAL_ANGV) != 0); //editobact->ob to gameobj baseact = tmpaddact; } break; case ACT_EDOB_END_OBJECT: { KX_SCA_EndObjectActuator* tmpendact = new KX_SCA_EndObjectActuator(gameobj,scene); baseact = tmpendact; } break; case ACT_EDOB_REPLACE_MESH: { RAS_MeshObject *tmpmesh = converter->FindGameMesh(editobact->me); if (!tmpmesh) { std::cout << "Warning: object \"" << objectname << "\" from ReplaceMesh actuator \"" << uniquename << "\" uses a mesh not owned by an object in scene \"" << scene->GetName() << "\"." << std::endl; } KX_SCA_ReplaceMeshActuator* tmpreplaceact = new KX_SCA_ReplaceMeshActuator( gameobj, tmpmesh, scene, (editobact->flag & ACT_EDOB_REPLACE_MESH_NOGFX) == 0, (editobact->flag & ACT_EDOB_REPLACE_MESH_PHYS) != 0); baseact = tmpreplaceact; } break; case ACT_EDOB_TRACK_TO: { SCA_IObject* originalval = NULL; if (editobact->ob) originalval = converter->FindGameObject(editobact->ob); KX_TrackToActuator* tmptrackact = new KX_TrackToActuator( gameobj, originalval, editobact->time, editobact->flag, editobact->trackflag, editobact->upflag); baseact = tmptrackact; break; } case ACT_EDOB_DYNAMICS: { KX_SCA_DynamicActuator* tmpdynact = new KX_SCA_DynamicActuator( gameobj, editobact->dyn_operation, editobact->mass); baseact = tmpdynact; } } break; } case ACT_CONSTRAINT: { float min = 0.0, max = 0.0; char *prop = NULL; KX_ConstraintActuator::KX_CONSTRAINTTYPE locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF; bConstraintActuator *conact = (bConstraintActuator*) bact->data; /* convert settings... degrees in the ui become radians */ /* internally */ if (conact->type == ACT_CONST_TYPE_ORI) { min = conact->minloc[0]; max = conact->maxloc[0]; switch (conact->mode) { case ACT_CONST_DIRPX: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX; break; case ACT_CONST_DIRPY: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY; break; case ACT_CONST_DIRPZ: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ; break; } } else if (conact->type == ACT_CONST_TYPE_DIST) { switch (conact->mode) { case ACT_CONST_DIRPX: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX; min = conact->minloc[0]; max = conact->maxloc[0]; break; case ACT_CONST_DIRPY: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY; min = conact->minloc[1]; max = conact->maxloc[1]; break; case ACT_CONST_DIRPZ: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ; min = conact->minloc[2]; max = conact->maxloc[2]; break; case ACT_CONST_DIRNX: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX; min = conact->minloc[0]; max = conact->maxloc[0]; break; case ACT_CONST_DIRNY: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY; min = conact->minloc[1]; max = conact->maxloc[1]; break; case ACT_CONST_DIRNZ: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ; min = conact->minloc[2]; max = conact->maxloc[2]; break; } prop = conact->matprop; } else if (conact->type == ACT_CONST_TYPE_FH) { switch (conact->mode) { case ACT_CONST_DIRPX: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX; min = conact->minloc[0]; max = conact->maxloc[0]; break; case ACT_CONST_DIRPY: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY; min = conact->minloc[1]; max = conact->maxloc[1]; break; case ACT_CONST_DIRPZ: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ; min = conact->minloc[2]; max = conact->maxloc[2]; break; case ACT_CONST_DIRNX: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX; min = conact->minloc[0]; max = conact->maxloc[0]; break; case ACT_CONST_DIRNY: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY; min = conact->minloc[1]; max = conact->maxloc[1]; break; case ACT_CONST_DIRNZ: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ; min = conact->minloc[2]; max = conact->maxloc[2]; break; } prop = conact->matprop; } else { switch (conact->flag) { case ACT_CONST_LOCX: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX; min = conact->minloc[0]; max = conact->maxloc[0]; break; case ACT_CONST_LOCY: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY; min = conact->minloc[1]; max = conact->maxloc[1]; break; case ACT_CONST_LOCZ: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ; min = conact->minloc[2]; max = conact->maxloc[2]; break; case ACT_CONST_ROTX: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX; min = conact->minrot[0] * (float)MT_RADS_PER_DEG; max = conact->maxrot[0] * (float)MT_RADS_PER_DEG; break; case ACT_CONST_ROTY: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY; min = conact->minrot[1] * (float)MT_RADS_PER_DEG; max = conact->maxrot[1] * (float)MT_RADS_PER_DEG; break; case ACT_CONST_ROTZ: locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ; min = conact->minrot[2] * (float)MT_RADS_PER_DEG; max = conact->maxrot[2] * (float)MT_RADS_PER_DEG; break; default: ; /* error */ } } KX_ConstraintActuator *tmpconact = new KX_ConstraintActuator( gameobj, conact->damp, conact->rotdamp, min, max, conact->maxrot, locrot, conact->time, conact->flag, prop); baseact = tmpconact; break; } case ACT_GROUP: { // deprecated } break; case ACT_SCENE: { bSceneActuator *sceneact = (bSceneActuator *) bact->data; STR_String nextSceneName(""); KX_SceneActuator* tmpsceneact; int mode = KX_SceneActuator::KX_SCENE_NODEF; KX_Camera *cam = NULL; //KX_Scene* scene = NULL; switch (sceneact->type) { case ACT_SCENE_RESUME: case ACT_SCENE_SUSPEND: case ACT_SCENE_ADD_FRONT: case ACT_SCENE_ADD_BACK: case ACT_SCENE_REMOVE: case ACT_SCENE_SET: { switch (sceneact->type) { case ACT_SCENE_RESUME: mode = KX_SceneActuator::KX_SCENE_RESUME; break; case ACT_SCENE_SUSPEND: mode = KX_SceneActuator::KX_SCENE_SUSPEND; break; case ACT_SCENE_ADD_FRONT: mode = KX_SceneActuator::KX_SCENE_ADD_FRONT_SCENE; break; case ACT_SCENE_ADD_BACK: mode = KX_SceneActuator::KX_SCENE_ADD_BACK_SCENE; break; case ACT_SCENE_REMOVE: mode = KX_SceneActuator::KX_SCENE_REMOVE_SCENE; break; case ACT_SCENE_SET: default: mode = KX_SceneActuator::KX_SCENE_SET_SCENE; break; }; if (sceneact->scene) { nextSceneName = sceneact->scene->id.name + 2; } break; } case ACT_SCENE_CAMERA: mode = KX_SceneActuator::KX_SCENE_SET_CAMERA; if (sceneact->camera) { KX_GameObject *tmp = converter->FindGameObject(sceneact->camera); if (tmp && tmp->GetGameObjectType() == SCA_IObject::OBJ_CAMERA) cam = (KX_Camera*)tmp; } break; case ACT_SCENE_RESTART: { mode = KX_SceneActuator::KX_SCENE_RESTART; break; } default: ; /* flag error */ } tmpsceneact = new KX_SceneActuator( gameobj, mode, scene, ketsjiEngine, nextSceneName, cam); baseact = tmpsceneact; break; } case ACT_GAME: { bGameActuator *gameact = (bGameActuator *) bact->data; KX_GameActuator* tmpgameact; STR_String filename = maggiename; STR_String loadinganimationname = ""; int mode = KX_GameActuator::KX_GAME_NODEF; switch (gameact->type) { case ACT_GAME_LOAD: { mode = KX_GameActuator::KX_GAME_LOAD; filename = gameact->filename; loadinganimationname = gameact->loadaniname; break; } case ACT_GAME_START: { mode = KX_GameActuator::KX_GAME_START; filename = gameact->filename; loadinganimationname = gameact->loadaniname; break; } case ACT_GAME_RESTART: { mode = KX_GameActuator::KX_GAME_RESTART; break; } case ACT_GAME_QUIT: { mode = KX_GameActuator::KX_GAME_QUIT; break; } case ACT_GAME_SAVECFG: { mode = KX_GameActuator::KX_GAME_SAVECFG; break; } case ACT_GAME_LOADCFG: { mode = KX_GameActuator::KX_GAME_LOADCFG; break; } case ACT_GAME_SCREENSHOT: { mode = KX_GameActuator::KX_GAME_SCREENSHOT; filename = gameact->filename; break; } default: ; /* flag error */ } tmpgameact = new KX_GameActuator( gameobj, mode, filename, loadinganimationname, scene, ketsjiEngine); baseact = tmpgameact; break; } case ACT_RANDOM: { bRandomActuator *randAct = (bRandomActuator *) bact->data; unsigned long seedArg = randAct->seed; if (seedArg == 0) { seedArg = (int)(ketsjiEngine->GetRealTime()*100000.0); seedArg ^= (intptr_t)randAct; } SCA_RandomActuator::KX_RANDOMACT_MODE modeArg = SCA_RandomActuator::KX_RANDOMACT_NODEF; SCA_RandomActuator *tmprandomact; float paraArg1 = 0.0; float paraArg2 = 0.0; switch (randAct->distribution) { case ACT_RANDOM_BOOL_CONST: modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST; paraArg1 = (float) randAct->int_arg_1; break; case ACT_RANDOM_BOOL_UNIFORM: modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM; break; case ACT_RANDOM_BOOL_BERNOUILLI: paraArg1 = randAct->float_arg_1; modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI; break; case ACT_RANDOM_INT_CONST: modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_CONST; paraArg1 = (float) randAct->int_arg_1; break; case ACT_RANDOM_INT_UNIFORM: paraArg1 = (float) randAct->int_arg_1; paraArg2 = (float) randAct->int_arg_2; modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM; break; case ACT_RANDOM_INT_POISSON: paraArg1 = randAct->float_arg_1; modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_POISSON; break; case ACT_RANDOM_FLOAT_CONST: paraArg1 = randAct->float_arg_1; modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST; break; case ACT_RANDOM_FLOAT_UNIFORM: paraArg1 = randAct->float_arg_1; paraArg2 = randAct->float_arg_2; modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM; break; case ACT_RANDOM_FLOAT_NORMAL: paraArg1 = randAct->float_arg_1; paraArg2 = randAct->float_arg_2; modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL; break; case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL: paraArg1 = randAct->float_arg_1; modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL; break; default: ; /* error */ } tmprandomact = new SCA_RandomActuator( gameobj, seedArg, modeArg, paraArg1, paraArg2, randAct->propname); baseact = tmprandomact; } break; case ACT_VISIBILITY: { bVisibilityActuator *vis_act = (bVisibilityActuator *) bact->data; KX_VisibilityActuator * tmp_vis_act = NULL; bool v = ((vis_act->flag & ACT_VISIBILITY_INVISIBLE) != 0); bool o = ((vis_act->flag & ACT_VISIBILITY_OCCLUSION) != 0); bool recursive = ((vis_act->flag & ACT_VISIBILITY_RECURSIVE) != 0); tmp_vis_act = new KX_VisibilityActuator(gameobj, !v, o, recursive); baseact = tmp_vis_act; } break; case ACT_STATE: { bStateActuator *sta_act = (bStateActuator *) bact->data; KX_StateActuator * tmp_sta_act = NULL; tmp_sta_act = new KX_StateActuator(gameobj, sta_act->type, sta_act->mask); baseact = tmp_sta_act; } break; case ACT_2DFILTER: { bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data; SCA_2DFilterActuator *tmp = NULL; RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode; switch (_2dfilter->type) { case ACT_2DFILTER_MOTIONBLUR: filtermode = RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR; break; case ACT_2DFILTER_BLUR: filtermode = RAS_2DFilterManager::RAS_2DFILTER_BLUR; break; case ACT_2DFILTER_SHARPEN: filtermode = RAS_2DFilterManager::RAS_2DFILTER_SHARPEN; break; case ACT_2DFILTER_DILATION: filtermode = RAS_2DFilterManager::RAS_2DFILTER_DILATION; break; case ACT_2DFILTER_EROSION: filtermode = RAS_2DFilterManager::RAS_2DFILTER_EROSION; break; case ACT_2DFILTER_LAPLACIAN: filtermode = RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN; break; case ACT_2DFILTER_SOBEL: filtermode = RAS_2DFilterManager::RAS_2DFILTER_SOBEL; break; case ACT_2DFILTER_PREWITT: filtermode = RAS_2DFilterManager::RAS_2DFILTER_PREWITT; break; case ACT_2DFILTER_GRAYSCALE: filtermode = RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE; break; case ACT_2DFILTER_SEPIA: filtermode = RAS_2DFilterManager::RAS_2DFILTER_SEPIA; break; case ACT_2DFILTER_INVERT: filtermode = RAS_2DFilterManager::RAS_2DFILTER_INVERT; break; case ACT_2DFILTER_CUSTOMFILTER: filtermode = RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER; break; case ACT_2DFILTER_NOFILTER: filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER; break; case ACT_2DFILTER_DISABLED: filtermode = RAS_2DFilterManager::RAS_2DFILTER_DISABLED; break; case ACT_2DFILTER_ENABLED: filtermode = RAS_2DFilterManager::RAS_2DFILTER_ENABLED; break; default: filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER; break; } tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag, _2dfilter->float_arg, _2dfilter->int_arg, ketsjiEngine->GetRasterizer(), scene); if (_2dfilter->text) { char *buf; // this is some blender specific code buf = txt_to_buf(_2dfilter->text); if (buf) { tmp->SetShaderText(buf); MEM_freeN(buf); } } baseact = tmp; } break; case ACT_PARENT: { bParentActuator *parAct = (bParentActuator *) bact->data; int mode = KX_ParentActuator::KX_PARENT_NODEF; bool addToCompound = true; bool ghost = true; KX_GameObject *tmpgob = NULL; switch (parAct->type) { case ACT_PARENT_SET: mode = KX_ParentActuator::KX_PARENT_SET; tmpgob = converter->FindGameObject(parAct->ob); addToCompound = !(parAct->flag & ACT_PARENT_COMPOUND); ghost = !(parAct->flag & ACT_PARENT_GHOST); break; case ACT_PARENT_REMOVE: mode = KX_ParentActuator::KX_PARENT_REMOVE; tmpgob = NULL; break; } KX_ParentActuator *tmpparact = new KX_ParentActuator(gameobj, mode, addToCompound, ghost, tmpgob); baseact = tmpparact; break; } case ACT_ARMATURE: { bArmatureActuator* armAct = (bArmatureActuator*) bact->data; KX_GameObject *tmpgob = converter->FindGameObject(armAct->target); KX_GameObject *subgob = converter->FindGameObject(armAct->subtarget); BL_ArmatureActuator* tmparmact = new BL_ArmatureActuator( gameobj, armAct->type, armAct->posechannel, armAct->constraint, tmpgob, subgob, armAct->weight, armAct->influence); baseact = tmparmact; break; } case ACT_STEERING: { bSteeringActuator *stAct = (bSteeringActuator *) bact->data; KX_GameObject *navmeshob = NULL; if (stAct->navmesh) { PointerRNA settings_ptr; RNA_pointer_create((ID *)stAct->navmesh, &RNA_GameObjectSettings, stAct->navmesh, &settings_ptr); if (RNA_enum_get(&settings_ptr, "physics_type") == OB_BODY_TYPE_NAVMESH) navmeshob = converter->FindGameObject(stAct->navmesh); } KX_GameObject *targetob = converter->FindGameObject(stAct->target); int mode = KX_SteeringActuator::KX_STEERING_NODEF; switch (stAct->type) { case ACT_STEERING_SEEK: mode = KX_SteeringActuator::KX_STEERING_SEEK; break; case ACT_STEERING_FLEE: mode = KX_SteeringActuator::KX_STEERING_FLEE; break; case ACT_STEERING_PATHFOLLOWING: mode = KX_SteeringActuator::KX_STEERING_PATHFOLLOWING; break; } bool selfTerminated = (stAct->flag & ACT_STEERING_SELFTERMINATED) !=0; bool enableVisualization = (stAct->flag & ACT_STEERING_ENABLEVISUALIZATION) !=0; short facingMode = (stAct->flag & ACT_STEERING_AUTOMATICFACING) ? stAct->facingaxis : 0; bool normalup = (stAct->flag & ACT_STEERING_NORMALUP) !=0; bool lockzvel = (stAct->flag & ACT_STEERING_LOCKZVEL) !=0; KX_SteeringActuator *tmpstact = new KX_SteeringActuator(gameobj, mode, targetob, navmeshob,stAct->dist, stAct->velocity, stAct->acceleration, stAct->turnspeed, selfTerminated, stAct->updateTime, scene->GetObstacleSimulation(), facingMode, normalup, enableVisualization, lockzvel); baseact = tmpstact; break; } case ACT_MOUSE: { bMouseActuator* mouAct = (bMouseActuator*) bact->data; int mode = KX_MouseActuator::KX_ACT_MOUSE_NODEF; switch (mouAct->type) { case ACT_MOUSE_VISIBILITY: { mode = KX_MouseActuator::KX_ACT_MOUSE_VISIBILITY; break; } case ACT_MOUSE_LOOK: { mode = KX_MouseActuator::KX_ACT_MOUSE_LOOK; break; } } bool visible = (mouAct->flag & ACT_MOUSE_VISIBLE) != 0; bool use_axis[2] = {(mouAct->flag & ACT_MOUSE_USE_AXIS_X) != 0, (mouAct->flag & ACT_MOUSE_USE_AXIS_Y) != 0}; bool reset[2] = {(mouAct->flag & ACT_MOUSE_RESET_X) != 0, (mouAct->flag & ACT_MOUSE_RESET_Y) != 0}; bool local[2] = {(mouAct->flag & ACT_MOUSE_LOCAL_X) != 0, (mouAct->flag & ACT_MOUSE_LOCAL_Y) != 0}; SCA_MouseManager* eventmgr = (SCA_MouseManager*) logicmgr->FindEventManager(SCA_EventManager::MOUSE_EVENTMGR); if (eventmgr) { KX_MouseActuator* tmpbaseact = new KX_MouseActuator(gameobj, ketsjiEngine, eventmgr, mode, visible, use_axis, mouAct->threshold, reset, mouAct->object_axis, local, mouAct->sensitivity, mouAct->limit_x, mouAct->limit_y); baseact = tmpbaseact; } else { //cout << "\n Couldn't find mouse event manager..."; - should throw an error here... } break; } default: ; /* generate some error */ } if (baseact && !(bact->flag & ACT_DEACTIVATE)) { baseact->SetExecutePriority(executePriority++); uniquename += "#ACT#"; uniqueint++; CIntValue* uniqueval = new CIntValue(uniqueint); uniquename += uniqueval->GetText(); uniqueval->Release(); baseact->SetName(bact->name); baseact->SetLogicManager(logicmgr); //gameobj->SetProperty(uniquename,baseact); gameobj->AddActuator(baseact); converter->RegisterGameActuator(baseact, bact); // done with baseact, release it baseact->Release(); } else if (baseact) baseact->Release(); bact = bact->next; } }
/* generic settings for active NLA-Strip */ static void nla_panel_properties(const bContext *C, Panel *pa) { PointerRNA strip_ptr; uiLayout *layout = pa->layout; uiLayout *column, *row, *sub; uiBlock *block; short showEvalProps = 1; if (!nla_panel_context(C, NULL, NULL, &strip_ptr)) return; block = uiLayoutGetBlock(layout); UI_block_func_handle_set(block, do_nla_region_buttons, NULL); /* Strip Properties ------------------------------------- */ /* strip type */ row = uiLayoutColumn(layout, true); uiItemR(row, &strip_ptr, "name", 0, NULL, ICON_NLA); // XXX icon? uiItemR(row, &strip_ptr, "type", 0, NULL, ICON_NONE); /* strip extents */ column = uiLayoutColumn(layout, true); uiItemL(column, IFACE_("Strip Extents:"), ICON_NONE); uiItemR(column, &strip_ptr, "frame_start", 0, NULL, ICON_NONE); uiItemR(column, &strip_ptr, "frame_end", 0, NULL, ICON_NONE); /* Evaluation-Related Strip Properties ------------------ */ /* sound properties strips don't have these settings */ if (RNA_enum_get(&strip_ptr, "type") == NLASTRIP_TYPE_SOUND) showEvalProps = 0; /* only show if allowed to... */ if (showEvalProps) { /* extrapolation */ row = uiLayoutRow(layout, true); uiItemR(row, &strip_ptr, "extrapolation", 0, NULL, ICON_NONE); /* blending */ row = uiLayoutRow(layout, true); uiItemR(row, &strip_ptr, "blend_type", 0, NULL, ICON_NONE); /* blend in/out + autoblending * - blend in/out can only be set when autoblending is off */ column = uiLayoutColumn(layout, true); uiLayoutSetActive(column, RNA_boolean_get(&strip_ptr, "use_animated_influence") == false); uiItemR(column, &strip_ptr, "use_auto_blend", 0, NULL, ICON_NONE); // XXX as toggle? sub = uiLayoutColumn(column, true); uiLayoutSetActive(sub, RNA_boolean_get(&strip_ptr, "use_auto_blend") == false); uiItemR(sub, &strip_ptr, "blend_in", 0, NULL, ICON_NONE); uiItemR(sub, &strip_ptr, "blend_out", 0, NULL, ICON_NONE); /* settings */ column = uiLayoutColumn(layout, true); uiLayoutSetActive(column, !(RNA_boolean_get(&strip_ptr, "use_animated_influence") || RNA_boolean_get(&strip_ptr, "use_animated_time"))); uiItemL(column, IFACE_("Playback Settings:"), ICON_NONE); uiItemR(column, &strip_ptr, "mute", 0, NULL, ICON_NONE); uiItemR(column, &strip_ptr, "use_reverse", 0, NULL, ICON_NONE); } }
static int data_transfer_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob_src = ED_object_active_context(C); ListBase ctx_objects; CollectionPointerLink *ctx_ob_dst; bool changed = false; const bool is_frozen = RNA_boolean_get(op->ptr, "use_freeze"); const bool reverse_transfer = RNA_boolean_get(op->ptr, "use_reverse_transfer"); const int data_type = RNA_enum_get(op->ptr, "data_type"); const bool use_create = RNA_boolean_get(op->ptr, "use_create"); const int map_vert_mode = RNA_enum_get(op->ptr, "vert_mapping"); const int map_edge_mode = RNA_enum_get(op->ptr, "edge_mapping"); const int map_loop_mode = RNA_enum_get(op->ptr, "loop_mapping"); const int map_poly_mode = RNA_enum_get(op->ptr, "poly_mapping"); const bool use_auto_transform = RNA_boolean_get(op->ptr, "use_auto_transform"); const bool use_object_transform = RNA_boolean_get(op->ptr, "use_object_transform"); const bool use_max_distance = RNA_boolean_get(op->ptr, "use_max_distance"); const float max_distance = use_max_distance ? RNA_float_get(op->ptr, "max_distance") : FLT_MAX; const float ray_radius = RNA_float_get(op->ptr, "ray_radius"); const float islands_precision = RNA_float_get(op->ptr, "islands_precision"); const int layers_src = RNA_enum_get(op->ptr, "layers_select_src"); const int layers_dst = RNA_enum_get(op->ptr, "layers_select_dst"); int layers_select_src[DT_MULTILAYER_INDEX_MAX] = {0}; int layers_select_dst[DT_MULTILAYER_INDEX_MAX] = {0}; const int fromto_idx = BKE_object_data_transfer_dttype_to_srcdst_index(data_type); const int mix_mode = RNA_enum_get(op->ptr, "mix_mode"); const float mix_factor = RNA_float_get(op->ptr, "mix_factor"); SpaceTransform space_transform_data; SpaceTransform *space_transform = (use_object_transform && !use_auto_transform) ? &space_transform_data : NULL; if (is_frozen) { BKE_report(op->reports, RPT_INFO, "Operator is frozen, changes to its settings won't take effect until you unfreeze it"); return OPERATOR_FINISHED; } if (reverse_transfer && ((ID *)(ob_src->data))->lib) { /* Do not transfer to linked data, not supported. */ return OPERATOR_CANCELLED; } if (fromto_idx != DT_MULTILAYER_INDEX_INVALID) { layers_select_src[fromto_idx] = layers_src; layers_select_dst[fromto_idx] = layers_dst; } data_transfer_exec_preprocess_objects(C, op, ob_src, &ctx_objects, reverse_transfer); for (ctx_ob_dst = ctx_objects.first; ctx_ob_dst; ctx_ob_dst = ctx_ob_dst->next) { Object *ob_dst = ctx_ob_dst->ptr.data; if (reverse_transfer) { SWAP(Object *, ob_src, ob_dst); } if (data_transfer_exec_is_object_valid(op, ob_src, ob_dst, reverse_transfer)) { if (space_transform) { BLI_SPACE_TRANSFORM_SETUP(space_transform, ob_dst, ob_src); } if (BKE_object_data_transfer_mesh( scene, ob_src, ob_dst, data_type, use_create, map_vert_mode, map_edge_mode, map_loop_mode, map_poly_mode, space_transform, use_auto_transform, max_distance, ray_radius, islands_precision, layers_select_src, layers_select_dst, mix_mode, mix_factor, NULL, false, op->reports)) { changed = true; } } DAG_id_tag_update(&ob_dst->id, OB_RECALC_DATA); if (reverse_transfer) { SWAP(Object *, ob_src, ob_dst); } } BLI_freelistN(&ctx_objects); WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, NULL); #if 0 /* TODO */ /* Note: issue with that is that if canceled, operator cannot be redone... Nasty in our case. */ return changed ? OPERATOR_FINISHED : OPERATOR_CANCELLED; #else (void)changed; return OPERATOR_FINISHED; #endif }