~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/modifiers/intern/MOD_util.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: MOD_util.c 28753 2010-05-13 19:23:52Z nazgul $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
7
5
 * modify it under the terms of the GNU General Public License
8
6
 * as published by the Free Software Foundation; either version 2
9
 
 * of the License, or (at your option) any later version. The Blender
10
 
 * Foundation also sells licenses for use in proprietary software under
11
 
 * the Blender License.  See http://www.blender.org/BL/ for information
12
 
 * about this.
 
7
 * of the License, or (at your option) any later version.
13
8
 *
14
 
 * This program is distributed in the hope that it will be useful;
 
9
 * This program is distributed in the hope that it will be useful,
15
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
12
 * GNU General Public License for more details.
18
13
 *
19
14
 * You should have received a copy of the GNU General Public License
20
 
 * along with this program; if not, write to the Free Software Foundation;
21
 
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
17
 *
23
18
 * The Original Code is Copyright (C) 2005 Blender Foundation.
24
19
 * All rights reserved.
30
25
 * ***** END GPL LICENSE BLOCK *****
31
26
 */
32
27
 
33
 
#include "string.h"
34
 
 
 
28
/** \file blender/modifiers/intern/MOD_util.c
 
29
 *  \ingroup modifiers
 
30
 */
 
31
 
 
32
 
 
33
#include <string.h>
 
34
 
 
35
#include "DNA_curve_types.h"
 
36
#include "DNA_image_types.h"
 
37
#include "DNA_lattice_types.h"
 
38
#include "DNA_meshdata_types.h"
35
39
#include "DNA_modifier_types.h"
36
40
#include "DNA_object_types.h"
37
 
#include "DNA_curve_types.h"
 
41
#include "DNA_scene_types.h"
 
42
 
 
43
#include "BLI_utildefines.h"
 
44
#include "BLI_math_vector.h"
 
45
#include "BLI_math_matrix.h"
38
46
 
39
47
#include "BKE_cdderivedmesh.h"
 
48
#include "BKE_deform.h"
 
49
#include "BKE_image.h"
 
50
#include "BKE_lattice.h"
40
51
#include "BKE_mesh.h"
41
52
#include "BKE_displist.h"
42
 
#include "BKE_utildefines.h"
 
53
 
43
54
#include "BKE_modifier.h"
44
55
 
45
56
#include "MOD_util.h"
49
60
 
50
61
#include "RE_shader_ext.h"
51
62
 
 
63
void modifier_init_texture(Scene *scene, Tex *tex)
 
64
{
 
65
        if (!tex)
 
66
                return;
 
67
 
 
68
        if (tex->ima && ELEM(tex->ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE))
 
69
                BKE_image_user_calc_frame(&tex->iuser, scene->r.cfra, 0);
 
70
}
 
71
 
52
72
void get_texture_value(Tex *texture, float *tex_co, TexResult *texres)
53
73
{
54
74
        int result_type;
55
75
 
56
 
        result_type = multitex_ext(texture, tex_co, NULL, NULL, 0, texres);
 
76
        /* no node textures for now */
 
77
        result_type = multitex_ext_safe(texture, tex_co, texres);
57
78
 
58
79
        /* if the texture gave an RGB value, we assume it didn't give a valid
59
 
        * intensity, so calculate one (formula from do_material_tex).
60
 
        * if the texture didn't give an RGB value, copy the intensity across
61
 
        */
62
 
        if(result_type & TEX_RGB)
 
80
         * intensity, so calculate one (formula from do_material_tex).
 
81
         * if the texture didn't give an RGB value, copy the intensity across
 
82
         */
 
83
        if (result_type & TEX_RGB)
63
84
                texres->tin = (0.35f * texres->tr + 0.45f * texres->tg
64
85
                                + 0.2f * texres->tb);
65
86
        else
66
87
                texres->tr = texres->tg = texres->tb = texres->tin;
67
88
}
68
89
 
 
90
void get_texture_coords(MappingInfoModifierData *dmd, Object *ob,
 
91
                        DerivedMesh *dm,
 
92
                        float (*co)[3], float (*texco)[3],
 
93
                        int numVerts)
 
94
{
 
95
        int i;
 
96
        int texmapping = dmd->texmapping;
 
97
        float mapob_imat[4][4];
 
98
 
 
99
        if (texmapping == MOD_DISP_MAP_OBJECT) {
 
100
                if (dmd->map_object)
 
101
                        invert_m4_m4(mapob_imat, dmd->map_object->obmat);
 
102
                else /* if there is no map object, default to local */
 
103
                        texmapping = MOD_DISP_MAP_LOCAL;
 
104
        }
 
105
 
 
106
        /* UVs need special handling, since they come from faces */
 
107
        if (texmapping == MOD_DISP_MAP_UV) {
 
108
                if (CustomData_has_layer(&dm->loopData, CD_MLOOPUV)) {
 
109
                        MPoly *mpoly = dm->getPolyArray(dm);
 
110
                        MPoly *mp;
 
111
                        MLoop *mloop = dm->getLoopArray(dm);
 
112
                        char *done = MEM_callocN(sizeof(*done) * numVerts,
 
113
                                                 "get_texture_coords done");
 
114
                        int numPolys = dm->getNumPolys(dm);
 
115
                        char uvname[MAX_CUSTOMDATA_LAYER_NAME];
 
116
                        MLoopUV *mloop_uv;
 
117
 
 
118
                        CustomData_validate_layer_name(&dm->loopData, CD_MLOOPUV, dmd->uvlayer_name, uvname);
 
119
                        mloop_uv = CustomData_get_layer_named(&dm->loopData, CD_MLOOPUV, uvname);
 
120
 
 
121
                        /* verts are given the UV from the first face that uses them */
 
122
                        for (i = 0, mp = mpoly; i < numPolys; ++i, ++mp) {
 
123
                                unsigned int fidx= mp->totloop - 1;
 
124
 
 
125
                                do {
 
126
                                        unsigned int lidx= mp->loopstart + fidx;
 
127
                                        unsigned int vidx= mloop[lidx].v;
 
128
 
 
129
                                        if (done[vidx] == 0) {
 
130
                                                /* remap UVs from [0, 1] to [-1, 1] */
 
131
                                                texco[vidx][0] = (mloop_uv[lidx].uv[0] * 2.0f) - 1.0f;
 
132
                                                texco[vidx][1] = (mloop_uv[lidx].uv[1] * 2.0f) - 1.0f;
 
133
                                                done[vidx] = 1;
 
134
                                        }
 
135
 
 
136
                                } while (fidx--);
 
137
                        }
 
138
 
 
139
                        MEM_freeN(done);
 
140
                        return;
 
141
                }
 
142
                else /* if there are no UVs, default to local */
 
143
                        texmapping = MOD_DISP_MAP_LOCAL;
 
144
        }
 
145
 
 
146
        for (i = 0; i < numVerts; ++i, ++co, ++texco) {
 
147
                switch(texmapping) {
 
148
                case MOD_DISP_MAP_LOCAL:
 
149
                        copy_v3_v3(*texco, *co);
 
150
                        break;
 
151
                case MOD_DISP_MAP_GLOBAL:
 
152
                        mul_v3_m4v3(*texco, ob->obmat, *co);
 
153
                        break;
 
154
                case MOD_DISP_MAP_OBJECT:
 
155
                        mul_v3_m4v3(*texco, ob->obmat, *co);
 
156
                        mul_m4_v3(mapob_imat, *texco);
 
157
                        break;
 
158
                }
 
159
        }
 
160
}
 
161
 
69
162
void modifier_vgroup_cache(ModifierData *md, float (*vertexCos)[3])
70
163
{
71
 
        while((md=md->next) && md->type==eModifierType_Armature) {
 
164
        while ((md=md->next) && md->type==eModifierType_Armature) {
72
165
                ArmatureModifierData *amd = (ArmatureModifierData*) md;
73
 
                if(amd->multi && amd->prevCos==NULL)
 
166
                if (amd->multi && amd->prevCos==NULL)
74
167
                        amd->prevCos= MEM_dupallocN(vertexCos);
75
168
                else
76
169
                        break;
78
171
        /* lattice/mesh modifier too */
79
172
}
80
173
 
81
 
void validate_layer_name(const CustomData *data, int type, char *name, char *outname)
82
 
{
83
 
        int index = -1;
84
 
 
85
 
        /* if a layer name was given, try to find that layer */
86
 
        if(name[0])
87
 
                index = CustomData_get_named_layer_index(data, CD_MTFACE, name);
88
 
 
89
 
        if(index < 0) {
90
 
                /* either no layer was specified, or the layer we want has been
91
 
                * deleted, so assign the active layer to name
92
 
                */
93
 
                index = CustomData_get_active_layer_index(data, CD_MTFACE);
94
 
                strcpy(outname, data->layers[index].name);
95
 
        }
96
 
        else
97
 
                strcpy(outname, name);
98
 
}
99
 
 
100
174
/* returns a cdderivedmesh if dm == NULL or is another type of derivedmesh */
101
 
DerivedMesh *get_cddm(struct Scene *scene, Object *ob, struct EditMesh *em, DerivedMesh *dm, float (*vertexCos)[3])
 
175
DerivedMesh *get_cddm(Object *ob, struct BMEditMesh *em, DerivedMesh *dm, float (*vertexCos)[3])
102
176
{
103
 
        if(dm && dm->type == DM_TYPE_CDDM)
 
177
        if (dm && dm->type == DM_TYPE_CDDM)
104
178
                return dm;
105
179
 
106
 
        if(!dm) {
107
 
                dm= get_dm(scene, ob, em, dm, vertexCos, 0);
 
180
        if (!dm) {
 
181
                dm= get_dm(ob, em, dm, vertexCos, 0);
108
182
        }
109
183
        else {
110
184
                dm= CDDM_copy(dm);
111
185
                CDDM_apply_vert_coords(dm, vertexCos);
112
186
        }
113
187
 
114
 
        if(dm)
 
188
        if (dm)
115
189
                CDDM_calc_normals(dm);
116
190
        
117
191
        return dm;
118
192
}
119
193
 
120
194
/* returns a derived mesh if dm == NULL, for deforming modifiers that need it */
121
 
DerivedMesh *get_dm(struct Scene *scene, Object *ob, struct EditMesh *em, DerivedMesh *dm, float (*vertexCos)[3], int orco)
 
195
DerivedMesh *get_dm(Object *ob, struct BMEditMesh *em, DerivedMesh *dm, float (*vertexCos)[3], int orco)
122
196
{
123
 
        if(dm)
 
197
        if (dm)
124
198
                return dm;
125
199
 
126
 
        if(ob->type==OB_MESH) {
127
 
                if(em) dm= CDDM_from_editmesh(em, ob->data);
 
200
        if (ob->type==OB_MESH) {
 
201
                if (em) dm= CDDM_from_BMEditMesh(em, ob->data, FALSE, FALSE);
128
202
                else dm = CDDM_from_mesh((struct Mesh *)(ob->data), ob);
129
203
 
130
 
                if(vertexCos) {
 
204
                if (vertexCos) {
131
205
                        CDDM_apply_vert_coords(dm, vertexCos);
132
206
                        //CDDM_calc_normals(dm);
133
207
                }
134
208
                
135
 
                if(orco)
 
209
                if (orco)
136
210
                        DM_add_vert_layer(dm, CD_ORCO, CD_ASSIGN, get_mesh_orco_verts(ob));
137
211
        }
138
 
        else if(ELEM3(ob->type,OB_FONT,OB_CURVE,OB_SURF)) {
 
212
        else if (ELEM3(ob->type,OB_FONT,OB_CURVE,OB_SURF)) {
139
213
                dm= CDDM_from_curve(ob);
140
214
        }
141
215
 
142
216
        return dm;
143
217
}
144
218
 
 
219
void modifier_get_vgroup(Object *ob, DerivedMesh *dm, const char *name, MDeformVert **dvert, int *defgrp_index)
 
220
{
 
221
        *defgrp_index = defgroup_name_index(ob, name);
 
222
        *dvert = NULL;
 
223
 
 
224
        if (*defgrp_index >= 0) {
 
225
                if (ob->type == OB_LATTICE)
 
226
                        *dvert = lattice_get_deform_verts(ob);
 
227
                else if (dm)
 
228
                        *dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
 
229
        }
 
230
}
 
231
 
145
232
/* only called by BKE_modifier.h/modifier.c */
146
 
void modifier_type_init(ModifierTypeInfo *types[], ModifierType type)
 
233
void modifier_type_init(ModifierTypeInfo *types[])
147
234
{
148
 
        memset(types, 0, sizeof(types));
149
235
#define INIT_TYPE(typeName) (types[eModifierType_##typeName] = &modifierType_##typeName)
150
236
        INIT_TYPE(None);
151
237
        INIT_TYPE(Curve);
169
255
        INIT_TYPE(Collision);
170
256
        INIT_TYPE(Boolean);
171
257
        INIT_TYPE(MeshDeform);
 
258
        INIT_TYPE(Ocean);
172
259
        INIT_TYPE(ParticleSystem);
173
260
        INIT_TYPE(ParticleInstance);
174
261
        INIT_TYPE(Explode);
182
269
        INIT_TYPE(ShapeKey);
183
270
        INIT_TYPE(Solidify);
184
271
        INIT_TYPE(Screw);
 
272
        INIT_TYPE(Warp);
 
273
        INIT_TYPE(WeightVGEdit);
 
274
        INIT_TYPE(WeightVGMix);
 
275
        INIT_TYPE(WeightVGProximity);
 
276
        INIT_TYPE(DynamicPaint);
 
277
        INIT_TYPE(Remesh);
185
278
#undef INIT_TYPE
186
279
}