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

Get visual tests running in 2.0 #7251

Merged
merged 4 commits into from
Sep 7, 2024
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
458 changes: 458 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"i18next": "^19.0.2",
"i18next-browser-languagedetector": "^4.0.1",
"lint-staged": "^15.1.0",
"resemblejs": "^5.0.0",
"rollup": "^4.9.6",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-visualizer": "^5.12.0",
Expand Down
6 changes: 0 additions & 6 deletions src/image/loading_displaying.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,13 @@ p5.prototype.loadImage = async function(
successCallback,
failureCallback,
(pImg => {
self._decrementPreload();
resolve(pImg);
}).bind(self)
);
}catch(e){
console.error(e.toString(), e.stack);
if (typeof failureCallback === 'function') {
failureCallback(e);
self._decrementPreload();
} else {
console.error(e);
}
Expand All @@ -160,7 +158,6 @@ p5.prototype.loadImage = async function(
e => {
if (typeof failureCallback === 'function') {
failureCallback(e);
self._decrementPreload();
} else {
console.error(e);
}
Expand All @@ -182,14 +179,12 @@ p5.prototype.loadImage = async function(
successCallback(pImg);
}
resolve();
self._decrementPreload();
};

img.onerror = e => {
p5._friendlyFileLoadError(0, img.src);
if (typeof failureCallback === 'function') {
failureCallback(e);
self._decrementPreload();
} else {
console.error(e);
}
Expand All @@ -215,7 +210,6 @@ p5.prototype.loadImage = async function(
p5._friendlyFileLoadError(0, path);
if (typeof failureCallback === 'function') {
failureCallback(e);
self._decrementPreload();
} else {
console.error(e);
}
Expand Down
45 changes: 20 additions & 25 deletions src/io/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ import Renderer from '../core/p5.Renderer';
* </code>
* </div>
*/
p5.prototype.loadJSON = function (...args) {
p5.prototype.loadJSON = async function (...args) {
p5._validateParameters('loadJSON', args);
const path = args[0];
let callback;
Expand All @@ -266,8 +266,7 @@ p5.prototype.loadJSON = function (...args) {
}
}

const self = this;
this.httpDo(
await new Promise(resolve => this.httpDo(
path,
'GET',
options,
Expand All @@ -280,7 +279,7 @@ p5.prototype.loadJSON = function (...args) {
callback(resp);
}

self._decrementPreload();
resolve()
},
err => {
// Error handling
Expand All @@ -292,7 +291,7 @@ p5.prototype.loadJSON = function (...args) {
throw err;
}
}
);
));

return ret;
};
Expand Down Expand Up @@ -431,7 +430,7 @@ p5.prototype.loadJSON = function (...args) {
* </code>
* </div>
*/
p5.prototype.loadStrings = function (...args) {
p5.prototype.loadStrings = async function (...args) {
p5._validateParameters('loadStrings', args);

const ret = [];
Expand All @@ -448,8 +447,7 @@ p5.prototype.loadStrings = function (...args) {
}
}

const self = this;
p5.prototype.httpDo.call(
await new Promise(resolve => p5.prototype.httpDo.call(
this,
args[0],
'GET',
Expand All @@ -476,7 +474,7 @@ p5.prototype.loadStrings = function (...args) {
callback(ret);
}

self._decrementPreload();
resolve()
},
function (err) {
// Error handling
Expand All @@ -488,7 +486,7 @@ p5.prototype.loadStrings = function (...args) {
throw err;
}
}
);
));

return ret;
};
Expand Down Expand Up @@ -563,7 +561,7 @@ p5.prototype.loadStrings = function (...args) {
* </code>
* </div>
*/
p5.prototype.loadTable = function (path) {
p5.prototype.loadTable = async function (path) {
// p5._validateParameters('loadTable', arguments);
let callback;
let errorCallback;
Expand Down Expand Up @@ -604,8 +602,7 @@ p5.prototype.loadTable = function (path) {

const t = new p5.Table();

const self = this;
this.httpDo(
await new Promise(resolve => this.httpDo(
path,
'GET',
'table',
Expand Down Expand Up @@ -737,7 +734,7 @@ p5.prototype.loadTable = function (path) {
callback(t);
}

self._decrementPreload();
resolve()
},
err => {
// Error handling
Expand All @@ -749,7 +746,7 @@ p5.prototype.loadTable = function (path) {
console.error(err);
}
}
);
));

return t;
};
Expand Down Expand Up @@ -929,7 +926,7 @@ function makeObject(row, headers) {
* </code>
* </div>
*/
p5.prototype.loadXML = function (...args) {
p5.prototype.loadXML = async function (...args) {
const ret = new p5.XML();
let callback, errorCallback;

Expand All @@ -944,8 +941,7 @@ p5.prototype.loadXML = function (...args) {
}
}

const self = this;
this.httpDo(
await new Promise(resolve => this.httpDo(
args[0],
'GET',
'xml',
Expand All @@ -957,7 +953,7 @@ p5.prototype.loadXML = function (...args) {
callback(ret);
}

self._decrementPreload();
resolve()
},
function (err) {
// Error handling
Expand All @@ -969,7 +965,7 @@ p5.prototype.loadXML = function (...args) {
throw err;
}
}
);
));

return ret;
};
Expand Down Expand Up @@ -1000,11 +996,10 @@ p5.prototype.loadXML = function (...args) {
* }
* </code></div>
*/
p5.prototype.loadBytes = function (file, callback, errorCallback) {
p5.prototype.loadBytes = async function (file, callback, errorCallback) {
const ret = {};

const self = this;
this.httpDo(
await new Promise(resolve => this.httpDo(
file,
'GET',
'arrayBuffer',
Expand All @@ -1015,7 +1010,7 @@ p5.prototype.loadBytes = function (file, callback, errorCallback) {
callback(ret);
}

self._decrementPreload();
resolve();
},
err => {
// Error handling
Expand All @@ -1027,7 +1022,7 @@ p5.prototype.loadBytes = function (file, callback, errorCallback) {
throw err;
}
}
);
));
return ret;
};

Expand Down
10 changes: 4 additions & 6 deletions src/typography/loading_displaying.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,11 @@ import '../core/friendly_errors/fes_core';
* </code>
* </div>
*/
p5.prototype.loadFont = function(path, onSuccess, onError) {
p5.prototype.loadFont = async function(path, onSuccess, onError) {
p5._validateParameters('loadFont', arguments);
const p5Font = new p5.Font(this);

const self = this;
opentype.load(path, (err, font) => {
await new Promise(resolve => opentype.load(path, (err, font) => {
if (err) {
p5._friendlyFileLoadError(4, path);
if (typeof onError !== 'undefined') {
Expand All @@ -146,8 +145,7 @@ p5.prototype.loadFont = function(path, onSuccess, onError) {
if (typeof onSuccess !== 'undefined') {
onSuccess(p5Font);
}

self._decrementPreload();
resolve();

// check that we have an acceptable font type
const validFontTypes = ['ttf', 'otf', 'woff', 'woff2'];
Expand All @@ -174,7 +172,7 @@ p5.prototype.loadFont = function(path, onSuccess, onError) {
);
document.head.appendChild(newStyle);
}
});
}));

return p5Font;
};
Expand Down
15 changes: 8 additions & 7 deletions src/webgl/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ import './p5.Geometry';
* @param {Boolean} [options.flipV]
* @return {p5.Geometry} new <a href="#/p5.Geometry">p5.Geometry</a> object.
*/
p5.prototype.loadModel = function (path, options) {
p5.prototype.loadModel = async function (path, options) {
p5._validateParameters('loadModel', arguments);
let normalize = false;
let successCallback;
Expand Down Expand Up @@ -420,7 +420,7 @@ p5.prototype.loadModel = function (path, options) {
}
}
if (fileType.match(/\.stl$/i)) {
this.httpDo(
await new Promise(resolve => this.httpDo(
path,
'GET',
'arrayBuffer',
Expand All @@ -439,15 +439,15 @@ p5.prototype.loadModel = function (path, options) {
model.flipV();
}

self._decrementPreload();
resolve();
if (typeof successCallback === 'function') {
successCallback(model);
}
},
failureCallback
);
));
} else if (fileType.match(/\.obj$/i)) {
this.loadStrings(
await new Promise(resolve => this.loadStrings(
path,
async lines => {
try {
Expand All @@ -474,14 +474,14 @@ p5.prototype.loadModel = function (path, options) {
model.flipV();
}

self._decrementPreload();
resolve();
if (typeof successCallback === 'function') {
successCallback(model);
}
}
},
failureCallback
);
));
} else {
p5._friendlyFileLoadError(3, path);
if (failureCallback) {
Expand Down Expand Up @@ -665,6 +665,7 @@ function parseObj(model, lines, materials = {}) {
model.vertexColors.push(materialDiffuseColor[0]);
model.vertexColors.push(materialDiffuseColor[1]);
model.vertexColors.push(materialDiffuseColor[2]);
model.vertexColors.push(1);
}
} else {
hasColorlessVertices = true;
Expand Down
8 changes: 4 additions & 4 deletions test/unit/visual/cases/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ visualSuite('WebGL', function() {
visualTest('OBJ model with MTL file displays diffuse colors correctly', function(p5, screenshot) {
return new Promise(resolve => {
p5.createCanvas(50, 50, p5.WEBGL);
p5.loadModel('unit/assets/octa-color.obj', model => {
p5.loadModel('/unit/assets/octa-color.obj', model => {
p5.background(255);
p5.rotateX(10 * 0.01);
p5.rotateY(10 * 0.01);
Expand All @@ -101,7 +101,7 @@ visualSuite('WebGL', function() {
visualTest('Object with no colors takes on fill color', function(p5, screenshot) {
return new Promise(resolve => {
p5.createCanvas(50, 50, p5.WEBGL);
p5.loadModel('unit/assets/cube.obj', model => {
p5.loadModel('/unit/assets/cube.obj', model => {
p5.background(255);
p5.fill('blue'); // Setting a fill color
p5.rotateX(p5.frameCount * 0.01);
Expand All @@ -117,8 +117,8 @@ visualSuite('WebGL', function() {
'Object with different texture coordinates per use of vertex keeps the coordinates intact',
async function(p5, screenshot) {
p5.createCanvas(50, 50, p5.WEBGL);
const tex = await new Promise(resolve => p5.loadImage('unit/assets/cat.jpg', resolve));
const cube = await new Promise(resolve => p5.loadModel('unit/assets/cube-textures.obj', resolve));
const tex = await new Promise(resolve => p5.loadImage('/unit/assets/cat.jpg', resolve));
const cube = await new Promise(resolve => p5.loadModel('/unit/assets/cube-textures.obj', resolve));
cube.normalize();
p5.background(255);
p5.texture(tex);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading