Python API get/setObject update for Actuators. (SetParent, AddObject, Camera and...
[blender.git] / source / gameengine / Converter / KX_ConvertActuators.cpp
1 /**
2 * $Id$
3 *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28 * Convert Blender actuators for use in the GameEngine
29 */
30
31 #ifdef WIN32
32 #pragma warning (disable : 4786) 
33 #endif //WIN32
34
35 #define BLENDER_HACK_DTIME 0.02
36
37 #include "MEM_guardedalloc.h"
38
39 #include "KX_BlenderSceneConverter.h"
40 #include "KX_ConvertActuators.h"
41
42 // Actuators
43 //SCA logiclibrary native logicbricks
44 #include "SCA_PropertyActuator.h"
45 #include "SCA_LogicManager.h"
46 #include "SCA_RandomActuator.h"
47 #include "SCA_2DFilterActuator.h"
48
49 // Ketsji specific logicbricks
50 #include "KX_SceneActuator.h"
51 #include "KX_IpoActuator.h"
52 #include "KX_SoundActuator.h"
53 #include "KX_CDActuator.h"
54 #include "KX_ObjectActuator.h"
55 #include "KX_TrackToActuator.h"
56 #include "KX_ConstraintActuator.h"
57 #include "KX_CameraActuator.h"
58 #include "KX_GameActuator.h"
59 #include "KX_StateActuator.h"
60 #include "KX_VisibilityActuator.h"
61 #include "KX_SCA_AddObjectActuator.h"
62 #include "KX_SCA_EndObjectActuator.h"
63 #include "KX_SCA_ReplaceMeshActuator.h"
64 #include "KX_ParentActuator.h"
65 #include "KX_SCA_DynamicActuator.h"
66
67 #include "KX_Scene.h"
68 #include "KX_KetsjiEngine.h"
69
70 #include "IntValue.h"
71 #include "KX_GameObject.h"
72
73 /* This little block needed for linking to Blender... */
74 #include "BKE_text.h"
75 #include "BLI_blenlib.h"
76
77 #include "KX_NetworkMessageActuator.h"
78
79 #ifdef WIN32
80 #include "BLI_winstuff.h"
81 #endif
82
83 #include "DNA_object_types.h"
84 #include "DNA_sound_types.h"
85 #include "DNA_scene_types.h"
86 #include "DNA_actuator_types.h"
87 #include "DNA_packedFile_types.h"
88 #include "BL_ActionActuator.h"
89 #include "BL_ShapeActionActuator.h"
90 /* end of blender include block */
91
92 #include "BL_BlenderDataConversion.h"
93
94 /** 
95 KX_BLENDERTRUNC needed to round 'almost' zero values to zero, else velocities etc. are incorrectly set 
96 */
97
98 #define KX_BLENDERTRUNC(x)  (( x < 0.0001 && x > -0.0001 )  ? 0.0 : x)
99
100 void BL_ConvertActuators(char* maggiename,
101                                                  struct Object* blenderobject,
102                                                  KX_GameObject* gameobj,
103                                                  SCA_LogicManager* logicmgr,
104                                                  KX_Scene* scene,
105                                                  KX_KetsjiEngine* ketsjiEngine,
106                                                  int & executePriority, 
107                                                  int activeLayerBitInfo,
108                                                  bool isInActiveLayer,
109                                                  RAS_IRenderTools* rendertools,
110                                                  KX_BlenderSceneConverter* converter
111                                                  )
112 {
113         
114         int uniqueint = 0;
115         bActuator* bact = (bActuator*) blenderobject->actuators.first;
116         while(bact)
117         {
118                 STR_String uniquename = bact->name;
119                 STR_String objectname = gameobj->GetName();
120                 
121                 SCA_IActuator* baseact = NULL;
122                 switch (bact->type)
123                 {
124                 case ACT_OBJECT:
125                         {
126                                 bObjectActuator* obact = (bObjectActuator*) bact->data;
127                                 MT_Vector3 forcevec(KX_BLENDERTRUNC(obact->forceloc[0]),
128                                         KX_BLENDERTRUNC(obact->forceloc[1]),
129                                         KX_BLENDERTRUNC(obact->forceloc[2]));
130                                 MT_Vector3 torquevec(obact->forcerot[0],obact->forcerot[1],obact->forcerot[2]);
131                                 MT_Vector3 dlocvec ( KX_BLENDERTRUNC(obact->dloc[0]),
132                                         KX_BLENDERTRUNC(obact->dloc[1]),
133                                         KX_BLENDERTRUNC(obact->dloc[2]));
134                                 MT_Vector3 drotvec ( KX_BLENDERTRUNC(obact->drot[0]),obact->drot[1],obact->drot[2]);
135                                 MT_Vector3 linvelvec ( KX_BLENDERTRUNC(obact->linearvelocity[0]),
136                                         KX_BLENDERTRUNC(obact->linearvelocity[1]),
137                                         KX_BLENDERTRUNC(obact->linearvelocity[2]));
138                                 MT_Vector3 angvelvec ( KX_BLENDERTRUNC(obact->angularvelocity[0]),
139                                         KX_BLENDERTRUNC(obact->angularvelocity[1]),
140                                         KX_BLENDERTRUNC(obact->angularvelocity[2]));
141                                 short damping = obact->damping;
142                                 
143                                 drotvec /=              BLENDER_HACK_DTIME;
144                                 //drotvec /=            BLENDER_HACK_DTIME;
145                                 drotvec *= MT_2_PI/360.0;
146                                 //dlocvec /= BLENDER_HACK_DTIME;
147                                 //linvelvec /=  BLENDER_HACK_DTIME;
148                                 //angvelvec /=  BLENDER_HACK_DTIME;
149                                 
150                                 /* Blender uses a bit vector internally for the local-flags. In */
151                                 /* KX, we have four bools. The compiler should be smart enough  */
152                                 /* to do the right thing. We need to explicitly convert here!   */
153                                 
154                                 KX_LocalFlags bitLocalFlag;
155                                 
156                                 bitLocalFlag.Force = bool((obact->flag & ACT_FORCE_LOCAL)!=0);
157                                 bitLocalFlag.Torque = bool((obact->flag & ACT_TORQUE_LOCAL) !=0);//rlocal;
158                                 bitLocalFlag.DLoc = bool((obact->flag & ACT_DLOC_LOCAL)!=0);
159                                 bitLocalFlag.DRot = bool((obact->flag & ACT_DROT_LOCAL)!=0);
160                                 bitLocalFlag.LinearVelocity = bool((obact->flag & ACT_LIN_VEL_LOCAL)!=0);
161                                 bitLocalFlag.AngularVelocity = bool((obact->flag & ACT_ANG_VEL_LOCAL)!=0);
162                                 bitLocalFlag.ServoControl = bool(obact->type == ACT_OBJECT_SERVO);
163                                 bitLocalFlag.AddOrSetLinV = bool((obact->flag & ACT_ADD_LIN_VEL)!=0);
164                                 
165                                 
166                                 KX_ObjectActuator* tmpbaseact = new KX_ObjectActuator(gameobj,
167                                         forcevec.getValue(),
168                                         torquevec.getValue(),
169                                         dlocvec.getValue(),
170                                         drotvec.getValue(),
171                                         linvelvec.getValue(),
172                                         angvelvec.getValue(),
173                                         damping,
174                                         bitLocalFlag
175                                         );
176                                 baseact = tmpbaseact;
177                                 break;
178                         }
179                 case ACT_ACTION:
180                         {
181                                 if (blenderobject->type==OB_ARMATURE){
182                                         bActionActuator* actact = (bActionActuator*) bact->data;
183                                         STR_String propname = (actact->name ? actact->name : "");
184                                         STR_String propframe = (actact->frameProp ? actact->frameProp : "");
185                                         
186                                         BL_ActionActuator* tmpbaseact = new BL_ActionActuator(
187                                                 gameobj,
188                                                 propname,
189                                                 propframe,
190                                                 actact->sta,
191                                                 actact->end,
192                                                 actact->act,
193                                                 actact->type, // + 1, because Blender starts to count at zero,
194                                                 actact->blendin,
195                                                 actact->priority,
196                                                 actact->end_reset,
197                                                 actact->stridelength
198                                                 // Ketsji at 1, because zero is reserved for "NoDef"
199                                                 );
200                                         baseact= tmpbaseact;
201                                         break;
202                                 }
203                                 else
204                                         printf ("Discarded action actuator from non-armature object [%s]\n", blenderobject->id.name+2);
205                         }
206                 case ACT_SHAPEACTION:
207                         {
208                                 if (blenderobject->type==OB_MESH){
209                                         bActionActuator* actact = (bActionActuator*) bact->data;
210                                         STR_String propname = (actact->name ? actact->name : "");
211                                         
212                                         BL_ShapeActionActuator* tmpbaseact = new BL_ShapeActionActuator(
213                                                 gameobj,
214                                                 propname,
215                                                 actact->sta,
216                                                 actact->end,
217                                                 actact->act,
218                                                 actact->type, // + 1, because Blender starts to count at zero,
219                                                 actact->blendin,
220                                                 actact->priority,
221                                                 actact->stridelength
222                                                 // Ketsji at 1, because zero is reserved for "NoDef"
223                                                 );
224                                         baseact= tmpbaseact;
225                                         break;
226                                 }
227                                 else
228                                         printf ("Discarded shape action actuator from non-mesh object [%s]\n", blenderobject->id.name+2);
229                         }
230                 case ACT_IPO:
231                         {
232                                 bIpoActuator* ipoact = (bIpoActuator*) bact->data;
233                                 bool ipochild = (ipoact->flag & ACT_IPOCHILD) !=0;
234                                 STR_String propname = ( ipoact->name ? ipoact->name : "");
235                                 // first bit?
236                                 bool ipo_as_force = (ipoact->flag & ACT_IPOFORCE);
237                                 bool local = (ipoact->flag & ACT_IPOLOCAL);
238                                 bool ipo_add = (ipoact->flag & ACT_IPOADD);
239                                 
240                                 KX_IpoActuator* tmpbaseact = new KX_IpoActuator(
241                                         gameobj,
242                                         propname ,
243                                         ipoact->sta,
244                                         ipoact->end,
245                                         ipochild,
246                                         ipoact->type + 1, // + 1, because Blender starts to count at zero,
247                                         // Ketsji at 1, because zero is reserved for "NoDef"
248                                         ipo_as_force,
249                                         ipo_add,
250                                         local);
251                                 baseact = tmpbaseact;
252                                 break;
253                         }
254                 case ACT_LAMP:
255                         {
256                                 break;
257                         }
258                 case ACT_CAMERA:
259                         {
260                                 bCameraActuator *camact = (bCameraActuator *) bact->data;
261                                 if (camact->ob) {
262                                         KX_GameObject *tmpgob = converter->FindGameObject(camact->ob);
263                                         
264                                         /* visifac, fac and axis are not copied from the struct...   */ 
265                                         /* that's some internal state...                             */
266                                         KX_CameraActuator *tmpcamact
267                                                 = new KX_CameraActuator(gameobj,
268                                                 tmpgob,
269                                                 camact->height,
270                                                 camact->min,
271                                                 camact->max,
272                                                 camact->axis=='x');
273                                         baseact = tmpcamact;
274                                 }
275                                 break;
276                         }
277                 case ACT_MESSAGE:
278                         {
279                                 bMessageActuator *msgAct = (bMessageActuator *) bact->data;
280                                 
281                                 /**
282                                 * Get the name of the properties that objects must own that
283                                 * we're sending to, if present
284                                 */
285                                 STR_String toPropName = (msgAct->toPropName
286                                         ? (char*) msgAct->toPropName
287                                         : "");
288                                         /**
289                                         * Get the Message Subject to send.
290                                 */
291                                 STR_String subject = (msgAct->subject
292                                         ? (char*) msgAct->subject
293                                         : "");
294                                 
295                                         /**
296                                         * Get the bodyType
297                                 */
298                                 int bodyType = msgAct->bodyType;
299                                 
300                                 /**
301                                 * Get the body (text message or property name whose value
302                                 * we'll be sending, might be empty
303                                 */
304                                 STR_String body = (msgAct->body
305                                         ? (char*) msgAct->body
306                                         : "");
307                                 
308                                 KX_NetworkMessageActuator *tmpmsgact = 
309                                         new KX_NetworkMessageActuator(
310                                         gameobj,                                        // actuator controlling object
311                                         scene->GetNetworkScene(),       // needed for replication
312                                         toPropName,
313                                         subject,
314                                         bodyType,
315                                         body);
316                                 baseact = tmpmsgact;
317                                 break;
318                         }
319                 case ACT_MATERIAL:
320                         {
321                                 break;
322                         }
323                 case ACT_SOUND:
324                         {
325                                 bSoundActuator* soundact = (bSoundActuator*) bact->data;
326                                 /* get type, and possibly a start and end frame */
327                                 short startFrame = soundact->sta, stopFrame = soundact->end;
328                                 KX_SoundActuator::KX_SOUNDACT_TYPE 
329                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
330                                 
331                                 switch(soundact->type) {
332                                 case ACT_SND_PLAY_STOP_SOUND:
333                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYSTOP;
334                                         break;
335                                 case ACT_SND_PLAY_END_SOUND:
336                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYEND;
337                                         break;
338                                 case ACT_SND_LOOP_STOP_SOUND:
339                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPSTOP;
340                                         break;
341                                 case ACT_SND_LOOP_END_SOUND:
342                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPEND;
343                                         break;
344                                 case ACT_SND_LOOP_BIDIRECTIONAL_SOUND:
345                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL;
346                                         break;
347                                 case ACT_SND_LOOP_BIDIRECTIONAL_STOP_SOUND:
348                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP;
349                                         break;
350                                         
351                                 default:
352                                         /* This is an error!!! */
353                                         soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
354                                 }
355                                 
356                                 if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF) 
357                                 {
358                                         SND_SoundObject* sndobj = NULL;
359                                         
360                                         if (soundact->sound)
361                                         {
362                                                 SND_Scene* soundscene = scene->GetSoundScene();
363                                                 STR_String samplename = soundact->sound->name;
364                                                 
365                                                 bool sampleisloaded = false;
366                                                 
367                                                 /* let's see if the sample was already loaded */
368                                                 if (soundscene->IsSampleLoaded(samplename))
369                                                 {
370                                                         sampleisloaded = true;
371                                                 }
372                                                 else
373                                                 {
374                                                         /* if not, make it so */
375                                                         PackedFile* pf = soundact->sound->newpackedfile;
376                                                         
377                                                         /* but we need a packed file then */
378                                                         if (pf)
379                                                         {
380                                                                 if (soundscene->LoadSample(samplename, pf->data, pf->size) > -1)
381                                                                         sampleisloaded = true;
382                                                         }
383                                                         /* or else load it from disk */
384                                                         else
385                                                         {
386                                                                 /* but we need to convert the samplename into absolute pathname first */
387                                                                 BLI_convertstringcode(soundact->sound->name, maggiename);
388                                                                 samplename = soundact->sound->name;
389                                                                 
390                                                                 /* and now we can load it */
391                                                                 if (soundscene->LoadSample(samplename, NULL, 0) > -1)
392                                                                         sampleisloaded = true;
393                                                         }
394                                                 }
395                                                 
396                                                 if (sampleisloaded)
397                                                 {
398                                                         sndobj = new SND_SoundObject();
399                                                         sndobj->SetSampleName(samplename.Ptr());
400                                                         sndobj->SetObjectName(bact->name);
401                                                         sndobj->SetRollOffFactor(soundact->sound->attenuation);
402                                                         sndobj->SetGain(soundact->sound->volume);
403                                                         sndobj->SetPitch(exp((soundact->sound->pitch / 12.0) * log(2.0)));
404                                                         //                                                      sndobj->SetLoopStart(soundact->sound->loopstart);
405                                                         //                                                      sndobj->SetLoopStart(soundact->sound->loopend);
406                                                         if (soundact->sound->flags & SOUND_FLAGS_LOOP)
407                                                         {
408                                                                 if (soundact->sound->flags & SOUND_FLAGS_BIDIRECTIONAL_LOOP)
409                                                                         sndobj->SetLoopMode(SND_LOOP_BIDIRECTIONAL);
410                                                                 else
411                                                                         sndobj->SetLoopMode(SND_LOOP_NORMAL);
412                                                         }
413                                                         else
414                                                                 sndobj->SetLoopMode(SND_LOOP_OFF);
415                                                         
416                                                         if (soundact->sound->flags & SOUND_FLAGS_PRIORITY)
417                                                                 sndobj->SetHighPriority(true);
418                                                         else
419                                                                 sndobj->SetHighPriority(false);
420                                                         
421                                                         if (soundact->sound->flags & SOUND_FLAGS_3D)
422                                                                 sndobj->Set3D(true);
423                                                         else
424                                                                 sndobj->Set3D(false);
425                                                         
426                                                         KX_SoundActuator* tmpsoundact = 
427                                                                 new KX_SoundActuator(gameobj, 
428                                                                 sndobj,
429                                                                 scene->GetSoundScene(), // needed for replication!
430                                                                 soundActuatorType,
431                                                                 startFrame,
432                                                                 stopFrame);
433                                                         
434                                                         tmpsoundact->SetName(bact->name);
435                                                         baseact = tmpsoundact;
436                                                         soundscene->AddObject(sndobj);
437                                                 } else {
438                                                         std::cout << "WARNING: Sound actuator " << bact->name << " failed to load sample." << std::endl;
439                                                 }
440                                         }
441                                 }
442                                 break;
443                         }
444                 case ACT_CD:
445                         {
446                                 bCDActuator* cdact = (bCDActuator*) bact->data;
447                                 /* get type, and possibly a start and end frame */
448                                 short startFrame = cdact->sta, stopFrame = cdact->end;
449                                 KX_CDActuator::KX_CDACT_TYPE 
450                                         cdActuatorType = KX_CDActuator::KX_CDACT_NODEF;
451                                 
452                                 switch(cdact->type)
453                                 {
454                                 case ACT_CD_PLAY_ALL:
455                                         cdActuatorType = KX_CDActuator::KX_CDACT_PLAY_ALL;
456                                         break;
457                                 case ACT_CD_PLAY_TRACK:
458                                         cdActuatorType = KX_CDActuator::KX_CDACT_PLAY_TRACK;
459                                         break;
460                                 case ACT_CD_LOOP_TRACK:
461                                         cdActuatorType = KX_CDActuator::KX_CDACT_LOOP_TRACK;
462                                         break;
463                                 case ACT_CD_VOLUME:
464                                         cdActuatorType = KX_CDActuator::KX_CDACT_VOLUME;
465                                         break;
466                                 case ACT_CD_STOP:
467                                         cdActuatorType = KX_CDActuator::KX_CDACT_STOP;
468                                         break;
469                                 case ACT_CD_PAUSE:
470                                         cdActuatorType = KX_CDActuator::KX_CDACT_PAUSE;
471                                         break;
472                                 case ACT_CD_RESUME:
473                                         cdActuatorType = KX_CDActuator::KX_CDACT_RESUME;
474                                         break;
475                                         
476                                 default:
477                                         /* This is an error!!! */
478                                         cdActuatorType = KX_CDActuator::KX_CDACT_NODEF;
479                                 }
480                                 
481                                 if (cdActuatorType != KX_CDActuator::KX_CDACT_NODEF) 
482                                 {
483                                         SND_CDObject* pCD = SND_CDObject::Instance();
484                                         
485                                         if (pCD)
486                                         {
487                                                 pCD->SetGain(cdact->volume);
488                                                 
489                                                 KX_CDActuator* tmpcdact = 
490                                                         new KX_CDActuator(gameobj, 
491                                                         scene->GetSoundScene(), // needed for replication!
492                                                         cdActuatorType,
493                                                         cdact->track,
494                                                         startFrame,
495                                                         stopFrame);
496                                                 
497                                                 tmpcdact->SetName(bact->name);
498                                                 baseact = tmpcdact;
499                                         }
500                                 }
501                                 break;
502                         }
503                 case ACT_PROPERTY:
504                         {
505                                 bPropertyActuator* propact = (bPropertyActuator*) bact->data;
506                                 SCA_IObject* destinationObj = NULL;
507                                 
508                                 /*
509                                 here the destinationobject is searched. problem with multiple scenes: other scenes
510                                 have not been converted yet, so the destobj will not be found, so the prop will
511                                 not be copied.
512                                 possible solutions:
513                                 - convert everything when possible and not realtime only when needed.
514                                 - let the object-with-property report itself to the act when converted
515                                 */
516                                 if (propact->ob)
517                                         destinationObj = converter->FindGameObject(propact->ob);
518                                 
519                                 SCA_PropertyActuator* tmppropact = new SCA_PropertyActuator(
520                                         gameobj,
521                                         destinationObj,
522                                         propact->name,
523                                         propact->value,
524                                         propact->type+1); // + 1 because Ketsji Logic starts
525                                 // with 0 for KX_ACT_PROP_NODEF
526                                 baseact = tmppropact;
527                                 break;
528                         }
529                 case ACT_EDIT_OBJECT:
530                         {
531                                 bEditObjectActuator *editobact 
532                                         = (bEditObjectActuator *) bact->data;
533                                 /* There are four different kinds of 'edit object' thingies  */
534                                 /* The alternative to this lengthy conversion is packing     */
535                                 /* several actuators in one, which is not very nice design.. */
536                                 switch (editobact->type) {
537                                 case ACT_EDOB_ADD_OBJECT: 
538                                         {
539                                                 
540                                                 // does the 'original' for replication exists, and 
541                                                 // is it in a non-active layer ?
542                                                 SCA_IObject* originalval = NULL;
543                                                 if (editobact->ob)
544                                                 {
545                                                         if (editobact->ob->lay & activeLayerBitInfo)
546                                                         {
547                                                                 fprintf(stderr, "Warning, object \"%s\" from AddObject actuator \"%s\" is not in a hidden layer.\n", objectname.Ptr(), uniquename.Ptr());
548                                                         }
549                                                         else {
550                                                                 originalval = converter->FindGameObject(editobact->ob);
551                                                         }
552                                                 }
553                                                 MT_Vector3 linvelvec ( KX_BLENDERTRUNC(editobact->linVelocity[0]),
554                                                         KX_BLENDERTRUNC(editobact->linVelocity[1]),
555                                                         KX_BLENDERTRUNC(editobact->linVelocity[2]));
556                                                         
557                                                 KX_SCA_AddObjectActuator* tmpaddact = 
558                                                         new KX_SCA_AddObjectActuator(
559                                                                 gameobj, 
560                                                                 originalval,
561                                                                 editobact->time,
562                                                                 scene,
563                                                                 linvelvec.getValue(),
564                                                                 editobact->localflag!=0
565                                                                 );
566                                                                 
567                                                                 //editobact->ob to gameobj
568                                                                 baseact = tmpaddact;
569                                         }
570                                         break;
571                                 case ACT_EDOB_END_OBJECT:
572                                         {
573                                                 KX_SCA_EndObjectActuator* tmpendact 
574                                                         = new KX_SCA_EndObjectActuator(gameobj,scene);
575                                                 baseact = tmpendact;
576                                         }
577                                         break;
578                                 case ACT_EDOB_REPLACE_MESH:
579                                         {
580                                                 RAS_MeshObject *tmpmesh = NULL;
581                                                 if (editobact->me)
582                                                         tmpmesh = BL_ConvertMesh(
583                                                                 editobact->me,
584                                                                 blenderobject,
585                                                                 rendertools,
586                                                                 scene,
587                                                                 converter
588                                                                 );
589
590                                                 KX_SCA_ReplaceMeshActuator* tmpreplaceact
591                                                         = new KX_SCA_ReplaceMeshActuator(
592                                                                 gameobj,
593                                                                 tmpmesh,
594                                                                 scene
595                                                                 );
596                                                         
597                                                         baseact = tmpreplaceact;
598                                         }
599                                         break;
600                                 case ACT_EDOB_TRACK_TO:
601                                         {
602                                                 SCA_IObject* originalval = NULL;
603                                                 if (editobact->ob)
604                                                         originalval = converter->FindGameObject(editobact->ob);
605                                                         
606                                                 KX_TrackToActuator* tmptrackact 
607                                                         = new KX_TrackToActuator(gameobj, 
608                                                                 originalval,
609                                                                 editobact->time,
610                                                                 editobact->flag,
611                                                                 blenderobject->trackflag,
612                                                                 blenderobject->upflag
613                                                                 );
614                                                         baseact = tmptrackact;
615                                                 break;
616                                         }
617                                 case ACT_EDOB_DYNAMICS:
618                                         {
619                                                 KX_SCA_DynamicActuator* tmpdynact 
620                                                         = new KX_SCA_DynamicActuator(gameobj, 
621                                                                 editobact->dyn_operation
622                                                                 );
623                                                         baseact = tmpdynact;
624                                         }
625                                 }
626                                 break;
627                         }
628                 case ACT_CONSTRAINT:
629                         {
630                                 float min = 0.0, max = 0.0;
631                                 char *prop = NULL;
632                                 KX_ConstraintActuator::KX_CONSTRAINTTYPE locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF;
633                                 bConstraintActuator *conact 
634                                         = (bConstraintActuator*) bact->data;
635                                 /* convert settings... degrees in the ui become radians  */ 
636                                 /* internally                                            */ 
637                                 if (conact->type == ACT_CONST_TYPE_ORI) {
638                                         min = (MT_2_PI * conact->minloc[0])/360.0;
639                                         max = (MT_2_PI * conact->maxloc[0])/360.0;
640                                         switch (conact->mode) {
641                                         case ACT_CONST_DIRPX:
642                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX;
643                                                 break;
644                                         case ACT_CONST_DIRPY:
645                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY;
646                                                 break;
647                                         case ACT_CONST_DIRPZ:
648                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ;
649                                                 break;
650                                         }
651                                 } else if (conact->type == ACT_CONST_TYPE_DIST) {
652                                         switch (conact->mode) {
653                                         case ACT_CONST_DIRPX:
654                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX;
655                                                 min = conact->minloc[0];
656                                                 max = conact->maxloc[0];
657                                                 break;
658                                         case ACT_CONST_DIRPY:
659                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY;
660                                                 min = conact->minloc[1];
661                                                 max = conact->maxloc[1];
662                                                 break;
663                                         case ACT_CONST_DIRPZ:
664                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ;
665                                                 min = conact->minloc[2];
666                                                 max = conact->maxloc[2];
667                                                 break;
668                                         case ACT_CONST_DIRNX:
669                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX;
670                                                 min = conact->minloc[0];
671                                                 max = conact->maxloc[0];
672                                                 break;
673                                         case ACT_CONST_DIRNY:
674                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY;
675                                                 min = conact->minloc[1];
676                                                 max = conact->maxloc[1];
677                                                 break;
678                                         case ACT_CONST_DIRNZ:
679                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ;
680                                                 min = conact->minloc[2];
681                                                 max = conact->maxloc[2];
682                                                 break;
683                                         }
684                                         prop = conact->matprop;
685                                 } else {
686                                         switch (conact->flag) {
687                                         case ACT_CONST_LOCX:
688                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX; 
689                                                 min = conact->minloc[0];
690                                                 max = conact->maxloc[0];
691                                                 break;
692                                         case ACT_CONST_LOCY:
693                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY; 
694                                                 min = conact->minloc[1];
695                                                 max = conact->maxloc[1];
696                                                 break;
697                                         case ACT_CONST_LOCZ:
698                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ;
699                                                 min = conact->minloc[2];
700                                                 max = conact->maxloc[2];
701                                                 break;
702                                         case ACT_CONST_ROTX:
703                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX;
704                                                 min = MT_2_PI * conact->minrot[0] / 360.0;
705                                                 max = MT_2_PI * conact->maxrot[0] / 360.0;
706                                                 break;
707                                         case ACT_CONST_ROTY:
708                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY;
709                                                 min = MT_2_PI * conact->minrot[1] / 360.0;
710                                                 max = MT_2_PI * conact->maxrot[1] / 360.0;
711                                                 break;
712                                         case ACT_CONST_ROTZ:
713                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ;
714                                                 min = MT_2_PI * conact->minrot[2] / 360.0;
715                                                 max = MT_2_PI * conact->maxrot[2] / 360.0;
716                                                 break;
717                                         default:
718                                                 ; /* error */ 
719                                         }
720                                 }
721                                 KX_ConstraintActuator *tmpconact 
722                                         = new KX_ConstraintActuator(gameobj,
723                                                 conact->damp,
724                                                 conact->rotdamp,
725                                                 min,
726                                                 max,
727                                                 conact->maxrot,
728                                                 locrot,
729                                                 conact->time,
730                                                 conact->flag,
731                                                 prop);
732                                 baseact = tmpconact;
733                                 break;
734                         }
735                 case ACT_GROUP:
736                         {
737                                 // deprecated
738                         }
739                         break;
740                 case ACT_SCENE:
741                         {
742                                 bSceneActuator *sceneact = (bSceneActuator *) bact->data;
743                                 STR_String nextSceneName("");
744                                 
745                                 KX_SceneActuator* tmpsceneact;
746                                 int mode = KX_SceneActuator::KX_SCENE_NODEF;
747                                 KX_Camera *cam = NULL;
748                                 //KX_Scene* scene = NULL;
749                                 switch (sceneact->type)
750                                 {
751                                 case ACT_SCENE_RESUME:
752                                 case ACT_SCENE_SUSPEND:
753                                 case ACT_SCENE_ADD_FRONT:
754                                 case ACT_SCENE_ADD_BACK:
755                                 case ACT_SCENE_REMOVE:
756                                 case ACT_SCENE_SET:
757                                         {
758                                                 switch (sceneact->type)
759                                                 {
760                                                 case ACT_SCENE_RESUME:
761                                                         mode = KX_SceneActuator::KX_SCENE_RESUME;
762                                                         break;
763                                                 case ACT_SCENE_SUSPEND:
764                                                         mode = KX_SceneActuator::KX_SCENE_SUSPEND;
765                                                         break;
766                                                 case ACT_SCENE_ADD_FRONT:
767                                                         mode = KX_SceneActuator::KX_SCENE_ADD_FRONT_SCENE;
768                                                         break;
769                                                 case ACT_SCENE_ADD_BACK:
770                                                         mode = KX_SceneActuator::KX_SCENE_ADD_BACK_SCENE;
771                                                         break;
772                                                 case ACT_SCENE_REMOVE:
773                                                         mode = KX_SceneActuator::KX_SCENE_REMOVE_SCENE;
774                                                         break;
775                                                 case ACT_SCENE_SET:
776                                                 default:
777                                                         mode = KX_SceneActuator::KX_SCENE_SET_SCENE;
778                                                         break;
779                                                 };
780                                                 
781                                                 if (sceneact->scene)
782                                                 {
783                                                         nextSceneName = sceneact->scene->id.name + 2; // this '2' is necessary to remove prefix 'SC'
784                                                 }
785                                                 
786                                                 break;
787                                         }
788                                 case ACT_SCENE_CAMERA:
789                                         mode = KX_SceneActuator::KX_SCENE_SET_CAMERA;
790                                         if (sceneact->camera)
791                                         {
792                                                 cam = (KX_Camera*) converter->FindGameObject(sceneact->camera);
793                                         }
794                                         break;
795                                 case ACT_SCENE_RESTART:
796                                         {
797                                                 
798                                                 mode =  KX_SceneActuator::KX_SCENE_RESTART;
799                                                 break;
800                                         }
801                                 default:
802                                         ; /* flag error */
803                                 }
804                                 tmpsceneact = new KX_SceneActuator(gameobj,
805                                                 mode,
806                                                 scene,
807                                                 ketsjiEngine,
808                                                 nextSceneName,
809                                                 cam);
810                                         baseact = tmpsceneact;
811                                 break;
812                         }
813                 case ACT_GAME:
814                         {
815                                 bGameActuator *gameact = (bGameActuator *) bact->data;
816                                 KX_GameActuator* tmpgameact;
817                                 STR_String filename = maggiename;
818                                 STR_String loadinganimationname = "";
819                                 int mode = KX_GameActuator::KX_GAME_NODEF;
820                                 switch (gameact->type)
821                                 {
822                                 case ACT_GAME_LOAD:
823                                         {
824                                                 mode = KX_GameActuator::KX_GAME_LOAD;
825                                                 filename = gameact->filename;
826                                                 loadinganimationname = gameact->loadaniname;
827                                                 break;
828                                         }
829                                 case ACT_GAME_START:
830                                         {
831                                                 mode = KX_GameActuator::KX_GAME_START;
832                                                 filename = gameact->filename;
833                                                 loadinganimationname = gameact->loadaniname;
834                                                 break;
835                                         }
836                                 case ACT_GAME_RESTART:
837                                         {
838                                                 mode = KX_GameActuator::KX_GAME_RESTART;
839                                                 break;
840                                         }
841                                 case ACT_GAME_QUIT:
842                                         {
843                                                 mode = KX_GameActuator::KX_GAME_QUIT;
844                                                 break;
845                                         }
846                                 default:
847                                         ; /* flag error */
848                                 }
849                                         tmpgameact = new KX_GameActuator(gameobj,
850                                                 mode,
851                                                 filename,
852                                                 loadinganimationname,
853                                                 scene,
854                                                 ketsjiEngine);
855                                         baseact = tmpgameact;
856
857                                 break;
858                         }
859                 case ACT_RANDOM:
860                         {
861                                 bRandomActuator *randAct 
862                                         = (bRandomActuator *) bact->data;
863                                 
864                                 unsigned long seedArg = randAct->seed;
865                                 SCA_RandomActuator::KX_RANDOMACT_MODE modeArg 
866                                         = SCA_RandomActuator::KX_RANDOMACT_NODEF;
867                                 SCA_RandomActuator *tmprandomact;
868                                 float paraArg1 = 0.0;
869                                 float paraArg2 = 0.0;
870                                 
871                                 switch  (randAct->distribution) {
872                                 case ACT_RANDOM_BOOL_CONST:
873                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST;
874                                         paraArg1 = (float) randAct->int_arg_1;
875                                         break;
876                                 case ACT_RANDOM_BOOL_UNIFORM:
877                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM;
878                                         break;
879                                 case ACT_RANDOM_BOOL_BERNOUILLI:
880                                         paraArg1 = randAct->float_arg_1;
881                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI;
882                                         break;
883                                 case ACT_RANDOM_INT_CONST:
884                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_CONST;
885                                         paraArg1 = (float) randAct->int_arg_1;
886                                         break;
887                                 case ACT_RANDOM_INT_UNIFORM:
888                                         paraArg1 = (float) randAct->int_arg_1;
889                                         paraArg2 = (float) randAct->int_arg_2;
890                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM;
891                                         break;
892                                 case ACT_RANDOM_INT_POISSON:
893                                         paraArg1 = randAct->float_arg_1;
894                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_POISSON;
895                                         break;
896                                 case ACT_RANDOM_FLOAT_CONST:
897                                         paraArg1 = randAct->float_arg_1;
898                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST;
899                                         break;
900                                 case ACT_RANDOM_FLOAT_UNIFORM:
901                                         paraArg1 = randAct->float_arg_1;
902                                         paraArg2 = randAct->float_arg_2;
903                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM;
904                                         break;
905                                 case ACT_RANDOM_FLOAT_NORMAL:
906                                         paraArg1 = randAct->float_arg_1;
907                                         paraArg2 = randAct->float_arg_2;
908                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL;
909                                         break;
910                                 case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
911                                         paraArg1 = randAct->float_arg_1;
912                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL;
913                                         break;
914                                 default:
915                                         ; /* error */                           
916                                 }
917                                 tmprandomact = new SCA_RandomActuator(gameobj,
918                                         seedArg,
919                                         modeArg, 
920                                         paraArg1,
921                                         paraArg2,
922                                         randAct->propname);
923                                 baseact = tmprandomact;
924                         }
925                         break;
926
927                 case ACT_VISIBILITY:
928                 {
929                         bVisibilityActuator *vis_act = (bVisibilityActuator *) bact->data;
930                         KX_VisibilityActuator * tmp_vis_act = NULL;
931                         bool v = ((vis_act->flag & ACT_VISIBILITY_INVISIBLE) != 0);
932
933                         tmp_vis_act = 
934                                 new KX_VisibilityActuator(gameobj,
935                                                           !v);
936                         
937                         baseact = tmp_vis_act;
938                 }
939                 break;
940
941                 case ACT_STATE:
942                 {
943                         bStateActuator *sta_act = (bStateActuator *) bact->data;
944                         KX_StateActuator * tmp_sta_act = NULL;
945
946                         tmp_sta_act = 
947                                 new KX_StateActuator(gameobj, sta_act->type, sta_act->mask);
948                         
949                         baseact = tmp_sta_act;
950                 }
951                 break;
952
953                 case ACT_2DFILTER:
954                 {
955                         bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data;
956             SCA_2DFilterActuator *tmp = NULL;
957
958                         RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode;
959                         switch(_2dfilter->type)
960                         {
961                                 case ACT_2DFILTER_MOTIONBLUR:
962                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR;
963                                         break;
964                                 case ACT_2DFILTER_BLUR:
965                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_BLUR;
966                                         break;
967                                 case ACT_2DFILTER_SHARPEN:
968                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_SHARPEN;
969                                         break;
970                                 case ACT_2DFILTER_DILATION:
971                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_DILATION;
972                                         break;
973                                 case ACT_2DFILTER_EROSION:
974                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_EROSION;
975                                         break;
976                                 case ACT_2DFILTER_LAPLACIAN:
977                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN;
978                                         break;
979                                 case ACT_2DFILTER_SOBEL:
980                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_SOBEL;
981                                         break;
982                                 case ACT_2DFILTER_PREWITT:
983                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_PREWITT;
984                                         break;
985                                 case ACT_2DFILTER_GRAYSCALE:
986                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE;
987                                         break;
988                                 case ACT_2DFILTER_SEPIA:
989                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_SEPIA;
990                                         break;
991                                 case ACT_2DFILTER_INVERT:
992                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_INVERT;
993                                         break;
994                                 case ACT_2DFILTER_CUSTOMFILTER:
995                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER;
996                                         break;
997                                 case ACT_2DFILTER_NOFILTER:
998                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
999                                         break;
1000                                 case ACT_2DFILTER_DISABLED:
1001                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_DISABLED;
1002                                         break;
1003                                 case ACT_2DFILTER_ENABLED:
1004                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_ENABLED;
1005                                         break;
1006                                 default:
1007                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
1008                                         break;
1009                         }
1010             
1011                         tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag,
1012                                 _2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),rendertools);
1013
1014                         if (_2dfilter->text)
1015                         {
1016                                 char *buf;
1017                                 // this is some blender specific code
1018                                 buf = txt_to_buf(_2dfilter->text);
1019                                 if (buf)
1020                                 {
1021                                         tmp->SetShaderText(STR_String(buf));
1022                                         MEM_freeN(buf);
1023                                 }
1024                         }
1025
1026             baseact = tmp;
1027                         
1028                 }
1029                 break;
1030                 case ACT_PARENT:
1031                         {
1032                                 bParentActuator *parAct = (bParentActuator *) bact->data;
1033                                 int mode = KX_ParentActuator::KX_PARENT_NODEF;
1034                                 KX_GameObject *tmpgob;
1035
1036                                 switch(parAct->type)
1037                                 {
1038                                         case ACT_PARENT_SET:
1039                                                 mode = KX_ParentActuator::KX_PARENT_SET;
1040                                                 tmpgob = converter->FindGameObject(parAct->ob);
1041                                                 break;
1042                                         case ACT_PARENT_REMOVE:
1043                                                 mode = KX_ParentActuator::KX_PARENT_REMOVE;
1044                                                 tmpgob = NULL;
1045                                                 break;
1046                                 }
1047         
1048                                 KX_ParentActuator *tmpparact
1049                                         = new KX_ParentActuator(gameobj,
1050                                         mode,
1051                                         tmpgob);
1052                                 baseact = tmpparact;
1053                                 break;
1054                         }
1055                 
1056                 default:
1057                         ; /* generate some error */
1058                 }
1059                 
1060                 if (baseact)
1061                 {
1062                         baseact->SetExecutePriority(executePriority++);
1063                         uniquename += "#ACT#";
1064                         uniqueint++;
1065                         CIntValue* uniqueval = new CIntValue(uniqueint);
1066                         uniquename += uniqueval->GetText();
1067                         uniqueval->Release();
1068                         baseact->SetName(STR_String(bact->name));
1069                         //gameobj->SetProperty(uniquename,baseact);
1070                         gameobj->AddActuator(baseact);
1071                         
1072                         converter->RegisterGameActuator(baseact, bact);
1073                         // done with baseact, release it
1074                         baseact->Release();
1075                 }
1076                 
1077                 bact = bact->next;
1078         }
1079 }
1080
1081