@stowkit/three-loader 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,10 +16,10 @@ import { StowKitLoader } from '@stowkit/three-loader';
|
|
|
16
16
|
// Load a pack (auto-initializes with defaults)
|
|
17
17
|
const pack = await StowKitLoader.load('assets.stow');
|
|
18
18
|
|
|
19
|
-
// Load assets by name
|
|
20
|
-
const mesh = await pack.loadMesh('
|
|
21
|
-
const texture = await pack.loadTexture('
|
|
22
|
-
const audio = await pack.loadAudio('
|
|
19
|
+
// Load assets by name
|
|
20
|
+
const mesh = await pack.loadMesh('character');
|
|
21
|
+
const texture = await pack.loadTexture('wood');
|
|
22
|
+
const audio = await pack.loadAudio('bgm', audioListener);
|
|
23
23
|
|
|
24
24
|
// Use in Three.js
|
|
25
25
|
scene.add(mesh);
|
|
@@ -94,18 +94,19 @@ Once you have a pack loaded, use these methods to load assets:
|
|
|
94
94
|
|
|
95
95
|
### Loading Meshes
|
|
96
96
|
|
|
97
|
-
#### `pack.loadMesh(
|
|
97
|
+
#### `pack.loadMesh(stringId: string): Promise<THREE.Group>`
|
|
98
98
|
|
|
99
|
-
Load a mesh by its canonical path
|
|
99
|
+
Load a mesh by its string ID (the canonical path used when packing). Automatically loads and applies textures and materials.
|
|
100
100
|
|
|
101
101
|
```typescript
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
const
|
|
102
|
+
// String IDs are whatever you used when packing the assets
|
|
103
|
+
const cookingStation = await pack.loadMesh('restaurant_display_cooking_station');
|
|
104
|
+
const door = await pack.loadMesh('restaurant_display_door');
|
|
105
|
+
const physics = await pack.loadMesh('restaurant_physics');
|
|
105
106
|
|
|
106
|
-
scene.add(
|
|
107
|
-
scene.add(
|
|
108
|
-
scene.add(
|
|
107
|
+
scene.add(cookingStation);
|
|
108
|
+
scene.add(door);
|
|
109
|
+
scene.add(physics);
|
|
109
110
|
```
|
|
110
111
|
|
|
111
112
|
**What you get:**
|
|
@@ -117,32 +118,37 @@ scene.add(building);
|
|
|
117
118
|
|
|
118
119
|
### Loading Textures
|
|
119
120
|
|
|
120
|
-
#### `pack.loadTexture(
|
|
121
|
+
#### `pack.loadTexture(stringId: string): Promise<THREE.CompressedTexture>`
|
|
121
122
|
|
|
122
|
-
Load a KTX2 texture by its canonical path
|
|
123
|
+
Load a KTX2 texture by its string ID (the canonical path used when packing).
|
|
123
124
|
|
|
124
125
|
```typescript
|
|
125
|
-
const
|
|
126
|
-
const
|
|
126
|
+
const shadow = await pack.loadTexture('_shadow');
|
|
127
|
+
const atlas = await pack.loadTexture('zy_Atlas');
|
|
127
128
|
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
shadowMaterial.map = shadow;
|
|
130
|
+
particleMaterial.map = atlas;
|
|
130
131
|
material.needsUpdate = true;
|
|
131
132
|
```
|
|
132
133
|
|
|
133
134
|
### Loading Audio
|
|
134
135
|
|
|
135
|
-
#### `loadAudio(
|
|
136
|
+
#### `pack.loadAudio(stringId: string, listener: THREE.AudioListener): Promise<THREE.Audio>`
|
|
136
137
|
|
|
137
|
-
Load
|
|
138
|
+
Load audio by its string ID (the canonical path used when packing).
|
|
138
139
|
|
|
139
140
|
```typescript
|
|
140
141
|
const listener = new THREE.AudioListener();
|
|
141
142
|
camera.add(listener);
|
|
142
143
|
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
const bgm = await pack.loadAudio('track_01', listener);
|
|
145
|
+
bgm.setLoop(true);
|
|
146
|
+
bgm.setVolume(0.5);
|
|
147
|
+
bgm.play();
|
|
148
|
+
|
|
149
|
+
// More audio
|
|
150
|
+
const click = await pack.loadAudio('click', listener);
|
|
151
|
+
const cashRegister = await pack.loadAudio('cash register', listener);
|
|
146
152
|
```
|
|
147
153
|
|
|
148
154
|
#### `createAudioPreview(index: number): Promise<HTMLAudioElement>`
|
|
@@ -388,15 +394,15 @@ const mesh = await loader.loadMesh('', 'models/character.mesh');
|
|
|
388
394
|
// Load pack once
|
|
389
395
|
const pack = await StowKitLoader.load('assets.stow');
|
|
390
396
|
|
|
391
|
-
// Load many assets
|
|
392
|
-
const
|
|
393
|
-
const
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
const
|
|
397
|
+
// Load many assets (using whatever string IDs you assigned when packing)
|
|
398
|
+
const station = await pack.loadMesh('restaurant_display_cooking_station');
|
|
399
|
+
const door = await pack.loadMesh('restaurant_display_door');
|
|
400
|
+
const shadow = await pack.loadTexture('_shadow');
|
|
401
|
+
const atlas = await pack.loadTexture('zy_Atlas');
|
|
402
|
+
const music = await pack.loadAudio('track_01', listener);
|
|
397
403
|
|
|
398
|
-
scene.add(
|
|
399
|
-
scene.add(
|
|
404
|
+
scene.add(station);
|
|
405
|
+
scene.add(door);
|
|
400
406
|
```
|
|
401
407
|
|
|
402
408
|
### Inspect Before Loading
|