ldraw v0.1.1
ldraw
The library will load and parse LDraw files.
yarn add ldraw
# or
npm install ldraw
This library does not need a special server. It just needs http access to LDraw files to download. If the files are not served from the same domain, the server hosting LDraw files needs to enable CORS access.
curl -O http://www.ldraw.org/library/updates/complete.zip && unzip complete.zip && rm complete.zip
npx http-server example --cors
open http://127.0.0.1:8080
ESM
import { LDraw } from 'ldraw';
import { FileLoader } from 'ldraw/lib/loaders';
CommonJS
const { LDraw } = require('ldraw');
const { FileLoader } = require('ldraw/lib/loaders');
Usage
Browser
import { LDraw } from 'ldraw';
async function main() {
const ldraw = new LDraw();
const part = await ldraw.find('3001.dat')
console.log(part);
}
main();
Node
import { LDraw } from 'ldraw';
import { FileLoader } from 'ldraw/lib/loaders';
async function main() {
const ldraw = new LDraw({ loaders: [FileLoader('/opt/ldraw')] });
const part = await ldraw.load('parts/3001.dat')
console.log(part);
}
main();
import { LDraw } from 'ldraw';
import { FileLoader, UrlLoader } from 'ldraw/lib/loaders';
async function main() {
const ldraw = new LDraw({
loaders: [
FileLoader('/opt/ldraw'),
UrlLoader('/ldraw')
]
});
const part = await ldraw.load('parts/3001.dat');
console.log(part);
}
main();
Loaders
UrlLoader
By default, the ldraw library looks in /parts, /p, /models folder of a default LDraw directory. When accessing these through a browser, in the console logs you will see a lot of failed attempts. The reason this is happening is that when a file references a part, it uses a relative filename
FileLoader
To configure LDraw to look at a file system, you need to use the FileLoader
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
9 years ago
9 years ago