Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 91 additions & 5 deletions editor/js/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,104 @@ function Loader( editor ) {

filesMap = filesMap || LoaderUtils.createFilesMap( files );

const normalizeLookupPath = function ( path ) {

let normalized = String( path || '' ).replace( /\\/g, '/' );
const queryIndex = normalized.indexOf( '?' );
if ( queryIndex !== - 1 ) normalized = normalized.slice( 0, queryIndex );
const hashIndex = normalized.indexOf( '#' );
if ( hashIndex !== - 1 ) normalized = normalized.slice( 0, hashIndex );

while ( normalized.startsWith( './' ) ) normalized = normalized.slice( 2 );
while ( normalized.startsWith( '../' ) ) normalized = normalized.slice( 3 );
while ( normalized.startsWith( '/' ) ) normalized = normalized.slice( 1 );

return normalized;

};

const createFileFinder = function ( map ) {

const suffixMap = {};
const warnedAmbiguous = new Set();

const addCandidate = function ( suffix, candidate ) {

if ( ! suffixMap[ suffix ] ) suffixMap[ suffix ] = [];
suffixMap[ suffix ].push( candidate );

};

for ( const rawKey in map ) {

const key = normalizeLookupPath( rawKey );
const file = map[ rawKey ];
if ( key === '' || ! file ) continue;

const parts = key.split( '/' );

for ( let i = 0; i < parts.length; i ++ ) {

const suffix = parts.slice( i ).join( '/' );
if ( suffix !== '' ) addCandidate( suffix, { key, file } );

}

}

for ( const suffix in suffixMap ) {

suffixMap[ suffix ].sort( function ( a, b ) {

if ( a.key.length !== b.key.length ) return a.key.length - b.key.length;
if ( a.key < b.key ) return - 1;
if ( a.key > b.key ) return 1;
return 0;

} );

}

return function findFile( url ) {

const lookup = normalizeLookupPath( url );
if ( lookup === '' ) return null;

const candidates = suffixMap[ lookup ];
if ( ! candidates || candidates.length === 0 ) return null;
if ( candidates.length === 1 ) return candidates[ 0 ];

for ( let i = 0; i < candidates.length; i ++ ) {

if ( candidates[ i ].key === lookup ) return candidates[ i ];

}

if ( ! warnedAmbiguous.has( lookup ) ) {

console.warn( 'Loader: Ambiguous file reference "' + lookup + '". Using "' + candidates[ 0 ].key + '".' );
warnedAmbiguous.add( lookup );

}

return candidates[ 0 ];

};

};

const findFile = createFileFinder( filesMap );

const manager = new THREE.LoadingManager();
manager.setURLModifier( function ( url ) {

url = url.replace( /^(\.?\/)/, '' ); // remove './'

const file = filesMap[ url ];
const resolved = findFile( url );

if ( file ) {
if ( resolved ) {

console.log( 'Loading', url );

return URL.createObjectURL( file );
return URL.createObjectURL( resolved.file );

}

Expand Down
1 change: 1 addition & 0 deletions examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
"webgpu_centroid_sampling",
"webgpu_clearcoat",
"webgpu_clipping",
"webgpu_compile_async",
"webgpu_compute_audio",
"webgpu_compute_birds",
"webgpu_compute_cloth",
Expand Down
26 changes: 26 additions & 0 deletions examples/jsm/loaders/usd/USDCParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,19 @@ class USDCParser {

// Seek to payload offset and read value
const offset = valueRep.payload;
if ( offset === 0 && isArray ) {

// Spec 16.3.9.3: Array payload 0 is an explicit empty-array sentinel.
return [];

}

if ( offset < 0 || offset >= this.buffer.byteLength ) {

throw new RangeError( 'USDCParser: Invalid payload offset ' + offset + ' for type ' + type + '.' );

}

const savedOffset = this.reader.tell();
this.reader.seek( offset );

Expand Down Expand Up @@ -1569,6 +1582,19 @@ class USDCParser {

}

if ( ! Number.isSafeInteger( size ) || size < 0 ) {

throw new RangeError( 'USDCParser: Invalid array size ' + size + ' for type ' + type + '.' );

}

if ( size > 0x7FFFFFFF ) {

// Crate stores counts as uint64, but JS typed arrays cannot represent all such sizes.
throw new RangeError( 'USDCParser: Array size ' + size + ' exceeds implementation limits.' );

}

if ( size === 0 ) return [];

// Handle compressed arrays
Expand Down
9 changes: 5 additions & 4 deletions examples/jsm/loaders/usd/USDComposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,12 +653,13 @@ class USDComposer {
if ( obj ) {

parent.add( obj );
this._buildHierarchy( obj, path );

}

} else if ( typeName === 'Material' || typeName === 'Shader' ) {
} else if ( typeName === 'Material' || typeName === 'Shader' || typeName === 'GeomSubset' ) {

// Skip materials/shaders, they're referenced by meshes
// Skip materials/shaders/subsets, they're referenced by meshes

} else {

Expand Down Expand Up @@ -1112,13 +1113,13 @@ class USDComposer {
}

const displayOpacity = attrs[ 'primvars:displayOpacity' ];
if ( displayOpacity && displayOpacity.length >= 1 ) {
if ( displayOpacity && displayOpacity.length === 1 && geomSubsets.length === 0 ) {

const opacity = displayOpacity[ 0 ];

const applyDisplayOpacity = ( mat ) => {

if ( opacity < 1 ) {
if ( opacity < 1 && mat.opacity === 1 && mat.transparent === false ) {

mat.opacity = opacity;
mat.transparent = true;
Expand Down
Binary file added examples/screenshots/webgpu_compile_async.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading