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

Expose PolygonOffsetRadius attribute to render irregular polygons #60

Open
jimbojw opened this issue Sep 27, 2022 · 0 comments
Open

Expose PolygonOffsetRadius attribute to render irregular polygons #60

jimbojw opened this issue Sep 27, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@jimbojw
Copy link
Collaborator

jimbojw commented Sep 27, 2022

Currently, the Sides sprite attribute allows the API user to render regular polygons. In addition, API users should be able to render irregular polygons.

The fragment shader used for drawing already supports offset radii in the getDistPolygon() method. See scene-fragment-shader.ts

Design question: Should the number of radius components always be 4? Should this be configurable? Under what circumstances would a different number be beneficial?

API Proposal:

  /**
   * Offset radii for irregular polygon rendering. Default value of 0
   * means not indented at all (point is on a unit circle). A value of
   * 1 would place the point at the center of the shape. A value of -1
   * would place the point at a distance of 2 from the center.
   * 
   * If a polygon has more than 4 points, the offset radii are used
   * again in a repeating fashion.
   */
  {
    attributeName: 'PolygonOffsetRadius',
    isBroadcastable: true,
    isInterpolable: true,
    components: ['A', 'B', 'C', 'D'],
  },

Example:

const sprite = scene.createSprite();
sprite.enter(s => {
  // A 5-pointed star is a 10-sided polygon.
  s.Sides = 10;

  // Where every other point is indented half way.
  s.PolygonOffsetRadius = [0, .5, 0, .5];
});

Implementation note: Consider the effect of negative values on the need to shift vertex coordinates outwards. Points further away demand extra space in the bounding box to ensure that the full shape is rendered. Make sure that both the rendering shaders and the hit test shader take this into account.

@jimbojw jimbojw added the enhancement New feature or request label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant