void vHavokStaticMesh::CreateHkRigidBody() { // Create the Havok shape hkpRigidBodyCinfo cInfo; cInfo.m_motionType = hkpMotion::MOTION_FIXED; // We use the first static mesh instance as origin reference VisStaticMeshInstance_cl *pMeshInstance = m_staticMeshes[0]; cInfo.m_collisionFilterInfo = pMeshInstance->GetCollisionBitmask(); if (cInfo.m_collisionFilterInfo & (1<<15)) { cInfo.m_collisionFilterInfo &= ~(1<<15); Vision::Error.Warning("vHavok: Static mesh [%s] has outdated collision information. Please reexport scene.", pMeshInstance->GetMesh()->GetFilename()); } // Get the scaling of the first static mesh which is used as a reference { hkMatrix4 mTransform; vHavokConversionUtils::VisMatrixToHkMatrix(m_staticMeshes[0]->GetTransform(), mTransform, false, false, true); hkVector4 vScale; vScale.set( mTransform.getColumn<0>().lengthSquared<3>(), mTransform.getColumn<1>().lengthSquared<3>(), mTransform.getColumn<2>().lengthSquared<3>(), hkSimdReal_1); vScale.setSqrt(vScale); vHavokConversionUtils::PhysVecToVisVec_noscale(vScale,m_vScale); } // Create the shape. // We can either create the shape from mem, or serialize it in (if cached). // Do not set vHavokShapeFactory::VShapeCreationFlags_SHRINK, so back compat. Better to have as an option. const int iCreationFlags = (pMeshInstance->GetCollisionBehavior()==VisStaticMeshInstance_cl::VIS_COLLISION_BEHAVIOR_FROMFILE) ? vHavokShapeFactory::VShapeCreationFlags_ALLOW_PERTRICOLINFO : 0; hkRefPtr<hkpShape> spShape = vHavokShapeFactory::CreateShapeFromStaticMeshInstances(m_staticMeshes, iCreationFlags, &m_szShapeCacheId); cInfo.m_shape = spShape; // When CollisionBehavior_e::FromFile was selected and there is no collisionFilterInfo available from file (due to old vcolmesh format, convex shape), // a default collisionFilterInfo will be used. if (cInfo.m_collisionFilterInfo==0) { bool bHasMaterialCacheData = false; const hkpShape *pShape = (hkpShape*)spShape.val(); const hkClass *pClass = pShape->getClassType(); if (pClass == &hkvBvCompressedMeshShapeClass) { const hkvBvCompressedMeshShape *pMeshShape = (hkvBvCompressedMeshShape*)(pShape); bHasMaterialCacheData = pMeshShape->m_userData != HK_NULL; } if (!bHasMaterialCacheData) cInfo.m_collisionFilterInfo = vHavokPhysicsModule::HK_LAYER_COLLIDABLE_STATIC; } cInfo.m_numShapeKeysInContactPointProperties = -1; // Ensure shape keys are stored. m_pRigidBody = new hkpRigidBody(cInfo); // Set user data to identify this static mesh during collision detection m_pRigidBody->setUserData((hkUlong)vHavokUserDataPointerPair_t::CombineTypeAndPointer(this, V_USERDATA_STATIC)); // Add our instance to the module UpdateVision2Havok(); m_module.AddStaticMesh(this); }