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

Method Add

Source/Engine/Tools/ModelTool/MeshAccelerationStructure.cpp:319–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

317}
318
319void MeshAccelerationStructure::Add(Model* model, int32 lodIndex)
320{
321 PROFILE_CPU();
322 lodIndex = Math::Clamp(lodIndex, model->HighestResidentLODIndex(), model->LODs.Count() - 1);
323 ModelLOD& lod = model->LODs[lodIndex];
324 _meshes.EnsureCapacity(_meshes.Count() + lod.Meshes.Count());
325 for (int32 i = 0; i < lod.Meshes.Count(); i++)
326 {
327 auto& mesh = lod.Meshes[i];
328 const MaterialSlot& materialSlot = model->MaterialSlots[mesh.GetMaterialSlotIndex()];
329 if (materialSlot.Material && !materialSlot.Material->WaitForLoaded())
330 {
331 // Skip transparent materials
332 if (materialSlot.Material->GetInfo().BlendMode != MaterialBlendMode::Opaque)
333 continue;
334 }
335
336 auto& meshData = _meshes.AddOne();
337 meshData.Asset = model;
338 model->AddReference();
339 MeshAccessor accessor;
340 MeshBufferType bufferTypes[2] = { MeshBufferType::Index, MeshBufferType::Vertex0 };
341 if (accessor.LoadMesh(&mesh, false, ToSpan(bufferTypes, 2)))
342 return;
343 auto indexStream = accessor.Index();
344 auto positionStream = accessor.Position();
345 if (!indexStream.IsValid() || !positionStream.IsValid())
346 return;
347 meshData.Indices = indexStream.GetCount();
348 meshData.Vertices = positionStream.GetCount();
349 meshData.IndexBuffer.Copy(indexStream.GetData());
350 meshData.VertexBuffer.Allocate(meshData.Vertices * sizeof(Float3));
351 positionStream.CopyTo(ToSpan(meshData.VertexBuffer.Get<Float3>(), meshData.Vertices));
352 meshData.Use16BitIndexBuffer = indexStream.GetFormat() == PixelFormat::R16_UInt;
353 meshData.Bounds = mesh.GetBox();
354 }
355}
356
357void MeshAccelerationStructure::Add(const ModelData* modelData, int32 lodIndex, bool copy)
358{

Callers 15

ProcessGroupMaterialMethod · 0.45
ProcessGroupTexturesMethod · 0.45
ProcessGroupToolsMethod · 0.45
SetupMethod · 0.45
AddLayerMethod · 0.45
prepareLayerMethod · 0.45
GenerateMethod · 0.45
VsToPsMethod · 0.45
DeserializeMethod · 0.45
SetupMethod · 0.45
GetFilesToDeployMethod · 0.45
ConvertWriteCallbackFunction · 0.45

Calls 15

ClampFunction · 0.85
WaitForLoadedMethod · 0.80
AddOneMethod · 0.80
PositionMethod · 0.80
CalculateBoxMethod · 0.80
ToSpanFunction · 0.50
CountMethod · 0.45
EnsureCapacityMethod · 0.45
GetInfoMethod · 0.45
AddReferenceMethod · 0.45
LoadMeshMethod · 0.45
IndexMethod · 0.45

Tested by

no test coverage detected