Unity匯出場景地形網格到 obj檔案

2021-07-15 01:31:05 字數 1819 閱讀 3895

當美術同事拼接好場景內容後,需要在指定場景上製作具體的行走麵時,用來提供網格參照。

主要**邏輯就是將場景內帶mesh的結點記錄下來,通過對應的.obj資料格式進行儲存。

具體**:

using unityengine;

using system.collections;

using system.io;

using system.text;

using unityeditor;

using unityeditor.scenemanagement;

////// 描述:匯出網格資料到.obj檔案

///public

sealed

class exportmesh

editorutility.displaydialog("提示", issuccess ? "已成功匯出mesh到.obj檔案" : "當前場景沒有找到可匯出的資源", "ok");

}///

/// 匯出網格資訊

//////

private

static

bool

exportgameobjectmesh(gameobject gobj)

writeobjfile(buf);

return

true;

}///

/// 解析meshfilter資料

//////

//////

頂點偏移量

private

static

intparsemeshfilter(stringbuilder buf, meshfilter mf , int offsetvertices)

transform meshtrans = mf.transform;

vector3 allvertices = mesh.vertices;

foreach (vector3 vertice in allvertices)

foreach (vector3 normal in mesh.normals)

foreach (vector2 uv in mesh.uv)

material mats = meshtrans.getcomponent().sharedmaterials;

for (int i = 0; i < mesh.submeshcount; i++)

}return allvertices.length;

}///

/// 保持obj檔案

//////

private

static

void

writeobjfile(stringbuilder buf)

}}

editorutil

using unityengine;

using system.collections;

using system.collections.generic;

using system.io;

////// 描述:工具開發常用工具集

///public

sealed

class editorutil

return golist.toarray();

}///

/// 檢測目錄是否存在,如果不存在,則建立目錄

//////

public

static

void

swapndirectory(string path)

}

有了這個小功能,美術大神就可以自己愉快的玩耍了!

Cocos Creator匯出場景和預製的問題

cocos creator支援匯出當前專案中的場景和預製為另乙個專案所用 1,選擇要匯出的場景或者預製 2,選擇要匯出到的目標資料夾位置並進行可能的重新命名 3,匯出乙個壓縮檔案.zip。4,解壓壓縮檔案.zip,然後可以拖動其中的內容到目標專案指定位置進行使用即可。但是也有一些小問題 1,目標專案...

Cocos Creator匯出場景和預製的問題

cocos creator支援匯出當前專案中的場景和預製為另乙個專案所用 1,選擇要匯出的場景或者預製 2,選擇要匯出到的目標資料夾位置並進行可能的重新命名 3,匯出乙個壓縮檔案.zip。4,解壓壓縮檔案.zip,然後可以拖動其中的內容到目標專案指定位置進行使用即可。但是也有一些小問題 1,目標專案...

Unity執行時輸出場景物體及角色為fbx檔案

在unity中匯入fbx是個跟簡單的事,只需要把fbx放到unity的專案資料夾下,它就能自動識別並讀取了,但是在unity執行的過程中輸出fbx卻相當麻煩。因為工作專案的需求,需要把場景中的物體在執行時匯出成fbx,所以對這個功能進行了研究,在unity商店也有一些匯出的外掛程式,但是基本都是只限...