spoint 0.1.26 → 0.1.28
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/client/app.js +1 -0
- package/package.json +1 -1
- package/src/sdk/StaticHandler.js +16 -5
package/client/app.js
CHANGED
|
@@ -662,6 +662,7 @@ loadingManager.onError = (url) => console.warn('[THREE] Failed to load:', url)
|
|
|
662
662
|
const gltfLoader = new GLTFLoader(loadingManager)
|
|
663
663
|
const dracoLoader = new DRACOLoader(loadingManager)
|
|
664
664
|
dracoLoader.setDecoderPath('/draco/')
|
|
665
|
+
dracoLoader.setWorkerLimit(1)
|
|
665
666
|
gltfLoader.setDRACOLoader(dracoLoader)
|
|
666
667
|
gltfLoader.register((parser) => new VRMLoaderPlugin(parser))
|
|
667
668
|
const playerMeshes = new Map()
|
package/package.json
CHANGED
package/src/sdk/StaticHandler.js
CHANGED
|
@@ -10,6 +10,20 @@ const MIME_TYPES = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const GZIP_EXTENSIONS = new Set(['.glb', '.vrm', '.gltf', '.js', '.css', '.html', '.json'])
|
|
13
|
+
const fileCache = new Map()
|
|
14
|
+
|
|
15
|
+
function getCached(fp, ext) {
|
|
16
|
+
const mtime = statSync(fp).mtimeMs
|
|
17
|
+
const key = fp
|
|
18
|
+
const cached = fileCache.get(key)
|
|
19
|
+
if (cached && cached.mtime === mtime) return cached
|
|
20
|
+
let raw = readFileSync(fp)
|
|
21
|
+
const shouldGzip = GZIP_EXTENSIONS.has(ext) && raw.length > 100
|
|
22
|
+
const content = shouldGzip ? gzipSync(raw) : raw
|
|
23
|
+
const entry = { mtime, content, gzipped: shouldGzip }
|
|
24
|
+
fileCache.set(key, entry)
|
|
25
|
+
return entry
|
|
26
|
+
}
|
|
13
27
|
|
|
14
28
|
export function createStaticHandler(dirs) {
|
|
15
29
|
return (req, res) => {
|
|
@@ -31,11 +45,8 @@ export function createStaticHandler(dirs) {
|
|
|
31
45
|
} else if (ext === '.glb' || ext === '.vrm' || ext === '.gltf') {
|
|
32
46
|
headers['Cache-Control'] = 'public, max-age=86400, immutable'
|
|
33
47
|
}
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
content = gzipSync(content)
|
|
37
|
-
headers['Content-Encoding'] = 'gzip'
|
|
38
|
-
}
|
|
48
|
+
const { content, gzipped } = getCached(fp, ext)
|
|
49
|
+
if (gzipped) headers['Content-Encoding'] = 'gzip'
|
|
39
50
|
headers['Content-Length'] = content.length
|
|
40
51
|
res.writeHead(200, headers)
|
|
41
52
|
res.end(content)
|