| 251 | }; |
| 252 | |
| 253 | bool 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 | { |
nothing calls this directly
no test coverage detected