-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
implementing beginContour and endContour in WEBGL mode #6042
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
implementing beginContour and endContour in WEBGL mode #6042
Conversation
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.
Thanks for your work on this so far! I've tried to explain a bit what further changes we'll have to do. Let me know if those make sense or if I can help explain anything some more!
@@ -101,7 +112,11 @@ p5.RendererGL.prototype.vertex = function(x, y) { | |||
v = arguments[4]; | |||
} | |||
const vert = new p5.Vector(x, y, z); | |||
this.immediateMode.geometry.vertices.push(vert); | |||
if (this.immediateMode.isContour) { | |||
this.immediateMode.geometry.contourVertices.push(vert); |
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.
Nice work, I think this is generally the right approach! The one difference is that we might have multiple beginContour
/endContour
calls within one shape. So we probably need contourVertices
to be an array of arrays in WebGL mode, instead of just a single array.
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.
Eventually, we'll need to pass all the contours into this array in _tesselateShape
here:
p5.js/src/webgl/p5.RendererGL.Immediate.js
Line 333 in 393ddbc
const contours = [ |
This probably means we'll need to store vertexNormals
, vertexColors
, vertexStrokeColors
, and uvs
for each contour as well as just the position.
p5.RendererGL.prototype.beginContour = function() { | ||
this.immediateMode.isContour = true; | ||
this.immediateMode.isFirstContour = true; | ||
this.immediateMode.geometry.contourVertices = []; |
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.
Do you think we can store this on this.immediateMode
instead of this.immediateMode.geometry
? We use the same geometry class for 3D models loaded with loadModel()
, which won't have this notion of contours, so this should probably just be internal to p5.RendererGL
.
if (shouldClose) { | ||
part.push([verts[j].length - 1, 0]); | ||
} | ||
res.push(part); |
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.
On the main branch, the expected output of this function is an array of [index1, index2]
tuples, basically saying "connect the vertex at geometry.vertices[index1]
with the vertex at geometry.vertices[index2]
with a line." This starts to get a little tricky now that not all the vertices are in the same geometry.vertices
array.
With your change, this now returns an array of arrays of those tuples. That could be helpful, since now we know that the first array element is the pairs for the main shape vertices, the second array element is the pairs for the first contour, the third array element is the pairs for the second contour, etc. It just means we'll have to update the _edgesToVertices
function, which takes this output and makes all the lines, to handle this new format.
e.g. over here, it directly accesses this.vertices[index]
. We'll have to update this to loop over each array of edges, and determine which set of vertices/vertex stroke colors it should be reading from:
p5.js/src/webgl/p5.Geometry.js
Line 281 in 393ddbc
const begin = this.vertices[currEdge[0]]; |
thanks @davepagurek these suggestions will be very helpful 😊 |
Hello @davepagurek sir, I have some questions can you please explain them, It would be beneficial to better my understanding.
|
|
Thanks for your initial work on this! With #6297 merged in, I'm going to close this draft as the initial feature is now implemented, but feel free to open new issues if you notice any bugs or have follow-up feature requests! |
Resolves #5946
Changes:
Added
beginContour()
andendContour()
in WEBGL renderer file and refactored some code for it.It is not complete yet I there are many bugs left to be solved, please suggest me if I am working in right direction or not ?
Progress:
Still working on it
Any guidance is really appreciated.
PR Checklist
npm run lint
passes