360 Secure SkillHub
360 安全技能中心

load-assets

该 Skill 面向 PlayCanvas 的 glTF/GLB 资产加载,说明模型实例化、Draco/Meshopt 几何压缩、KTX2/Basis 纹理压缩,以及 Draco、Basis 和 Meshopt 解码器的配置与预加载方式。

分类:开发
playcanvas
热度 0.00
最近更新 2026-11-11 05:19:30

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add playcanvas/skills/load-assets
兼容性
通用兼容
联网要求
不联网
数据出网
数据不出本机
Metadata
name
load-assets
description
Use when loading glTF/GLB models or textures in PlayCanvas, choosing Draco or Basis/KTX2 compression, or setting up decoders and preloading.

Load assets

glTF is fully supported

Load .glb files as container assets and call asset.resource.instantiateRenderEntity(), not instantiateModelEntity. The importer already handles KHR_lights_punctual, KHR_materials_* (clearcoat, sheen, transmission, volume, iridescence, variants, and more), KHR_texture_transform, and EXT_mesh_gpu_instancing; do not rebuild these by hand. Preload asset sets with AssetListLoader.

Compress for size

  • Geometry: Draco (KHR_draco_mesh_compression), or from Engine 2.24 Meshopt (EXT_meshopt_compression, KHR_meshopt_compression). Older Engines cannot load Meshopt, so decode such files before shipping.
  • Textures: KTX2 with Basis (KHR_texture_basisu) transcodes to a GPU format, cutting both download size and VRAM. ETC1S is smallest and lossy. UASTC is larger and keeps detail, which matters most for normal maps. Weigh size against visible detail.

Set up decoders

The npm package ships no Draco or Basis wasm. Copy draco/ and basis/ from the Engine's examples/assets/wasm at the installed tag (find-examples), and configure them before loading:

import { WasmModule, basisInitialize } from 'playcanvas';

WasmModule.setConfig('DracoDecoderModule', {
    glueUrl: '/wasm/draco/draco.wasm.js',
    wasmUrl: '/wasm/draco/draco.wasm.wasm',
    fallbackUrl: '/wasm/draco/draco.js'
});
await new Promise((resolve) => WasmModule.getInstance('DracoDecoderModule', resolve));
basisInitialize({
    glueUrl: '/wasm/basis/basis.wasm.js',
    wasmUrl: '/wasm/basis/basis.wasm.wasm',
    fallbackUrl: '/wasm/basis/basis.js'
});

From 2.24, also copy meshopt/ and call meshoptInitialize({ url: '/wasm/meshopt/meshopt_decoder.mjs' }) before loading Meshopt files; without it they fail unless they carry uncompressed fallback buffers.

In Web Components, a <pc-wasm name="DracoDecoderModule"> element under <pc-app> sets the Draco config with glue, wasm, and fallback attributes.

Other assets

  • Raise texture.anisotropy, which defaults to 1, for surfaces viewed at grazing angles.
  • Gaussian splats load as gsplat assets onto a gsplat component; start from a gaussian-splatting example.