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

LineMaterial: Clean up #26720

Merged
merged 3 commits into from
Sep 14, 2023
Merged

LineMaterial: Clean up #26720

merged 3 commits into from
Sep 14, 2023

Conversation

LeviPesin
Copy link
Contributor

Related issue: #26704 (comment)

Description

Replace Object.defineProperties() with class fields getters/setters.

@mrdoob mrdoob added this to the r157 milestone Sep 14, 2023
@mrdoob mrdoob merged commit e6304f3 into mrdoob:dev Sep 14, 2023
18 checks passed
@LeviPesin LeviPesin deleted the patch-8 branch September 14, 2023 09:19

},
if ( ! this.uniforms.linewidth ) return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain the reason for this line, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure -- the problem is that in the ShaderMaterial contructor linewidth property is set, so the setter is called, so if this.uniforms.linewidth is undefined (as it is in that constructor), assign to a property of undefined fails. A cleaner solution would be to use optional chaining.

Copy link
Collaborator

Choose a reason for hiding this comment

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

With all due respect, I feel uneasy about the four lines I highlighted. If I had a better solution, I would suggest it.

Maybe comments would help.

@Mugen87 has good judgement about this sort of thing. I will defer to whatever he thinks.

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 think the best solution is to use optional chaining or at least do something like if ( this.uniforms && this.uniforms.linewidth ) this.uniforms.linewidth.value = ....

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since there are many contributors to three.js, it is important that we write code that can be maintained by others. IMHO, the lines I highlighted here are too hacky. It appears you agree there are better approaches.

I would be satisfied reverting to the prior implementation.


this.uniforms.resolution.value.copy( value );
if ( ! this.uniforms ) return;
this.uniforms.opacity.value = value;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain the reason for this line, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above, but opacity is set in Material.


if ( value === true ) {
if ( ! this.defines ) return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain this line, too, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above.


this.defines.USE_ALPHA_TO_COVERAGE = '';
this.extensions.derivatives = true;
if ( ( value === true ) !== this.alphaToCoverage ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this line, too...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line is almost the same as was before, I just simplified it a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants