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