{"id":13600133,"url":"https://github.com/kovacsv/assimpjs","last_synced_at":"2025-04-07T10:27:11.222Z","repository":{"id":39867669,"uuid":"397842196","full_name":"kovacsv/assimpjs","owner":"kovacsv","description":"The emscripten interface for the assimp library that allows you to import 40+ 3D file formats in the browser.","archived":false,"fork":false,"pushed_at":"2024-04-01T17:44:35.000Z","size":15949,"stargazers_count":124,"open_issues_count":13,"forks_count":20,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-31T08:09:59.307Z","etag":null,"topics":["3d","assimp","import","webgl"],"latest_commit_sha":null,"homepage":"","language":"C++","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/kovacsv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":["kovacsv"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2021-08-19T06:36:45.000Z","updated_at":"2025-03-27T19:59:54.000Z","dependencies_parsed_at":"2024-01-14T04:41:18.377Z","dependency_job_id":"2b42f7d9-21b0-4bd1-a7fd-fe019b1dd3e7","html_url":"https://github.com/kovacsv/assimpjs","commit_stats":{"total_commits":152,"total_committers":2,"mean_commits":76.0,"dds":0.006578947368421018,"last_synced_commit":"733a2c6c251bc31aa6e407087d63a68994836f1d"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovacsv%2Fassimpjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovacsv%2Fassimpjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovacsv%2Fassimpjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovacsv%2Fassimpjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kovacsv","download_url":"https://codeload.github.com/kovacsv/assimpjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247634474,"owners_count":20970531,"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":["3d","assimp","import","webgl"],"created_at":"2024-08-01T18:00:28.342Z","updated_at":"2025-04-07T10:27:11.199Z","avatar_url":"https://github.com/kovacsv.png","language":"C++","funding_links":["https://github.com/sponsors/kovacsv"],"categories":["C++"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \n\u003cimg src=\"docs/images/assimpjs_logo_small.png?raw=true\"\u003e \u003cbr\u003e\n\n[Check out the live demo here!](http://kovacsv.github.io/assimpjs)\n\n[![npm version](https://badge.fury.io/js/assimpjs.svg)](https://badge.fury.io/js/assimpjs)\n[![Native Build](https://github.com/kovacsv/assimpjs/actions/workflows/native_build.yml/badge.svg)](https://github.com/kovacsv/assimpjs/actions/workflows/native_build.yml)\n[![WASM Build](https://github.com/kovacsv/assimpjs/actions/workflows/wasm_build.yml/badge.svg)](https://github.com/kovacsv/assimpjs/actions/workflows/wasm_build.yml)\n    \n\u003c/div\u003e\n\n# assimpjs\n\nThe [emscripten](https://emscripten.org) interface for the [assimp](https://github.com/assimp/assimp) library. It runs entirely in the browser, and allows you to import 40+ 3D file formats and access the result in JSON or glTF format. This is not a full port of assimp, but an easy to use interface to access it's functionality.\n\n## How to install?\n\nYou can get assimpjs from [npm](https://www.npmjs.com/package/assimpjs):\n\n```\nnpm install assimpjs\n```\n\n## How to use?\n\nThe library runs in the browser and as a node.js module as well.\n\nYou will need two files from the `dist` folder: `assimpjs.js` and `assimpjs.wasm`. The wasm file is loaded runtime by the js file.\n\nGiven that browsers don't access the file system, you should provide all the files needed for import. Some 3D formats are coming in multiple files, so you should list all of them to import the model properly.\n\nYou should provide two things for every file:\n- **name:** The name of the file. It's used if files are referring to each other.\n- **content:** The content of the file as an `Uint8Array` object.\n\nThe supported target formats are: `assjson`, `gltf`, `gltf2`, `glb`, and `glb2`. The number of result files depends on the format.\n\n### Use from the browser\n\nFirst, include the `assimpjs.js` file in your website.\n\n```html\n\u003cscript type=\"text/javascript\" src=\"assimpjs.js\"\u003e\u003c/script\u003e\n```\n\nAfter that, download the model files, and pass them to assimpjs.\n\n```js\nassimpjs ().then (function (ajs) {\n    // fetch the files to import\n    let files = [\n        'testfiles/cube_with_materials.obj',\n        'testfiles/cube_with_materials.mtl'\n    ];\n    Promise.all (files.map ((file) =\u003e fetch (file))).then ((responses) =\u003e {\n        return Promise.all (responses.map ((res) =\u003e res.arrayBuffer ()));\n    }).then ((arrayBuffers) =\u003e {\n        // create new file list object, and add the files\n        let fileList = new ajs.FileList ();\n        for (let i = 0; i \u003c files.length; i++) {\n            fileList.AddFile (files[i], new Uint8Array (arrayBuffers[i]));\n        }\n        \n        // convert file list to assimp json\n        let result = ajs.ConvertFileList (fileList, 'assjson');\n        \n        // check if the conversion succeeded\n        if (!result.IsSuccess () || result.FileCount () == 0) {\n            resultDiv.innerHTML = result.GetErrorCode ();\n            return;\n        }\n\n        // get the result file, and convert to string\n        let resultFile = result.GetFile (0);\n        let jsonContent = new TextDecoder ().decode (resultFile.GetContent ());\n\n        // parse the result json\n        let resultJson = JSON.parse (jsonContent);\n        \n        resultDiv.innerHTML = JSON.stringify (resultJson, null, 4);\n    });\n});\n```\n\n### Use as a node.js module\n\nYou should require the `assimpjs` module in your script. In node.js you can use the file system module to get the buffer of each file.\n\n```js\nlet fs = require ('fs');\nconst assimpjs = require ('assimpjs')();\n\nassimpjs.then ((ajs) =\u003e {\n    // create new file list object\n    let fileList = new ajs.FileList ();\n    \n    // add model files\n    fileList.AddFile (\n        'cube_with_materials.obj',\n        fs.readFileSync ('testfiles/cube_with_materials.obj')\n    );\n    fileList.AddFile (\n        'cube_with_materials.mtl',\n        fs.readFileSync ('testfiles/cube_with_materials.mtl')\n    );\n    \n    // convert file list to assimp json\n    let result = ajs.ConvertFileList (fileList, 'assjson');\n\n    // check if the conversion succeeded\n    if (!result.IsSuccess () || result.FileCount () == 0) {\n        console.log (result.GetErrorCode ());\n        return;\n    }\n\n    // get the result file, and convert to string\n    let resultFile = result.GetFile (0);\n    let jsonContent = new TextDecoder ().decode (resultFile.GetContent ());\n\n    // parse the result json\n    let resultJson = JSON.parse (jsonContent);\n});\n```\n\nIt's also possible to delay load the required files so they have to be loaded only when the importer needs them. In this case you have to provide only the name and content of the main file, and implement callbacks to provide additional files.\n\n```js\nlet fs = require ('fs');\nconst assimpjs = require ('assimpjs')();\n\nassimpjs.then ((ajs) =\u003e {\n    // convert model\n    let result = ajs.ConvertFile (\n        // file name\n        'cube_with_materials.obj',\n        // file format\n        'assjson',\n        // file content as arraybuffer\n        fs.readFileSync ('testfiles/cube_with_materials.obj'),\n        // check if file exists by name\n        function (fileName) {\n            return fs.existsSync ('testfiles/' + fileName);\n        },\n        // get file content as arraybuffer by name\n        function (fileName) {\n            return fs.readFileSync ('testfiles/' + fileName);\n        }\n    );\n    \n    // check if the conversion succeeded\n    if (!result.IsSuccess () || result.FileCount () == 0) {\n        console.log (result.GetErrorCode ());\n        return;\n    }\n\n    // get the result file, and convert to string\n    let resultFile = result.GetFile (0);\n    let jsonContent = new TextDecoder ().decode (resultFile.GetContent ());\n\n    // parse the result json\n    let resultJson = JSON.parse (jsonContent);\n});\n```\n\n## How to build on Windows?\n\nA set of batch scripts are prepared for building on Windows.\n\n### 1. Install Prerequisites\n\nInstall [CMake](https://cmake.org) (3.6 minimum version is needed). Make sure that the cmake executable is in the PATH.\n\n### 2. Install Emscripten SDK\n\nRun the Emscripten setup script.\n\n```\ntools\\setup_emscripten_win.bat\n```\n\n### 3. Compile the WASM library\n\nRun the release build script.\n\n```\ntools\\build_wasm_win_release.bat\n```\n\n### 4. Build the native project (optional)\n\nIf you want to debug the code, it's useful to build a native project. To do that, just use cmake to generate the project of your choice.\n\n## How to run locally?\n\nTo run the demo and the examples locally, you have to start a web server. Run `npm install` from the root directory, then run `npm start` and visit `http://localhost:8080`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkovacsv%2Fassimpjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkovacsv%2Fassimpjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkovacsv%2Fassimpjs/lists"}