{"id":15497203,"url":"https://github.com/jwerle/regl-model","last_synced_at":"2025-06-12T15:06:10.607Z","repository":{"id":57352529,"uuid":"69819332","full_name":"jwerle/regl-model","owner":"jwerle","description":"Generate a model matrix from position, scale, and rotation vectors. ","archived":false,"fork":false,"pushed_at":"2016-10-03T21:24:53.000Z","size":240,"stargazers_count":11,"open_issues_count":0,"forks_count":5,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-22T21:47:50.400Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://jwerle.github.io/regl-model/example/","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/jwerle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-02T20:10:33.000Z","updated_at":"2021-02-17T16:19:49.000Z","dependencies_parsed_at":"2022-09-16T08:00:36.323Z","dependency_job_id":null,"html_url":"https://github.com/jwerle/regl-model","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jwerle/regl-model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fregl-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fregl-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fregl-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fregl-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwerle","download_url":"https://codeload.github.com/jwerle/regl-model/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fregl-model/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259490506,"owners_count":22865763,"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-10-02T08:31:44.146Z","updated_at":"2025-06-12T15:06:10.563Z","avatar_url":"https://github.com/jwerle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"regl-model\n==========\n\nGenerate a model matrix from position, scale, and rotation vectors.\nThis module will generate a regl command that will provide a\n`uniform mat4 model` derived from input variables. The command will also\nexpose context variables\n\n## Installation\n\n```sh\n$ npm install regl-model --save\n```\n\nSee [demo here](https://jwerle.github.io/regl-model/example/)\n\n## [Example](http://requirebin.com/?gist=6b1bdf08f01a8cc0fe77ffba0324da18)\n\n```js\nconst quat = require('gl-quat')\nconst regl = require('regl')()\nconst model = require('regl-model')(regl)\nconst bunny = require('regl-primitive')(regl, require('bunny'))\nconst camera = require('regl-camera')(regl, {distance: 40})\nconst material = regl({\n  vert: `\n  precision mediump float;\n  attribute vec3 position, normal;\n  uniform mat4 projection, model, view;\n  varying vec3 vnormal;\n  void main () {\n    vnormal = normal;\n    gl_Position = projection * view * model * vec4(position, 1.0);\n  }\n  `,\n\n  frag: `\n  precision mediump float;\n  varying vec3 vnormal;\n  void main () {\n    gl_FragColor = vec4(abs(vnormal), 1.0);\n  }\n  `,\n})\n\nconst rotation = [0, 0, 0, 1]\nregl.frame(({time}) =\u003e {\n  regl.clear({color: [0, 0, 0, 1], depth: true})\n  quat.identity(rotation)\n  quat.rotateX(rotation, rotation, 0.8*time)\n  quat.rotateY(rotation, rotation, 0.8*time)\n  camera(() =\u003e {\n    model({rotation}, () =\u003e {\n      material(() =\u003e {\n        bunny()\n      })\n    })\n  })\n})\n\n```\n\n## API\n\n### Constructor\n\n#### `const model = require('regl-model)(regl[, initialState])`\n\nwhere `regl-model` expects the following arguments:\n\n* `regl` - A handle to a regl instance\n* `initialState` - Initial model state\n\nwhere `initialState` can contain one of the following properties:\n\n* `position` - Initial position vector (default: `[0, 0, 0]`)\n* `scale` - Initial scale vector (default: `[1, 1, 1]`)\n* `rotation` - Initial rotation quaternion (default: `[0, 0, 0, 1]`)\n\nand `model` is now a function that accepts the same input as the\n`initialState` object.\n\n\n#### Usage\n\n```js\nregl.frame(() =\u003e {\n  model({rotation, position, scale}, ({transform}) =\u003e {\n    drawCommand()\n  })\n})\n```\n\n#### Input\n\nThe `model` function accepts following context variables:\n\n* `transform` - Parent model transform that will be applied to model\n  matrix\n* `rotation` - Rotation quaternion\n* `position` - Position vector\n* `scale` - Scale vector\n\n#### Context\n\nThe `model` function will expose the following context variables:\n\n* `transform` - Local model transform that can be used as input to\n  another `regl-model` command\n* `rotation` - Rotation quaternion applied to model matrix\n* `position` - Position vector applied to model matrix\n* `scale` - Scale vector applied to model matrix\n\n## License\n\nAPI\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fregl-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwerle%2Fregl-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fregl-model/lists"}