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

[p5.js 2.0] IO refactoring #7365

Merged
merged 26 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8746f7f
Create new implementation of io loading function
limzykenneth Nov 6, 2024
d6839ee
Basic rewrite of http methods, still need to consider overloads
limzykenneth Nov 7, 2024
aad74a2
Rewrite loadXML
limzykenneth Nov 7, 2024
5d49207
Rewrite loadTable
limzykenneth Nov 7, 2024
b98fa40
Minor refactor. Callbacks now also acts as filter
limzykenneth Nov 10, 2024
bffbfa9
Quick fix to io test
limzykenneth Nov 10, 2024
e43f709
Simplify loadImage implementation
limzykenneth Nov 10, 2024
c391330
Add back success callback to loadImage
limzykenneth Nov 10, 2024
3ba0be0
Fix some io tests
limzykenneth Nov 11, 2024
718e463
Fix image loading test
limzykenneth Nov 11, 2024
ee0d558
Remove duplicate image loading test
limzykenneth Nov 11, 2024
6d9a0b3
Clean up and add back FES io messages
limzykenneth Nov 11, 2024
e625c7c
loadImage use unified request function
limzykenneth Nov 12, 2024
7f05bed
Promisify loadShader
limzykenneth Nov 13, 2024
316e67b
Fix loadModel tests
limzykenneth Nov 15, 2024
44f04cd
Fix most of file write tests
limzykenneth Nov 16, 2024
eb96987
Fix remaining test cases for file save
limzykenneth Nov 16, 2024
53350cd
Fix partial saveTable tests
limzykenneth Nov 16, 2024
f789d8c
Fix saveTable and save image tests
limzykenneth Nov 19, 2024
2750e61
Mouse events test breaking, ignoring for new implementation in #7378
limzykenneth Nov 19, 2024
7fe92ff
Remove testWithDownload helper in favor of vi.mock
limzykenneth Nov 19, 2024
55efc88
saveTable will need more detailed test in the future
limzykenneth Nov 19, 2024
29cf9da
Fix final cases for loadShader
limzykenneth Nov 19, 2024
55afdc5
Clean up
limzykenneth Nov 19, 2024
842c5ec
Ignore saveGif test as it needs refactoring
limzykenneth Nov 19, 2024
d71c498
Update documentation
limzykenneth Nov 20, 2024
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
430 changes: 219 additions & 211 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.7",
"@rollup/plugin-terser": "^0.4.4",
"@vitest/browser": "^2.0.4",
"@vitest/browser": "^2.1.5",
"all-contributors-cli": "^6.19.0",
"concurrently": "^8.2.2",
"connect-modrewrite": "^0.10.1",
Expand All @@ -48,14 +48,15 @@
"i18next": "^19.0.2",
"i18next-browser-languagedetector": "^4.0.1",
"lint-staged": "^15.1.0",
"msw": "^2.6.3",
"rollup": "^4.9.6",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-visualizer": "^5.12.0",
"typescript": "^5.5.4",
"unplugin-swc": "^1.4.2",
"vite": "^5.0.2",
"vite-plugin-string": "^1.2.2",
"vitest": "^2.0.4",
"vitest": "^2.1.5",
"webdriverio": "^9.0.7",
"zod": "^3.23.8"
},
Expand Down Expand Up @@ -83,5 +84,10 @@
"hooks": {
"pre-commit": "lint-staged"
}
},
"msw": {
"workerDirectory": [
"test"
]
}
}
1 change: 1 addition & 0 deletions preview/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import vitePluginString from 'vite-plugin-string';

export default defineConfig({
root: './',
appType: 'mpa',
plugins: [
vitePluginString({
include: [
Expand Down
2 changes: 0 additions & 2 deletions src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,6 @@ import rendering from './rendering';
import renderer from './p5.Renderer';
import renderer2D from './p5.Renderer2D';
import graphics from './p5.Graphics';
// import element from './p5.Element';

p5.registerAddon(transform);
p5.registerAddon(structure);
Expand All @@ -674,6 +673,5 @@ p5.registerAddon(rendering);
p5.registerAddon(renderer);
p5.registerAddon(renderer2D);
p5.registerAddon(graphics);
// p5.registerAddon(element);

export default p5;
30 changes: 27 additions & 3 deletions src/core/p5.Graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @for p5
*/

import p5 from './main';
// import p5 from './main';
import * as constants from './constants';
import primitives2D from '../shape/2d_primitives';
import attributes from '../shape/attributes';
Expand All @@ -15,6 +15,7 @@ import image from '../image/image';
import loadingDisplaying from '../image/loading_displaying';
import pixels from '../image/pixels';
import transform from './transform';
import { Framebuffer } from '../webgl/p5.Framebuffer';

import primitives3D from '../webgl/3d_primitives';
import light from '../webgl/light';
Expand All @@ -30,7 +31,7 @@ class Graphics {
this._pInst = pInst;
this._renderer = new renderers[r](this._pInst, w, h, false, canvas);

p5.prototype._initializeInstanceVariables.apply(this);
this._initializeInstanceVariables(this);

this._renderer._applyDefaults();
return this;
Expand Down Expand Up @@ -552,7 +553,7 @@ class Graphics {
* </div>
*/
createFramebuffer(options) {
return new p5.Framebuffer(this._renderer, options);
return new Framebuffer(this._renderer, options);
}

_assert3d(name) {
Expand All @@ -561,6 +562,29 @@ class Graphics {
`${name}() is only supported in WEBGL mode. If you'd like to use 3D graphics and WebGL, see https://p5js.org/examples/form-3d-primitives.html for more information.`
);
};

_initializeInstanceVariables() {
this._accessibleOutputs = {
text: false,
grid: false,
textLabel: false,
gridLabel: false
};

this._styles = [];

this._bezierDetail = 20;
this._curveDetail = 20;

this._colorMode = constants.RGB;
this._colorMaxes = {
rgb: [255, 255, 255, 255],
hsb: [360, 100, 100, 1],
hsl: [360, 100, 100, 1]
};

this._downKeys = {}; //Holds the key codes of currently pressed keys
}
};

function graphics(p5, fn){
Expand Down
11 changes: 7 additions & 4 deletions src/image/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* for drawing images to the main display canvas.
*/
import * as omggif from 'omggif';
import { Element } from '../dom/p5.Element';
import { Framebuffer } from '../webgl/p5.Framebuffer';

function image(p5, fn){
/**
Expand Down Expand Up @@ -278,10 +280,10 @@ function image(p5, fn){
if (args[0] instanceof HTMLCanvasElement) {
htmlCanvas = args[0];
args.shift();
} else if (args[0] instanceof p5.Element) {
} else if (args[0] instanceof Element) {
htmlCanvas = args[0].elt;
args.shift();
} else if (args[0] instanceof p5.Framebuffer) {
} else if (args[0] instanceof Framebuffer) {
const framebuffer = args[0];
temporaryGraphics = this.createGraphics(framebuffer.width,
framebuffer.height);
Expand Down Expand Up @@ -325,6 +327,7 @@ function image(p5, fn){
}

htmlCanvas.toBlob(blob => {
console.log("here");
fn.downloadFile(blob, filename, extension);
if(temporaryGraphics) temporaryGraphics.remove();
}, mimeType);
Expand Down Expand Up @@ -658,10 +661,10 @@ function image(p5, fn){
fn.saveFrames = function(fName, ext, _duration, _fps, callback) {
p5._validateParameters('saveFrames', arguments);
let duration = _duration || 3;
duration = fn.constrain(duration, 0, 15);
duration = Math.max(Math.min(duration, 15), 0);
duration = duration * 1000;
let fps = _fps || 15;
fps = fn.constrain(fps, 0, 22);
fps = Math.max(Math.min(fps, 22), 0);
let count = 0;

const makeFrame = fn._makeFrame;
Expand Down
Loading
Loading