2
* ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19
* All rights reserved.
21
* The Original Code is: all of this file.
23
* Contributor(s): none yet.
25
* ***** END GPL LICENSE BLOCK *****
28
/** \file gameengine/Ketsji/KX_IpoConvert.cpp
33
/* don't show stl-warnings */
34
# pragma warning (disable:4786)
37
#include "BKE_material.h" /* give_current_material */
39
#include "KX_GameObject.h"
40
#include "KX_IpoConvert.h"
41
#include "KX_IInterpolator.h"
42
#include "KX_ScalarInterpolator.h"
44
#include "KX_BlenderScalarInterpolator.h"
45
#include "KX_BlenderSceneConverter.h"
48
/* This little block needed for linking to Blender... */
50
#include "BLI_winstuff.h"
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 */
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"
72
#include "STR_HashedString.h"
74
static BL_InterpolatorList *GetAdtList(struct bAction *for_act, KX_BlenderSceneConverter *converter)
76
BL_InterpolatorList *adtList= converter->FindInterpolatorList(for_act);
79
adtList = new BL_InterpolatorList(for_act);
80
converter->RegisterInterpolatorList(adtList, for_act);
86
SG_Controller *BL_CreateIPO(struct bAction *action, KX_GameObject* gameobj, KX_BlenderSceneConverter *converter)
88
KX_IpoSGController* ipocontr = new KX_IpoSGController();
89
ipocontr->SetGameObject(gameobj);
91
Object* blenderobject = gameobj->GetBlenderObject();
93
ipocontr->GetIPOTransform().SetPosition(MT_Point3(blenderobject->loc));
94
ipocontr->GetIPOTransform().SetEulerAngles(MT_Vector3(blenderobject->rot));
95
ipocontr->GetIPOTransform().SetScaling(MT_Vector3(blenderobject->size));
97
const char *rotmode, *drotmode;
99
switch (blenderobject->rotmode) {
100
case ROT_MODE_AXISANGLE:
101
rotmode = "rotation_axis_angle";
102
drotmode = "delta_rotation_axis_angle";
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";
109
rotmode = "rotation_euler";
110
drotmode = "delta_rotation_euler";
114
BL_InterpolatorList *adtList= GetAdtList(action, converter);
116
// For each active channel in the adtList add an
117
// interpolator to the game object.
119
KX_IInterpolator *interpolator;
120
KX_IScalarInterpolator *interp;
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);
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);
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);
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);
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);
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);
170
SG_Controller *BL_CreateObColorIPO(struct bAction *action, KX_GameObject* gameobj, KX_BlenderSceneConverter *converter)
172
KX_ObColorIpoSGController* ipocontr_obcol=NULL;
173
KX_IInterpolator *interpolator;
174
KX_IScalarInterpolator *interp;
175
BL_InterpolatorList *adtList= GetAdtList(action, converter);
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();
182
interpolator= new KX_ScalarInterpolator(&ipocontr_obcol->m_rgba[i], interp);
183
ipocontr_obcol->AddInterpolator(interpolator);
187
return ipocontr_obcol;
190
SG_Controller *BL_CreateLampIPO(struct bAction *action, KX_GameObject* lightobj, KX_BlenderSceneConverter *converter)
192
KX_LightIpoSGController* ipocontr = new KX_LightIpoSGController();
194
Lamp *blenderlamp = (Lamp*)lightobj->GetBlenderObject()->data;
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;
202
BL_InterpolatorList *adtList= GetAdtList(action, converter);
204
// For each active channel in the adtList add an
205
// interpolator to the game object.
207
KX_IInterpolator *interpolator;
208
KX_IScalarInterpolator *interp;
210
if ((interp= adtList->GetScalarInterpolator("energy", 0))) {
211
interpolator= new KX_ScalarInterpolator(&ipocontr->m_energy, interp);
212
ipocontr->AddInterpolator(interpolator);
213
ipocontr->SetModifyEnergy(true);
216
if ((interp = adtList->GetScalarInterpolator("distance", 0))) {
217
interpolator= new KX_ScalarInterpolator(&ipocontr->m_dist, interp);
218
ipocontr->AddInterpolator(interpolator);
219
ipocontr->SetModifyDist(true);
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);
233
SG_Controller *BL_CreateCameraIPO(struct bAction *action, KX_GameObject* cameraobj, KX_BlenderSceneConverter *converter)
235
KX_CameraIpoSGController* ipocontr = new KX_CameraIpoSGController();
237
Camera *blendercamera = (Camera*)cameraobj->GetBlenderObject()->data;
239
ipocontr->m_lens = blendercamera->lens;
240
ipocontr->m_clipstart = blendercamera->clipsta;
241
ipocontr->m_clipend = blendercamera->clipend;
243
BL_InterpolatorList *adtList= GetAdtList(action, converter);
245
// For each active channel in the adtList add an
246
// interpolator to the game object.
248
KX_IInterpolator *interpolator;
249
KX_IScalarInterpolator *interp;
251
if ((interp = adtList->GetScalarInterpolator("lens", 0))) {
252
interpolator= new KX_ScalarInterpolator(&ipocontr->m_lens, interp);
253
ipocontr->AddInterpolator(interpolator);
254
ipocontr->SetModifyLens(true);
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);
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);
272
void BL_ConvertWorldIpos(struct World* blenderworld,KX_BlenderSceneConverter *converter)
275
if (blenderworld->adt) {
277
KX_WorldIpoController* ipocontr = new KX_WorldIpoController();
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
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;
290
BL_InterpolatorList *adtList= GetAdtList(blenderworld->adt->action, converter);
292
// For each active channel in the adtList add an
293
// interpolator to the game object.
295
KX_IInterpolator *interpolator;
296
KX_IScalarInterpolator *interp;
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);
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);
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);
320
SG_Controller *BL_CreateMaterialIpo(
321
struct bAction *action,
322
Material* blendermaterial,
324
KX_GameObject* gameobj,
325
KX_BlenderSceneConverter *converter
328
KX_MaterialIpoController* ipocontr = NULL;
330
BL_InterpolatorList *adtList= GetAdtList(action, converter);
331
KX_IInterpolator *interpolator;
332
KX_IScalarInterpolator *sinterp;
335
for (int i=0; i<3; i++) {
336
if ((sinterp = adtList->GetScalarInterpolator("diffuse_color", i))) {
338
ipocontr = new KX_MaterialIpoController(matname_hash);
340
interpolator= new KX_ScalarInterpolator(&ipocontr->m_rgba[i], sinterp);
341
ipocontr->AddInterpolator(interpolator);
345
if ((sinterp = adtList->GetScalarInterpolator("alpha", 0))) {
347
ipocontr = new KX_MaterialIpoController(matname_hash);
349
interpolator= new KX_ScalarInterpolator(&ipocontr->m_rgba[3], sinterp);
350
ipocontr->AddInterpolator(interpolator);
353
for (int i=0; i<3; i++) {
354
if ((sinterp = adtList->GetScalarInterpolator("specular_color", i))) {
356
ipocontr = new KX_MaterialIpoController(matname_hash);
358
interpolator= new KX_ScalarInterpolator(&ipocontr->m_specrgb[i], sinterp);
359
ipocontr->AddInterpolator(interpolator);
363
if ((sinterp = adtList->GetScalarInterpolator("specular_hardness", 0))) {
365
ipocontr = new KX_MaterialIpoController(matname_hash);
367
interpolator= new KX_ScalarInterpolator(&ipocontr->m_hard, sinterp);
368
ipocontr->AddInterpolator(interpolator);
371
if ((sinterp = adtList->GetScalarInterpolator("specularity", 0))) {
373
ipocontr = new KX_MaterialIpoController(matname_hash);
375
interpolator= new KX_ScalarInterpolator(&ipocontr->m_spec, sinterp);
376
ipocontr->AddInterpolator(interpolator);
379
if ((sinterp = adtList->GetScalarInterpolator("diffuse_reflection", 0))) {
381
ipocontr = new KX_MaterialIpoController(matname_hash);
383
interpolator= new KX_ScalarInterpolator(&ipocontr->m_ref, sinterp);
384
ipocontr->AddInterpolator(interpolator);
387
if ((sinterp = adtList->GetScalarInterpolator("emit", 0))) {
389
ipocontr = new KX_MaterialIpoController(matname_hash);
391
interpolator= new KX_ScalarInterpolator(&ipocontr->m_emit, sinterp);
392
ipocontr->AddInterpolator(interpolator);
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;
401
ipocontr->m_specrgb[0] = blendermaterial->specr;
402
ipocontr->m_specrgb[1] = blendermaterial->specg;
403
ipocontr->m_specrgb[2] = blendermaterial->specb;
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;