2010-04-11 22:12:30 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +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.
|
|
|
|
*
|
|
|
|
* 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) 2005 by the Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Daniel Dunbar
|
|
|
|
* Ton Roosendaal,
|
|
|
|
* Ben Batt,
|
|
|
|
* Brecht Van Lommel,
|
|
|
|
* Campbell Barton
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-02-25 13:57:17 +00:00
|
|
|
/** \file blender/modifiers/intern/MOD_uvproject.c
|
|
|
|
* \ingroup modifiers
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
/* UV Project modifier: Generates UVs projected from an object */
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "DNA_camera_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_object_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 01:09:59 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
#include "BLI_uvproject.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
|
2011-11-19 20:40:46 +00:00
|
|
|
#include "BKE_camera.h"
|
2015-10-08 14:21:11 +02:00
|
|
|
#include "BKE_library_query.h"
|
2012-01-04 14:42:11 +00:00
|
|
|
#include "BKE_mesh.h"
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
#include "MOD_modifiertypes.h"
|
|
|
|
|
2010-04-12 01:09:59 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "depsgraph_private.h"
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
#include "DEG_depsgraph_build.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
UVProjectModifierData *umd = (UVProjectModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
umd->flags = 0;
|
|
|
|
umd->num_projectors = 1;
|
|
|
|
umd->aspectx = umd->aspecty = 1.0f;
|
|
|
|
umd->scalex = umd->scaley = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void copyData(ModifierData *md, ModifierData *target)
|
|
|
|
{
|
2013-12-22 04:35:52 +11:00
|
|
|
#if 0
|
2012-05-06 13:38:33 +00:00
|
|
|
UVProjectModifierData *umd = (UVProjectModifierData *) md;
|
|
|
|
UVProjectModifierData *tumd = (UVProjectModifierData *) target;
|
2013-12-22 04:35:52 +11:00
|
|
|
#endif
|
|
|
|
modifier_copyData_generic(md, target);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED(md))
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
CustomDataMask dataMask = 0;
|
|
|
|
|
|
|
|
/* ask for UV coordinates */
|
2013-09-18 15:48:24 +00:00
|
|
|
dataMask |= CD_MLOOPUV | CD_MTEXPOLY;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
return dataMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void foreachObjectLink(ModifierData *md, Object *ob,
|
2012-05-06 13:38:33 +00:00
|
|
|
ObjectWalkFunc walk, void *userData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
UVProjectModifierData *umd = (UVProjectModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
int i;
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
for (i = 0; i < MOD_UVPROJECT_MAXPROJECTORS; ++i)
|
2015-10-08 14:21:11 +02:00
|
|
|
walk(userData, ob, &umd->projectors[i], IDWALK_NOP);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void foreachIDLink(ModifierData *md, Object *ob,
|
2012-05-06 13:38:33 +00:00
|
|
|
IDWalkFunc walk, void *userData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
UVProjectModifierData *umd = (UVProjectModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2015-10-08 14:21:11 +02:00
|
|
|
walk(userData, ob, (ID **)&umd->image, IDWALK_USER);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2015-10-05 15:57:10 +02:00
|
|
|
foreachObjectLink(md, ob, (ObjectWalkFunc)walk, userData);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
static void updateDepgraph(ModifierData *md, DagForest *forest,
|
2015-03-13 11:48:04 +05:00
|
|
|
struct Main *UNUSED(bmain),
|
2012-05-06 13:38:33 +00:00
|
|
|
struct Scene *UNUSED(scene),
|
|
|
|
Object *UNUSED(ob),
|
|
|
|
DagNode *obNode)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
UVProjectModifierData *umd = (UVProjectModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
int i;
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
for (i = 0; i < umd->num_projectors; ++i) {
|
|
|
|
if (umd->projectors[i]) {
|
2010-04-11 22:12:30 +00:00
|
|
|
DagNode *curNode = dag_get_node(forest, umd->projectors[i]);
|
|
|
|
|
|
|
|
dag_add_relation(forest, curNode, obNode,
|
2012-05-06 13:38:33 +00:00
|
|
|
DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "UV Project Modifier");
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
static void updateDepsgraph(ModifierData *md,
|
|
|
|
struct Main *UNUSED(bmain),
|
|
|
|
struct Scene *UNUSED(scene),
|
|
|
|
Object *UNUSED(ob),
|
|
|
|
struct DepsNodeHandle *node)
|
|
|
|
{
|
|
|
|
UVProjectModifierData *umd = (UVProjectModifierData *)md;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < umd->num_projectors; ++i) {
|
|
|
|
if (umd->projectors[i] != NULL) {
|
|
|
|
DEG_add_object_relation(node, umd->projectors[i], DEG_OB_COMP_TRANSFORM, "UV Project Modifier");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
typedef struct Projector {
|
2012-05-06 13:38:33 +00:00
|
|
|
Object *ob; /* object this projector is derived from */
|
|
|
|
float projmat[4][4]; /* projection matrix */
|
|
|
|
float normal[3]; /* projector normal in world space */
|
|
|
|
void *uci; /* optional uv-project info (panorama projection) */
|
2010-04-11 22:12:30 +00:00
|
|
|
} Projector;
|
|
|
|
|
|
|
|
static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
|
2012-05-06 13:38:33 +00:00
|
|
|
Object *ob, DerivedMesh *dm)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
float (*coords)[3], (*co)[3];
|
2012-01-04 14:42:11 +00:00
|
|
|
MLoopUV *mloop_uv;
|
2012-01-20 14:44:38 +00:00
|
|
|
MTexPoly *mtexpoly, *mt = NULL;
|
2012-01-04 14:42:11 +00:00
|
|
|
int i, numVerts, numPolys, numLoops;
|
2010-04-11 22:12:30 +00:00
|
|
|
Image *image = umd->image;
|
2012-01-04 14:42:11 +00:00
|
|
|
MPoly *mpoly, *mp;
|
|
|
|
MLoop *mloop;
|
2015-04-20 23:37:04 +10:00
|
|
|
const bool override_image = (umd->flags & MOD_UVPROJECT_OVERRIDEIMAGE) != 0;
|
2010-04-11 22:12:30 +00:00
|
|
|
Projector projectors[MOD_UVPROJECT_MAXPROJECTORS];
|
|
|
|
int num_projectors = 0;
|
2012-01-11 08:51:06 +00:00
|
|
|
char uvname[MAX_CUSTOMDATA_LAYER_NAME];
|
2012-05-06 13:38:33 +00:00
|
|
|
float aspx = umd->aspectx ? umd->aspectx : 1.0f;
|
|
|
|
float aspy = umd->aspecty ? umd->aspecty : 1.0f;
|
|
|
|
float scax = umd->scalex ? umd->scalex : 1.0f;
|
|
|
|
float scay = umd->scaley ? umd->scaley : 1.0f;
|
|
|
|
int free_uci = 0;
|
2011-11-04 14:36:06 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
for (i = 0; i < umd->num_projectors; ++i)
|
|
|
|
if (umd->projectors[i])
|
2010-04-11 22:12:30 +00:00
|
|
|
projectors[num_projectors++].ob = umd->projectors[i];
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (num_projectors == 0) return dm;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-11-23 17:25:25 +00:00
|
|
|
/* make sure there are UV Maps available */
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (!CustomData_has_layer(&dm->loopData, CD_MLOOPUV)) return dm;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* make sure we're using an existing layer */
|
2012-01-04 14:42:11 +00:00
|
|
|
CustomData_validate_layer_name(&dm->loopData, CD_MLOOPUV, umd->uvlayer_name, uvname);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* calculate a projection matrix and normal for each projector */
|
2012-03-24 06:24:53 +00:00
|
|
|
for (i = 0; i < num_projectors; ++i) {
|
2010-04-11 22:12:30 +00:00
|
|
|
float tmpmat[4][4];
|
|
|
|
float offsetmat[4][4];
|
|
|
|
Camera *cam = NULL;
|
|
|
|
/* calculate projection matrix */
|
|
|
|
invert_m4_m4(projectors[i].projmat, projectors[i].ob->obmat);
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
projectors[i].uci = NULL;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (projectors[i].ob->type == OB_CAMERA) {
|
2010-06-15 21:46:02 +00:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
cam = (Camera *)projectors[i].ob->data;
|
2012-05-04 16:20:51 +00:00
|
|
|
if (cam->type == CAM_PANO) {
|
2012-05-06 13:38:33 +00:00
|
|
|
projectors[i].uci = BLI_uvproject_camera_info(projectors[i].ob, NULL, aspx, aspy);
|
2012-05-05 00:23:55 +00:00
|
|
|
BLI_uvproject_camera_info_scale(projectors[i].uci, scax, scay);
|
2012-05-06 13:38:33 +00:00
|
|
|
free_uci = 1;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2010-06-15 21:46:02 +00:00
|
|
|
else {
|
2012-09-22 03:33:31 +00:00
|
|
|
CameraParams params;
|
|
|
|
|
|
|
|
/* setup parameters */
|
|
|
|
BKE_camera_params_init(¶ms);
|
|
|
|
BKE_camera_params_from_object(¶ms, projectors[i].ob);
|
|
|
|
|
|
|
|
/* compute matrix, viewplane, .. */
|
|
|
|
BKE_camera_params_compute_viewplane(¶ms, 1, 1, aspx, aspy);
|
|
|
|
|
|
|
|
/* scale the view-plane */
|
|
|
|
params.viewplane.xmin *= scax;
|
|
|
|
params.viewplane.xmax *= scax;
|
|
|
|
params.viewplane.ymin *= scay;
|
|
|
|
params.viewplane.ymax *= scay;
|
|
|
|
|
|
|
|
BKE_camera_params_compute_matrix(¶ms);
|
2013-05-26 18:36:25 +00:00
|
|
|
mul_m4_m4m4(tmpmat, params.winmat, projectors[i].projmat);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-04-11 22:12:30 +00:00
|
|
|
copy_m4_m4(tmpmat, projectors[i].projmat);
|
|
|
|
}
|
|
|
|
|
|
|
|
unit_m4(offsetmat);
|
|
|
|
mul_mat3_m4_fl(offsetmat, 0.5);
|
|
|
|
offsetmat[3][0] = offsetmat[3][1] = offsetmat[3][2] = 0.5;
|
2012-09-22 03:33:31 +00:00
|
|
|
|
2013-05-26 18:36:25 +00:00
|
|
|
mul_m4_m4m4(projectors[i].projmat, offsetmat, tmpmat);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* calculate worldspace projector normal (for best projector test) */
|
|
|
|
projectors[i].normal[0] = 0;
|
|
|
|
projectors[i].normal[1] = 0;
|
|
|
|
projectors[i].normal[2] = 1;
|
|
|
|
mul_mat3_m4_v3(projectors[i].ob->obmat, projectors[i].normal);
|
|
|
|
}
|
|
|
|
|
2012-01-04 14:42:11 +00:00
|
|
|
numPolys = dm->getNumPolys(dm);
|
|
|
|
numLoops = dm->getNumLoops(dm);
|
2011-12-19 08:26:53 +00:00
|
|
|
|
2011-11-23 17:25:25 +00:00
|
|
|
/* make sure we are not modifying the original UV map */
|
2012-01-04 14:42:11 +00:00
|
|
|
mloop_uv = CustomData_duplicate_referenced_layer_named(&dm->loopData,
|
2012-05-06 13:38:33 +00:00
|
|
|
CD_MLOOPUV, uvname, numLoops);
|
2012-01-04 14:42:11 +00:00
|
|
|
|
|
|
|
/* can be NULL */
|
2012-02-24 12:30:49 +00:00
|
|
|
mt = mtexpoly = CustomData_duplicate_referenced_layer_named(&dm->polyData,
|
2012-05-06 13:38:33 +00:00
|
|
|
CD_MTEXPOLY, uvname, numPolys);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
numVerts = dm->getNumVerts(dm);
|
|
|
|
|
2014-04-04 14:26:01 +11:00
|
|
|
coords = MEM_mallocN(sizeof(*coords) * numVerts,
|
2012-05-06 13:38:33 +00:00
|
|
|
"uvprojectModifier_do coords");
|
2010-04-11 22:12:30 +00:00
|
|
|
dm->getVertCos(dm, coords);
|
|
|
|
|
|
|
|
/* convert coords to world space */
|
2012-03-24 06:24:53 +00:00
|
|
|
for (i = 0, co = coords; i < numVerts; ++i, ++co)
|
2010-04-11 22:12:30 +00:00
|
|
|
mul_m4_v3(ob->obmat, *co);
|
|
|
|
|
|
|
|
/* if only one projector, project coords to UVs */
|
2012-05-06 13:38:33 +00:00
|
|
|
if (num_projectors == 1 && projectors[0].uci == NULL)
|
2012-03-24 06:24:53 +00:00
|
|
|
for (i = 0, co = coords; i < numVerts; ++i, ++co)
|
2011-05-20 10:09:03 +00:00
|
|
|
mul_project_m4_v3(projectors[0].projmat, *co);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-01-04 14:42:11 +00:00
|
|
|
mpoly = dm->getPolyArray(dm);
|
|
|
|
mloop = dm->getLoopArray(dm);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* apply coords as UVs, and apply image if tfaces are new */
|
2012-03-24 06:24:53 +00:00
|
|
|
for (i = 0, mp = mpoly; i < numPolys; ++i, ++mp, ++mt) {
|
|
|
|
if (override_image || !image || (mtexpoly == NULL || mt->tpage == image)) {
|
|
|
|
if (num_projectors == 1) {
|
|
|
|
if (projectors[0].uci) {
|
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-05-05 00:23:55 +00:00
|
|
|
BLI_uvproject_from_camera(mloop_uv[lidx].uv, coords[vidx], projectors[0].uci);
|
2012-01-04 06:20:10 +00:00
|
|
|
} while (fidx--);
|
2010-06-15 21:46:02 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* apply transformed coords as UVs */
|
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 14:42:11 +00:00
|
|
|
copy_v2_v2(mloop_uv[lidx].uv, coords[vidx]);
|
2012-01-04 06:20:10 +00:00
|
|
|
} while (fidx--);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-09 18:28:30 +00:00
|
|
|
/* multiple projectors, select the closest to face normal direction */
|
2010-04-11 22:12:30 +00:00
|
|
|
float face_no[3];
|
|
|
|
int j;
|
|
|
|
Projector *best_projector;
|
|
|
|
float best_dot;
|
|
|
|
|
|
|
|
/* get the untransformed face normal */
|
2012-05-05 21:28:12 +00:00
|
|
|
BKE_mesh_calc_poly_normal_coords(mp, mloop + mp->loopstart, (const float (*)[3])coords, face_no);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* find the projector which the face points at most directly
|
2012-03-09 18:28:30 +00:00
|
|
|
* (projector normal with largest dot product is best)
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
best_dot = dot_v3v3(projectors[0].normal, face_no);
|
|
|
|
best_projector = &projectors[0];
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
for (j = 1; j < num_projectors; ++j) {
|
2010-04-11 22:12:30 +00:00
|
|
|
float tmp_dot = dot_v3v3(projectors[j].normal,
|
2012-05-06 13:38:33 +00:00
|
|
|
face_no);
|
2012-03-24 06:24:53 +00:00
|
|
|
if (tmp_dot > best_dot) {
|
2010-04-11 22:12:30 +00:00
|
|
|
best_dot = tmp_dot;
|
|
|
|
best_projector = &projectors[j];
|
|
|
|
}
|
|
|
|
}
|
2010-06-15 21:46:02 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (best_projector->uci) {
|
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-05-05 00:23:55 +00:00
|
|
|
BLI_uvproject_from_camera(mloop_uv[lidx].uv, coords[vidx], best_projector->uci);
|
2012-01-04 06:20:10 +00:00
|
|
|
} while (fidx--);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
else {
|
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;
|
2013-05-08 12:55:36 +00:00
|
|
|
mul_v2_project_m4_v3(mloop_uv[lidx].uv, best_projector->projmat, coords[vidx]);
|
2012-01-04 06:20:10 +00:00
|
|
|
} while (fidx--);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (override_image && mtexpoly) {
|
2012-01-04 14:42:11 +00:00
|
|
|
mt->tpage = image;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(coords);
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (free_uci) {
|
2010-04-11 22:12:30 +00:00
|
|
|
int j;
|
2012-03-24 06:24:53 +00:00
|
|
|
for (j = 0; j < num_projectors; ++j) {
|
|
|
|
if (projectors[j].uci) {
|
2010-04-11 22:12:30 +00:00
|
|
|
MEM_freeN(projectors[j].uci);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Fix [#30234] Various problems with CD layers and tesselation, related to modifiers stack.
Should also fix [#30266], [#29451], and partly [#30316].
Here are the changes made by this commit:
* It adds a "dirty" flag to DerivedMesh struct (for now, only DM_DIRTY_TESS_CDLAYERS, but more might be added as needed).
* It adds a new func, DM_update_tessface_data, which assumes tessfaces themselves are valid, but updates tessellated customdata from their poly/loop counter parts.
* At end of modstack, when valid tessellated faces are present in finaldm , but the cdlayers dirty flag is set, call that function (instead of recomputing the whole tessellation).
* Edits to the codes concerned (UVProject, DynamicPaint, and Subsurf modifiers).
* Also add to subsurf dm generation code the creation of a CD_POLYINDEX layer (mandatory for DM_update_tessface_data to work well, and imho all tessellated dm should have one).
Note: some pieces of old code are just #if 0’ed, will clean them later.
2012-03-18 22:06:57 +00:00
|
|
|
|
|
|
|
/* Mark tessellated CD layers as dirty. */
|
|
|
|
dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
return dm;
|
|
|
|
}
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
|
2012-05-06 13:38:33 +00:00
|
|
|
DerivedMesh *derivedData,
|
2012-05-09 15:00:26 +00:00
|
|
|
ModifierApplyFlag UNUSED(flag))
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
DerivedMesh *result;
|
2012-05-06 13:38:33 +00:00
|
|
|
UVProjectModifierData *umd = (UVProjectModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
result = uvprojectModifier_do(umd, ob, derivedData);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_UVProject = {
|
|
|
|
/* name */ "UVProject",
|
|
|
|
/* structName */ "UVProjectModifierData",
|
|
|
|
/* structSize */ sizeof(UVProjectModifierData),
|
2011-12-20 14:15:59 +00:00
|
|
|
/* type */ eModifierTypeType_NonGeometrical,
|
2012-05-06 13:38:33 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
|
|
|
eModifierTypeFlag_SupportsMapping |
|
|
|
|
eModifierTypeFlag_SupportsEditmode |
|
|
|
|
eModifierTypeFlag_EnableInEditmode,
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* copyData */ copyData,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* applyModifier */ applyModifier,
|
2013-05-02 14:42:05 +00:00
|
|
|
/* applyModifierEM */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ requiredDataMask,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* freeData */ NULL,
|
|
|
|
/* isDisabled */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* updateDepgraph */ updateDepgraph,
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
/* updateDepsgraph */ updateDepsgraph,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
/* dependsOnNormals */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* foreachObjectLink */ foreachObjectLink,
|
|
|
|
/* foreachIDLink */ foreachIDLink,
|
2011-08-12 18:11:22 +00:00
|
|
|
/* foreachTexLink */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|