2010-04-11 22:12:30 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +00:00
|
|
|
* 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.
|
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
2011-02-25 13:57:17 +00:00
|
|
|
*/
|
|
|
|
|
|
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
|
|
|
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "BLI_utildefines.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"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
#include "DNA_camera_types.h"
|
|
|
|
|
#include "DNA_object_types.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"
|
2017-05-24 23:14:32 +10:00
|
|
|
#include "BKE_material.h"
|
2012-01-04 14:42:11 +00:00
|
|
|
#include "BKE_mesh.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
|
|
|
|
2018-05-25 11:05:51 +02:00
|
|
|
#include "DEG_depsgraph.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"
|
2018-05-25 11:05:51 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
UVProjectModifierData *umd = (UVProjectModifierData *)md;
|
2017-05-24 23:14:32 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
umd->num_projectors = 1;
|
|
|
|
|
umd->aspectx = umd->aspecty = 1.0f;
|
|
|
|
|
umd->scalex = umd->scaley = 1.0f;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void requiredDataMask(Object *UNUSED(ob),
|
|
|
|
|
ModifierData *UNUSED(md),
|
|
|
|
|
CustomData_MeshMasks *r_cddata_masks)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* ask for UV coordinates */
|
|
|
|
|
r_cddata_masks->lmask |= CD_MLOOPUV;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk, void *userData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
UVProjectModifierData *umd = (UVProjectModifierData *)md;
|
|
|
|
|
int i;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
for (i = 0; i < MOD_UVPROJECT_MAXPROJECTORS; ++i) {
|
2019-04-17 06:17:24 +02:00
|
|
|
walk(userData, ob, &umd->projectors[i], IDWALK_CB_NOP);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-04-19 18:07:06 +02:00
|
|
|
#if 0
|
2019-04-17 08:24:14 +02:00
|
|
|
UVProjectModifierData *umd = (UVProjectModifierData *)md;
|
2018-04-19 18:07:06 +02:00
|
|
|
#endif
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
foreachObjectLink(md, ob, (ObjectWalkFunc)walk, userData);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-22 12:54:06 +01:00
|
|
|
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
UVProjectModifierData *umd = (UVProjectModifierData *)md;
|
|
|
|
|
bool do_add_own_transform = false;
|
|
|
|
|
for (int i = 0; i < umd->num_projectors; ++i) {
|
|
|
|
|
if (umd->projectors[i] != NULL) {
|
|
|
|
|
DEG_add_object_relation(
|
|
|
|
|
ctx->node, umd->projectors[i], DEG_OB_COMP_TRANSFORM, "UV Project Modifier");
|
|
|
|
|
do_add_own_transform = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (do_add_own_transform) {
|
|
|
|
|
DEG_add_modifier_to_transform_relation(ctx->node, "UV Project Modifier");
|
|
|
|
|
}
|
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-11 22:12:30 +00:00
|
|
|
typedef struct Projector {
|
2019-04-17 06:17:24 +02: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;
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static Mesh *uvprojectModifier_do(UVProjectModifierData *umd,
|
|
|
|
|
const ModifierEvalContext *UNUSED(ctx),
|
|
|
|
|
Object *ob,
|
|
|
|
|
Mesh *mesh)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float(*coords)[3], (*co)[3];
|
|
|
|
|
MLoopUV *mloop_uv;
|
|
|
|
|
int i, numVerts, numPolys, numLoops;
|
|
|
|
|
MPoly *mpoly, *mp;
|
|
|
|
|
MLoop *mloop;
|
|
|
|
|
Projector projectors[MOD_UVPROJECT_MAXPROJECTORS];
|
|
|
|
|
int num_projectors = 0;
|
|
|
|
|
char uvname[MAX_CUSTOMDATA_LAYER_NAME];
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < umd->num_projectors; ++i) {
|
|
|
|
|
if (umd->projectors[i] != NULL) {
|
|
|
|
|
projectors[num_projectors++].ob = umd->projectors[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (num_projectors == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return mesh;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* make sure there are UV Maps available */
|
|
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (!CustomData_has_layer(&mesh->ldata, CD_MLOOPUV)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return mesh;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* make sure we're using an existing layer */
|
|
|
|
|
CustomData_validate_layer_name(&mesh->ldata, CD_MLOOPUV, umd->uvlayer_name, uvname);
|
|
|
|
|
|
|
|
|
|
/* calculate a projection matrix and normal for each projector */
|
|
|
|
|
for (i = 0; i < num_projectors; ++i) {
|
|
|
|
|
float tmpmat[4][4];
|
|
|
|
|
float offsetmat[4][4];
|
|
|
|
|
Camera *cam = NULL;
|
|
|
|
|
/* calculate projection matrix */
|
|
|
|
|
invert_m4_m4(projectors[i].projmat, projectors[i].ob->obmat);
|
|
|
|
|
|
|
|
|
|
projectors[i].uci = NULL;
|
|
|
|
|
|
|
|
|
|
if (projectors[i].ob->type == OB_CAMERA) {
|
|
|
|
|
cam = (Camera *)projectors[i].ob->data;
|
|
|
|
|
if (cam->type == CAM_PANO) {
|
|
|
|
|
projectors[i].uci = BLI_uvproject_camera_info(projectors[i].ob, NULL, aspx, aspy);
|
|
|
|
|
BLI_uvproject_camera_info_scale(projectors[i].uci, scax, scay);
|
|
|
|
|
free_uci = 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
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);
|
|
|
|
|
mul_m4_m4m4(tmpmat, params.winmat, projectors[i].projmat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
mul_m4_m4m4(projectors[i].projmat, offsetmat, tmpmat);
|
|
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
numPolys = mesh->totpoly;
|
|
|
|
|
numLoops = mesh->totloop;
|
|
|
|
|
|
|
|
|
|
/* make sure we are not modifying the original UV map */
|
|
|
|
|
mloop_uv = CustomData_duplicate_referenced_layer_named(
|
|
|
|
|
&mesh->ldata, CD_MLOOPUV, uvname, numLoops);
|
|
|
|
|
|
|
|
|
|
coords = BKE_mesh_vertexCos_get(mesh, &numVerts);
|
|
|
|
|
|
|
|
|
|
/* convert coords to world space */
|
2019-04-22 09:15:10 +10:00
|
|
|
for (i = 0, co = coords; i < numVerts; ++i, ++co) {
|
2019-04-17 06:17:24 +02:00
|
|
|
mul_m4_v3(ob->obmat, *co);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* if only one projector, project coords to UVs */
|
2019-04-22 09:15:10 +10:00
|
|
|
if (num_projectors == 1 && projectors[0].uci == NULL) {
|
|
|
|
|
for (i = 0, co = coords; i < numVerts; ++i, ++co) {
|
2019-04-17 06:17:24 +02:00
|
|
|
mul_project_m4_v3(projectors[0].projmat, *co);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
mpoly = mesh->mpoly;
|
|
|
|
|
mloop = mesh->mloop;
|
|
|
|
|
|
|
|
|
|
/* apply coords as UVs */
|
|
|
|
|
for (i = 0, mp = mpoly; i < numPolys; ++i, ++mp) {
|
|
|
|
|
if (num_projectors == 1) {
|
|
|
|
|
if (projectors[0].uci) {
|
|
|
|
|
unsigned int fidx = mp->totloop - 1;
|
|
|
|
|
do {
|
|
|
|
|
unsigned int lidx = mp->loopstart + fidx;
|
|
|
|
|
unsigned int vidx = mloop[lidx].v;
|
|
|
|
|
BLI_uvproject_from_camera(mloop_uv[lidx].uv, coords[vidx], projectors[0].uci);
|
|
|
|
|
} while (fidx--);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* apply transformed coords as UVs */
|
|
|
|
|
unsigned int fidx = mp->totloop - 1;
|
|
|
|
|
do {
|
|
|
|
|
unsigned int lidx = mp->loopstart + fidx;
|
|
|
|
|
unsigned int vidx = mloop[lidx].v;
|
|
|
|
|
copy_v2_v2(mloop_uv[lidx].uv, coords[vidx]);
|
|
|
|
|
} while (fidx--);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* multiple projectors, select the closest to face normal direction */
|
|
|
|
|
float face_no[3];
|
|
|
|
|
int j;
|
|
|
|
|
Projector *best_projector;
|
|
|
|
|
float best_dot;
|
|
|
|
|
|
|
|
|
|
/* get the untransformed face normal */
|
|
|
|
|
BKE_mesh_calc_poly_normal_coords(
|
|
|
|
|
mp, mloop + mp->loopstart, (const float(*)[3])coords, face_no);
|
|
|
|
|
|
|
|
|
|
/* find the projector which the face points at most directly
|
|
|
|
|
* (projector normal with largest dot product is best)
|
|
|
|
|
*/
|
|
|
|
|
best_dot = dot_v3v3(projectors[0].normal, face_no);
|
|
|
|
|
best_projector = &projectors[0];
|
|
|
|
|
|
|
|
|
|
for (j = 1; j < num_projectors; ++j) {
|
|
|
|
|
float tmp_dot = dot_v3v3(projectors[j].normal, face_no);
|
|
|
|
|
if (tmp_dot > best_dot) {
|
|
|
|
|
best_dot = tmp_dot;
|
|
|
|
|
best_projector = &projectors[j];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (best_projector->uci) {
|
|
|
|
|
unsigned int fidx = mp->totloop - 1;
|
|
|
|
|
do {
|
|
|
|
|
unsigned int lidx = mp->loopstart + fidx;
|
|
|
|
|
unsigned int vidx = mloop[lidx].v;
|
|
|
|
|
BLI_uvproject_from_camera(mloop_uv[lidx].uv, coords[vidx], best_projector->uci);
|
|
|
|
|
} while (fidx--);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
unsigned int fidx = mp->totloop - 1;
|
|
|
|
|
do {
|
|
|
|
|
unsigned int lidx = mp->loopstart + fidx;
|
|
|
|
|
unsigned int vidx = mloop[lidx].v;
|
|
|
|
|
mul_v2_project_m4_v3(mloop_uv[lidx].uv, best_projector->projmat, coords[vidx]);
|
|
|
|
|
} while (fidx--);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MEM_freeN(coords);
|
|
|
|
|
|
|
|
|
|
if (free_uci) {
|
|
|
|
|
int j;
|
|
|
|
|
for (j = 0; j < num_projectors; ++j) {
|
|
|
|
|
if (projectors[j].uci) {
|
|
|
|
|
MEM_freeN(projectors[j].uci);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Mark tessellated CD layers as dirty. */
|
|
|
|
|
mesh->runtime.cd_dirty_vert |= CD_MASK_TESSLOOPNORMAL;
|
|
|
|
|
|
|
|
|
|
return mesh;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Mesh *result;
|
|
|
|
|
UVProjectModifierData *umd = (UVProjectModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
result = uvprojectModifier_do(umd, ctx, ctx->object, mesh);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return result;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_UVProject = {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* name */ "UVProject",
|
|
|
|
|
/* structName */ "UVProjectModifierData",
|
|
|
|
|
/* structSize */ sizeof(UVProjectModifierData),
|
|
|
|
|
/* type */ eModifierTypeType_NonGeometrical,
|
|
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsMapping |
|
|
|
|
|
eModifierTypeFlag_SupportsEditmode | eModifierTypeFlag_EnableInEditmode,
|
|
|
|
|
|
|
|
|
|
/* copyData */ modifier_copyData_generic,
|
|
|
|
|
|
|
|
|
|
/* deformVerts */ NULL,
|
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
|
/* deformMatricesEM */ NULL,
|
|
|
|
|
/* applyModifier */ applyModifier,
|
|
|
|
|
|
|
|
|
|
/* initData */ initData,
|
|
|
|
|
/* requiredDataMask */ requiredDataMask,
|
|
|
|
|
/* freeData */ NULL,
|
|
|
|
|
/* isDisabled */ NULL,
|
|
|
|
|
/* updateDepsgraph */ updateDepsgraph,
|
|
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
|
/* foreachObjectLink */ foreachObjectLink,
|
|
|
|
|
/* foreachIDLink */ foreachIDLink,
|
|
|
|
|
/* foreachTexLink */ NULL,
|
|
|
|
|
/* freeRuntimeData */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|