@ludicon/spark.js 0.1.2 → 0.1.3
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 +11 -0
- package/package.json +1 -1
- package/src/three-gltf.js +19 -12
package/README.md
CHANGED
|
@@ -179,6 +179,17 @@ registerSparkLoader(loader, spark)
|
|
|
179
179
|
|
|
180
180
|
After registration, the loader will automatically encode textures with Spark whenever applicable.
|
|
181
181
|
|
|
182
|
+
To use the Spark plugins with the three.js 3DTilesRenderer, you can pass them to the renderer's `GLTFExtensionsPlugin` as follows:
|
|
183
|
+
|
|
184
|
+
```js
|
|
185
|
+
import { createSparkPlugins } from "@ludicon/spark.js/three-gltf";
|
|
186
|
+
|
|
187
|
+
tiles = new TilesRenderer();
|
|
188
|
+
tiles.registerPlugin( new GLTFExtensionsPlugin( {
|
|
189
|
+
plugins: createSparkPlugins( spark, { generateMipmaps: false } )
|
|
190
|
+
} ) );
|
|
191
|
+
```
|
|
192
|
+
|
|
182
193
|
|
|
183
194
|
## License
|
|
184
195
|
|
package/package.json
CHANGED
package/src/three-gltf.js
CHANGED
|
@@ -10,7 +10,7 @@ const Channel = {
|
|
|
10
10
|
RGBA: 15 // 1111
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
class GLTFSparkPlugin {
|
|
13
|
+
export class GLTFSparkPlugin {
|
|
14
14
|
constructor(name, parser, spark, options) {
|
|
15
15
|
this.name = name
|
|
16
16
|
this.parser = parser
|
|
@@ -216,19 +216,26 @@ class SparkLoader extends THREE.TextureLoader {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
export function
|
|
220
|
-
|
|
221
|
-
for (let i = 0; i < loader.pluginCallbacks.length; i++) {
|
|
222
|
-
const plugin = loader.pluginCallbacks[i](loader)
|
|
219
|
+
export function createSparkPlugins(spark, options = {}) {
|
|
220
|
+
const pluginCache = new WeakMap()
|
|
223
221
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
222
|
+
function getOrCreatePlugin(parser) {
|
|
223
|
+
let plugin = pluginCache.get(parser)
|
|
224
|
+
if (!plugin) {
|
|
225
|
+
plugin = new GLTFSparkPlugin("spark", parser, spark, options)
|
|
226
|
+
pluginCache.set(parser, plugin)
|
|
227
227
|
}
|
|
228
|
+
return plugin
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
return ["spark", "EXT_texture_webp", "EXT_texture_avif"].map(name => parser => {
|
|
232
|
+
const plugin = getOrCreatePlugin(parser)
|
|
233
|
+
return { name, loadTexture: idx => plugin.loadTexture(idx) }
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function registerSparkLoader(loader, spark, options = {}) {
|
|
238
|
+
for (const callback of createSparkPlugins(spark, options)) {
|
|
239
|
+
loader.register(callback)
|
|
240
|
+
}
|
|
234
241
|
}
|