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

[2.0 beta 1] textToModel adds extra face? #7474

Open
1 of 17 tasks
davepagurek opened this issue Jan 18, 2025 · 4 comments
Open
1 of 17 tasks

[2.0 beta 1] textToModel adds extra face? #7474

davepagurek opened this issue Jan 18, 2025 · 4 comments

Comments

@davepagurek
Copy link
Contributor

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

2.0 beta 1

Web browser and version

Firefox

Operating system

MacOS

Steps to reproduce this

I was testing out textToModel here, combining it with a shader to displace vertices: https://openprocessing.org/sketch/2513601

I notice that when the vertices get displaced, sometimes the fills go outside of the strokes in a straight line:

Image

It looks like there's an extra face here, or a face that hasn't been subdivided, so that when the endpoints move, it draws a straight line between them, rather than following the warped curve.

This has something to do with p5.Font.textToModel here probably:

const geom = this._pInst.buildGeometry(() => {

When drawing the front faces, I've called endContour(CLOSE), I wonder if the CLOSE is causing an extra face to be made?

@HarshitaKatariya
Copy link

I was looking into the issue related to textToModel and vertex displacement artifacts. The report mentions endContour(CLOSE), but I couldn't find any method in p5.js that accepts CLOSE as an argument.

Could you clarify if this is a mistake in the issue description, or if there's an undocumented feature related to endContour() that I'm missing?

@perminder-17
Copy link
Contributor

I was looking into the issue related to textToModel and vertex displacement artifacts. The report mentions endContour(CLOSE), but I couldn't find any method in p5.js that accepts CLOSE as an argument.

Could you clarify if this is a mistake in the issue description, or if there's an undocumented feature related to endContour() that I'm missing?

Hi @HarshitaKatariya, thanks for the concern. Actually I think we have CLOSE as an argument in endContour() method as you can see here.

endContour(closeMode = constants.OPEN, _index = this.contours.length - 1) {
const contour = this.at(_index);
if (closeMode === constants.CLOSE) {

I think you are correct, it's still undocumented I think.

@davepagurek
Copy link
Contributor Author

Right, @HarshitaKatariya endContour(CLOSE) is a new p5 2.0 feature that we'll be adding documentation for in the next month or two before we fully release 2.0.

More context: the problem

We've narrowed down the issue, and it's not because there are extra faces it turns out! It's that the default shape mode is actually removing vertices, when they lie on a straight line. So you can start with a contour that looks like the left, but ends up with the triangles on the right:

Image

This is OK in general, except that we're making the side faces, we're using QUAD_STRIP, which does not remove points, so the sides have higher detail than the fronts, which is noticeable when you then try to bend the points in a shader to make a curve, because the higher-subdivided one has the ability to bend while the unsubdivided one can't bend any more:

Image

Potential solutions

@perminder-17 was looking into whether mapbox's earcut has the same simplifying behaviour as our existing triangulator, libtess. It seems like it does unfortunately, but earcut seems to be generally faster anyway, so that change will be good regardless and gives us more wiggle room to address the duplication ourselves somehow.

The core issue is that points on the same line look like they can be simplified with no loss of detail. So maybe a solution here is to generate a new vertex property (see the custom vertex property section here: https://github.com/processing/p5.js/releases/tag/v2.0.0-beta.1), assign it random values per vertex so that these properties no longer can be simplified, and then delete it in the resulting geometry? (A quick way to check if it fixes this issue is to assign random texture coordinates in textToModel because we don't have any to begin with, e.g. vertex(x, y, z, Math.random(), Math.random()), and see if that fixes the sketch.)

Since we probably don't want an extra vertex property in general, we maybe also need to add a way to get/set this behaviour. Maybe we name it simplifyTriangles, defaulting to true, and you can call simplifyTriangles(false) to prevent it?

@davepagurek
Copy link
Contributor Author

Also, if the random texture coordinates thing works, feel free to make a PR for that right now, and we can make a new issue to address simplifyTriangles in general

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants