Skip to content

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Feb 18, 2025

Related issue: #30534

Description

Adding JSDoc for Material and Texture.

Fixing more found CSS issues.

Copy link

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.51
78.38
336.51
78.38
+0 B
+0 B
WebGPU 519.2
144.16
519.2
144.16
+0 B
+0 B
WebGPU Nodes 518.67
144.05
518.67
144.05
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 465.51
112.23
465.51
112.23
+0 B
+0 B
WebGPU 591.03
160.12
591.03
160.12
+0 B
+0 B
WebGPU Nodes 546.34
149.59
546.34
149.59
+0 B
+0 B

@Mugen87 Mugen87 added this to the r174 milestone Feb 18, 2025
@Mugen87 Mugen87 merged commit 860644b into mrdoob:dev Feb 18, 2025
12 checks passed
* {@link Material#blendSrc}, {@link Material#blendDst} or {@link Material#blendEquation}
* should have any effect.
*
* @type {(NoBlending|NormalBlending|AdditiveBlending|SubtractiveBlending|MultiplyBlending|CustomBlending)}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@s-rigaud Do you have an idea how we can rewrite this so we have a single type definition an refer to it just once. Something like:

@type {BlendingTypes}

I've struggled with such enum-like definitions for quite a while with JSDoc. I know there is the () syntax that you can use the restrict the usage on the values inside the parenthesis. But in our case we need to define NoBlending first and then a collection of all blending types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think something like NoBlending should be documented as a global.

But then there is still the question if we could group some globals into a type.

Copy link
Contributor

@s-rigaud s-rigaud Feb 18, 2025

Choose a reason for hiding this comment

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

I'm aware of limitations of Jsdoc regarding enums and tuples in general. Most of the time I end up with some workaround implying some TS.

Base on this answer and the struggle of just using enum I think we will have to also find a workaround for those values.

The best approach I got is to define a type and to document each possible values as properties (the semantic is not really suited as the @property keyword should be used for the key of an object and not a fake enum but it is the best output documentation I manage to generate for now). I end up with a "coherent" documentation from a user point of view:

/**
 * @typedef {number} BlendingType
 * @property {number} NoBlending 0
 * @property {number} NormalBlending 1
 **/

image
image

Copy link
Collaborator Author

@Mugen87 Mugen87 Feb 18, 2025

Choose a reason for hiding this comment

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

Would that also work in context of auto-completion in editors? I could expect a tool could complain when doing the following...

material.blending = NoBlending;

...since NoBlending is not of type BlendingType. It is a property of the type and that seems to be a mismatch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well they won't complain if they are based on the JsDoc because all the types in @type {(NoBlending|NormalBlending|AdditiveBlending|SubtractiveBlending|MultiplyBlending|CustomBlending)} are already undfined and being evaluated to any. The only way to be more precise is to use the number type but then you lose all the accepted values. We could put all the valid integer values but it's not really maintainable. I am not aware of a nice solution to handle this case :/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because all the types in @type {(NoBlending|NormalBlending|AdditiveBlending|SubtractiveBlending|MultiplyBlending|CustomBlending)} are already undfined and being evaluated to any.

It seems when actually documenting the globals, this issue resolves. E.g. when documenting ClampToEdgeWrapping in src/constants.js like so:

/**
 * The last pixel of the texture stretches to the edge of the mesh.
 *
 * @constant
 * @type {number}
 */
export const ClampToEdgeWrapping = 1001;

The ClampToEdgeWrapping references in the docs are now links and refer to the correct global.

From Texture.html docs:
image

From global.html:
image

Let's start with this approach and see how it goes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice ! Do you think it worth documenting the value as well ? Currently nothing is shown about it 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The value of such constants does usually not matter.

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.

2 participants