public aiScene ReadFile(string pFile, aiPostProcessSteps pFlags) { IntPtr cPtr = AssimpPINVOKE.Importer_ReadFile__SWIG_0(swigCPtr, pFile, (uint)pFlags); aiScene ret = (cPtr == IntPtr.Zero) ? null : new aiScene(cPtr, false); return ret; }
/// <summary> /// Loads a ship from a file using the Assimp library and returns a reference to a 'Scene' object which /// contains all the data in that resource. It is important to note that this will first load the mesh with /// Assimp into 'unmanaged' memory (allocated by the C/C++ DLL) and then copy it into the managed memory allocated by the 'Scene'. /// As such, calling this will typically take longer and, for the duration of this method call, use double the memory of the /// standard assimp import call. As such, if speed or memory are of concern to you then consider using the the /// unmanaged interface in 'Unmanaged.Assimp'. /// </summary> /// <param name="sResourcePath">The path to the mesh resource. E.g. "data\characters\yourmum.x"</param> /// <param name="eFlags">The postprocessing flags that are specified. This is (uint) compatible with entries in the PostProcessingFlags enum.</param> /// <returns>A 'Scene' object which represents the loaded resource. If load failed, null is returned.</returns> public static Scene readFile(String sResourcePath, aiPostProcessSteps eFlags) { // Ensure we have a valid path. if (sResourcePath == null) throw new ArgumentNullException("The resource path cannot be null."); if (sResourcePath == "") throw new ArgumentNullException("The resource path cannot be null."); // Drop into unsafe mode so we can access the pointers in the Assimp library. unsafe { // Declare a pointer to the scene. UnmanagedAssimp.aiScene* pScene; try { // Try and load the mesh as specfied above. //UnmanagedAssimp.aiSetImportPropertyFloat(UnmanagedAssimp.AI_CONFIG_PP_CT_MAX_SMOOTHING_ANGLE, 80.0f); //UnmanagedAssimp.aiSetImportPropertyFloat(UnmanagedAssimp.AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, 80.0f); //UnmanagedAssimp.aiSetImportPropertyInteger(UnmanagedAssimp.AI_CONFIG_IMPORT_ASE_RECONSTRUCT_NORMALS, 1); // This is commented out because we want the pre-transform vertices step to flatten the mesh. //UnmanagedAssimp.aiSetImportPropertyInteger(UnmanagedAssimp.AI_CONFIG_PP_PTV_KEEP_HIERARCHY, 1); // This is commented out because we do not normalise the mesh. //UnmanagedAssimp.aiSetImportPropertyInteger(UnmanagedAssimp.AI_CONFIG_PP_PTV_NORMALIZE, 0); // Force Assimp to ignore all lines and points on import. int iIgnoreFaceTypes = (int)(UnmanagedAssimp.aiPrimitiveType.aiPrimitiveType_LINE | UnmanagedAssimp.aiPrimitiveType.aiPrimitiveType_POINT); UnmanagedAssimp.aiSetImportPropertyInteger(UnmanagedAssimp.AI_CONFIG_PP_SBP_REMOVE, iIgnoreFaceTypes); pScene = UnmanagedAssimp.aiImportFile(sResourcePath, (uint)eFlags); } catch (Exception pError) { throw pError; // Something went wrong so make it the users problem! //throw new Exception("Assimp suffered an error when converting loading the resource into unmanaged memory. See the inner exception for details.", pError); } // A C# pointer to the scene. IntPtr pScenePtr = new IntPtr(pScene); // If the mesh did not load correctly, return null. if (pScenePtr == IntPtr.Zero) return null; try { // Now we want to parse the scene with the managed wrapper. Scene oScene = new Scene(pScenePtr, sResourcePath); // Now that is done we can release the Assimp stuff. UnmanagedAssimp.aiReleaseImport(pScene); // Success - return a reference to our newly created scene! return oScene; } catch (Exception pError) { throw pError; // There was an error with the managed library. Take responsibility for my bad code by forwarding the error to YOU! //throw new Exception("Error converting Assimp resource data to managed memory. See the inner exception for details.", pError); } } }
public bool ValidateFlags(aiPostProcessSteps pFlags) { bool ret = AssimpPINVOKE.Importer_ValidateFlags(swigCPtr, (uint)pFlags); return ret; }
// <summary> /// Add a property related to unity options ( and not assimp property or /// preprocessor step. /// </summary> /// <param name="option"> Options type enum </param> private void DisplayCustomMenu(Property property) { switch (property.data.customOption) { case Property.SelfDefinedOption.PRESETS: // Get the user modifed list of flags aiPostProcessSteps steps = options.GetFlags(); // Test if the current steps fit a pre-configuration Preset current_preset = ( Model.Module.Import.Assimp.CompareFlags(steps, aiPostProcessSteps.aiProcessPreset_TargetRealtime_Fast) ? Preset.Fast : ( Model.Module.Import.Assimp.CompareFlags(steps, aiPostProcessSteps.aiProcessPreset_TargetRealtime_Quality) ? Preset.Quality : ( Model.Module.Import.Assimp.CompareFlags(steps, aiPostProcessSteps.aiProcessPreset_TargetRealtime_MaxQuality) ? Preset.Best : ( Model.Module.Import.Assimp.CompareFlags(steps, 0) ? Preset.None : Preset.Custom ) ) ) ); // Display the preset checkboxes & save the current selected preset foreach (Preset preset in Enum.GetValues(typeof(Preset))) { string name = Enum.GetName(typeof(Preset), preset); bool custom = (name.CompareTo("Custom") == 0); if (custom) { GUI.enabled = false; } if (GUILayout.Toggle(current_preset == preset, name)) { current_preset = preset; } if (custom) { GUI.enabled = true; } } // Set the flags in the properties based on the selected preset switch (current_preset) { case Preset.None: steps = 0; break; case Preset.Fast: steps = aiPostProcessSteps.aiProcessPreset_TargetRealtime_Fast; break; case Preset.Quality: steps = aiPostProcessSteps.aiProcessPreset_TargetRealtime_Quality; break; case Preset.Best: steps = aiPostProcessSteps.aiProcessPreset_TargetRealtime_MaxQuality; break; default: case Preset.Custom: steps = options.GetFlags(); break; } options.SetFlags(Model.Module.Import.Assimp.UsedSteps(steps)); break; case Property.SelfDefinedOption.SHOW_ALL_POST_PROCESS_STEPS: bool?show_all = Property.Data.GetBool(property.data); if (show_all.HasValue) { showAll = show_all.Value; showAll = GUILayout.Toggle(showAll, "Show all post processing steps"); if (showAll != show_all.Value) { property.SetChanged(true); } property.data.currentValue = showAll.ToString(); } break; case Property.SelfDefinedOption.ACTIVATE_LOGGING: bool?activate_logging = Property.Data.GetBool(property.data); if (activate_logging.HasValue) { bool activated = GUILayout.Toggle(activate_logging.Value, "Activate logging"); if (activated != activate_logging.Value) { property.SetChanged(true); } property.data.currentValue = activated.ToString(); } break; } }
public bool ValidateFlags(aiPostProcessSteps pFlags) { bool ret = assimp_swigPINVOKE.Importer_ValidateFlags(swigCPtr, (uint)pFlags); return(ret); }
public aiReturn Export(aiScene pScene, string pFormatId, string pPath, aiPostProcessSteps pPreprocessing) { aiReturn ret = (aiReturn)assimp_swigPINVOKE.Exporter_Export__SWIG_1(swigCPtr, aiScene.getCPtr(pScene), pFormatId, pPath, (uint)pPreprocessing); return(ret); }
public IEnumerator ToAssimp(Module.Export.Assimp.Context context, string filename, aiPostProcessSteps steps, Module.ExporterSuccessCallback return_callback, Module.ProgressCallback progress_callback) { bool success = false; string extension = System.IO.Path.GetExtension(filename).Remove(0, 1).ToLower(); uint export_format_count = context.exporter.GetExportFormatCount(); bool found_exporter = false; for (uint i = 0; i < export_format_count; i++) { using (aiExportFormatDesc desc = context.exporter.GetExportFormatDescription(i)) { if (extension == desc.fileExtension.ToLower()) { using (aiScene scene = new aiScene()) { InitProgress(context, progress_callback, this); context.scene = scene; // Export nodes IResult nodes_result = context.threads.AddTask(() => { using (aiNode root = root_node.ToAssimp(context, this, null)) { scene.mRootNode = root.Unmanaged(); } }); // Export materials. context.threads.AddTask(() => Material.ToAssimp(context, this)); // We must wait for all the nodes to be processed before exporting meshes because indexes are computed during parsing. while (!nodes_result.Done) { context.progress.Display(); yield return(null); } // Export meshes context.threads.AddTask(() => Mesh.ToAssimp(context, this)); // Wait for all tasks to be completed IEnumerator it = context.threads.WaitForTasksCompletion(); while (it.MoveNext()) { context.progress.Display(); yield return(it.Current); } // Do the final export using Assimp now that we created the complete structure in the C++ DLL. Result <aiReturn> status = context.threads.AddTask(() => context.exporter.Export(scene, desc.id, filename, steps)); // Wait for export to complete while (!status.Done) { context.progress.Display(); yield return(null); } if (progress_callback != null) { progress_callback(1f); } context.Clean(); // Check export status if (status.Success && status.Value == aiReturn.aiReturn_SUCCESS) { success = true; } else { Debug.LogErrorFormat("Failed to export to: {0}. \nThe exporter reported the following error: {1}", filename, context.exporter.GetErrorString()); } } found_exporter = true; break; } } } if (!found_exporter) { Debug.LogErrorFormat("No exporter for format '{0}' was found in Assimp.", extension); } if (return_callback != null) { return_callback(success); } }
internal Data(Importer importer, aiPostProcessSteps step, string option_text, Category category, bool user_defined) : this(option_text, Property.Type.BOOL, category, InitValue(importer, step), user_defined) { isStepFlag = true; processStep = step; }
internal Data(Importer importer, aiPostProcessSteps step, string option_text, Category category) : this(importer, step, option_text, category, true) { }
/// <summary> /// Compute the actual postprocess steps that will be used for import, including user defined steps, mandatory steps and without forbidden steps. /// </summary> /// <param name="flags">The requested postprocess steps to use, as bit flags.</param> /// <returns>The postprocess steps that will be used, based on requested steps, mandatory steps and without forbidden steps.</returns> public static aiPostProcessSteps UsedSteps(aiPostProcessSteps flags) { return((flags | mandatoryPostProcessSteps) & ~forbidenPostProcessSteps); }
/// <summary> /// Check if to set of postprocess steps are identical. /// </summary> /// <remarks> /// The postprocess steps are normalized before comparison to take into account the actual steps that would be used on import for both. /// </remarks> /// <param name="flags1">The first set of postprocess steps to compare, as bit flags.</param> /// <param name="flags2">The second set of postprocess steps to compare, as bit flags.</param> /// <returns>True if both set of postprocess steps are equivalent, false otherwise.</returns> public static bool CompareFlags(aiPostProcessSteps flags1, aiPostProcessSteps flags2) { return(UsedSteps(flags1) == UsedSteps(flags2)); }
/// <summary> /// Test if at least one of the postprocess steps in a set is enabled or not. /// </summary> /// <param name="flags">The postprocess steps to check, as bit flags.</param> /// <returns>True if at least one of the postprocess steps is enabled, false otherwise.</returns> public bool IsFlagSet(aiPostProcessSteps flags) { return(Option.Flags.IsSet((int)postProcessSteps, (int)flags)); }
/// <summary> /// Enable or disable a set of postprocess steps. /// </summary> /// <param name="flags">The postprocess steps to set, as bit flags.</param> /// <param name="state">The desired state for the postprocess steps. True will enable the steps, false will disable them.</param> public void ChangeFlag(aiPostProcessSteps flags, bool state) { postProcessSteps = (aiPostProcessSteps)Option.Flags.Toogle((int)postProcessSteps, (int)flags, state); }
public static aiExportDataBlob aiExportSceneToBlob(aiScene pScene, string pFormatId, aiPostProcessSteps pPreprocessing) { global::System.IntPtr cPtr = assimp_swigPINVOKE.aiExportSceneToBlob(aiScene.getCPtr(pScene), pFormatId, (uint)pPreprocessing); aiExportDataBlob ret = (cPtr == global::System.IntPtr.Zero) ? null : new aiExportDataBlob(cPtr, false); return(ret); }
public static aiReturn aiExportSceneEx(aiScene pScene, string pFormatId, string pFileName, aiFileIO pIO, aiPostProcessSteps pPreprocessing) { aiReturn ret = (aiReturn)assimp_swigPINVOKE.aiExportSceneEx(aiScene.getCPtr(pScene), pFormatId, pFileName, aiFileIO.getCPtr(pIO), (uint)pPreprocessing); return(ret); }
public static aiScene aiImportFileFromMemoryWithProperties(string pBuffer, uint pLength, aiPostProcessSteps pFlags, string pHint, aiPropertyStore pProps) { global::System.IntPtr cPtr = assimp_swigPINVOKE.aiImportFileFromMemoryWithProperties(pBuffer, pLength, (uint)pFlags, pHint, aiPropertyStore.getCPtr(pProps)); aiScene ret = (cPtr == global::System.IntPtr.Zero) ? null : new aiScene(cPtr, false); return(ret); }