Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

load-and-optimize-gltf

БесплатноБез исполняемых скриптовНе проверен

Load glTF/GLB models in three.js with GLTFLoader wired to the Meshopt, KTX2 and Draco decoders, shrink the file first with glTF Transform (`gltf-transform…

nirholasот nirholas★ 289 звёзд на GitHub

Об этом скилле

Load and optimize glTF in three.js

Targets three.js r187 ([email protected]). Every runnable block below is executed in Chromium against a real CC0 model before this plugin ships.

The order that works: optimize the file, then load it with one loader that knows every decoder, then measure. A loader without the decoders fails on compressed files, and a compressed file without measurement is a guess.

1. Optimize the file

glTF Transform does it in one command. model.glb is your source file; nothing to install beyond Node.

npx @gltf-transform/[email protected] inspect model.glb
npx @gltf-transform/[email protected] optimize model.glb model-optimized.glb --compress meshopt --texture-compress ktx2 --texture-size 2048
  • --compress meshopt compresses geometry and animation. It decodes faster than Draco and is the default.
  • --texture-compress ktx2 writes GPU-compressed Basis Universal textures: they stay compressed in GPU memory (4 to 8 times smaller than a decoded JPEG or PNG). It needs the ktx CLI from KTX-Software on PATH. Without it, use --texture-compress webp: smaller downloads, same GPU memory as the original.
  • --texture-size 2048 caps every texture. Use 1024 for props on mobile.

KTX2 and WebP win on different axes. Measured on a CC0 armchair from the three.ws catalog (three 1024x1024 JPEG textures), with the gpuSize column of inspect:

File Download Texture VRAM
model.glb (source) 1.70 MB 16.8 MB
model-optimized.glb (Meshopt + KTX2) 2.05 MB 3.5 MB
model-draco.glb (Draco + WebP, below) 0.20 MB 16.8 MB

optimize encodes normal and roughness maps as UASTC (high quality, large on disk) and base color as ETC1S (small), so the KTX2 file can be bigger than the JPEG source while using a fifth of the GPU memory. Pick KTX2 when many textures must stay resident (scenes, mobile, WebXR). Pick WebP when one model must arrive fast and VRAM is not the limit.

If an existing pipeline already standardizes on Draco, this variant keeps it:

npx @gltf-transform/[email protected] optimize model.glb model-draco.glb --compress draco --texture-compress webp

Check what optimize changes before you ship it. By default it flattens the scene graph and joins meshes to cut draw calls. That renames and merges nodes, so code that calls getObjectByName('Door') or animates a single part breaks. Keep named parts with --join-named false, or keep the hierarchy with --flatten false --join false. It also simplifies geometry (--simplify-error 0.0001 of the mesh extent); pass --simplify false for CAD or anything with hard silhouettes.

2. Load with one loader that knows every decoder

Create the loader once and reuse it for every model. The decoders run in workers and spinning them up per file wastes time.

import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
import { MeshoptDecoder } from 'three/addons/libs/meshopt_decoder.module.js';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';

// Decoder files ship inside the three package. Pin the CDN path to the same version
// you import, or copy examples/jsm/libs/{draco,basis} into your static folder.
const LIBS = 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/libs/';

const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

const scene = new THREE.Scene();
scene.background = new THREE.Color(0x1d2026);
const pmrem = new THREE.PMREMGenerator(renderer);
scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;

const camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 0.01, 100);

const draco = new DRACOLoader().setDecoderPath(`${LIBS}draco/gltf/`);
const ktx2 = new KTX2Loader().setTranscoderPath(`${LIBS}basis/`).detectSupport(renderer);
const loader = new GLTFLoader().setDRACOLoader(draco).setKTX2Loader(ktx2).setMeshoptDecoder(MeshoptDecoder);

// Both outputs from step 1, side by side: Meshopt + KTX2 on the left, Draco + WebP on the right.
const [meshopt, dracoModel] = await Promise.all([
	loader.loadAsync('model-optimized.glb'),
	loader.loadAsync('model-draco.glb'),
]);
const group = new THREE.Group();
for (const [i, gltf] of [meshopt, dracoModel].entries()) {
	const size = new THREE.Box3().setFromObject(gltf.scene).getSize(new THREE.Vector3());
	gltf.scene.position.x = (i - 0.5) * size.x * 1.3;
	group.add(gltf.scene);
}
scene.add(group);
frameObject(camera, group);

window.addEventListener('resize', () => {
	camera.aspect = window.innerWidth / window.innerHeig
Полный SKILL.md на GitHub

Установить load-and-optimize-gltf в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл load-and-optimize-gltf?

Load glTF/GLB models in three.js with GLTFLoader wired to the Meshopt, KTX2 and Draco decoders, shrink the file first with glTF Transform (`gltf-transform optimize`), and measure what changed (bytes over the wire, decode time, draw calls, triangles, texture memory). Use when a model will not load, loads slowly, is too big for the web, throws a decoder error ("setMeshoptDecoder must be called", "No DRACOLoader instance provided", "KTX2Loader"), or when the user asks how to compress, optimize or load a GLB.

Как установить скилл load-and-optimize-gltf?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл load-and-optimize-gltf запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить load-and-optimize-gltf с