{"id":14981254,"url":"https://github.com/stevinz/three-subdivide","last_synced_at":"2025-04-13T09:43:18.571Z","repository":{"id":45748554,"uuid":"514072249","full_name":"stevinz/three-subdivide","owner":"stevinz","description":"Smooth subdivision surface modifier for use with three.js BufferGeometry.","archived":false,"fork":false,"pushed_at":"2023-08-03T22:40:21.000Z","size":1710,"stargazers_count":95,"open_issues_count":1,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T01:11:17.672Z","etag":null,"topics":["buffergeometry","loop-subdivision","modifier","subdivision","subdivision-surface","three-js","threejs","triangle","webgl"],"latest_commit_sha":null,"homepage":"https://stevinz.github.io/three-subdivide","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/stevinz.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-14T23:11:33.000Z","updated_at":"2025-03-26T02:06:27.000Z","dependencies_parsed_at":"2024-06-18T21:25:39.770Z","dependency_job_id":"82da1d95-77f8-4122-a3f9-1bcc6565d693","html_url":"https://github.com/stevinz/three-subdivide","commit_stats":{"total_commits":81,"total_committers":3,"mean_commits":27.0,"dds":0.04938271604938271,"last_synced_commit":"c9aea3441f498f195eea853d1c23cc37ea74ea6e"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevinz%2Fthree-subdivide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevinz%2Fthree-subdivide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevinz%2Fthree-subdivide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevinz%2Fthree-subdivide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevinz","download_url":"https://codeload.github.com/stevinz/three-subdivide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248693906,"owners_count":21146885,"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":["buffergeometry","loop-subdivision","modifier","subdivision","subdivision-surface","three-js","threejs","triangle","webgl"],"created_at":"2024-09-24T14:03:12.877Z","updated_at":"2025-04-13T09:43:18.546Z","avatar_url":"https://github.com/stevinz.png","language":"JavaScript","readme":"# Three Subdivide\n\nThis modifier uses the [Loop](https://en.wikipedia.org/wiki/Loop_subdivision_surface) (Charles Loop, 1987) subdivision surface algorithm to smooth modern three.js [BufferGeometry](https://threejs.org/docs/?q=geometry#api/en/core/BufferGeometry).\n\n## Examples\n\n- \u003ca href='https://stevinz.github.io/three-subdivide/LoopSubdivision.html'\u003eThree.js Built-In Geometries\u003c/a\u003e\n\n- \u003ca href='https://stevinz.github.io/three-subdivide/MorphTargets.html'\u003eMorph Target Animation\u003c/a\u003e\n\n## Screenshot\n\n\u003cp align=\"center\"\u003e\u003cimg width='400' src='example/textures/subdivded.jpg' alt='Loop Subdivision Demo' /\u003e\u003c/p\u003e\n\n## Background\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;At one point, [three.js](https://threejs.org/) included a subdivision surface modifier in the extended examples, it was removed in r125. This modifier was originally based on the [Catmull-Clark](https://en.wikipedia.org/wiki/Catmull%E2%80%93Clark_subdivision_surface) algorithm, which works best for geometry with convex coplanar n-gon faces. In three.js r60 the modifier was changed to use the Loop algorithm, which was designed to work better with triangle based meshes.\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;The Loop algorithm, however, doesn't always provide uniform results as the vertices are skewed toward the most used vertex positions. A triangle box (like `BoxGeometry` for example) will favor some corners more than others. To alleviate this issue, this implementation includes an initial pass to split coplanar faces at their shared edges. It starts by splitting along the longest shared edge first, and then from that midpoint it splits to any remaining coplanar shared edges. This can be disabled by passing 'split' as false.\n\u003c/div\u003e\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;Also by default, this implementation inserts new UV coordinates, but does not average them using the Loop algorithm. In some cases (often in flat geometries) this will produce undesired results, a noticeable tearing will occur. In such cases, try passing 'uvSmooth' as true to enable UV averaging.\n\n## Install\n\n- Option 1: Copy file `LoopSubdivision.js`, import from file...\n\n```javascript\nimport { LoopSubdivision } from 'LoopSubdivision.js';\n```\n\n- Option 2: Install from [npm](https://www.npmjs.com/package/three-subdivide), import from 'three-subdivide'...\n```\nnpm install three-subdivide\n```\n```javascript\nimport { LoopSubdivision } from 'three-subdivide';\n```\n\n- Option 3: Import directly from CDN...\n```javascript\nimport { LoopSubdivision } from 'https://unpkg.com/three-subdivide/build/index.module.js';\n```\n\n## Usage\n\nTo create subdivided geometry, use the static function `modify()`. The following code creates a cube with smoothed geometry and adds it to a three.js `Scene`.\n\n```javascript\nimport * as THREE from 'three';\nimport { LoopSubdivision } from 'LoopSubdivision.js';\n\nconst iterations = 1;\n\nconst params = {\n    split:          true,       // optional, default: true\n    uvSmooth:       false,      // optional, default: false\n    preserveEdges:  false,      // optional, default: false\n    flatOnly:       false,      // optional, default: false\n    maxTriangles:   Infinity,   // optional, default: Infinity\n};\n\nconst geometry = LoopSubdivision.modify(new THREE.BoxGeometry(), iterations, params);\n\nconst material = new THREE.MeshNormalMaterial();\nconst mesh = new THREE.Mesh(geometry, material);\n\nconst scene = new THREE.Scene();\nscene.add(mesh);\n```\n\n## Modify\n\nLoopSubdivision.modify(bufferGeometry, iterations = 1, params = {}) {\n\n- [bufferGeometry]() : BufferGeometry - existing three.js BufferGeometry object to be subdivided\n- [iterations]() : Int (optional) - total passes of subdivision to apply, generally between 1 to 5\n- [params]() : Object (optional) - optional parameters object, see below\n\nParameters Object ('params')\n\n- [split]() : Boolean (optional) - split coplanar faces at their shared edges before subdividing?\n- [uvSmooth]() : Boolean (optional) - smooth UV coordinates during subdivision?\n- [preserveEdges]() Boolean (optional) - should edges / breaks in geometry be ignored during subdivision?\n- [flatOnly]() : Boolean (optioanl) - subdivide triangles but do not apply smoothing?\n- [maxTriangles]() : Number (optional) - limits subdivision to meshes with less than this number of triangles\n\n\u003e NOTE: This modifier converts geometry to non-indexed before the subdivision algorithm is applied. If desired, you can use [BufferGeometryUtils.mergeVertices](https://threejs.org/docs/?q=buffer#examples/en/utils/BufferGeometryUtils.mergeVertices) to re-index geometry.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevinz%2Fthree-subdivide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevinz%2Fthree-subdivide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevinz%2Fthree-subdivide/lists"}