Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_rand.c
- This file was added.
| /* | |||||
| * ***** BEGIN GPL LICENSE BLOCK ***** | |||||
| * | |||||
| * This program is free software; you can redistribute it and/or | |||||
| * modify it under the terms of the GNU General Public License | |||||
| * as published by the Free Software Foundation; either version 2 | |||||
| * of the License, or (at your option) any later version. | |||||
| * | |||||
| * This program is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with this program; if not, write to the Free Software Foundation, | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| * | |||||
| * The Original Code is Copyright (C) 2013 by Blender Foundation | |||||
| * All rights reserved. | |||||
| * | |||||
| * ***** END GPL LICENSE BLOCK ***** | |||||
| */ | |||||
| /** \file blender/editors/object/object_rand.c | |||||
| * \ingroup edobj | |||||
| */ | |||||
| #include "DNA_object_types.h" | |||||
| #include "BLI_math.h" | |||||
| #include "BLI_rand.h" | |||||
| #include "BKE_context.h" | |||||
| #include "RNA_access.h" | |||||
| #include "RNA_define.h" | |||||
| #include "WM_api.h" | |||||
| #include "WM_types.h" | |||||
| #include "ED_transverts.h" | |||||
| #include "object_intern.h" | |||||
| /** | |||||
| * generic randomize vertices function | |||||
| */ | |||||
| static bool object_rand_transverts(TransVertStore *tvs, float factor) | |||||
| { | |||||
| TransVert *tv; | |||||
| int a; | |||||
| float vec[3]; /* direction vector */ | |||||
| if (!tvs || !(tvs->transverts)) { | |||||
| return false; | |||||
| } | |||||
| tv = tvs->transverts; | |||||
| for (a = 0; a < tvs->transverts_tot; a++, tv++) { | |||||
| /* generate a random direction*/ | |||||
| BLI_frand_v3(vec); | |||||
| sub_v3_fl(vec, 0.5); | |||||
| /* normalize the direction*/ | |||||
| normalize_v3(vec); | |||||
| /* reallocate the vert to the scaled direction*/ | |||||
| madd_v3_v3fl(tv->loc, vec, factor); | |||||
| } | |||||
| return true; | |||||
| } | |||||
| static int object_rand_verts_exec(bContext *C, wmOperator *op) | |||||
| { | |||||
| const float factor = RNA_float_get(op->ptr, "factor"); | |||||
| TransVertStore tvs = {NULL}; | |||||
| Object *obedit = CTX_data_edit_object(C); | |||||
| if (obedit) { | |||||
| if (ED_transverts_check_obedit(obedit)) | |||||
| ED_transverts_create_from_obedit(&tvs, obedit, TM_ALL_JOINTS | TM_SKIP_HANDLES); | |||||
| if (tvs.transverts_tot == 0) | |||||
| return OPERATOR_CANCELLED; | |||||
| object_rand_transverts(&tvs, factor); | |||||
| ED_transverts_update_obedit(&tvs, obedit); | |||||
| ED_transverts_free(&tvs); | |||||
| } | |||||
| WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit); | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| void OBJECT_OT_vertex_rand(struct wmOperatorType *ot) | |||||
| { | |||||
| /* identifiers */ | |||||
| ot->name = "Randomize"; | |||||
walid: QT complains about it for not being used!
/home/walid3/Programmes/blender_git/master/source/bl… | |||||
Not Done Inline ActionsJust remove it theres no reason to have it. campbellbarton: Just remove it theres no reason to have it. | |||||
| ot->description = "Randomize vertices"; | |||||
| ot->idname = "OBJECT_OT_vertex_rand"; | |||||
| /* api callbacks */ | |||||
| ot->exec = object_rand_verts_exec; | |||||
| ot->poll = ED_transverts_poll; | |||||
| /* flags */ | |||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | |||||
| /* props */ | |||||
| RNA_def_float(ot->srna, "factor", 1.0f, 0.0f, FLT_MAX, "Randomization Factor", "", 0.0f, 1.0f); | |||||
| } | |||||
QT complains about it for not being used!
/home/walid3/Programmes/blender_git/master/source/blender/editors/object/object_rand.c:104: warning: variable 'prop' set but not used [-Wunused-but-set-variable]
PropertyRNA *prop; ^is there a missing thing in this usage?