Blender V2.61 - r43446

KX_ConvertActuators.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  * Convert Blender actuators for use in the GameEngine
00027  */
00028 
00034 #if defined(WIN32) && !defined(FREE_WINDOWS)
00035 #pragma warning (disable : 4786) 
00036 #endif //WIN32
00037 
00038 #include <math.h>
00039 
00040 #include "MEM_guardedalloc.h"
00041 
00042 #include "KX_BlenderSceneConverter.h"
00043 #include "KX_ConvertActuators.h"
00044 
00045 #ifdef WITH_AUDASPACE
00046 #  include "AUD_C-API.h"
00047 #  include "AUD_ChannelMapperFactory.h"
00048 #endif
00049 
00050 // Actuators
00051 //SCA logiclibrary native logicbricks
00052 #include "SCA_PropertyActuator.h"
00053 #include "SCA_LogicManager.h"
00054 #include "SCA_RandomActuator.h"
00055 #include "SCA_2DFilterActuator.h"
00056 
00057 // Ketsji specific logicbricks
00058 #include "KX_SceneActuator.h"
00059 #include "KX_IpoActuator.h"
00060 #include "KX_SoundActuator.h"
00061 #include "KX_ObjectActuator.h"
00062 #include "KX_TrackToActuator.h"
00063 #include "KX_ConstraintActuator.h"
00064 #include "KX_CameraActuator.h"
00065 #include "KX_GameActuator.h"
00066 #include "KX_StateActuator.h"
00067 #include "KX_VisibilityActuator.h"
00068 #include "KX_SCA_AddObjectActuator.h"
00069 #include "KX_SCA_EndObjectActuator.h"
00070 #include "KX_SCA_ReplaceMeshActuator.h"
00071 #include "KX_ParentActuator.h"
00072 #include "KX_SCA_DynamicActuator.h"
00073 #include "KX_SteeringActuator.h"
00074 
00075 #include "KX_Scene.h"
00076 #include "KX_KetsjiEngine.h"
00077 
00078 #include "IntValue.h"
00079 #include "KX_GameObject.h"
00080 
00081 /* This little block needed for linking to Blender... */
00082 #include "BKE_text.h"
00083 #include "BLI_blenlib.h"
00084 #include "BLI_math_base.h"
00085 
00086 #define FILE_MAX 240 // repeated here to avoid dependency from BKE_utildefines.h
00087 
00088 #include "KX_NetworkMessageActuator.h"
00089 
00090 #ifdef WIN32
00091 #include "BLI_winstuff.h"
00092 #endif
00093 
00094 #include "DNA_object_types.h"
00095 #include "DNA_sound_types.h"
00096 #include "DNA_scene_types.h"
00097 #include "DNA_actuator_types.h"
00098 #include "DNA_packedFile_types.h"
00099 #include "BL_ActionActuator.h"
00100 #include "BL_ShapeActionActuator.h"
00101 #include "BL_ArmatureActuator.h"
00102 #include "RNA_access.h"
00103 #include "BL_Action.h"
00104 /* end of blender include block */
00105 
00106 #include "BL_BlenderDataConversion.h"
00107 
00112 #define KX_BLENDERTRUNC(x)  (( x < 0.0001 && x > -0.0001 )  ? 0.0 : x)
00113 
00114 void BL_ConvertActuators(const char* maggiename,
00115                          struct Object* blenderobject,
00116                          KX_GameObject* gameobj,
00117                          SCA_LogicManager* logicmgr,
00118                          KX_Scene* scene,
00119                          KX_KetsjiEngine* ketsjiEngine,
00120                          int activeLayerBitInfo,
00121                          bool isInActiveLayer,
00122                          RAS_IRenderTools* rendertools,
00123                          KX_BlenderSceneConverter* converter
00124                          )
00125 {
00126     
00127     int uniqueint = 0;
00128     int actcount = 0;
00129     int executePriority = 0;
00130     bActuator* bact = (bActuator*) blenderobject->actuators.first;
00131     while (bact)
00132     {
00133         actcount++;
00134         bact = bact->next;
00135     }
00136     gameobj->ReserveActuator(actcount);
00137     bact = (bActuator*) blenderobject->actuators.first;
00138     while(bact)
00139     {
00140         STR_String uniquename = bact->name;
00141         STR_String& objectname = gameobj->GetName();
00142         
00143         SCA_IActuator* baseact = NULL;
00144         switch (bact->type)
00145         {
00146         case ACT_OBJECT:
00147             {
00148                 bObjectActuator* obact = (bObjectActuator*) bact->data;
00149                 KX_GameObject* obref = NULL;
00150                 MT_Vector3 forcevec(KX_BLENDERTRUNC(obact->forceloc[0]),
00151                     KX_BLENDERTRUNC(obact->forceloc[1]),
00152                     KX_BLENDERTRUNC(obact->forceloc[2]));
00153                 MT_Vector3 torquevec(obact->forcerot[0],obact->forcerot[1],obact->forcerot[2]);
00154                 MT_Vector3 dlocvec ( KX_BLENDERTRUNC(obact->dloc[0]),
00155                     KX_BLENDERTRUNC(obact->dloc[1]),
00156                     KX_BLENDERTRUNC(obact->dloc[2]));
00157                 MT_Vector3 drotvec ( KX_BLENDERTRUNC(obact->drot[0]),obact->drot[1],obact->drot[2]);
00158                 MT_Vector3 linvelvec ( KX_BLENDERTRUNC(obact->linearvelocity[0]),
00159                     KX_BLENDERTRUNC(obact->linearvelocity[1]),
00160                     KX_BLENDERTRUNC(obact->linearvelocity[2]));
00161                 MT_Vector3 angvelvec ( KX_BLENDERTRUNC(obact->angularvelocity[0]),
00162                     KX_BLENDERTRUNC(obact->angularvelocity[1]),
00163                     KX_BLENDERTRUNC(obact->angularvelocity[2]));
00164                 short damping = obact->damping;
00165                 
00166                 /* Blender uses a bit vector internally for the local-flags. In */
00167                 /* KX, we have four bools. The compiler should be smart enough  */
00168                 /* to do the right thing. We need to explicitly convert here!   */
00169                 
00170                 KX_LocalFlags bitLocalFlag;
00171                 
00172                 bitLocalFlag.Force = bool((obact->flag & ACT_FORCE_LOCAL)!=0);
00173                 bitLocalFlag.Torque = bool((obact->flag & ACT_TORQUE_LOCAL) !=0);//rlocal;
00174                 bitLocalFlag.DLoc = bool((obact->flag & ACT_DLOC_LOCAL)!=0);
00175                 bitLocalFlag.DRot = bool((obact->flag & ACT_DROT_LOCAL)!=0);
00176                 bitLocalFlag.LinearVelocity = bool((obact->flag & ACT_LIN_VEL_LOCAL)!=0);
00177                 bitLocalFlag.AngularVelocity = bool((obact->flag & ACT_ANG_VEL_LOCAL)!=0);
00178                 bitLocalFlag.ServoControl = bool(obact->type == ACT_OBJECT_SERVO);
00179                 bitLocalFlag.AddOrSetLinV = bool((obact->flag & ACT_ADD_LIN_VEL)!=0);
00180                 if (obact->reference && bitLocalFlag.ServoControl)
00181                 {
00182                     obref = converter->FindGameObject(obact->reference);
00183                 }
00184                 
00185                 KX_ObjectActuator* tmpbaseact = new KX_ObjectActuator(gameobj,
00186                     obref,
00187                     forcevec.getValue(),
00188                     torquevec.getValue(),
00189                     dlocvec.getValue(),
00190                     drotvec.getValue(),
00191                     linvelvec.getValue(),
00192                     angvelvec.getValue(),
00193                     damping,
00194                     bitLocalFlag
00195                     );
00196                 baseact = tmpbaseact;
00197                 break;
00198             }
00199         case ACT_ACTION:
00200             {
00201                 bActionActuator* actact = (bActionActuator*) bact->data;
00202                 STR_String propname = (actact->name ? actact->name : "");
00203                 STR_String propframe = (actact->frameProp ? actact->frameProp : "");
00204 
00205                 short ipo_flags = 0;
00206 
00207                 // Convert flags
00208                 if (actact->flag & ACT_IPOFORCE) ipo_flags |= BL_Action::ACT_IPOFLAG_FORCE;
00209                 if (actact->flag & ACT_IPOLOCAL) ipo_flags |= BL_Action::ACT_IPOFLAG_LOCAL;
00210                 if (actact->flag & ACT_IPOADD) ipo_flags |= BL_Action::ACT_IPOFLAG_ADD;
00211                 if (actact->flag & ACT_IPOCHILD) ipo_flags |= BL_Action::ACT_IPOFLAG_CHILD;
00212                     
00213                 BL_ActionActuator* tmpbaseact = new BL_ActionActuator(
00214                     gameobj,
00215                     propname,
00216                     propframe,
00217                     actact->sta,
00218                     actact->end,
00219                     actact->act,
00220                     actact->type, // + 1, because Blender starts to count at zero,
00221                     actact->blendin,
00222                     actact->priority,
00223                     actact->layer,
00224                     actact->layer_weight,
00225                     ipo_flags,
00226                     actact->end_reset,
00227                     actact->stridelength
00228                     // Ketsji at 1, because zero is reserved for "NoDef"
00229                     );
00230                 baseact= tmpbaseact;
00231                 break;
00232             }
00233         case ACT_SHAPEACTION:
00234             {
00235                 if (blenderobject->type==OB_MESH){
00236                     bActionActuator* actact = (bActionActuator*) bact->data;
00237                     STR_String propname = (actact->name ? actact->name : "");
00238                     STR_String propframe = (actact->frameProp ? actact->frameProp : "");
00239                     
00240                     BL_ShapeActionActuator* tmpbaseact = new BL_ShapeActionActuator(
00241                         gameobj,
00242                         propname,
00243                         propframe,
00244                         actact->sta,
00245                         actact->end,
00246                         actact->act,
00247                         actact->type, // + 1, because Blender starts to count at zero,
00248                         actact->blendin,
00249                         actact->priority,
00250                         actact->stridelength
00251                         // Ketsji at 1, because zero is reserved for "NoDef"
00252                         );
00253                     baseact= tmpbaseact;
00254                     break;
00255                 }
00256                 else
00257                     printf ("Discarded shape action actuator from non-mesh object [%s]\n", blenderobject->id.name+2);
00258             }
00259         case ACT_IPO:
00260             {
00261                 bIpoActuator* ipoact = (bIpoActuator*) bact->data;
00262                 bool ipochild = (ipoact->flag & ACT_IPOCHILD) !=0;
00263                 STR_String propname = ipoact->name;
00264                 STR_String frameProp = ipoact->frameProp;
00265                 // first bit?
00266                 bool ipo_as_force = (ipoact->flag & ACT_IPOFORCE);
00267                 bool local = (ipoact->flag & ACT_IPOLOCAL);
00268                 bool ipo_add = (ipoact->flag & ACT_IPOADD);
00269                 
00270                 KX_IpoActuator* tmpbaseact = new KX_IpoActuator(
00271                     gameobj,
00272                     propname ,
00273                     frameProp,
00274                     ipoact->sta,
00275                     ipoact->end,
00276                     ipochild,
00277                     ipoact->type + 1, // + 1, because Blender starts to count at zero,
00278                     // Ketsji at 1, because zero is reserved for "NoDef"
00279                     ipo_as_force,
00280                     ipo_add,
00281                     local);
00282                 baseact = tmpbaseact;
00283                 break;
00284             }
00285         case ACT_LAMP:
00286             {
00287                 break;
00288             }
00289         case ACT_CAMERA:
00290             {
00291                 bCameraActuator *camact = (bCameraActuator *) bact->data;
00292                 if (camact->ob) {
00293                     KX_GameObject *tmpgob = converter->FindGameObject(camact->ob);
00294                     
00295                     /* visifac, fac and axis are not copied from the struct...   */ 
00296                     /* that's some internal state...                             */
00297                     KX_CameraActuator *tmpcamact
00298                         = new KX_CameraActuator(gameobj,
00299                         tmpgob,
00300                         camact->height,
00301                         camact->min,
00302                         camact->max,
00303                         camact->axis,
00304                         camact->damping);
00305                     baseact = tmpcamact;
00306                 }
00307                 break;
00308             }
00309         case ACT_MESSAGE:
00310             {
00311                 bMessageActuator *msgAct = (bMessageActuator *) bact->data;
00312                 
00317                 STR_String toPropName = (msgAct->toPropName
00318                     ? (char*) msgAct->toPropName
00319                     : "");
00320                 
00324                 STR_String subject = (msgAct->subject
00325                     ? (char*) msgAct->subject
00326                     : "");
00327                 
00331                 int bodyType = msgAct->bodyType;
00332                 
00337                 STR_String body = (msgAct->body
00338                     ? (char*) msgAct->body
00339                     : "");
00340                 
00341                 KX_NetworkMessageActuator *tmpmsgact = 
00342                     new KX_NetworkMessageActuator(
00343                     gameobj,                    // actuator controlling object
00344                     scene->GetNetworkScene(),   // needed for replication
00345                     toPropName,
00346                     subject,
00347                     bodyType,
00348                     body);
00349                 baseact = tmpmsgact;
00350                 break;
00351             }
00352         case ACT_MATERIAL:
00353             {
00354                 break;
00355             }
00356         case ACT_SOUND:
00357             {
00358                 bSoundActuator* soundact = (bSoundActuator*) bact->data;
00359                 /* get type, and possibly a start and end frame */
00360                 KX_SoundActuator::KX_SOUNDACT_TYPE
00361                     soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
00362                 
00363                 switch(soundact->type) {
00364                 case ACT_SND_PLAY_STOP_SOUND:
00365                     soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYSTOP;
00366                     break;
00367                 case ACT_SND_PLAY_END_SOUND:
00368                     soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYEND;
00369                     break;
00370                 case ACT_SND_LOOP_STOP_SOUND:
00371                     soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPSTOP;
00372                     break;
00373                 case ACT_SND_LOOP_END_SOUND:
00374                     soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPEND;
00375                     break;
00376                 case ACT_SND_LOOP_BIDIRECTIONAL_SOUND:
00377                     soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL;
00378                     break;
00379                 case ACT_SND_LOOP_BIDIRECTIONAL_STOP_SOUND:
00380                     soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP;
00381                     break;
00382                     
00383                 default:
00384                     /* This is an error!!! */
00385                     soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
00386                 }
00387                 
00388                 if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF) 
00389                 {
00390                     bSound* sound = soundact->sound;
00391                     bool is3d = soundact->flag & ACT_SND_3D_SOUND ? true : false;
00392                     AUD_Reference<AUD_IFactory> snd_sound;
00393                     KX_3DSoundSettings settings;
00394                     settings.cone_inner_angle = soundact->sound3D.cone_inner_angle;
00395                     settings.cone_outer_angle = soundact->sound3D.cone_outer_angle;
00396                     settings.cone_outer_gain = soundact->sound3D.cone_outer_gain;
00397                     settings.max_distance = soundact->sound3D.max_distance;
00398                     settings.max_gain = soundact->sound3D.max_gain;
00399                     settings.min_gain = soundact->sound3D.min_gain;
00400                     settings.reference_distance = soundact->sound3D.reference_distance;
00401                     settings.rolloff_factor = soundact->sound3D.rolloff_factor;
00402 
00403                     if(!sound)
00404                     {
00405                         std::cout <<    "WARNING: Sound actuator \"" << bact->name <<
00406                                         "\" from object \"" <<  blenderobject->id.name+2 <<
00407                                         "\" has no sound datablock." << std::endl;
00408                     }
00409                     else
00410                     {
00411                         snd_sound = *reinterpret_cast<AUD_Reference<AUD_IFactory>*>(sound->playback_handle);
00412 
00413                         // if sound shall be 3D but isn't mono, we have to make it mono!
00414                         if(is3d)
00415                         {
00416                             try
00417                             {
00418                                 AUD_Reference<AUD_IReader> reader = snd_sound->createReader();
00419                                 if(reader->getSpecs().channels != AUD_CHANNELS_MONO)
00420                                 {
00421                                     AUD_DeviceSpecs specs;
00422                                     specs.channels = AUD_CHANNELS_MONO;
00423                                     specs.rate = AUD_RATE_INVALID;
00424                                     specs.format = AUD_FORMAT_INVALID;
00425                                     snd_sound = new AUD_ChannelMapperFactory(snd_sound, specs);
00426                                 }
00427                             }
00428                             catch(AUD_Exception&)
00429                             {
00430                                 // sound cannot be played... ignore
00431                             }
00432                         }
00433                     }
00434                     KX_SoundActuator* tmpsoundact =
00435                         new KX_SoundActuator(gameobj,
00436                         snd_sound,
00437                         soundact->volume,
00438                         (float)(exp((soundact->pitch / 12.0) * M_LN2)),
00439                         is3d,
00440                         settings,
00441                         soundActuatorType);
00442 
00443                     tmpsoundact->SetName(bact->name);
00444                     baseact = tmpsoundact;
00445                 }
00446                 break;
00447             }
00448         case ACT_PROPERTY:
00449             {
00450                 bPropertyActuator* propact = (bPropertyActuator*) bact->data;
00451                 SCA_IObject* destinationObj = NULL;
00452                 
00453                 /*
00454                 here the destinationobject is searched. problem with multiple scenes: other scenes
00455                 have not been converted yet, so the destobj will not be found, so the prop will
00456                 not be copied.
00457                 possible solutions:
00458                 - convert everything when possible and not realtime only when needed.
00459                 - let the object-with-property report itself to the act when converted
00460                 */
00461                 if (propact->ob)
00462                     destinationObj = converter->FindGameObject(propact->ob);
00463                 
00464                 SCA_PropertyActuator* tmppropact = new SCA_PropertyActuator(
00465                     gameobj,
00466                     destinationObj,
00467                     propact->name,
00468                     propact->value,
00469                     propact->type+1); // + 1 because Ketsji Logic starts
00470                 // with 0 for KX_ACT_PROP_NODEF
00471                 baseact = tmppropact;
00472                 break;
00473             }
00474         case ACT_EDIT_OBJECT:
00475             {
00476                 bEditObjectActuator *editobact 
00477                     = (bEditObjectActuator *) bact->data;
00478                 /* There are four different kinds of 'edit object' thingies  */
00479                 /* The alternative to this lengthy conversion is packing     */
00480                 /* several actuators in one, which is not very nice design.. */
00481                 switch (editobact->type) {
00482                 case ACT_EDOB_ADD_OBJECT: 
00483                     {
00484                         
00485                         // does the 'original' for replication exists, and 
00486                         // is it in a non-active layer ?
00487                         SCA_IObject* originalval = NULL;
00488                         if (editobact->ob)
00489                         {
00490                             if (editobact->ob->lay & activeLayerBitInfo)
00491                             {
00492                                 fprintf(stderr, "Warning, object \"%s\" from AddObject actuator \"%s\" is not in a hidden layer.\n", objectname.Ptr(), uniquename.Ptr());
00493                             }
00494                             else {
00495                                 originalval = converter->FindGameObject(editobact->ob);
00496                             }
00497                         }
00498                         
00499                         KX_SCA_AddObjectActuator* tmpaddact = 
00500                             new KX_SCA_AddObjectActuator(
00501                                 gameobj, 
00502                                 originalval,
00503                                 editobact->time,
00504                                 scene,
00505                                 editobact->linVelocity,
00506                                 (editobact->localflag & ACT_EDOB_LOCAL_LINV)!=0,
00507                                 editobact->angVelocity,
00508                                 (editobact->localflag & ACT_EDOB_LOCAL_ANGV)!=0
00509                                 );
00510                                 
00511                                 //editobact->ob to gameobj
00512                                 baseact = tmpaddact;
00513                     }
00514                     break;
00515                 case ACT_EDOB_END_OBJECT:
00516                     {
00517                         KX_SCA_EndObjectActuator* tmpendact 
00518                             = new KX_SCA_EndObjectActuator(gameobj,scene);
00519                         baseact = tmpendact;
00520                     }
00521                     break;
00522                 case ACT_EDOB_REPLACE_MESH:
00523                     {
00524                         RAS_MeshObject *tmpmesh = NULL;
00525                         if (editobact->me)
00526                             tmpmesh = BL_ConvertMesh(
00527                                 editobact->me,
00528                                 blenderobject,
00529                                 scene,
00530                                 converter
00531                                 );
00532 
00533                         KX_SCA_ReplaceMeshActuator* tmpreplaceact
00534                             = new KX_SCA_ReplaceMeshActuator(
00535                                 gameobj,
00536                                 tmpmesh,
00537                                 scene,
00538                                 (editobact->flag & ACT_EDOB_REPLACE_MESH_NOGFX)==0,
00539                                 (editobact->flag & ACT_EDOB_REPLACE_MESH_PHYS)!=0
00540                                 
00541                                 );
00542                             
00543                             baseact = tmpreplaceact;
00544                     }
00545                     break;
00546                 case ACT_EDOB_TRACK_TO:
00547                     {
00548                         SCA_IObject* originalval = NULL;
00549                         if (editobact->ob)
00550                             originalval = converter->FindGameObject(editobact->ob);
00551                             
00552                         KX_TrackToActuator* tmptrackact 
00553                             = new KX_TrackToActuator(gameobj, 
00554                                 originalval,
00555                                 editobact->time,
00556                                 editobact->flag,
00557                                 blenderobject->trackflag,
00558                                 blenderobject->upflag
00559                                 );
00560                             baseact = tmptrackact;
00561                         break;
00562                     }
00563                 case ACT_EDOB_DYNAMICS:
00564                     {
00565                         KX_SCA_DynamicActuator* tmpdynact 
00566                             = new KX_SCA_DynamicActuator(gameobj, 
00567                                 editobact->dyn_operation,
00568                                 editobact->mass
00569                                 );
00570                             baseact = tmpdynact;
00571                     }
00572                 }
00573                 break;
00574             }
00575         case ACT_CONSTRAINT:
00576             {
00577                 float min = 0.0, max = 0.0;
00578                 char *prop = NULL;
00579                 KX_ConstraintActuator::KX_CONSTRAINTTYPE locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF;
00580                 bConstraintActuator *conact 
00581                     = (bConstraintActuator*) bact->data;
00582                 /* convert settings... degrees in the ui become radians  */ 
00583                 /* internally                                            */ 
00584                 if (conact->type == ACT_CONST_TYPE_ORI) {
00585                     min = (float)((MT_2_PI * conact->minloc[0])/360.0);
00586                     max = (float)((MT_2_PI * conact->maxloc[0])/360.0);
00587                     switch (conact->mode) {
00588                     case ACT_CONST_DIRPX:
00589                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX;
00590                         break;
00591                     case ACT_CONST_DIRPY:
00592                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY;
00593                         break;
00594                     case ACT_CONST_DIRPZ:
00595                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ;
00596                         break;
00597                     }
00598                 } else if (conact->type == ACT_CONST_TYPE_DIST) {
00599                     switch (conact->mode) {
00600                     case ACT_CONST_DIRPX:
00601                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX;
00602                         min = conact->minloc[0];
00603                         max = conact->maxloc[0];
00604                         break;
00605                     case ACT_CONST_DIRPY:
00606                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY;
00607                         min = conact->minloc[1];
00608                         max = conact->maxloc[1];
00609                         break;
00610                     case ACT_CONST_DIRPZ:
00611                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ;
00612                         min = conact->minloc[2];
00613                         max = conact->maxloc[2];
00614                         break;
00615                     case ACT_CONST_DIRNX:
00616                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX;
00617                         min = conact->minloc[0];
00618                         max = conact->maxloc[0];
00619                         break;
00620                     case ACT_CONST_DIRNY:
00621                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY;
00622                         min = conact->minloc[1];
00623                         max = conact->maxloc[1];
00624                         break;
00625                     case ACT_CONST_DIRNZ:
00626                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ;
00627                         min = conact->minloc[2];
00628                         max = conact->maxloc[2];
00629                         break;
00630                     }
00631                     prop = conact->matprop;
00632                 } else if (conact->type == ACT_CONST_TYPE_FH) {
00633                     switch (conact->mode) {
00634                     case ACT_CONST_DIRPX:
00635                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX;
00636                         min = conact->minloc[0];
00637                         max = conact->maxloc[0];
00638                         break;
00639                     case ACT_CONST_DIRPY:
00640                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY;
00641                         min = conact->minloc[1];
00642                         max = conact->maxloc[1];
00643                         break;
00644                     case ACT_CONST_DIRPZ:
00645                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ;
00646                         min = conact->minloc[2];
00647                         max = conact->maxloc[2];
00648                         break;
00649                     case ACT_CONST_DIRNX:
00650                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX;
00651                         min = conact->minloc[0];
00652                         max = conact->maxloc[0];
00653                         break;
00654                     case ACT_CONST_DIRNY:
00655                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY;
00656                         min = conact->minloc[1];
00657                         max = conact->maxloc[1];
00658                         break;
00659                     case ACT_CONST_DIRNZ:
00660                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ;
00661                         min = conact->minloc[2];
00662                         max = conact->maxloc[2];
00663                         break;
00664                     }
00665                     prop = conact->matprop;
00666                 } else {
00667                     switch (conact->flag) {
00668                     case ACT_CONST_LOCX:
00669                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX; 
00670                         min = conact->minloc[0];
00671                         max = conact->maxloc[0];
00672                         break;
00673                     case ACT_CONST_LOCY:
00674                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY; 
00675                         min = conact->minloc[1];
00676                         max = conact->maxloc[1];
00677                         break;
00678                     case ACT_CONST_LOCZ:
00679                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ;
00680                         min = conact->minloc[2];
00681                         max = conact->maxloc[2];
00682                         break;
00683                     case ACT_CONST_ROTX:
00684                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX;
00685                         min = conact->minrot[0] * (float)MT_RADS_PER_DEG;
00686                         max = conact->maxrot[0] * (float)MT_RADS_PER_DEG;
00687                         break;
00688                     case ACT_CONST_ROTY:
00689                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY;
00690                         min = conact->minrot[1] * (float)MT_RADS_PER_DEG;
00691                         max = conact->maxrot[1] * (float)MT_RADS_PER_DEG;
00692                         break;
00693                     case ACT_CONST_ROTZ:
00694                         locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ;
00695                         min = conact->minrot[2] * (float)MT_RADS_PER_DEG;
00696                         max = conact->maxrot[2] * (float)MT_RADS_PER_DEG;
00697                         break;
00698                     default:
00699                         ; /* error */ 
00700                     }
00701                 }
00702                 KX_ConstraintActuator *tmpconact 
00703                     = new KX_ConstraintActuator(gameobj,
00704                         conact->damp,
00705                         conact->rotdamp,
00706                         min,
00707                         max,
00708                         conact->maxrot,
00709                         locrot,
00710                         conact->time,
00711                         conact->flag,
00712                         prop);
00713                 baseact = tmpconact;
00714                 break;
00715             }
00716         case ACT_GROUP:
00717             {
00718                 // deprecated
00719             }
00720             break;
00721         case ACT_SCENE:
00722             {
00723                 bSceneActuator *sceneact = (bSceneActuator *) bact->data;
00724                 STR_String nextSceneName("");
00725                 
00726                 KX_SceneActuator* tmpsceneact;
00727                 int mode = KX_SceneActuator::KX_SCENE_NODEF;
00728                 KX_Camera *cam = NULL;
00729                 //KX_Scene* scene = NULL;
00730                 switch (sceneact->type)
00731                 {
00732                 case ACT_SCENE_RESUME:
00733                 case ACT_SCENE_SUSPEND:
00734                 case ACT_SCENE_ADD_FRONT:
00735                 case ACT_SCENE_ADD_BACK:
00736                 case ACT_SCENE_REMOVE:
00737                 case ACT_SCENE_SET:
00738                     {
00739                         switch (sceneact->type)
00740                         {
00741                         case ACT_SCENE_RESUME:
00742                             mode = KX_SceneActuator::KX_SCENE_RESUME;
00743                             break;
00744                         case ACT_SCENE_SUSPEND:
00745                             mode = KX_SceneActuator::KX_SCENE_SUSPEND;
00746                             break;
00747                         case ACT_SCENE_ADD_FRONT:
00748                             mode = KX_SceneActuator::KX_SCENE_ADD_FRONT_SCENE;
00749                             break;
00750                         case ACT_SCENE_ADD_BACK:
00751                             mode = KX_SceneActuator::KX_SCENE_ADD_BACK_SCENE;
00752                             break;
00753                         case ACT_SCENE_REMOVE:
00754                             mode = KX_SceneActuator::KX_SCENE_REMOVE_SCENE;
00755                             break;
00756                         case ACT_SCENE_SET:
00757                         default:
00758                             mode = KX_SceneActuator::KX_SCENE_SET_SCENE;
00759                             break;
00760                         };
00761                         
00762                         if (sceneact->scene)
00763                         {
00764                             nextSceneName = sceneact->scene->id.name + 2; // this '2' is necessary to remove prefix 'SC'
00765                         }
00766                         
00767                         break;
00768                     }
00769                 case ACT_SCENE_CAMERA:
00770                     mode = KX_SceneActuator::KX_SCENE_SET_CAMERA;
00771                     if (sceneact->camera)
00772                     {
00773                         cam = (KX_Camera*) converter->FindGameObject(sceneact->camera);
00774                     }
00775                     break;
00776                 case ACT_SCENE_RESTART:
00777                     {
00778                         
00779                         mode =  KX_SceneActuator::KX_SCENE_RESTART;
00780                         break;
00781                     }
00782                 default:
00783                     ; /* flag error */
00784                 }
00785                 tmpsceneact = new KX_SceneActuator(gameobj,
00786                         mode,
00787                         scene,
00788                         ketsjiEngine,
00789                         nextSceneName,
00790                         cam);
00791                     baseact = tmpsceneact;
00792                 break;
00793             }
00794         case ACT_GAME:
00795             {
00796                 bGameActuator *gameact = (bGameActuator *) bact->data;
00797                 KX_GameActuator* tmpgameact;
00798                 STR_String filename = maggiename;
00799                 STR_String loadinganimationname = "";
00800                 int mode = KX_GameActuator::KX_GAME_NODEF;
00801                 switch (gameact->type)
00802                 {
00803                 case ACT_GAME_LOAD:
00804                     {
00805                         mode = KX_GameActuator::KX_GAME_LOAD;
00806                         filename = gameact->filename;
00807                         loadinganimationname = gameact->loadaniname;
00808                         break;
00809                     }
00810                 case ACT_GAME_START:
00811                     {
00812                         mode = KX_GameActuator::KX_GAME_START;
00813                         filename = gameact->filename;
00814                         loadinganimationname = gameact->loadaniname;
00815                         break;
00816                     }
00817                 case ACT_GAME_RESTART:
00818                     {
00819                         mode = KX_GameActuator::KX_GAME_RESTART;
00820                         break;
00821                     }
00822                 case ACT_GAME_QUIT:
00823                     {
00824                         mode = KX_GameActuator::KX_GAME_QUIT;
00825                         break;
00826                     }
00827                 case ACT_GAME_SAVECFG:
00828                     {
00829                         mode = KX_GameActuator::KX_GAME_SAVECFG;
00830                         break;
00831                     }
00832                 case ACT_GAME_LOADCFG:
00833                     {
00834                         mode = KX_GameActuator::KX_GAME_LOADCFG;
00835                         break;
00836                     }
00837                 default:
00838                     ; /* flag error */
00839                 }
00840                     tmpgameact = new KX_GameActuator(gameobj,
00841                         mode,
00842                         filename,
00843                         loadinganimationname,
00844                         scene,
00845                         ketsjiEngine);
00846                     baseact = tmpgameact;
00847 
00848                 break;
00849             }
00850         case ACT_RANDOM:
00851             {
00852                 bRandomActuator *randAct 
00853                     = (bRandomActuator *) bact->data;
00854                 
00855                 unsigned long seedArg = randAct->seed;
00856                 if (seedArg == 0)
00857                 {
00858                     seedArg = (int)(ketsjiEngine->GetRealTime()*100000.0);
00859                     seedArg ^= (intptr_t)randAct;
00860                 }
00861                 SCA_RandomActuator::KX_RANDOMACT_MODE modeArg 
00862                     = SCA_RandomActuator::KX_RANDOMACT_NODEF;
00863                 SCA_RandomActuator *tmprandomact;
00864                 float paraArg1 = 0.0;
00865                 float paraArg2 = 0.0;
00866                 
00867                 switch  (randAct->distribution) {
00868                 case ACT_RANDOM_BOOL_CONST:
00869                     modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST;
00870                     paraArg1 = (float) randAct->int_arg_1;
00871                     break;
00872                 case ACT_RANDOM_BOOL_UNIFORM:
00873                     modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM;
00874                     break;
00875                 case ACT_RANDOM_BOOL_BERNOUILLI:
00876                     paraArg1 = randAct->float_arg_1;
00877                     modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI;
00878                     break;
00879                 case ACT_RANDOM_INT_CONST:
00880                     modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_CONST;
00881                     paraArg1 = (float) randAct->int_arg_1;
00882                     break;
00883                 case ACT_RANDOM_INT_UNIFORM:
00884                     paraArg1 = (float) randAct->int_arg_1;
00885                     paraArg2 = (float) randAct->int_arg_2;
00886                     modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM;
00887                     break;
00888                 case ACT_RANDOM_INT_POISSON:
00889                     paraArg1 = randAct->float_arg_1;
00890                     modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_POISSON;
00891                     break;
00892                 case ACT_RANDOM_FLOAT_CONST:
00893                     paraArg1 = randAct->float_arg_1;
00894                     modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST;
00895                     break;
00896                 case ACT_RANDOM_FLOAT_UNIFORM:
00897                     paraArg1 = randAct->float_arg_1;
00898                     paraArg2 = randAct->float_arg_2;
00899                     modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM;
00900                     break;
00901                 case ACT_RANDOM_FLOAT_NORMAL:
00902                     paraArg1 = randAct->float_arg_1;
00903                     paraArg2 = randAct->float_arg_2;
00904                     modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL;
00905                     break;
00906                 case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
00907                     paraArg1 = randAct->float_arg_1;
00908                     modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL;
00909                     break;
00910                 default:
00911                     ; /* error */               
00912                 }
00913                 tmprandomact = new SCA_RandomActuator(gameobj,
00914                     seedArg,
00915                     modeArg, 
00916                     paraArg1,
00917                     paraArg2,
00918                     randAct->propname);
00919                 baseact = tmprandomact;
00920             }
00921             break;
00922 
00923         case ACT_VISIBILITY:
00924         {
00925             bVisibilityActuator *vis_act = (bVisibilityActuator *) bact->data;
00926             KX_VisibilityActuator * tmp_vis_act = NULL;
00927             bool v = ((vis_act->flag & ACT_VISIBILITY_INVISIBLE) != 0);
00928             bool o = ((vis_act->flag & ACT_VISIBILITY_OCCLUSION) != 0);
00929             bool recursive = ((vis_act->flag & ACT_VISIBILITY_RECURSIVE) != 0);
00930 
00931             tmp_vis_act = new KX_VisibilityActuator(gameobj, !v, o, recursive);
00932             
00933             baseact = tmp_vis_act;
00934         }
00935         break;
00936 
00937         case ACT_STATE:
00938         {
00939             bStateActuator *sta_act = (bStateActuator *) bact->data;
00940             KX_StateActuator * tmp_sta_act = NULL;
00941 
00942             tmp_sta_act = 
00943                 new KX_StateActuator(gameobj, sta_act->type, sta_act->mask);
00944             
00945             baseact = tmp_sta_act;
00946         }
00947         break;
00948 
00949         case ACT_2DFILTER:
00950         {
00951             bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data;
00952             SCA_2DFilterActuator *tmp = NULL;
00953 
00954             RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode;
00955             switch(_2dfilter->type)
00956             {
00957                 case ACT_2DFILTER_MOTIONBLUR:
00958                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR;
00959                     break;
00960                 case ACT_2DFILTER_BLUR:
00961                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_BLUR;
00962                     break;
00963                 case ACT_2DFILTER_SHARPEN:
00964                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_SHARPEN;
00965                     break;
00966                 case ACT_2DFILTER_DILATION:
00967                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_DILATION;
00968                     break;
00969                 case ACT_2DFILTER_EROSION:
00970                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_EROSION;
00971                     break;
00972                 case ACT_2DFILTER_LAPLACIAN:
00973                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN;
00974                     break;
00975                 case ACT_2DFILTER_SOBEL:
00976                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_SOBEL;
00977                     break;
00978                 case ACT_2DFILTER_PREWITT:
00979                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_PREWITT;
00980                     break;
00981                 case ACT_2DFILTER_GRAYSCALE:
00982                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE;
00983                     break;
00984                 case ACT_2DFILTER_SEPIA:
00985                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_SEPIA;
00986                     break;
00987                 case ACT_2DFILTER_INVERT:
00988                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_INVERT;
00989                     break;
00990                 case ACT_2DFILTER_CUSTOMFILTER:
00991                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER;
00992                     break;
00993                 case ACT_2DFILTER_NOFILTER:
00994                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
00995                     break;
00996                 case ACT_2DFILTER_DISABLED:
00997                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_DISABLED;
00998                     break;
00999                 case ACT_2DFILTER_ENABLED:
01000                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_ENABLED;
01001                     break;
01002                 default:
01003                     filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
01004                     break;
01005             }
01006 
01007             tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag,
01008                 _2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),scene);
01009 
01010             if (_2dfilter->text)
01011             {
01012                 char *buf;
01013                 // this is some blender specific code
01014                 buf = txt_to_buf(_2dfilter->text);
01015                 if (buf)
01016                 {
01017                     tmp->SetShaderText(buf);
01018                     MEM_freeN(buf);
01019                 }
01020             }
01021 
01022             baseact = tmp;
01023 
01024         }
01025         break;
01026         case ACT_PARENT:
01027             {
01028                 bParentActuator *parAct = (bParentActuator *) bact->data;
01029                 int mode = KX_ParentActuator::KX_PARENT_NODEF;
01030                 bool addToCompound = true;
01031                 bool ghost = true;
01032                 KX_GameObject *tmpgob = NULL;
01033 
01034                 switch(parAct->type)
01035                 {
01036                     case ACT_PARENT_SET:
01037                         mode = KX_ParentActuator::KX_PARENT_SET;
01038                         tmpgob = converter->FindGameObject(parAct->ob);
01039                         addToCompound = !(parAct->flag & ACT_PARENT_COMPOUND);
01040                         ghost = !(parAct->flag & ACT_PARENT_GHOST);
01041                         break;
01042                     case ACT_PARENT_REMOVE:
01043                         mode = KX_ParentActuator::KX_PARENT_REMOVE;
01044                         tmpgob = NULL;
01045                         break;
01046                 }
01047     
01048                 KX_ParentActuator *tmpparact
01049                     = new KX_ParentActuator(gameobj,
01050                     mode,
01051                     addToCompound,
01052                     ghost,
01053                     tmpgob);
01054                 baseact = tmpparact;
01055                 break;
01056             }
01057         
01058         case ACT_ARMATURE:
01059             {
01060                 bArmatureActuator* armAct = (bArmatureActuator*) bact->data;
01061                 KX_GameObject *tmpgob = converter->FindGameObject(armAct->target);
01062                 KX_GameObject *subgob = converter->FindGameObject(armAct->subtarget);
01063                 BL_ArmatureActuator* tmparmact = new BL_ArmatureActuator(gameobj, armAct->type, armAct->posechannel, armAct->constraint, tmpgob, subgob, armAct->weight);
01064                 baseact = tmparmact;
01065                 break;
01066             }
01067         case ACT_STEERING:
01068             {
01069                 bSteeringActuator *stAct = (bSteeringActuator *) bact->data;
01070                 KX_GameObject *navmeshob = NULL;
01071                 if (stAct->navmesh)
01072                 {
01073                     PointerRNA settings_ptr;
01074                     RNA_pointer_create((ID *)stAct->navmesh, &RNA_GameObjectSettings, stAct->navmesh, &settings_ptr);
01075                     if (RNA_enum_get(&settings_ptr, "physics_type") == OB_BODY_TYPE_NAVMESH)
01076                         navmeshob = converter->FindGameObject(stAct->navmesh);
01077                 }
01078                 KX_GameObject *targetob = converter->FindGameObject(stAct->target);
01079 
01080                 int mode = KX_SteeringActuator::KX_STEERING_NODEF;
01081                 switch(stAct->type)
01082                 {
01083                 case ACT_STEERING_SEEK:
01084                     mode = KX_SteeringActuator::KX_STEERING_SEEK;
01085                     break;
01086                 case ACT_STEERING_FLEE:
01087                     mode = KX_SteeringActuator::KX_STEERING_FLEE;
01088                     break;
01089                 case ACT_STEERING_PATHFOLLOWING:
01090                     mode = KX_SteeringActuator::KX_STEERING_PATHFOLLOWING;
01091                     break;
01092                 }
01093 
01094                 bool selfTerminated = (stAct->flag & ACT_STEERING_SELFTERMINATED) !=0;
01095                 bool enableVisualization = (stAct->flag & ACT_STEERING_ENABLEVISUALIZATION) !=0;
01096                 short facingMode = (stAct->flag & ACT_STEERING_AUTOMATICFACING) ? stAct->facingaxis : 0;
01097                 bool normalup = (stAct->flag & ACT_STEERING_NORMALUP) !=0;
01098                 KX_SteeringActuator *tmpstact
01099                     = new KX_SteeringActuator(gameobj, mode, targetob, navmeshob,stAct->dist, 
01100                     stAct->velocity, stAct->acceleration, stAct->turnspeed, 
01101                     selfTerminated, stAct->updateTime,
01102                     scene->GetObstacleSimulation(), facingMode, normalup, enableVisualization);
01103                 baseact = tmpstact;
01104                 break;
01105             }
01106         default:
01107             ; /* generate some error */
01108         }
01109         
01110         if (baseact)
01111         {
01112             baseact->SetExecutePriority(executePriority++);
01113             uniquename += "#ACT#";
01114             uniqueint++;
01115             CIntValue* uniqueval = new CIntValue(uniqueint);
01116             uniquename += uniqueval->GetText();
01117             uniqueval->Release();
01118             baseact->SetName(bact->name);
01119             //gameobj->SetProperty(uniquename,baseact);
01120             gameobj->AddActuator(baseact);
01121             
01122             converter->RegisterGameActuator(baseact, bact);
01123             // done with baseact, release it
01124             baseact->Release();
01125         }
01126         
01127         bact = bact->next;
01128     }
01129 }
01130 
01131