2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2010-04-11 23:20:03 +00:00
|
|
|
* $Id$
|
2010-04-11 22:12:30 +00:00
|
|
|
*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version. The Blender
|
|
|
|
* Foundation also sells licenses for use in proprietary software under
|
|
|
|
* the Blender License. See http://www.blender.org/BL/ for information
|
|
|
|
* about this.
|
|
|
|
*
|
|
|
|
* 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;
|
2010-08-10 21:22:26 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-04-11 22:12:30 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): Ben Batt
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-25 13:57:17 +00:00
|
|
|
/** \file blender/modifiers/intern/MOD_util.c
|
|
|
|
* \ingroup modifiers
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-08-13 15:26:37 +00:00
|
|
|
#include <string.h>
|
2010-04-12 22:33:43 +00:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_curve_types.h"
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
#include "BKE_mesh.h"
|
|
|
|
#include "BKE_displist.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2010-04-25 01:10:03 +00:00
|
|
|
#include "BKE_modifier.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "MOD_util.h"
|
2010-04-25 01:10:03 +00:00
|
|
|
#include "MOD_modifiertypes.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "RE_shader_ext.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
void get_texture_value(Tex *texture, float *tex_co, TexResult *texres)
|
|
|
|
{
|
|
|
|
int result_type;
|
|
|
|
|
2010-12-27 19:26:38 +00:00
|
|
|
/* no node textures for now */
|
|
|
|
result_type = multitex_ext_safe(texture, tex_co, texres);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* if the texture gave an RGB value, we assume it didn't give a valid
|
|
|
|
* intensity, so calculate one (formula from do_material_tex).
|
|
|
|
* if the texture didn't give an RGB value, copy the intensity across
|
|
|
|
*/
|
|
|
|
if(result_type & TEX_RGB)
|
|
|
|
texres->tin = (0.35f * texres->tr + 0.45f * texres->tg
|
|
|
|
+ 0.2f * texres->tb);
|
|
|
|
else
|
|
|
|
texres->tr = texres->tg = texres->tb = texres->tin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void modifier_vgroup_cache(ModifierData *md, float (*vertexCos)[3])
|
|
|
|
{
|
|
|
|
while((md=md->next) && md->type==eModifierType_Armature) {
|
|
|
|
ArmatureModifierData *amd = (ArmatureModifierData*) md;
|
|
|
|
if(amd->multi && amd->prevCos==NULL)
|
|
|
|
amd->prevCos= MEM_dupallocN(vertexCos);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* lattice/mesh modifier too */
|
|
|
|
}
|
|
|
|
|
|
|
|
void validate_layer_name(const CustomData *data, int type, char *name, char *outname)
|
|
|
|
{
|
|
|
|
int index = -1;
|
|
|
|
|
|
|
|
/* if a layer name was given, try to find that layer */
|
|
|
|
if(name[0])
|
2010-10-14 06:29:17 +00:00
|
|
|
index = CustomData_get_named_layer_index(data, type, name);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
if(index < 0) {
|
|
|
|
/* either no layer was specified, or the layer we want has been
|
|
|
|
* deleted, so assign the active layer to name
|
|
|
|
*/
|
2010-10-14 06:29:17 +00:00
|
|
|
index = CustomData_get_active_layer_index(data, type);
|
2010-04-11 22:12:30 +00:00
|
|
|
strcpy(outname, data->layers[index].name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
strcpy(outname, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns a cdderivedmesh if dm == NULL or is another type of derivedmesh */
|
2010-10-14 06:29:17 +00:00
|
|
|
DerivedMesh *get_cddm(Object *ob, struct EditMesh *em, DerivedMesh *dm, float (*vertexCos)[3])
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
if(dm && dm->type == DM_TYPE_CDDM)
|
|
|
|
return dm;
|
|
|
|
|
|
|
|
if(!dm) {
|
2010-10-14 06:29:17 +00:00
|
|
|
dm= get_dm(ob, em, dm, vertexCos, 0);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-07-19 04:44:37 +00:00
|
|
|
dm= CDDM_copy(dm, 0);
|
2010-04-11 22:12:30 +00:00
|
|
|
CDDM_apply_vert_coords(dm, vertexCos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dm)
|
|
|
|
CDDM_calc_normals(dm);
|
|
|
|
|
|
|
|
return dm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns a derived mesh if dm == NULL, for deforming modifiers that need it */
|
2010-10-14 06:29:17 +00:00
|
|
|
DerivedMesh *get_dm(Object *ob, struct EditMesh *em, DerivedMesh *dm, float (*vertexCos)[3], int orco)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
if(dm)
|
|
|
|
return dm;
|
|
|
|
|
|
|
|
if(ob->type==OB_MESH) {
|
2011-03-29 05:48:18 +00:00
|
|
|
if(em) dm= CDDM_from_BMEditMesh(em, ob->data, 0);
|
2010-04-11 22:12:30 +00:00
|
|
|
else dm = CDDM_from_mesh((struct Mesh *)(ob->data), ob);
|
|
|
|
|
|
|
|
if(vertexCos) {
|
|
|
|
CDDM_apply_vert_coords(dm, vertexCos);
|
|
|
|
//CDDM_calc_normals(dm);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(orco)
|
|
|
|
DM_add_vert_layer(dm, CD_ORCO, CD_ASSIGN, get_mesh_orco_verts(ob));
|
|
|
|
}
|
|
|
|
else if(ELEM3(ob->type,OB_FONT,OB_CURVE,OB_SURF)) {
|
2010-05-13 19:23:52 +00:00
|
|
|
dm= CDDM_from_curve(ob);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return dm;
|
|
|
|
}
|
2010-04-25 01:10:03 +00:00
|
|
|
|
|
|
|
/* only called by BKE_modifier.h/modifier.c */
|
2010-10-14 06:29:17 +00:00
|
|
|
void modifier_type_init(ModifierTypeInfo *types[])
|
2010-04-25 01:10:03 +00:00
|
|
|
{
|
|
|
|
#define INIT_TYPE(typeName) (types[eModifierType_##typeName] = &modifierType_##typeName)
|
|
|
|
INIT_TYPE(None);
|
|
|
|
INIT_TYPE(Curve);
|
|
|
|
INIT_TYPE(Lattice);
|
|
|
|
INIT_TYPE(Subsurf);
|
|
|
|
INIT_TYPE(Build);
|
|
|
|
INIT_TYPE(Array);
|
|
|
|
INIT_TYPE(Mirror);
|
|
|
|
INIT_TYPE(EdgeSplit);
|
|
|
|
INIT_TYPE(Bevel);
|
|
|
|
INIT_TYPE(Displace);
|
|
|
|
INIT_TYPE(UVProject);
|
|
|
|
INIT_TYPE(Decimate);
|
|
|
|
INIT_TYPE(Smooth);
|
|
|
|
INIT_TYPE(Cast);
|
|
|
|
INIT_TYPE(Wave);
|
|
|
|
INIT_TYPE(Armature);
|
|
|
|
INIT_TYPE(Hook);
|
|
|
|
INIT_TYPE(Softbody);
|
|
|
|
INIT_TYPE(Cloth);
|
|
|
|
INIT_TYPE(Collision);
|
|
|
|
INIT_TYPE(Boolean);
|
|
|
|
INIT_TYPE(MeshDeform);
|
|
|
|
INIT_TYPE(ParticleSystem);
|
|
|
|
INIT_TYPE(ParticleInstance);
|
|
|
|
INIT_TYPE(Explode);
|
|
|
|
INIT_TYPE(Shrinkwrap);
|
|
|
|
INIT_TYPE(Fluidsim);
|
|
|
|
INIT_TYPE(Mask);
|
|
|
|
INIT_TYPE(SimpleDeform);
|
|
|
|
INIT_TYPE(Multires);
|
|
|
|
INIT_TYPE(Surface);
|
|
|
|
INIT_TYPE(Smoke);
|
|
|
|
INIT_TYPE(ShapeKey);
|
|
|
|
INIT_TYPE(Solidify);
|
|
|
|
INIT_TYPE(Screw);
|
2011-03-25 00:32:38 +00:00
|
|
|
INIT_TYPE(NgonInterp);
|
2010-04-25 01:10:03 +00:00
|
|
|
#undef INIT_TYPE
|
|
|
|
}
|