diff options
Diffstat (limited to 'source/gameengine/Converter/BL_BlenderDataConversion.cpp')
-rw-r--r-- | source/gameengine/Converter/BL_BlenderDataConversion.cpp | 408 |
1 files changed, 132 insertions, 276 deletions
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index c6140743950..e4f20359079 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -52,23 +52,13 @@ #include <algorithm> #include "BL_BlenderDataConversion.h" -#include "KX_BlenderScalarInterpolator.h" -#include "RAS_IPolygonMaterial.h" - -// Expressions -#include "ListValue.h" -#include "IntValue.h" -// Collision & Fuzzics LTD +#include "MT_Matrix3x3.h" +#include "MT_MinMax.h" #include "PHY_Pro.h" #include "PHY_IPhysicsEnvironment.h" -#include "PHY_DynamicTypes.h" - -#include "KX_Scene.h" -#include "KX_GameObject.h" -#include "RAS_FramingManager.h" #include "RAS_MeshObject.h" #include "RAS_IRasterizer.h" #include "RAS_ILightObject.h" @@ -76,31 +66,27 @@ #include "KX_ConvertActuators.h" #include "KX_ConvertControllers.h" #include "KX_ConvertSensors.h" - #include "SCA_LogicManager.h" -#include "SCA_EventManager.h" #include "SCA_TimeEventManager.h" + +#include "KX_ClientObjectInfo.h" +#include "KX_Scene.h" +#include "KX_GameObject.h" #include "KX_Light.h" #include "KX_Camera.h" -#include "KX_ClientObjectInfo.h" #include "KX_EmptyObject.h" #include "KX_FontObject.h" -#include "MT_Point3.h" -#include "MT_Transform.h" -#include "MT_MinMax.h" -#include "SCA_IInputDevice.h" + #include "RAS_TexMatrix.h" #include "RAS_ICanvas.h" -#include "RAS_MaterialBucket.h" -//#include "KX_BlenderPolyMaterial.h" #include "RAS_Polygon.h" #include "RAS_TexVert.h" #include "RAS_BucketManager.h" +#include "RAS_IPolygonMaterial.h" #include "BL_Material.h" #include "KX_BlenderMaterial.h" #include "BL_Texture.h" -#include "DNA_action_types.h" #include "BKE_main.h" #include "BKE_global.h" #include "BKE_object.h" @@ -109,9 +95,10 @@ #include "BL_SkinDeformer.h" #include "BL_MeshDeformer.h" #include "KX_SoftBodyDeformer.h" -//#include "BL_ArmatureController.h" + #include "BLI_utildefines.h" #include "BLI_listbase.h" + #include "BlenderWorldInfo.h" #include "KX_KetsjiEngine.h" @@ -143,13 +130,14 @@ #include "DNA_sound_types.h" #include "DNA_key_types.h" #include "DNA_armature_types.h" +#include "DNA_action_types.h" #include "DNA_object_force.h" +#include "DNA_constraint_types.h" #include "MEM_guardedalloc.h" #include "BKE_key.h" #include "BKE_mesh.h" -#include "MT_Point3.h" #include "BLI_math.h" @@ -170,29 +158,18 @@ extern Material defmaterial; /* material.c */ #include "KX_BlenderInputDevice.h" #include "KX_ConvertProperties.h" -#include "KX_HashedPtr.h" - - -#include "KX_ScalarInterpolator.h" - -#include "KX_IpoConvert.h" -#include "BL_System.h" #include "SG_Node.h" #include "SG_BBox.h" -#include "SG_Tree.h" +#include "KX_SG_NodeRelationships.h" +#include "KX_SG_BoneParentNodeRelationship.h" #ifdef WITH_BULLET #include "CcdPhysicsEnvironment.h" #include "CcdGraphicController.h" #endif -#include "KX_MotionState.h" - -// This file defines relationships between parents and children -// in the game engine. -#include "KX_SG_NodeRelationships.h" -#include "KX_SG_BoneParentNodeRelationship.h" +#include "KX_MotionState.h" #include "BL_ArmatureObject.h" #include "BL_DeformableGameObject.h" @@ -200,18 +177,9 @@ extern Material defmaterial; /* material.c */ #include "KX_NavMeshObject.h" #include "KX_ObstacleSimulation.h" -#ifdef __cplusplus -extern "C" { -#endif -//XXX void update_for_newframe(); -//void BKE_scene_update_for_newframe(struct Scene *sce, unsigned int lay); -//void do_all_data_ipos(void); -#ifdef __cplusplus -} -#endif - #include "BLI_threads.h" + static bool default_light_mode = 0; static std::map<int, SCA_IInputDevice::KX_EnumInputs> create_translate_table() @@ -389,6 +357,11 @@ static std::map<int, SCA_IInputDevice::KX_EnumInputs> create_translate_table() static std::map<int, SCA_IInputDevice::KX_EnumInputs> gReverseKeyTranslateTable = create_translate_table(); +SCA_IInputDevice::KX_EnumInputs ConvertKeyCode(int key_code) +{ + return gReverseKeyTranslateTable[key_code]; +} + static unsigned int KX_rgbaint2uint_new(unsigned int icol) { union @@ -889,10 +862,10 @@ static bool ConvertMaterial( // swap the material color, so MCol on bitmap font works if (validmat && (use_vcol == false) && (mat->game.flag & GEMAT_TEXT)) { - rgb[0] = KX_rgbaint2uint_new(rgb[0]); - rgb[1] = KX_rgbaint2uint_new(rgb[1]); - rgb[2] = KX_rgbaint2uint_new(rgb[2]); - rgb[3] = KX_rgbaint2uint_new(rgb[3]); + material->rgb[0] = KX_rgbaint2uint_new(rgb[0]); + material->rgb[1] = KX_rgbaint2uint_new(rgb[1]); + material->rgb[2] = KX_rgbaint2uint_new(rgb[2]); + material->rgb[3] = KX_rgbaint2uint_new(rgb[3]); } if (validmat) @@ -1389,16 +1362,14 @@ static void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj, } bool isCompoundChild = false; - bool hasCompoundChildren = !parent && (blenderobject->gameflag & OB_CHILD); + bool hasCompoundChildren = !parent && (blenderobject->gameflag & OB_CHILD) && !(blenderobject->gameflag & OB_SOFT_BODY); /* When the parent is not OB_DYNAMIC and has no OB_COLLISION then it gets no bullet controller - * and cant be apart of the parents compound shape */ + * and cant be apart of the parents compound shape, same goes for OB_SOFT_BODY */ if (parent && (parent->gameflag & (OB_DYNAMIC | OB_COLLISION))) { - - if ((parent->gameflag & OB_CHILD) != 0 && (blenderobject->gameflag & OB_CHILD)) - { + if( (parent->gameflag & OB_CHILD)!=0 && (blenderobject->gameflag & OB_CHILD) && !(parent->gameflag & OB_SOFT_BODY)) { isCompoundChild = true; - } + } } if (processCompoundChildren != isCompoundChild) return; @@ -1711,9 +1682,6 @@ struct parentChildLink { SG_Node* m_gamechildnode; }; -#include "DNA_constraint_types.h" -//XXX #include "BIF_editconstraint.h" - static bPoseChannel *get_active_posechannel2(Object *ob) { bArmature *arm= (bArmature*)ob->data; @@ -1747,20 +1715,15 @@ static ListBase *get_active_constraints2(Object *ob) return NULL; } -static void UNUSED_FUNCTION(RBJconstraints)(Object *ob)//not used +static void UNUSED_FUNCTION(print_active_constraints2)(Object *ob) //not used, use to debug { - ListBase *conlist; - bConstraint *curcon; - - conlist = get_active_constraints2(ob); + bConstraint* curcon; + ListBase* conlist = get_active_constraints2(ob); if (conlist) { for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) { - printf("%i\n",curcon->type); } - - } } @@ -1782,20 +1745,22 @@ static KX_GameObject* getGameOb(STR_String busc,CListValue* sumolist) * note: all var names match args are passed from the caller */ static void bl_ConvertBlenderObject_Single( KX_BlenderSceneConverter *converter, - Scene *blenderscene, Object *blenderobject, - vector<MT_Vector3> &inivel, vector<MT_Vector3> &iniang, + Object *blenderobject, vector<parentChildLink> &vec_parent_child, CListValue* logicbrick_conversionlist, - CListValue* objectlist, CListValue* inactivelist, CListValue* sumolist, + CListValue* objectlist, CListValue* inactivelist, CListValue* sumolist, KX_Scene* kxscene, KX_GameObject* gameobj, SCA_LogicManager* logicmgr, SCA_TimeEventManager* timemgr, bool isInActiveLayer ) { - MT_Point3 posPrev; - MT_Matrix3x3 angor; - if (converter->addInitFromFrame) blenderscene->r.cfra=blenderscene->r.sfra; + sumolist->Add(gameobj->AddRef()); + + BL_ConvertProperties(blenderobject,gameobj,timemgr,kxscene,isInActiveLayer); + gameobj->SetName(blenderobject->id.name + 2); + + /* Setting local coordinates according to current local+delta */ MT_Point3 pos( blenderobject->loc[0]+blenderobject->dloc[0], blenderobject->loc[1]+blenderobject->dloc[1], @@ -1804,97 +1769,61 @@ static void bl_ConvertBlenderObject_Single( MT_Matrix3x3 rotation; float rotmat[3][3]; - BKE_object_rot_to_mat3(blenderobject, rotmat, false); + BKE_object_rot_to_mat3(blenderobject, rotmat, true); rotation.setValue3x3((float*)rotmat); - MT_Vector3 scale(blenderobject->size); - - if (converter->addInitFromFrame) {//rcruiz - blenderscene->r.cfra=blenderscene->r.sfra-1; - //XXX update_for_newframe(); - MT_Vector3 tmp=pos-MT_Point3(blenderobject->loc[0]+blenderobject->dloc[0], - blenderobject->loc[1]+blenderobject->dloc[1], - blenderobject->loc[2]+blenderobject->dloc[2] - ); - - float rotmatPrev[3][3]; - BKE_object_rot_to_mat3(blenderobject, rotmatPrev, false); - - float eulxyz[3], eulxyzPrev[3]; - mat3_to_eul(eulxyz, rotmat); - mat3_to_eul(eulxyzPrev, rotmatPrev); - - double fps = (double) blenderscene->r.frs_sec/ - (double) blenderscene->r.frs_sec_base; - - tmp.scale(fps, fps, fps); - inivel.push_back(tmp); - tmp[0]=eulxyz[0]-eulxyzPrev[0]; - tmp[1]=eulxyz[1]-eulxyzPrev[1]; - tmp[2]=eulxyz[2]-eulxyzPrev[2]; - tmp.scale(fps, fps, fps); - iniang.push_back(tmp); - blenderscene->r.cfra=blenderscene->r.sfra; - //XXX update_for_newframe(); - } + MT_Vector3 scale( + blenderobject->size[0]*blenderobject->dscale[0], + blenderobject->size[1]*blenderobject->dscale[1], + blenderobject->size[2]*blenderobject->dscale[2] + ); gameobj->NodeSetLocalPosition(pos); gameobj->NodeSetLocalOrientation(rotation); gameobj->NodeSetLocalScale(scale); - gameobj->NodeUpdateGS(0); - sumolist->Add(gameobj->AddRef()); - - BL_ConvertProperties(blenderobject,gameobj,timemgr,kxscene,isInActiveLayer); - - gameobj->SetName(blenderobject->id.name + 2); - - // update children/parent hierarchy - if ((blenderobject->parent != 0)&&(!converter->addInitFromFrame)) + /* if the node has a parent, add a parent/child link */ + if (blenderobject->parent != 0) { - // blender has an additional 'parentinverse' offset in each object - SG_Callbacks callback(NULL,NULL,NULL,KX_Scene::KX_ScenegraphUpdateFunc,KX_Scene::KX_ScenegraphRescheduleFunc); - SG_Node* parentinversenode = new SG_Node(NULL,kxscene,callback); - - // define a normal parent relationship for this node. - KX_NormalParentRelation * parent_relation = KX_NormalParentRelation::New(); - parentinversenode->SetParentRelation(parent_relation); + SG_Callbacks callbacks( + NULL, /* replicationfunc, */ + NULL, /* destructionfunc,*/ + NULL, /* updatefunc, */ + KX_Scene::KX_ScenegraphUpdateFunc, /* schedulefunc, */ + KX_Scene::KX_ScenegraphRescheduleFunc); /* reschedulefunc */ + + /* + * when an object gets parented, an inverse parenting matrix is kept, + * or the child would pop to the parents position, alignment, etc. + * the GE scene graph makes an intermediate node between the parent + * and child to store this transform. + */ + SG_Node* parentinversenode = new SG_Node(NULL,kxscene,callbacks); + parentinversenode->SetParentRelation(KX_NormalParentRelation::New()); + parentinversenode->AddChild(gameobj->GetSGNode()); + /* add the link to vec_parent_child that will be processed later, connecting the parent nodes */ parentChildLink pclink; pclink.m_blenderchild = blenderobject; pclink.m_gamechildnode = parentinversenode; vec_parent_child.push_back(pclink); - float* fl = (float*) blenderobject->parentinv; - MT_Transform parinvtrans(fl); - parentinversenode->SetLocalPosition(parinvtrans.getOrigin()); - // problem here: the parent inverse transform combines scaling and rotation - // in the basis but the scenegraph needs separate rotation and scaling. - // This is not important for OpenGL (it uses 4x4 matrix) but it is important - // for the physic engine that needs a separate scaling - //parentinversenode->SetLocalOrientation(parinvtrans.getBasis()); - - // Extract the rotation and the scaling from the basis - MT_Matrix3x3 ori(parinvtrans.getBasis()); - MT_Vector3 x(ori.getColumn(0)); - MT_Vector3 y(ori.getColumn(1)); - MT_Vector3 z(ori.getColumn(2)); - MT_Vector3 parscale(x.length(), y.length(), z.length()); - if (!MT_fuzzyZero(parscale[0])) - x /= parscale[0]; - if (!MT_fuzzyZero(parscale[1])) - y /= parscale[1]; - if (!MT_fuzzyZero(parscale[2])) - z /= parscale[2]; - ori.setColumn(0, x); - ori.setColumn(1, y); - ori.setColumn(2, z); - parentinversenode->SetLocalOrientation(ori); - parentinversenode->SetLocalScale(parscale); + /* extract location, orientation and scale out of the inverse parent matrix */ + float invp_loc[3], invp_rot[3][3], invp_size[3]; + mat4_to_loc_rot_size(invp_loc, invp_rot, invp_size, blenderobject->parentinv); + + MT_Matrix3x3 invp_rot_mt; + invp_rot_mt.setValue3x3((float *) invp_rot); + parentinversenode->SetLocalPosition(MT_Point3(invp_loc)); + parentinversenode->SetLocalOrientation(invp_rot_mt); + parentinversenode->SetLocalScale(MT_Vector3(invp_size)); - parentinversenode->AddChild(gameobj->GetSGNode()); } + /* Note: world coordinates are calculated for all nodes when the scene graph + * is complete, after processing vec_parent_child */ + + // needed for python scripting logicmgr->RegisterGameObjectName(gameobj->GetName(),gameobj); @@ -1909,18 +1838,11 @@ static void bl_ConvertBlenderObject_Single( logicbrick_conversionlist->Add(gameobj->AddRef()); - if (converter->addInitFromFrame) { - posPrev=gameobj->NodeGetWorldPosition(); - angor=gameobj->NodeGetWorldOrientation(); - } + if (isInActiveLayer) { objectlist->Add(gameobj->AddRef()); - //tf.Add(gameobj->GetSGNode()); - - gameobj->NodeUpdateGS(0); gameobj->AddMeshUser(); - } else { @@ -1928,11 +1850,6 @@ static void bl_ConvertBlenderObject_Single( //at the end of this function if it is not a root object inactivelist->Add(gameobj->AddRef()); } - - if (converter->addInitFromFrame) { - gameobj->NodeSetLocalPosition(posPrev); - gameobj->NodeSetLocalOrientation(angor); - } } @@ -1951,8 +1868,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, #define BL_CONVERTBLENDEROBJECT_SINGLE \ bl_ConvertBlenderObject_Single(converter, \ - blenderscene, blenderobject, \ - inivel, iniang, \ + blenderobject, \ vec_parent_child, \ logicbrick_conversionlist, \ objectlist, inactivelist, sumolist, \ @@ -1974,7 +1890,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie, RAS_FrameSettings::RAS_FrameType frame_type; int aspect_width; int aspect_height; - vector<MT_Vector3> inivel,iniang; set<Group*> grouplist; // list of groups to be converted set<Object*> allblobj; // all objects converted set<Object*> groupobj; // objects from groups (never in active layer) @@ -2020,24 +1935,25 @@ void BL_ConvertBlenderObjects(struct Main* maggie, // no occlusion culling by default kxscene->SetDbvtOcclusionRes(0); + + /* Objects' Conversion */ + int activeLayerBitInfo = blenderscene->lay; - + // list of all object converted, active and inactive CListValue* sumolist = new CListValue(); - + vector<parentChildLink> vec_parent_child; - + CListValue* objectlist = kxscene->GetObjectList(); CListValue* inactivelist = kxscene->GetInactiveList(); CListValue* parentlist = kxscene->GetRootParentList(); - + SCA_LogicManager* logicmgr = kxscene->GetLogicManager(); SCA_TimeEventManager* timemgr = kxscene->GetTimeEventManager(); - + CListValue* logicbrick_conversionlist = new CListValue(); - - //SG_TreeFactory tf; - + // Convert actions to actionmap bAction *curAct; for (curAct = (bAction*)maggie->action.first; curAct; curAct=(bAction*)curAct->id.next) @@ -2046,6 +1962,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } SetDefaultLightMode(blenderscene); + // Let's support scene set. // Beware of name conflict in linked data, it will not crash but will create confusion // in Python scripting and in certain actuators (replace mesh). Linked scene *should* have @@ -2061,23 +1978,15 @@ void BL_ConvertBlenderObjects(struct Main* maggie, rendertools, converter, libloading); - - bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) !=0; - bool addobj=true; - - if (converter->addInitFromFrame) - if (!isInActiveLayer) - addobj=false; + bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) !=0; if (gameobj) { - if (addobj) - { /* macro calls object conversion funcs */ - BL_CONVERTBLENDEROBJECT_SINGLE; + /* macro calls object conversion funcs */ + BL_CONVERTBLENDEROBJECT_SINGLE; - if (gameobj->IsDupliGroup()) { - grouplist.insert(blenderobject->dup_group); - } + if (gameobj->IsDupliGroup()) { + grouplist.insert(blenderobject->dup_group); } /* Note about memory leak issues: @@ -2121,22 +2030,12 @@ void BL_ConvertBlenderObjects(struct Main* maggie, rendertools, converter, libloading); - - // this code is copied from above except that - // object from groups are never in active layer - bool isInActiveLayer = false; - bool addobj=true; - - if (converter->addInitFromFrame) - if (!isInActiveLayer) - addobj=false; + bool isInActiveLayer = false; if (gameobj) { - if (addobj) - { /* macro calls object conversion funcs */ - BL_CONVERTBLENDEROBJECT_SINGLE; - } + /* macro calls object conversion funcs */ + BL_CONVERTBLENDEROBJECT_SINGLE; if (gameobj->IsDupliGroup()) { @@ -2146,7 +2045,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } } - /* see comment above re: mem leaks */ gameobj->Release(); } @@ -2183,14 +2081,14 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } } } - - // create hierarchy information + int i; + + + /* Build the scene graph relations */ vector<parentChildLink>::iterator pcit; - for (pcit = vec_parent_child.begin();!(pcit==vec_parent_child.end());++pcit) { - struct Object* blenderchild = pcit->m_blenderchild; struct Object* blenderparent = blenderchild->parent; KX_GameObject* parentobj = converter->FindGameObject(blenderparent); @@ -2228,33 +2126,28 @@ void BL_ConvertBlenderObjects(struct Main* maggie, continue; } + /* override the parent relation type if not normal. + * If the type is not supported, the NormalParentRelation is kept. */ switch (blenderchild->partype) { case PARVERT1: { - // creat a new vertex parent relationship for this node. - KX_VertexParentRelation * vertex_parent_relation = KX_VertexParentRelation::New(); - pcit->m_gamechildnode->SetParentRelation(vertex_parent_relation); + pcit->m_gamechildnode->SetParentRelation(KX_VertexParentRelation::New()); break; } case PARSLOW: { - // creat a new slow parent relationship for this node. - KX_SlowParentRelation * slow_parent_relation = KX_SlowParentRelation::New(blenderchild->sf); - pcit->m_gamechildnode->SetParentRelation(slow_parent_relation); + pcit->m_gamechildnode->SetParentRelation(KX_SlowParentRelation::New(blenderchild->sf)); break; } case PARBONE: { - // parent this to a bone Bone *parent_bone = BKE_armature_find_bone_name(BKE_armature_from_object(blenderchild->parent), blenderchild->parsubstr); if (parent_bone) { - KX_BoneParentRelation *bone_parent_relation = KX_BoneParentRelation::New(parent_bone); - pcit->m_gamechildnode->SetParentRelation(bone_parent_relation); + pcit->m_gamechildnode->SetParentRelation(KX_BoneParentRelation::New(parent_bone)); } - break; } case PARSKEL: // skinned - ignore @@ -2267,19 +2160,19 @@ void BL_ConvertBlenderObjects(struct Main* maggie, // unhandled break; } - + parentobj-> GetSGNode()->AddChild(pcit->m_gamechildnode); } vec_parent_child.clear(); - // find 'root' parents (object that has not parents in SceneGraph) + /* Find all 'root' parents (objects that have no parents in SceneGraph) and init the world transforms */ for (i=0;i<sumolist->GetCount();++i) { KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i); if (gameobj->GetSGNode()->GetSGParent() == 0) { parentlist->Add(gameobj->AddRef()); - gameobj->NodeUpdateGS(0); + gameobj->GetSGNode()->UpdateWorldData(0, true); } } @@ -2290,7 +2183,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, for (i=0; i<sumolist->GetCount();i++) { KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i); - if (gameobj->GetMeshCount() > 0) + if (gameobj->GetMeshCount() > 0) { MT_Point3 box[2]; gameobj->GetSGNode()->BBox().getmm(box, MT_Transform::Identity()); @@ -2304,6 +2197,8 @@ void BL_ConvertBlenderObjects(struct Main* maggie, if (occlusion) kxscene->SetDbvtOcclusionRes(blenderscene->gm.occlusionRes); } + + if (blenderscene->world) kxscene->GetPhysicsEnvironment()->SetNumTimeSubSteps(blenderscene->gm.physubstep); @@ -2338,7 +2233,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } bool processCompoundChildren = false; - // create physics information for (i=0;i<sumolist->GetCount();i++) { @@ -2369,32 +2263,19 @@ void BL_ConvertBlenderObjects(struct Main* maggie, int layerMask = (groupobj.find(blenderobject) == groupobj.end()) ? activeLayerBitInfo : 0; BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,converter,processCompoundChildren); } - - //set ini linearVel and int angularVel //rcruiz - if (converter->addInitFromFrame) - for (i=0;i<sumolist->GetCount();i++) - { - KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i); - if (gameobj->IsDynamic()) { - gameobj->setLinearVelocity(inivel[i],false); - gameobj->setAngularVelocity(iniang[i],false); - } - - - } - // create physics joints + // create physics joints for (i=0;i<sumolist->GetCount();i++) { KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i); struct Object* blenderobject = gameobj->GetBlenderObject(); ListBase *conlist; bConstraint *curcon; - conlist = get_active_constraints2(blenderobject); if ((gameobj->GetLayer()&activeLayerBitInfo)==0) continue; + conlist = get_active_constraints2(blenderobject); if (conlist) { for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) { if (curcon->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) { @@ -2405,15 +2286,13 @@ void BL_ConvertBlenderObjects(struct Main* maggie, PHY_IPhysicsController* physctr2 = 0; - if (dat->tar) - { + if (dat->tar) { KX_GameObject *gotar=getGameOb(dat->tar->id.name+2,sumolist); if (gotar && ((gotar->GetLayer()&activeLayerBitInfo)!=0) && gotar->GetPhysicsController()) physctr2 = gotar->GetPhysicsController(); } - if (gameobj->GetPhysicsController()) - { + if (gameobj->GetPhysicsController()) { PHY_IPhysicsController* physctrl = gameobj->GetPhysicsController(); //we need to pass a full constraint frame, not just axis @@ -2422,62 +2301,47 @@ void BL_ConvertBlenderObjects(struct Main* maggie, MT_Vector3 axis0 = localCFrame.getColumn(0); MT_Vector3 axis1 = localCFrame.getColumn(1); MT_Vector3 axis2 = localCFrame.getColumn(2); - + int constraintId = kxscene->GetPhysicsEnvironment()->CreateConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX, (float)dat->pivY,(float)dat->pivZ, (float)axis0.x(),(float)axis0.y(),(float)axis0.z(), (float)axis1.x(),(float)axis1.y(),(float)axis1.z(), (float)axis2.x(),(float)axis2.y(),(float)axis2.z(),dat->flag); - if (constraintId) - { + if (constraintId) { //if it is a generic 6DOF constraint, set all the limits accordingly - if (dat->type == PHY_GENERIC_6DOF_CONSTRAINT) - { + if (dat->type == PHY_GENERIC_6DOF_CONSTRAINT) { int dof; int dofbit=1; - for (dof=0;dof<6;dof++) - { - if (dat->flag & dofbit) - { + for (dof=0;dof<6;dof++) { + if (dat->flag & dofbit) { kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,dat->minLimit[dof],dat->maxLimit[dof]); - } else - { + } else { //minLimit > maxLimit means free(disabled limit) for this degree of freedom kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,1,-1); } dofbit<<=1; } - } - else if (dat->type == PHY_CONE_TWIST_CONSTRAINT) - { + } else if (dat->type == PHY_CONE_TWIST_CONSTRAINT) { int dof; int dofbit = 1<<3; // bitflag use_angular_limit_x - - for (dof=3;dof<6;dof++) - { - if (dat->flag & dofbit) - { + + for (dof=3;dof<6;dof++) { + if (dat->flag & dofbit) { kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,dat->minLimit[dof],dat->maxLimit[dof]); - } - else - { + } else { //maxLimit < 0 means free(disabled limit) for this degree of freedom kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,1,-1); } dofbit<<=1; } - } - else if (dat->type == PHY_LINEHINGE_CONSTRAINT) - { + } else if (dat->type == PHY_LINEHINGE_CONSTRAINT) { int dof = 3; // dof for angular x int dofbit = 1<<3; // bitflag use_angular_limit_x - - if (dat->flag & dofbit) - { + + if (dat->flag & dofbit) { kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof, dat->minLimit[dof],dat->maxLimit[dof]); - } else - { + } else { //minLimit > maxLimit means free(disabled limit) for this degree of freedom kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,1,-1); } @@ -2537,8 +2401,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } } -#define CONVERT_LOGIC -#ifdef CONVERT_LOGIC // convert logic bricks, sensors, controllers and actuators for (i=0;i<logicbrick_conversionlist->GetCount();i++) { @@ -2573,8 +2435,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie, gameobj->ResetState(); } -#endif //CONVERT_LOGIC - logicbrick_conversionlist->Release(); // Calculate the scene btree - @@ -2601,7 +2461,3 @@ void BL_ConvertBlenderObjects(struct Main* maggie, bucketmanager->OptimizeBuckets(distance); } -SCA_IInputDevice::KX_EnumInputs ConvertKeyCode(int key_code) -{ - return gReverseKeyTranslateTable[key_code]; -} |