entangled-worlds-orbiters-shared 1.0.5 → 1.0.7
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/package.json
CHANGED
package/src/config/index.js
CHANGED
|
@@ -4,7 +4,8 @@ export {
|
|
|
4
4
|
getTextureOptions,
|
|
5
5
|
getDefaultTexture,
|
|
6
6
|
getSkyboxOptions,
|
|
7
|
-
getDefaultSkybox
|
|
7
|
+
getDefaultSkybox,
|
|
8
|
+
getTextureFallbackUrl
|
|
8
9
|
} from './textureConfig.js';
|
|
9
10
|
|
|
10
11
|
// runtime base helpers
|
|
@@ -12,4 +13,4 @@ export {
|
|
|
12
13
|
setPublicBase,
|
|
13
14
|
getPublicBase,
|
|
14
15
|
resolvePublicUrl
|
|
15
|
-
} from './env.js';
|
|
16
|
+
} from './env.js';
|
|
@@ -4,6 +4,32 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { resolvePublicUrl } from './env.js';
|
|
6
6
|
|
|
7
|
+
function buildTextureUrl(baseUrl, categoryPath, value) {
|
|
8
|
+
if (!value) return null;
|
|
9
|
+
if (/^https?:\/\//i.test(value)) return value;
|
|
10
|
+
if (value.startsWith('/')) return resolvePublicUrl(value);
|
|
11
|
+
const prefix = `${baseUrl || ''}${categoryPath || ''}`;
|
|
12
|
+
return resolvePublicUrl(`${prefix}/${value}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function findTextureItem(textureConfig, category, textureUrl) {
|
|
16
|
+
if (!textureUrl || !textureConfig) return null;
|
|
17
|
+
const categoryConfig = textureConfig.textures?.[category];
|
|
18
|
+
if (!categoryConfig || !categoryConfig.items) return null;
|
|
19
|
+
const baseUrl = textureConfig.baseUrl || '/default';
|
|
20
|
+
const categoryPath = categoryConfig.basePath || `/${category}`;
|
|
21
|
+
|
|
22
|
+
for (const item of categoryConfig.items) {
|
|
23
|
+
const resolved = buildTextureUrl(baseUrl, categoryPath, item.filename || item.id);
|
|
24
|
+
if (!resolved) continue;
|
|
25
|
+
if (resolved === textureUrl) {
|
|
26
|
+
return { item, baseUrl, categoryPath };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
7
33
|
let cachedConfig = null;
|
|
8
34
|
let configPromise = null;
|
|
9
35
|
let lastConfigUrl = null;
|
|
@@ -85,8 +111,10 @@ export async function getTextureOptions(category, config = null) {
|
|
|
85
111
|
|
|
86
112
|
categoryConfig.items.forEach(item => {
|
|
87
113
|
const key = item.label || item.id;
|
|
88
|
-
const
|
|
89
|
-
|
|
114
|
+
const resolved = buildTextureUrl(baseUrl, categoryPath, item.filename || item.id);
|
|
115
|
+
if (resolved) {
|
|
116
|
+
options[key] = resolved;
|
|
117
|
+
}
|
|
90
118
|
});
|
|
91
119
|
|
|
92
120
|
return options;
|
|
@@ -123,6 +151,21 @@ export async function getDefaultTexture(category, config = null) {
|
|
|
123
151
|
return null;
|
|
124
152
|
}
|
|
125
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Return the configured fallback URL for a given texture if defined.
|
|
156
|
+
* @param {string} category - Texture category (clouds, moons, etc.)
|
|
157
|
+
* @param {string} textureUrl - Resolved texture URL
|
|
158
|
+
* @param {Object|null} config - Optional texture config override
|
|
159
|
+
* @returns {string|null} Resolved fallback texture URL or null
|
|
160
|
+
*/
|
|
161
|
+
export function getTextureFallbackUrl(category, textureUrl, config = null) {
|
|
162
|
+
const textureConfig = config || cachedConfig;
|
|
163
|
+
if (!textureConfig) return null;
|
|
164
|
+
const found = findTextureItem(textureConfig, category, textureUrl);
|
|
165
|
+
if (!found || !found.item?.fallback) return null;
|
|
166
|
+
return buildTextureUrl(found.baseUrl, found.categoryPath, found.item.fallback);
|
|
167
|
+
}
|
|
168
|
+
|
|
126
169
|
/**
|
|
127
170
|
* Get texture by ID within a category
|
|
128
171
|
* @param {string} category - Texture category
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import { loadTexture } from '../loaders/bodyTextureLoader.js';
|
|
3
|
-
import {
|
|
3
|
+
import { resolvePublicUrl } from '../config/env.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function moonTexPath(file) {
|
|
6
|
+
return resolvePublicUrl(`default/textures/moons/${file}`);
|
|
7
|
+
}
|
|
8
8
|
export const DEFAULT_MOON_TEX_KTX2 = moonTexPath('moon-equirectangular.ktx2');
|
|
9
9
|
export const DEFAULT_MOON_TEX_PNG = moonTexPath('moon-equirectangular.png');
|
|
10
10
|
|
|
@@ -13,6 +13,7 @@ export async function generateMoons({
|
|
|
13
13
|
orbitRadius = 1.5,
|
|
14
14
|
textureKTX2 = DEFAULT_MOON_TEX_KTX2,
|
|
15
15
|
texturePNG = DEFAULT_MOON_TEX_PNG,
|
|
16
|
+
textureFallback = null,
|
|
16
17
|
useTexture = true,
|
|
17
18
|
// NEW: seed for deterministic positioning
|
|
18
19
|
seed = null, // if provided, ensures consistent moon positions
|
|
@@ -90,15 +91,8 @@ export async function generateMoons({
|
|
|
90
91
|
try { sharedTexture = await buildUvGridTexture(); usedUvGrid = true; } catch(_) {}
|
|
91
92
|
} else if (useTexture) {
|
|
92
93
|
// Use textureKey if provided, otherwise fall back to default textures
|
|
93
|
-
let primaryTexture = textureKey
|
|
94
|
-
const fallbackTexture = texturePNG;
|
|
95
|
-
|
|
96
|
-
// Resolve textureKey to absolute URL if it's relative
|
|
97
|
-
if (textureKey && textureKey.startsWith('/')) {
|
|
98
|
-
primaryTexture = `${HERBARIUM_BASE}${textureKey}`;
|
|
99
|
-
} else if (textureKey) {
|
|
100
|
-
primaryTexture = textureKey; // already absolute
|
|
101
|
-
}
|
|
94
|
+
let primaryTexture = textureKey ? resolvePublicUrl(textureKey) : textureKTX2;
|
|
95
|
+
const fallbackTexture = textureFallback || texturePNG;
|
|
102
96
|
|
|
103
97
|
try {
|
|
104
98
|
sharedTexture = await loadTexture(primaryTexture);
|
|
@@ -29,6 +29,7 @@ export class MoonsManager {
|
|
|
29
29
|
seed = null, // seed for deterministic positioning
|
|
30
30
|
textureKey = null, // NEW: specific texture key/path to use
|
|
31
31
|
moonColor = '#ffffff', // NEW: moon color
|
|
32
|
+
textureFallback = null,
|
|
32
33
|
} = opts;
|
|
33
34
|
|
|
34
35
|
let newGroup = null;
|
|
@@ -41,6 +42,7 @@ export class MoonsManager {
|
|
|
41
42
|
useTexture,
|
|
42
43
|
seed,
|
|
43
44
|
textureKey, // Pass texture key for custom moon textures
|
|
45
|
+
textureFallback,
|
|
44
46
|
moonColor, // Pass moon color to generator
|
|
45
47
|
});
|
|
46
48
|
} catch (e) {
|