{"id":20778023,"url":"https://github.com/stackgl/gl-geometry","last_synced_at":"2025-04-30T18:40:49.370Z","repository":{"id":17580793,"uuid":"20384281","full_name":"stackgl/gl-geometry","owner":"stackgl","description":"A flexible wrapper for gl-vao and gl-buffer that you can use to set up renderable WebGL geometries from a variety of different formats.","archived":false,"fork":false,"pushed_at":"2019-06-20T14:08:40.000Z","size":162,"stargazers_count":50,"open_issues_count":3,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-16T04:20:38.422Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stackgl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-01T19:18:01.000Z","updated_at":"2024-11-28T15:26:53.000Z","dependencies_parsed_at":"2022-09-23T22:01:19.526Z","dependency_job_id":null,"html_url":"https://github.com/stackgl/gl-geometry","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fgl-geometry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fgl-geometry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fgl-geometry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackgl%2Fgl-geometry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackgl","download_url":"https://codeload.github.com/stackgl/gl-geometry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251764392,"owners_count":21640054,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T13:18:41.741Z","updated_at":"2025-04-30T18:40:49.300Z","avatar_url":"https://github.com/stackgl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gl-geometry [![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)\n\nA flexible wrapper for [gl-vao](http://github.com/stackgl/gl-vao)\nand [gl-buffer](http://github.com/stackgl/gl-buffer) that you can use to\nset up renderable WebGL geometries from a variety of different formats.\n\n## Usage ##\n\n[![NPM](https://nodei.co/npm/gl-geometry.png)](https://nodei.co/npm/gl-geometry/)\n\n### geom = createGeometry(gl) ###\n\nCreates a new geometry attached to the WebGL canvas context `gl`.\n\n### geom.attr(name, values[, opt]) ###\n\nDefine or update an attribute value, for example using a simplicial complex:\n\n``` javascript\nvar createGeometry = require('gl-geometry')\nvar bunny = require('bunny')\n\nvar geom = createGeometry(gl)\n  .attr('positions', bunny)\n```\n\nThe following vertex formats are supported and will be normalized:\n\n* Arrays of arrays, e.g. `[[0, 0, 0], [1, 0, 0], [1, 1, 0]]`.\n\n* Flat arrays, e.g. `[0, 0, 0, 1, 0, 0, 1, 1, 0]`.\n\n* [Typed arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays),\n  preferably a `Float32Array`.\n\n* 1-dimensional [ndarrays](https://github.com/scijs/ndarray).\n\n* [simplicial complexes](https://github.com/mikolalysenko/simplicial-complex),\n  i.e. an object with a `positions` array and a `cells` array. The former is\n  a list of unique vertices in the mesh (if you've used three.js, think\n  `THREE.Vector3`), and the latter is an index mapping these vertices to faces\n  (`THREE.Face3`) in the mesh. It looks something like this:\n\n  ``` json\n  {\n    \"positions\": [\n      [0.0, 0.0, 0.0],\n      [1.5, 0.0, 0.0],\n      [1.5, 1.5, 0.0],\n      [0.0, 1.5, 0.0]\n    ],\n    \"cells\": [\n      [0, 1, 2],\n      [1, 2, 3]\n    ]\n  }\n  ```\n\nYou can specify `opt.size` for the vertex size, defaults to 3.\n\nYou can update attribute values by calling `attr` again with the same `name`:\n\n* By default the entire contents of the associated `gl-buffer` are replaced by\n`data`; the buffer will be resized accordingly.\n\n* Alternatively, you can pass `opt.offset` to copy `data` into the current\nbuffer at a specific offset (in bytes). In this case, the buffer cannot be\nresized.\n\n### geom.faces(values[, opt]) ###\n\nPass a simplicial complex's `cells` property here in any of the above formats\nto use it as your index when drawing the geometry. For example:\n\n``` javascript\nvar createGeometry = require('gl-geometry')\nvar bunny = require('bunny')\n\nbunny.normals = normals.vertexNormals(\n    bunny.cells\n  , bunny.positions\n)\n\nvar geom = createGeometry(gl)\n  .attr('positions', bunny.positions)\n  .attr('normals', bunny.normals)\n  .faces(bunny.cells)\n```\n\nYou can specify `opt.size` for the cell size, defaults to 3.\n\n### geom.bind([shader]) ###\n\nBinds the underlying [VAO](https://github.com/stackgl/gl-vao) – this must\nbe called before calling `geom.draw`. Optionally, you can pass in a\n[gl-shader](http://github.com/stackgl/gl-shader) to\nautomatically set up your attribute locations for you.\n\n### geom.draw(mode, start, stop) ###\n\nDraws the geometry to the screen using the currently bound shader.\n\nOptionally, you can pass in the drawing mode, which should be one of the\nfollowing:\n\n* `gl.POINTS`\n* `gl.LINES`\n* `gl.LINE_STRIP`\n* `gl.LINE_LOOP`\n* `gl.TRIANGLES`\n* `gl.TRIANGLE_STRIP`\n* `gl.TRIANGLE_FAN`\n\nThe default value is `gl.TRIANGLES`. You're also able to pass in a `start` and\n`stop` range for the points you want to render, just the same as you would\nwith `gl.drawArrays` or `gl.drawElements`.\n\n### geom.unbind() ###\n\nUnbinds the underlying VAO. This *must* be done when you're finished drawing,\nunless you're binding to another gl-geometry or gl-vao instance.\n\n### geom.dispose() ###\n\nDisposes the underlying element and array buffers, as well as the VAO.\n\n## See Also\n\n* [ArrayBuffer and Typed Arrays](https://www.khronos.org/registry/webgl/specs/1.0/#5.13)\n* [The WebGL Context](https://www.khronos.org/registry/webgl/specs/1.0/#5.14)\n* [simplicial-complex](http://github.com/mikolalysenko/simplicial-complex)\n* [ndarray](https://github.com/scijs/ndarray)\n* [gl-shader](https://github.com/stackgl/gl-shader)\n* [gl-buffer](https://github.com/stackgl/gl-buffer)\n* [gl-vao](https://github.com/stackgl/gl-vao)\n\n## License\n\nMIT. See [LICENSE.md](http://github.com/hughsk/is-typedarray/blob/master/LICENSE.md) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackgl%2Fgl-geometry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackgl%2Fgl-geometry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackgl%2Fgl-geometry/lists"}