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

Docs: More JSDoc. #30646

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions examples/jsm/effects/AnaglyphEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ import {
} from 'three';
import { FullScreenQuad } from '../postprocessing/Pass.js';

/**
* A class that creates an anaglyph effect.
*
* Note that this class can only be used with {@link WebGLRenderer}.
* When using {@link WebGPURenderer}, use {@link AnaglyphPassNode}.
*/
class AnaglyphEffect {

/**
* Constructs a new anaglyph effect.
*
* @param {WebGLRenderer} renderer - The renderer.
* @param {number} width - The width of the effect in physical pixels.
* @param {number} height - The height of the effect in physical pixels.
*/
constructor( renderer, width = 512, height = 512 ) {

// Dubois matrices from https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.7.6968&rep=rep1&type=pdf#page=4
Expand Down Expand Up @@ -94,6 +107,12 @@ class AnaglyphEffect {

const _quad = new FullScreenQuad( _material );

/**
* Resizes the effect.
*
* @param {number} width - The width of the effect in logical pixels.
* @param {number} height - The height of the effect in logical pixels.
*/
this.setSize = function ( width, height ) {

renderer.setSize( width, height );
Expand All @@ -105,6 +124,13 @@ class AnaglyphEffect {

};

/**
* When using this effect, this method should be called instead of the
* default {@link WebGLRenderer#render}.
*
* @param {Object3D} scene - The scene to render.
* @param {Camera} camera - The camera.
*/
this.render = function ( scene, camera ) {

const currentRenderTarget = renderer.getRenderTarget();
Expand All @@ -130,6 +156,10 @@ class AnaglyphEffect {

};

/**
* Frees internal resources. This method should be called
* when the effect is no longer required.
*/
this.dispose = function () {

_renderTargetL.dispose();
Expand Down
55 changes: 46 additions & 9 deletions examples/jsm/effects/AsciiEffect.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
/**
* Ascii generation is based on https://github.com/hassadee/jsascii/blob/master/jsascii.js
* A class that creates a ASCII effect.
*
* 16 April 2012 - @blurspline
* The ASCII generation is based on [jsascii]{@link https://github.com/hassadee/jsascii/blob/master/jsascii.js}.
*/

class AsciiEffect {

/**
* Constructs a new ASCII effect.
*
* @param {WebGLRenderer} renderer - The renderer.
* @param {string} [charSet=' .:-=+*#%@'] - The char set.
* @param {AsciiEffect~Options} [options] - The configuration parameter.
*/
constructor( renderer, charSet = ' .:-=+*#%@', options = {} ) {

// ' .,:;=|iI+hHOE#`$';
Expand All @@ -14,12 +20,12 @@ class AsciiEffect {

// Some ASCII settings

const fResolution = options[ 'resolution' ] || 0.15; // Higher for more details
const fResolution = options[ 'resolution' ] || 0.15;
const iScale = options[ 'scale' ] || 1;
const bColor = options[ 'color' ] || false; // nice but slows down rendering!
const bAlpha = options[ 'alpha' ] || false; // Transparency
const bBlock = options[ 'block' ] || false; // blocked characters. like good O dos
const bInvert = options[ 'invert' ] || false; // black is white, white is black
const bColor = options[ 'color' ] || false;
const bAlpha = options[ 'alpha' ] || false;
const bBlock = options[ 'block' ] || false;
const bInvert = options[ 'invert' ] || false;
const strResolution = options[ 'strResolution' ] || 'low';

let width, height;
Expand All @@ -33,6 +39,12 @@ class AsciiEffect {
let iWidth, iHeight;
let oImg;

/**
* Resizes the effect.
*
* @param {number} w - The width of the effect in logical pixels.
* @param {number} h - The height of the effect in logical pixels.
*/
this.setSize = function ( w, h ) {

width = w;
Expand All @@ -44,14 +56,26 @@ class AsciiEffect {

};


/**
* When using this effect, this method should be called instead of the
* default {@link WebGLRenderer#render}.
*
* @param {Object3D} scene - The scene to render.
* @param {Camera} camera - The camera.
*/
this.render = function ( scene, camera ) {

renderer.render( scene, camera );
asciifyImage( oAscii );

};

/**
* The DOM element of the effect. This element must be used instead of the
* default {@link WebGLRenderer#domElement}.
*
* @type {HTMLDivElement}
*/
this.domElement = domElement;


Expand Down Expand Up @@ -260,4 +284,17 @@ class AsciiEffect {

}

/**
* This type represents configuration settings of `AsciiEffect`.
*
* @typedef {Object} AsciiEffect~Options
* @property {number} [resolution=0.15] - A higher value leads to more details.
* @property {number} [scale=1] - The scale of the effect.
* @property {boolean} [color=false] - Whether colors should be enabled or not. Better quality but slows down rendering.
* @property {boolean} [alpha=false] - Whether transparency should be enabled or not.
* @property {boolean} [block=false] - Whether blocked characters should be enabled or not.
* @property {boolean} [invert=false] - Whether colors should be inverted or not.
* @property {('low'|'medium'|'high')} [strResolution='low'] - The string resolution.
**/

export { AsciiEffect };
170 changes: 59 additions & 111 deletions examples/jsm/effects/OutlineEffect.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,29 @@ import {
} from 'three';

/**
* Reference: https://en.wikipedia.org/wiki/Cel_shading
* An outline effect for toon shaders.
*
* API
*
* 1. Traditional
* Note that this class can only be used with {@link WebGLRenderer}.
* When using {@link WebGPURenderer}, use {@link ToonOutlinePassNode}.
*
* ```js
* const effect = new OutlineEffect( renderer );
*
* function render() {
*
* effect.render( scene, camera );
*
* }
*
* 2. VR compatible
*
* const effect = new OutlineEffect( renderer );
* let renderingOutline = false;
*
* scene.onAfterRender = function () {
*
* if ( renderingOutline ) return;
*
* renderingOutline = true;
*
* effect.renderOutline( scene, camera );
*
* renderingOutline = false;
*
* };
*
* function render() {
*
* renderer.render( scene, camera );
*
* }
*
* // How to set default outline parameters
* new OutlineEffect( renderer, {
* defaultThickness: 0.01,
* defaultColor: [ 0, 0, 0 ],
* defaultAlpha: 0.8,
* defaultKeepAlive: true // keeps outline material in cache even if material is removed from scene
* } );
*
* // How to set outline parameters for each material
* material.userData.outlineParameters = {
* thickness: 0.01,
* color: [ 0, 0, 0 ],
* alpha: 0.8,
* visible: true,
* keepAlive: true
* };
* ```
*/

class OutlineEffect {

/**
* Constructs a new outline effect.
*
* @param {WebGLRenderer} renderer - The renderer.
* @param {OutlineEffect~Options} [parameters] - The configuration parameter.
*/
constructor( renderer, parameters = {} ) {

this.enabled = true;
Expand Down Expand Up @@ -413,6 +379,13 @@ class OutlineEffect {

}

/**
* When using this effect, this method should be called instead of the
* default {@link WebGLRenderer#render}.
*
* @param {Object3D} scene - The scene to render.
* @param {Camera} camera - The camera.
*/
this.render = function ( scene, camera ) {

if ( this.enabled === false ) {
Expand All @@ -433,6 +406,30 @@ class OutlineEffect {

};

/**
* This method can be used to render outlines in VR.
*
* ```js
* const effect = new OutlineEffect( renderer );
* let renderingOutline = false;
*
* scene.onAfterRender = function () {
*
* if ( renderingOutline ) return;
*
* renderingOutline = true;
* effect.renderOutline( scene, camera );
* renderingOutline = false;
* };
*
* function render() {
* renderer.render( scene, camera );
* }
* ```
*
* @param {Object3D} scene - The scene to render.
* @param {Camera} camera - The camera.
*/
this.renderOutline = function ( scene, camera ) {

const currentAutoClear = renderer.autoClear;
Expand Down Expand Up @@ -460,80 +457,31 @@ class OutlineEffect {

};

/*
* See #9918
*
* The following property copies and wrapper methods enable
* OutlineEffect to be called from other *Effect, like
*
* effect = new StereoEffect( new OutlineEffect( renderer ) );
*
* function render () {
/**
* Resizes the effect.
*
* effect.render( scene, camera );
*
* }
* @param {number} width - The width of the effect in logical pixels.
* @param {number} height - The height of the effect in logical pixels.
*/
this.autoClear = renderer.autoClear;
this.domElement = renderer.domElement;
this.shadowMap = renderer.shadowMap;

this.clear = function ( color, depth, stencil ) {

renderer.clear( color, depth, stencil );
this.setSize = function ( width, height ) {

};

this.getPixelRatio = function () {

return renderer.getPixelRatio();

};

this.setPixelRatio = function ( value ) {

renderer.setPixelRatio( value );

};

this.getSize = function ( target ) {

return renderer.getSize( target );

};

this.setSize = function ( width, height, updateStyle ) {

renderer.setSize( width, height, updateStyle );

};

this.setViewport = function ( x, y, width, height ) {

renderer.setViewport( x, y, width, height );

};

this.setScissor = function ( x, y, width, height ) {

renderer.setScissor( x, y, width, height );

};

this.setScissorTest = function ( boolean ) {

renderer.setScissorTest( boolean );

};

this.setRenderTarget = function ( renderTarget ) {

renderer.setRenderTarget( renderTarget );
renderer.setSize( width, height );

};

}

}

/**
* This type represents configuration settings of `OutlineEffect`.
*
* @typedef {Object} OutlineEffect~Options
* @property {number} [defaultThickness=0.003] - The outline thickness.
* @property {Array<number>} [defaultColor=[0,0,0]] - The outline color.
* @property {number} [defaultAlpha=1] - The outline alpha value.
* @property {boolean} [defaultKeepAlive=false] - Whether to keep alive cached internal materials or not.
**/


export { OutlineEffect };
Loading
Loading