@3driseai/3drise-core 1.0.21 → 1.0.23

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.
Files changed (179) hide show
  1. package/dist/autoAnimate/composer.d.ts +6 -0
  2. package/dist/autoAnimate/composer.d.ts.map +1 -1
  3. package/dist/autoAnimate/composer.js +4 -3
  4. package/dist/autoAnimate/describeScene.js +1 -1
  5. package/dist/catalog/catalogInfo.d.ts +22 -0
  6. package/dist/catalog/catalogInfo.d.ts.map +1 -0
  7. package/dist/catalog/catalogInfo.js +204 -0
  8. package/dist/catalog/index.d.ts +3 -0
  9. package/dist/catalog/index.d.ts.map +1 -0
  10. package/dist/catalog/index.js +2 -0
  11. package/dist/catalog/objectCatalog.d.ts +33 -0
  12. package/dist/catalog/objectCatalog.d.ts.map +1 -0
  13. package/dist/catalog/objectCatalog.js +94 -0
  14. package/dist/data/allMaterials.js +2 -2
  15. package/dist/data/defaults.d.ts +0 -12
  16. package/dist/data/defaults.d.ts.map +1 -1
  17. package/dist/data/defaults.js +0 -12
  18. package/dist/data/environmentDefaults.d.ts +10 -0
  19. package/dist/data/environmentDefaults.d.ts.map +1 -0
  20. package/dist/data/environmentDefaults.js +126 -0
  21. package/dist/data/gridsDefaults.d.ts +2 -0
  22. package/dist/data/gridsDefaults.d.ts.map +1 -1
  23. package/dist/data/gridsDefaults.js +57 -0
  24. package/dist/data/index.d.ts +4 -0
  25. package/dist/data/index.d.ts.map +1 -1
  26. package/dist/data/index.js +4 -0
  27. package/dist/data/landDefaults.d.ts +26 -0
  28. package/dist/data/landDefaults.d.ts.map +1 -0
  29. package/dist/data/landDefaults.js +76 -0
  30. package/dist/data/spaceDefaults.d.ts +10 -0
  31. package/dist/data/spaceDefaults.d.ts.map +1 -0
  32. package/dist/data/spaceDefaults.js +46 -0
  33. package/dist/data/textDefaults.d.ts +16 -0
  34. package/dist/data/textDefaults.d.ts.map +1 -0
  35. package/dist/data/textDefaults.js +219 -0
  36. package/dist/environment/oceanConfigs.d.ts +5 -4
  37. package/dist/environment/oceanConfigs.d.ts.map +1 -1
  38. package/dist/environment/oceanConfigs.js +2 -2
  39. package/dist/environment/terrainConfigs.d.ts +78 -0
  40. package/dist/environment/terrainConfigs.d.ts.map +1 -1
  41. package/dist/environment/terrainConfigs.js +72 -2
  42. package/dist/index.d.ts +3 -1
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +3 -1
  45. package/dist/properties/registry.d.ts +15 -1
  46. package/dist/properties/registry.d.ts.map +1 -1
  47. package/dist/properties/registry.js +99 -13
  48. package/dist/properties/tables/environmentProperties.d.ts +9 -0
  49. package/dist/properties/tables/environmentProperties.d.ts.map +1 -0
  50. package/dist/properties/tables/environmentProperties.js +127 -0
  51. package/dist/properties/tables/geometryProperties.d.ts +7 -0
  52. package/dist/properties/tables/geometryProperties.d.ts.map +1 -1
  53. package/dist/properties/tables/geometryProperties.js +9 -1
  54. package/dist/properties/tables/gridProperties.d.ts.map +1 -1
  55. package/dist/properties/tables/gridProperties.js +117 -93
  56. package/dist/properties/tables/index.d.ts +4 -0
  57. package/dist/properties/tables/index.d.ts.map +1 -1
  58. package/dist/properties/tables/index.js +4 -0
  59. package/dist/properties/tables/landProperties.d.ts +5 -0
  60. package/dist/properties/tables/landProperties.d.ts.map +1 -0
  61. package/dist/properties/tables/landProperties.js +24 -0
  62. package/dist/properties/tables/optionalProperties.d.ts +1 -2
  63. package/dist/properties/tables/optionalProperties.d.ts.map +1 -1
  64. package/dist/properties/tables/optionalProperties.js +22 -0
  65. package/dist/properties/tables/spaceProperties.d.ts +8 -0
  66. package/dist/properties/tables/spaceProperties.d.ts.map +1 -0
  67. package/dist/properties/tables/spaceProperties.js +42 -0
  68. package/dist/properties/tables/textProperties.d.ts +4 -0
  69. package/dist/properties/tables/textProperties.d.ts.map +1 -0
  70. package/dist/properties/tables/textProperties.js +387 -0
  71. package/dist/properties/types.d.ts +1 -1
  72. package/dist/properties/types.d.ts.map +1 -1
  73. package/dist/services/MaterialRegistry.d.ts.map +1 -1
  74. package/dist/services/MaterialRegistry.js +2 -0
  75. package/dist/services/SceneActions.d.ts +9 -0
  76. package/dist/services/SceneActions.d.ts.map +1 -1
  77. package/dist/services/SceneActions.js +30 -0
  78. package/dist/services/SkySystemManager.d.ts +22 -0
  79. package/dist/services/SkySystemManager.d.ts.map +1 -1
  80. package/dist/services/SkySystemManager.js +50 -18
  81. package/dist/services/TextureResolver.d.ts.map +1 -1
  82. package/dist/services/TextureResolver.js +22 -0
  83. package/dist/services/index.d.ts +1 -1
  84. package/dist/services/index.d.ts.map +1 -1
  85. package/dist/services/index.js +1 -1
  86. package/dist/shaders/SkyboxMaterial.js +3 -3
  87. package/dist/shaders/StarsMaterial.d.ts +5 -0
  88. package/dist/shaders/StarsMaterial.d.ts.map +1 -1
  89. package/dist/shaders/StarsMaterial.js +59 -57
  90. package/dist/three/LetterV.d.ts +7 -1
  91. package/dist/three/LetterV.d.ts.map +1 -1
  92. package/dist/three/Text2DV.d.ts +7 -1
  93. package/dist/three/Text2DV.d.ts.map +1 -1
  94. package/dist/three/Text3DV.d.ts +7 -1
  95. package/dist/three/Text3DV.d.ts.map +1 -1
  96. package/dist/types/actions.d.ts +6 -6
  97. package/dist/types/actions.d.ts.map +1 -1
  98. package/dist/types/commands.d.ts +61 -0
  99. package/dist/types/commands.d.ts.map +1 -0
  100. package/dist/types/commands.js +1 -0
  101. package/dist/types/environment.d.ts +34 -1
  102. package/dist/types/environment.d.ts.map +1 -1
  103. package/dist/types/environment.js +15 -0
  104. package/dist/types/environmentObjects.d.ts +152 -0
  105. package/dist/types/environmentObjects.d.ts.map +1 -0
  106. package/dist/types/environmentObjects.js +10 -0
  107. package/dist/types/index.d.ts +5 -2
  108. package/dist/types/index.d.ts.map +1 -1
  109. package/dist/types/landObjects.d.ts +15 -0
  110. package/dist/types/landObjects.d.ts.map +1 -0
  111. package/dist/types/landObjects.js +1 -0
  112. package/dist/types/objectSettings.d.ts +189 -16
  113. package/dist/types/objectSettings.d.ts.map +1 -1
  114. package/dist/types/objectsConfigs.d.ts +0 -3
  115. package/dist/types/objectsConfigs.d.ts.map +1 -1
  116. package/dist/types/scene3d.d.ts +12 -5
  117. package/dist/types/scene3d.d.ts.map +1 -1
  118. package/dist/types/spaceObjects.d.ts +65 -0
  119. package/dist/types/spaceObjects.d.ts.map +1 -0
  120. package/dist/types/spaceObjects.js +11 -0
  121. package/dist/types/textObjects.d.ts +371 -0
  122. package/dist/types/textObjects.d.ts.map +1 -0
  123. package/dist/types/textObjects.js +14 -0
  124. package/dist/types/types.d.ts +3 -6
  125. package/dist/types/types.d.ts.map +1 -1
  126. package/dist/types/users.d.ts +3 -1
  127. package/dist/types/users.d.ts.map +1 -1
  128. package/dist/types/users.js +2 -0
  129. package/dist/ui/index.d.ts +5 -0
  130. package/dist/ui/index.d.ts.map +1 -0
  131. package/dist/ui/index.js +4 -0
  132. package/dist/ui/uiBindings.d.ts +45 -0
  133. package/dist/ui/uiBindings.d.ts.map +1 -0
  134. package/dist/ui/uiBindings.js +172 -0
  135. package/dist/ui/uiKeys.d.ts +14 -0
  136. package/dist/ui/uiKeys.d.ts.map +1 -0
  137. package/dist/ui/uiKeys.js +22 -0
  138. package/dist/ui/uiSanitize.d.ts +18 -0
  139. package/dist/ui/uiSanitize.d.ts.map +1 -0
  140. package/dist/ui/uiSanitize.js +251 -0
  141. package/dist/ui/uiSpec.d.ts +116 -0
  142. package/dist/ui/uiSpec.d.ts.map +1 -0
  143. package/dist/ui/uiSpec.js +173 -0
  144. package/dist/utils/dataUtils.d.ts.map +1 -1
  145. package/dist/utils/dataUtils.js +0 -6
  146. package/dist/utils/environmentMigration.d.ts +3 -0
  147. package/dist/utils/environmentMigration.d.ts.map +1 -0
  148. package/dist/utils/environmentMigration.js +50 -0
  149. package/dist/utils/generativeAnimatable.d.ts +1 -1
  150. package/dist/utils/generativeAnimatable.d.ts.map +1 -1
  151. package/dist/utils/generativeAnimatable.js +12 -0
  152. package/dist/utils/getAnimatableProperties.d.ts +1 -1
  153. package/dist/utils/getAnimatableProperties.d.ts.map +1 -1
  154. package/dist/utils/getAnimatableProperties.js +1 -1
  155. package/dist/utils/gridMigration.d.ts +3 -0
  156. package/dist/utils/gridMigration.d.ts.map +1 -0
  157. package/dist/utils/gridMigration.js +34 -0
  158. package/dist/utils/index.d.ts +6 -0
  159. package/dist/utils/index.d.ts.map +1 -1
  160. package/dist/utils/index.js +6 -0
  161. package/dist/utils/objectEffects.d.ts +24 -2
  162. package/dist/utils/objectEffects.d.ts.map +1 -1
  163. package/dist/utils/objectEffects.js +28 -2
  164. package/dist/utils/objectMigration.d.ts +9 -0
  165. package/dist/utils/objectMigration.d.ts.map +1 -0
  166. package/dist/utils/objectMigration.js +13 -0
  167. package/dist/utils/skyPhase.d.ts +61 -0
  168. package/dist/utils/skyPhase.d.ts.map +1 -0
  169. package/dist/utils/skyPhase.js +93 -0
  170. package/dist/utils/spaceMigration.d.ts +3 -0
  171. package/dist/utils/spaceMigration.d.ts.map +1 -0
  172. package/dist/utils/spaceMigration.js +46 -0
  173. package/dist/utils/sunUtils.d.ts +26 -1
  174. package/dist/utils/sunUtils.d.ts.map +1 -1
  175. package/dist/utils/sunUtils.js +37 -6
  176. package/dist/utils/textMigration.d.ts +3 -0
  177. package/dist/utils/textMigration.d.ts.map +1 -0
  178. package/dist/utils/textMigration.js +56 -0
  179. package/package.json +1 -1
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Time-of-day phases, keyed by SUN ELEVATION — never by the clock.
3
+ *
4
+ * Everything that changes with the time of day (the Preetham atmosphere, star
5
+ * visibility, labels) reads these, so they all turn at the moment the sun
6
+ * actually crosses the horizon, whatever sunrise/sunset hours or sun model is in
7
+ * use. There used to be six hour tables that disagreed by up to 1.5 h.
8
+ *
9
+ * Keys, in degrees of sun elevation:
10
+ * night ≤ −12 (astronomical-ish: sky fully dark)
11
+ * twilight −4 (blue hour, sun just below the horizon)
12
+ * golden 3 (sun on the horizon: reddest, haziest)
13
+ * day ≥ 15
14
+ * Between two keys the weights cross-fade with a smoothstep; they always sum to 1.
15
+ */
16
+ export const SKY_PHASE_ELEVATIONS = { night: -12, twilight: -4, golden: 3, day: 15 };
17
+ /** Built-in atmospheres for the non-day phases. The day look is the user's own
18
+ * sky settings (see atmosphereForSunElevation). */
19
+ export const SKY_PHASE_ATMOSPHERES = {
20
+ night: { turbidity: 0.5, rayleigh: 0.1, mieCoefficient: 0.001, mieDirectionalG: 0.8 },
21
+ twilight: { turbidity: 2.5, rayleigh: 2.0, mieCoefficient: 0.008, mieDirectionalG: 0.86 },
22
+ golden: { turbidity: 4.5, rayleigh: 3.5, mieCoefficient: 0.012, mieDirectionalG: 0.92 },
23
+ };
24
+ const smooth = (t) => {
25
+ const c = Math.max(0, Math.min(1, t));
26
+ return c * c * (3 - 2 * c);
27
+ };
28
+ /** Phase weights for a sun elevation in degrees. Sum to 1. */
29
+ export function skyPhaseWeights(sunElevation, out) {
30
+ const w = out ?? { night: 0, twilight: 0, golden: 0, day: 0 };
31
+ w.night = 0;
32
+ w.twilight = 0;
33
+ w.golden = 0;
34
+ w.day = 0;
35
+ const { night, twilight, golden, day } = SKY_PHASE_ELEVATIONS;
36
+ if (sunElevation <= night) {
37
+ w.night = 1;
38
+ return w;
39
+ }
40
+ if (sunElevation >= day) {
41
+ w.day = 1;
42
+ return w;
43
+ }
44
+ if (sunElevation < twilight) {
45
+ const t = smooth((sunElevation - night) / (twilight - night));
46
+ w.night = 1 - t;
47
+ w.twilight = t;
48
+ }
49
+ else if (sunElevation < golden) {
50
+ const t = smooth((sunElevation - twilight) / (golden - twilight));
51
+ w.twilight = 1 - t;
52
+ w.golden = t;
53
+ }
54
+ else {
55
+ const t = smooth((sunElevation - golden) / (day - golden));
56
+ w.golden = 1 - t;
57
+ w.day = t;
58
+ }
59
+ return w;
60
+ }
61
+ /**
62
+ * The Preetham atmosphere for a sun elevation: the user's `day` look by day,
63
+ * blended through golden hour and twilight into night as the sun goes down.
64
+ * The user's sliders, keyframes and pointer bindings keep working with the clock
65
+ * on — they shape the day, and time of day adds the evening around it.
66
+ */
67
+ export function atmosphereForSunElevation(sunElevation, day, out) {
68
+ const w = skyPhaseWeights(sunElevation);
69
+ const { night: n, twilight: t, golden: g } = SKY_PHASE_ATMOSPHERES;
70
+ const o = out ?? { turbidity: 0, rayleigh: 0, mieCoefficient: 0, mieDirectionalG: 0 };
71
+ o.turbidity = w.night * n.turbidity + w.twilight * t.turbidity + w.golden * g.turbidity + w.day * day.turbidity;
72
+ o.rayleigh = w.night * n.rayleigh + w.twilight * t.rayleigh + w.golden * g.rayleigh + w.day * day.rayleigh;
73
+ o.mieCoefficient = w.night * n.mieCoefficient + w.twilight * t.mieCoefficient + w.golden * g.mieCoefficient + w.day * day.mieCoefficient;
74
+ o.mieDirectionalG = w.night * n.mieDirectionalG + w.twilight * t.mieDirectionalG + w.golden * g.mieDirectionalG + w.day * day.mieDirectionalG;
75
+ return o;
76
+ }
77
+ /** How visible the night sky is (stars, moon halo): 0 by day, 1 once the sun is
78
+ * 12° down. */
79
+ export function nightAmount(sunElevation) {
80
+ const w = skyPhaseWeights(sunElevation);
81
+ return w.night + w.twilight * 0.5;
82
+ }
83
+ /**
84
+ * How bright the sky dome is drawn, 1 by day. Preetham alone never gets darker
85
+ * than a flat grey after sunset (its constant 0.1 base term), so the night reads
86
+ * as overcast dusk instead of night. SkyMesh multiplies its output by this.
87
+ */
88
+ export const SKY_PHASE_BRIGHTNESS = { night: 0.08, twilight: 0.5, golden: 1, day: 1 };
89
+ export function skyBrightnessForSunElevation(sunElevation) {
90
+ const w = skyPhaseWeights(sunElevation);
91
+ const b = SKY_PHASE_BRIGHTNESS;
92
+ return w.night * b.night + w.twilight * b.twilight + w.golden * b.golden + w.day * b.day;
93
+ }
@@ -0,0 +1,3 @@
1
+ import type { CreatedObjectSettings } from '../types/scene3d';
2
+ export declare function migrateSpaceObject<T extends CreatedObjectSettings>(obj: T): T;
3
+ //# sourceMappingURL=spaceMigration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spaceMigration.d.ts","sourceRoot":"","sources":["../../src/utils/spaceMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAsB9D,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,qBAAqB,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CA2B7E"}
@@ -0,0 +1,46 @@
1
+ // =============================================================================
2
+ // Space objects — load-time migration of the legacy config
3
+ // =============================================================================
4
+ //
5
+ // The old starfield spun itself through a `rotateSpeed` knob (rotation.y +=
6
+ // rotateSpeed * 0.01 every frame). Spinning the whole object is the parent's
7
+ // transform, so the knob is gone from the space family; a saved starfield that
8
+ // had it gets the equivalent transform 'spin' effect instead (rad/s at 60 fps),
9
+ // unless it already animates its transform (a rotation effect, or keyframes: an
10
+ // enabled transform effect would switch those off). The dead `size` / `sep` keys (never
11
+ // read by the renderer) are dropped too.
12
+ //
13
+ // Pure and idempotent: returns the same object when there is nothing to migrate,
14
+ // so it can run on every load without marking anything dirty.
15
+ //
16
+ const ROTATION_EFFECTS = new Set(['rotate3d', 'spin', 'sway', 'flip']);
17
+ /** The old per-frame step (0.01 rad per unit) at 60 frames per second. */
18
+ const LEGACY_FRAMES_PER_SECOND = 60;
19
+ export function migrateSpaceObject(obj) {
20
+ if (!obj || obj.type !== 'space')
21
+ return obj;
22
+ const config = obj.config;
23
+ if (!config || config.type !== 'stars')
24
+ return obj;
25
+ if (!('rotateSpeed' in config) && !('size' in config) && !('sep' in config))
26
+ return obj;
27
+ const { rotateSpeed, size: _size, sep: _sep, ...rest } = config;
28
+ const next = { ...obj, config: rest };
29
+ const speed = typeof rotateSpeed === 'number' ? rotateSpeed * 0.01 * LEGACY_FRAMES_PER_SECOND : 0;
30
+ if (speed > 0) {
31
+ const animations = obj.animations ?? {};
32
+ const transform = animations.transform ?? {};
33
+ const effects = transform.effects ?? [];
34
+ const keyframed = (transform.animations?.length ?? 0) > 0;
35
+ if (!keyframed && !effects.some(e => ROTATION_EFFECTS.has(e?.type))) {
36
+ const hasOther = Object.entries(animations).some(([k, v]) => k !== 'enabled' && v && ((v.animations?.length ?? 0) > 0 || (v.effects?.length ?? 0) > 0));
37
+ next.animations = {
38
+ ...animations,
39
+ // Switch the animations on only when nothing else is there that the user may have turned off.
40
+ enabled: hasOther ? (animations.enabled ?? true) : true,
41
+ transform: { ...transform, effects: [...effects, { type: 'spin', enabled: true, speed, options: { axis: 'y' } }] },
42
+ };
43
+ }
44
+ }
45
+ return next;
46
+ }
@@ -1,6 +1,31 @@
1
- export declare function createSunPosition(elevation: number, azimuth: number): {
1
+ /**
2
+ * THE sun direction convention for 3drise. Every piece that turns an
3
+ * elevation/azimuth pair into a direction — the Preetham sky, the key light,
4
+ * the day-cycle clock, the clouds, the ocean, the terrain, the lighting rig —
5
+ * goes through `sunDirectionFromAngles`, so the sun that is drawn and the sun
6
+ * that lights the scene cannot disagree.
7
+ *
8
+ * elevation degrees above the horizon (90 = straight up, negative = below)
9
+ * azimuth degrees around +Y, measured from +X towards +Z
10
+ * (0 → +X, 90 → +Z, 180 → −X, −90 → −Z)
11
+ *
12
+ * There used to be two conventions: this one (Preetham sky, LightsManager) and
13
+ * x = sin(az), z = cos(az) (the clock, the skybox shader, useCloudSun), which
14
+ * mirrored the lit sun across the x = z plane — up to 137° away from the disc.
15
+ */
16
+ export interface Vec3Like {
2
17
  x: number;
3
18
  y: number;
4
19
  z: number;
20
+ }
21
+ /** Unit vector toward the sun. Writes into `out` when given (a THREE.Vector3
22
+ * works), so per-frame callers allocate nothing. */
23
+ export declare function sunDirectionFromAngles<T extends Vec3Like = Vec3Like>(elevation: number, azimuth: number, out?: T): T;
24
+ /** Inverse of `sunDirectionFromAngles`. The vector need not be normalised. */
25
+ export declare function sunAnglesFromDirection(dir: Vec3Like): {
26
+ elevation: number;
27
+ azimuth: number;
5
28
  };
29
+ /** Kept for existing callers; same convention. */
30
+ export declare function createSunPosition(elevation: number, azimuth: number): Vec3Like;
6
31
  //# sourceMappingURL=sunUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sunUtils.d.ts","sourceRoot":"","sources":["../../src/utils/sunUtils.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG;IAC/D,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACb,CAQJ"}
1
+ {"version":3,"file":"sunUtils.d.ts","sourceRoot":"","sources":["../../src/utils/sunUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,WAAW,QAAQ;IACrB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACb;AAID;qDACqD;AACrD,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CASpH;AAED,8EAA8E;AAC9E,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,QAAQ,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAM5F;AAED,kDAAkD;AAClD,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,CAE9E"}
@@ -1,9 +1,40 @@
1
- export function createSunPosition(elevation, azimuth) {
2
- const phi = (90 - elevation) * (Math.PI / 180);
3
- const theta = azimuth * (Math.PI / 180);
1
+ /**
2
+ * THE sun direction convention for 3drise. Every piece that turns an
3
+ * elevation/azimuth pair into a direction — the Preetham sky, the key light,
4
+ * the day-cycle clock, the clouds, the ocean, the terrain, the lighting rig —
5
+ * goes through `sunDirectionFromAngles`, so the sun that is drawn and the sun
6
+ * that lights the scene cannot disagree.
7
+ *
8
+ * elevation degrees above the horizon (90 = straight up, negative = below)
9
+ * azimuth degrees around +Y, measured from +X towards +Z
10
+ * (0 → +X, 90 → +Z, 180 → −X, −90 → −Z)
11
+ *
12
+ * There used to be two conventions: this one (Preetham sky, LightsManager) and
13
+ * x = sin(az), z = cos(az) (the clock, the skybox shader, useCloudSun), which
14
+ * mirrored the lit sun across the x = z plane — up to 137° away from the disc.
15
+ */
16
+ const DEG = Math.PI / 180;
17
+ /** Unit vector toward the sun. Writes into `out` when given (a THREE.Vector3
18
+ * works), so per-frame callers allocate nothing. */
19
+ export function sunDirectionFromAngles(elevation, azimuth, out) {
20
+ const el = elevation * DEG;
21
+ const az = azimuth * DEG;
22
+ const c = Math.cos(el);
23
+ const target = (out ?? { x: 0, y: 0, z: 0 });
24
+ target.x = c * Math.cos(az);
25
+ target.y = Math.sin(el);
26
+ target.z = c * Math.sin(az);
27
+ return target;
28
+ }
29
+ /** Inverse of `sunDirectionFromAngles`. The vector need not be normalised. */
30
+ export function sunAnglesFromDirection(dir) {
31
+ const r = Math.sqrt(dir.x * dir.x + dir.y * dir.y + dir.z * dir.z) || 1;
4
32
  return {
5
- x: Math.sin(phi) * Math.cos(theta),
6
- y: Math.cos(phi),
7
- z: Math.sin(phi) * Math.sin(theta),
33
+ elevation: Math.asin(Math.max(-1, Math.min(1, dir.y / r))) / DEG,
34
+ azimuth: Math.atan2(dir.z, dir.x) / DEG,
8
35
  };
9
36
  }
37
+ /** Kept for existing callers; same convention. */
38
+ export function createSunPosition(elevation, azimuth) {
39
+ return sunDirectionFromAngles(elevation, azimuth);
40
+ }
@@ -0,0 +1,3 @@
1
+ import type { CreatedObjectSettings } from '../types/scene3d';
2
+ export declare function migrateTextObject<T extends CreatedObjectSettings>(obj: T): T;
3
+ //# sourceMappingURL=textMigration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textMigration.d.ts","sourceRoot":"","sources":["../../src/utils/textMigration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAqB9D,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,qBAAqB,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAuC5E"}
@@ -0,0 +1,56 @@
1
+ import { DEFAULT_TEXT_OBJECTS, TEXT_FONTS } from '../data/textDefaults.js';
2
+ // =============================================================================
3
+ // Text — load-time migration of the legacy 2d (bitmap) / 3d text
4
+ // =============================================================================
5
+ //
6
+ // Object type 'text' used to host two renderers told apart by `config.renderMode` and carrying no
7
+ // `config.type`: a troika bitmap text ('bitmap') and a per-letter extruded text ('text3d'). Both are gone:
8
+ // bitmap → the `plain` text look (same object type; the material colour / opacity become the look's own
9
+ // knobs, the em size matches so a 0.5 fontSize keeps its size and any other scales the transform)
10
+ // text3d → the `text` shape of the mesh family (object type 'mesh'), which keeps its material and bevel
11
+ // Fonts the packed font list does not know fall back to the default face.
12
+ //
13
+ // Pure and idempotent: a text with a config.type is already in the new shape and is returned as is.
14
+ //
15
+ const KNOWN_FONTS = new Set(TEXT_FONTS.map((f) => f.id));
16
+ const fontOf = (font) => (typeof font === 'string' && KNOWN_FONTS.has(font) ? font : 'inter');
17
+ const num = (v, d) => (typeof v === 'number' && Number.isFinite(v) ? v : d);
18
+ export function migrateTextObject(obj) {
19
+ if (!obj || obj.type !== 'text')
20
+ return obj;
21
+ const config = (obj.config ?? {});
22
+ if (typeof config.type === 'string' && config.type in DEFAULT_TEXT_OBJECTS)
23
+ return obj;
24
+ const text = typeof config.text === 'string' ? config.text : 'Hello';
25
+ const font = fontOf(config.font);
26
+ const material = (obj.materialSettings ?? {});
27
+ if (config.renderMode === 'text3d') {
28
+ const bevel = config.bevelEnabled !== false;
29
+ return {
30
+ ...obj,
31
+ type: 'mesh',
32
+ config: {
33
+ type: 'text', text, font,
34
+ size: num(config.size, 1), height: num(config.height, 0.2), letterSpacing: num(config.letterSpacing, 0),
35
+ bevelEnabled: bevel, bevelThickness: num(config.bevelThickness, 0.02), bevelSize: num(config.bevelSize, 0.015), bevelSegments: num(config.bevelSegments, 3),
36
+ },
37
+ };
38
+ }
39
+ // bitmap (or no renderMode at all) → plain look
40
+ const next = {
41
+ ...obj,
42
+ config: {
43
+ ...DEFAULT_TEXT_OBJECTS.plain, text, font,
44
+ ...(typeof material.color === 'string' ? { color: material.color } : {}),
45
+ ...(typeof material.opacity === 'number' ? { opacity: material.opacity } : {}),
46
+ },
47
+ };
48
+ const fontSize = num(config.fontSize, 0.5);
49
+ if (Math.abs(fontSize - 0.5) > 1e-6) {
50
+ const k = fontSize / 0.5;
51
+ const ms = obj.meshSettings ?? {};
52
+ const sc = Array.isArray(ms.scale) && ms.scale.length === 3 ? ms.scale : [1, 1, 1];
53
+ next.meshSettings = { ...ms, scale: sc.map((v) => v * k) };
54
+ }
55
+ return next;
56
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3driseai/3drise-core",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",