├── README.md ├── package.json ├── repair-obj.js └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # repair-obj 2 | Fixes holes and other broken stuff in an OBJ file 3 | 4 | ### Install 5 | 6 | ``` 7 | npm i repair-obj 8 | ``` 9 | 10 | ### Usage 11 | 12 | ``` 13 | repair-obj < mymesh.obj > fixed.obj 14 | ``` 15 | 16 | # License 17 | (c) 2017 Mikola Lysenko. MIT License 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "repair-obj", 3 | "version": "1.0.0", 4 | "description": "Fixes holes and other broken stuff in an OBJ file", 5 | "main": "repair-obj.js", 6 | "bin": { 7 | "repair-obj": "repair-obj.js" 8 | }, 9 | "dependencies": { 10 | "mesh-fixer": "^1.0.2" 11 | }, 12 | "devDependencies": {}, 13 | "scripts": { 14 | "test": "echo \"Error: no test specified\" && exit 1" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/mikolalysenko/mesh-fixer-cli.git" 19 | }, 20 | "author": "Mikola Lysenko", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/mikolalysenko/mesh-fixer-cli/issues" 24 | }, 25 | "homepage": "https://github.com/mikolalysenko/mesh-fixer-cli#readme" 26 | } 27 | -------------------------------------------------------------------------------- /repair-obj.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var repairMesh = require('mesh-fixer') 4 | 5 | var str = [] 6 | process.stdin 7 | .setEncoding('utf-8') 8 | .on('readable', function () { 9 | var chunk = process.stdin.read() 10 | if (chunk) { 11 | str.push(chunk) 12 | } 13 | }) 14 | .on('end', function () { 15 | var verts = [] 16 | var faces = [] 17 | 18 | str.join('').split('\n').forEach(function (line) { 19 | var toks = line.split(/\s+/) 20 | if (toks[0] === 'v') { 21 | verts.push(toks.slice(1).map((x) => +x)) 22 | } else if (toks[0] === 'f') { 23 | faces.push(toks.slice(1).map((x) => (x - 1) | 0)) 24 | } 25 | }) 26 | 27 | var repaired = repairMesh(faces, verts) 28 | 29 | repaired.positions.forEach((p) => { 30 | console.log('v', p[0], p[1], p[2]) 31 | }) 32 | 33 | repaired.cells.forEach((c) => { 34 | console.log('f', c[0] + 1, c[1] + 1, c[2] + 1) 35 | }) 36 | }) 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2013 Mikola Lysenko 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | --------------------------------------------------------------------------------