Skip to content

Commit

Permalink
fixed Ior > IOR, test switching to node names to avoid duplication pr…
Browse files Browse the repository at this point in the history
…oblems (but incomplete yet, needs full paths)
  • Loading branch information
hybridherbst committed May 30, 2022
1 parent 8c232c3 commit 7e0d1de
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions examples/jsm/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2116,15 +2116,15 @@ PropertyBinding.findNode = ( node, path ) => {
if ( path.startsWith( '.materials.' ) ) {

if ( animationPointerDebug ) console.log( 'FIND', path );

const remainingPath = path.substring( '.materials.'.length ).substring( path.indexOf( '.' ) );
const nextIndex = remainingPath.indexOf( '.' );
const uuid = nextIndex < 0 ? remainingPath : remainingPath.substring( 0, nextIndex );
if ( animationPointerDebug ) console.log( remainingPath, uuid );
let res = null;
node.traverse( x => {

if ( res !== null || x.type !== 'Mesh' ) return;
if ( x[ 'material' ]?.uuid === uuid ) {
if ( x[ 'material' ]?.uuid === uuid || x[ 'material' ]?.name === uuid ) {

res = x[ 'material' ];
if ( animationPointerDebug ) console.log( res, remainingPath );
Expand All @@ -2135,13 +2135,15 @@ PropertyBinding.findNode = ( node, path ) => {
else if ( remainingPath.endsWith( '.emissiveMap' ) )
res = res[ 'emissiveMap' ];

// TODO add other texture slots. Better would be a list of texture slots
// TODO other texture slots only make sense if three.js actually supports them
// (currently only .map can have repeat/offset)

}

}

} );

return res;

} else if ( path.startsWith( '.nodes.' ) || path.startsWith( '.lights.' ) || path.startsWith( '.cameras.' ) ) {
Expand All @@ -2154,17 +2156,26 @@ PropertyBinding.findNode = ( node, path ) => {
const isUUID = val.length == 36;
if ( isUUID ) {

// access by UUID
currentTarget = node.getObjectByProperty( 'uuid', val );

} else if ( currentTarget && currentTarget[ val ] ) {

// access by index
const index = Number.parseInt( val );
let key = val;
if ( index >= 0 ) key = index;
currentTarget = currentTarget[ key ];
if ( animationPointerDebug )
console.log( currentTarget );

} else {

// access by node name
const foundNode = node.getObjectByName( val );
if ( foundNode )
currentTarget = foundNode;

}

}
Expand Down Expand Up @@ -3925,7 +3936,6 @@ class GLTFParser {
const pathStart = path.substring( 0, pathIndex );
targetProperty = path.substring( pathIndex );

// TODO implement all properties and/or find a better way to have a good mapping here
switch ( targetProperty ) {

// Core Spec PBR Properties
Expand All @@ -3952,6 +3962,8 @@ class GLTFParser {
case 'baseColorTexture/extensions/KHR_texture_transform/offset':
targetProperty = 'map/offset';
break;

// UV transforms for anything but map doesn't seem to currently be supported in three.js
case 'emissiveTexture/extensions/KHR_texture_transform/scale':
targetProperty = 'emissiveMap/repeat';
break;
Expand All @@ -3963,7 +3975,7 @@ class GLTFParser {
case 'extensions/KHR_materials_emissive_strength/emissiveStrength':
targetProperty = 'emissiveIntensity';
break;

// KHR_materials_transmission
case 'extensions/KHR_materials_transmission/transmissionFactor':
targetProperty = 'transmission';
Expand All @@ -3973,7 +3985,7 @@ class GLTFParser {
case 'extensions/KHR_materials_ior/ior':
targetProperty = 'ior';
break;

// KHR_materials_volume
case 'extensions/KHR_materials_volume/thicknessFactor':
targetProperty = 'thickness';
Expand All @@ -3990,14 +4002,15 @@ class GLTFParser {
targetProperty = 'iridescence';
break;
case 'extensions/KHR_materials_iridescence/iridescenceIor':
targetProperty = 'iridescenceIor';
targetProperty = 'iridescenceIOR';
break;
case 'extensions/KHR_materials_iridescence/iridescenceThicknessMinimum':
targetProperty = 'iridescenceThicknessRange[0]';
break;
case 'extensions/KHR_materials_iridescence/iridescenceThicknessMaximum':
targetProperty = 'iridescenceThicknessRange[1]';
break;

}

path = pathStart + targetProperty;
Expand Down Expand Up @@ -4193,7 +4206,7 @@ class GLTFParser {
animationPointerPropertyPath = animationPointerPropertyPath.replaceAll( '/', '.' );
// replace node/material/camera/light ID by UUID
const parts = animationPointerPropertyPath.split( '.' );
parts[ 2 ] = node.uuid;
parts[ 2 ] = node.name; // node.uuid;
animationPointerPropertyPath = parts.join( '.' );
if ( animationPointerDebug )
console.log( node, inputAccessor, outputAccessor, target, animationPointerPropertyPath );
Expand Down

0 comments on commit 7e0d1de

Please sign in to comment.