glTF exporter: remove some unused code
This commit is contained in:
parent
1ec2d0647e
commit
3e70027f57
|
@ -201,11 +201,5 @@ def needs_baking(channels: typing.Tuple[bpy.types.FCurve],
|
|||
"Baking animation because of differently located keyframes in one channel")
|
||||
return True
|
||||
|
||||
# # Baking is required when the animation targets a quaternion with bezier interpolation
|
||||
# if channels[0].data_path == "rotation_quaternion" and interpolation == "BEZIER":
|
||||
# gltf2_io_debug.print_console("WARNING",
|
||||
# "Baking animation because targeting a quaternion with bezier interpolation")
|
||||
# return True
|
||||
|
||||
return False
|
||||
|
||||
|
|
|
@ -12,24 +12,11 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#
|
||||
# Imports
|
||||
#
|
||||
|
||||
import bpy
|
||||
from mathutils import Vector, Matrix
|
||||
|
||||
from . import gltf2_blender_export_keys
|
||||
from ...io.exp import gltf2_io_get
|
||||
from ...blender.com.gltf2_blender_conversion import texture_transform_blender_to_gltf
|
||||
from io_scene_gltf2.io.com import gltf2_io_debug
|
||||
#
|
||||
# Globals
|
||||
#
|
||||
|
||||
#
|
||||
# Functions
|
||||
#
|
||||
|
||||
|
||||
def get_animation_target(action_group: bpy.types.ActionGroup):
|
||||
|
@ -104,247 +91,6 @@ def find_shader_image_from_shader_socket(shader_socket, max_hops=10):
|
|||
return None
|
||||
|
||||
|
||||
def get_shader_add_to_shader_node(shader_node):
|
||||
|
||||
if shader_node is None:
|
||||
return None
|
||||
|
||||
if len(shader_node.outputs['BSDF'].links) == 0:
|
||||
return None
|
||||
|
||||
to_node = shader_node.outputs['BSDF'].links[0].to_node
|
||||
|
||||
if not isinstance(to_node, bpy.types.ShaderNodeAddShader):
|
||||
return None
|
||||
|
||||
return to_node
|
||||
|
||||
#
|
||||
|
||||
|
||||
def get_shader_emission_from_shader_add(shader_add):
|
||||
|
||||
if shader_add is None:
|
||||
return None
|
||||
|
||||
if not isinstance(shader_add, bpy.types.ShaderNodeAddShader):
|
||||
return None
|
||||
|
||||
from_node = None
|
||||
|
||||
for input in shader_add.inputs:
|
||||
|
||||
if len(input.links) == 0:
|
||||
continue
|
||||
|
||||
from_node = input.links[0].from_node
|
||||
|
||||
if isinstance(from_node, bpy.types.ShaderNodeEmission):
|
||||
break
|
||||
|
||||
return from_node
|
||||
|
||||
|
||||
def get_shader_mapping_from_shader_image(shader_image):
|
||||
|
||||
if shader_image is None:
|
||||
return None
|
||||
|
||||
if not isinstance(shader_image, bpy.types.ShaderNodeTexImage):
|
||||
return None
|
||||
|
||||
if shader_image.inputs.get('Vector') is None:
|
||||
return None
|
||||
|
||||
if len(shader_image.inputs['Vector'].links) == 0:
|
||||
return None
|
||||
|
||||
from_node = shader_image.inputs['Vector'].links[0].from_node
|
||||
|
||||
#
|
||||
|
||||
if not isinstance(from_node, bpy.types.ShaderNodeMapping):
|
||||
return None
|
||||
|
||||
return from_node
|
||||
|
||||
|
||||
def get_image_material_usage_to_socket(shader_image, socket_name):
|
||||
if shader_image is None:
|
||||
return -1
|
||||
|
||||
if not isinstance(shader_image, bpy.types.ShaderNodeTexImage):
|
||||
return -2
|
||||
|
||||
if shader_image.outputs.get('Color') is None:
|
||||
return -3
|
||||
|
||||
if len(shader_image.outputs.get('Color').links) == 0:
|
||||
return -4
|
||||
|
||||
for img_link in shader_image.outputs.get('Color').links:
|
||||
separate_rgb = img_link.to_node
|
||||
|
||||
if not isinstance(separate_rgb, bpy.types.ShaderNodeSeparateRGB):
|
||||
continue
|
||||
|
||||
for i, channel in enumerate("RGB"):
|
||||
if separate_rgb.outputs.get(channel) is None:
|
||||
continue
|
||||
for link in separate_rgb.outputs.get(channel).links:
|
||||
if socket_name == link.to_socket.name:
|
||||
return i
|
||||
|
||||
return -6
|
||||
|
||||
|
||||
def get_emission_node_from_lamp_output_node(lamp_node):
|
||||
if lamp_node is None:
|
||||
return None
|
||||
|
||||
if not isinstance(lamp_node, bpy.types.ShaderNodeOutputLamp):
|
||||
return None
|
||||
|
||||
if lamp_node.inputs.get('Surface') is None:
|
||||
return None
|
||||
|
||||
if len(lamp_node.inputs.get('Surface').links) == 0:
|
||||
return None
|
||||
|
||||
from_node = lamp_node.inputs.get('Surface').links[0].from_node
|
||||
if isinstance(from_node, bpy.types.ShaderNodeEmission):
|
||||
return from_node
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_ligth_falloff_node_from_emission_node(emission_node, type):
|
||||
if emission_node is None:
|
||||
return None
|
||||
|
||||
if not isinstance(emission_node, bpy.types.ShaderNodeEmission):
|
||||
return None
|
||||
|
||||
if emission_node.inputs.get('Strength') is None:
|
||||
return None
|
||||
|
||||
if len(emission_node.inputs.get('Strength').links) == 0:
|
||||
return None
|
||||
|
||||
from_node = emission_node.inputs.get('Strength').links[0].from_node
|
||||
if not isinstance(from_node, bpy.types.ShaderNodeLightFalloff):
|
||||
return None
|
||||
|
||||
if from_node.outputs.get(type) is None:
|
||||
return None
|
||||
|
||||
if len(from_node.outputs.get(type).links) == 0:
|
||||
return None
|
||||
|
||||
if emission_node != from_node.outputs.get(type).links[0].to_node:
|
||||
return None
|
||||
|
||||
return from_node
|
||||
|
||||
|
||||
def get_shader_image_from_shader_node(name, shader_node):
|
||||
|
||||
if shader_node is None:
|
||||
return None
|
||||
|
||||
if not isinstance(shader_node, bpy.types.ShaderNodeGroup) and \
|
||||
not isinstance(shader_node, bpy.types.ShaderNodeBsdfPrincipled) and \
|
||||
not isinstance(shader_node, bpy.types.ShaderNodeEmission):
|
||||
return None
|
||||
|
||||
if shader_node.inputs.get(name) is None:
|
||||
return None
|
||||
|
||||
if len(shader_node.inputs[name].links) == 0:
|
||||
return None
|
||||
|
||||
from_node = shader_node.inputs[name].links[0].from_node
|
||||
|
||||
#
|
||||
|
||||
if isinstance(from_node, bpy.types.ShaderNodeNormalMap):
|
||||
|
||||
name = 'Color'
|
||||
|
||||
if len(from_node.inputs[name].links) == 0:
|
||||
return None
|
||||
|
||||
from_node = from_node.inputs[name].links[0].from_node
|
||||
|
||||
#
|
||||
|
||||
if not isinstance(from_node, bpy.types.ShaderNodeTexImage):
|
||||
return None
|
||||
|
||||
return from_node
|
||||
|
||||
|
||||
def get_texture_index_from_shader_node(export_settings, glTF, name, shader_node):
|
||||
"""Return the texture index in the glTF array."""
|
||||
from_node = get_shader_image_from_shader_node(name, shader_node)
|
||||
|
||||
if from_node is None:
|
||||
return -1
|
||||
|
||||
#
|
||||
|
||||
if from_node.image is None or from_node.image.size[0] == 0 or from_node.image.size[1] == 0:
|
||||
return -1
|
||||
|
||||
return gltf2_io_get.get_texture_index(glTF, from_node.image.name)
|
||||
|
||||
|
||||
def get_texture_index_from_export_settings(export_settings, name):
|
||||
"""Return the texture index in the glTF array."""
|
||||
|
||||
|
||||
def get_texcoord_index_from_shader_node(glTF, name, shader_node):
|
||||
"""Return the texture coordinate index, if assigned and used."""
|
||||
from_node = get_shader_image_from_shader_node(name, shader_node)
|
||||
|
||||
if from_node is None:
|
||||
return 0
|
||||
|
||||
#
|
||||
|
||||
if len(from_node.inputs['Vector'].links) == 0:
|
||||
return 0
|
||||
|
||||
input_node = from_node.inputs['Vector'].links[0].from_node
|
||||
|
||||
#
|
||||
|
||||
if isinstance(input_node, bpy.types.ShaderNodeMapping):
|
||||
|
||||
if len(input_node.inputs['Vector'].links) == 0:
|
||||
return 0
|
||||
|
||||
input_node = input_node.inputs['Vector'].links[0].from_node
|
||||
|
||||
#
|
||||
|
||||
if not isinstance(input_node, bpy.types.ShaderNodeUVMap):
|
||||
return 0
|
||||
|
||||
if input_node.uv_map == '':
|
||||
return 0
|
||||
|
||||
#
|
||||
|
||||
# Try to gather map index.
|
||||
for blender_mesh in bpy.data.meshes:
|
||||
texCoordIndex = blender_mesh.uv_layers.find(input_node.uv_map)
|
||||
if texCoordIndex >= 0:
|
||||
return texCoordIndex
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def get_texture_transform_from_texture_node(texture_node):
|
||||
if not isinstance(texture_node, bpy.types.ShaderNodeTexImage):
|
||||
return None
|
||||
|
@ -426,28 +172,6 @@ def get_texture_transform_from_texture_node(texture_node):
|
|||
return texture_transform
|
||||
|
||||
|
||||
def get_image_uri(export_settings, blender_image):
|
||||
"""Return the final URI depending on a file path."""
|
||||
file_format = get_image_format(export_settings, blender_image)
|
||||
extension = '.jpg' if file_format == 'JPEG' else '.png'
|
||||
|
||||
return gltf2_io_get.get_image_name(blender_image.name) + extension
|
||||
|
||||
|
||||
def get_image_format(export_settings, blender_image):
|
||||
"""
|
||||
Return the final output format of the given image.
|
||||
|
||||
Only PNG and JPEG are supported as outputs - all other formats must be converted.
|
||||
"""
|
||||
if blender_image.file_format in ['PNG', 'JPEG']:
|
||||
return blender_image.file_format
|
||||
|
||||
use_alpha = export_settings[gltf2_blender_export_keys.FILTERED_IMAGES_USE_ALPHA].get(blender_image.name)
|
||||
|
||||
return 'PNG' if use_alpha else 'JPEG'
|
||||
|
||||
|
||||
def get_node(data_path):
|
||||
"""Return Blender node on a given Blender data path."""
|
||||
if data_path is None:
|
||||
|
@ -465,13 +189,3 @@ def get_node(data_path):
|
|||
|
||||
return node_name[:(index)]
|
||||
|
||||
|
||||
def get_data_path(data_path):
|
||||
"""Return Blender data path."""
|
||||
index = data_path.rfind('.')
|
||||
|
||||
if index == -1:
|
||||
return data_path
|
||||
|
||||
return data_path[(index + 1):]
|
||||
|
||||
|
|
|
@ -1,316 +0,0 @@
|
|||
# Copyright 2018 The glTF-Blender-IO authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
#
|
||||
# Imports
|
||||
#
|
||||
|
||||
import os
|
||||
|
||||
#
|
||||
# Globals
|
||||
#
|
||||
|
||||
#
|
||||
# Functions
|
||||
#
|
||||
|
||||
|
||||
def get_material_requires_texcoords(glTF, index):
|
||||
"""Query function, if a material "needs" texture coordinates. This is the case, if a texture is present and used."""
|
||||
if glTF.materials is None:
|
||||
return False
|
||||
|
||||
materials = glTF.materials
|
||||
|
||||
if index < 0 or index >= len(materials):
|
||||
return False
|
||||
|
||||
material = materials[index]
|
||||
|
||||
# General
|
||||
|
||||
if material.emissive_texture is not None:
|
||||
return True
|
||||
|
||||
if material.normal_texture is not None:
|
||||
return True
|
||||
|
||||
if material.occlusion_texture is not None:
|
||||
return True
|
||||
|
||||
# Metallic roughness
|
||||
|
||||
if material.pbr_metallic_roughness is not None and \
|
||||
material.pbr_metallic_roughness.base_color_texture is not None:
|
||||
return True
|
||||
|
||||
if material.pbr_metallic_roughness is not None and \
|
||||
material.pbr_metallic_roughness.metallic_roughness_texture is not None:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_material_requires_normals(glTF, index):
|
||||
"""
|
||||
Query function, if a material "needs" normals. This is the case, if a texture is present and used.
|
||||
|
||||
At point of writing, same function as for texture coordinates.
|
||||
"""
|
||||
return get_material_requires_texcoords(glTF, index)
|
||||
|
||||
|
||||
def get_material_index(glTF, name):
|
||||
"""Return the material index in the glTF array."""
|
||||
if name is None:
|
||||
return -1
|
||||
|
||||
if glTF.materials is None:
|
||||
return -1
|
||||
|
||||
index = 0
|
||||
for material in glTF.materials:
|
||||
if material.name == name:
|
||||
return index
|
||||
|
||||
index += 1
|
||||
|
||||
return -1
|
||||
|
||||
|
||||
def get_mesh_index(glTF, name):
|
||||
"""Return the mesh index in the glTF array."""
|
||||
if glTF.meshes is None:
|
||||
return -1
|
||||
|
||||
index = 0
|
||||
for mesh in glTF.meshes:
|
||||
if mesh.name == name:
|
||||
return index
|
||||
|
||||
index += 1
|
||||
|
||||
return -1
|
||||
|
||||
|
||||
def get_skin_index(glTF, name, index_offset):
|
||||
"""Return the skin index in the glTF array."""
|
||||
if glTF.skins is None:
|
||||
return -1
|
||||
|
||||
skeleton = get_node_index(glTF, name)
|
||||
|
||||
index = 0
|
||||
for skin in glTF.skins:
|
||||
if skin.skeleton == skeleton:
|
||||
return index + index_offset
|
||||
|
||||
index += 1
|
||||
|
||||
return -1
|
||||
|
||||
|
||||
def get_camera_index(glTF, name):
|
||||
"""Return the camera index in the glTF array."""
|
||||
if glTF.cameras is None:
|
||||
return -1
|
||||
|
||||
index = 0
|
||||
for camera in glTF.cameras:
|
||||
if camera.name == name:
|
||||
return index
|
||||
|
||||
index += 1
|
||||
|
||||
return -1
|
||||
|
||||
|
||||
def get_light_index(glTF, name):
|
||||
"""Return the light index in the glTF array."""
|
||||
if glTF.extensions is None:
|
||||
return -1
|
||||
|
||||
extensions = glTF.extensions
|
||||
|
||||
if extensions.get('KHR_lights_punctual') is None:
|
||||
return -1
|
||||
|
||||
khr_lights_punctual = extensions['KHR_lights_punctual']
|
||||
|
||||
if khr_lights_punctual.get('lights') is None:
|
||||
return -1
|
||||
|
||||
lights = khr_lights_punctual['lights']
|
||||
|
||||
index = 0
|
||||
for light in lights:
|
||||
if light['name'] == name:
|
||||
return index
|
||||
|
||||
index += 1
|
||||
|
||||
return -1
|
||||
|
||||
|
||||
def get_node_index(glTF, name):
|
||||
"""Return the node index in the glTF array."""
|
||||
if glTF.nodes is None:
|
||||
return -1
|
||||
|
||||
index = 0
|
||||
for node in glTF.nodes:
|
||||
if node.name == name:
|
||||
return index
|
||||
|
||||
index += 1
|
||||
|
||||
return -1
|
||||
|
||||
|
||||
def get_scene_index(glTF, name):
|
||||
"""Return the scene index in the glTF array."""
|
||||
if glTF.scenes is None:
|
||||
return -1
|
||||
|
||||
index = 0
|
||||
for scene in glTF.scenes:
|
||||
if scene.name == name:
|
||||
return index
|
||||
|
||||
index += 1
|
||||
|
||||
return -1
|
||||
|
||||
|
||||
def get_texture_index(glTF, filename):
|
||||
"""Return the texture index in the glTF array by a given file path."""
|
||||
if glTF.textures is None:
|
||||
return -1
|
||||
|
||||
image_index = get_image_index(glTF, filename)
|
||||
|
||||
if image_index == -1:
|
||||
return -1
|
||||
|
||||
for texture_index, texture in enumerate(glTF.textures):
|
||||
if image_index == texture.source:
|
||||
return texture_index
|
||||
|
||||
return -1
|
||||
|
||||
|
||||
def get_image_index(glTF, filename):
|
||||
"""Return the image index in the glTF array."""
|
||||
if glTF.images is None:
|
||||
return -1
|
||||
|
||||
image_name = get_image_name(filename)
|
||||
|
||||
for index, current_image in enumerate(glTF.images):
|
||||
if image_name == current_image.name:
|
||||
return index
|
||||
|
||||
return -1
|
||||
|
||||
|
||||
def get_image_name(filename):
|
||||
"""Return user-facing, extension-agnostic name for image."""
|
||||
return os.path.splitext(filename)[0]
|
||||
|
||||
|
||||
def get_scalar(default_value, init_value=0.0):
|
||||
"""Return scalar with a given default/fallback value."""
|
||||
return_value = init_value
|
||||
|
||||
if default_value is None:
|
||||
return return_value
|
||||
|
||||
return_value = default_value
|
||||
|
||||
return return_value
|
||||
|
||||
|
||||
def get_vec2(default_value, init_value=[0.0, 0.0]):
|
||||
"""Return vec2 with a given default/fallback value."""
|
||||
return_value = init_value
|
||||
|
||||
if default_value is None or len(default_value) < 2:
|
||||
return return_value
|
||||
|
||||
index = 0
|
||||
for number in default_value:
|
||||
return_value[index] = number
|
||||
|
||||
index += 1
|
||||
if index == 2:
|
||||
return return_value
|
||||
|
||||
return return_value
|
||||
|
||||
|
||||
def get_vec3(default_value, init_value=[0.0, 0.0, 0.0]):
|
||||
"""Return vec3 with a given default/fallback value."""
|
||||
return_value = init_value
|
||||
|
||||
if default_value is None or len(default_value) < 3:
|
||||
return return_value
|
||||
|
||||
index = 0
|
||||
for number in default_value:
|
||||
return_value[index] = number
|
||||
|
||||
index += 1
|
||||
if index == 3:
|
||||
return return_value
|
||||
|
||||
return return_value
|
||||
|
||||
|
||||
def get_vec4(default_value, init_value=[0.0, 0.0, 0.0, 1.0]):
|
||||
"""Return vec4 with a given default/fallback value."""
|
||||
return_value = init_value
|
||||
|
||||
if default_value is None or len(default_value) < 4:
|
||||
return return_value
|
||||
|
||||
index = 0
|
||||
for number in default_value:
|
||||
return_value[index] = number
|
||||
|
||||
index += 1
|
||||
if index == 4:
|
||||
return return_value
|
||||
|
||||
return return_value
|
||||
|
||||
|
||||
def get_index(elements, name):
|
||||
"""Return index of a glTF element by a given name."""
|
||||
if elements is None or name is None:
|
||||
return -1
|
||||
|
||||
index = 0
|
||||
for element in elements:
|
||||
if isinstance(element, dict):
|
||||
if element.get('name') == name:
|
||||
return index
|
||||
else:
|
||||
if element.name == name:
|
||||
return index
|
||||
|
||||
index += 1
|
||||
|
||||
return -1
|
||||
|
Loading…
Reference in New Issue