void vHavokBehaviorComponent::InitVisionCharacter( VisBaseEntity_cl* entityOwner ) { m_entityOwner = entityOwner; m_isListeningToEvents = false; vHavokBehaviorModule* behaviorModule = vHavokBehaviorModule::GetInstance(); if( behaviorModule != HK_NULL ) { HK_ASSERT2(0x2f1c46e9, m_character == HK_NULL, "Character should be freed first." ); // Try to create a character. May fail if path/file settings are not specified m_character = behaviorModule->addCharacter( this ); if( m_character != HK_NULL ) { // Set up the animation config and create bone mapping UpdateAnimationAndBoneIndexList(); // Set character transform UpdateHavokTransformFromVision(); // Update the Physics UpdateBehaviorPhysics(); } } }
void vHavokBehaviorComponent::InitVisionCharacter( VisBaseEntity_cl* entityOwner ) { m_entityOwner = entityOwner; m_isListeningToEvents = false; vHavokBehaviorModule* behaviorModule = vHavokBehaviorModule::GetInstance(); if( behaviorModule != HK_NULL ) { HK_ASSERT2(0x2f1c46e9, m_character == HK_NULL, "Character should be freed first." ); // Try to create a character. May fail if path/file settings are not specified m_character = behaviorModule->addCharacter( this ); if( m_character != HK_NULL ) { // Set up the animation config and create bone mapping UpdateAnimationAndBoneIndexList(); // Set character transform UpdateHavokTransformFromVision(); // Update the Physics UpdateBehaviorPhysics(); // Tag ragdoll rigid bodies to be ignored by nav mesh cutting hkbRagdollDriver* ragdollDriver = m_character->getRagdollDriver(); if (ragdollDriver) { hkbRagdollInterface* ragdollInterface = ragdollDriver->getRagdollInterface(); if (ragdollInterface) { for (int i = 0; i < ragdollInterface->getNumBones(); i++) { hkpRigidBody* rigidBody = static_cast<hkpRigidBody*>(ragdollInterface->getRigidBodyOfBone(i)); if (rigidBody) { rigidBody->addProperty(VHAVOK_PROPERTY_DO_NO_CUT_NAV_MESH, 1); } } } } } } }
void vHavokBehaviorComponent::OnVariableValueChanged(VisVariable_cl *pVar, const char * value) { // Early out if we are simulating in the Editor if( Vision::Editor.IsInEditor() && Vision::Editor.IsPlaying() ) return; // In editor, exiting playmode, after SetOwner called with NULL, OnVariableValueChanged will be called for vartable entries VisBaseEntity_cl *const entityOwner = vstatic_cast<VisBaseEntity_cl*>(GetOwner()); if(!entityOwner) return; #if defined (_VISION_WIN32) if ( hkString::strCmp( pVar->name, "m_projectName" ) == 0 ) { // reset the previous setting of the Character and the Behavior properties m_characterName = ""; m_behaviorName = ""; Vision::Editor.SetVariableInEditor( this, "Character", "", false, false ); Vision::Editor.SetVariableInEditor( this, "Behavior", "", false, false ); } else if ( hkString::strCmp( pVar->name, "m_characterName" ) == 0 ) { // reset the previous setting of the Behavior property m_behaviorName = ""; Vision::Editor.SetVariableInEditor( this, "Behavior", "", false, false ); } #endif bool characterExists = false; // Make sure this character is in our module before attempting to do anything on variable change vHavokBehaviorModule* behaviorModule = vHavokBehaviorModule::GetInstance(); for( int i = 0; i < behaviorModule->m_visionCharacters.getSize(); i++ ) { if( behaviorModule->m_visionCharacters[i] == this ) { characterExists = true; if ( hkString::strCmp( pVar->name, "m_enableRagdoll" ) == 0 || hkString::strCmp( pVar->name, "m_useBehaviorWorldFromModel" ) == 0 ) { UpdateBehaviorPhysics(); } else { // Cleanup DeInit(); // Reinit InitVisionCharacter( entityOwner ); } // Step the character once to update pose SingleStepCharacter(); break; } } // If the character doesn't exist yet, try to create it if(!characterExists) { InitVisionCharacter(entityOwner); SingleStepCharacter(); } }