【2人回答】unity3D文件怎么打开?

您所在的位置:网站首页 cg文件打开方式 【2人回答】unity3D文件怎么打开?

【2人回答】unity3D文件怎么打开?

2024-07-05 12:42:38| 来源: 网络整理| 查看: 265

回答:

unity3D导出obj的方法如下: 从terrAIn菜单下选择export to obj... ,在分辨率窗口,选择要四边形还是三角形网格结构。同样也可以选择要导出地形的分辨率,有高中低等等.点击export,选择要保存的位置和文件名.obj文件将被导出.要注意如果选择大面积的full地形导出,最终的obj文件将非常大,而且也要导出时间较长。 下面为exportterrAIn.js脚本 import system.io;import system.text;enum saveFormat {triangles, quads}enum saveresolution {full, half, quarter, eighth, sixteenth}class exportterrAIn extends editorWindow { var saveFormat = saveFormat.triangles; var saveresolution = saveresolution.half; static var terrAIn : terrAIndata; static var terrAInpos : vector3; var tcount : int; var counter : int; var totalcount : int; @menUItem ("terrAIn/export to obj...") static function init () { terrAIn = null; var terrAInobject : terrAIn = selection.activeobject as terrAIn; if (!terrAInobject) { terrAInobject = terrAIn.activeterrAIn;} if (terrAInobject) { terrAIn = terrAInobject.terrAIndata; terrAInpos = terrAInobject.transForm.position;} editorWindow.getWindow(exportterrAIn).show(); } function ongUI () { if (!terrAIn) { gUIlayout.label("no terrAIn found"); if (gUIlayout.button("cancel")) {editorWindow.getWindow(exportterrAIn).close(); } return; } saveFormat = editorgUIlayout.enumpopup("export Format", saveFormat); saveresolution = editorgUIlayout.enumpopup("resolution", saveresolution); if (gUIlayout.button("export")) {export(); } } function export () { var filename = editorutility.savefilepanel("export .obj file", "", "terrAIn", "obj"); var w = terrAIn.heightmapwIDth; var h = terrAIn.heightmapheight; var meshscale = terrAIn.size; var tres = mathf.pow(2, parseint(saveresolution)); meshscale = vector3(meshscale.x/(w-1)*tres, meshscale.y, meshscale.z/(h-1)*tres); var uvscale = vector2(1.0/(w-1), 1.0/(h-1)); var tdata = terrAIn.getheights(0, 0, w, h); w = (w-1) / tres + 1; h = (h-1) / tres + 1; var tvertices = new vector3[w * h]; var tuv = new vector2[w * h]; if (saveFormat == saveFormat.triangles) { var tpolys = new int[(w-1) * (h-1) * 6];} else { tpolys = new int[(w-1) * (h-1) * 4];} // bUIld vertices and uvs For (y = 0; y < h; y++) { For (x = 0; x < w; x++) { tvertices[y*w + x] = vector3.scale(meshscale, vector3(x, tdata[x*tres,y*tres], y)) + terrAInpos; tuv[y*w + x] = vector2.scale(vector2(x*tres, y*tres), uvscale);} } var index = 0; if (saveFormat == saveFormat.triangles) { // bUIld triangle indices: 3 indices into vertex array For each triangle For (y = 0; y < h-1; y++) { For (x = 0; x < w-1; x++) { // For each grID cell output two triangles tpolys[index++] = (y * w) + x; tpolys[index++] = ((y+1) * w) + x; tpolys[index++] = (y * w) + x + 1; tpolys[index++] = ((y+1) * w) + x; tpolys[index++] = ((y+1) * w) + x + 1; tpolys[index++] = (y * w) + x + 1;} } } else { // bUIld quad indices: 4 indices into vertex array For each quad For (y = 0; y < h-1; y++) { For (x = 0; x < w-1; x++) { // For each grID cell output one quad tpolys[index++] = (y * w) + x; tpolys[index++] = ((y+1) * w) + x; tpolys[index++] = ((y+1) * w) + x + 1; tpolys[index++] = (y * w) + x + 1;} } } // export to .obj try { var SW = new streamwriter(filename); SW.writeline("# unity terrAIn obj file"); // write vertices system.threading.thread.currentthread.currentculture = new system.globalization.cultureinfo("en-us"); counter = tcount = 0; totalcount = (tvertices.length*2 + (saveFormat == saveFormat.triangles? tpolys.length/3 : tpolys.length/4)) / 1000; For (i = 0; i < tvertices.length; i++) {updateProgress(); var sb = stringbUIlder("v ", 20); // stringbUIlder stuff is done this way becAuse it's faster than using the "{0} {1} {2}"etc. Format // which is important when you're exporting hUGe terrAIns. sb.append(tvertices[i].x.tostring()).append(" "). append(tvertices[i].y.tostring()).append(" ").append(tvertices[i].z.tostring()); SW.writeline(sb); } // write uvs For (i = 0; i < tuv.length; i++) {updateProgress(); sb = stringbUIlder("vt ", 22); sb.append(tuv[i].x.tostring()).append(" ").append(tuv[i].y.tostring()); SW.writeline(sb); } if (saveFormat == saveFormat.triangles) { // write triangles For (i = 0; i < tpolys.length; i += 3) {updateProgress(); sb = stringbUIlder("f ", 43); sb.append(tpolys[i]+1).append("/").append(tpolys[i]+1).append(" "). append(tpolys[i+1]+1).append("/").append(tpolys[i+1]+1).append(" ").append(tpolys[i+2]+1).append("/").append(tpolys[i+2]+1); SW.writeline(sb); } } else { // write quads For (i = 0; i < tpolys.length; i += 4) {updateProgress(); sb = stringbUIlder("f ", 57); sb.append(tpolys[i]+1).append("/").append(tpolys[i]+1).append(" "). append(tpolys[i+1]+1).append("/").append(tpolys[i+1]+1).append(" "). append(tpolys[i+2]+1).append("/").append(tpolys[i+2]+1).append(" ").append(tpolys[i+3]+1).append("/").append(tpolys[i+3]+1); SW.writeline(sb); } } } catch (err) { debUG.log("error saving file: " + err.message);} SW.close(); terrAIn = null;editorutility.clearProgressbar(); editorWindow.getWindow(exportterrAIn).close(); } function updateProgress () { if (counter++ == 1000) { counter = 0; editorutility.displayProgressbar("saving...", "", mathf.inverselerp(0, totalcount, ++tcount));} }



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭