0.1.1 • Published 9 years ago

ldraw v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

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

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.0-beta.5

3 years ago

1.0.0-beta.4

3 years ago

1.0.0-beta.3

3 years ago

1.0.0-beta.2

3 years ago

1.0.0-beta.1

3 years ago

1.0.0-beta.0

3 years ago

0.1.1

9 years ago

0.1.0

9 years ago