Skip to content

Commit

Permalink
Fix blend shapes (#161)
Browse files Browse the repository at this point in the history
* fix blend shapes;zip dir;scale textures

* factor multiply fix

* moved below root xform

* metadata

* toggle alpha

* updated changelog

* metadata update

* increment minor version
  • Loading branch information
kcoley committed Jun 17, 2019
1 parent bfa8bfe commit c0301fc
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 116 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,15 @@

## 0.1.23 (2019-02-27)
**Fixed Bugs:**
- Fixed a bug where `TEXCOORD_1` attribute was not being read (https://github.com/kcoley/gltf2usd/issues/149)
- Fixed a bug where `TEXCOORD_1` attribute was not being read (https://github.com/kcoley/gltf2usd/issues/149)

## 0.2.0 (2019-02-27)
**Fixed Bugs:**
- Fix blend shapes
**Changes:**
- The Usd file generation now happens in a temp directory
- Add `--scale-texture` optional parameter to multiply metallic/roughness factors by textures
- Added creator metadata
- Moved material scope to below root xform
- connect opacity of diffuse texture if alpha blend or mask is used
- Export extras data on nodes and glTF asset
8 changes: 4 additions & 4 deletions Source/_gltf2usd/gltf2/Animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pxr import Gf

class AnimationSampler:
class AnimationSampler(object):
def __init__(self, sampler_entry, animation):
self._animation = animation
self._input_accessor_index = sampler_entry['input']
Expand Down Expand Up @@ -117,15 +117,15 @@ def _step_interpolate_values(self, value0, value1, factor):



class AnimationChannelTarget:
class AnimationChannelTarget(object):
def __init__(self, animation_channel_target_entry):
self._node_index = animation_channel_target_entry['node']
self._path = animation_channel_target_entry['path']
@property
def path(self):
return self._path

class AnimationChannel:
class AnimationChannel(object):
def __init__(self, channel_entry, animation):
self._sampler_index = channel_entry['sampler']
self._target = AnimationChannelTarget(channel_entry['target'])
Expand All @@ -143,7 +143,7 @@ def sampler(self):
return self._animation._samplers[self._sampler_index]


class Animation:
class Animation(object):
def __init__(self, animation_entry, index, gltf_loader):
self._gltf_loader = gltf_loader
self._name = animation_entry['name'] if ('name' in animation_entry) else 'animation_{}'.format(index)
Expand Down
28 changes: 28 additions & 0 deletions Source/_gltf2usd/gltf2/Asset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Asset(object):
def __init__(self, asset_entry):
self._generator = asset_entry['generator'] if 'generator' in asset_entry else None
self._version = asset_entry['version'] if 'version' in asset_entry else None
self._extras = asset_entry['extras'] if 'extras' in asset_entry else {}
self._copyright = asset_entry['copyright'] if 'copyright' in asset_entry else None
self._minversion = asset_entry['minversion'] if 'minversion' in asset_entry else None

@property
def generator(self):
return self._generator

@property
def version(self):
return self._version

@property
def minversion(self):
return self._minversion

@property
def copyright(self):
return self._copyright

@property
def extras(self):
return self._extras

18 changes: 17 additions & 1 deletion Source/_gltf2usd/gltf2/GLTFImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_image_path(self):
return self._image_path


def write_to_directory(self, output_dir, channels, texture_prefix, offset = [0,0], scale = [1,1], rotation = 0):
def write_to_directory(self, output_dir, channels, texture_prefix, offset = [0,0], scale = [1,1], rotation = 0, scale_factor=None):
file_name = '{0}_{1}'.format(texture_prefix, ntpath.basename(self._name)) if texture_prefix else ntpath.basename(self._name)
destination = os.path.join(output_dir, file_name)
original_img = Image.open(self._image_path)
Expand Down Expand Up @@ -87,6 +87,22 @@ def write_to_directory(self, output_dir, channels, texture_prefix, offset = [0,0
if destination.endswith('jpg') or destination.endswith('.jpeg'):
img = img.convert('RGB')

if scale_factor:
width, height = img.size
for x in range(width):
for y in range(height):
value = img.getpixel((x, y))
if isinstance(value, int):
value = value * scale_factor[0]
img.putpixel((x, y), (int(value)))
else:
value = list(value)
value[0] = int(value[0] * scale_factor[0])
value[1] = int(value[1] * scale_factor[1])
value[2] = int(value[2] * scale_factor[2])
value = tuple(value)
img.putpixel((x, y), (value))

#apply texture transform if necessary
if offset != [0,0] or scale != [1,1] or rotation != 0:
if not self._generate_texture_transform_texture:
Expand Down
6 changes: 3 additions & 3 deletions Source/_gltf2usd/gltf2/Material.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def get_wrap_s(self):
def get_wrap_t(self):
return self._wrap_t

def write_to_directory(self, output_directory, channels, texture_prefix=""):
return self._image.write_to_directory(output_directory, channels, texture_prefix, self._tt_offset, self._tt_scale, self._tt_rotation)
def write_to_directory(self, output_directory, channels, texture_prefix="", scale_factor=None):
return self._image.write_to_directory(output_directory, channels, texture_prefix, self._tt_offset, self._tt_scale, self._tt_rotation, scale_factor)

def get_texcoord_index(self):
return self._texcoord_index
Expand Down Expand Up @@ -72,7 +72,7 @@ def __init__(self, occlusion_texture_entry, gltf_loader):
def strength(self):
return self._strength

class PbrMetallicRoughness:
class PbrMetallicRoughness(object):
def __init__(self, pbr_metallic_roughness_entry, gltf_loader):
self._name = pbr_metallic_roughness_entry['name'] if ('name' in pbr_metallic_roughness_entry) else 'pbr_mat_roughness_texture'
self._base_color_factor = pbr_metallic_roughness_entry['baseColorFactor'] if ('baseColorFactor' in pbr_metallic_roughness_entry) else [1.0,1.0,1.0, 1.0]
Expand Down
8 changes: 4 additions & 4 deletions Source/_gltf2usd/gltf2/Mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PrimitiveModeType(Enum):
TRIANGLE_STRIP = 5
TRIANGLE_FAN = 6

class PrimitiveAttribute:
class PrimitiveAttribute(object):
def __init__(self, attribute_name, attribute_data, accessor_type, min_value=None, max_value=None):
self._attribute_type = attribute_name
self._attribute_data = attribute_data
Expand All @@ -35,7 +35,7 @@ def get_data(self):
return self._attribute_data


class PrimitiveTarget:
class PrimitiveTarget(object):
def __init__(self, target_entry, target_index, gltf_loader):
self._name = None
self._attributes = {}
Expand All @@ -53,7 +53,7 @@ def get_name(self):
return self._name


class Primitive:
class Primitive(object):
def __init__(self, primitive_entry, i, gltf_mesh, gltf_loader):
self._name = primitive_entry['name'] if ('name' in primitive_entry) else 'primitive_{}'.format(i)
self._attributes = {}
Expand Down Expand Up @@ -111,7 +111,7 @@ def get_name(self):



class Mesh:
class Mesh(object):
def __init__(self, mesh_entry, mesh_index, gltf_loader):
self._name = mesh_entry['name'] if 'name' in mesh_entry else 'mesh_{}'.format(mesh_index)
self._primitives = []
Expand Down
9 changes: 7 additions & 2 deletions Source/_gltf2usd/gltf2/Node.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unicodedata

class Node:
class Node(object):
"""Create a glTF node object
"""

Expand All @@ -24,6 +24,7 @@ def __init__(self, node_dict, node_index, gltf_loader):

self._children_indices = node_dict['children'] if ('children' in node_dict) else []
self._children = []
self._extras = node_dict['extras'] if 'extras' in node_dict else {}

@property
def name(self):
Expand Down Expand Up @@ -63,4 +64,8 @@ def get_skin(self):

@property
def index(self):
return self._node_index
return self._node_index

@property
def extras(self):
return self._extras
2 changes: 1 addition & 1 deletion Source/_gltf2usd/gltf2/Scene.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Scene:
class Scene(object):
def __init__(self, scene_entry, scene_index, nodes):
self._nodes = []
if 'nodes' in scene_entry:
Expand Down
2 changes: 1 addition & 1 deletion Source/_gltf2usd/gltf2/Skin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sets import Set
class Skin:
class Skin(object):
"""Represents a glTF Skin
"""

Expand Down
16 changes: 13 additions & 3 deletions Source/_gltf2usd/gltf2loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import gltf2usdUtils

from gltf2 import Skin, Node, Animation, Scene, Mesh, Material, GLTFImage

from gltf2 import Skin, Node, Animation, Scene, Mesh, Material, GLTFImage, Asset


class AccessorType(Enum):
Expand Down Expand Up @@ -88,7 +87,7 @@ def accessor_component_type_bytesize(x):



class GLTF2Loader:
class GLTF2Loader(object):
"""A very simple glTF loader. It is essentially a utility to load data from accessors
"""

Expand Down Expand Up @@ -120,6 +119,7 @@ def __init__(self, gltf_file, optimize_textures=False, generate_texture_transfor
def _initialize(self):
"""Initializes the glTF loader
"""
self._initialize_asset()
self._initialize_images()
self._initialize_materials()
self._initialize_meshes()
Expand All @@ -129,6 +129,12 @@ def _initialize(self):

self._initialize_animations()

def _initialize_asset(self):
if 'asset' in self.json_data:
self._asset = Asset.Asset(self.json_data['asset'])
else:
self._asset = None

def _initialize_images(self):
self._images = []
if 'images' in self.json_data:
Expand Down Expand Up @@ -224,6 +230,10 @@ def _initialize_skins(self):
if node._skin_index != None:
node._skin = self.skins[node._skin_index]


def get_asset(self):
return self._asset

def get_nodes(self):
return self.nodes

Expand Down
2 changes: 1 addition & 1 deletion Source/_gltf2usd/gltf2usdUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pxr import Gf, UsdSkel

class GLTF2USDUtils:
class GLTF2USDUtils(object):
@staticmethod
def convert_to_usd_friendly_node_name(name):
"""Format a glTF name to make it more USD friendly
Expand Down
2 changes: 1 addition & 1 deletion Source/_gltf2usd/gltfUsdMaterialHelper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class GLTFUSDMaterialHelper:
class GLTFUSDMaterialHelper(object):
def __init__(self):
pass
Loading

0 comments on commit c0301fc

Please sign in to comment.