You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using AssimpNet 4.1.0 I want to load a model from file, clear it's normals and then apply post processing to regenerate smooth normals. For this to work I have to jump through hoops converting the scene from managed to unmanaged memory. The IntPtr to the unmanaged scene is getting corrupted and returned as Zero from AssimpLibrary.Instance.AppyPostProcessing() when it's called on the IntPtr that comes from Scene.ToUnmanagedScene().
Using AssimpNet 5.0.0-beta1 it doesn't return a Ptr.Zero but crashes instead.
For the sake of keeping the examples smaller cleaning up of unmanaged memory is not included, but I have tested if that makes any difference and it doesn't from what I've seen.
Any help or even a different approach to force smooth normals would be greatly appreciated!
// 1. Import the model without any additional processing
Scene scene = importer.ImportFile(file, PostProcessSteps.Triangulate);
// 2. Clear normals (uncommented for debugging)
//for(int i = 0; i < scene.Meshes.Count; i++)
//{
// scene.Meshes[i].Normals.Clear();
//}
// 3. Get pointer to unmanaged scene
IntPtr ptrBeforePP = Scene.ToUnmanagedScene(scene);
// 4. Apply post processing after manually manipulated the meshes
IntPtr ptrAfterPP = AssimpLibrary.Instance.ApplyPostProcessing(ptrBeforePP, PostProcessSteps.GenerateSmoothNormals);
Importing as unmanaged scene
// 1. Import the model as unmanaged scene
IntPtr ptrBeforeFirstPP = AssimpLibrary.Instance.ImportFile(file, PostProcessSteps.None, IntPtr.Zero, IntPtr.Zero);
// 2. Apply first postprocessing, returning a valid IntPtr
IntPtr ptrAfterFirstPP = AssimpLibrary.Instance.ApplyPostProcessing(ptrBeforeFirstPP, PostProcessSteps.Triangulate);
// 3. Convert unmanaged scene to managed scene and clear normals (uncommented for debugging)
Scene scene = Scene.FromUnmanagedScene(ptrAfterFirstPP);
//for(int i = 0; i < scene.Meshes.Count; i++)
//{
// scene.Meshes[i].Normals.Clear();
//}
// 4. Convert managed scene to unmanaged scene
IntPtr ptrBeforeSecondPP = Scene.ToUnmanagedScene(scene);
// 5. Apply second postprocessing, returning IntPtr.Zero
IntPtr ptrAfterSecondPP = AssimpLibrary.Instance.ApplyPostProcessing(ptrBeforeSecondPP, PostProcessSteps.GenerateSmoothNormals);
Context (Environment)
.NET Core 3.1
Issue is independent from the model or file format being used
The text was updated successfully, but these errors were encountered:
Using AssimpNet 4.1.0 I want to load a model from file, clear it's normals and then apply post processing to regenerate smooth normals. For this to work I have to jump through hoops converting the scene from managed to unmanaged memory. The IntPtr to the unmanaged scene is getting corrupted and returned as Zero from
AssimpLibrary.Instance.AppyPostProcessing()
when it's called on the IntPtr that comes fromScene.ToUnmanagedScene()
.Using AssimpNet 5.0.0-beta1 it doesn't return a Ptr.Zero but crashes instead.
For the sake of keeping the examples smaller cleaning up of unmanaged memory is not included, but I have tested if that makes any difference and it doesn't from what I've seen.
Any help or even a different approach to force smooth normals would be greatly appreciated!
Expected Behavior
Variable
ptr2
should have a non-zero value.Current Behavior
Variable
ptr2
is always zero.Steps to Reproduce
Importing as managed scene
Importing as unmanaged scene
Context (Environment)
The text was updated successfully, but these errors were encountered: