Support for textures

This commit is contained in:
Simone Barbieri 2021-05-25 12:55:20 +01:00
parent c72f9f8c73
commit 2a4b421914
3 changed files with 51 additions and 7 deletions

View file

@ -28,7 +28,7 @@ class BlendLookLoader(plugin.AssetLoader):
color = "orange"
def get_all_children(self, obj):
children = obj.children
children = list(obj.children)
for child in children:
children.extend(child.children)
@ -47,7 +47,7 @@ class BlendLookLoader(plugin.AssetLoader):
materials = []
for entry in data:
file = entry.get('filename')
file = entry.get('fbx_filename')
if file is None:
continue
@ -56,6 +56,14 @@ class BlendLookLoader(plugin.AssetLoader):
mesh = [o for o in bpy.context.scene.objects if o.select_get()][0]
material = mesh.data.materials[0]
texture_file = entry.get('tga_filename')
if texture_file:
node_tree = material.node_tree
pbsdf = node_tree.nodes['Principled BSDF']
base_color = pbsdf.inputs[0]
tex_node = base_color.links[0].from_node
tex_node.image.filepath = f"{materials_path}/{texture_file}"
materials.append(material)
for child in self.get_all_children(active_obj):

View file

@ -63,4 +63,4 @@ class CreateLook(Creator):
unreal.EditorAssetLibrary.save_asset(object_path)
pipeline.imprint(f"{full_path}/{container_name}", self.data)
pipeline.imprint(f"{full_path}/{container_name}", self.data)

View file

@ -2,6 +2,7 @@ import json
import os
import unreal
from unreal import MaterialEditingLibrary as mat_lib
import openpype.api
from avalon import io
@ -32,6 +33,43 @@ class ExtractLook(openpype.api.Extractor):
name = asset.get_editor_property('asset_name')
json_element = {'material': str(name)}
material_obj = object.get_editor_property('static_materials')[0]
material = material_obj.material_interface
base_color = mat_lib.get_material_property_input_node(
material, unreal.MaterialProperty.MP_BASE_COLOR)
base_color_name = base_color.get_editor_property('parameter_name')
texture = mat_lib.get_material_default_texture_parameter_value(
material, base_color_name)
if texture:
# Export Texture
tga_filename = f"{instance.name}_{name}_texture.tga"
tga_exporter = unreal.TextureExporterTGA()
tga_export_task = unreal.AssetExportTask()
tga_export_task.set_editor_property('exporter', tga_exporter)
tga_export_task.set_editor_property('automated', True)
tga_export_task.set_editor_property('object', texture)
tga_export_task.set_editor_property(
'filename', f"{stagingdir}/{tga_filename}")
tga_export_task.set_editor_property('prompt', False)
tga_export_task.set_editor_property('selected', False)
unreal.Exporter.run_asset_export_task(tga_export_task)
json_element['tga_filename'] = tga_filename
transfers.append((
f"{stagingdir}/{tga_filename}",
f"{resources_dir}/{tga_filename}"))
fbx_filename = f"{instance.name}_{name}.fbx"
fbx_exporter = unreal.StaticMeshExporterFBX()
@ -53,14 +91,12 @@ class ExtractLook(openpype.api.Extractor):
unreal.Exporter.run_asset_export_task(task)
json_element['fbx_filename'] = fbx_filename
transfers.append((
f"{stagingdir}/{fbx_filename}",
f"{resources_dir}/{fbx_filename}"))
json_element = {
'material': str(name),
'filename': fbx_filename
}
json_data.append(json_element)
json_filename = f"{instance.name}.json"