python unreal.RenderingLibrary
classmethod export_texture2d(world_context_object, texture, file_path, file_name) → None¶
”Exports a Texture2D as a HDR image onto the disk.”
”Texture2D を HDR イメージとしてディスクにエクスポートします。”
とあります。
まず、手動では沢山形式が選べるが、pythonでは「HDR」しか選べない。
1,以下のような感じで書き出します。
texture2d=editorAssetLib.load_asset(AssetDataFullNameArr[1])
OutfileName=assetName+".hdr" #UEの出力画像は常にバイナリの中身が.hdrのようだ =拡張子がまちがっていたのでphotoshopで開けなかった。
RenderingLib.export_texture2d(texture2d, texture2d, outputDirPath,OutfileName)
で書き出した。
2,JSXでそのファイルを開き
var docRef = app.open(File(filePath));
doc=docRef
3、リサイズ処理
var fWidth = 512;
var fHeight = 512;
doc.resizeImage(fWidth,fHeight);
4,セーブした
// saveHDR
function step3_saveHDR(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putString(cTID('As '), "Radiance");
desc1.putPath(cTID('In '), new File(filePath));
desc1.putInteger(cTID('DocI'), 253);
desc1.putBoolean(cTID('LwCs'), true);
executeAction(sTID('save'), desc1, dialogMode);
};
5,インポートした
def importMyAssets(self):
texture_task = buildImportTask(texture_HDR, '/Game/Textures')
texture_task2 = buildImportTask(texture_HDR, '/Game/Textures')
executeImportTasks([texture_task,texture_task2])
# unreal. AasetImportTask --https://api.unrealengine.com/INT/PythonAPI/clasa/AssetImportTask.html
def buildImportTask(self,filename,destination_path):
print("buildImportTask -----Start!!!")
task = unreal.AssetImportTask()
task.set_editor_property('automated', True)
task.set_editor_property('destination_name', '')
task.set_editor_property('destination_path',destination_path)
task.set_editor_property('filename', filename)
task.set_editor_property('replace_existing',True)
task.set_editor_property('save', True)
print("buildImportTask ------End!!!")
return task
#unreal.AssetToola- https://api.unrealengine.com/INI/PythonAPI/class/AssetTools.html
def executeImportTasks(self,tasks):
print("executeImportTasks ------------------------Start!!!")
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks(tasks)
for task in tasks:
for path in task.get_editor_property('imported_object_paths'):
print('Imported: is'+ path)
print("executeImportTasks ------------------------End!!!")
インポートすると縦横比が変わって512x256となってしまう。