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

Method buildInner

Source/Engine/CSG/CSGBuilder.cpp:253–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251};
252
253bool CSGBuilderImpl::buildInner(Scene* scene, BuildData& data)
254{
255 // Setup CSG meshes list and build them
256 {
257 Function<bool(Actor*, MeshesArray&, MeshesLookup&)> treeWalkFunction(walkTree);
258 SceneQuery::TreeExecute<Array<CSG::Mesh*>&, MeshesLookup&>(treeWalkFunction, data.meshes, data.cache);
259 }
260 if (data.meshes.IsEmpty())
261 return false;
262
263 // Process all meshes (performs actual CSG opterations on geometry in tree structure)
264 CSG::Mesh* combinedMesh = Combine(scene, data.cache);
265 if (combinedMesh == nullptr)
266 return false;
267
268 // TODO: split too big meshes (too many verts, to far parts, etc.)
269
270 // Triangulate meshes
271 {
272 // TODO: setup valid loop for splited meshes
273
274 // Convert CSG meshes into raw triangles data
275 RawData meshData;
276 Array<MeshVertex> vertexBuffer;
277 combinedMesh->Triangulate(meshData, vertexBuffer);
278 meshData.RemoveEmptySlots();
279 if (meshData.Slots.HasItems())
280 {
281 const auto sceneDataFolderPath = scene->GetDataFolderPath();
282
283 // Convert CSG mesh data to common storage type
284 ModelData modelData;
285 meshData.ToModelData(modelData);
286
287 // Convert CSG mesh to the local transformation of the scene
288 if (!scene->GetTransform().IsIdentity())
289 {
290 Matrix t;
291 scene->GetWorldToLocalMatrix(t);
292 modelData.TransformBuffer(t);
293 }
294
295 // Import model data to the asset
296 {
297 Guid modelDataAssetId = scene->CSGData.Model.GetID();
298 if (!modelDataAssetId.IsValid())
299 modelDataAssetId = Guid::New();
300 const String modelDataAssetPath = sceneDataFolderPath / TEXT("CSG_Mesh") + ASSET_FILES_EXTENSION_WITH_DOT;
301 if (AssetsImportingManager::Create(AssetsImportingManager::CreateModelTag, modelDataAssetPath, modelDataAssetId, &modelData))
302 {
303 LOG(Warning, "Failed to import CSG mesh data");
304 return true;
305 }
306 data.outputModelAssetId = modelDataAssetId;
307 }
308
309 // Generate asset with CSG mesh metadata (for collisions and brush queries)
310 {

Callers

nothing calls this directly

Calls 15

CombineFunction · 0.85
RemoveEmptySlotsMethod · 0.80
GetDataFolderPathMethod · 0.80
ToModelDataMethod · 0.80
IsIdentityMethod · 0.80
GetTransformMethod · 0.80
GetWorldToLocalMatrixMethod · 0.80
TransformBufferMethod · 0.80
GetIDMethod · 0.80
NewFunction · 0.50
CreateFunction · 0.50
InvertFunction · 0.50

Tested by

no test coverage detected