-
-
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
Support for 3D coordinate on Image #7172
base: main
Are you sure you want to change the base?
Changes from 2 commits
4326a02
97efe53
c2d6142
168e0e3
aab2120
7942b73
2a80879
96997fd
ca19e53
1c76a8d
6e31086
247e855
8d81b73
7ae6f8b
ab32870
ed1796a
e764cb1
038a5ad
71027b0
07beef9
1b53827
af0b2e8
9e19785
80844dc
15d0015
f0f57cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2391,6 +2391,24 @@ p5.RendererGL = class RendererGL extends p5.Renderer { | |
|
||
return triangleVerts; | ||
} | ||
|
||
image3D(img,sx,sy,sz,sWidth,sHeight,dx,dy,dWidth,dHeight) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shares a lot of code with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code uses |
||
if (this._isErasing) { | ||
this.blendMode(this._cachedBlendMode); | ||
} | ||
|
||
this._pInst.push(); | ||
this._pInst.translate(sx, sy, sz); | ||
this._pInst.texture(img); | ||
this._pInst.noStroke(); | ||
this._pInst.plane(sWidth, sHeight); | ||
this._pInst.pop(); | ||
|
||
if (this._isErasing) { | ||
this.blendMode(constants.REMOVE); | ||
} | ||
} | ||
|
||
}; | ||
/** | ||
* ensures that p5 is using a 3d renderer. throws an error if not. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think placing this argument here will break calls to
image()
that don't usez
but do use the arguments that follow it.I think we might need to follow the approach of some other 2D/3D functions like
dist
here, where we reinterpret the arguments array based on some criteria:p5.js/src/math/calculation.js
Lines 221 to 227 in 21d7c8c
In this case, the criteria will probably depend on the length of the arguments.
Since this is somewhat complex, I think it would also be a good idea to add some unit tests to make sure that this continues to work for the 2D case as well as the new 3D case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review. I went with the length approach initially .
Odd number of parameters → Use 2D mode.
Even number of parameters → Check if the 10th parameter is a number.
If it's not a number, defer to 2D mode.
If it's a number, use 3D mode.
but starting from the third parameter single arguments become optional
image(img, dx, dy, dWidth, dHeight, sx, sy, [sWidth], [sHeight], [fit], [xAlign], [yAlign])
hence my even/odd length logic fails as soon as the function starts receiving optional arguments.The best solution I got at the moment was, to shift the values of the input argument to the right in case of 2D_rendering.
The results have been successful in every test .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also work for 3D mode if the z coordinate is omitted?
Also a possible other approach for the even/odd check: you might need to check if the number of arguments up to the
fit
parameter (which should be a string instead of a number) is even or odd. That might mean something like:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are in WebGL mode and call
image
withoutz
but with some of the options afterz
, does that still work? e.g. this should draw the image fullscreen on the canvas:Just based on the code so far, it looks like in WebGL mode, it never shifts all the arguments over the way it does when
this._renderer instanceof p5.RendererGL === false
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the
ImgeMode(CENTER)
is a trap on WebGL mode. Is there any way to workaround this ? we could add a newimageModeGL
that supportsWebGL
coordinates ?