2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
26 * Convert Blender actuators for use in the GameEngine
29 /** \file gameengine/Converter/KX_ConvertActuators.cpp
34 #if defined(WIN32) && !defined(FREE_WINDOWS)
35 #pragma warning (disable : 4786)
40 #include "MEM_guardedalloc.h"
42 #include "KX_BlenderSceneConverter.h"
43 #include "KX_ConvertActuators.h"
46 # include "AUD_C-API.h"
47 # include "AUD_ChannelMapperFactory.h"
51 //SCA logiclibrary native logicbricks
52 #include "SCA_PropertyActuator.h"
53 #include "SCA_LogicManager.h"
54 #include "SCA_RandomActuator.h"
55 #include "SCA_2DFilterActuator.h"
57 // Ketsji specific logicbricks
58 #include "KX_SceneActuator.h"
59 #include "KX_IpoActuator.h"
60 #include "KX_SoundActuator.h"
61 #include "KX_ObjectActuator.h"
62 #include "KX_TrackToActuator.h"
63 #include "KX_ConstraintActuator.h"
64 #include "KX_CameraActuator.h"
65 #include "KX_GameActuator.h"
66 #include "KX_StateActuator.h"
67 #include "KX_VisibilityActuator.h"
68 #include "KX_SCA_AddObjectActuator.h"
69 #include "KX_SCA_EndObjectActuator.h"
70 #include "KX_SCA_ReplaceMeshActuator.h"
71 #include "KX_ParentActuator.h"
72 #include "KX_SCA_DynamicActuator.h"
73 #include "KX_SteeringActuator.h"
76 #include "KX_KetsjiEngine.h"
79 #include "KX_GameObject.h"
81 /* This little block needed for linking to Blender... */
83 #include "BLI_blenlib.h"
84 #include "BLI_math_base.h"
86 #define FILE_MAX 240 // repeated here to avoid dependency from BKE_utildefines.h
88 #include "KX_NetworkMessageActuator.h"
91 #include "BLI_winstuff.h"
94 #include "DNA_object_types.h"
95 #include "DNA_sound_types.h"
96 #include "DNA_scene_types.h"
97 #include "DNA_actuator_types.h"
98 #include "DNA_packedFile_types.h"
99 #include "BL_ActionActuator.h"
100 #include "BL_ShapeActionActuator.h"
101 #include "BL_ArmatureActuator.h"
102 #include "RNA_access.h"
103 #include "BL_Action.h"
104 /* end of blender include block */
106 #include "BL_BlenderDataConversion.h"
109 KX_BLENDERTRUNC needed to round 'almost' zero values to zero, else velocities etc. are incorrectly set
112 #define KX_BLENDERTRUNC(x) (( x < 0.0001 && x > -0.0001 ) ? 0.0 : x)
114 void BL_ConvertActuators(const char* maggiename,
115 struct Object* blenderobject,
116 KX_GameObject* gameobj,
117 SCA_LogicManager* logicmgr,
119 KX_KetsjiEngine* ketsjiEngine,
120 int activeLayerBitInfo,
121 bool isInActiveLayer,
122 RAS_IRenderTools* rendertools,
123 KX_BlenderSceneConverter* converter
129 int executePriority = 0;
130 bActuator* bact = (bActuator*) blenderobject->actuators.first;
136 gameobj->ReserveActuator(actcount);
137 bact = (bActuator*) blenderobject->actuators.first;
140 STR_String uniquename = bact->name;
141 STR_String& objectname = gameobj->GetName();
143 SCA_IActuator* baseact = NULL;
148 bObjectActuator* obact = (bObjectActuator*) bact->data;
149 KX_GameObject* obref = NULL;
150 MT_Vector3 forcevec(KX_BLENDERTRUNC(obact->forceloc[0]),
151 KX_BLENDERTRUNC(obact->forceloc[1]),
152 KX_BLENDERTRUNC(obact->forceloc[2]));
153 MT_Vector3 torquevec(obact->forcerot[0],obact->forcerot[1],obact->forcerot[2]);
154 MT_Vector3 dlocvec ( KX_BLENDERTRUNC(obact->dloc[0]),
155 KX_BLENDERTRUNC(obact->dloc[1]),
156 KX_BLENDERTRUNC(obact->dloc[2]));
157 MT_Vector3 drotvec ( KX_BLENDERTRUNC(obact->drot[0]),obact->drot[1],obact->drot[2]);
158 MT_Vector3 linvelvec ( KX_BLENDERTRUNC(obact->linearvelocity[0]),
159 KX_BLENDERTRUNC(obact->linearvelocity[1]),
160 KX_BLENDERTRUNC(obact->linearvelocity[2]));
161 MT_Vector3 angvelvec ( KX_BLENDERTRUNC(obact->angularvelocity[0]),
162 KX_BLENDERTRUNC(obact->angularvelocity[1]),
163 KX_BLENDERTRUNC(obact->angularvelocity[2]));
164 short damping = obact->damping;
166 /* Blender uses a bit vector internally for the local-flags. In */
167 /* KX, we have four bools. The compiler should be smart enough */
168 /* to do the right thing. We need to explicitly convert here! */
170 KX_LocalFlags bitLocalFlag;
172 bitLocalFlag.Force = bool((obact->flag & ACT_FORCE_LOCAL)!=0);
173 bitLocalFlag.Torque = bool((obact->flag & ACT_TORQUE_LOCAL) !=0);//rlocal;
174 bitLocalFlag.DLoc = bool((obact->flag & ACT_DLOC_LOCAL)!=0);
175 bitLocalFlag.DRot = bool((obact->flag & ACT_DROT_LOCAL)!=0);
176 bitLocalFlag.LinearVelocity = bool((obact->flag & ACT_LIN_VEL_LOCAL)!=0);
177 bitLocalFlag.AngularVelocity = bool((obact->flag & ACT_ANG_VEL_LOCAL)!=0);
178 bitLocalFlag.ServoControl = bool(obact->type == ACT_OBJECT_SERVO);
179 bitLocalFlag.AddOrSetLinV = bool((obact->flag & ACT_ADD_LIN_VEL)!=0);
180 if (obact->reference && bitLocalFlag.ServoControl)
182 obref = converter->FindGameObject(obact->reference);
185 KX_ObjectActuator* tmpbaseact = new KX_ObjectActuator(gameobj,
188 torquevec.getValue(),
191 linvelvec.getValue(),
192 angvelvec.getValue(),
196 baseact = tmpbaseact;
201 bActionActuator* actact = (bActionActuator*) bact->data;
202 STR_String propname = (actact->name ? actact->name : "");
203 STR_String propframe = (actact->frameProp ? actact->frameProp : "");
208 if (actact->flag & ACT_IPOFORCE) ipo_flags |= BL_Action::ACT_IPOFLAG_FORCE;
209 if (actact->flag & ACT_IPOLOCAL) ipo_flags |= BL_Action::ACT_IPOFLAG_LOCAL;
210 if (actact->flag & ACT_IPOADD) ipo_flags |= BL_Action::ACT_IPOFLAG_ADD;
211 if (actact->flag & ACT_IPOCHILD) ipo_flags |= BL_Action::ACT_IPOFLAG_CHILD;
213 BL_ActionActuator* tmpbaseact = new BL_ActionActuator(
220 actact->type, // + 1, because Blender starts to count at zero,
224 actact->layer_weight,
228 // Ketsji at 1, because zero is reserved for "NoDef"
233 case ACT_SHAPEACTION:
235 if (blenderobject->type==OB_MESH){
236 bActionActuator* actact = (bActionActuator*) bact->data;
237 STR_String propname = (actact->name ? actact->name : "");
238 STR_String propframe = (actact->frameProp ? actact->frameProp : "");
240 BL_ShapeActionActuator* tmpbaseact = new BL_ShapeActionActuator(
247 actact->type, // + 1, because Blender starts to count at zero,
251 // Ketsji at 1, because zero is reserved for "NoDef"
257 printf ("Discarded shape action actuator from non-mesh object [%s]\n", blenderobject->id.name+2);
261 bIpoActuator* ipoact = (bIpoActuator*) bact->data;
262 bool ipochild = (ipoact->flag & ACT_IPOCHILD) !=0;
263 STR_String propname = ipoact->name;
264 STR_String frameProp = ipoact->frameProp;
266 bool ipo_as_force = (ipoact->flag & ACT_IPOFORCE);
267 bool local = (ipoact->flag & ACT_IPOLOCAL);
268 bool ipo_add = (ipoact->flag & ACT_IPOADD);
270 KX_IpoActuator* tmpbaseact = new KX_IpoActuator(
277 ipoact->type + 1, // + 1, because Blender starts to count at zero,
278 // Ketsji at 1, because zero is reserved for "NoDef"
282 baseact = tmpbaseact;
291 bCameraActuator *camact = (bCameraActuator *) bact->data;
293 KX_GameObject *tmpgob = converter->FindGameObject(camact->ob);
295 /* visifac, fac and axis are not copied from the struct... */
296 /* that's some internal state... */
297 KX_CameraActuator *tmpcamact
298 = new KX_CameraActuator(gameobj,
311 bMessageActuator *msgAct = (bMessageActuator *) bact->data;
314 * Get the name of the properties that objects must own that
315 * we're sending to, if present
317 STR_String toPropName = (msgAct->toPropName
318 ? (char*) msgAct->toPropName
322 * Get the Message Subject to send.
324 STR_String subject = (msgAct->subject
325 ? (char*) msgAct->subject
331 int bodyType = msgAct->bodyType;
334 * Get the body (text message or property name whose value
335 * we'll be sending, might be empty
337 STR_String body = (msgAct->body
338 ? (char*) msgAct->body
341 KX_NetworkMessageActuator *tmpmsgact =
342 new KX_NetworkMessageActuator(
343 gameobj, // actuator controlling object
344 scene->GetNetworkScene(), // needed for replication
358 bSoundActuator* soundact = (bSoundActuator*) bact->data;
359 /* get type, and possibly a start and end frame */
360 KX_SoundActuator::KX_SOUNDACT_TYPE
361 soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
363 switch(soundact->type) {
364 case ACT_SND_PLAY_STOP_SOUND:
365 soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYSTOP;
367 case ACT_SND_PLAY_END_SOUND:
368 soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYEND;
370 case ACT_SND_LOOP_STOP_SOUND:
371 soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPSTOP;
373 case ACT_SND_LOOP_END_SOUND:
374 soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPEND;
376 case ACT_SND_LOOP_BIDIRECTIONAL_SOUND:
377 soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL;
379 case ACT_SND_LOOP_BIDIRECTIONAL_STOP_SOUND:
380 soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP;
384 /* This is an error!!! */
385 soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
388 if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF)
390 bSound* sound = soundact->sound;
391 bool is3d = soundact->flag & ACT_SND_3D_SOUND ? true : false;
392 AUD_Reference<AUD_IFactory> snd_sound;
393 KX_3DSoundSettings settings;
394 settings.cone_inner_angle = soundact->sound3D.cone_inner_angle;
395 settings.cone_outer_angle = soundact->sound3D.cone_outer_angle;
396 settings.cone_outer_gain = soundact->sound3D.cone_outer_gain;
397 settings.max_distance = soundact->sound3D.max_distance;
398 settings.max_gain = soundact->sound3D.max_gain;
399 settings.min_gain = soundact->sound3D.min_gain;
400 settings.reference_distance = soundact->sound3D.reference_distance;
401 settings.rolloff_factor = soundact->sound3D.rolloff_factor;
405 std::cout << "WARNING: Sound actuator \"" << bact->name <<
406 "\" from object \"" << blenderobject->id.name+2 <<
407 "\" has no sound datablock." << std::endl;
411 snd_sound = *reinterpret_cast<AUD_Reference<AUD_IFactory>*>(sound->playback_handle);
413 // if sound shall be 3D but isn't mono, we have to make it mono!
418 AUD_Reference<AUD_IReader> reader = snd_sound->createReader();
419 if(reader->getSpecs().channels != AUD_CHANNELS_MONO)
421 AUD_DeviceSpecs specs;
422 specs.channels = AUD_CHANNELS_MONO;
423 specs.rate = AUD_RATE_INVALID;
424 specs.format = AUD_FORMAT_INVALID;
425 snd_sound = new AUD_ChannelMapperFactory(snd_sound, specs);
428 catch(AUD_Exception&)
430 // sound cannot be played... ignore
434 KX_SoundActuator* tmpsoundact =
435 new KX_SoundActuator(gameobj,
438 (float)(exp((soundact->pitch / 12.0) * M_LN2)),
443 tmpsoundact->SetName(bact->name);
444 baseact = tmpsoundact;
450 bPropertyActuator* propact = (bPropertyActuator*) bact->data;
451 SCA_IObject* destinationObj = NULL;
454 here the destinationobject is searched. problem with multiple scenes: other scenes
455 have not been converted yet, so the destobj will not be found, so the prop will
458 - convert everything when possible and not realtime only when needed.
459 - let the object-with-property report itself to the act when converted
462 destinationObj = converter->FindGameObject(propact->ob);
464 SCA_PropertyActuator* tmppropact = new SCA_PropertyActuator(
469 propact->type+1); // + 1 because Ketsji Logic starts
470 // with 0 for KX_ACT_PROP_NODEF
471 baseact = tmppropact;
474 case ACT_EDIT_OBJECT:
476 bEditObjectActuator *editobact
477 = (bEditObjectActuator *) bact->data;
478 /* There are four different kinds of 'edit object' thingies */
479 /* The alternative to this lengthy conversion is packing */
480 /* several actuators in one, which is not very nice design.. */
481 switch (editobact->type) {
482 case ACT_EDOB_ADD_OBJECT:
485 // does the 'original' for replication exists, and
486 // is it in a non-active layer ?
487 SCA_IObject* originalval = NULL;
490 if (editobact->ob->lay & activeLayerBitInfo)
492 fprintf(stderr, "Warning, object \"%s\" from AddObject actuator \"%s\" is not in a hidden layer.\n", objectname.Ptr(), uniquename.Ptr());
495 originalval = converter->FindGameObject(editobact->ob);
499 KX_SCA_AddObjectActuator* tmpaddact =
500 new KX_SCA_AddObjectActuator(
505 editobact->linVelocity,
506 (editobact->localflag & ACT_EDOB_LOCAL_LINV)!=0,
507 editobact->angVelocity,
508 (editobact->localflag & ACT_EDOB_LOCAL_ANGV)!=0
511 //editobact->ob to gameobj
515 case ACT_EDOB_END_OBJECT:
517 KX_SCA_EndObjectActuator* tmpendact
518 = new KX_SCA_EndObjectActuator(gameobj,scene);
522 case ACT_EDOB_REPLACE_MESH:
524 RAS_MeshObject *tmpmesh = NULL;
526 tmpmesh = BL_ConvertMesh(
533 KX_SCA_ReplaceMeshActuator* tmpreplaceact
534 = new KX_SCA_ReplaceMeshActuator(
538 (editobact->flag & ACT_EDOB_REPLACE_MESH_NOGFX)==0,
539 (editobact->flag & ACT_EDOB_REPLACE_MESH_PHYS)!=0
543 baseact = tmpreplaceact;
546 case ACT_EDOB_TRACK_TO:
548 SCA_IObject* originalval = NULL;
550 originalval = converter->FindGameObject(editobact->ob);
552 KX_TrackToActuator* tmptrackact
553 = new KX_TrackToActuator(gameobj,
557 blenderobject->trackflag,
558 blenderobject->upflag
560 baseact = tmptrackact;
563 case ACT_EDOB_DYNAMICS:
565 KX_SCA_DynamicActuator* tmpdynact
566 = new KX_SCA_DynamicActuator(gameobj,
567 editobact->dyn_operation,
577 float min = 0.0, max = 0.0;
579 KX_ConstraintActuator::KX_CONSTRAINTTYPE locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF;
580 bConstraintActuator *conact
581 = (bConstraintActuator*) bact->data;
582 /* convert settings... degrees in the ui become radians */
584 if (conact->type == ACT_CONST_TYPE_ORI) {
585 min = (float)((MT_2_PI * conact->minloc[0])/360.0);
586 max = (float)((MT_2_PI * conact->maxloc[0])/360.0);
587 switch (conact->mode) {
588 case ACT_CONST_DIRPX:
589 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX;
591 case ACT_CONST_DIRPY:
592 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY;
594 case ACT_CONST_DIRPZ:
595 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ;
598 } else if (conact->type == ACT_CONST_TYPE_DIST) {
599 switch (conact->mode) {
600 case ACT_CONST_DIRPX:
601 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX;
602 min = conact->minloc[0];
603 max = conact->maxloc[0];
605 case ACT_CONST_DIRPY:
606 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY;
607 min = conact->minloc[1];
608 max = conact->maxloc[1];
610 case ACT_CONST_DIRPZ:
611 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ;
612 min = conact->minloc[2];
613 max = conact->maxloc[2];
615 case ACT_CONST_DIRNX:
616 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX;
617 min = conact->minloc[0];
618 max = conact->maxloc[0];
620 case ACT_CONST_DIRNY:
621 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY;
622 min = conact->minloc[1];
623 max = conact->maxloc[1];
625 case ACT_CONST_DIRNZ:
626 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ;
627 min = conact->minloc[2];
628 max = conact->maxloc[2];
631 prop = conact->matprop;
632 } else if (conact->type == ACT_CONST_TYPE_FH) {
633 switch (conact->mode) {
634 case ACT_CONST_DIRPX:
635 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX;
636 min = conact->minloc[0];
637 max = conact->maxloc[0];
639 case ACT_CONST_DIRPY:
640 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY;
641 min = conact->minloc[1];
642 max = conact->maxloc[1];
644 case ACT_CONST_DIRPZ:
645 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ;
646 min = conact->minloc[2];
647 max = conact->maxloc[2];
649 case ACT_CONST_DIRNX:
650 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX;
651 min = conact->minloc[0];
652 max = conact->maxloc[0];
654 case ACT_CONST_DIRNY:
655 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY;
656 min = conact->minloc[1];
657 max = conact->maxloc[1];
659 case ACT_CONST_DIRNZ:
660 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ;
661 min = conact->minloc[2];
662 max = conact->maxloc[2];
665 prop = conact->matprop;
667 switch (conact->flag) {
669 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX;
670 min = conact->minloc[0];
671 max = conact->maxloc[0];
674 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY;
675 min = conact->minloc[1];
676 max = conact->maxloc[1];
679 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ;
680 min = conact->minloc[2];
681 max = conact->maxloc[2];
684 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX;
685 min = conact->minrot[0] * (float)MT_RADS_PER_DEG;
686 max = conact->maxrot[0] * (float)MT_RADS_PER_DEG;
689 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY;
690 min = conact->minrot[1] * (float)MT_RADS_PER_DEG;
691 max = conact->maxrot[1] * (float)MT_RADS_PER_DEG;
694 locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ;
695 min = conact->minrot[2] * (float)MT_RADS_PER_DEG;
696 max = conact->maxrot[2] * (float)MT_RADS_PER_DEG;
702 KX_ConstraintActuator *tmpconact
703 = new KX_ConstraintActuator(gameobj,
723 bSceneActuator *sceneact = (bSceneActuator *) bact->data;
724 STR_String nextSceneName("");
726 KX_SceneActuator* tmpsceneact;
727 int mode = KX_SceneActuator::KX_SCENE_NODEF;
728 KX_Camera *cam = NULL;
729 //KX_Scene* scene = NULL;
730 switch (sceneact->type)
732 case ACT_SCENE_RESUME:
733 case ACT_SCENE_SUSPEND:
734 case ACT_SCENE_ADD_FRONT:
735 case ACT_SCENE_ADD_BACK:
736 case ACT_SCENE_REMOVE:
739 switch (sceneact->type)
741 case ACT_SCENE_RESUME:
742 mode = KX_SceneActuator::KX_SCENE_RESUME;
744 case ACT_SCENE_SUSPEND:
745 mode = KX_SceneActuator::KX_SCENE_SUSPEND;
747 case ACT_SCENE_ADD_FRONT:
748 mode = KX_SceneActuator::KX_SCENE_ADD_FRONT_SCENE;
750 case ACT_SCENE_ADD_BACK:
751 mode = KX_SceneActuator::KX_SCENE_ADD_BACK_SCENE;
753 case ACT_SCENE_REMOVE:
754 mode = KX_SceneActuator::KX_SCENE_REMOVE_SCENE;
758 mode = KX_SceneActuator::KX_SCENE_SET_SCENE;
764 nextSceneName = sceneact->scene->id.name + 2; // this '2' is necessary to remove prefix 'SC'
769 case ACT_SCENE_CAMERA:
770 mode = KX_SceneActuator::KX_SCENE_SET_CAMERA;
771 if (sceneact->camera)
773 cam = (KX_Camera*) converter->FindGameObject(sceneact->camera);
776 case ACT_SCENE_RESTART:
779 mode = KX_SceneActuator::KX_SCENE_RESTART;
785 tmpsceneact = new KX_SceneActuator(gameobj,
791 baseact = tmpsceneact;
796 bGameActuator *gameact = (bGameActuator *) bact->data;
797 KX_GameActuator* tmpgameact;
798 STR_String filename = maggiename;
799 STR_String loadinganimationname = "";
800 int mode = KX_GameActuator::KX_GAME_NODEF;
801 switch (gameact->type)
805 mode = KX_GameActuator::KX_GAME_LOAD;
806 filename = gameact->filename;
807 loadinganimationname = gameact->loadaniname;
812 mode = KX_GameActuator::KX_GAME_START;
813 filename = gameact->filename;
814 loadinganimationname = gameact->loadaniname;
817 case ACT_GAME_RESTART:
819 mode = KX_GameActuator::KX_GAME_RESTART;
824 mode = KX_GameActuator::KX_GAME_QUIT;
827 case ACT_GAME_SAVECFG:
829 mode = KX_GameActuator::KX_GAME_SAVECFG;
832 case ACT_GAME_LOADCFG:
834 mode = KX_GameActuator::KX_GAME_LOADCFG;
840 tmpgameact = new KX_GameActuator(gameobj,
843 loadinganimationname,
846 baseact = tmpgameact;
852 bRandomActuator *randAct
853 = (bRandomActuator *) bact->data;
855 unsigned long seedArg = randAct->seed;
858 seedArg = (int)(ketsjiEngine->GetRealTime()*100000.0);
859 seedArg ^= (intptr_t)randAct;
861 SCA_RandomActuator::KX_RANDOMACT_MODE modeArg
862 = SCA_RandomActuator::KX_RANDOMACT_NODEF;
863 SCA_RandomActuator *tmprandomact;
864 float paraArg1 = 0.0;
865 float paraArg2 = 0.0;
867 switch (randAct->distribution) {
868 case ACT_RANDOM_BOOL_CONST:
869 modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST;
870 paraArg1 = (float) randAct->int_arg_1;
872 case ACT_RANDOM_BOOL_UNIFORM:
873 modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM;
875 case ACT_RANDOM_BOOL_BERNOUILLI:
876 paraArg1 = randAct->float_arg_1;
877 modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI;
879 case ACT_RANDOM_INT_CONST:
880 modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_CONST;
881 paraArg1 = (float) randAct->int_arg_1;
883 case ACT_RANDOM_INT_UNIFORM:
884 paraArg1 = (float) randAct->int_arg_1;
885 paraArg2 = (float) randAct->int_arg_2;
886 modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM;
888 case ACT_RANDOM_INT_POISSON:
889 paraArg1 = randAct->float_arg_1;
890 modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_POISSON;
892 case ACT_RANDOM_FLOAT_CONST:
893 paraArg1 = randAct->float_arg_1;
894 modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST;
896 case ACT_RANDOM_FLOAT_UNIFORM:
897 paraArg1 = randAct->float_arg_1;
898 paraArg2 = randAct->float_arg_2;
899 modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM;
901 case ACT_RANDOM_FLOAT_NORMAL:
902 paraArg1 = randAct->float_arg_1;
903 paraArg2 = randAct->float_arg_2;
904 modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL;
906 case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
907 paraArg1 = randAct->float_arg_1;
908 modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL;
913 tmprandomact = new SCA_RandomActuator(gameobj,
919 baseact = tmprandomact;
925 bVisibilityActuator *vis_act = (bVisibilityActuator *) bact->data;
926 KX_VisibilityActuator * tmp_vis_act = NULL;
927 bool v = ((vis_act->flag & ACT_VISIBILITY_INVISIBLE) != 0);
928 bool o = ((vis_act->flag & ACT_VISIBILITY_OCCLUSION) != 0);
929 bool recursive = ((vis_act->flag & ACT_VISIBILITY_RECURSIVE) != 0);
931 tmp_vis_act = new KX_VisibilityActuator(gameobj, !v, o, recursive);
933 baseact = tmp_vis_act;
939 bStateActuator *sta_act = (bStateActuator *) bact->data;
940 KX_StateActuator * tmp_sta_act = NULL;
943 new KX_StateActuator(gameobj, sta_act->type, sta_act->mask);
945 baseact = tmp_sta_act;
951 bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data;
952 SCA_2DFilterActuator *tmp = NULL;
954 RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode;
955 switch(_2dfilter->type)
957 case ACT_2DFILTER_MOTIONBLUR:
958 filtermode = RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR;
960 case ACT_2DFILTER_BLUR:
961 filtermode = RAS_2DFilterManager::RAS_2DFILTER_BLUR;
963 case ACT_2DFILTER_SHARPEN:
964 filtermode = RAS_2DFilterManager::RAS_2DFILTER_SHARPEN;
966 case ACT_2DFILTER_DILATION:
967 filtermode = RAS_2DFilterManager::RAS_2DFILTER_DILATION;
969 case ACT_2DFILTER_EROSION:
970 filtermode = RAS_2DFilterManager::RAS_2DFILTER_EROSION;
972 case ACT_2DFILTER_LAPLACIAN:
973 filtermode = RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN;
975 case ACT_2DFILTER_SOBEL:
976 filtermode = RAS_2DFilterManager::RAS_2DFILTER_SOBEL;
978 case ACT_2DFILTER_PREWITT:
979 filtermode = RAS_2DFilterManager::RAS_2DFILTER_PREWITT;
981 case ACT_2DFILTER_GRAYSCALE:
982 filtermode = RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE;
984 case ACT_2DFILTER_SEPIA:
985 filtermode = RAS_2DFilterManager::RAS_2DFILTER_SEPIA;
987 case ACT_2DFILTER_INVERT:
988 filtermode = RAS_2DFilterManager::RAS_2DFILTER_INVERT;
990 case ACT_2DFILTER_CUSTOMFILTER:
991 filtermode = RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER;
993 case ACT_2DFILTER_NOFILTER:
994 filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
996 case ACT_2DFILTER_DISABLED:
997 filtermode = RAS_2DFilterManager::RAS_2DFILTER_DISABLED;
999 case ACT_2DFILTER_ENABLED:
1000 filtermode = RAS_2DFilterManager::RAS_2DFILTER_ENABLED;
1003 filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
1007 tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag,
1008 _2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),scene);
1010 if (_2dfilter->text)
1013 // this is some blender specific code
1014 buf = txt_to_buf(_2dfilter->text);
1017 tmp->SetShaderText(buf);
1028 bParentActuator *parAct = (bParentActuator *) bact->data;
1029 int mode = KX_ParentActuator::KX_PARENT_NODEF;
1030 bool addToCompound = true;
1032 KX_GameObject *tmpgob = NULL;
1034 switch(parAct->type)
1036 case ACT_PARENT_SET:
1037 mode = KX_ParentActuator::KX_PARENT_SET;
1038 tmpgob = converter->FindGameObject(parAct->ob);
1039 addToCompound = !(parAct->flag & ACT_PARENT_COMPOUND);
1040 ghost = !(parAct->flag & ACT_PARENT_GHOST);
1042 case ACT_PARENT_REMOVE:
1043 mode = KX_ParentActuator::KX_PARENT_REMOVE;
1048 KX_ParentActuator *tmpparact
1049 = new KX_ParentActuator(gameobj,
1054 baseact = tmpparact;
1060 bArmatureActuator* armAct = (bArmatureActuator*) bact->data;
1061 KX_GameObject *tmpgob = converter->FindGameObject(armAct->target);
1062 KX_GameObject *subgob = converter->FindGameObject(armAct->subtarget);
1063 BL_ArmatureActuator* tmparmact = new BL_ArmatureActuator(gameobj, armAct->type, armAct->posechannel, armAct->constraint, tmpgob, subgob, armAct->weight);
1064 baseact = tmparmact;
1069 bSteeringActuator *stAct = (bSteeringActuator *) bact->data;
1070 KX_GameObject *navmeshob = NULL;
1073 PointerRNA settings_ptr;
1074 RNA_pointer_create((ID *)stAct->navmesh, &RNA_GameObjectSettings, stAct->navmesh, &settings_ptr);
1075 if (RNA_enum_get(&settings_ptr, "physics_type") == OB_BODY_TYPE_NAVMESH)
1076 navmeshob = converter->FindGameObject(stAct->navmesh);
1078 KX_GameObject *targetob = converter->FindGameObject(stAct->target);
1080 int mode = KX_SteeringActuator::KX_STEERING_NODEF;
1083 case ACT_STEERING_SEEK:
1084 mode = KX_SteeringActuator::KX_STEERING_SEEK;
1086 case ACT_STEERING_FLEE:
1087 mode = KX_SteeringActuator::KX_STEERING_FLEE;
1089 case ACT_STEERING_PATHFOLLOWING:
1090 mode = KX_SteeringActuator::KX_STEERING_PATHFOLLOWING;
1094 bool selfTerminated = (stAct->flag & ACT_STEERING_SELFTERMINATED) !=0;
1095 bool enableVisualization = (stAct->flag & ACT_STEERING_ENABLEVISUALIZATION) !=0;
1096 short facingMode = (stAct->flag & ACT_STEERING_AUTOMATICFACING) ? stAct->facingaxis : 0;
1097 bool normalup = (stAct->flag & ACT_STEERING_NORMALUP) !=0;
1098 KX_SteeringActuator *tmpstact
1099 = new KX_SteeringActuator(gameobj, mode, targetob, navmeshob,stAct->dist,
1100 stAct->velocity, stAct->acceleration, stAct->turnspeed,
1101 selfTerminated, stAct->updateTime,
1102 scene->GetObstacleSimulation(), facingMode, normalup, enableVisualization);
1107 ; /* generate some error */
1112 baseact->SetExecutePriority(executePriority++);
1113 uniquename += "#ACT#";
1115 CIntValue* uniqueval = new CIntValue(uniqueint);
1116 uniquename += uniqueval->GetText();
1117 uniqueval->Release();
1118 baseact->SetName(bact->name);
1119 //gameobj->SetProperty(uniquename,baseact);
1120 gameobj->AddActuator(baseact);
1122 converter->RegisterGameActuator(baseact, bact);
1123 // done with baseact, release it