FByteBulkData* UNavCollision::GetCookedData(FName Format) { if (IsTemplate()) { return NULL; } bool bContainedData = CookedFormatData.Contains(Format); FByteBulkData* Result = &CookedFormatData.GetFormat(Format); if (!bContainedData) { if (FPlatformProperties::RequiresCookedData()) { UE_LOG(LogNavigation, Fatal, TEXT("Attempt to build nav collision data for %s when we are unable to. This platform requires cooked packages."), *GetPathName()); } TArray<uint8> OutData; FDerivedDataNavCollisionCooker* DerivedNavCollisionData = new FDerivedDataNavCollisionCooker(Format, this); if (DerivedNavCollisionData->CanBuild() && GetDerivedDataCacheRef().GetSynchronous(DerivedNavCollisionData, OutData)) { if (OutData.Num()) { Result->Lock(LOCK_READ_WRITE); FMemory::Memcpy(Result->Realloc(OutData.Num()), OutData.GetData(), OutData.Num()); Result->Unlock(); } } } check(Result); return Result->GetBulkDataSize() > 0 ? Result : NULL; // we don't return empty bulk data...but we save it to avoid thrashing the DDC }
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 }
FByteBulkData* USoundWave::GetCompressedData(FName Format) { if (IsTemplate() || IsRunningDedicatedServer()) { return NULL; } bool bContainedData = CompressedFormatData.Contains(Format); FByteBulkData* Result = &CompressedFormatData.GetFormat(Format); if (!bContainedData) { if (!FPlatformProperties::RequiresCookedData() && GetDerivedDataCache()) { TArray<uint8> OutData; FDerivedAudioDataCompressor* DeriveAudioData = new FDerivedAudioDataCompressor(this, Format); GetDerivedDataCacheRef().GetSynchronous(DeriveAudioData, OutData); if (OutData.Num()) { Result->Lock(LOCK_READ_WRITE); FMemory::Memcpy(Result->Realloc(OutData.Num()), OutData.GetData(), OutData.Num()); Result->Unlock(); } } else { UE_LOG(LogAudio, Error, TEXT("Attempt to access the DDC when there is none available on sound '%s', format = %s. Should have been cooked."), *GetFullName(), *Format.ToString()); } } check(Result); return Result->GetBulkDataSize() > 0 ? Result : NULL; // we don't return empty bulk data...but we save it to avoid thrashing the DDC }
FByteBulkData* UPhysicsSerializer::GetBinaryData(FName Format, const TArray<FBodyInstance*>& Bodies, const TArray<class UBodySetup*>& BodySetups, const TArray<class UPhysicalMaterial*>& PhysicalMaterials) { if (!FParse::Param(FCommandLine::Get(), TEXT("PhysxSerialization"))) { return nullptr; } #if PLATFORM_MAC return nullptr; //This is not supported right now #endif QUICK_SCOPE_CYCLE_COUNTER(STAT_GetBinaryData); const bool bContainedData = BinaryFormatData.Contains(Format); FByteBulkData* Result = &BinaryFormatData.GetFormat(Format); if (!FParse::Param(FCommandLine::Get(), TEXT("NoPhysxAlignment"))) { Result->SetBulkDataAlignment(PHYSX_SERIALIZATION_ALIGNMENT); } if (!bContainedData) { #if WITH_EDITOR #if WITH_PHYSX TArray<uint8> OutData; FDerivedDataPhysXBinarySerializer* DerivedPhysXSerializer = new FDerivedDataPhysXBinarySerializer(Format, Bodies, BodySetups, PhysicalMaterials, FGuid::NewGuid()); //TODO: Maybe it's worth adding this to the DDC. For now there's a lot of complexity with the guid invalidation so I've left it out. if (DerivedPhysXSerializer->CanBuild()) { DerivedPhysXSerializer->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 use binary physics data but we are unable to.")); } } return Result->GetBulkDataSize() > 0 ? Result : nullptr; }