Skip to content

Commit 033508e

Browse files
authored
API Reference improvements and fixes (#7499)
* API Reference improvements and fixes * Lint fix * More edits * Update audio listener overview * More updates * Tweak RenderComponent * Tweak ScriptComponent * Tweaks * Lint fix * Fix a TypeDoc warning * Fix tests on Windows * Fix more TypeDoc warnings * Rewrite application-related class descriptions * Whitspace * Tweak * Tweaks * Update Entity class description * Improve the ComponentSystemRegistry class description * Tweak * Fix a TypeDoc warning * Fix two more TypeDoc warnings
1 parent e989431 commit 033508e

File tree

29 files changed

+286
-202
lines changed

29 files changed

+286
-202
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"lint": "eslint scripts src test utils build.mjs eslint.config.mjs rollup.config.mjs",
125125
"publint": "publint --level error",
126126
"serve": "serve build -l 51000 --cors",
127-
"test": "mocha --ignore 'test/assets/scripts/**' --recursive --require test/fixtures.mjs --timeout 5000",
127+
"test": "mocha --ignore \"test/assets/scripts/*.js\" --recursive --require test/fixtures.mjs --timeout 5000",
128128
"test:coverage": "c8 npm test",
129129
"test:types": "tsc --pretty false build/playcanvas.d.ts"
130130
},

src/core/event-handler.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { EventHandle } from './event-handle.js';
44
* Callback used by {@link EventHandler} functions. Note the callback is limited to 8 arguments.
55
*
66
* @callback HandleEventCallback
7-
* @param {*} [arg1] - First argument that is passed from caller.
8-
* @param {*} [arg2] - Second argument that is passed from caller.
9-
* @param {*} [arg3] - Third argument that is passed from caller.
10-
* @param {*} [arg4] - Fourth argument that is passed from caller.
11-
* @param {*} [arg5] - Fifth argument that is passed from caller.
12-
* @param {*} [arg6] - Sixth argument that is passed from caller.
13-
* @param {*} [arg7] - Seventh argument that is passed from caller.
14-
* @param {*} [arg8] - Eighth argument that is passed from caller.
7+
* @param {any} [arg1] - First argument that is passed from caller.
8+
* @param {any} [arg2] - Second argument that is passed from caller.
9+
* @param {any} [arg3] - Third argument that is passed from caller.
10+
* @param {any} [arg4] - Fourth argument that is passed from caller.
11+
* @param {any} [arg5] - Fifth argument that is passed from caller.
12+
* @param {any} [arg6] - Sixth argument that is passed from caller.
13+
* @param {any} [arg7] - Seventh argument that is passed from caller.
14+
* @param {any} [arg8] - Eighth argument that is passed from caller.
1515
*/
1616

1717
/**
@@ -259,14 +259,14 @@ class EventHandler {
259259
* Fire an event, all additional arguments are passed on to the event listener.
260260
*
261261
* @param {string} name - Name of event to fire.
262-
* @param {*} [arg1] - First argument that is passed to the event handler.
263-
* @param {*} [arg2] - Second argument that is passed to the event handler.
264-
* @param {*} [arg3] - Third argument that is passed to the event handler.
265-
* @param {*} [arg4] - Fourth argument that is passed to the event handler.
266-
* @param {*} [arg5] - Fifth argument that is passed to the event handler.
267-
* @param {*} [arg6] - Sixth argument that is passed to the event handler.
268-
* @param {*} [arg7] - Seventh argument that is passed to the event handler.
269-
* @param {*} [arg8] - Eighth argument that is passed to the event handler.
262+
* @param {any} [arg1] - First argument that is passed to the event handler.
263+
* @param {any} [arg2] - Second argument that is passed to the event handler.
264+
* @param {any} [arg3] - Third argument that is passed to the event handler.
265+
* @param {any} [arg4] - Fourth argument that is passed to the event handler.
266+
* @param {any} [arg5] - Fifth argument that is passed to the event handler.
267+
* @param {any} [arg6] - Sixth argument that is passed to the event handler.
268+
* @param {any} [arg7] - Seventh argument that is passed to the event handler.
269+
* @param {any} [arg8] - Eighth argument that is passed to the event handler.
270270
* @returns {EventHandler} Self for chaining.
271271
* @example
272272
* obj.fire('test', 'This is the message');

src/extras/render-passes/camera-frame.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { CameraFrameOptions, RenderPassCameraFrame } from './render-pass-camera-
3535
* used together at a higher cost. Defaults to 1.
3636
* @property {boolean} sceneColorMap - Whether rendering generates a scene color map. Defaults to false.
3737
* @property {boolean} sceneDepthMap - Whether rendering generates a scene depth map. Defaults to false.
38-
* @property {number} toneMapping - The tone mapping. Defaults to {@link ToneMapping.LINEAR}. Can be:
38+
* @property {number} toneMapping - The tone mapping. Can be:
3939
*
4040
* - {@link TONEMAP_LINEAR}
4141
* - {@link TONEMAP_FILMIC}
@@ -44,6 +44,7 @@ import { CameraFrameOptions, RenderPassCameraFrame } from './render-pass-camera-
4444
* - {@link TONEMAP_ACES2}
4545
* - {@link TONEMAP_NEUTRAL}
4646
*
47+
* Defaults to {@link TONEMAP_LINEAR}.
4748
* @property {number} sharpness - The sharpening intensity, 0-1 range. This can be used to increase
4849
* the sharpness of the rendered image. Often used to counteract the blurriness of the TAA effect,
4950
* but also blurriness caused by rendering to a lower resolution render target by using

src/framework/app-base.js

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,21 @@ import { getApplication, setApplication } from './globals.js';
106106
let app = null;
107107

108108
/**
109-
* An Application represents and manages your PlayCanvas application. If you are developing using
110-
* the PlayCanvas Editor, the Application is created for you. You can access your Application
111-
* instance in your scripts. Below is a skeleton script which shows how you can access the
112-
* application 'app' property inside the initialize and update functions:
109+
* AppBase represents the base functionality for all PlayCanvas applications. It is responsible for
110+
* initializing and managing the application lifecycle. It coordinates core engine systems such
111+
* as:
113112
*
114-
* ```javascript
115-
* // Editor example: accessing the pc.Application from a script
116-
* var MyScript = pc.createScript('myScript');
113+
* - The graphics device - see {@link GraphicsDevice}.
114+
* - The asset registry - see {@link AssetRegistry}.
115+
* - The component system registry - see {@link ComponentSystemRegistry}.
116+
* - The scene - see {@link Scene}.
117+
* - Input devices - see {@link Keyboard}, {@link Mouse}, {@link TouchDevice}, and {@link GamePads}.
118+
* - The main update/render loop.
117119
*
118-
* MyScript.prototype.initialize = function() {
119-
* // Every script instance has a property 'this.app' accessible in the initialize...
120-
* const app = this.app;
121-
* };
122-
*
123-
* MyScript.prototype.update = function(dt) {
124-
* // ...and update functions.
125-
* const app = this.app;
126-
* };
127-
* ```
128-
*
129-
* If you are using the Engine without the Editor, you have to create the application instance
130-
* manually.
120+
* Using AppBase directly requires you to register {@link ComponentSystem}s and
121+
* {@link ResourceHandler}s yourself. This facilitates
122+
* [tree-shaking](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking) when bundling
123+
* your application.
131124
*/
132125
class AppBase extends EventHandler {
133126
/**
@@ -288,8 +281,8 @@ class AppBase extends EventHandler {
288281

289282
/**
290283
* Set to true to render the scene on the next iteration of the main loop. This only has an
291-
* effect if {@link AppBase#autoRender} is set to false. The value of renderNextFrame is set
292-
* back to false again as soon as the scene has been rendered.
284+
* effect if {@link autoRender} is set to false. The value of renderNextFrame is set back to
285+
* false again as soon as the scene has been rendered.
293286
*
294287
* @type {boolean}
295288
* @example
@@ -449,11 +442,11 @@ class AppBase extends EventHandler {
449442
/**
450443
* Create a new AppBase instance.
451444
*
452-
* @param {HTMLCanvasElement} canvas - The canvas element.
445+
* @param {HTMLCanvasElement | OffscreenCanvas} canvas - The canvas element.
453446
* @example
454-
* // Engine-only example: create the application manually
455-
* const options = new AppOptions();
456447
* const app = new pc.AppBase(canvas);
448+
*
449+
* const options = new AppOptions();
457450
* app.init(options);
458451
*
459452
* // Start the application's main loop

src/framework/app-options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
*/
1515

1616
/**
17-
* AppOptions is an object that holds configuration settings utilized in the creation of AppBase. It
18-
* allows functionality to be included or excluded from the AppBase instance.
17+
* AppOptions holds configuration settings utilized in the creation of an {@link AppBase} instance.
18+
* It allows functionality to be included or excluded from the AppBase instance.
1919
*/
2020
class AppOptions {
2121
/**

src/framework/application.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,11 @@ import { XrManager } from './xr/xr-manager.js';
6565
*/
6666

6767
/**
68-
* An Application represents and manages your PlayCanvas application. If you are developing using
69-
* the PlayCanvas Editor, the Application is created for you. You can access your Application
70-
* instance in your scripts. Below is a skeleton script which shows how you can access the
71-
* application 'app' property inside the initialize and update functions:
72-
*
73-
* ```javascript
74-
* // Editor example: accessing the pc.Application from a script
75-
* var MyScript = pc.createScript('myScript');
76-
*
77-
* MyScript.prototype.initialize = function() {
78-
* // Every script instance has a property 'this.app' accessible in the initialize...
79-
* const app = this.app;
80-
* };
81-
*
82-
* MyScript.prototype.update = function(dt) {
83-
* // ...and update functions.
84-
* const app = this.app;
85-
* };
86-
* ```
87-
*
88-
* If you are using the Engine without the Editor, you have to create the application instance
89-
* manually.
68+
* Application is a subclass of {@link AppBase}, which represents the base functionality for all
69+
* PlayCanvas applications. It acts as a convenience class by internally registering all
70+
* {@link ComponentSystem}s and {@link ResourceHandler}s implemented in the PlayCanvas Engine. This
71+
* makes app setup simple but results in the full engine being included when bundling for your
72+
* application.
9073
*/
9174
class Application extends AppBase {
9275
/**

src/framework/components/audio-listener/component.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
import { Component } from '../component.js';
22

33
/**
4-
* Represents the audio listener in the 3D world, so that 3D positioned audio sources are heard
5-
* correctly.
4+
* The AudioListenerComponent enables an {@link Entity} to represent the point from where
5+
* positional {@link SoundComponent}s are heard. This is typically the main camera Entity in your
6+
* scene. And typically, you will only have one AudioListenerComponent in your scene.
7+
*
8+
* You should never need to use the AudioListenerComponent constructor directly. To add a
9+
* AudioListenerComponent to an {@link Entity}, use {@link Entity#addComponent}:
10+
*
11+
* ```javascript
12+
* const entity = new pc.Entity();
13+
* entity.addComponent('audiolistener');
14+
* ```
15+
*
16+
* Relevant Engine API examples:
17+
*
18+
* - [Positional Sound](https://playcanvas.github.io/#/sound/positional)
619
*
720
* @hideconstructor
821
* @category Sound

src/framework/components/camera/component.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,31 @@ import { PostEffectQueue } from './post-effect-queue.js';
3131
*/
3232

3333
/**
34-
* The Camera Component enables an Entity to render the scene. A scene requires at least one
35-
* enabled camera component to be rendered. Note that multiple camera components can be enabled
36-
* simultaneously (for split-screen or offscreen rendering, for example).
34+
* The CameraComponent enables an {@link Entity} to render the scene. A scene requires at least
35+
* one enabled camera component to be rendered. The camera's view direction is along the negative
36+
* z-axis of the owner entity.
37+
*
38+
* Note that multiple camera components can be enabled simultaneously (for split-screen or
39+
* offscreen rendering, for example).
40+
*
41+
* You should never need to use the CameraComponent constructor directly. To add a CameraComponent
42+
* to an {@link Entity}, use {@link Entity#addComponent}:
3743
*
3844
* ```javascript
39-
* // Add a pc.CameraComponent to an entity
4045
* const entity = new pc.Entity();
4146
* entity.addComponent('camera', {
4247
* nearClip: 1,
4348
* farClip: 100,
4449
* fov: 55
4550
* });
51+
* ```
4652
*
47-
* // Get the pc.CameraComponent on an entity
48-
* const cameraComponent = entity.camera;
53+
* Once the CameraComponent is added to the entity, you can access it via the `camera` property:
54+
*
55+
* ```javascript
56+
* entity.camera.nearClip = 2; // Set the near clip of the camera
4957
*
50-
* // Update a property on a camera component
51-
* entity.camera.nearClip = 2;
58+
* console.log(entity.camera.nearClip); // Get the near clip of the camera
5259
* ```
5360
*
5461
* @hideconstructor

src/framework/components/collision/component.js

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,46 @@ const _vec3 = new Vec3();
1515
const _quat = new Quat();
1616

1717
/**
18-
* A collision volume. Use this in conjunction with a {@link RigidBodyComponent} to make a
18+
* The CollisionComponent enables an {@link Entity} to act as a collision volume. Use it on its own
19+
* to define a trigger volume. Or use it in conjunction with a {@link RigidBodyComponent} to make a
1920
* collision volume that can be simulated using the physics engine.
2021
*
21-
* If the {@link Entity} does not have a {@link RigidBodyComponent} then this collision volume will
22-
* act as a trigger volume. When an entity with a dynamic or kinematic body enters or leaves an
23-
* entity with a trigger volume, both entities will receive trigger events.
22+
* When an entity is configured as a trigger volume, if an entity with a dynamic or kinematic body
23+
* enters or leaves that trigger volume, both entities will receive trigger events.
2424
*
25-
* The following table shows all the events that can be fired between two Entities:
25+
* You should never need to use the CollisionComponent constructor directly. To add an
26+
* CollisionComponent to an {@link Entity}, use {@link Entity#addComponent}:
2627
*
27-
* | | Rigid Body (Static) | Rigid Body (Dynamic or Kinematic) | Trigger Volume |
28-
* | ------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------------------------- | --------------------------------------------------- |
29-
* | **Rigid Body (Static)** | | <ul><li>contact</li><li>collisionstart</li><li>collisionend</li></ul> | |
30-
* | **Rigid Body (Dynamic or Kinematic)** | <ul><li>contact</li><li>collisionstart</li><li>collisionend</li></ul> | <ul><li>contact</li><li>collisionstart</li><li>collisionend</li></ul> | <ul><li>triggerenter</li><li>triggerleave</li></ul> |
31-
* | **Trigger Volume** | | <ul><li>triggerenter</li><li>triggerleave</li></ul> | |
28+
* ```javascript
29+
* const entity = pc.Entity();
30+
* entity.addComponent('collision'); // This defaults to 1x1x1 box-shaped trigger volume
31+
* ```
32+
*
33+
* To create a 0.5 radius dynamic rigid body sphere:
34+
*
35+
* ```javascript
36+
* const entity = pc.Entity();
37+
* entity.addComponent('collision', {
38+
* type: 'sphere'
39+
* });
40+
* entity.addComponent('rigidbody', {
41+
* type: 'dynamic'
42+
* });
43+
* ```
44+
*
45+
* Once the CollisionComponent is added to the entity, you can access it via the `collision` property:
46+
*
47+
* ```javascript
48+
* entity.collision.type = 'cylinder'; // Set the collision volume to a cylinder
49+
*
50+
* console.log(entity.collision.type); // Get the collision volume type and print it
51+
* ```
52+
*
53+
* Relevant Engine API examples:
54+
*
55+
* - [Compound Collision](https://playcanvas.github.io/#/physics/compound-collision)
56+
* - [Falling Shapes](https://playcanvas.github.io/#/physics/falling-shapes)
57+
* - [Offset Collision](https://playcanvas.github.io/#/physics/offset-collision)
3258
*
3359
* @hideconstructor
3460
* @category Physics

src/framework/components/element/component.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,37 +45,36 @@ const matD = new Mat4();
4545
* {@link ScreenComponent} ancestor, the ElementComponent will be transformed like any other
4646
* entity.
4747
*
48-
* You should never need to use the ElementComponent constructor. To add an ElementComponent to a
49-
* {@link Entity}, use {@link Entity#addComponent}:
48+
* You should never need to use the ElementComponent constructor directly. To add an
49+
* ElementComponent to an {@link Entity}, use {@link Entity#addComponent}:
5050
*
5151
* ```javascript
52-
* // Add an element component to an entity with the default options
5352
* const entity = pc.Entity();
54-
* entity.addComponent("element"); // This defaults to a 'group' element
53+
* entity.addComponent('element'); // This defaults to a 'group' element
5554
* ```
5655
*
5756
* To create a simple text-based element:
5857
*
5958
* ```javascript
60-
* entity.addComponent("element", {
59+
* entity.addComponent('element', {
6160
* anchor: new pc.Vec4(0.5, 0.5, 0.5, 0.5), // centered anchor
6261
* fontAsset: fontAsset,
6362
* fontSize: 128,
6463
* pivot: new pc.Vec2(0.5, 0.5), // centered pivot
65-
* text: "Hello World!",
64+
* text: 'Hello World!',
6665
* type: pc.ELEMENTTYPE_TEXT
6766
* });
6867
* ```
6968
*
70-
* Once the ElementComponent is added to the entity, you can set and get any of its properties:
69+
* Once the ElementComponent is added to the entity, you can access it via the `element` property:
7170
*
7271
* ```javascript
7372
* entity.element.color = pc.Color.RED; // Set the element's color to red
7473
*
7574
* console.log(entity.element.color); // Get the element's color and print it
7675
* ```
7776
*
78-
* Relevant 'Engine-only' examples:
77+
* Relevant Engine API examples:
7978
*
8079
* - [Basic text rendering](https://playcanvas.github.io/#/user-interface/text)
8180
* - [Auto font sizing](https://playcanvas.github.io/#/user-interface/text-auto-font-size)

0 commit comments

Comments
 (0)