glTF : fixes for emission export, correction nodes for lights & camera

This commit is contained in:
Julien Duroure 2018-12-01 06:04:52 +01:00
parent 9a627ee667
commit 40b00140cb
6 changed files with 45 additions and 17 deletions

View File

@ -582,3 +582,4 @@ def unregister():
# remove from the export / import menu
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)

View File

@ -12,13 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import bpy
from typing import Optional, List, Any
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
from typing import Optional
from io_scene_gltf2.io.com import gltf2_io_lights_punctual
from io_scene_gltf2.io.com import gltf2_io_debug
def gather_light_spot(blender_lamp, export_settings) -> Optional[gltf2_io_lights_punctual.LightSpot]:

View File

@ -24,6 +24,7 @@ from io_scene_gltf2.io.com import gltf2_io_debug
from io_scene_gltf2.blender.exp import gltf2_blender_gather_light_spots
from io_scene_gltf2.blender.exp import gltf2_blender_search_node_tree
@cached
def gather_lights_punctual(blender_lamp, export_settings) -> Optional[Dict[str, Any]]:
if not __filter_lights_punctual(blender_lamp, export_settings):

View File

@ -88,9 +88,9 @@ def __gather_double_sided(blender_material, export_settings):
def __gather_emmissive_factor(blender_material, export_settings):
emissive = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Emissive")
if isinstance(emissive, bpy.types.NodeSocket):
return emissive.default_value
emissive_socket = gltf2_blender_get.get_socket_or_texture_slot(blender_material, "Emissive")
if isinstance(emissive_socket, bpy.types.NodeSocket):
return list(emissive_socket.default_value)
return None

View File

@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import math
import bpy
from mathutils import Quaternion
from . import gltf2_blender_export_keys
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
@ -47,6 +49,17 @@ def gather_node(blender_object, export_settings):
)
node.translation, node.rotation, node.scale = __gather_trans_rot_scale(blender_object, export_settings)
if blender_object.type == 'LIGHT':
correction_node = __get_correction_node(blender_object, export_settings)
correction_node.extensions = {"KHR_lights_punctual": node.extensions["KHR_lights_punctual"]}
del node.extensions["KHR_lights_punctual"]
node.children.append(correction_node)
if blender_object.type == 'CAMERA':
correction_node = __get_correction_node(blender_object, export_settings)
correction_node.camera = node.camera
node.camera = None
node.children.append(correction_node)
return node
@ -171,3 +184,24 @@ def __gather_skin(blender_object, export_settings):
def __gather_weights(blender_object, export_settings):
return None
def __get_correction_node(blender_object, export_settings):
correction_quaternion = gltf2_blender_extract.convert_swizzle_rotation(
Quaternion((1.0, 0.0, 0.0), math.radians(-90.0)), export_settings)
correction_quaternion = [correction_quaternion[1], correction_quaternion[2],
correction_quaternion[3], correction_quaternion[0]]
return gltf2_io.Node(
camera=None,
children=None,
extensions=None,
extras=None,
matrix=None,
mesh=None,
name=blender_object.name + '_Orientation',
rotation=correction_quaternion,
scale=None,
skin=None,
translation=None,
weights=None
)

View File

@ -43,17 +43,14 @@ def get_socket_or_texture_slot(blender_material: bpy.types.Material, name: str):
:return: either a blender NodeSocket, if the material is a node tree or a blender Texture otherwise
"""
if blender_material.node_tree and blender_material.use_nodes:
if name == "Emissive":
# Emissive is a special case as the input node in the 'Emission' shader node is named 'Color' and only the
# output is named 'Emission'
links = [link for link in blender_material.node_tree.links if link.from_socket.name == 'Emission']
if not links:
return None
return links[0].to_socket
i = [input for input in blender_material.node_tree.inputs]
o = [output for output in blender_material.node_tree.outputs]
nodes = [node for node in blender_material.node_tree.nodes]
nodes = filter(lambda n: isinstance(n, bpy.types.ShaderNodeBsdfPrincipled), nodes)
if name == "Emissive":
nodes = filter(lambda n: isinstance(n, bpy.types.ShaderNodeEmission), nodes)
name = "Color"
else:
nodes = filter(lambda n: isinstance(n, bpy.types.ShaderNodeBsdfPrincipled), nodes)
inputs = sum([[input for input in node.inputs if input.name == name] for node in nodes], [])
if not inputs:
return None