Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDrawLoader: fileMap should exist when parsing. #23097

Merged
merged 2 commits into from
Dec 28, 2021

Conversation

gero3
Copy link
Contributor

@gero3 gero3 commented Dec 27, 2021

Description
'fileMap' should exist when parsing the LDRAW model. This also removes a TODO from the editor.

@mrdoob mrdoob added this to the r137 milestone Dec 28, 2021
@mrdoob mrdoob merged commit fbd067f into mrdoob:dev Dec 28, 2021
@mrdoob
Copy link
Owner

mrdoob commented Dec 28, 2021

Thanks!

@mrdoob
Copy link
Owner

mrdoob commented Dec 28, 2021

Oh, maybe @yomboprime remembers why it was set to null by default?

@yomboprime
Copy link
Collaborator

Oh, maybe @yomboprime remembers why it was set to null by default?

This comment says it clearly:
// This object is a map from file names to paths. It agilizes the paths search. If it is not set then files will be searched by trial and error.

I'm afraid we've lost the ability to load directly from original parts repository files (instead of using the packed models). It is a pity I didn't make any app that used that functionality. Its use case is for example a Lego editor. Though I guess it is not a great problem overall.

@yomboprime
Copy link
Collaborator

yomboprime commented Dec 28, 2021

I would add that great part of the overall complexity of the loader is to handle the various subdirectories and filename variations the format has. That complexity could be removed and rely solely on packed models.

@yomboprime
Copy link
Collaborator

I would add that great part of the overall complexity of the loader is to handle the various subdirectories and filename variations the format has. That complexity could be removed and rely solely on packed models.

Well I've read the code again and it is not that much complexity.

@yomboprime
Copy link
Collaborator

yomboprime commented Dec 28, 2021

Oh, maybe @yomboprime remembers why it was set to null by default?

This comment says it clearly: // This object is a map from file names to paths. It agilizes the paths search. If it is not set then files will be searched by trial and error.

I'm afraid we've lost the ability to load directly from original parts repository files (instead of using the packed models). It is a pity I didn't make any app that used that functionality. Its use case is for example a Lego editor. Though I guess it is not a great problem overall.

Perhaps we should make this change, adding a check for fileMap (it is valid to have null fileMap):
if ( scope.fileMap && scope.fileMap[ fileName ] ) {

I think this would restore the functionality I was talking about (ability to load from the repository rather than packed models)

@gkjohnson
Copy link
Collaborator

gkjohnson commented Dec 28, 2021

Perhaps we should make this change, adding a check for fileMap (it is valid to have null fileMap):

Why is it valid to have a null fileMap? From looking at the code it doesn't seem to offer a difference in behavior?

I think this would restore the functionality I was talking about (ability to load from the repository rather than packed models)

For what it's worth the way I load models using the repository of parts is like so. I've uploaded the ldraw library to a personal repo specifically so I can test it. With this approach no file map is needed though it does try to load the same file multiple times until the right directory is found. I believe if you put all parts in the same folder it wouldn't have to check multiple directories:

// initialize library paths and materials
const loader = new LDrawLoader();
loader.setPartsLibraryPath( 'https://raw.githubusercontent.com/gkjohnson/ldraw-parts-library/master/complete/ldraw/' );
await loader.preloadMaterials( 'https://raw.githubusercontent.com/gkjohnson/ldraw-parts-library/master/colors/ldcfgalt.ldr' );

// load the model
loader.load( 'https://raw.githubusercontent.com/gkjohnson/ldraw-parts-library/master/complete/ldraw/10030-1%20-%20Imperial%20Star%20Destroyer%20-%20UCS.mpd' );

@yomboprime
Copy link
Collaborator

yomboprime commented Dec 28, 2021

Why is it valid to have a null fileMap? From looking at the code it doesn't seem to offer a difference in behavior?

An editor/part browser that loads parts dynamically (by user action) could not have a file map. But it could be generated prior to loading. So it is not a big problem but the use case is there.

I believe if you put all parts in the same file...

Do you mean directory here, or packed file? I guess the former.

Thanks for the clarification about loading from the repo, BTW.

@gkjohnson
Copy link
Collaborator

An editor/part browser that loads parts dynamically (by user action) could not have a file map. But it could be generated prior to loading. So it is not a big problem but the use case is there.

I think this use case is still supported even if the fileMap field is defaulted to {}.

Do you mean directory here, or packed file? I guess the former.

Oh yeah I meant type "folder" 😁 thanks for the catch.

@yomboprime
Copy link
Collaborator

I think this use case is still supported even if the fileMap field is defaulted to {}.

Oh, you're right.

@Mugen87 Mugen87 changed the title fileMap should exist when parsing LDrawLoader: fileMap should exist when parsing. Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants