-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
TS: Added undefined
as .defines
member
#20356
Conversation
`.defines` is not declared at https://github.com/mrdoob/three.js/blob/dev/src/materials/Material.js, so it is optional.
@@ -139,7 +139,7 @@ export class Material extends EventDispatcher { | |||
* The pairs are defined in both vertex and fragment shaders. Default is undefined. | |||
* @default undefined | |||
*/ | |||
defines: { [key: string]: any }; | |||
defines: undefined | { [key: string]: any }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be safe since all materials which actually set defines like MeshStandardMaterial
overwrite the type declaration in their own TS file with:
defines: { [key: string]: any };
So property access in context of those materials should not break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better modeling the type exactly for that .js unless the item is internal.
for this case Material is exported (not internal), one can class MyMaterial extends Material {}
in TS.
this.defines['x'] = 0; // passed typecheck, fail at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about defining defines
in Material.js
like so:
this.defines = {};
In this way, it would be never undefined
. An we could delete all type declarations of defines
in derived materials (e.g. ShaderMaterial
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about defining
defines
inMaterial.js
like so:this.defines = {};In this way, it would be never
undefined
. An we could delete all type declarations ofdefines
in derived materials (e.g.ShaderMaterial
).
This will make those derived materials (point, sprite, shadow..) bloated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean with "bloated"? Do you mind explaining in more detail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean with "bloated"? Do you mind explaining in more detail?
After adding .defines = {}
to Material.js; it is fine from shadermaterial POV as it needs this property.
But for those derived materials like pointsmaterial, spritematerial, shadowmaterial etc,
they own a .defines
(an empty js object) which is never be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this also true for other common material properties. E.g. vertexColors
or flatShading
is not use by all materials.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this also true for other common material properties. E.g.
vertexColors
orflatShading
is not use by all materials.
I've no idea why those props are existing there.
Thanks! |
.defines
is not declared at https://github.com/mrdoob/three.js/blob/dev/src/materials/Material.js, so it is optional.