FByteBulkData* UBodySetup::GetCookedData(FName Format) { if (IsTemplate()) { return NULL; } IInterface_CollisionDataProvider* CDP = Cast<IInterface_CollisionDataProvider>(GetOuter()); // If there is nothing to cook or if we are reading data from a cooked package for an asset with no collision, // we want to return here if ((AggGeom.ConvexElems.Num() == 0 && CDP == NULL) || !bHasCookedCollisionData) { return NULL; } FFormatContainer* UseCookedData = CookedFormatDataOverride ? CookedFormatDataOverride : &CookedFormatData; bool bContainedData = UseCookedData->Contains(Format); FByteBulkData* Result = &UseCookedData->GetFormat(Format); #if WITH_PHYSX if (!bContainedData) { if (FPlatformProperties::RequiresCookedData()) { UE_LOG(LogPhysics, Error, TEXT("Attempt to build physics data for %s when we are unable to. This platform requires cooked packages."), *GetPathName()); } if (AggGeom.ConvexElems.Num() == 0 && (CDP == NULL || CDP->ContainsPhysicsTriMeshData(bMeshCollideAll) == false)) { return NULL; } #if WITH_RUNTIME_PHYSICS_COOKING || WITH_EDITOR TArray<uint8> OutData; FDerivedDataPhysXCooker* DerivedPhysXData = new FDerivedDataPhysXCooker(Format, this); if (DerivedPhysXData->CanBuild()) { #if WITH_EDITOR GetDerivedDataCacheRef().GetSynchronous(DerivedPhysXData, OutData); #elif WITH_RUNTIME_PHYSICS_COOKING DerivedPhysXData->Build(OutData); #endif if (OutData.Num()) { Result->Lock(LOCK_READ_WRITE); FMemory::Memcpy(Result->Realloc(OutData.Num()), OutData.GetData(), OutData.Num()); Result->Unlock(); } } else #endif { UE_LOG(LogPhysics, Warning, TEXT("Attempt to build physics data for %s when we are unable to."), *GetPathName()); } } #endif // WITH_PHYSX check(Result); return Result->GetBulkDataSize() > 0 ? Result : NULL; // we don't return empty bulk data...but we save it to avoid thrashing the DDC }
bool FDerivedDataPhysXCooker::ShouldGenerateTriMeshData(bool InUseAllTriData) { check(Cooker != NULL); IInterface_CollisionDataProvider* CDP = Cast<IInterface_CollisionDataProvider>(CollisionDataProvider); const bool bPerformCook = ( CDP != NULL ) ? CDP->ContainsPhysicsTriMeshData(InUseAllTriData) : false; return bPerformCook; }