~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/gameengine/Ketsji/KX_IpoConvert.cpp

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
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.
 
17
 *
 
18
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 
19
 * All rights reserved.
 
20
 *
 
21
 * The Original Code is: all of this file.
 
22
 *
 
23
 * Contributor(s): none yet.
 
24
 *
 
25
 * ***** END GPL LICENSE BLOCK *****
 
26
 */
 
27
 
 
28
/** \file gameengine/Ketsji/KX_IpoConvert.cpp
 
29
 *  \ingroup bgeconv
 
30
 */
 
31
 
 
32
#ifdef _MSC_VER
 
33
   /* don't show stl-warnings */
 
34
#  pragma warning (disable:4786)
 
35
#endif
 
36
 
 
37
#include "BKE_material.h" /* give_current_material */
 
38
 
 
39
#include "KX_GameObject.h"
 
40
#include "KX_IpoConvert.h"
 
41
#include "KX_IInterpolator.h"
 
42
#include "KX_ScalarInterpolator.h"
 
43
 
 
44
#include "KX_BlenderScalarInterpolator.h"
 
45
#include "KX_BlenderSceneConverter.h"
 
46
 
 
47
 
 
48
/* This little block needed for linking to Blender... */
 
49
#ifdef WIN32
 
50
#include "BLI_winstuff.h"
 
51
#endif
 
52
 
 
53
#include "DNA_object_types.h"
 
54
#include "DNA_action_types.h"
 
55
#include "DNA_anim_types.h"
 
56
#include "DNA_ipo_types.h"
 
57
#include "DNA_lamp_types.h"
 
58
#include "DNA_world_types.h"
 
59
#include "DNA_camera_types.h"
 
60
#include "DNA_material_types.h"
 
61
/* end of blender include block */
 
62
 
 
63
#include "KX_IPO_SGController.h"
 
64
#include "KX_LightIpoSGController.h"
 
65
#include "KX_CameraIpoSGController.h"
 
66
#include "KX_WorldIpoController.h"
 
67
#include "KX_ObColorIpoSGController.h"
 
68
#include "KX_MaterialIpoController.h"
 
69
 
 
70
#include "SG_Node.h"
 
71
 
 
72
#include "STR_HashedString.h"
 
73
 
 
74
static BL_InterpolatorList *GetAdtList(struct bAction *for_act, KX_BlenderSceneConverter *converter)
 
75
{
 
76
        BL_InterpolatorList *adtList= converter->FindInterpolatorList(for_act);
 
77
 
 
78
        if (!adtList) {
 
79
                adtList = new BL_InterpolatorList(for_act);
 
80
                converter->RegisterInterpolatorList(adtList, for_act);
 
81
        }
 
82
                        
 
83
        return adtList;
 
84
}
 
85
 
 
86
SG_Controller *BL_CreateIPO(struct bAction *action, KX_GameObject* gameobj, KX_BlenderSceneConverter *converter)
 
87
{
 
88
        KX_IpoSGController* ipocontr = new KX_IpoSGController();
 
89
        ipocontr->SetGameObject(gameobj);
 
90
 
 
91
        Object* blenderobject = gameobj->GetBlenderObject();
 
92
 
 
93
        ipocontr->GetIPOTransform().SetPosition(MT_Point3(blenderobject->loc));
 
94
        ipocontr->GetIPOTransform().SetEulerAngles(MT_Vector3(blenderobject->rot));
 
95
        ipocontr->GetIPOTransform().SetScaling(MT_Vector3(blenderobject->size));
 
96
 
 
97
        const char *rotmode, *drotmode;
 
98
 
 
99
        switch (blenderobject->rotmode) {
 
100
        case ROT_MODE_AXISANGLE:
 
101
                rotmode = "rotation_axis_angle";
 
102
                drotmode = "delta_rotation_axis_angle";
 
103
                break;
 
104
        case ROT_MODE_QUAT: /* XXX, this isn't working, currently only eulers are supported [#28853] */
 
105
                rotmode = "rotation_quaternion";
 
106
                drotmode = "delta_rotation_quaternion";
 
107
                break;
 
108
        default:
 
109
                rotmode = "rotation_euler";
 
110
                drotmode = "delta_rotation_euler";
 
111
                break;
 
112
        }
 
113
 
 
114
        BL_InterpolatorList *adtList= GetAdtList(action, converter);
 
115
                
 
116
        // For each active channel in the adtList add an
 
117
        // interpolator to the game object.
 
118
                
 
119
        KX_IInterpolator *interpolator;
 
120
        KX_IScalarInterpolator *interp;
 
121
                
 
122
        for (int i=0; i<3; i++) {
 
123
                if ((interp = adtList->GetScalarInterpolator("location", i))) {
 
124
                        interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetPosition()[i]), interp);
 
125
                        ipocontr->AddInterpolator(interpolator);
 
126
                        ipocontr->SetIPOChannelActive(OB_LOC_X+i, true);
 
127
                }
 
128
        }
 
129
        for (int i=0; i<3; i++) {
 
130
                if ((interp = adtList->GetScalarInterpolator("delta_location", i))) {
 
131
                        interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaPosition()[i]), interp);
 
132
                        ipocontr->AddInterpolator(interpolator);
 
133
                        ipocontr->SetIPOChannelActive(OB_DLOC_X+i, true);
 
134
                }
 
135
        }
 
136
        for (int i=0; i<3; i++) {
 
137
                if ((interp = adtList->GetScalarInterpolator(rotmode, i))) {
 
138
                        interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetEulerAngles()[i]), interp);
 
139
                        ipocontr->AddInterpolator(interpolator);
 
140
                        ipocontr->SetIPOChannelActive(OB_ROT_X+i, true);
 
141
                }
 
142
        }
 
143
        for (int i=0; i<3; i++) {
 
144
                if ((interp = adtList->GetScalarInterpolator(drotmode, i))) {
 
145
                        interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[i]), interp);
 
146
                        ipocontr->AddInterpolator(interpolator);
 
147
                        ipocontr->SetIPOChannelActive(OB_DROT_X+i, true);
 
148
                }
 
149
        }
 
150
        for (int i=0; i<3; i++) {
 
151
                if ((interp = adtList->GetScalarInterpolator("scale", i))) {
 
152
                        interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetScaling()[i]), interp);
 
153
                        ipocontr->AddInterpolator(interpolator);
 
154
                        ipocontr->SetIPOChannelActive(OB_SIZE_X+i, true);
 
155
                }
 
156
        }
 
157
        for (int i=0; i<3; i++) {
 
158
                if ((interp = adtList->GetScalarInterpolator("delta_scale", i))) {
 
159
                        interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaScaling()[i]), interp);
 
160
                        ipocontr->AddInterpolator(interpolator);
 
161
                        ipocontr->SetIPOChannelActive(OB_DSIZE_X+i, true);
 
162
                }
 
163
        }
 
164
                
 
165
 
 
166
        return ipocontr;
 
167
}
 
168
 
 
169
 
 
170
SG_Controller *BL_CreateObColorIPO(struct bAction *action, KX_GameObject* gameobj, KX_BlenderSceneConverter *converter)
 
171
{
 
172
        KX_ObColorIpoSGController* ipocontr_obcol=NULL;
 
173
        KX_IInterpolator *interpolator;
 
174
        KX_IScalarInterpolator *interp;
 
175
        BL_InterpolatorList *adtList= GetAdtList(action, converter);
 
176
 
 
177
        for (int i=0; i<4; i++) {
 
178
                if ((interp = adtList->GetScalarInterpolator("color", i))) {
 
179
                        if (!ipocontr_obcol) {
 
180
                                ipocontr_obcol = new KX_ObColorIpoSGController();
 
181
                        }
 
182
                        interpolator= new KX_ScalarInterpolator(&ipocontr_obcol->m_rgba[i], interp);
 
183
                        ipocontr_obcol->AddInterpolator(interpolator);
 
184
                }
 
185
        }
 
186
 
 
187
        return ipocontr_obcol;
 
188
}
 
189
 
 
190
SG_Controller *BL_CreateLampIPO(struct bAction *action, KX_GameObject*  lightobj, KX_BlenderSceneConverter *converter)
 
191
{
 
192
        KX_LightIpoSGController* ipocontr = new KX_LightIpoSGController();
 
193
 
 
194
        Lamp *blenderlamp = (Lamp*)lightobj->GetBlenderObject()->data;
 
195
 
 
196
        ipocontr->m_energy = blenderlamp->energy;
 
197
        ipocontr->m_col_rgb[0] = blenderlamp->r;
 
198
        ipocontr->m_col_rgb[1] = blenderlamp->g;
 
199
        ipocontr->m_col_rgb[2] = blenderlamp->b;
 
200
        ipocontr->m_dist = blenderlamp->dist;
 
201
 
 
202
        BL_InterpolatorList *adtList= GetAdtList(action, converter);
 
203
 
 
204
        // For each active channel in the adtList add an
 
205
        // interpolator to the game object.
 
206
                
 
207
        KX_IInterpolator *interpolator;
 
208
        KX_IScalarInterpolator *interp;
 
209
                
 
210
        if ((interp= adtList->GetScalarInterpolator("energy", 0))) {
 
211
                interpolator= new KX_ScalarInterpolator(&ipocontr->m_energy, interp);
 
212
                ipocontr->AddInterpolator(interpolator);
 
213
                ipocontr->SetModifyEnergy(true);
 
214
        }
 
215
 
 
216
        if ((interp = adtList->GetScalarInterpolator("distance", 0))) {
 
217
                interpolator= new KX_ScalarInterpolator(&ipocontr->m_dist, interp);
 
218
                ipocontr->AddInterpolator(interpolator);
 
219
                ipocontr->SetModifyDist(true);
 
220
        }
 
221
                
 
222
        for (int i=0; i<3; i++) {
 
223
                if ((interp = adtList->GetScalarInterpolator("color", i))) {
 
224
                        interpolator= new KX_ScalarInterpolator(&ipocontr->m_col_rgb[i], interp);
 
225
                        ipocontr->AddInterpolator(interpolator);
 
226
                        ipocontr->SetModifyColor(true);
 
227
                }
 
228
        }
 
229
 
 
230
        return ipocontr;
 
231
}
 
232
 
 
233
SG_Controller *BL_CreateCameraIPO(struct bAction *action, KX_GameObject*  cameraobj, KX_BlenderSceneConverter *converter)
 
234
{
 
235
        KX_CameraIpoSGController* ipocontr = new KX_CameraIpoSGController();
 
236
 
 
237
        Camera *blendercamera = (Camera*)cameraobj->GetBlenderObject()->data;
 
238
 
 
239
        ipocontr->m_lens = blendercamera->lens;
 
240
        ipocontr->m_clipstart = blendercamera->clipsta;
 
241
        ipocontr->m_clipend = blendercamera->clipend;
 
242
 
 
243
        BL_InterpolatorList *adtList= GetAdtList(action, converter);
 
244
 
 
245
        // For each active channel in the adtList add an
 
246
        // interpolator to the game object.
 
247
                
 
248
        KX_IInterpolator *interpolator;
 
249
        KX_IScalarInterpolator *interp;
 
250
                
 
251
        if ((interp = adtList->GetScalarInterpolator("lens", 0))) {
 
252
                interpolator= new KX_ScalarInterpolator(&ipocontr->m_lens, interp);
 
253
                ipocontr->AddInterpolator(interpolator);
 
254
                ipocontr->SetModifyLens(true);
 
255
        }
 
256
 
 
257
        if ((interp = adtList->GetScalarInterpolator("clip_start", 0))) {
 
258
                interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipstart, interp);
 
259
                ipocontr->AddInterpolator(interpolator);
 
260
                ipocontr->SetModifyClipStart(true);
 
261
        }
 
262
 
 
263
        if ((interp = adtList->GetScalarInterpolator("clip_end", 0))) {
 
264
                interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipend, interp);
 
265
                ipocontr->AddInterpolator(interpolator);
 
266
                ipocontr->SetModifyClipEnd(true);
 
267
        }
 
268
 
 
269
        return ipocontr;
 
270
}
 
271
 
 
272
void BL_ConvertWorldIpos(struct World* blenderworld,KX_BlenderSceneConverter *converter)
 
273
{
 
274
 
 
275
        if (blenderworld->adt) {
 
276
 
 
277
                KX_WorldIpoController* ipocontr = new KX_WorldIpoController();
 
278
 
 
279
// Erwin, hook up the world ipo controller here
 
280
// Gino: hook it up to what ?
 
281
// is there a userinterface element for that ?
 
282
// for now, we have some new python hooks to access the data, for a work-around
 
283
                
 
284
                ipocontr->m_mist_start  = blenderworld->miststa;
 
285
                ipocontr->m_mist_dist   = blenderworld->mistdist;
 
286
                ipocontr->m_mist_rgb[0] = blenderworld->horr;
 
287
                ipocontr->m_mist_rgb[1] = blenderworld->horg;
 
288
                ipocontr->m_mist_rgb[2] = blenderworld->horb;
 
289
 
 
290
                BL_InterpolatorList *adtList= GetAdtList(blenderworld->adt->action, converter);
 
291
 
 
292
                // For each active channel in the adtList add an
 
293
                // interpolator to the game object.
 
294
                
 
295
                KX_IInterpolator *interpolator;
 
296
                KX_IScalarInterpolator *interp;
 
297
                
 
298
                for (int i=0; i<3; i++) {
 
299
                        if ((interp = adtList->GetScalarInterpolator("horizon_color", i))) {
 
300
                                interpolator= new KX_ScalarInterpolator(&ipocontr->m_mist_rgb[i], interp);
 
301
                                ipocontr->AddInterpolator(interpolator);
 
302
                                ipocontr->SetModifyMistColor(true);
 
303
                        }
 
304
                }
 
305
 
 
306
                if ((interp = adtList->GetScalarInterpolator("mist.depth", 0))) {
 
307
                        interpolator= new KX_ScalarInterpolator(&ipocontr->m_mist_dist, interp);
 
308
                        ipocontr->AddInterpolator(interpolator);
 
309
                        ipocontr->SetModifyMistDist(true);
 
310
                }
 
311
 
 
312
                if ((interp = adtList->GetScalarInterpolator("mist.start", 0))) {
 
313
                        interpolator= new KX_ScalarInterpolator(&ipocontr->m_mist_start, interp);
 
314
                        ipocontr->AddInterpolator(interpolator);
 
315
                        ipocontr->SetModifyMistStart(true);
 
316
                }
 
317
        }
 
318
}
 
319
 
 
320
SG_Controller *BL_CreateMaterialIpo(
 
321
        struct bAction *action,
 
322
        Material* blendermaterial,
 
323
        dword matname_hash,
 
324
        KX_GameObject* gameobj,  
 
325
        KX_BlenderSceneConverter *converter
 
326
        )
 
327
{
 
328
        KX_MaterialIpoController* ipocontr = NULL;
 
329
 
 
330
        BL_InterpolatorList *adtList= GetAdtList(action, converter);
 
331
        KX_IInterpolator *interpolator;
 
332
        KX_IScalarInterpolator *sinterp;
 
333
 
 
334
        // --
 
335
        for (int i=0; i<3; i++) {
 
336
                if ((sinterp = adtList->GetScalarInterpolator("diffuse_color", i))) {
 
337
                        if (!ipocontr) {
 
338
                                ipocontr = new KX_MaterialIpoController(matname_hash);
 
339
                        }
 
340
                        interpolator= new KX_ScalarInterpolator(&ipocontr->m_rgba[i], sinterp);
 
341
                        ipocontr->AddInterpolator(interpolator);
 
342
                }
 
343
        }
 
344
 
 
345
        if ((sinterp = adtList->GetScalarInterpolator("alpha", 0))) {
 
346
                if (!ipocontr) {
 
347
                        ipocontr = new KX_MaterialIpoController(matname_hash);
 
348
                }
 
349
                interpolator= new KX_ScalarInterpolator(&ipocontr->m_rgba[3], sinterp);
 
350
                ipocontr->AddInterpolator(interpolator);
 
351
        }
 
352
 
 
353
        for (int i=0; i<3; i++) {
 
354
                if ((sinterp = adtList->GetScalarInterpolator("specular_color", i))) {
 
355
                        if (!ipocontr) {
 
356
                                ipocontr = new KX_MaterialIpoController(matname_hash);
 
357
                        }
 
358
                        interpolator= new KX_ScalarInterpolator(&ipocontr->m_specrgb[i], sinterp);
 
359
                        ipocontr->AddInterpolator(interpolator);
 
360
                }
 
361
        }
 
362
 
 
363
        if ((sinterp = adtList->GetScalarInterpolator("specular_hardness", 0))) {
 
364
                if (!ipocontr) {
 
365
                        ipocontr = new KX_MaterialIpoController(matname_hash);
 
366
                }
 
367
                interpolator= new KX_ScalarInterpolator(&ipocontr->m_hard, sinterp);
 
368
                ipocontr->AddInterpolator(interpolator);
 
369
        }
 
370
 
 
371
        if ((sinterp = adtList->GetScalarInterpolator("specularity", 0))) {
 
372
                if (!ipocontr) {
 
373
                        ipocontr = new KX_MaterialIpoController(matname_hash);
 
374
                }
 
375
                interpolator= new KX_ScalarInterpolator(&ipocontr->m_spec, sinterp);
 
376
                ipocontr->AddInterpolator(interpolator);
 
377
        }
 
378
 
 
379
        if ((sinterp = adtList->GetScalarInterpolator("diffuse_reflection", 0))) {
 
380
                if (!ipocontr) {
 
381
                        ipocontr = new KX_MaterialIpoController(matname_hash);
 
382
                }
 
383
                interpolator= new KX_ScalarInterpolator(&ipocontr->m_ref, sinterp);
 
384
                ipocontr->AddInterpolator(interpolator);
 
385
        }
 
386
 
 
387
        if ((sinterp = adtList->GetScalarInterpolator("emit", 0))) {
 
388
                if (!ipocontr) {
 
389
                        ipocontr = new KX_MaterialIpoController(matname_hash);
 
390
                }
 
391
                interpolator= new KX_ScalarInterpolator(&ipocontr->m_emit, sinterp);
 
392
                ipocontr->AddInterpolator(interpolator);
 
393
        }
 
394
 
 
395
        if (ipocontr) {
 
396
                ipocontr->m_rgba[0]     = blendermaterial->r;
 
397
                ipocontr->m_rgba[1]     = blendermaterial->g;
 
398
                ipocontr->m_rgba[2]     = blendermaterial->b;
 
399
                ipocontr->m_rgba[3]     = blendermaterial->alpha;
 
400
 
 
401
                ipocontr->m_specrgb[0]  = blendermaterial->specr;
 
402
                ipocontr->m_specrgb[1]  = blendermaterial->specg;
 
403
                ipocontr->m_specrgb[2]  = blendermaterial->specb;
 
404
 
 
405
                ipocontr->m_hard                = blendermaterial->har;
 
406
                ipocontr->m_spec                = blendermaterial->spec;
 
407
                ipocontr->m_ref                 = blendermaterial->ref;
 
408
                ipocontr->m_emit                = blendermaterial->emit;
 
409
                ipocontr->m_alpha               = blendermaterial->alpha;
 
410
        }
 
411
 
 
412
        return ipocontr;
 
413
}