資源簡介
放入工程就能用,里面一個js版本,一個是cs版本,用其中一個就行

代碼片段和文件信息
//?Converted?from?Unityscript?to?C#?at?http://www.M2H.nl/files/js_to_c.php?-?by?Mike?Hergaarden
//?Do?test?the?code!?You?usually?need?to?change?a?few?small?bits.
using?UnityEngine;
using?System.Collections;
using?UnityEditor;
using?System.IO;
using?System;
using?System.Text;
enum?SaveFormat?{?Triangles?Quads?}
enum?SaveResolution?{?Full?Half?Quarter?Eighth?Sixteenth?}
public?class?ExportTerrain?:?EditorWindow
{
????SaveFormat?saveFormat?=?SaveFormat.Triangles;
????SaveResolution?saveResolution?=?SaveResolution.Half;
????static?TerrainData?terrain;
????static?Vector3?terrainPos;
????int?tCount;
????int?counter;
????int?totalCount;
????static?ExportTerrain?window;
????[MenuItem(“地形導出/OBJ格式“)]
????static?void?Init()
????{
????????terrain?=?null;
????????Terrain?terrainobject?=?Selection.activeobject?as?Terrain;
????????if?(!terrainobject)
????????{
????????????terrainobject?=?Terrain.activeTerrain;
????????}
????????if?(terrainobject)
????????{
????????????terrain?=?terrainobject.terrainData;
????????????terrainPos?=?terrainobject.transform.position;
????????}
????????
????????window?=?(ExportTerrain)GetWindow(typeof(ExportTerrain)?true?“My?Empty?Window“);
????????window.Show();
????}
????void?OnGUI()
????{
????????if?(!terrain)
????????{
????????????GUILayout.Label(“No?terrain?found“);
????????????if?(GUILayout.Button(“Cancel“))
????????????{
????????????????window.Close();
????????????}
????????????return;
????????}
????????saveFormat?=?(SaveFormat)EditorGUILayout.EnumPopup(“Export?Format“?saveFormat);
????????saveResolution?=?(SaveResolution)EditorGUILayout.EnumPopup(“Resolution“?saveResolution);
????????if?(GUILayout.Button(“導出“))
????????{
????????????Export();
????????}
????}
????void?Export()
????{
????????var?fileName?=?EditorUtility.SaveFilePanel(“Export?.obj?file“?““?“Terrain“?“obj“);
????????int?w?=?terrain.heightmapWidth;
????????int?h?=?terrain.heightmapHeight;
????????var?meshScale?=?terrain.size;
????????var?tRes?=?Mathf.Pow(2?(float)saveResolution);
????????meshScale?=?new?Vector3(meshScale.x?/?(w?-?1)?*?tRes?meshScale.y?meshScale.z?/?(h?-?1)?*?tRes);
????????var?uvScale?=?new?Vector2(1.0f?/?(w?-?1)?1.0f?/?(h?-?1));
????????var?tData?=?terrain.GetHeights(0?0?w?h);
????????w?=?(int)((w?-?1)?/?tRes?+?1);
????????h?=?(int)((h?-?1)?/?tRes?+?1);
????????var?tVertices?=?new?Vector3[(int)w?*?(int)h];
????????var?tUV?=?new?Vector2[(int)w?*?(int)h];
????????int[]?tPolys;
????????if?(saveFormat?==?SaveFormat.Triangles)
????????{
????????????tPolys?=?new?int[(w?-?1)?*?(h?-?1)?*?6];
????????}
????????else
????????{
????????????tPolys?=?new?int[(w?-?1)?*?(h?-?1)?*?4];
????????}
????????//?Build?vertices?and?UVs??
????????for?(int?y?=?0;?y?????????{
????????????for?(int?x?=?0;?x?????????????{
????????????????tVertices[y?*?w?+?x]?=?Vector3.Scale(meshScalenew?Vector3(x?(tData[x?*?(int)tRes?y?*?(int)t
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????7966??2017-10-18?18:50??ExportTerrain.cs
?????文件????????8321??2017-10-18?17:39??ExportTerrain.js
- 上一篇:labview藍牙接收程序
- 下一篇:NFC_READER V5.0讀寫程序.exe
評論
共有 條評論