► Terrain To OBJ ◄

5986145--643466--Cover.jpg

This is support forum for the Terrain To OBJ asset (link).

Run-time and Editor solution for converting Unity Terrain object into OBJ format mesh.

Key features:
• Total control over vertex count.
• Chunking system.
• Generated mesh can be split into any number of sub meshes. Saved in one OBJ file.
• File precision control.
• Generated OBJ file can be directly imported into any 3d modeling software.
• No dependencies on external tools and plugins.
• User friendly Editor tool.
Run-time API adds ToOBJ extension method to the TerrainData class and returns 'string' containing Terrain in OBJ format.

5986145--643475--Editor (2).jpg

[quote]
"Is there vertex count limit?"
No, OBJ file has no limits on vertex count.
[/quote]

[quote]
"Does unlimited vertex count require 32 bit mesh index format support?"
No, 16 and 32 index formats are irrelevant for OBJ files, that can contain mesh with any vertex count.
[/quote]

[quote]
"I do not need generating all tiles of a split mesh, but just one in the specific location. Can I do this with this plugin?"
Yes, using run-time API can be generated individual parts of a split mesh. Editor tool generates all split meshes together but saves them as a separate sub meshes into one OBJ file.
[/quote]

Update History

[spoiler]

v2020.4
• Updated API supports saving OBJ file using StreamWriter, avoiding using string builder.
• Editor exporter is 50% faster.
• Improved progress bar for editor exporter.

v2020.3
Editor improvements

v2020.2
• Generated mesh can use custom origin position.

v2020.1
• Initial Release

[/spoiler]

Amazing Assets - YouTube Facebook Twitter

1 Like

Great Tool @Arkhivrag ! Simple but effective !

I have some suggestions if you are going to upgrade the asset :

  • When dealing with multiple terrains, it would be great to store their world position to apply them to the obj so that when importing them in a 3D software, they are at the right positions.
  • Maybe have a documentation for your users, like how to get access to the tool in the menu.

Anyway, thanks for this tool ;)

  1. Can be easily added. Will update tomorrow.
  2. Documentation is already included.

Amazing Assets - YouTube Facebook Twitter

1 Like


;) oops got it !

Hi @Arkhivrag , I'm using Unity 2020.1.17f1 and I'm starting to have the following error when trying to export one terrain to OBJ. Any idea why?

ArgumentOutOfRangeException: capacity was less than the current size.
Parameter name: requiredLength
System.Text.StringBuilder.ExpandByABlock (System.Int32 minBlockCharCount) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Text.StringBuilder.Append (System.Char* value, System.Int32 valueCount) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Text.StringBuilder.AppendHelper (System.String value) (at <9577ac7a62ef43179789031239ba8798>:0)
System.Text.StringBuilder.Append (System.String value) (at <9577ac7a62ef43179789031239ba8798>:0)
AmazingAssets.TerrainExtensions.TerrainToOBJ.‎‪‏‪‪‮‏‍‪‎‎‏‪‮‫‎‍‮‪‮‍‌‪‮ (System.Text.StringBuilder , System.String ) (at <9f80ad21da934f0da831fde289ccef12>:0)
AmazingAssets.TerrainExtensions.TerrainToOBJ.ToOBJ (UnityEngine.TerrainData terrainData, System.Int32 vertexCountHorizontal, System.Int32 vertexCountVertical, System.Int32 chunkCountHorizontal, System.Int32 chunkCountVertical, System.Boolean perChunkUV, System.Boolean calculateNormals, UnityEngine.Vector3 originPosition, System.Int32 precision) (at <9f80ad21da934f0da831fde289ccef12>:0)
AmazingAssets.TerrainExtensions.Editor.TerrainToOBJEditor.DrawGenerateButton () (at <450e3698fa17421ba589d4069ccf1e41>:0)
AmazingAssets.TerrainExtensions.Editor.TerrainToOBJEditor.OnGUI () (at <450e3698fa17421ba589d4069ccf1e41>:0)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <c84609c921cb488481d7d8a5fcdf9588>:0)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <c84609c921cb488481d7d8a5fcdf9588>:0)
UnityEditor.DockArea.OldOnGUI () (at <c84609c921cb488481d7d8a5fcdf9588>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUIRaw (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEventAtTargetPhase (UnityEngine.UIElements.EventBase evt) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.MouseCaptureDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.EventDispatcher.OpenGate () (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.EventDispatcherGate.Dispose () (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <51648d78f489425494db94c505b138b2>:0)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean&

Here are my parameters :
6665611--762697--upload_2020-12-28_19-30-49.png

Try new version v2020.4. It has updated API and better memory management.

Amazing Assets - YouTube Facebook Twitter

does this support terrain holes? It would make a huge difference


No.
Unity terrain itself supports holes as alpha cutout effect.

Amazing Assets - YouTube Facebook Twitter

That I know, but if you create a mesh you can create holes. That's a big advantage of converting it to mesh. Does the tool do it automatically?


Converting terrain to OBJ mesh? - Yes (without holes).

Amazing Assets - YouTube Facebook Twitter

I'm asking about creating holes, not about converting to mesh without holes.
Please, can you look into adding this feature? Otherwise it is very difficult for people with large terrains and many holes on it.