void DialogAFConstraint::OnBnClickedButtonRenameconstraint() { int i; CString name, newName; DialogAFName nameDlg; if ( !file || !constraint ) { return; } i = m_comboConstraintList.GetCurSel(); if ( i != CB_ERR ) { m_comboConstraintList.GetLBText( i, name ); nameDlg.SetName( name ); nameDlg.SetComboBox( &m_comboConstraintList ); if ( nameDlg.DoModal() == IDOK ) { nameDlg.GetName( newName ); // rename constraint; file->RenameConstraint( name, newName ); m_comboConstraintList.DeleteString( i ); m_comboConstraintList.SetCurSel( m_comboConstraintList.AddString( newName ) ); LoadConstraint( newName ); gameEdit->AF_UpdateEntities( file->GetName() ); AFDialogSetFileModified(); } } }
void DialogAFConstraint::OnBnClickedButtonNewconstraint() { DialogAFName nameDlg; CString str; nameDlg.SetComboBox( &m_comboConstraintList ); if ( nameDlg.DoModal() == IDOK ) { nameDlg.GetName( str ); // create new constraint file->NewConstraint( str ); m_comboConstraintList.SetCurSel( m_comboConstraintList.AddString( str ) ); LoadConstraint( str ); gameEdit->AF_UpdateEntities( file->GetName() ); AFDialogSetFileModified(); } InitNewRenameDeleteButtons(); }
/* ================ DialogAFConstraint::InitConstraintList ================ */ void DialogAFConstraint::InitConstraintList( void ) { CString str; m_comboConstraintList.ResetContent(); if ( !file ) { return; } for ( int i = 0; i < file->constraints.Num(); i++ ) { m_comboConstraintList.AddString( file->constraints[i]->name.c_str() ); } if ( m_comboConstraintList.GetCount() != 0 ) { m_comboConstraintList.SetCurSel( 0 ); m_comboConstraintList.GetLBText( 0, str ); LoadConstraint( str ); } }
/* ================ idAF::Load ================ */ bool idAF::Load( idEntity *ent, const char *fileName ) { int i, j; const idDeclAF *file; const idDeclModelDef *modelDef; idRenderModel *model; int numJoints; idJointMat *joints; assert( ent ); self = ent; physicsObj.SetSelf( self ); if( animator == NULL ) { gameLocal.DWarning( "Couldn't load af '%s' for entity '%s' at (%s): NULL animator\n", name.c_str(), ent->name.c_str(), ent->GetPhysics()->GetOrigin().ToString( 0 ) ); return false; } name = fileName; name.StripFileExtension(); file = static_cast<const idDeclAF *>( declManager->FindType( DECL_AF, name ) ); if( !file ) { gameLocal.DWarning( "Couldn't load af '%s' for entity '%s' at (%s)\n", name.c_str(), ent->name.c_str(), ent->GetPhysics()->GetOrigin().ToString( 0 ) ); return false; } if( file->bodies.Num() == 0 || file->bodies[0]->jointName != "origin" ) { gameLocal.DWarning( "idAF::Load: articulated figure '%s' for entity '%s' at (%s) has no body which modifies the origin joint.", name.c_str(), ent->name.c_str(), ent->GetPhysics()->GetOrigin().ToString( 0 ) ); return false; } modelDef = animator->ModelDef(); if( modelDef == NULL || modelDef->GetState() == DS_DEFAULTED ) { gameLocal.DWarning( "idAF::Load: articulated figure '%s' for entity '%s' at (%s) has no or defaulted modelDef '%s'", name.c_str(), ent->name.c_str(), ent->GetPhysics()->GetOrigin().ToString( 0 ), modelDef ? modelDef->GetName() : "" ); return false; } model = animator->ModelHandle(); if( model == NULL || model->IsDefaultModel() ) { gameLocal.DWarning( "idAF::Load: articulated figure '%s' for entity '%s' at (%s) has no or defaulted model '%s'", name.c_str(), ent->name.c_str(), ent->GetPhysics()->GetOrigin().ToString( 0 ), model ? model->Name() : "" ); return false; } // get the modified animation modifiedAnim = animator->GetAnim( ARTICULATED_FIGURE_ANIM ); if( !modifiedAnim ) { gameLocal.DWarning( "idAF::Load: articulated figure '%s' for entity '%s' at (%s) has no modified animation '%s'", name.c_str(), ent->name.c_str(), ent->GetPhysics()->GetOrigin().ToString( 0 ), ARTICULATED_FIGURE_ANIM ); return false; } // create the animation frame used to setup the articulated figure numJoints = animator->NumJoints(); joints = ( idJointMat * )_alloca16( numJoints * sizeof( joints[0] ) ); gameEdit->ANIM_CreateAnimFrame( model, animator->GetAnim( modifiedAnim )->MD5Anim( 0 ), numJoints, joints, 1, animator->ModelDef()->GetVisualOffset(), animator->RemoveOrigin() ); // set all vector positions from model joints file->Finish( GetJointTransform, joints, animator ); // initialize articulated figure physics physicsObj.SetGravity( gameLocal.GetGravity() ); physicsObj.SetClipMask( file->clipMask ); physicsObj.SetDefaultFriction( file->defaultLinearFriction, file->defaultAngularFriction, file->defaultContactFriction ); physicsObj.SetSuspendSpeed( file->suspendVelocity, file->suspendAcceleration ); physicsObj.SetSuspendTolerance( file->noMoveTime, file->noMoveTranslation, file->noMoveRotation ); physicsObj.SetSuspendTime( file->minMoveTime, file->maxMoveTime ); physicsObj.SetSelfCollision( file->selfCollision ); // clear the list with transforms from joints to bodies jointMods.SetNum( 0, false ); // clear the joint to body conversion list jointBody.AssureSize( animator->NumJoints() ); for( i = 0; i < jointBody.Num(); i++ ) { jointBody[i] = -1; } // delete any bodies in the physicsObj that are no longer in the idDeclAF for( i = 0; i < physicsObj.GetNumBodies(); i++ ) { idAFBody *body = physicsObj.GetBody( i ); for( j = 0; j < file->bodies.Num(); j++ ) { if( file->bodies[j]->name.Icmp( body->GetName() ) == 0 ) { break; } } if( j >= file->bodies.Num() ) { physicsObj.DeleteBody( i ); i--; } } // delete any constraints in the physicsObj that are no longer in the idDeclAF for( i = 0; i < physicsObj.GetNumConstraints(); i++ ) { idAFConstraint *constraint = physicsObj.GetConstraint( i ); for( j = 0; j < file->constraints.Num(); j++ ) { if( file->constraints[j]->name.Icmp( constraint->GetName() ) == 0 && file->constraints[j]->type == constraint->GetType() ) { break; } } if( j >= file->constraints.Num() ) { physicsObj.DeleteConstraint( i ); i--; } } // load bodies from the file for( i = 0; i < file->bodies.Num(); i++ ) { LoadBody( file->bodies[i], joints ); } // load constraints from the file for( i = 0; i < file->constraints.Num(); i++ ) { LoadConstraint( file->constraints[i] ); } physicsObj.UpdateClipModels(); // check if each joint is contained by a body for( i = 0; i < animator->NumJoints(); i++ ) { if( jointBody[i] == -1 ) { gameLocal.DWarning( "idAF::Load: articulated figure '%s' for entity '%s' at (%s) joint '%s' is not contained by a body", name.c_str(), self->name.c_str(), self->GetPhysics()->GetOrigin().ToString( 0 ), animator->GetJointName( ( jointHandle_t )i ) ); } } physicsObj.SetMass( file->totalMass ); physicsObj.SetChanged(); // disable the articulated figure for collision detection until activated physicsObj.DisableClip(); isLoaded = true; return true; }
void DialogAFConstraint::OnCbnSelchangeComboConstraints() { CString str; GetSafeComboBoxSelection( &m_comboConstraintList, str, -1 ); LoadConstraint( str ); }