glTF importer: import data from texture samplers + exporter fix
This commit is contained in:
parent
bc2bf031bd
commit
9f1b91ca13
|
@ -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, 1, 10),
|
||||
"version": (1, 1, 11),
|
||||
'blender': (2, 81, 6),
|
||||
'location': 'File > Import-Export',
|
||||
'description': 'Import-Export as glTF 2.0',
|
||||
|
|
|
@ -64,13 +64,13 @@ def __gather_name(blender_shader_node, export_settings):
|
|||
|
||||
|
||||
def __gather_wrap_s(blender_shader_node, export_settings):
|
||||
if blender_shader_node.extension == 'CLIP':
|
||||
if blender_shader_node.extension == 'EXTEND':
|
||||
return 33071
|
||||
return None
|
||||
|
||||
|
||||
def __gather_wrap_t(blender_shader_node, export_settings):
|
||||
if blender_shader_node.extension == 'CLIP':
|
||||
if blender_shader_node.extension == 'EXTEND':
|
||||
return 33071
|
||||
return None
|
||||
|
||||
|
@ -79,7 +79,7 @@ def __gather_wrap_t(blender_shader_node, export_settings):
|
|||
def gather_sampler_from_texture_slot(blender_texture: bpy.types.TextureSlot, export_settings):
|
||||
magFilter = 9729
|
||||
wrap = 10497
|
||||
if blender_texture.texture.extension == 'CLIP':
|
||||
if blender_texture.texture.extension == 'EXTEND':
|
||||
wrap = 33071
|
||||
|
||||
minFilter = 9986
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
import bpy
|
||||
from .gltf2_blender_image import BlenderImage
|
||||
from ..com.gltf2_blender_conversion import texture_transform_gltf_to_blender
|
||||
from io_scene_gltf2.io.com.gltf2_io import Sampler
|
||||
from io_scene_gltf2.io.com.gltf2_io_debug import print_console
|
||||
from io_scene_gltf2.io.com.gltf2_io_constants import TextureFilter, TextureWrap
|
||||
|
||||
def make_texture_block(gltf, node_tree, tex_info, location, label, name=None, colorspace=None):
|
||||
"""Creates a block of Shader Nodes for the given TextureInfo.
|
||||
|
@ -45,7 +48,12 @@ def make_texture_block(gltf, node_tree, tex_info, location, label, name=None, co
|
|||
if tex_img.image:
|
||||
tex_img.image.colorspace_settings.is_data = True
|
||||
|
||||
# TODO do sampler
|
||||
if pytexture.sampler is not None:
|
||||
pysampler = gltf.data.samplers[pytexture.sampler]
|
||||
else:
|
||||
pysampler = Sampler.from_dict({})
|
||||
set_filtering(tex_img, pysampler)
|
||||
set_wrap_mode(tex_img, pysampler)
|
||||
|
||||
# Mapping (transforms UVs for KHR_texture_transform)
|
||||
|
||||
|
@ -84,3 +92,58 @@ def make_texture_block(gltf, node_tree, tex_info, location, label, name=None, co
|
|||
|
||||
return tex_img
|
||||
|
||||
def set_filtering(tex_img, pysampler):
|
||||
"""Set the filtering/interpolation on an Image Texture from the glTf sampler."""
|
||||
minf = pysampler.min_filter
|
||||
magf = pysampler.mag_filter
|
||||
|
||||
# Ignore mipmapping
|
||||
if minf in [TextureFilter.NearestMipmapNearest, TextureFilter.NearestMipmapLinear]:
|
||||
minf = TextureFilter.Nearest
|
||||
elif minf in [TextureFilter.LinearMipmapNearest, TextureFilter.LinearMipmapLinear]:
|
||||
minf = TextureFilter.Linear
|
||||
|
||||
# If both are nearest or the only specified one was nearest, use nearest.
|
||||
if (minf, magf) in [
|
||||
(TextureFilter.Nearest, TextureFilter.Nearest),
|
||||
(TextureFilter.Nearest, None),
|
||||
(None, TextureFilter.Nearest),
|
||||
]:
|
||||
tex_img.interpolation = 'Closest'
|
||||
else:
|
||||
tex_img.interpolation = 'Linear'
|
||||
|
||||
def set_wrap_mode(tex_img, pysampler):
|
||||
"""Set the extension on an Image Texture node from the pysampler."""
|
||||
wrap_s = pysampler.wrap_s
|
||||
wrap_t = pysampler.wrap_t
|
||||
|
||||
if wrap_s is None:
|
||||
wrap_s = TextureWrap.Repeat
|
||||
if wrap_t is None:
|
||||
wrap_t = TextureWrap.Repeat
|
||||
|
||||
# The extension property on the Image Texture node can only handle the case
|
||||
# where both directions are the same and are either REPEAT or CLAMP_TO_EDGE.
|
||||
if (wrap_s, wrap_t) == (TextureWrap.Repeat, TextureWrap.Repeat):
|
||||
extension = TextureWrap.Repeat
|
||||
elif (wrap_s, wrap_t) == (TextureWrap.ClampToEdge, TextureWrap.ClampToEdge):
|
||||
extension = TextureWrap.ClampToEdge
|
||||
else:
|
||||
print_console('WARNING',
|
||||
'texture wrap mode unsupported: (%s, %s)' % (wrap_name(wrap_s), wrap_name(wrap_t)),
|
||||
)
|
||||
# Default to repeat
|
||||
extension = TextureWrap.Repeat
|
||||
|
||||
if extension == TextureWrap.Repeat:
|
||||
tex_img.extension = 'REPEAT'
|
||||
elif extension == TextureWrap.ClampToEdge:
|
||||
tex_img.extension = 'EXTEND'
|
||||
|
||||
def wrap_name(wrap):
|
||||
if wrap == TextureWrap.ClampToEdge: return 'CLAMP_TO_EDGE'
|
||||
if wrap == TextureWrap.MirroredRepeat: return 'MIRRORED_REPEAT'
|
||||
if wrap == TextureWrap.Repeat: return 'REPEAT'
|
||||
return 'UNKNOWN (%s)' % wrap
|
||||
|
||||
|
|
|
@ -103,6 +103,21 @@ class DataType:
|
|||
}[num_elems]
|
||||
|
||||
|
||||
class TextureFilter(IntEnum):
|
||||
Nearest = 9728
|
||||
Linear = 9729
|
||||
NearestMipmapNearest = 9984
|
||||
LinearMipmapNearest = 9985
|
||||
NearestMipmapLinear = 9986
|
||||
LinearMipmapLinear = 9987
|
||||
|
||||
|
||||
class TextureWrap(IntEnum):
|
||||
ClampToEdge = 33071
|
||||
MirroredRepeat = 33648
|
||||
Repeat = 10497
|
||||
|
||||
|
||||
#################
|
||||
# LEGACY DEFINES
|
||||
|
||||
|
|
Loading…
Reference in New Issue