patch [#33697] Apply transformation added to metaballs.
from Jesse Werner (vidjogamer), with own addition of RNA function, scale and rotation support.
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#define __ED_MBALL_H__
|
||||
|
||||
struct bContext;
|
||||
struct MetaBall;
|
||||
struct Object;
|
||||
struct wmKeyConfig;
|
||||
|
||||
@@ -48,5 +49,6 @@ void load_editMball(struct Object *obedit);
|
||||
|
||||
void undo_push_mball(struct bContext *C, const char *name);
|
||||
|
||||
#endif
|
||||
void ED_mball_transform(struct MetaBall *mb, float *mat);
|
||||
|
||||
#endif /* __ED_MBALL_H__ */
|
||||
|
||||
@@ -586,3 +586,27 @@ void undo_push_mball(bContext *C, const char *name)
|
||||
undo_editmode_push(C, name, get_data, free_undoMball, undoMball_to_editMball, editMball_to_undoMball, NULL);
|
||||
}
|
||||
|
||||
/* matrix is 4x4 */
|
||||
void ED_mball_transform(MetaBall *mb, float *mat)
|
||||
{
|
||||
MetaElem *me;
|
||||
float quat[4];
|
||||
const float scale = mat4_to_scale((float (*)[4])mat);
|
||||
const float scale_sqrt = sqrtf(scale);
|
||||
|
||||
mat4_to_quat(quat, (float (*)[4])mat);
|
||||
|
||||
for (me = mb->elems.first; me; me = me->next) {
|
||||
mul_m4_v3((float (*)[4])mat, &me->x);
|
||||
mul_qt_qtqt(me->quat, quat, me->quat);
|
||||
me->rad *= scale;
|
||||
/* hrmf, probably elems shouldn't be
|
||||
* treating scale differently - campbell */
|
||||
if (ELEM3(me->type, MB_CUBE, MB_PLANE, MB_TUBE)) {
|
||||
mul_v3_fl(&me->expx, scale);
|
||||
}
|
||||
else {
|
||||
mul_v3_fl(&me->expx, scale_sqrt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
|
||||
#include "ED_armature.h"
|
||||
#include "ED_keyframing.h"
|
||||
#include "ED_mball.h"
|
||||
#include "ED_mesh.h"
|
||||
#include "ED_screen.h"
|
||||
#include "ED_view3d.h"
|
||||
@@ -407,6 +408,12 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo
|
||||
change = 0;
|
||||
}
|
||||
}
|
||||
else if (ob->type == OB_MBALL) {
|
||||
if (ID_REAL_USERS(ob->data) > 1) {
|
||||
BKE_report(reports, RPT_ERROR, "Cannot apply to a multi user metaball, doing nothing");
|
||||
change = 0;
|
||||
}
|
||||
}
|
||||
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
|
||||
Curve *cu;
|
||||
|
||||
@@ -516,6 +523,10 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo
|
||||
bp++;
|
||||
}
|
||||
}
|
||||
else if (ob->type == OB_MBALL) {
|
||||
MetaBall *mb = ob->data;
|
||||
ED_mball_transform(mb, (float *)mat);
|
||||
}
|
||||
else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
|
||||
Curve *cu = ob->data;
|
||||
|
||||
|
||||
@@ -105,6 +105,7 @@ set(APISRC
|
||||
rna_main_api.c
|
||||
rna_material_api.c
|
||||
rna_mesh_api.c
|
||||
rna_meta_api.c
|
||||
rna_texture_api.c
|
||||
rna_object_api.c
|
||||
rna_pose_api.c
|
||||
|
||||
@@ -3248,7 +3248,7 @@ static RNAProcessItem PROCESS_ITEMS[] = {
|
||||
{"rna_main.c", "rna_main_api.c", RNA_def_main},
|
||||
{"rna_material.c", "rna_material_api.c", RNA_def_material},
|
||||
{"rna_mesh.c", "rna_mesh_api.c", RNA_def_mesh},
|
||||
{"rna_meta.c", NULL, RNA_def_meta},
|
||||
{"rna_meta.c", "rna_meta_api.c", RNA_def_meta},
|
||||
{"rna_modifier.c", NULL, RNA_def_modifier},
|
||||
{"rna_nla.c", NULL, RNA_def_nla},
|
||||
{"rna_nodetree.c", NULL, RNA_def_nodetree},
|
||||
|
||||
@@ -264,6 +264,7 @@ void RNA_api_keymapitems(struct StructRNA *srna);
|
||||
void RNA_api_main(struct StructRNA *srna);
|
||||
void RNA_api_material(StructRNA *srna);
|
||||
void RNA_api_mesh(struct StructRNA *srna);
|
||||
void RNA_api_meta(struct StructRNA *srna);
|
||||
void RNA_api_object(struct StructRNA *srna);
|
||||
void RNA_api_object_base(struct StructRNA *srna);
|
||||
void RNA_api_pose(struct StructRNA *srna);
|
||||
|
||||
@@ -351,6 +351,8 @@ static void rna_def_metaball(BlenderRNA *brna)
|
||||
|
||||
/* anim */
|
||||
rna_def_animdata_common(srna);
|
||||
|
||||
RNA_api_meta(srna);
|
||||
}
|
||||
|
||||
void RNA_def_meta(BlenderRNA *brna)
|
||||
|
||||
60
source/blender/makesrna/intern/rna_meta_api.c
Normal file
60
source/blender/makesrna/intern/rna_meta_api.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* ***** 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) 2009 Blender Foundation.
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Contributor(s): Blender Foundation
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/** \file blender/makesrna/intern/rna_meta_api.c
|
||||
* \ingroup RNA
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "RNA_define.h"
|
||||
|
||||
#include "BLO_sys_types.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "ED_mball.h"
|
||||
|
||||
#include "rna_internal.h" /* own include */
|
||||
|
||||
#ifdef RNA_RUNTIME
|
||||
/* none */
|
||||
#else
|
||||
|
||||
void RNA_api_meta(StructRNA *srna)
|
||||
{
|
||||
FunctionRNA *func;
|
||||
PropertyRNA *parm;
|
||||
|
||||
func = RNA_def_function(srna, "transform", "ED_mball_transform");
|
||||
RNA_def_function_ui_description(func, "Transform meta elements by a matrix");
|
||||
parm = RNA_def_float_matrix(func, "matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user