Changeset View
Standalone View
source/gameengine/Converter/BL_BlenderDataConversion.cpp
| Context not available. | |||||
| } | } | ||||
| static bool bl_FindConstraint(KX_GameObject *gameobj, set<KX_GameObject*> convertedlist) | |||||
sybren: To me the name "findConstraint" suggests it finds a constraint and returns it. This seems more… | |||||
| { | |||||
| set<KX_GameObject*>::iterator gobit; | |||||
| for (gobit = convertedlist.begin(); gobit != convertedlist.end(); gobit++) { | |||||
| if ((*gobit)->GetName() == gameobj->GetName()) | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /* helper for BL_ConvertBlenderObjects, avoids code duplication | /* helper for BL_ConvertBlenderObjects, avoids code duplication | ||||
| * note: all var names match args are passed from the caller */ | * note: all var names match args are passed from the caller */ | ||||
| static void bl_ConvertBlenderObject_Single( | static void bl_ConvertBlenderObject_Single( | ||||
| Context not available. | |||||
| // is not in a separate thread. | // is not in a separate thread. | ||||
| BL_Texture::GetMaxUnits(); | BL_Texture::GetMaxUnits(); | ||||
| /* we have to ensure that group definitions are only converted once | |||||
| * push all converted group members to this set */ | |||||
| set<KX_GameObject*> convertedlist; | |||||
sybrenUnsubmitted Not Done Inline ActionsPlease add a comment that explains in which situations it is possible that a constraint would be converted twice, as this won't be obvious to everybody. You've invested time to understand this topic -- ensure that your knowledge of why things are done the way they are done is saved for future developers (including future you) ;-) sybren: Please add a comment that explains in which situations it is possible that a constraint would… | |||||
| if (alwaysUseExpandFraming) { | if (alwaysUseExpandFraming) { | ||||
| frame_type = RAS_FrameSettings::e_frame_extend; | frame_type = RAS_FrameSettings::e_frame_extend; | ||||
| aspect_width = canvas->GetWidth(); | aspect_width = canvas->GetWidth(); | ||||
| Context not available. | |||||
| converter, | converter, | ||||
| libloading); | libloading); | ||||
| /* insert object to the constraint game object list | |||||
| * so we can check later if there is a instance in the scene or | |||||
| * an instance and its actual group definition */ | |||||
| convertedlist.insert((KX_GameObject*)gameobj->AddRef()); | |||||
| bool isInActiveLayer = false; | bool isInActiveLayer = false; | ||||
| if (gameobj) | if (gameobj) | ||||
| { | { | ||||
| Context not available. | |||||
| ListBase *conlist; | ListBase *conlist; | ||||
| bConstraint *curcon; | bConstraint *curcon; | ||||
| if ((gameobj->GetLayer()&activeLayerBitInfo)==0) | |||||
| continue; | |||||
| conlist = get_active_constraints2(blenderobject); | conlist = get_active_constraints2(blenderobject); | ||||
| if (conlist) { | |||||
| for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) { | |||||
| if (curcon->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) { | |||||
| bRigidBodyJointConstraint *dat=(bRigidBodyJointConstraint *)curcon->data; | if (!conlist) | ||||
| continue; | |||||
| if (!dat->child && !(curcon->flag & CONSTRAINT_OFF)) { | for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) { | ||||
| if (curcon->type != CONSTRAINT_TYPE_RIGIDBODYJOINT) | |||||
| continue; | |||||
| PHY_IPhysicsController* physctr2 = 0; | bRigidBodyJointConstraint *dat = (bRigidBodyJointConstraint *)curcon->data; | ||||
| if (!dat->tar || dat->child || (curcon->flag & CONSTRAINT_OFF)) | |||||
sybrenUnsubmitted Not Done Inline ActionsWhy can these cases be skipped? Maybe add a comment that explains this. sybren: Why can these cases be skipped? Maybe add a comment that explains this. | |||||
Not Done Inline ActionsSkipp has one "p" ;-) sybren: Skipp has one "p" ;-) | |||||
| continue; | |||||
| if (dat->tar) { | /* Store constraints of grouped and instanced objects for all layers */ | ||||
| KX_GameObject *gotar=getGameOb(dat->tar->id.name+2,sumolist); | gameobj->AddConstraint(dat); | ||||
| if (gotar && ((gotar->GetLayer()&activeLayerBitInfo)!=0) && gotar->GetPhysicsController()) | |||||
| physctr2 = gotar->GetPhysicsController(); | /* Skipped already converted constraints */ | ||||
| } | if (bl_FindConstraint(gameobj, convertedlist)) | ||||
| continue; | |||||
| if (gameobj->GetPhysicsController()) { | KX_GameObject *gotar=getGameOb(dat->tar->id.name+2,sumolist); | ||||
sybrenUnsubmitted Not Done Inline ActionsStyle: Spaces around = and after commas. sybren: Style: Spaces around `=` and after commas. | |||||
| PHY_IPhysicsController* physctrl = gameobj->GetPhysicsController(); | |||||
| //we need to pass a full constraint frame, not just axis | if (gotar && ((gotar->GetLayer()&activeLayerBitInfo) != 0) && gotar->GetPhysicsController() | ||||
sybrenUnsubmitted Not Done Inline Actions((gotar->GetLayer()&activeLayerBitInfo) != 0) can be written as (gotar->GetLayer() & activeLayerBitInfo) sybren: `((gotar->GetLayer()&activeLayerBitInfo) != 0)` can be written as `(gotar->GetLayer() &… | |||||
| && ((gameobj->GetLayer()&activeLayerBitInfo) != 0) && gameobj->GetPhysicsController()) | |||||
| //localConstraintFrameBasis | { | ||||
| MT_Matrix3x3 localCFrame(MT_Vector3(dat->axX,dat->axY,dat->axZ)); | PHY_IPhysicsEnvironment *physEnv = kxscene->GetPhysicsEnvironment(); | ||||
sybrenUnsubmitted Not Done Inline ActionsThis can be moved outside the loop. sybren: This can be moved outside the loop. | |||||
| MT_Vector3 axis0 = localCFrame.getColumn(0); | physEnv->SetupObjectConstraints(gameobj, gotar, dat); | ||||
| 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 it is a generic 6DOF constraint, set all the limits accordingly | |||||
| if (dat->type == PHY_GENERIC_6DOF_CONSTRAINT) { | |||||
| int dof; | |||||
| int dofbit=1; | |||||
| for (dof=0;dof<6;dof++) { | |||||
| if (dat->flag & dofbit) { | |||||
| kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,dat->minLimit[dof],dat->maxLimit[dof]); | |||||
| } 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) { | |||||
| int dof; | |||||
| int dofbit = 1<<3; // bitflag use_angular_limit_x | |||||
| for (dof=3;dof<6;dof++) { | |||||
| if (dat->flag & dofbit) { | |||||
| kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,dat->minLimit[dof],dat->maxLimit[dof]); | |||||
| } 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) { | |||||
| int dof = 3; // dof for angular x | |||||
| int dofbit = 1<<3; // bitflag use_angular_limit_x | |||||
| if (dat->flag & dofbit) { | |||||
| kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof, | |||||
| dat->minLimit[dof],dat->maxLimit[dof]); | |||||
| } else { | |||||
| //minLimit > maxLimit means free(disabled limit) for this degree of freedom | |||||
| kxscene->GetPhysicsEnvironment()->SetConstraintParam(constraintId,dof,1,-1); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* cleanup converted set of group objects */ | |||||
| set<KX_GameObject*>::iterator gobit; | |||||
| for (gobit=convertedlist.begin(); gobit!=convertedlist.end(); gobit++) | |||||
sybrenUnsubmitted Not Done Inline ActionsStyle: spaces around = and !=. sybren: Style: spaces around `=` and `!=`. | |||||
| (*gobit)->Release(); | |||||
| convertedlist.clear(); | |||||
| sumolist->Release(); | sumolist->Release(); | ||||
| // convert world | // convert world | ||||
| Context not available. | |||||
Not Done Inline ActionsThis could be replaced with if (curcon->type != CONSTRAINT_TYPE_RIGIDBODYJOINT) continue; to unindent the rest of the code block. sybren: This could be replaced with `if (curcon->type != CONSTRAINT_TYPE_RIGIDBODYJOINT) continue;` to… | |||||
Not Done Inline ActionsThe body of this if seems complicated enough to warrant its own method. Setting skip = true and then testing for that, it would simply be return when a separate method is used. sybren: The body of this `if` seems complicated enough to warrant its own method. Setting `skip = true`… | |||||
To me the name "findConstraint" suggests it finds a constraint and returns it. This seems more like an "isConstraintInList" kind of function. Also it needs a comment to describe its intended use.