Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Converter/BL_BlenderDataConversion.cpp
| 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; | |||||
| 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. | |||||
| rendertools, | rendertools, | ||||
| 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()); | |||||
| // this code is copied from above except that | // this code is copied from above except that | ||||
| // object from groups are never in active layer | // object from groups are never in active layer | ||||
sybren: Style: Spaces around `=` and after commas. | |||||
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() &… | |||||
Not Done Inline ActionsThis can be moved outside the loop. sybren: This can be moved outside the loop. | |||||
Not Done Inline ActionsStyle: spaces around = and !=. sybren: Style: spaces around `=` and `!=`. | |||||
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" ;-) | |||||
| Context not available. | |||||
| bConstraint *curcon; | bConstraint *curcon; | ||||
| conlist = get_active_constraints2(blenderobject); | conlist = get_active_constraints2(blenderobject); | ||||
| if ((gameobj->GetLayer()&activeLayerBitInfo)==0) | |||||
| continue; | |||||
| if (conlist) { | if (conlist) { | ||||
| for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) { | for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) { | ||||
| if (curcon->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) { | if (curcon->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) { | ||||
sybrenUnsubmitted 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… | |||||
| bRigidBodyJointConstraint *dat = (bRigidBodyJointConstraint *)curcon->data; | |||||
| if (dat->tar && !dat->child && !(curcon->flag & CONSTRAINT_OFF)) { | |||||
sybrenUnsubmitted 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`… | |||||
| /* store constraints of grouped objects and instances objects for all layers */ | |||||
| gameobj->AddConstraint(dat); | |||||
| /* Prevents Blender to crash, object was already converted or constraint is added | |||||
| * to a game object for later replication */ | |||||
| bool skip = false; | |||||
| set<KX_GameObject*>::iterator gobit; | |||||
| for (gobit=convertedlist.begin(); gobit != convertedlist.end(); gobit++) { | |||||
| if((*gobit)->GetName() == gameobj->GetName()) { | |||||
| skip = true; | |||||
| break; | |||||
| } | |||||
| } | |||||
| bRigidBodyJointConstraint *dat=(bRigidBodyJointConstraint *)curcon->data; | if(skip) | ||||
| continue; | |||||
| if (!dat->child && !(curcon->flag & CONSTRAINT_OFF)) { | |||||
| PHY_IPhysicsController* physctr2 = 0; | KX_GameObject *gotar = getGameOb(dat->tar->id.name + 2, sumolist); | ||||
| if (dat->tar) | if (gotar && ((gotar->GetLayer()&activeLayerBitInfo) != 0) && gotar->GetPhysicsController() | ||||
| && ((gameobj->GetLayer()&activeLayerBitInfo) != 0) && gameobj->GetPhysicsController()) | |||||
| { | { | ||||
| KX_GameObject *gotar=getGameOb(dat->tar->id.name+2,sumolist); | PHY_IPhysicsEnvironment *physEnv = kxscene->GetPhysicsEnvironment(); | ||||
| if (gotar && ((gotar->GetLayer()&activeLayerBitInfo)!=0) && gotar->GetPhysicsController()) | physEnv->SetupObjectConstraints(gameobj, gotar, dat); | ||||
| physctr2 = gotar->GetPhysicsController(); | |||||
| } | |||||
| if (gameobj->GetPhysicsController()) | |||||
| { | |||||
| PHY_IPhysicsController* physctrl = gameobj->GetPhysicsController(); | |||||
| //we need to pass a full constraint frame, not just axis | |||||
| //localConstraintFrameBasis | |||||
| MT_Matrix3x3 localCFrame(MT_Vector3(dat->axX,dat->axY,dat->axZ)); | |||||
| 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 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); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| /* cleanup converted set of group objects */ | |||||
| set<KX_GameObject*>::iterator gobit; | |||||
| for (gobit=convertedlist.begin(); gobit!=convertedlist.end(); gobit++) | |||||
| (*gobit)->Release(); | |||||
| convertedlist.clear(); | |||||
| sumolist->Release(); | sumolist->Release(); | ||||
| // convert world | // convert world | ||||
| Context not available. | |||||
Style: Spaces around = and after commas.