-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
textOutput() and gridOuput() are incomplete and inaccurate in WEBGL #6126
Comments
If anyone is interested in taking this on, the way I've calculated screen-space positions out of WebGL coordinates in the past is by doing this: // Assuming `this` is a `RendererGL`:
const toClipSpace = new DOMMatrixReadOnly(this.uPMatrix.mat4).multiply(
new DOMMatrixReadOnly(this.uMVMatrix.mat4)
);
const clip = toClipSpace.transformPoint(new DOMPoint(0,0,0));
const screenX = (clip.x / clip.w + 1) / 2 * this.width;
const screenY = (clip.y / clip.w + 1) / 2 * this.height; |
i would like to contribute |
Thanks @Gaurav-1306! I'll assign it to you. Let me know if I can help clarify anything! |
p5.js/src/accessibility/outputs.js Lines 544 to 550 in cea9e09
@davepagurek |
hey @davepagurek
i tried solving the problem using this, but i am unable to do it. can you help! |
That looks like a good start! It looks like the function currently returns some strings for the location: p5.js/src/accessibility/outputs.js Lines 553 to 559 in cea9e09
so maybe rather than returning an object with an x and y position, your code should be something like this, where both branches set //gets position of shape in the canvas
p5.prototype._getPos = function (x, y) {
const untransformedPosition = new DOMPointReadOnly(x, y);
+ let transformedX = 0;
+ let transformedY = 0;
if (this._renderer.isP3D) {
const toClipSpace = new DOMMatrixReadOnly(this._renderer.uPMatrix.mat4)
.multiply(
new DOMMatrixReadOnly(this.uMVMatrix.mat4)
);
const clip = toClipSpace.transformPoint(new DOMPoint(0, 0, 0));
- const transformedX = (clip.x / clip.w + 1) / 2 * this.width;
+ transformedX = (clip.x / clip.w + 1) / 2 * this.width;
- const transformedY = (clip.y / clip.w + 1) / 2 * this.height;
+ transformedY = (clip.y / clip.w + 1) / 2 * this.height;
- return { x: transformedX, y: transformedY };
} else {
const currentTransform = this.drawingContext.getTransform();
- const { x: transformedX, y: transformedY } = untransformedPosition
+ { x: transformedX, y: transformedY } = untransformedPosition
.matrixTransform(currentTransform);
console.log('the diff');
console.log(transformedX, transformedY); |
We can close this issue , |
The label now correctly describes the square's position as the bottom right! That's awesome! Unfortunately, the sphere is still not described, and now the label says that the square takes up 15625% of the canvas, whereas before it said 6%. |
Thank you for the update @calebfoss . We can Identify 2 issues here. Unreported shapes and inaccurate percentage. Please take a look at my code . It seems seems all 3D shapes are not reported by the function. function setup() {
createCanvas(400, 400, WEBGL);
textOutput(LABEL);
}
function draw() {
background(220);
sphere();
circle(50, 50, 100);
square(100, 100, 100);
} |
@Forchapeatl, exactly! 3D shape descriptions were never implemented. That's what I was referring to here:
In this accessibility features proposal, I go into more detail on the future of these functions. I'm glad you're looking into improving the accessibility features! |
Most appropriate sub-area of p5.js?
p5.js version
1.6.0
Web browser and version
No response
Operating System
No response
Steps to reproduce this
I first identified this issue in the discussion for PR #6122
When using WEBGL mode, textOutput() and gridOutput() only produce descriptions of 2D shapes, and the descriptions are inaccurate because they do not take into account the difference in origin point or the camera settings.
In the example below, the textOutput describes a square in the upper left corner (rather than lower right where it appears on the canvas) and does not include the sphere.
Live in p5 editor
I think producing accurate descriptions in WEBGL would be a big undertaking, and in the meantime, I think it would be best for textOuput() and gridOutput() to throw a friendly error when called in WEBGL mode. I'm happy to open a PR for this.
The text was updated successfully, but these errors were encountered: