@kite3d/engine 0.16.0 → 0.17.0

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/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
- const n = "0.16.0", e = {
1
+ const n = "0.17.0", e = {
2
2
  version: n
3
3
  }, o = e.version;
4
4
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kite3d/engine",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "The open Kite3D game runtime, project format, scripting helpers, and game plugins.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -29,8 +29,8 @@ import {
29
29
  } from '../authoringValidation.ts'
30
30
  import {RuntimeNestedAssetLoader} from './nestedAssets.ts'
31
31
  import {
32
- assetUrlPrefix,
33
32
  AssetsJSONManifest,
33
+ createProjectAssetURLModifier,
34
34
  ExternalPlugin,
35
35
  isDependencyModuleSpecifier,
36
36
  parseAssetsJSONManifest,
@@ -142,7 +142,7 @@ async function createProjectGame({
142
142
 
143
143
  // Three's LoadingManager delegates through this importer hook. It covers
144
144
  // glTF buffers/textures and nested imports without patching global fetch.
145
- const urlModifier = createURLModifier(baseUrl, assetsManifest)
145
+ const urlModifier = createProjectAssetURLModifier(baseUrl, assetsManifest)
146
146
  viewer.assetManager.importer.addURLModifier(urlModifier)
147
147
  removeURLModifier = () => viewer?.assetManager.importer.removeURLModifier(urlModifier)
148
148
 
@@ -246,22 +246,6 @@ async function registerProjectScripts(
246
246
  await registerScripts(viewer, modules)
247
247
  }
248
248
 
249
- function createURLModifier(base: URL, assets: AssetsJSONManifest) {
250
- const assetIdPrefix = `${assetUrlPrefix}@`
251
- return (url: string): string => {
252
- if (url.startsWith(assetIdPrefix)) {
253
- const id = url.slice(assetIdPrefix.length).split('/', 1)[0]
254
- const asset = assets.files[id]
255
- if (!asset?.path) throw new Error(`Unknown asset id in URL: ${id}`)
256
- return new URL(asset.path, base).href
257
- }
258
- if (url.startsWith(assetUrlPrefix)) {
259
- return new URL(url.slice(assetUrlPrefix.length), base).href
260
- }
261
- return url
262
- }
263
- }
264
-
265
249
  function resolvePluginSpecifier(
266
250
  definition: ExternalPlugin,
267
251
  packageJson: ProjectPackageJSON,
@@ -17,10 +17,35 @@ export interface ProjectGeneratorState {
17
17
  export interface AssetsJSONManifest {
18
18
  files: Record<string, {
19
19
  path: string
20
+ files?: Record<string, string>
20
21
  }>
21
22
  version: number
22
23
  }
23
24
 
25
+ export function createProjectAssetURLModifier(base: URL, assets: AssetsJSONManifest) {
26
+ const assetIdPrefix = `${assetUrlPrefix}@`
27
+ return (url: string): string => {
28
+ if (url.startsWith(assetIdPrefix)) {
29
+ const request = new URL(url, 'https://kite3d.invalid')
30
+ const relative = decodeURIComponent(request.pathname.slice(assetIdPrefix.length))
31
+ const slash = relative.indexOf('/')
32
+ const id = slash < 0 ? relative : relative.slice(0, slash)
33
+ const assetPath = slash < 0 ? '' : relative.slice(slash + 1)
34
+ const asset = assets.files[id]
35
+ if (!asset?.path) throw new Error(`Unknown asset id in URL: ${id}`)
36
+ const registered = asset.files?.[assetPath]
37
+ if (registered) return new URL(registered, base).href
38
+ if (asset.files) throw new Error(`Unknown file for asset ${id}: ${assetPath}`)
39
+ if (/^f\.[^/]+$/i.test(assetPath)) return new URL(asset.path, base).href
40
+ return new URL(assetPath, new URL(asset.path, base)).href
41
+ }
42
+ if (url.startsWith(assetUrlPrefix)) {
43
+ return new URL(url.slice(assetUrlPrefix.length), base).href
44
+ }
45
+ return url
46
+ }
47
+ }
48
+
24
49
  export interface ProjectDependency {
25
50
  key: string
26
51
  version: string