Skip to content

Commit

Permalink
converter: Attempt to reuse texture stages
Browse files Browse the repository at this point in the history
  • Loading branch information
Moguri committed Jul 13, 2024
1 parent 0d469fc commit d316901
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions gltf/_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def __init__(
self.buffers = {}
self.lights = {}
self.textures = {}
self.texture_stages = {}
self.mat_states = {}
self.mat_mesh_map = {}
self.meshes = {}
Expand Down Expand Up @@ -540,6 +541,18 @@ def get_buffer_from_accessor(self, gltf_data, accid, unpack=True):
else:
return buffdata

def get_texture_stage(self, slot_name, texmode, texcoord):
texcoord = str(texcoord)
tshash = slot_name + str(texmode) + texcoord

if tshash not in self.texture_stages:
texstage = TextureStage(slot_name)
texstage.set_texcoord_name(InternalName.get_texcoord_name(texcoord))
texstage.set_mode(texmode)
self.texture_stages[tshash] = texstage

return self.texture_stages[tshash]

def make_texture_srgb(self, texture):
if self.settings.no_srgb:
return
Expand Down Expand Up @@ -671,9 +684,11 @@ def add_texture(gltf_texture, slot_name, texmode, *, make_srgb=False):
if make_srgb:
self.make_texture_srgb(texdata)

texstage = TextureStage(slot_name)
texstage.set_texcoord_name(InternalName.get_texcoord_name(str(gltf_texture.get('texCoord', 0))))
texstage.set_mode(texmode)
texstage = self.get_texture_stage(
slot_name,
texmode,
gltf_texture.get('texCoord', 0)
)
tex_attrib = tex_attrib.add_on_stage(texstage, texdata)

transform_ext = gltf_texture.get('extensions', {}).get('KHR_texture_transform')
Expand Down

0 comments on commit d316901

Please sign in to comment.