2011-02-23 10:52:22 +00:00
|
|
|
/*
|
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
|
2011-11-29 10:54:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2010-04-11 22:12:30 +00:00
|
|
|
*
|
2011-11-29 10:54:47 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2010-04-11 22:12:30 +00:00
|
|
|
* 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
|
2011-11-29 10:54:47 +00:00
|
|
|
* 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
|
|
|
|
2012-04-10 14:11:45 +00:00
|
|
|
#include "DNA_curve_types.h"
|
|
|
|
#include "DNA_image_types.h"
|
2011-07-11 09:15:20 +00:00
|
|
|
#include "DNA_lattice_types.h"
|
2012-04-10 14:11:45 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
2012-04-10 14:11:45 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2011-05-01 15:16:59 +00:00
|
|
|
#include "BLI_math_vector.h"
|
|
|
|
#include "BLI_math_matrix.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
2011-07-11 09:15:20 +00:00
|
|
|
#include "BKE_deform.h"
|
2012-04-10 14:11:45 +00:00
|
|
|
#include "BKE_image.h"
|
2011-07-11 09:15:20 +00:00
|
|
|
#include "BKE_lattice.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_mesh.h"
|
|
|
|
#include "BKE_displist.h"
|
Fix #36058: Displace Modifier errors using a baked Image and displace baking inconsistency between 2.67/2.68RC and previous versions
This was in fact really nasty bug, caused by multitex_nodes
function using global variable R (which is a copy of current
renderer). this variable is not initialized to anything
meaningful for until first rendering (preview or final)
happened.
Since multitex_nodes might be used outside of render pipeline,
made it so whether CM is on or off as an argument to functions
multitex_ext_safe and multitex_ext. Now multitex_nodes() is
only shall be used for stuff happening from render pipeline!
Also needed to make some changes to other places, so all the
usages of texture sampling knows for the fact whether CM is
on or off.
And one more change is related on behavior of dispalcement,
wave, warp, weightvg modifiers and smoke. They'll be always
using CM off since texture is used for influence, not for
color.
It's rather bigger patch, but it's mostly straightforward
changes, which we really need to be done.
Reviewed by Brecht, thanks!
2013-07-15 14:47:58 +00:00
|
|
|
#include "BKE_scene.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
|
|
|
|
2012-04-10 14:11:45 +00:00
|
|
|
void modifier_init_texture(Scene *scene, Tex *tex)
|
|
|
|
{
|
|
|
|
if (!tex)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tex->ima && ELEM(tex->ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE))
|
2012-05-05 16:03:57 +00:00
|
|
|
BKE_image_user_frame_calc(&tex->iuser, scene->r.cfra, 0);
|
2012-04-10 14:11:45 +00:00
|
|
|
}
|
|
|
|
|
2011-05-01 15:16:59 +00:00
|
|
|
void get_texture_coords(MappingInfoModifierData *dmd, Object *ob,
|
|
|
|
DerivedMesh *dm,
|
|
|
|
float (*co)[3], float (*texco)[3],
|
|
|
|
int numVerts)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int texmapping = dmd->texmapping;
|
|
|
|
float mapob_imat[4][4];
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (texmapping == MOD_DISP_MAP_OBJECT) {
|
|
|
|
if (dmd->map_object)
|
2011-05-01 15:16:59 +00:00
|
|
|
invert_m4_m4(mapob_imat, dmd->map_object->obmat);
|
|
|
|
else /* if there is no map object, default to local */
|
|
|
|
texmapping = MOD_DISP_MAP_LOCAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* UVs need special handling, since they come from faces */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (texmapping == MOD_DISP_MAP_UV) {
|
|
|
|
if (CustomData_has_layer(&dm->loopData, CD_MLOOPUV)) {
|
2012-01-04 21:36:06 +00:00
|
|
|
MPoly *mpoly = dm->getPolyArray(dm);
|
|
|
|
MPoly *mp;
|
|
|
|
MLoop *mloop = dm->getLoopArray(dm);
|
2011-05-01 15:16:59 +00:00
|
|
|
char *done = MEM_callocN(sizeof(*done) * numVerts,
|
|
|
|
"get_texture_coords done");
|
2012-01-04 21:36:06 +00:00
|
|
|
int numPolys = dm->getNumPolys(dm);
|
2012-01-11 08:51:06 +00:00
|
|
|
char uvname[MAX_CUSTOMDATA_LAYER_NAME];
|
2012-01-04 21:36:06 +00:00
|
|
|
MLoopUV *mloop_uv;
|
2011-05-01 15:16:59 +00:00
|
|
|
|
2012-01-04 21:36:06 +00:00
|
|
|
CustomData_validate_layer_name(&dm->loopData, CD_MLOOPUV, dmd->uvlayer_name, uvname);
|
|
|
|
mloop_uv = CustomData_get_layer_named(&dm->loopData, CD_MLOOPUV, uvname);
|
2011-05-01 15:16:59 +00:00
|
|
|
|
|
|
|
/* verts are given the UV from the first face that uses them */
|
2012-03-24 06:24:53 +00:00
|
|
|
for (i = 0, mp = mpoly; i < numPolys; ++i, ++mp) {
|
2012-05-06 13:38:33 +00:00
|
|
|
unsigned int fidx = mp->totloop - 1;
|
2012-01-04 06:20:10 +00:00
|
|
|
|
|
|
|
do {
|
2012-05-06 13:38:33 +00:00
|
|
|
unsigned int lidx = mp->loopstart + fidx;
|
|
|
|
unsigned int vidx = mloop[lidx].v;
|
2012-01-04 06:20:10 +00:00
|
|
|
|
|
|
|
if (done[vidx] == 0) {
|
|
|
|
/* remap UVs from [0, 1] to [-1, 1] */
|
2012-01-04 21:36:06 +00:00
|
|
|
texco[vidx][0] = (mloop_uv[lidx].uv[0] * 2.0f) - 1.0f;
|
|
|
|
texco[vidx][1] = (mloop_uv[lidx].uv[1] * 2.0f) - 1.0f;
|
2012-01-04 06:20:10 +00:00
|
|
|
done[vidx] = 1;
|
|
|
|
}
|
2011-05-01 15:16:59 +00:00
|
|
|
|
2012-01-04 06:20:10 +00:00
|
|
|
} while (fidx--);
|
2011-05-01 15:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(done);
|
|
|
|
return;
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
else /* if there are no UVs, default to local */
|
2011-05-01 15:16:59 +00:00
|
|
|
texmapping = MOD_DISP_MAP_LOCAL;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
for (i = 0; i < numVerts; ++i, ++co, ++texco) {
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (texmapping) {
|
2012-05-06 13:38:33 +00:00
|
|
|
case MOD_DISP_MAP_LOCAL:
|
|
|
|
copy_v3_v3(*texco, *co);
|
|
|
|
break;
|
|
|
|
case MOD_DISP_MAP_GLOBAL:
|
|
|
|
mul_v3_m4v3(*texco, ob->obmat, *co);
|
|
|
|
break;
|
|
|
|
case MOD_DISP_MAP_OBJECT:
|
|
|
|
mul_v3_m4v3(*texco, ob->obmat, *co);
|
|
|
|
mul_m4_v3(mapob_imat, *texco);
|
|
|
|
break;
|
2011-05-01 15:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
void modifier_vgroup_cache(ModifierData *md, float (*vertexCos)[3])
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
while ((md = md->next) && md->type == eModifierType_Armature) {
|
|
|
|
ArmatureModifierData *amd = (ArmatureModifierData *) md;
|
|
|
|
if (amd->multi && amd->prevCos == NULL)
|
|
|
|
amd->prevCos = MEM_dupallocN(vertexCos);
|
2010-04-11 22:12:30 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* lattice/mesh modifier too */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns a cdderivedmesh if dm == NULL or is another type of derivedmesh */
|
2013-07-16 08:24:53 +00:00
|
|
|
DerivedMesh *get_cddm(Object *ob, struct BMEditMesh *em, DerivedMesh *dm, float (*vertexCos)[3], bool use_normals)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2013-07-16 08:24:53 +00:00
|
|
|
if (dm) {
|
|
|
|
if (dm->type != DM_TYPE_CDDM) {
|
|
|
|
dm = CDDM_copy(dm);
|
|
|
|
CDDM_apply_vert_coords(dm, vertexCos);
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2013-07-16 08:24:53 +00:00
|
|
|
if (use_normals) {
|
|
|
|
DM_ensure_normals(dm);
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-07-16 08:24:53 +00:00
|
|
|
dm = get_dm(ob, em, dm, vertexCos, use_normals, false);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return dm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns a derived mesh if dm == NULL, for deforming modifiers that need it */
|
2013-07-16 08:24:53 +00:00
|
|
|
DerivedMesh *get_dm(Object *ob, struct BMEditMesh *em, DerivedMesh *dm,
|
|
|
|
float (*vertexCos)[3], bool use_normals, bool use_orco)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2013-07-16 08:24:53 +00:00
|
|
|
if (dm) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
else if (ob->type == OB_MESH) {
|
2012-10-24 07:24:11 +00:00
|
|
|
if (em) dm = CDDM_from_editbmesh(em, FALSE, FALSE);
|
2010-04-11 22:12:30 +00:00
|
|
|
else dm = CDDM_from_mesh((struct Mesh *)(ob->data), ob);
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (vertexCos) {
|
2010-04-11 22:12:30 +00:00
|
|
|
CDDM_apply_vert_coords(dm, vertexCos);
|
2013-05-30 17:36:43 +00:00
|
|
|
dm->dirty |= DM_DIRTY_NORMALS;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-07-16 08:24:53 +00:00
|
|
|
if (use_orco) {
|
2012-05-05 21:28:12 +00:00
|
|
|
DM_add_vert_layer(dm, CD_ORCO, CD_ASSIGN, BKE_mesh_orco_verts_get(ob));
|
2013-07-16 08:24:53 +00:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2012-04-29 15:47:02 +00:00
|
|
|
else if (ELEM3(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
|
2012-05-06 13:38:33 +00:00
|
|
|
dm = CDDM_from_curve(ob);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-07-16 08:24:53 +00:00
|
|
|
if (use_normals) {
|
|
|
|
if (LIKELY(dm)) {
|
|
|
|
DM_ensure_normals(dm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
return dm;
|
|
|
|
}
|
2010-04-25 01:10:03 +00:00
|
|
|
|
2011-07-11 09:15:20 +00:00
|
|
|
void modifier_get_vgroup(Object *ob, DerivedMesh *dm, const char *name, MDeformVert **dvert, int *defgrp_index)
|
|
|
|
{
|
|
|
|
*defgrp_index = defgroup_name_index(ob, name);
|
|
|
|
*dvert = NULL;
|
|
|
|
|
2012-10-22 17:19:05 +00:00
|
|
|
if (*defgrp_index != -1) {
|
2012-03-24 06:24:53 +00:00
|
|
|
if (ob->type == OB_LATTICE)
|
2012-05-05 16:03:57 +00:00
|
|
|
*dvert = BKE_lattice_deform_verts_get(ob);
|
2012-03-24 06:24:53 +00:00
|
|
|
else if (dm)
|
2011-07-11 09:15:20 +00:00
|
|
|
*dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2011-11-13 12:17:27 +00:00
|
|
|
INIT_TYPE(Ocean);
|
2010-04-25 01:10:03 +00:00
|
|
|
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-05-01 15:16:59 +00:00
|
|
|
INIT_TYPE(Warp);
|
2011-07-25 15:27:01 +00:00
|
|
|
INIT_TYPE(WeightVGEdit);
|
|
|
|
INIT_TYPE(WeightVGMix);
|
|
|
|
INIT_TYPE(WeightVGProximity);
|
2011-05-24 07:08:58 +00:00
|
|
|
INIT_TYPE(DynamicPaint);
|
2011-12-30 21:11:40 +00:00
|
|
|
INIT_TYPE(Remesh);
|
2012-05-22 15:29:01 +00:00
|
|
|
INIT_TYPE(Skin);
|
2012-10-24 10:39:11 +00:00
|
|
|
INIT_TYPE(LaplacianSmooth);
|
2012-11-19 20:40:08 +00:00
|
|
|
INIT_TYPE(Triangulate);
|
2012-12-14 04:07:30 +00:00
|
|
|
INIT_TYPE(UVWarp);
|
2013-01-21 15:41:00 +00:00
|
|
|
INIT_TYPE(MeshCache);
|
2013-11-24 07:00:49 +11:00
|
|
|
INIT_TYPE(LaplacianDeform);
|
2010-04-25 01:10:03 +00:00
|
|
|
#undef INIT_TYPE
|
|
|
|
}
|