Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-01-04 18:42:11 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-01-04 18:42:11 +0400
commit570b13fbba045b047174d499343eaabcb5820b08 (patch)
tree358165737e15239c03c9527a696134011341701c /source/blender/modifiers/intern/MOD_uvproject.c
parent46b1ad99d390a5f2f3b670a67bd62f37987846b5 (diff)
update UV project modifier to use MLoopUV's rather then tessface UV's
Diffstat (limited to 'source/blender/modifiers/intern/MOD_uvproject.c')
-rw-r--r--source/blender/modifiers/intern/MOD_uvproject.c70
1 files changed, 39 insertions, 31 deletions
diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c
index 2aed6f05277..47c8e2a7d05 100644
--- a/source/blender/modifiers/intern/MOD_uvproject.c
+++ b/source/blender/modifiers/intern/MOD_uvproject.c
@@ -47,6 +47,7 @@
#include "BKE_camera.h"
+#include "BKE_mesh.h"
#include "BKE_DerivedMesh.h"
#include "MOD_modifiertypes.h"
@@ -147,10 +148,12 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
Object *ob, DerivedMesh *dm)
{
float (*coords)[3], (*co)[3];
- MTFace *tface;
- int i, numVerts, numFaces;
+ MLoopUV *mloop_uv;
+ MTexPoly *mtexpoly, *mt;
+ int i, numVerts, numPolys, numLoops;
Image *image = umd->image;
- MFace *mface, *mf;
+ MPoly *mpoly, *mp;
+ MLoop *mloop;
int override_image = ((umd->flags & MOD_UVPROJECT_OVERRIDEIMAGE) != 0);
Projector projectors[MOD_UVPROJECT_MAXPROJECTORS];
int num_projectors = 0;
@@ -172,10 +175,10 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
/* make sure there are UV Maps available */
- if(!CustomData_has_layer(&dm->faceData, CD_MTFACE)) return dm;
+ if(!CustomData_has_layer(&dm->loopData, CD_MLOOPUV)) return dm;
/* make sure we're using an existing layer */
- CustomData_validate_layer_name(&dm->faceData, CD_MTFACE, umd->uvlayer_name, uvname);
+ CustomData_validate_layer_name(&dm->loopData, CD_MLOOPUV, umd->uvlayer_name, uvname);
/* calculate a projection matrix and normal for each projector */
for(i = 0; i < num_projectors; ++i) {
@@ -259,11 +262,16 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
mul_mat3_m4_v3(projectors[i].ob->obmat, projectors[i].normal);
}
- numFaces = dm->getNumTessFaces(dm);
+ numPolys = dm->getNumPolys(dm);
+ numLoops = dm->getNumLoops(dm);
/* make sure we are not modifying the original UV map */
- tface = CustomData_duplicate_referenced_layer_named(&dm->faceData,
- CD_MTFACE, uvname, numFaces);
+ mloop_uv = CustomData_duplicate_referenced_layer_named(&dm->loopData,
+ CD_MLOOPUV, uvname, numLoops);
+
+ /* can be NULL */
+ mtexpoly = CustomData_duplicate_referenced_layer_named(&dm->polyData,
+ CD_MTEXPOLY, uvname, numPolys);
numVerts = dm->getNumVerts(dm);
@@ -280,26 +288,28 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
for(i = 0, co = coords; i < numVerts; ++i, ++co)
mul_project_m4_v3(projectors[0].projmat, *co);
- mface = dm->getTessFaceArray(dm);
- numFaces = dm->getNumTessFaces(dm);
+ mpoly = dm->getPolyArray(dm);
+ mloop = dm->getLoopArray(dm);
/* apply coords as UVs, and apply image if tfaces are new */
- for(i = 0, mf = mface; i < numFaces; ++i, ++mf, ++tface) {
- if(override_image || !image || tface->tpage == image) {
+ 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) {
- unsigned int fidx= mf->v4 ? 3:2;
+ unsigned int fidx= mp->totloop - 1;
do {
- unsigned int vidx= *(&mf->v1 + fidx);
- project_from_camera(tface->uv[fidx], coords[vidx], projectors[0].uci);
+ unsigned int lidx= mp->loopstart + fidx;
+ unsigned int vidx= mloop[lidx].v;
+ project_from_camera(mloop_uv[lidx].uv, coords[vidx], projectors[0].uci);
} while (fidx--);
}
else {
/* apply transformed coords as UVs */
- unsigned int fidx= mf->v4 ? 3:2;
+ unsigned int fidx= mp->totloop - 1;
do {
- unsigned int vidx= *(&mf->v1 + fidx);
- copy_v2_v2(tface->uv[fidx], coords[vidx]);
+ unsigned int lidx= mp->loopstart + fidx;
+ unsigned int vidx= mloop[lidx].v;
+ copy_v2_v2(mloop_uv[lidx].uv, coords[vidx]);
} while (fidx--);
}
} else {
@@ -312,11 +322,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
float best_dot;
/* get the untransformed face normal */
- if(mf->v4) {
- normal_quad_v3(face_no, coords[mf->v1], coords[mf->v2], coords[mf->v3], coords[mf->v4]);
- } else {
- normal_tri_v3(face_no, coords[mf->v1], coords[mf->v2], coords[mf->v3]);
- }
+ 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)
@@ -334,29 +340,31 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
}
if(best_projector->uci) {
- unsigned int fidx= mf->v4 ? 3:2;
+ unsigned int fidx= mp->totloop - 1;
do {
- unsigned int vidx= *(&mf->v1 + fidx);
- project_from_camera(tface->uv[fidx], coords[vidx], best_projector->uci);
+ unsigned int lidx= mp->loopstart + fidx;
+ unsigned int vidx= mloop[lidx].v;
+ project_from_camera(mloop_uv[lidx].uv, coords[vidx], best_projector->uci);
} while (fidx--);
}
else {
- unsigned int fidx= mf->v4 ? 3:2;
+ unsigned int fidx= mp->totloop - 1;
do {
- unsigned int vidx= *(&mf->v1 + fidx);
+ unsigned int lidx= mp->loopstart + fidx;
+ unsigned int vidx= mloop[lidx].v;
float tco[3];
copy_v3_v3(tco, coords[vidx]);
mul_project_m4_v3(best_projector->projmat, tco);
- copy_v2_v2(tface->uv[fidx], tco);
+ copy_v2_v2(mloop_uv[lidx].uv, tco);
} while (fidx--);
}
}
}
- if(override_image) {
- tface->tpage = image;
+ if(override_image && mtexpoly) {
+ mt->tpage = image;
}
}