private void AddMeshes(Node node, CModelAsset asset, string assetPath, CMeshLoadingJob loadingJob, ref Matrix transform) { Matrix previousTransform = transform; transform = Matrix.Multiply(previousTransform, FromAssimpMatrix(node.Transform)); if (node.HasMeshes) { foreach (int meshIndex in node.MeshIndices) { CMeshAsset meshAsset = new CMeshAsset(); // We always import all meshes in a file so we use always import here LoadMeshInternal(meshIndex, meshAsset, loadingJob, assetPath, null, true); meshAsset.LoadFinished(); SMeshChild modelChild = new SMeshChild() { meshAsset = meshAsset, relativeTransform = transform }; asset.MeshChildren.Add(modelChild); } } for (int i = 0; i < node.ChildCount; i++) { AddMeshes(node.Children[i], asset, assetPath, loadingJob, ref transform); } transform = previousTransform; }
public CMeshAsset LoadMeshAsset(string filename, bool bAlwaysImport = false) { // Block new loads and wait for our current load to finish m_bIsLoading = true; m_currentLoadTask?.Wait(); // Load the asset synchronous CMeshAsset outAsset = new CMeshAsset(); if (!bAlwaysImport && TryGetExistingAsset(filename, "Assets/", outAsset, out CMeshAsset existingAsset)) { m_bIsLoading = false; return(existingAsset); } Scene scene = m_importer.ImportFile(filename, PostProcessPreset.TargetRealTimeMaximumQuality | PostProcessPreset.ConvertToLeftHanded); if (scene.HasMeshes) { string basePath = Path.GetDirectoryName(filename); CMeshLoadingJob loadingJob = new CMeshLoadingJob(scene, basePath); LoadMeshInternal(0, outAsset, loadingJob, "Assets/", Path.GetFileNameWithoutExtension(filename), bAlwaysImport); } outAsset.LoadFinished(); // Unblock loader m_bIsLoading = false; // Continue loading request StartNextLoadRequest(); return(outAsset); }
public bool Import(string filename, string importPath, bool bAlwaysImport = false) { // Block new loads and wait for our current load to finish m_bIsLoading = true; m_currentLoadTask?.Wait(); // Load the asset synchronous Scene scene = m_importer.ImportFile(filename, PostProcessPreset.TargetRealTimeMaximumQuality | PostProcessPreset.ConvertToLeftHanded); if (scene.HasMeshes) { if (scene.MeshCount > 1) { CModelAsset outModel = new CModelAsset(); LoadModelInternal(filename, scene, outModel, importPath); outModel.LoadFinished(); outModel.Name = Path.GetFileNameWithoutExtension(filename); if (CAssetRegistry.Instance.RequestRegisterAsset(outModel, importPath + "Models/", out CModelAsset existingModel, bAlwaysImport)) { existingModel.WaitUntilLoaded(); } } else { string basePath = Path.GetDirectoryName(filename); CMeshLoadingJob loadingJob = new CMeshLoadingJob(scene, basePath); CMeshAsset outMesh = new CMeshAsset(); LoadMeshInternal(0, outMesh, loadingJob, importPath, Path.GetFileNameWithoutExtension(filename), bAlwaysImport); outMesh.LoadFinished(); } } // Unblock loader m_bIsLoading = false; // Continue loading request StartNextLoadRequest(); return(true); }