资源简介
放入工程就能用,里面一个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 < h; y++)
{
for (int x = 0; x < w; 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
相关资源
- 网络连接案例,包含控制台,Unity
-
Unity Touchsc
riptNGUI-master - 基于openGL的三维地形场景的生成
- UnityDownloadAssistant-2017
- unity路径工具Itween插件
- unity真实反射shader mirror_shaders
- UnityTerrain2MeshV3
- Unity3-2019所有可破解安装包.txt
- unity 读取手机相册
- Unity游戏人工智能AI开发
- T4M unity 地形插件
- LitJson for unity
- Unity3D客户端PureMVC框架视屏讲解
- unity3d斗地主
- Oculus SDK 开发必备 OculusIntegration_1.39
- Unity内置着色器源码 builtin_shaders-5.6
- Unity内置着色器源码 builtin_shaders-201
- Unity4.x从入门到精通课本及源码
- Shader编程教程 完整
- Unity3d视频教程
- FXMaker1.5支持最新unity5
-
1比10000地形图的ArcGIS符号库(st
yl - Unity 3D ShaderLab开发实战详解
- 百度语音识别 Unity插件
- Unity插件 Scratch Card 1.6 刮刮卡/刮刮乐
- Unity Asset Bundle Browser tool.unitypackage
- Unity本地保存插件Easy Save
- 《Unity 5.x 完全自学手册》配书资源地
- DOTween Pro 1.0.165 游戏可视化编辑器扩展
- Unity UGUI ui上显示3D模型游戏物体
评论
共有 条评论