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

refactor(mtlreader): add a boolean to not automatically request and l… #2406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion Sources/IO/Misc/MTLReader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function vtkMTLReader(publicAPI, model) {
model.materials[model.currentMaterial] = {};
}
model.materials[model.currentMaterial][tokens[0]] = tokens.slice(1);
if (tokens[0] === 'map_Kd') {
if (model.autoLoadMaterials && tokens[0] === 'map_Kd') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setImageSrc() seems to be implemented to overwrite the image. It's similar to what you need (you already have the image in cache and you do not want to load it again).

Maybe we could combine both usage:
e.g.

image.src = model.imageSourceHelper(tokens[1]);
...
model.imageSourceHelper = (source) => [model.baseURL, source].join('/');
macro.setGet(['imageSourceBuilder']);
...
mtlReader.setImageSourceBuilder((source) => {return ''});

@jourdain what is the purpose of setImageSrc() ? What's the use case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't necessarily have it in cache.
Sometimes "map_Kd" is mentioned, but we don't want to use it because the image source file does not exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jourdain can you please tell us how you use setImageSrc()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the mtl file will have a name/path and you want to link it to an HTML image so you call
setImageSrc(mtl_name, image_url)

You can see it being used here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks and all my apologies for not finding it myself, I blame github online search (couldn't find it), and my VSCode search that is configured to search only the "Sources" folder. My bad

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries and sorry for not providing that info sooner, but still pretty busy on trame v2.

const image = new Image();
image.onload = () => setTimeout(imageReady, 0);
image.src = [model.baseURL, tokens[1]].join('/');
Expand Down Expand Up @@ -165,6 +165,7 @@ const DEFAULT_VALUES = {
requestCount: 0,
materials: {},
interpolateTextures: true,
autoLoadMaterials: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to loadMaterialImages ?

// baseURL: null,
// dataAccessHelper: null,
// url: null,
Expand All @@ -182,6 +183,7 @@ export function extend(publicAPI, model, initialValues = {}) {
'dataAccessHelper',
'interpolateTextures',
'splitGroup',
'autoLoadMaterials',
]);
macro.event(publicAPI, model, 'busy');

Expand Down