glTF importer: omit texture mapping & UVMap node when not needed
This commit is contained in:
parent
fb2b2f5cff
commit
b629ab427c
|
@ -15,7 +15,7 @@
|
|||
bl_info = {
|
||||
'name': 'glTF 2.0 format',
|
||||
'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
|
||||
"version": (1, 2, 22),
|
||||
"version": (1, 2, 23),
|
||||
'blender': (2, 82, 7),
|
||||
'location': 'File > Import-Export',
|
||||
'description': 'Import-Export as glTF 2.0',
|
||||
|
|
|
@ -64,10 +64,16 @@ def texture(
|
|||
x -= 340
|
||||
|
||||
# UV Transform (for KHR_texture_transform)
|
||||
mapping = mh.node_tree.nodes.new('ShaderNodeMapping')
|
||||
mapping.location = x - 160, y + 30
|
||||
mapping.vector_type = 'POINT'
|
||||
if tex_info.extensions and 'KHR_texture_transform' in tex_info.extensions:
|
||||
needs_tex_transform = 'KHR_texture_transform' in (tex_info.extensions or {})
|
||||
if needs_tex_transform:
|
||||
mapping = mh.node_tree.nodes.new('ShaderNodeMapping')
|
||||
mapping.location = x - 160, y + 30
|
||||
mapping.vector_type = 'POINT'
|
||||
# Outputs
|
||||
mh.node_tree.links.new(uv_socket, mapping.outputs[0])
|
||||
# Inputs
|
||||
uv_socket = mapping.inputs[0]
|
||||
|
||||
transform = tex_info.extensions['KHR_texture_transform']
|
||||
transform = texture_transform_gltf_to_blender(transform)
|
||||
mapping.inputs['Location'].default_value[0] = transform['offset'][0]
|
||||
|
@ -75,25 +81,21 @@ def texture(
|
|||
mapping.inputs['Rotation'].default_value[2] = transform['rotation']
|
||||
mapping.inputs['Scale'].default_value[0] = transform['scale'][0]
|
||||
mapping.inputs['Scale'].default_value[1] = transform['scale'][1]
|
||||
# Outputs
|
||||
mh.node_tree.links.new(uv_socket, mapping.outputs[0])
|
||||
# Inputs
|
||||
uv_socket = mapping.inputs[0]
|
||||
|
||||
x -= 260
|
||||
x -= 260
|
||||
|
||||
# UV Map
|
||||
uv_map = mh.node_tree.nodes.new('ShaderNodeUVMap')
|
||||
uv_map.location = x - 160, y - 70
|
||||
# Get UVMap
|
||||
uv_idx = tex_info.tex_coord or 0
|
||||
try:
|
||||
uv_idx = tex_info.extensions['KHR_texture_transform']['texCoord']
|
||||
except Exception:
|
||||
pass
|
||||
uv_map.uv_map = 'UVMap' if uv_idx == 0 else 'UVMap.%03d' % uv_idx
|
||||
# Outputs
|
||||
mh.node_tree.links.new(uv_socket, uv_map.outputs[0])
|
||||
if uv_idx != 0 or needs_tex_transform:
|
||||
uv_map = mh.node_tree.nodes.new('ShaderNodeUVMap')
|
||||
uv_map.location = x - 160, y - 70
|
||||
uv_map.uv_map = 'UVMap' if uv_idx == 0 else 'UVMap.%03d' % uv_idx
|
||||
# Outputs
|
||||
mh.node_tree.links.new(uv_socket, uv_map.outputs[0])
|
||||
|
||||
def set_filtering(tex_img, pysampler):
|
||||
"""Set the filtering/interpolation on an Image Texture from the glTf sampler."""
|
||||
|
|
Loading…
Reference in New Issue