npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

three-assets-loader

v2.0.1

Published

Its a helper tool for loading all assets and you can use it anywhere.

Downloads

232

Readme

Three.js Asset Loader

A lightweight, type-safe, and efficient asset loading system for Three.js projects. Load GLTF models, textures, audio (positional & global), and cube textures — all with built-in progress tracking, animation support, and full disposal for memory safety.

Perfect for games, interactive experiences, or any WebGL/Three.js application where performance and clean resource management matter.

Features

Type-safe asset definitions via assetsEntry.ts

Parallel loading with progress feedback

GLTF + Animation support (with an AnimationMixer per model)

Positional & Global Audio

Texture & CubeTexture loading

Automatic memory-safe disposal

Singleton architecture — safe across modules

Optional CLI setup tool to bootstrap configuration

Installation npm install three-js-asset-loader ///////////////////////////////////////////////////////////////////////////////////////////

⚠️ Requires three as a peer dependency

npm install three /////////////////////////////////////////////////////////////////////////////////////////////

Quick Start

/*********************************/

  1. Generate Config Files (Optional via CLI) npx three-js-asset-loader init

This creates:

assetsEntry.ts – Define your assets

exampleScene.ts – Usage example

/*********************************/

  1. Define Your Assets (assetsEntry.ts) // assetsEntry.ts // Asset format must follow this structure. // If you don’t have any category (like fonts, HDRIs etc.), you may omit it.

export const assetsEntry = { models: [ { name: "oldCar", path: "/car.glb", cloneRequest: { enabled: true, count: 5, methods: "DeepClone", }, }, { name: "character", path: "/character.glb", cloneRequest: { enabled: false, }, }, ], audios: [ { name: "audio", path: "/audio.mp3", positional: true, loop: true, volume: 0.5, }, ], textures: [ { name: "texture1", path: "/texture.jpg", cloneRequest: { enabled: true, count: 4, }, }, { name: "texture2", path: "/texture2.jpg", cloneRequest: { enabled: true, count: 4, }, }, ], cubeTextures: [ { name: "skybox1", paths: [ "/Yokohama2/negx.jpg", "/Yokohama2/negy.jpg", "/Yokohama2/negz.jpg", "/Yokohama2/posx.jpg", "/Yokohama2/posy.jpg", "/Yokohama2/posz.jpg", ], }, ], hdrCubeTextures: [ // Example: // { // name: "skybox2", // paths: [...], // isPMREMGenerator: true, // }, ], hdrTextures: [ { name: "hdr1", path: "/hdri1.hdr", mapping: "EquirectangularReflectionMapping", }, ], fonts: [ { name: "roboto", path: "/gentilis_regular.typeface.json", }, ], };

3. Load Assets in Your Scene

import { Scene, PerspectiveCamera } from "three"; import { assetsEntry } from "./assetsEntry.js"; import { AssetsLoader, AllAssets,LoadingManager } from "three-assets-loader";

const scene = new Scene(); const camera = new PerspectiveCamera(75, innerWidth / innerHeight, 0.1, 1000); camera.position.z = 5;

const assetsLoader = new AssetsLoader(assetsEntry, scene);

// Must be called if using HDR CubeTextures or HDRI textures. // Call BEFORE: await assetsLoader.loadAllAssets(); assetsLoader.setRendererForHdrMap(renderer);

// Optional: Show loading progress const loadingManager = LoadingManager.getInstance(); const progressBar = document.getElementById("progress");

loadingManager.onProgress((progress) => { progressBar.style.width = ${progress.percent}%; });

// Load everything await assetsLoader.loadAllAssets();

// This instance holds every loaded asset (including generated clones). const allAssets = AllAssets.getInstance();

Working With Models // Fetch source model const source = allAssets.fetchModel("character");

/* NOTE: When fetching a source model, you receive the exact original reference. If the same model is fetched and modified in multiple places, transformations will apply everywhere because the reference is shared. */

Clone Types Clone Type Description DeepClone Fully clones geometry and materials. Not recommended for animated models. ShallowClone Clones geometry only; materials remain shared. SkeletonClone Best for animated models (bones/skin). Extra options: deepClone, cloneGeometry. // Generate clones allAssets.fetchModel("car2", { count: 2, methods: "DeepClone" }); allAssets.fetchModel("car2", { count: 2, methods: "ShallowClone" }); allAssets.fetchModel("car2", { count: 2, methods: "SkeletonClone" });

// Fetch a clone later: const car = allAssets.fetchModel("car2SkeletonClone1");

Clone naming format:

Example → car2SkeletonClone0

Returned Model Properties Overview const carClone = allAssets.fetchModel("car2");

This returns:

Property Meaning actionRef Animation actions (if available) animations Animation clips (source model only) id Unique model ID (source only) mixerRef Animation mixer modelRef Object3D clone (for clone models only) name Source model name parentName / parentId Parent source info (clone only) sourceModel Original Object3D (source only) Animation Example const car = allAssets.fetchModel("car2SkeletonClone0"); car.actionsRef["AllAnim"].play();

if (car.mixerRef) car.mixerRef.update(delta);

Audio Usage

Global audio:

const audio = allAssets.fetchAudio("audioName"); audio.play();

Positional audio:

allAssets.setCameraForPositionalAudio(camera);

const audio = allAssets.fetchAudio("audio"); cube1.add(audio.audio); audio.audio.setRefDistance(6); audio.audio.play();

Environment Maps const cubeTextures = allAssets.fetchCubeTexture("skybox1"); scene.background = cubeTextures.cubeMap;

HDR environment:

const hdriTexture = allAssets.fetchHdriTexture("hdr1"); scene.background = hdriTexture.original; scene.environment = hdriTexture.hdri;

Fonts const font1 = allAssets.fetchFont("roboto");

Disposal & Memory Management

Use these to avoid memory leaks.

disposeEverything

Clears ALL assets loaded from assetsEntry — including models, textures, audio, etc. Your manually created custom meshes will not be removed, but their asset-based texture references will.

Additional Disposal APIs

  • disposeAllTextures
  • disposeAudio("audioName")
  • disposeCloneModel("car2DeepClone0")
  • disposeCloneTexture("textureCloneName")
  • disposeCubeMap("cubeMapName")
  • disposeFont()
  • disposeHdrCubeMap()
  • disposeHdriTexture("hdriName", scene)
  • disposeModelsByScene(scene1)
  • disposeSourceModel("car2")
  • disposeSourceTexture("textureName")
  • disposeTexturesByScene(scene1)

Helper Functions allAssets.getAllTexturesArray(); allAssets.getClone("car2SkeletonClone1"); allAssets.getClones("car2");

Result format:

car2: { deep: [], shallow: [], skeleton: [], }

CLI Commands Command Description npx three-js-asset-loader init Generates configuration and example files Built With

Three.js

TypeScript

ES Modules