Skip to content

Commit 135c8fe

Browse files
authored
[FIX] Several fixes reported by checkJs (playcanvas#2878)
* [FIX] Several fixes reported by checkJs * Remove invalid 'see' tag * Add missing property initializer for SkinPartition * Fix package.json on Windows and add missing import * Fix calcGpuSize
1 parent bbe6f8c commit 135c8fe

18 files changed

+58
-82
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
"test": "karma start tests/karma.conf.js -- --single-run --release",
7575
"test:watch": "karma start tests/karma.conf.js",
7676
"test:debug": "karma start tests/karma.conf.js -- --single-run=false",
77-
"test:tsd": "npm run tsd && tsc --pretty false build/playcanvas.d.ts;",
78-
"tsd": "jsdoc -c conf-tsd.json; node tsd.js;",
77+
"test:tsd": "npm run tsd && tsc --pretty false build/playcanvas.d.ts",
78+
"tsd": "jsdoc -c conf-tsd.json && node tsd.js",
7979
"unzipbundle": "gzip -x tests/assets/bundle.gz"
8080
}
8181
}

src/anim/controller/anim-blend-tree.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Vec2 } from '../../math/vec2.js';
2+
13
import { AnimNode } from './anim-node.js';
24
import {
35
ANIM_BLEND_1D, ANIM_BLEND_2D_DIRECTIONAL, ANIM_BLEND_2D_CARTESIAN, ANIM_BLEND_DIRECT
@@ -115,7 +117,7 @@ class AnimBlendTree extends AnimNode {
115117
return;
116118
}
117119
this._parameterValues = parameterValues;
118-
p = new pc.Vec2(this._parameterValues);
120+
p = new Vec2(this._parameterValues);
119121

120122
weightSum = 0.0;
121123
for (i = 0; i < this._children.length; i++) {
@@ -145,7 +147,7 @@ class AnimBlendTree extends AnimNode {
145147
return;
146148
}
147149
this._parameterValues = parameterValues;
148-
p = new pc.Vec2(this._parameterValues);
150+
p = new Vec2(this._parameterValues);
149151

150152

151153
weightSum = 0.0;
@@ -157,8 +159,8 @@ class AnimBlendTree extends AnimNode {
157159
pj = this._children[j].point.clone();
158160
var pipAngle = getAngleRad(pi, p);
159161
var pipjAngle = getAngleRad(pi, pj);
160-
pipj = new pc.Vec2((pj.length() - pi.length()) / ((pj.length() + pi.length()) / 2), pipjAngle * 2.0);
161-
pip = new pc.Vec2((p.length() - pi.length()) / ((pj.length() + pi.length()) / 2), pipAngle * 2.0);
162+
pipj = new Vec2((pj.length() - pi.length()) / ((pj.length() + pi.length()) / 2), pipjAngle * 2.0);
163+
pip = new Vec2((p.length() - pi.length()) / ((pj.length() + pi.length()) / 2), pipAngle * 2.0);
162164
result = clamp(1.0 - Math.abs((pip.clone().dot(pipj) / pipj.lengthSq())), 0.0, 1.0);
163165
if (result < minj) minj = result;
164166
}

src/anim/controller/anim-controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
* @name AnimController
1616
* @classdesc The AnimController manages the animations for it's entity, based on the provided state graph and parameters. It's update method determines which state the controller should be in based on the current time, parameters and available states / transitions. It also ensures the AnimEvaluator is supplied with the correct animations, based on the currently active state.
1717
* @description Create a new AnimController.
18-
* @param {animEvaluator} animEvaluator - The animation evaluator used to blend all current playing animation keyframes and update the entities properties based on the current animation values.
18+
* @param {AnimEvaluator} animEvaluator - The animation evaluator used to blend all current playing animation keyframes and update the entities properties based on the current animation values.
1919
* @param {object[]} states - The list of states used to form the controller state graph.
2020
* @param {object[]} transitions - The list of transitions used to form the controller state graph.
2121
* @param {object[]} parameters - The anim components parameters.

src/anim/controller/anim-node.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Vec2 } from '../../math/vec2.js';
2+
13
/**
24
* @private
35
* @class
@@ -15,7 +17,7 @@ class AnimNode {
1517
this._state = state;
1618
this._parent = parent;
1719
this._name = name;
18-
this._point = Array.isArray(point) ? new pc.Vec2(point) : point;
20+
this._point = Array.isArray(point) ? new Vec2(point[0], point[1]) : point;
1921
this._speed = speed;
2022
this._weight = 1.0;
2123
this._animTrack = null;

src/anim/evaluator/anim-evaluator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ class AnimEvaluator {
104104

105105
/**
106106
* @private
107-
* @name AnimEvaluator
108-
* @type {number}
107+
* @name AnimEvaluator#clips
108+
* @type {AnimClip[]}
109109
* @description The number of clips.
110110
*/
111111
get clips() {

src/core/string.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ var string = {
201201
* @function
202202
* @name string.getSymbols
203203
* @description Gets an array of all grapheme clusters (visible symbols) in a string. This is needed because
204-
* some symbols (such as emoji or accented characters) are actually made up of multiple character codes.
204+
* some symbols (such as emoji or accented characters) are actually made up of multiple character codes. See
205+
* {@link https://mathiasbynens.be/notes/javascript-unicode here} for more info.
205206
* @param {string} string - The string to break into symbols.
206207
* @returns {string[]} The symbols in the string.
207-
* @see {@link https://mathiasbynens.be/notes/javascript-unicode Unicode strings in JavaScript}
208208
*/
209209
getSymbols: function (string) {
210210
if (typeof string !== 'string') {

src/graphics/graphics-device.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,24 +268,24 @@ class GraphicsDevice extends EventHandler {
268268
// Add handlers for when the WebGL context is lost or restored
269269
this.contextLost = false;
270270

271-
this._contextLostHandler = function (event) {
271+
this._contextLostHandler = event => {
272272
event.preventDefault();
273273
this.contextLost = true;
274274
this.loseContext();
275275
// #ifdef DEBUG
276276
console.log('pc.GraphicsDevice: WebGL context lost.');
277277
// #endif
278278
this.fire('devicelost');
279-
}.bind(this);
279+
};
280280

281-
this._contextRestoredHandler = function () {
281+
this._contextRestoredHandler = () => {
282282
// #ifdef DEBUG
283283
console.log('pc.GraphicsDevice: WebGL context restored.');
284284
// #endif
285285
this.restoreContext();
286286
this.contextLost = false;
287287
this.fire('devicerestored');
288-
}.bind(this);
288+
};
289289

290290
// Retrieve the WebGL context
291291
var preferWebGl2 = (options && options.preferWebGl2 !== undefined) ? options.preferWebGl2 : true;
@@ -2484,6 +2484,7 @@ class GraphicsDevice extends EventHandler {
24842484
* * {@link CLEARFLAG_COLOR}
24852485
* * {@link CLEARFLAG_DEPTH}
24862486
* * {@link CLEARFLAG_STENCIL}
2487+
* @param {number} options.stencil - The stencil value to clear the stencil buffer to. Defaults to 0.
24872488
* @example
24882489
* // Clear color buffer to black and depth buffer to 1.0
24892490
* device.clear();
@@ -3616,11 +3617,11 @@ class GraphicsDevice extends EventHandler {
36163617
this._enableAutoInstancing = value && this.extInstancing;
36173618
}
36183619

3619-
/**
3620-
* @name GraphicsDevice#maxPixelRatio
3621-
* @type {number}
3622-
* @description Maximum pixel ratio.
3623-
*/
3620+
/**
3621+
* @name GraphicsDevice#maxPixelRatio
3622+
* @type {number}
3623+
* @description Maximum pixel ratio.
3624+
*/
36243625
get maxPixelRatio() {
36253626
return this._maxPixelRatio;
36263627
}
@@ -3633,7 +3634,7 @@ class GraphicsDevice extends EventHandler {
36333634
/**
36343635
* @readonly
36353636
* @name GraphicsDevice#textureFloatHighPrecision
3636-
* @type {number}
3637+
* @type {boolean}
36373638
* @description Check if high precision floating-point textures are supported.
36383639
*/
36393640
get textureFloatHighPrecision() {
@@ -3646,7 +3647,7 @@ class GraphicsDevice extends EventHandler {
36463647
/**
36473648
* @readonly
36483649
* @name GraphicsDevice#textureHalfFloatUpdatable
3649-
* @type {number}
3650+
* @type {boolean}
36503651
* @description Check if texture with half float format can be updated with data.
36513652
*/
36523653
get textureHalfFloatUpdatable() {

src/graphics/prefilter-cubemap.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ function prefilterCubemap(options) {
247247
cubemap._levels[i] = mips[i]._levels[0];
248248

249249
cubemap.upload();
250-
cubemap._prefilteredMips = true;
251250
options.singleFilteredFixed = cubemap;
252251
}
253252

@@ -268,7 +267,6 @@ function prefilterCubemap(options) {
268267
cubemap._levels[i] = mips[i]._levels[0];
269268
}
270269
cubemap.upload();
271-
cubemap._prefilteredMips = true;
272270
options.singleFilteredFixedRgbm = cubemap;
273271
}
274272
}

src/graphics/texture.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ class Texture {
607607

608608
if (format === PIXELFORMAT_PVRTC_2BPP_RGB_1 ||
609609
format === PIXELFORMAT_PVRTC_2BPP_RGBA_1) {
610-
blockWidth = Math.floor(blockWidth / 2, 1);
610+
blockWidth = Math.max(Math.floor(blockWidth / 2), 1);
611611
}
612612

613613
result += blockWidth * blockHeight * blockDepth * blockSize;
@@ -656,6 +656,10 @@ class Texture {
656656
* @param {object} [options] - Optional options object. Valid properties are as follows:
657657
* @param {number} [options.level] - The mip level to lock with 0 being the top level. Defaults to 0.
658658
* @param {number} [options.face] - If the texture is a cubemap, this is the index of the face to lock.
659+
* @param {number} [options.mode] - The lock mode. Can be:
660+
* * {@link TEXTURELOCK_READ}
661+
* * {@link TEXTURELOCK_WRITE}
662+
* Defaults to {@link TEXTURELOCK_WRITE}.
659663
* @returns {Uint8Array|Uint16Array|Float32Array} A typed array containing the pixel data of the locked mip level.
660664
*/
661665
lock(options = {}) {

src/math/curve-set.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class CurveSet {
132132
* @param {number} precision - The number of samples to return.
133133
* @param {number} min - The minimum output value.
134134
* @param {number} max - The maximum output value.
135-
* @returns {number[]} The set of quantized values.
135+
* @returns {Float32Array} The set of quantized values.
136136
*/
137137
quantizeClamped(precision, min, max) {
138138
var result = this.quantize(precision);

src/math/mat3.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Vec3 } from './vec3.js';
2+
13
/**
24
* @class
35
* @name Mat3

src/resources/parser/glb-parser.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
TYPE_INT8, TYPE_UINT8, TYPE_INT16, TYPE_UINT16, TYPE_INT32, TYPE_UINT32, TYPE_FLOAT32
2121
} from '../../graphics/constants.js';
2222
import { IndexBuffer } from '../../graphics/index-buffer.js';
23+
import { Texture } from '../../graphics/texture.js';
2324
import { VertexBuffer } from '../../graphics/vertex-buffer.js';
2425
import { VertexFormat } from '../../graphics/vertex-format.js';
2526

@@ -315,18 +316,18 @@ var cloneTexture = function (texture) {
315316
return result;
316317
};
317318

318-
var result = new pc.Texture(texture.device, texture); // duplicate texture
319+
var result = new Texture(texture.device, texture); // duplicate texture
319320
result._levels = shallowCopyLevels(texture); // shallow copy the levels structure
320321
return result;
321322
};
322323

323324
// given a texture asset, clone it
324325
var cloneTextureAsset = function (src) {
325-
var result = new pc.Asset(src.name + '_clone',
326-
src.type,
327-
src.file,
328-
src.data,
329-
src.options);
326+
var result = new Asset(src.name + '_clone',
327+
src.type,
328+
src.file,
329+
src.data,
330+
src.options);
330331
result.loaded = true;
331332
result.resource = cloneTexture(src.resource);
332333
src.registry.add(result);

src/resources/template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TemplateHandler {
1818

1919
var assets = this._app.assets;
2020

21-
http.get(url.load, function (err, response) {
21+
http.get(url.load, {}, function (err, response) {
2222
if (err) {
2323
callback("Error requesting template: " + url.original);
2424
} else {

src/scene/camera.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,17 @@ class Camera {
320320
* @returns {Camera} A cloned Camera.
321321
*/
322322
clone() {
323-
return new this.constructor().copy(this);
323+
return new Camera().copy(this);
324324
}
325325

326+
/**
327+
* @private
328+
* @function
329+
* @name Camera#copy
330+
* @param {Camera} other - Camera to copy.
331+
* @description Copies one camera to another.
332+
* @returns {Camera} Self for chaining.
333+
*/
326334
copy(other) {
327335
this.aspectRatio = other.aspectRatio;
328336
this.aspectRatioMode = other.aspectRatioMode;
@@ -349,6 +357,7 @@ class Camera {
349357
this.renderTarget = other.renderTarget;
350358
this.scissorRect = other.scissorRect;
351359
this.vrDisplay = other.vrDisplay;
360+
return this;
352361
}
353362

354363
_updateViewProjMat() {

src/scene/scene.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ class Scene extends EventHandler {
420420
if (!this.skyboxRotation.equals(Quat.IDENTITY)) {
421421
if (!this._skyboxRotationMat4) this._skyboxRotationMat4 = new Mat4();
422422
if (!this._skyboxRotationMat3) this._skyboxRotationMat3 = new Mat3();
423-
this._skyboxRotationMat4.setTRS(pc.Vec3.ZERO, this._skyboxRotation, pc.Vec3.ONE);
423+
this._skyboxRotationMat4.setTRS(Vec3.ZERO, this._skyboxRotation, Vec3.ONE);
424424
this._skyboxRotationMat4.invertTo3x3(this._skyboxRotationMat3);
425425
material.setParameter("cubeMapRotationMatrix", this._skyboxRotationMat3.data);
426426
}

src/scene/skin-partition.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class SkinPartition {
2424
// to this particular partition. speeds up checking for duplicate vertices so we don't
2525
// add the same vertex more than once.
2626
this.indexMap = {};
27+
28+
this.originalMesh = null;
2729
}
2830

2931
addVertex(vertex, idx, vertexArray) {

src/shape/bounding-sphere.js

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { Vec3 } from '../math/vec3.js';
22

33
var tmpVecA = new Vec3();
44
var tmpVecB = new Vec3();
5-
var tmpVecC = new Vec3();
6-
var tmpVecD = new Vec3();
75

86
/**
97
* @class
@@ -28,49 +26,6 @@ class BoundingSphere {
2826
return lenSq < r * r;
2927
}
3028

31-
compute(vertices) {
32-
var i;
33-
var numVerts = vertices.length / 3;
34-
35-
var vertex = tmpVecA;
36-
var avgVertex = tmpVecB;
37-
var sum = tmpVecC;
38-
39-
// FIRST PASS:
40-
// Find the "average vertex", which is the sphere's center...
41-
42-
for (i = 0; i < numVerts; i++) {
43-
vertex.set(vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]);
44-
sum.addSelf(vertex);
45-
46-
// apply a part-result to avoid float-overflows
47-
if (i % 100 === 0) {
48-
sum.scale(1 / numVerts);
49-
avgVertex.add(sum);
50-
sum.set(0, 0, 0);
51-
}
52-
}
53-
54-
sum.scale(1 / numVerts);
55-
avgVertex.add(sum);
56-
57-
this.center.copy(avgVertex);
58-
59-
// SECOND PASS:
60-
// Find the maximum (squared) distance of all vertices to the center...
61-
var maxDistSq = 0;
62-
var centerToVert = tmpVecD;
63-
64-
for (i = 0; i < numVerts; i++) {
65-
vertex.set(vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]);
66-
67-
centerToVert.sub2(vertex, this.center);
68-
maxDistSq = Math.max(centerToVert.lengthSq(), maxDistSq);
69-
}
70-
71-
this.radius = Math.sqrt(maxDistSq);
72-
}
73-
7429
/**
7530
* @function
7631
* @name BoundingSphere#intersectsRay

src/xr/xr-input-source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class XrInputSource extends EventHandler {
278278
* @function
279279
* @name XrInputSource#getRotation
280280
* @description Get the world space rotation of input source if it is handheld ({@link XrInputSource#grip} is true). Otherwise it will return null.
281-
* @returns {Vec3|null} The world space rotation of handheld input source.
281+
* @returns {Quat|null} The world space rotation of handheld input source.
282282
*/
283283
getRotation() {
284284
if (! this._rotation) return null;

0 commit comments

Comments
 (0)