Some version were not merged from svn/missing --> svn merge -r 16370:16371 https...
[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_Scene* soundscene = scene->GetSoundScene();
359                                         STR_String samplename = "";
360                                         bool sampleisloaded = false;
361                                         
362                                         if (soundact->sound) {
363                                                 /* Need to convert the samplename into absolute path
364                                                  * before checking if its loaded */
365                                                 char fullpath[sizeof(soundact->sound->name)];
366                                                 
367                                                 /* dont modify soundact->sound->name, only change a copy */
368                                                 BLI_strncpy(fullpath, soundact->sound->name, sizeof(fullpath));
369                                                 BLI_convertstringcode(fullpath, maggiename);
370                                                 samplename = fullpath;
371                                                 
372                                                 /* let's see if the sample was already loaded */
373                                                 if (soundscene->IsSampleLoaded(samplename))
374                                                 {
375                                                         sampleisloaded = true;
376                                                 }
377                                                 else {
378                                                         /* if not, make it so */
379                                                         PackedFile* pf = soundact->sound->newpackedfile;
380                                                         
381                                                         /* but we need a packed file then */
382                                                         if (pf)
383                                                         {
384                                                                 if (soundscene->LoadSample(samplename, pf->data, pf->size) > -1)
385                                                                         sampleisloaded = true;
386                                                         }
387                                                         /* or else load it from disk */
388                                                         else
389                                                         {
390                                                                 if (soundscene->LoadSample(samplename, NULL, 0) > -1) {
391                                                                         sampleisloaded = true;
392                                                                 }
393                                                                 else {
394                                                                         std::cout <<    "WARNING: Sound actuator \"" << bact->name <<
395                                                                                                         "\" from object \"" <<  blenderobject->id.name+2 <<
396                                                                                                         "\" failed to load sample." << std::endl;
397                                                                 }
398                                                         }
399                                                 }
400                                         } else {
401                                                 std::cout <<    "WARNING: Sound actuator \"" << bact->name <<
402                                                                                 "\" from object \"" <<  blenderobject->id.name+2 <<
403                                                                                 "\" has no sound datablock." << std::endl;
404                                         }
405                                         
406                                         /* Note, allowing actuators for sounds that are not there was added since 2.47
407                                          * This is because python may expect the actuator and raise an exception if it dosnt find it
408                                          * better just to add a dummy sound actuator. */
409                                         SND_SoundObject* sndobj = NULL;
410                                         if (sampleisloaded)
411                                         {
412                                                 /* setup the SND_SoundObject */
413                                                 sndobj = new SND_SoundObject();
414                                                 sndobj->SetSampleName(samplename.Ptr());
415                                                 sndobj->SetObjectName(bact->name);
416                                                 if (soundact->sound) {
417                                                         sndobj->SetRollOffFactor(soundact->sound->attenuation);
418                                                         sndobj->SetGain(soundact->sound->volume);
419                                                         sndobj->SetPitch(exp((soundact->sound->pitch / 12.0) * log(2.0)));
420                                                         //                                                      sndobj->SetLoopStart(soundact->sound->loopstart);
421                                                         //                                                      sndobj->SetLoopStart(soundact->sound->loopend);
422                                                         if (soundact->sound->flags & SOUND_FLAGS_LOOP)
423                                                         {
424                                                                 if (soundact->sound->flags & SOUND_FLAGS_BIDIRECTIONAL_LOOP)
425                                                                         sndobj->SetLoopMode(SND_LOOP_BIDIRECTIONAL);
426                                                                 else
427                                                                         sndobj->SetLoopMode(SND_LOOP_NORMAL);
428                                                         }
429                                                         else {
430                                                                 sndobj->SetLoopMode(SND_LOOP_OFF);
431                                                         }
432                                                         
433                                                         if (soundact->sound->flags & SOUND_FLAGS_PRIORITY)
434                                                                 sndobj->SetHighPriority(true);
435                                                         else
436                                                                 sndobj->SetHighPriority(false);
437                                                         
438                                                         if (soundact->sound->flags & SOUND_FLAGS_3D)
439                                                                 sndobj->Set3D(true);
440                                                         else
441                                                                 sndobj->Set3D(false);
442                                                 }
443                                                 else {
444                                                         /* dummy values for a NULL sound
445                                                         * see editsound.c - defaults are unlikely to change soon */
446                                                         sndobj->SetRollOffFactor(1.0);
447                                                         sndobj->SetGain(1.0);
448                                                         sndobj->SetPitch(1.0);
449                                                         sndobj->SetLoopMode(SND_LOOP_OFF);
450                                                         sndobj->SetHighPriority(false);
451                                                         sndobj->Set3D(false);
452                                                 }
453                                         }
454                                         KX_SoundActuator* tmpsoundact = 
455                                                 new KX_SoundActuator(gameobj, 
456                                                 sndobj,
457                                                 scene->GetSoundScene(), // needed for replication!
458                                                 soundActuatorType,
459                                                 startFrame,
460                                                 stopFrame);
461                                         
462                                         tmpsoundact->SetName(bact->name);
463                                         baseact = tmpsoundact;
464                                         if (sndobj)
465                                                 soundscene->AddObject(sndobj);
466                                 }
467                                 break;
468                         }
469                 case ACT_CD:
470                         {
471                                 bCDActuator* cdact = (bCDActuator*) bact->data;
472                                 /* get type, and possibly a start and end frame */
473                                 short startFrame = cdact->sta, stopFrame = cdact->end;
474                                 KX_CDActuator::KX_CDACT_TYPE 
475                                         cdActuatorType = KX_CDActuator::KX_CDACT_NODEF;
476                                 
477                                 switch(cdact->type)
478                                 {
479                                 case ACT_CD_PLAY_ALL:
480                                         cdActuatorType = KX_CDActuator::KX_CDACT_PLAY_ALL;
481                                         break;
482                                 case ACT_CD_PLAY_TRACK:
483                                         cdActuatorType = KX_CDActuator::KX_CDACT_PLAY_TRACK;
484                                         break;
485                                 case ACT_CD_LOOP_TRACK:
486                                         cdActuatorType = KX_CDActuator::KX_CDACT_LOOP_TRACK;
487                                         break;
488                                 case ACT_CD_VOLUME:
489                                         cdActuatorType = KX_CDActuator::KX_CDACT_VOLUME;
490                                         break;
491                                 case ACT_CD_STOP:
492                                         cdActuatorType = KX_CDActuator::KX_CDACT_STOP;
493                                         break;
494                                 case ACT_CD_PAUSE:
495                                         cdActuatorType = KX_CDActuator::KX_CDACT_PAUSE;
496                                         break;
497                                 case ACT_CD_RESUME:
498                                         cdActuatorType = KX_CDActuator::KX_CDACT_RESUME;
499                                         break;
500                                         
501                                 default:
502                                         /* This is an error!!! */
503                                         cdActuatorType = KX_CDActuator::KX_CDACT_NODEF;
504                                 }
505                                 
506                                 if (cdActuatorType != KX_CDActuator::KX_CDACT_NODEF) 
507                                 {
508                                         SND_CDObject* pCD = SND_CDObject::Instance();
509                                         
510                                         if (pCD)
511                                         {
512                                                 pCD->SetGain(cdact->volume);
513                                                 
514                                                 KX_CDActuator* tmpcdact = 
515                                                         new KX_CDActuator(gameobj, 
516                                                         scene->GetSoundScene(), // needed for replication!
517                                                         cdActuatorType,
518                                                         cdact->track,
519                                                         startFrame,
520                                                         stopFrame);
521                                                 
522                                                 tmpcdact->SetName(bact->name);
523                                                 baseact = tmpcdact;
524                                         }
525                                 }
526                                 break;
527                         }
528                 case ACT_PROPERTY:
529                         {
530                                 bPropertyActuator* propact = (bPropertyActuator*) bact->data;
531                                 SCA_IObject* destinationObj = NULL;
532                                 
533                                 /*
534                                 here the destinationobject is searched. problem with multiple scenes: other scenes
535                                 have not been converted yet, so the destobj will not be found, so the prop will
536                                 not be copied.
537                                 possible solutions:
538                                 - convert everything when possible and not realtime only when needed.
539                                 - let the object-with-property report itself to the act when converted
540                                 */
541                                 if (propact->ob)
542                                         destinationObj = converter->FindGameObject(propact->ob);
543                                 
544                                 SCA_PropertyActuator* tmppropact = new SCA_PropertyActuator(
545                                         gameobj,
546                                         destinationObj,
547                                         propact->name,
548                                         propact->value,
549                                         propact->type+1); // + 1 because Ketsji Logic starts
550                                 // with 0 for KX_ACT_PROP_NODEF
551                                 baseact = tmppropact;
552                                 break;
553                         }
554                 case ACT_EDIT_OBJECT:
555                         {
556                                 bEditObjectActuator *editobact 
557                                         = (bEditObjectActuator *) bact->data;
558                                 /* There are four different kinds of 'edit object' thingies  */
559                                 /* The alternative to this lengthy conversion is packing     */
560                                 /* several actuators in one, which is not very nice design.. */
561                                 switch (editobact->type) {
562                                 case ACT_EDOB_ADD_OBJECT: 
563                                         {
564                                                 
565                                                 // does the 'original' for replication exists, and 
566                                                 // is it in a non-active layer ?
567                                                 SCA_IObject* originalval = NULL;
568                                                 if (editobact->ob)
569                                                 {
570                                                         if (editobact->ob->lay & activeLayerBitInfo)
571                                                         {
572                                                                 fprintf(stderr, "Warning, object \"%s\" from AddObject actuator \"%s\" is not in a hidden layer.\n", objectname.Ptr(), uniquename.Ptr());
573                                                         }
574                                                         else {
575                                                                 originalval = converter->FindGameObject(editobact->ob);
576                                                         }
577                                                 }
578                                                 MT_Vector3 linvelvec (
579                                                         KX_BLENDERTRUNC(editobact->linVelocity[0]),
580                                                         KX_BLENDERTRUNC(editobact->linVelocity[1]),
581                                                         KX_BLENDERTRUNC(editobact->linVelocity[2]));
582                                                 
583                                                 MT_Vector3 angvelvec (
584                                                         KX_BLENDERTRUNC(editobact->angVelocity[0]),
585                                                         KX_BLENDERTRUNC(editobact->angVelocity[1]),
586                                                         KX_BLENDERTRUNC(editobact->angVelocity[2]));
587                                                 
588                                                 KX_SCA_AddObjectActuator* tmpaddact = 
589                                                         new KX_SCA_AddObjectActuator(
590                                                                 gameobj, 
591                                                                 originalval,
592                                                                 editobact->time,
593                                                                 scene,
594                                                                 linvelvec.getValue(),
595                                                                 (editobact->localflag & ACT_EDOB_LOCAL_LINV)!=0,
596                                                                 angvelvec.getValue(),
597                                                                 (editobact->localflag & ACT_EDOB_LOCAL_ANGV)!=0
598                                                                 );
599                                                                 
600                                                                 //editobact->ob to gameobj
601                                                                 baseact = tmpaddact;
602                                         }
603                                         break;
604                                 case ACT_EDOB_END_OBJECT:
605                                         {
606                                                 KX_SCA_EndObjectActuator* tmpendact 
607                                                         = new KX_SCA_EndObjectActuator(gameobj,scene);
608                                                 baseact = tmpendact;
609                                         }
610                                         break;
611                                 case ACT_EDOB_REPLACE_MESH:
612                                         {
613                                                 RAS_MeshObject *tmpmesh = NULL;
614                                                 if (editobact->me)
615                                                         tmpmesh = BL_ConvertMesh(
616                                                                 editobact->me,
617                                                                 blenderobject,
618                                                                 rendertools,
619                                                                 scene,
620                                                                 converter
621                                                                 );
622
623                                                 KX_SCA_ReplaceMeshActuator* tmpreplaceact
624                                                         = new KX_SCA_ReplaceMeshActuator(
625                                                                 gameobj,
626                                                                 tmpmesh,
627                                                                 scene
628                                                                 );
629                                                         
630                                                         baseact = tmpreplaceact;
631                                         }
632                                         break;
633                                 case ACT_EDOB_TRACK_TO:
634                                         {
635                                                 SCA_IObject* originalval = NULL;
636                                                 if (editobact->ob)
637                                                         originalval = converter->FindGameObject(editobact->ob);
638                                                         
639                                                 KX_TrackToActuator* tmptrackact 
640                                                         = new KX_TrackToActuator(gameobj, 
641                                                                 originalval,
642                                                                 editobact->time,
643                                                                 editobact->flag,
644                                                                 blenderobject->trackflag,
645                                                                 blenderobject->upflag
646                                                                 );
647                                                         baseact = tmptrackact;
648                                                 break;
649                                         }
650                                 case ACT_EDOB_DYNAMICS:
651                                         {
652                                                 KX_SCA_DynamicActuator* tmpdynact 
653                                                         = new KX_SCA_DynamicActuator(gameobj, 
654                                                                 editobact->dyn_operation
655                                                                 );
656                                                         baseact = tmpdynact;
657                                         }
658                                 }
659                                 break;
660                         }
661                 case ACT_CONSTRAINT:
662                         {
663                                 float min = 0.0, max = 0.0;
664                                 char *prop = NULL;
665                                 KX_ConstraintActuator::KX_CONSTRAINTTYPE locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF;
666                                 bConstraintActuator *conact 
667                                         = (bConstraintActuator*) bact->data;
668                                 /* convert settings... degrees in the ui become radians  */ 
669                                 /* internally                                            */ 
670                                 if (conact->type == ACT_CONST_TYPE_ORI) {
671                                         min = (MT_2_PI * conact->minloc[0])/360.0;
672                                         max = (MT_2_PI * conact->maxloc[0])/360.0;
673                                         switch (conact->mode) {
674                                         case ACT_CONST_DIRPX:
675                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX;
676                                                 break;
677                                         case ACT_CONST_DIRPY:
678                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY;
679                                                 break;
680                                         case ACT_CONST_DIRPZ:
681                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ;
682                                                 break;
683                                         }
684                                 } else if (conact->type == ACT_CONST_TYPE_DIST) {
685                                         switch (conact->mode) {
686                                         case ACT_CONST_DIRPX:
687                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX;
688                                                 min = conact->minloc[0];
689                                                 max = conact->maxloc[0];
690                                                 break;
691                                         case ACT_CONST_DIRPY:
692                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY;
693                                                 min = conact->minloc[1];
694                                                 max = conact->maxloc[1];
695                                                 break;
696                                         case ACT_CONST_DIRPZ:
697                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ;
698                                                 min = conact->minloc[2];
699                                                 max = conact->maxloc[2];
700                                                 break;
701                                         case ACT_CONST_DIRNX:
702                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX;
703                                                 min = conact->minloc[0];
704                                                 max = conact->maxloc[0];
705                                                 break;
706                                         case ACT_CONST_DIRNY:
707                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY;
708                                                 min = conact->minloc[1];
709                                                 max = conact->maxloc[1];
710                                                 break;
711                                         case ACT_CONST_DIRNZ:
712                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ;
713                                                 min = conact->minloc[2];
714                                                 max = conact->maxloc[2];
715                                                 break;
716                                         }
717                                         prop = conact->matprop;
718                                 } else {
719                                         switch (conact->flag) {
720                                         case ACT_CONST_LOCX:
721                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX; 
722                                                 min = conact->minloc[0];
723                                                 max = conact->maxloc[0];
724                                                 break;
725                                         case ACT_CONST_LOCY:
726                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY; 
727                                                 min = conact->minloc[1];
728                                                 max = conact->maxloc[1];
729                                                 break;
730                                         case ACT_CONST_LOCZ:
731                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ;
732                                                 min = conact->minloc[2];
733                                                 max = conact->maxloc[2];
734                                                 break;
735                                         case ACT_CONST_ROTX:
736                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX;
737                                                 min = MT_2_PI * conact->minrot[0] / 360.0;
738                                                 max = MT_2_PI * conact->maxrot[0] / 360.0;
739                                                 break;
740                                         case ACT_CONST_ROTY:
741                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY;
742                                                 min = MT_2_PI * conact->minrot[1] / 360.0;
743                                                 max = MT_2_PI * conact->maxrot[1] / 360.0;
744                                                 break;
745                                         case ACT_CONST_ROTZ:
746                                                 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ;
747                                                 min = MT_2_PI * conact->minrot[2] / 360.0;
748                                                 max = MT_2_PI * conact->maxrot[2] / 360.0;
749                                                 break;
750                                         default:
751                                                 ; /* error */ 
752                                         }
753                                 }
754                                 KX_ConstraintActuator *tmpconact 
755                                         = new KX_ConstraintActuator(gameobj,
756                                                 conact->damp,
757                                                 conact->rotdamp,
758                                                 min,
759                                                 max,
760                                                 conact->maxrot,
761                                                 locrot,
762                                                 conact->time,
763                                                 conact->flag,
764                                                 prop);
765                                 baseact = tmpconact;
766                                 break;
767                         }
768                 case ACT_GROUP:
769                         {
770                                 // deprecated
771                         }
772                         break;
773                 case ACT_SCENE:
774                         {
775                                 bSceneActuator *sceneact = (bSceneActuator *) bact->data;
776                                 STR_String nextSceneName("");
777                                 
778                                 KX_SceneActuator* tmpsceneact;
779                                 int mode = KX_SceneActuator::KX_SCENE_NODEF;
780                                 KX_Camera *cam = NULL;
781                                 //KX_Scene* scene = NULL;
782                                 switch (sceneact->type)
783                                 {
784                                 case ACT_SCENE_RESUME:
785                                 case ACT_SCENE_SUSPEND:
786                                 case ACT_SCENE_ADD_FRONT:
787                                 case ACT_SCENE_ADD_BACK:
788                                 case ACT_SCENE_REMOVE:
789                                 case ACT_SCENE_SET:
790                                         {
791                                                 switch (sceneact->type)
792                                                 {
793                                                 case ACT_SCENE_RESUME:
794                                                         mode = KX_SceneActuator::KX_SCENE_RESUME;
795                                                         break;
796                                                 case ACT_SCENE_SUSPEND:
797                                                         mode = KX_SceneActuator::KX_SCENE_SUSPEND;
798                                                         break;
799                                                 case ACT_SCENE_ADD_FRONT:
800                                                         mode = KX_SceneActuator::KX_SCENE_ADD_FRONT_SCENE;
801                                                         break;
802                                                 case ACT_SCENE_ADD_BACK:
803                                                         mode = KX_SceneActuator::KX_SCENE_ADD_BACK_SCENE;
804                                                         break;
805                                                 case ACT_SCENE_REMOVE:
806                                                         mode = KX_SceneActuator::KX_SCENE_REMOVE_SCENE;
807                                                         break;
808                                                 case ACT_SCENE_SET:
809                                                 default:
810                                                         mode = KX_SceneActuator::KX_SCENE_SET_SCENE;
811                                                         break;
812                                                 };
813                                                 
814                                                 if (sceneact->scene)
815                                                 {
816                                                         nextSceneName = sceneact->scene->id.name + 2; // this '2' is necessary to remove prefix 'SC'
817                                                 }
818                                                 
819                                                 break;
820                                         }
821                                 case ACT_SCENE_CAMERA:
822                                         mode = KX_SceneActuator::KX_SCENE_SET_CAMERA;
823                                         if (sceneact->camera)
824                                         {
825                                                 cam = (KX_Camera*) converter->FindGameObject(sceneact->camera);
826                                         }
827                                         break;
828                                 case ACT_SCENE_RESTART:
829                                         {
830                                                 
831                                                 mode =  KX_SceneActuator::KX_SCENE_RESTART;
832                                                 break;
833                                         }
834                                 default:
835                                         ; /* flag error */
836                                 }
837                                 tmpsceneact = new KX_SceneActuator(gameobj,
838                                                 mode,
839                                                 scene,
840                                                 ketsjiEngine,
841                                                 nextSceneName,
842                                                 cam);
843                                         baseact = tmpsceneact;
844                                 break;
845                         }
846                 case ACT_GAME:
847                         {
848                                 bGameActuator *gameact = (bGameActuator *) bact->data;
849                                 KX_GameActuator* tmpgameact;
850                                 STR_String filename = maggiename;
851                                 STR_String loadinganimationname = "";
852                                 int mode = KX_GameActuator::KX_GAME_NODEF;
853                                 switch (gameact->type)
854                                 {
855                                 case ACT_GAME_LOAD:
856                                         {
857                                                 mode = KX_GameActuator::KX_GAME_LOAD;
858                                                 filename = gameact->filename;
859                                                 loadinganimationname = gameact->loadaniname;
860                                                 break;
861                                         }
862                                 case ACT_GAME_START:
863                                         {
864                                                 mode = KX_GameActuator::KX_GAME_START;
865                                                 filename = gameact->filename;
866                                                 loadinganimationname = gameact->loadaniname;
867                                                 break;
868                                         }
869                                 case ACT_GAME_RESTART:
870                                         {
871                                                 mode = KX_GameActuator::KX_GAME_RESTART;
872                                                 break;
873                                         }
874                                 case ACT_GAME_QUIT:
875                                         {
876                                                 mode = KX_GameActuator::KX_GAME_QUIT;
877                                                 break;
878                                         }
879                                 default:
880                                         ; /* flag error */
881                                 }
882                                         tmpgameact = new KX_GameActuator(gameobj,
883                                                 mode,
884                                                 filename,
885                                                 loadinganimationname,
886                                                 scene,
887                                                 ketsjiEngine);
888                                         baseact = tmpgameact;
889
890                                 break;
891                         }
892                 case ACT_RANDOM:
893                         {
894                                 bRandomActuator *randAct 
895                                         = (bRandomActuator *) bact->data;
896                                 
897                                 unsigned long seedArg = randAct->seed;
898                                 SCA_RandomActuator::KX_RANDOMACT_MODE modeArg 
899                                         = SCA_RandomActuator::KX_RANDOMACT_NODEF;
900                                 SCA_RandomActuator *tmprandomact;
901                                 float paraArg1 = 0.0;
902                                 float paraArg2 = 0.0;
903                                 
904                                 switch  (randAct->distribution) {
905                                 case ACT_RANDOM_BOOL_CONST:
906                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST;
907                                         paraArg1 = (float) randAct->int_arg_1;
908                                         break;
909                                 case ACT_RANDOM_BOOL_UNIFORM:
910                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM;
911                                         break;
912                                 case ACT_RANDOM_BOOL_BERNOUILLI:
913                                         paraArg1 = randAct->float_arg_1;
914                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI;
915                                         break;
916                                 case ACT_RANDOM_INT_CONST:
917                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_CONST;
918                                         paraArg1 = (float) randAct->int_arg_1;
919                                         break;
920                                 case ACT_RANDOM_INT_UNIFORM:
921                                         paraArg1 = (float) randAct->int_arg_1;
922                                         paraArg2 = (float) randAct->int_arg_2;
923                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM;
924                                         break;
925                                 case ACT_RANDOM_INT_POISSON:
926                                         paraArg1 = randAct->float_arg_1;
927                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_POISSON;
928                                         break;
929                                 case ACT_RANDOM_FLOAT_CONST:
930                                         paraArg1 = randAct->float_arg_1;
931                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST;
932                                         break;
933                                 case ACT_RANDOM_FLOAT_UNIFORM:
934                                         paraArg1 = randAct->float_arg_1;
935                                         paraArg2 = randAct->float_arg_2;
936                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM;
937                                         break;
938                                 case ACT_RANDOM_FLOAT_NORMAL:
939                                         paraArg1 = randAct->float_arg_1;
940                                         paraArg2 = randAct->float_arg_2;
941                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL;
942                                         break;
943                                 case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
944                                         paraArg1 = randAct->float_arg_1;
945                                         modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL;
946                                         break;
947                                 default:
948                                         ; /* error */                           
949                                 }
950                                 tmprandomact = new SCA_RandomActuator(gameobj,
951                                         seedArg,
952                                         modeArg, 
953                                         paraArg1,
954                                         paraArg2,
955                                         randAct->propname);
956                                 baseact = tmprandomact;
957                         }
958                         break;
959
960                 case ACT_VISIBILITY:
961                 {
962                         bVisibilityActuator *vis_act = (bVisibilityActuator *) bact->data;
963                         KX_VisibilityActuator * tmp_vis_act = NULL;
964                         bool v = ((vis_act->flag & ACT_VISIBILITY_INVISIBLE) != 0);
965                         bool recursive = ((vis_act->flag & ACT_VISIBILITY_RECURSIVE) != 0);
966
967                         tmp_vis_act = new KX_VisibilityActuator(gameobj, !v, recursive);
968                         
969                         baseact = tmp_vis_act;
970                 }
971                 break;
972
973                 case ACT_STATE:
974                 {
975                         bStateActuator *sta_act = (bStateActuator *) bact->data;
976                         KX_StateActuator * tmp_sta_act = NULL;
977
978                         tmp_sta_act = 
979                                 new KX_StateActuator(gameobj, sta_act->type, sta_act->mask);
980                         
981                         baseact = tmp_sta_act;
982                 }
983                 break;
984
985                 case ACT_2DFILTER:
986                 {
987                         bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data;
988             SCA_2DFilterActuator *tmp = NULL;
989
990                         RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode;
991                         switch(_2dfilter->type)
992                         {
993                                 case ACT_2DFILTER_MOTIONBLUR:
994                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR;
995                                         break;
996                                 case ACT_2DFILTER_BLUR:
997                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_BLUR;
998                                         break;
999                                 case ACT_2DFILTER_SHARPEN:
1000                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_SHARPEN;
1001                                         break;
1002                                 case ACT_2DFILTER_DILATION:
1003                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_DILATION;
1004                                         break;
1005                                 case ACT_2DFILTER_EROSION:
1006                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_EROSION;
1007                                         break;
1008                                 case ACT_2DFILTER_LAPLACIAN:
1009                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN;
1010                                         break;
1011                                 case ACT_2DFILTER_SOBEL:
1012                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_SOBEL;
1013                                         break;
1014                                 case ACT_2DFILTER_PREWITT:
1015                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_PREWITT;
1016                                         break;
1017                                 case ACT_2DFILTER_GRAYSCALE:
1018                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE;
1019                                         break;
1020                                 case ACT_2DFILTER_SEPIA:
1021                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_SEPIA;
1022                                         break;
1023                                 case ACT_2DFILTER_INVERT:
1024                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_INVERT;
1025                                         break;
1026                                 case ACT_2DFILTER_CUSTOMFILTER:
1027                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER;
1028                                         break;
1029                                 case ACT_2DFILTER_NOFILTER:
1030                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
1031                                         break;
1032                                 case ACT_2DFILTER_DISABLED:
1033                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_DISABLED;
1034                                         break;
1035                                 case ACT_2DFILTER_ENABLED:
1036                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_ENABLED;
1037                                         break;
1038                                 default:
1039                                         filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
1040                                         break;
1041                         }
1042             
1043                         tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag,
1044                                 _2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),rendertools);
1045
1046                         if (_2dfilter->text)
1047                         {
1048                                 char *buf;
1049                                 // this is some blender specific code
1050                                 buf = txt_to_buf(_2dfilter->text);
1051                                 if (buf)
1052                                 {
1053                                         tmp->SetShaderText(STR_String(buf));
1054                                         MEM_freeN(buf);
1055                                 }
1056                         }
1057
1058             baseact = tmp;
1059                         
1060                 }
1061                 break;
1062                 case ACT_PARENT:
1063                         {
1064                                 bParentActuator *parAct = (bParentActuator *) bact->data;
1065                                 int mode = KX_ParentActuator::KX_PARENT_NODEF;
1066                                 KX_GameObject *tmpgob = NULL;
1067
1068                                 switch(parAct->type)
1069                                 {
1070                                         case ACT_PARENT_SET:
1071                                                 mode = KX_ParentActuator::KX_PARENT_SET;
1072                                                 tmpgob = converter->FindGameObject(parAct->ob);
1073                                                 break;
1074                                         case ACT_PARENT_REMOVE:
1075                                                 mode = KX_ParentActuator::KX_PARENT_REMOVE;
1076                                                 tmpgob = NULL;
1077                                                 break;
1078                                 }
1079         
1080                                 KX_ParentActuator *tmpparact
1081                                         = new KX_ParentActuator(gameobj,
1082                                         mode,
1083                                         tmpgob);
1084                                 baseact = tmpparact;
1085                                 break;
1086                         }
1087                 
1088                 default:
1089                         ; /* generate some error */
1090                 }
1091                 
1092                 if (baseact)
1093                 {
1094                         baseact->SetExecutePriority(executePriority++);
1095                         uniquename += "#ACT#";
1096                         uniqueint++;
1097                         CIntValue* uniqueval = new CIntValue(uniqueint);
1098                         uniquename += uniqueval->GetText();
1099                         uniqueval->Release();
1100                         baseact->SetName(STR_String(bact->name));
1101                         //gameobj->SetProperty(uniquename,baseact);
1102                         gameobj->AddActuator(baseact);
1103                         
1104                         converter->RegisterGameActuator(baseact, bact);
1105                         // done with baseact, release it
1106                         baseact->Release();
1107                 }
1108                 
1109                 bact = bact->next;
1110         }
1111 }
1112
1113