Skip to content

Commit

Permalink
Add all avalaible materials in export
Browse files Browse the repository at this point in the history
  • Loading branch information
StidOfficial committed May 29, 2020
1 parent 9057985 commit bd4109f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __export(export_settings):


def __gather_gltf(exporter, export_settings):
active_scene_idx, scenes, animations = gltf2_blender_gather.gather_gltf2(export_settings)
active_scene_idx, scenes, animations, materials = gltf2_blender_gather.gather_gltf2(export_settings)

plan = {'active_scene_idx': active_scene_idx, 'scenes': scenes, 'animations': animations}
export_user_extensions('gather_gltf_hook', export_settings, plan)
Expand All @@ -75,7 +75,8 @@ def __gather_gltf(exporter, export_settings):
exporter.add_scene(scene, idx==active_scene_idx)
for animation in animations:
exporter.add_animation(animation)

for material in materials:
exporter.add_material(material)

def __create_buffer(exporter, export_settings):
buffer = bytes()
Expand Down
9 changes: 8 additions & 1 deletion addons/io_scene_gltf2/blender/exp/gltf2_blender_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from io_scene_gltf2.io.com.gltf2_io_debug import print_console
from io_scene_gltf2.blender.exp import gltf2_blender_gather_nodes
from io_scene_gltf2.blender.exp import gltf2_blender_gather_animations
from io_scene_gltf2.blender.exp import gltf2_blender_gather_materials
from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached
from ..com.gltf2_blender_extras import generate_extras
from io_scene_gltf2.blender.exp import gltf2_blender_export_keys
Expand All @@ -32,14 +33,20 @@ def gather_gltf2(export_settings):
"""
scenes = []
animations = [] # unfortunately animations in gltf2 are just as 'root' as scenes.
materials = []
active_scene = None
for blender_scene in bpy.data.scenes:
scenes.append(__gather_scene(blender_scene, export_settings))
if export_settings[gltf2_blender_export_keys.ANIMATIONS]:
animations += __gather_animations(blender_scene, export_settings)
if bpy.context.scene.name == blender_scene.name:
active_scene = len(scenes) -1
return active_scene, scenes, animations

for material in bpy.data.materials:
double_sided = not material.use_backface_culling
materials.append(gltf2_blender_gather_materials.gather_material(material, double_sided, export_settings))

return active_scene, scenes, animations, materials


@cached
Expand Down
12 changes: 12 additions & 0 deletions addons/io_scene_gltf2/blender/exp/gltf2_blender_gltf2_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ def add_animation(self, animation: gltf2_io.Animation):

self.__traverse(animation)

def add_material(self, material: gltf2_io.Material):
"""
Add an material to the glTF.
:param material: glTF material, with python style references (names)
:return: nothing
"""
if self.__finalized:
raise RuntimeError("Tried to add material to finalized glTF file")

self.__traverse(material)

def __to_reference(self, property):
"""
Append a child of root property to its respective list and return a reference into said list.
Expand Down

0 comments on commit bd4109f

Please sign in to comment.