diff options
Diffstat (limited to 'source/blender/modifiers/intern/MOD_uvproject.c')
-rw-r--r-- | source/blender/modifiers/intern/MOD_uvproject.c | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c index 77ce879bbf6..7cd65236c5d 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 = NULL; + 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->getNumFaces(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,25 +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->getFaceArray(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 { @@ -311,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) @@ -333,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; } } @@ -386,7 +395,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, } static DerivedMesh *applyModifierEM(ModifierData *md, Object *ob, - struct EditMesh *UNUSED(editData), + struct BMEditMesh *UNUSED(editData), DerivedMesh *derivedData) { return applyModifier(md, ob, derivedData, 0, 1); |