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

TS: Added undefined as .defines member #20356

Merged
merged 1 commit into from
Sep 24, 2020
Merged
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
2 changes: 1 addition & 1 deletion src/materials/Material.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Copy link
Collaborator

@Mugen87 Mugen87 Sep 16, 2020

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

@Mugen87 Mugen87 Sep 18, 2020

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).

Copy link
Contributor Author

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).

This will make those derived materials (point, sprite, shadow..) bloated.

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

@Mugen87 Mugen87 Sep 18, 2020

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.

Copy link
Contributor Author

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.

I've no idea why those props are existing there.


/**
* Which depth function to use. Default is {@link LessEqualDepth}. See the depth mode constants for all possible values.
Expand Down