diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-01-04 10:20:10 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-01-04 10:20:10 +0400 |
commit | d0cdefd9fa37bf6788dad27b87d8d569c58ad94a (patch) | |
tree | 8807f7717662ad96cf6ad1d8df0a5caa12162361 /source/blender/modifiers/intern | |
parent | 8d8403c15ec8694d7d71d8a9f4a9e3a1fade666e (diff) | |
parent | 434c1e6df82a082fe03034a3ad3825f7b50ea533 (diff) |
svn merge ^/trunk/blender -r43092:43092
Diffstat (limited to 'source/blender/modifiers/intern')
-rw-r--r-- | source/blender/modifiers/intern/MOD_util.c | 41 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_uvproject.c | 62 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_wave.c | 91 |
3 files changed, 41 insertions, 153 deletions
diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c index 8c2b86094f1..6d2e2b42405 100644 --- a/source/blender/modifiers/intern/MOD_util.c +++ b/source/blender/modifiers/intern/MOD_util.c @@ -107,36 +107,19 @@ void get_texture_coords(MappingInfoModifierData *dmd, Object *ob, /* verts are given the UV from the first face that uses them */ for(i = 0, mf = mface; i < numFaces; ++i, ++mf, ++tf) { - if(!done[mf->v1]) { - texco[mf->v1][0] = tf->uv[0][0]; - texco[mf->v1][1] = tf->uv[0][1]; - texco[mf->v1][2] = 0; - done[mf->v1] = 1; - } - if(!done[mf->v2]) { - texco[mf->v2][0] = tf->uv[1][0]; - texco[mf->v2][1] = tf->uv[1][1]; - texco[mf->v2][2] = 0; - done[mf->v2] = 1; - } - if(!done[mf->v3]) { - texco[mf->v3][0] = tf->uv[2][0]; - texco[mf->v3][1] = tf->uv[2][1]; - texco[mf->v3][2] = 0; - done[mf->v3] = 1; - } - if(!done[mf->v4]) { - texco[mf->v4][0] = tf->uv[3][0]; - texco[mf->v4][1] = tf->uv[3][1]; - texco[mf->v4][2] = 0; - done[mf->v4] = 1; - } - } + unsigned int fidx= mf->v4 ? 3:2; + + do { + unsigned int vidx = *(&mf->v1 + fidx); + + if (done[vidx] == 0) { + /* remap UVs from [0, 1] to [-1, 1] */ + texco[vidx][0] = (tf->uv[fidx][0] * 2.0f) - 1.0f; + texco[vidx][1] = (tf->uv[fidx][1] * 2.0f) - 1.0f; + done[vidx] = 1; + } - /* remap UVs from [0, 1] to [-1, 1] */ - for(i = 0; i < numVerts; ++i) { - texco[i][0] = texco[i][0] * 2 - 1; - texco[i][1] = texco[i][1] * 2 - 1; + } while (fidx--); } MEM_freeN(done); diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c index d7c78492f92..2aed6f05277 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.c +++ b/source/blender/modifiers/intern/MOD_uvproject.c @@ -288,41 +288,34 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, if(override_image || !image || tface->tpage == image) { if(num_projectors == 1) { if(projectors[0].uci) { - project_from_camera(tface->uv[0], coords[mf->v1], projectors[0].uci); - project_from_camera(tface->uv[1], coords[mf->v2], projectors[0].uci); - project_from_camera(tface->uv[2], coords[mf->v3], projectors[0].uci); - if(mf->v4) - project_from_camera(tface->uv[3], coords[mf->v4], projectors[0].uci); + unsigned int fidx= mf->v4 ? 3:2; + do { + unsigned int vidx= *(&mf->v1 + fidx); + project_from_camera(tface->uv[fidx], coords[vidx], projectors[0].uci); + } while (fidx--); } else { /* apply transformed coords as UVs */ - copy_v2_v2(tface->uv[0], coords[mf->v1]); - copy_v2_v2(tface->uv[1], coords[mf->v2]); - copy_v2_v2(tface->uv[2], coords[mf->v3]); - if (mf->v4) { - copy_v2_v2(tface->uv[3], coords[mf->v4]); - } + unsigned int fidx= mf->v4 ? 3:2; + do { + unsigned int vidx= *(&mf->v1 + fidx); + copy_v2_v2(tface->uv[fidx], coords[vidx]); + } while (fidx--); } } else { /* multiple projectors, select the closest to face normal * direction */ - float co1[3], co2[3], co3[3], co4[3]; float face_no[3]; int j; Projector *best_projector; float best_dot; - copy_v3_v3(co1, coords[mf->v1]); - copy_v3_v3(co2, coords[mf->v2]); - copy_v3_v3(co3, coords[mf->v3]); - /* get the untransformed face normal */ if(mf->v4) { - copy_v3_v3(co4, coords[mf->v4]); - normal_quad_v3(face_no, co1, co2, co3, co4); + normal_quad_v3(face_no, coords[mf->v1], coords[mf->v2], coords[mf->v3], coords[mf->v4]); } else { - normal_tri_v3(face_no, co1, co2, co3); + normal_tri_v3(face_no, coords[mf->v1], coords[mf->v2], coords[mf->v3]); } /* find the projector which the face points at most directly @@ -341,26 +334,23 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, } if(best_projector->uci) { - project_from_camera(tface->uv[0], coords[mf->v1], best_projector->uci); - project_from_camera(tface->uv[1], coords[mf->v2], best_projector->uci); - project_from_camera(tface->uv[2], coords[mf->v3], best_projector->uci); - if(mf->v4) - project_from_camera(tface->uv[3], coords[mf->v4], best_projector->uci); + unsigned int fidx= mf->v4 ? 3:2; + do { + unsigned int vidx= *(&mf->v1 + fidx); + project_from_camera(tface->uv[fidx], coords[vidx], best_projector->uci); + } while (fidx--); } else { - mul_project_m4_v3(best_projector->projmat, co1); - mul_project_m4_v3(best_projector->projmat, co2); - mul_project_m4_v3(best_projector->projmat, co3); - if(mf->v4) - mul_project_m4_v3(best_projector->projmat, co4); + unsigned int fidx= mf->v4 ? 3:2; + do { + unsigned int vidx= *(&mf->v1 + fidx); + float tco[3]; - /* apply transformed coords as UVs */ - copy_v2_v2(tface->uv[0], co1); - copy_v2_v2(tface->uv[1], co2); - copy_v2_v2(tface->uv[2], co3); - if (mf->v4) { - copy_v2_v2(tface->uv[3], co4); - } + copy_v3_v3(tco, coords[vidx]); + mul_project_m4_v3(best_projector->projmat, tco); + copy_v2_v2(tface->uv[fidx], tco); + + } while (fidx--); } } } diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c index 6e3673f0549..cb2f6f4d6bc 100644 --- a/source/blender/modifiers/intern/MOD_wave.c +++ b/source/blender/modifiers/intern/MOD_wave.c @@ -73,7 +73,7 @@ static void initData(ModifierData *md) wmd->lifetime= 0.0f; wmd->damp= 10.0f; wmd->falloff= 0.0f; - wmd->texmapping = MOD_WAV_MAP_LOCAL; + wmd->texmapping = MOD_DISP_MAP_LOCAL; wmd->defgrp_name[0] = 0; } @@ -160,7 +160,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) /* ask for UV coordinates if we need them */ - if(wmd->texture && wmd->texmapping == MOD_WAV_MAP_UV) + if(wmd->texture && wmd->texmapping == MOD_DISP_MAP_UV) dataMask |= CD_MASK_MTFACE; /* ask for vertexgroups if we need them */ @@ -170,91 +170,6 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) return dataMask; } -static void wavemod_get_texture_coords(WaveModifierData *wmd, Object *ob, - DerivedMesh *dm, - float (*co)[3], float (*texco)[3], - int numVerts) -{ - int i; - int texmapping = wmd->texmapping; - - if(texmapping == MOD_WAV_MAP_OBJECT) { - if(wmd->map_object) - invert_m4_m4(wmd->map_object->imat, wmd->map_object->obmat); - else /* if there is no map object, default to local */ - texmapping = MOD_WAV_MAP_LOCAL; - } - - /* UVs need special handling, since they come from faces */ - if(texmapping == MOD_WAV_MAP_UV) { - if(CustomData_has_layer(&dm->faceData, CD_MTFACE)) { - MFace *mface = dm->getTessFaceArray(dm); - MFace *mf; - char *done = MEM_callocN(sizeof(*done) * numVerts, - "get_texture_coords done"); - int numFaces = dm->getNumTessFaces(dm); - char uvname[32]; - MTFace *tf; - - CustomData_validate_layer_name(&dm->faceData, CD_MTFACE, wmd->uvlayer_name, uvname); - tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname); - - /* verts are given the UV from the first face that uses them */ - for(i = 0, mf = mface; i < numFaces; ++i, ++mf, ++tf) { - if(!done[mf->v1]) { - texco[mf->v1][0] = tf->uv[0][0]; - texco[mf->v1][1] = tf->uv[0][1]; - texco[mf->v1][2] = 0; - done[mf->v1] = 1; - } - if(!done[mf->v2]) { - texco[mf->v2][0] = tf->uv[1][0]; - texco[mf->v2][1] = tf->uv[1][1]; - texco[mf->v2][2] = 0; - done[mf->v2] = 1; - } - if(!done[mf->v3]) { - texco[mf->v3][0] = tf->uv[2][0]; - texco[mf->v3][1] = tf->uv[2][1]; - texco[mf->v3][2] = 0; - done[mf->v3] = 1; - } - if(!done[mf->v4]) { - texco[mf->v4][0] = tf->uv[3][0]; - texco[mf->v4][1] = tf->uv[3][1]; - texco[mf->v4][2] = 0; - done[mf->v4] = 1; - } - } - - /* remap UVs from [0, 1] to [-1, 1] */ - for(i = 0; i < numVerts; ++i) { - texco[i][0] = texco[i][0] * 2 - 1; - texco[i][1] = texco[i][1] * 2 - 1; - } - - MEM_freeN(done); - return; - } else /* if there are no UVs, default to local */ - texmapping = MOD_WAV_MAP_LOCAL; - } - - for(i = 0; i < numVerts; ++i, ++co, ++texco) { - switch(texmapping) { - case MOD_WAV_MAP_LOCAL: - copy_v3_v3(*texco, *co); - break; - case MOD_WAV_MAP_GLOBAL: - mul_v3_m4v3(*texco, ob->obmat, *co); - break; - case MOD_WAV_MAP_OBJECT: - mul_v3_m4v3(*texco, ob->obmat, *co); - mul_m4_v3(wmd->map_object->imat, *texco); - break; - } - } -} - static void waveModifier_do(WaveModifierData *md, Scene *scene, Object *ob, DerivedMesh *dm, float (*vertexCos)[3], int numVerts) @@ -305,7 +220,7 @@ static void waveModifier_do(WaveModifierData *md, if(wmd->texture) { tex_co = MEM_mallocN(sizeof(*tex_co) * numVerts, "waveModifier_do tex_co"); - wavemod_get_texture_coords(wmd, ob, dm, vertexCos, tex_co, numVerts); + get_texture_coords((MappingInfoModifierData *)wmd, ob, dm, vertexCos, tex_co, numVerts); } if(lifefac != 0.0f) { |