@umicat/three-sdk 1.20.0 → 1.21.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/Attachments.js +2 -1
- package/dist/SceneLoader3D.js +7 -7
- package/dist/Skin.js +2 -1
- package/dist/scene3d.d.ts +20 -0
- package/dist/scene3d.js +26 -0
- package/package.json +1 -1
package/dist/Attachments.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
2
2
|
import { clone as cloneRigged } from 'three/examples/jsm/utils/SkeletonUtils.js';
|
|
3
3
|
import { attachToSocket } from './Sockets.js';
|
|
4
|
+
import { resolveAssetUrl } from './scene3d.js';
|
|
4
5
|
const cache = new Map();
|
|
5
6
|
let loader = null;
|
|
6
7
|
function fetchProp(url) {
|
|
@@ -57,7 +58,7 @@ export async function applyAttachments(wearer, wearerAsset, manifest, list, opts
|
|
|
57
58
|
}
|
|
58
59
|
resolved.push({ key: a.id ?? socketName, name: a.id ?? prop.id, prop, socket });
|
|
59
60
|
}
|
|
60
|
-
const gltfs = await Promise.all(resolved.map(({ prop }) => opts.preloaded?.get(prop.id) ?? fetchProp((opts.assetBase
|
|
61
|
+
const gltfs = await Promise.all(resolved.map(({ prop }) => opts.preloaded?.get(prop.id) ?? fetchProp(resolveAssetUrl(opts.assetBase, prop.path))));
|
|
61
62
|
for (const object of opts.previous?.values() ?? [])
|
|
62
63
|
detach(object);
|
|
63
64
|
const worn = new Map();
|
package/dist/SceneLoader3D.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
|
3
3
|
import { clone as cloneRigged } from 'three/examples/jsm/utils/SkeletonUtils.js';
|
|
4
|
-
import { validateScene, IDENTITY_QUAT, wedgeVertices, cornerWedgeVertices, defaultColliderForPrimitive, resampleHeights, heightfieldColliderArgs, } from './scene3d.js';
|
|
4
|
+
import { validateScene, IDENTITY_QUAT, wedgeVertices, cornerWedgeVertices, defaultColliderForPrimitive, resampleHeights, heightfieldColliderArgs, resolveAssetUrl, } from './scene3d.js';
|
|
5
5
|
import { applySkin } from './Skin.js';
|
|
6
6
|
import { applyAttachments } from './Attachments.js';
|
|
7
7
|
function toVec(v, d = 0) {
|
|
@@ -362,7 +362,7 @@ export async function makeHeightfield(hf, manifest, opts = {}) {
|
|
|
362
362
|
const have = (manifest.heightmaps ?? []).map((h) => h.id).join(', ');
|
|
363
363
|
throw new Error(`[umicat] manifest has no heightmap '${hf.assetId}'. It has: ${have || '(none)'}`);
|
|
364
364
|
}
|
|
365
|
-
const px = await heightmapPixels((opts.assetBase
|
|
365
|
+
const px = await heightmapPixels(resolveAssetUrl(opts.assetBase, entry.path));
|
|
366
366
|
const seg = heightfieldSegments(hf);
|
|
367
367
|
const heights = resampleHeights(px.data, px.width, px.height, seg.render);
|
|
368
368
|
const material = new THREE.MeshStandardMaterial({ color: hf.color ?? '#ffffff' });
|
|
@@ -526,7 +526,7 @@ export async function loadModelAsset(manifest, modelAssetId, opts = {}) {
|
|
|
526
526
|
const have = (manifest.models ?? []).map((m) => m.id).join(', ');
|
|
527
527
|
throw new Error(`[umicat] manifest has no model '${modelAssetId}'. It has: ${have || '(none)'}`);
|
|
528
528
|
}
|
|
529
|
-
const gltf = await new GLTFLoader().loadAsync((opts.assetBase
|
|
529
|
+
const gltf = await new GLTFLoader().loadAsync(resolveAssetUrl(opts.assetBase, asset.path));
|
|
530
530
|
const object = gltf.scene;
|
|
531
531
|
if (opts.skin) {
|
|
532
532
|
const path = asset.skins?.[opts.skin];
|
|
@@ -565,10 +565,10 @@ export async function applySky(scene, sky, opts = {}) {
|
|
|
565
565
|
if (sky.paths?.length !== 6) {
|
|
566
566
|
throw new Error(`cubemap sky needs exactly 6 faces, got ${sky.paths?.length ?? 0} — use cubeFacesFromNames to order them`);
|
|
567
567
|
}
|
|
568
|
-
texture = await new THREE.CubeTextureLoader().loadAsync(sky.paths.map((p) => base
|
|
568
|
+
texture = await new THREE.CubeTextureLoader().loadAsync(sky.paths.map((p) => resolveAssetUrl(base, p)));
|
|
569
569
|
}
|
|
570
570
|
else {
|
|
571
|
-
texture = await new THREE.TextureLoader().loadAsync(base
|
|
571
|
+
texture = await new THREE.TextureLoader().loadAsync(resolveAssetUrl(base, sky.path));
|
|
572
572
|
texture.mapping = THREE.EquirectangularReflectionMapping;
|
|
573
573
|
}
|
|
574
574
|
texture.colorSpace = THREE.SRGBColorSpace;
|
|
@@ -656,7 +656,7 @@ export async function loadScene3D(scene3d, manifest, opts = {}) {
|
|
|
656
656
|
if (heightmapPixelsById.has(entry.id))
|
|
657
657
|
continue;
|
|
658
658
|
heightmapPixelsById.set(entry.id, { data: new Float32Array(1), width: 1, height: 1 });
|
|
659
|
-
heightmapJobs.push(heightmapPixels((opts.assetBase
|
|
659
|
+
heightmapJobs.push(heightmapPixels(resolveAssetUrl(opts.assetBase, entry.path))
|
|
660
660
|
.then((px) => { heightmapPixelsById.set(entry.id, px); }));
|
|
661
661
|
}
|
|
662
662
|
if (heightmapJobs.length)
|
|
@@ -668,7 +668,7 @@ export async function loadScene3D(scene3d, manifest, opts = {}) {
|
|
|
668
668
|
const asset = models.get(id);
|
|
669
669
|
if (!asset)
|
|
670
670
|
throw new Error(`scene3d references model '${id}', which the manifest does not define`);
|
|
671
|
-
const url = (opts.assetBase
|
|
671
|
+
const url = resolveAssetUrl(opts.assetBase, asset.path);
|
|
672
672
|
loaded.set(id, await loader.loadAsync(url));
|
|
673
673
|
}));
|
|
674
674
|
}
|
package/dist/Skin.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
+
import { resolveAssetUrl } from './scene3d.js';
|
|
2
3
|
/** Objects whose materials have already been given their own copies. */
|
|
3
4
|
const isolated = new WeakSet();
|
|
4
5
|
const textures = new Map();
|
|
@@ -100,7 +101,7 @@ export function applySkinTexture(object, texture, opts = {}) {
|
|
|
100
101
|
* did nothing", and there is no other signal.
|
|
101
102
|
*/
|
|
102
103
|
export async function applySkin(object, url, opts = {}) {
|
|
103
|
-
const full = (opts.assetBase
|
|
104
|
+
const full = resolveAssetUrl(opts.assetBase, url);
|
|
104
105
|
const texture = await loadSkinTexture(full, opts.cache !== false);
|
|
105
106
|
return applySkinTexture(object, texture, opts);
|
|
106
107
|
}
|
package/dist/scene3d.d.ts
CHANGED
|
@@ -511,6 +511,26 @@ export declare function heightfieldColliderArgs(heights: Float32Array, n: number
|
|
|
511
511
|
* edge" from "at ground level" — they are different answers.
|
|
512
512
|
*/
|
|
513
513
|
export declare function sampleHeightfield(heights: Float32Array, n: number, size: Vec3, x: number, z: number): number | null;
|
|
514
|
+
/**
|
|
515
|
+
* Join a project's asset base to an asset's own path — **unless the path is
|
|
516
|
+
* already complete**, in which case it is returned untouched.
|
|
517
|
+
*
|
|
518
|
+
* Every asset path in this SDK used to be a bare `base + path` concatenation,
|
|
519
|
+
* which quietly made one whole category of asset unreferenceable: anything
|
|
520
|
+
* hosted somewhere else. A manifest entry pointing at
|
|
521
|
+
* `https://cdn.umicat.ai/platform/...` became
|
|
522
|
+
* `<base>https://cdn.umicat.ai/platform/...` and 404'd, in every project whose
|
|
523
|
+
* base is non-empty — which is every real project. This blocked platform-hosted
|
|
524
|
+
* assets of ANY kind (ADR-050's preset heightmaps are what surfaced it) and it
|
|
525
|
+
* applied equally to models, skins, props and skies.
|
|
526
|
+
*
|
|
527
|
+
* Left deliberately alone: a ROOT-RELATIVE `/foo.png`. It reads as "from the
|
|
528
|
+
* site root", but `base + '/foo.png'` against a CDN base is the established
|
|
529
|
+
* behaviour and almost certainly what the author of such a path meant.
|
|
530
|
+
* Changing it would be a silent behaviour change for existing projects, which
|
|
531
|
+
* is not worth it to make one more spelling work.
|
|
532
|
+
*/
|
|
533
|
+
export declare function resolveAssetUrl(base: string | undefined, path: string): string;
|
|
514
534
|
/** Identity quaternion, spelled out so callers don't have to remember the order. */
|
|
515
535
|
export declare const IDENTITY_QUAT: Quat;
|
|
516
536
|
export declare function vec3(x?: number, y?: number, z?: number): Vec3;
|
package/dist/scene3d.js
CHANGED
|
@@ -250,6 +250,32 @@ export function sampleHeightfield(heights, n, size, x, z) {
|
|
|
250
250
|
const bottom = h(x0, z0 + 1) * (1 - tx) + h(x0 + 1, z0 + 1) * tx;
|
|
251
251
|
return (top * (1 - tz) + bottom * tz) * size.y;
|
|
252
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Join a project's asset base to an asset's own path — **unless the path is
|
|
255
|
+
* already complete**, in which case it is returned untouched.
|
|
256
|
+
*
|
|
257
|
+
* Every asset path in this SDK used to be a bare `base + path` concatenation,
|
|
258
|
+
* which quietly made one whole category of asset unreferenceable: anything
|
|
259
|
+
* hosted somewhere else. A manifest entry pointing at
|
|
260
|
+
* `https://cdn.umicat.ai/platform/...` became
|
|
261
|
+
* `<base>https://cdn.umicat.ai/platform/...` and 404'd, in every project whose
|
|
262
|
+
* base is non-empty — which is every real project. This blocked platform-hosted
|
|
263
|
+
* assets of ANY kind (ADR-050's preset heightmaps are what surfaced it) and it
|
|
264
|
+
* applied equally to models, skins, props and skies.
|
|
265
|
+
*
|
|
266
|
+
* Left deliberately alone: a ROOT-RELATIVE `/foo.png`. It reads as "from the
|
|
267
|
+
* site root", but `base + '/foo.png'` against a CDN base is the established
|
|
268
|
+
* behaviour and almost certainly what the author of such a path meant.
|
|
269
|
+
* Changing it would be a silent behaviour change for existing projects, which
|
|
270
|
+
* is not worth it to make one more spelling work.
|
|
271
|
+
*/
|
|
272
|
+
export function resolveAssetUrl(base, path) {
|
|
273
|
+
// Any scheme (`https:`, `data:`, `blob:`) or protocol-relative `//host/...`
|
|
274
|
+
// is already a complete reference.
|
|
275
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(path) || path.startsWith('//'))
|
|
276
|
+
return path;
|
|
277
|
+
return (base ?? '') + path;
|
|
278
|
+
}
|
|
253
279
|
/** Identity quaternion, spelled out so callers don't have to remember the order. */
|
|
254
280
|
export const IDENTITY_QUAT = [0, 0, 0, 1];
|
|
255
281
|
export function vec3(x = 0, y = 0, z = 0) { return { x, y, z }; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umicat/three-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"description": "Three.js runtime for Umicat games: the scene3d design format, its loader with physics, a kinematic character controller, and the Umicat platform via @umicat/platform-sdk.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|