Skip to content

Commit 9a711cc

Browse files
committed
USDComposer: Fixed variant composition.
1 parent 27f2f4e commit 9a711cc

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

examples/jsm/loaders/usd/USDAParser.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,34 @@ class USDAParser {
217217

218218
}
219219

220+
if ( key === 'variants' ) {
221+
222+
const variantSelection = {};
223+
const variants = data[ key ];
224+
225+
for ( const vKey in variants ) {
226+
227+
const match = vKey.match( /^string\s+(\w+)$/ );
228+
if ( match ) {
229+
230+
const variantSetName = match[ 1 ];
231+
const variantValue = variants[ vKey ].replace( /"/g, '' );
232+
variantSelection[ variantSetName ] = variantValue;
233+
234+
}
235+
236+
}
237+
238+
if ( Object.keys( variantSelection ).length > 0 ) {
239+
240+
primFields.variantSelection = variantSelection;
241+
242+
}
243+
244+
continue;
245+
246+
}
247+
220248
if ( key.startsWith( 'rel ' ) ) {
221249

222250
const relName = key.slice( 4 );

examples/jsm/loaders/usd/USDComposer.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,34 @@ class USDComposer {
766766
_getAttributes( path ) {
767767

768768
const attrs = {};
769+
770+
this._collectAttributesFromPath( path, attrs );
771+
772+
// Collect overrides from sibling variants
773+
const variantMatch = path.match( /^(.+?)\/\{(\w+)=(\w+)\}\/(.+)$/ );
774+
if ( variantMatch ) {
775+
776+
const basePath = variantMatch[ 1 ];
777+
const relativePath = variantMatch[ 4 ];
778+
const variantPaths = this._getVariantPaths( basePath );
779+
780+
for ( const vp of variantPaths ) {
781+
782+
if ( path.startsWith( vp ) ) continue;
783+
784+
const overridePath = vp + '/' + relativePath;
785+
this._collectAttributesFromPath( overridePath, attrs );
786+
787+
}
788+
789+
}
790+
791+
return attrs;
792+
793+
}
794+
795+
_collectAttributesFromPath( path, attrs ) {
796+
769797
const prefix = path + '.';
770798

771799
for ( const attrPath in this.specsByPath ) {
@@ -781,7 +809,6 @@ class USDComposer {
781809

782810
}
783811

784-
// Include elementSize for skinning attributes
785812
if ( attrSpec.fields?.elementSize !== undefined ) {
786813

787814
attrs[ attrName + ':elementSize' ] = attrSpec.fields.elementSize;
@@ -796,8 +823,6 @@ class USDComposer {
796823

797824
}
798825

799-
return attrs;
800-
801826
}
802827

803828
/**
@@ -830,7 +855,6 @@ class USDComposer {
830855

831856
}
832857

833-
// Apply displayColor if no texture/color was set
834858
const displayColor = attrs[ 'primvars:displayColor' ];
835859
if ( displayColor && displayColor.length >= 3 ) {
836860

@@ -856,7 +880,6 @@ class USDComposer {
856880

857881
}
858882

859-
// Apply displayOpacity for transparency
860883
const displayOpacity = attrs[ 'primvars:displayOpacity' ];
861884
if ( displayOpacity && displayOpacity.length >= 1 ) {
862885

0 commit comments

Comments
 (0)