Skip to content

Commit

Permalink
Merge branch 'main' into fix_2326
Browse files Browse the repository at this point in the history
  • Loading branch information
julienduroure committed Aug 30, 2024
2 parents 690d2ec + 6244491 commit 9bb85fa
Show file tree
Hide file tree
Showing 114 changed files with 442 additions and 471 deletions.
12 changes: 6 additions & 6 deletions Technical.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

Here are the main step of the importer:

- Reading and parsing file (See *__init__.py* and *gltf2_blender_gltf.py* files)
- Creating virtual tree and compute nodes (see *gltf2_blender_vnode.py* file)
- Reading and parsing file (See *__init__.py* and *blender_gltf.py* files)
- Creating virtual tree and compute nodes (see *vnode.py* file)
- Then Blender objects are created, based on virtual tree nodes (see all *create* static methods of *blender/imp/gltf2_blender_* files)
- For animations, all gltf animations are created, but only the first one is then set as Blender active action.

Expand All @@ -14,7 +14,7 @@ Here are the main step of the importer:
If you want to add a new material extension, here are some steps you need to follow:

- Add the extension in list of managed extensions, in *extensions_managed* list of *glTFImporter* class
- If your extension need a node that is not Principled Shader node, add it, and correspondance links, in *make_output_nodes* function, in *gltf2_blender_pbrMetallicRoughness.py* file
- If your extension need a node that is not Principled Shader node, add it, and correspondance links, in *make_output_nodes* function, in *pbrMetallicRoughness.py* file
- Add your newly created nodes for textures in *calc_locations* function, in order to have the nodes correcly displayed without overlapping
- Add you new function at end of *pbr_metallic_roughness* function. Create this function in a new file, on *blender/imp/* directory

Expand All @@ -23,13 +23,13 @@ If you want to add a new material extension, here are some steps you need to fol

Here are the main step of the exporter:

- A virtual node tree is created, then filtered (See *blender/exp/gltf2_blender_gather_tree.py* file)
- A virtual node tree is created, then filtered (See *blender/exp/tree.py* file)
- Based on this tree, nodes are exported, with some cache, avoiding calculating multiple time the same things
- At end of process, json tabs are created, replacing references to nodes by index in tabs (See multiple *traverse* functions)

### Adding a new material extension

- In *gltf2_blender_gather_materials.py/__gather_extensions*, add a function to manage your extension
- In *materials.py/__gather_extensions*, add a function to manage your extension
- Create an *Extension* class to store your extension data.
- Third parameter is used to set the extension required
- If you need an extension at root of json, use ChildOfRootExtension instead
Expand All @@ -42,4 +42,4 @@ Here are the main step of the exporter:
- In this function, store needed data for calculation, by using *store_data* method
- Create a new file in *blender/exp/*, storing your numpy calculation function. This function will use data stored in ExportImage class
- Example: *Specular*
- If your extension manages some texture, make sure to manage active UVMaps checks in *gltf2_blender_gather_materials.py/gather_material* function
- If your extension manages some texture, make sure to manage active UVMaps checks in *materials.py/gather_material* function
12 changes: 6 additions & 6 deletions addons/io_scene_gltf2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
bl_info = {
'name': 'glTF 2.0 format',
'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
"version": (4, 3, 12),
"version": (4, 3, 13),
'blender': (4, 2, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',
Expand Down Expand Up @@ -165,7 +165,7 @@ def get_format_items(scene, context):
def is_draco_available():
# Initialize on first use
if not hasattr(is_draco_available, "draco_exists"):
from .io.com import gltf2_io_draco_compression_extension
from .io.com import draco as gltf2_io_draco_compression_extension
is_draco_available.draco_exists = gltf2_io_draco_compression_extension.dll_exists()

return is_draco_available.draco_exists
Expand Down Expand Up @@ -1040,9 +1040,9 @@ def execute(self, context):
import os
import datetime
import logging
from .io.com.gltf2_io_debug import Log
from .blender.exp import gltf2_blender_export
from .io.com.gltf2_io_path import path_to_uri
from .io.com.debug import Log
from .blender.exp import export as gltf2_blender_export
from .io.com.path import path_to_uri

if self.will_save_settings:
self.save_settings(context)
Expand Down Expand Up @@ -1881,7 +1881,7 @@ def import_gltf2(self, context):
def unit_import(self, filename, import_settings):
import time
from .io.imp.gltf2_io_gltf import glTFImporter, ImportError
from .blender.imp.gltf2_blender_gltf import BlenderGlTF
from .blender.imp.blender_gltf import BlenderGlTF

try:
gltf_importer = glTFImporter(filename, import_settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from math import sin, cos, tan, atan
from mathutils import Matrix, Vector
import numpy as np
from ...io.com import gltf2_io_constants
from ...io.com import constants as gltf2_io_constants

PBR_WATTS_TO_LUMENS = 683
# Industry convention, biological peak at 555nm, scientific standard as part of SI candela definition.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,21 @@ def skip_sk(key_blocks, k):

def is_first_index(key_blocks, k):
return key_blocks[0].name == k.name

def get_object_from_datapath(blender_object, data_path: str):
if "." in data_path:
# gives us: ('modifiers["Subsurf"]', 'levels')
path_prop, path_attr = data_path.rsplit(".", 1)

# same as: prop = obj.modifiers["Subsurf"]
if path_attr in ["rotation", "scale", "location",
"rotation_axis_angle", "rotation_euler", "rotation_quaternion"]:
prop = blender_object.path_resolve(path_prop)
else:
prop = blender_object.path_resolve(data_path)
else:
prop = blender_object
# single attribute such as name, location... etc
# path_attr = data_path

return prop
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


import bpy
from .gltf2_blender_json import is_json_convertible
from .json_util import is_json_convertible


# Custom properties, which are in most cases present and should not be imported/exported.
Expand Down
2 changes: 1 addition & 1 deletion addons/io_scene_gltf2/blender/com/gltf2_blender_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import math
from mathutils import Matrix, Vector, Quaternion, Euler

from .gltf2_blender_data_path import get_target_property_name
from .data_path import get_target_property_name


def list_to_mathutils(values: typing.List[float], data_path: str) -> typing.Union[Vector, Quaternion, Euler]:
Expand Down
2 changes: 1 addition & 1 deletion addons/io_scene_gltf2/blender/com/gltf2_blender_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import bpy
from ..com.gltf2_blender_material_helpers import get_gltf_node_name, create_settings_group
from ..com.material_helpers import get_gltf_node_name, create_settings_group

################ glTF Material Output node ###########################################

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import numpy as np

from ...io.com import gltf2_io
from ...io.com import gltf2_io_constants
from ...io.exp import gltf2_io_binary_data
from .gltf2_blender_gather_cache import cached
from ...io.com import constants as gltf2_io_constants
from ...io.exp import binary_data as gltf2_io_binary_data
from .cache import cached

@cached
def gather_accessor(buffer_view: gltf2_io_binary_data.BinaryData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
import bpy
import typing
from ....io.com import gltf2_io
from ....io.exp.gltf2_io_user_extensions import export_user_extensions
from ....blender.com.gltf2_blender_conversion import get_gltf_interpolation
from ...com.gltf2_blender_data_path import is_bone_anim_channel
from ...com.gltf2_blender_extras import generate_extras
from ..gltf2_blender_gather_cache import cached
from ..gltf2_blender_gather_tree import VExportNode
from .fcurves.gltf2_blender_gather_fcurves_animation import gather_animation_fcurves
from .sampled.armature.armature_action_sampled import gather_action_armature_sampled
from .sampled.armature.armature_channels import gather_sampled_bone_channel
from .sampled.object.gltf2_blender_gather_object_action_sampled import gather_action_object_sampled
from .sampled.shapekeys.gltf2_blender_gather_sk_action_sampled import gather_action_sk_sampled
from .sampled.object.gltf2_blender_gather_object_channels import gather_object_sampled_channels, gather_sampled_object_channel
from .sampled.shapekeys.gltf2_blender_gather_sk_channels import gather_sampled_sk_channel
from .gltf2_blender_gather_drivers import get_sk_drivers, get_driver_on_shapekey
from .gltf2_blender_gather_animation_utils import reset_bone_matrix, reset_sk_data, link_samplers, add_slide_data, merge_tracks_perform, bake_animation
from ....io.exp.user_extensions import export_user_extensions
from ....blender.com.conversion import get_gltf_interpolation
from ...com.data_path import is_bone_anim_channel
from ...com.extras import generate_extras
from ..cache import cached
from ..tree import VExportNode
from .fcurves.animation import gather_animation_fcurves
from .sampled.armature.action_sampled import gather_action_armature_sampled
from .sampled.armature.channels import gather_sampled_bone_channel
from .sampled.object.action_sampled import gather_action_object_sampled
from .sampled.shapekeys.action_sampled import gather_action_sk_sampled
from .sampled.object.channels import gather_object_sampled_channels, gather_sampled_object_channel
from .sampled.shapekeys.channels import gather_sampled_sk_channel
from .drivers import get_sk_drivers, get_driver_on_shapekey
from .anim_utils import reset_bone_matrix, reset_sk_data, link_samplers, add_slide_data, merge_tracks_perform, bake_animation

def gather_actions_animations(export_settings):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
import bpy
import typing
from mathutils import Matrix
from ....blender.com.gltf2_blender_data_path import get_sk_exported
from ....blender.com.data_path import get_sk_exported
from ....io.com import gltf2_io
from ....io.exp.gltf2_io_user_extensions import export_user_extensions
from ..gltf2_blender_gather_tree import VExportNode
from .sampled.armature.armature_action_sampled import gather_action_armature_sampled
from .sampled.object.gltf2_blender_gather_object_action_sampled import gather_action_object_sampled
from .sampled.shapekeys.gltf2_blender_gather_sk_channels import gather_sampled_sk_channel
from .sampled.data.gltf2_blender_gather_data_channels import gather_data_sampled_channels
from .gltf2_blender_gather_drivers import get_sk_drivers
from ....io.exp.user_extensions import export_user_extensions
from ..tree import VExportNode
from .sampled.armature.action_sampled import gather_action_armature_sampled
from .sampled.object.action_sampled import gather_action_object_sampled
from .sampled.shapekeys.channels import gather_sampled_sk_channel
from .sampled.data.channels import gather_data_sampled_channels
from .drivers import get_sk_drivers

def link_samplers(animation: gltf2_io.Animation, export_settings):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# limitations under the License.


from .gltf2_blender_gather_action import gather_actions_animations
from .gltf2_blender_gather_scene_animation import gather_scene_animations
from .gltf2_blender_gather_tracks import gather_tracks_animations
from .action import gather_actions_animations
from .scene_animation import gather_scene_animations
from .tracks import gather_tracks_animations


def gather_animations(export_settings):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ....blender.com.gltf2_blender_data_path import get_sk_exported, skip_sk
from ...com.gltf2_blender_data_path import get_target_object_path
from ..gltf2_blender_gather_cache import skdriverdiscovercache
from ....blender.com.data_path import get_sk_exported, skip_sk, get_target_object_path
from ..cache import skdriverdiscovercache

@skdriverdiscovercache
def get_sk_drivers(blender_armature_uuid, export_settings):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

import bpy
from .....io.com import gltf2_io
from .....io.exp.gltf2_io_user_extensions import export_user_extensions
from ....com.gltf2_blender_extras import generate_extras
from .gltf2_blender_gather_fcurves_channels import gather_animation_fcurves_channels
from .....io.exp.user_extensions import export_user_extensions
from ....com.extras import generate_extras
from .channels import gather_animation_fcurves_channels

def gather_animation_fcurves(
obj_uuid: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import bpy
import typing
from .....io.com import gltf2_io
from .....io.exp.gltf2_io_user_extensions import export_user_extensions
from ....com.gltf2_blender_conversion import get_target
from ...gltf2_blender_gather_cache import cached
from ...gltf2_blender_gather_joints import gather_joint_vnode
from .....io.exp.user_extensions import export_user_extensions
from ....com.conversion import get_target
from ...cache import cached
from ...joints import gather_joint_vnode

@cached
def gather_fcurve_channel_target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@

import bpy
import typing
from .....io.exp.gltf2_io_user_extensions import export_user_extensions
from .....blender.com.gltf2_blender_data_path import skip_sk
from .....io.exp.user_extensions import export_user_extensions
from .....io.com import gltf2_io
from ....exp.gltf2_blender_gather_cache import cached
from ....com.gltf2_blender_data_path import get_target_object_path, get_target_property_name, get_rotation_modes
from ....com.gltf2_blender_conversion import get_target, get_channel_from_target
from ...gltf2_blender_get import get_object_from_datapath
from .gltf2_blender_gather_fcurves_channel_target import gather_fcurve_channel_target
from .gltf2_blender_gather_fcurves_sampler import gather_animation_fcurves_sampler
from ....exp.cache import cached
from ....com.data_path import get_target_object_path, get_target_property_name, get_rotation_modes, get_object_from_datapath, skip_sk
from ....com.conversion import get_target, get_channel_from_target
from .channel_target import gather_fcurve_channel_target
from .sampler import gather_animation_fcurves_sampler


@cached
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

import bpy
import typing
from .....blender.com.gltf2_blender_data_path import get_sk_exported
from ....com.gltf2_blender_data_path import get_target_object_path
from ...gltf2_blender_gather_cache import cached
from ..gltf2_blender_gather_keyframes import Keyframe
from ....com.data_path import get_target_object_path, get_sk_exported
from ...cache import cached
from ..keyframes import Keyframe


@cached
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
import typing
import mathutils
from .....io.com import gltf2_io
from .....io.com import gltf2_io_constants
from .....blender.com.gltf2_blender_conversion import get_gltf_interpolation
from .....io.exp import gltf2_io_binary_data
from .....io.exp.gltf2_io_user_extensions import export_user_extensions
from ....com.gltf2_blender_data_path import get_target_property_name
from .....io.com import constants as gltf2_io_constants
from .....blender.com.conversion import get_gltf_interpolation
from .....io.exp import binary_data as gltf2_io_binary_data
from .....io.exp.user_extensions import export_user_extensions
from ....com.data_path import get_target_property_name
from ....com import gltf2_blender_math
from ...gltf2_blender_gather_cache import cached
from ...gltf2_blender_gather_accessors import gather_accessor
from ...gltf2_blender_gather_tree import VExportNode
from .gltf2_blender_gather_fcurves_keyframes import gather_fcurve_keyframes
from ...cache import cached
from ...accessors import gather_accessor
from ...tree import VExportNode
from .keyframes import gather_fcurve_keyframes

@cached
def gather_animation_fcurves_sampler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

import bpy
import typing
from ......io.exp.gltf2_io_user_extensions import export_user_extensions
from ......io.exp.user_extensions import export_user_extensions
from ......io.com import gltf2_io
from .....com.gltf2_blender_extras import generate_extras
from ...fcurves.gltf2_blender_gather_fcurves_sampler import gather_animation_fcurves_sampler
from .armature_channels import gather_armature_sampled_channels
from .....com.extras import generate_extras
from ...fcurves.sampler import gather_animation_fcurves_sampler
from .channels import gather_armature_sampled_channels



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ......io.exp.gltf2_io_user_extensions import export_user_extensions
from ......io.exp.user_extensions import export_user_extensions
from ......io.com import gltf2_io
from ....gltf2_blender_gather_cache import cached
from ....gltf2_blender_gather_joints import gather_joint_vnode
from ....cache import cached
from ....joints import gather_joint_vnode

@cached
def gather_armature_sampled_channel_target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
import bpy
import typing
from ......io.com import gltf2_io
from ......io.exp.gltf2_io_user_extensions import export_user_extensions
from .....com.gltf2_blender_conversion import get_gltf_interpolation
from .....com.gltf2_blender_conversion import get_target, get_channel_from_target
from ...fcurves.gltf2_blender_gather_fcurves_channels import get_channel_groups
from ...fcurves.gltf2_blender_gather_fcurves_channels import needs_baking
from ...gltf2_blender_gather_drivers import get_sk_drivers
from ..object.gltf2_blender_gather_object_channels import gather_sampled_object_channel
from ..shapekeys.gltf2_blender_gather_sk_channels import gather_sampled_sk_channel
from .armature_channel_target import gather_armature_sampled_channel_target
from .armature_sampler import gather_bone_sampled_animation_sampler
from ......io.exp.user_extensions import export_user_extensions
from .....com.conversion import get_gltf_interpolation
from .....com.conversion import get_target, get_channel_from_target
from ...fcurves.channels import get_channel_groups
from ...fcurves.channels import needs_baking
from ...drivers import get_sk_drivers
from ..object.channels import gather_sampled_object_channel
from ..shapekeys.channels import gather_sampled_sk_channel
from .channel_target import gather_armature_sampled_channel_target
from .sampler import gather_bone_sampled_animation_sampler

def gather_armature_sampled_channels(armature_uuid, blender_action_name, export_settings) -> typing.List[gltf2_io.AnimationChannel]:
channels = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

import typing
import numpy as np
from ....gltf2_blender_gather_cache import cached
from ...gltf2_blender_gather_keyframes import Keyframe
from ..gltf2_blender_gather_animation_sampling_cache import get_cache_data
from ....cache import cached
from ...keyframes import Keyframe
from ..sampling_cache import get_cache_data

@cached
def gather_bone_sampled_keyframes(
Expand Down
Loading

0 comments on commit 9bb85fa

Please sign in to comment.