Skip to content

SolalDR/loader

Repository files navigation

loader

build version

Description

A library to handle assets loading.

Installation

npm i @solaldr/loader

How to use

Basic use

import AssetsLoader from '@solaldr/loader'
import { ThreeLoader } from '@solaldr/loader/dist/index.esm'

const assetsLoader = new AssetsLoader([
  {
    test: /\.(?:png|jpe?g)/,
    loader:  new ThreeLoader(new THREE.TextureLoader())
  },
  {
    test: /\.(?:glb|gltf)/,
    loader:  new ThreeLoader(new THREE.GLTFLoader())
  }
])

assetsLoader.load('/test.glb').then((gltfScene) => {
  console.log(gltfScene);
})

Add Group

With array definition

const g = assetsLoader.addGroup([
  "./object.gltf", 
  { name: 'test', path: './test.gltf' }
])

With object definition

const g = assetsLoader.addGroup({
  name: 'global',
  baseUrl: './public/',
  files: [ "object.gltf", "object2.gltf" ]
})

Inside another group

group.addGroup({
  name: 'subGroup',
  baseUrl: './public/',
  files: [ "object3.gltf", "object4.gltf" ]
})

Load a group

From an existent group

group.load();

Directly during création

const results = await assetsLoader.loadGroup({
  name: 'global',
  baseUrl: './public/',
  files: [ "object.gltf", "object2.gltf" ]
})

Add File

From string definition

const file = assetsLoader.addFile("test.png")

From object definition

const file = assetsLoader.addFile({
  name: "test",
  path: "./test.png"
})

Load a file

const result = await file.load()

Fetch a file or a group

const group = assetsManager.get('global')

Events

event description compat
load Triggered when the ressource is fully loaded File|Group|Manager
progress Wrapper for the ProgressEvent File|Group|Manager
file:load Triggered when a file is loaded inside a group Group

License

MIT.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published