MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / CookCollision

Method CookCollision

Source/Engine/Physics/CollisionData.cpp:26–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24#if COMPILE_WITH_PHYSICS_COOKING
25
26bool CollisionData::CookCollision(CollisionDataType type, ModelBase* modelObj, int32 modelLodIndex, uint32 materialSlotsMask, ConvexMeshGenerationFlags convexFlags, int32 convexVertexLimit)
27{
28 if (!IsVirtual())
29 {
30 LOG(Warning, "Only virtual assets can be modified at runtime.");
31 return true;
32 }
33 if (IsInMainThread() && modelObj && modelObj->IsVirtual())
34 {
35 LOG(Error, "Cannot cook collision data for virtual models on a main thread (virtual models data is stored on GPU only). Use thread pool or async task.");
36 return true;
37 }
38 PROFILE_CPU();
39 PROFILE_MEM(Physics);
40
41 // Prepare
42 CollisionCooking::Argument arg;
43 arg.Type = type;
44 arg.Model = modelObj;
45 arg.ModelLodIndex = modelLodIndex;
46 arg.MaterialSlotsMask = materialSlotsMask;
47 arg.ConvexFlags = convexFlags;
48 arg.ConvexVertexLimit = convexVertexLimit;
49
50 // Cook collision
51 SerializedOptions options;
52 BytesContainer outputData;
53 if (CollisionCooking::CookCollision(arg, options, outputData))
54 return true;
55
56 // Load data
57 unload(true);
58 if (load(&options, outputData.Get(), outputData.Length()) != LoadResult::Ok)
59 return true;
60
61 // Mark as loaded (eg. Mesh Colliders using this asset will update shape for physics simulation)
62 onLoaded();
63 return false;
64}
65
66bool CollisionData::CookCollision(CollisionDataType type, const Span<Float3>& vertices, const Span<uint32>& triangles, ConvexMeshGenerationFlags convexFlags, int32 convexVertexLimit)
67{

Callers

nothing calls this directly

Calls 10

IsVirtualFunction · 0.85
IsInMainThreadFunction · 0.85
CookCollisionFunction · 0.85
loadFunction · 0.85
IsVirtualMethod · 0.80
GetMethod · 0.45
LengthMethod · 0.45
ResizeMethod · 0.45
AddMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected