Skip to content

created indices are wrong #13

Closed
Closed

Description

@Kosta-Github

@mourner In the README.md it is stated about the creation of indices:

  • Alternatively, you can get triangulation results in the form of flat index and vertex arrays by passing true as a second argument to earcut (convenient for uploading results directly to WebGL as buffers):
    var triangles = earcut([[[10,0],[0,50],[60,60],[70,10]]], true);
    // {vertices: [0,50, 10,0, 70,10, 60,60], indices: [1,0,2, 3,2,1]}

But the current implementation creates indices which are a multiple of the passed-in dimension. For the given 2D case it produces something like this: [2,0,4, 6,4,2]. And passing in 3D coords like this [[[10,0,0],[0,50,0],[60,60,0],[70,10,0]]] it produces something like this: [3,0,6, 9,6,3].

Is this a bug in the description or a bug in the implementation? If you want to be able to upload the produced indices directly into a WebGL index buffer, the implementation needs to be changed to follow the description given above. Right now, I need to divide each generated index by 2 or 3 (depending on the passed-in dimensionality of the passed-in vertices).

Activity

  1. mourner commented on Mar 9, 2015

    @mourner
    Member

    Sounds right! I didn't actually test out the indexed output in GL so missed this point. Thanks for the report! Should be fixed on the implementation side.

  2. added a commit that references this issue on Mar 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions