@3driseai/3drise-viewer 0.1.12 → 0.1.13
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/components/EnvironmentManager.d.ts +3 -0
- package/dist/components/EnvironmentManager.d.ts.map +1 -1
- package/dist/components/EnvironmentManager.js +8 -3
- package/dist/components/SkyController.d.ts.map +1 -1
- package/dist/components/SkyController.js +20 -7
- package/dist/components/SkySystem.d.ts +12 -0
- package/dist/components/SkySystem.d.ts.map +1 -1
- package/dist/components/SkySystem.js +45 -9
- package/dist/components/Stars.d.ts.map +1 -1
- package/dist/components/Stars.js +5 -2
- package/dist/hooks/useEnvironmentProbe.d.ts +2 -1
- package/dist/hooks/useEnvironmentProbe.d.ts.map +1 -1
- package/dist/hooks/useSkySystem.d.ts.map +1 -1
- package/dist/hooks/useSkySystem.js +16 -9
- package/package.json +2 -2
|
@@ -61,6 +61,9 @@ export interface EnvironmentManagerProps extends ObjectReadyProps {
|
|
|
61
61
|
playerPosition?: Vector3;
|
|
62
62
|
onTimeOfDayChange?: SkySystemProps['onTimeOfDayChange'];
|
|
63
63
|
onTimeUpdate?: SkySystemProps['onTimeUpdate'];
|
|
64
|
+
/** False for a secondary canvas (preview, thumbnail) that must not take over
|
|
65
|
+
* the shared time-of-day clock. See SkySystemProps.driveTime. */
|
|
66
|
+
driveTime?: boolean;
|
|
64
67
|
}
|
|
65
68
|
declare const EnvironmentManager: React.ForwardRefExoticComponent<EnvironmentManagerProps & React.RefAttributes<SkySystemRef>>;
|
|
66
69
|
export default EnvironmentManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentManager.d.ts","sourceRoot":"","sources":["../../src/components/EnvironmentManager.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAkB,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc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B,CAAC;IACtC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,cAAc,CAAC,EAAE,wBAAwB,CAAC;IAC1C,eAAe,CAAC,EAAE,yBAAyB,CAAC;IAC5C,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,cAAc,CAAC,mBAAmB,CAAC,CAAC;IACxD,YAAY,CAAC,EAAE,cAAc,CAAC,cAAc,CAAC,CAAC;IAC9C;sEACkE;IAClE,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;AAoBD,QAAA,MAAM,kBAAkB,8FAwGtB,CAAC;AAGH,eAAe,kBAAkB,CAAC"}
|
|
@@ -23,7 +23,7 @@ const DEFAULT_HDR = {
|
|
|
23
23
|
},
|
|
24
24
|
};
|
|
25
25
|
const ORIGIN = new Vector3(0, 0, 0);
|
|
26
|
-
const EnvironmentManager = forwardRef(({ timeSettings, environment, hdrSettings, skySettings, cloudsSettings, terrainSettings, landscapeSettings, oceanSettings, fogSettings, cubeCameraResolution = 512, skyboxScale = 100000, playerPosition = ORIGIN, onTimeOfDayChange, onTimeUpdate, onObjectReady, onObjectDispose, }, ref) => {
|
|
26
|
+
const EnvironmentManager = forwardRef(({ timeSettings, environment, hdrSettings, skySettings, cloudsSettings, terrainSettings, landscapeSettings, oceanSettings, fogSettings, cubeCameraResolution = 512, skyboxScale = 100000, playerPosition = ORIGIN, onTimeOfDayChange, onTimeUpdate, driveTime = true, onObjectReady, onObjectDispose, }, ref) => {
|
|
27
27
|
const hdr = hdrSettings ?? environment?.hdr ?? DEFAULT_HDR;
|
|
28
28
|
const sky = skySettings ?? environment?.sky;
|
|
29
29
|
const clouds = cloudsSettings ?? environment?.clouds;
|
|
@@ -37,12 +37,17 @@ const EnvironmentManager = forwardRef(({ timeSettings, environment, hdrSettings,
|
|
|
37
37
|
const skyActive = !!sky?.visible || sunSystemVisible;
|
|
38
38
|
const sunIntensity = sky?.sunSystem?.intensity ?? 1;
|
|
39
39
|
useEnvironmentProbe({
|
|
40
|
+
// Real-time sync moves the sun just as much as autoAnimate does; gating
|
|
41
|
+
// the refresh on autoAnimate alone left the capture frozen at whatever
|
|
42
|
+
// the sky looked like when the probe was built, so reflections drifted
|
|
43
|
+
// out of step with the sky and popped when something else forced a
|
|
44
|
+
// capture.
|
|
45
|
+
autoAnimate: !!timeSettings.autoAnimate || !!timeSettings.syncWithRealTime,
|
|
40
46
|
hdrActive: isHdrActive(hdr),
|
|
41
47
|
skyActive,
|
|
42
|
-
autoAnimate: !!timeSettings.autoAnimate,
|
|
43
48
|
resolution: cubeCameraResolution,
|
|
44
49
|
});
|
|
45
|
-
return (_jsxs(_Fragment, { children: [_jsx(HdrEnvironment, { hdr: hdr, onObjectReady: onObjectReady, onObjectDispose: onObjectDispose }), _jsx(TerrainBuilder, { settings: terrain, skySettings: sky, timeSettings: timeSettings, sunIntensity: sunIntensity, onObjectReady: onObjectReady, onObjectDispose: onObjectDispose }), _jsx(LandscapeBuilder, { settings: landscape, onObjectReady: onObjectReady, onObjectDispose: onObjectDispose }), _jsx(OceanBuilder, { settings: ocean, skySettings: sky, timeSettings: timeSettings, sunIntensity: sunIntensity, onObjectReady: onObjectReady, onObjectDispose: onObjectDispose }), _jsx(SkySystem, { ref: ref, timeSettings: timeSettings, visible: true, sunSystemVisible: sunSystemVisible, sunSize: sky?.sunSystem?.sunSize, moonSize: sky?.sunSystem?.moonSize, skyboxScale: skyboxScale, sunIntensity: sunIntensity, castShadow: sky?.sunSystem?.castShadow, shadowMapSize: sky?.sunSystem?.shadowMapSize, playerPosition: playerPosition, cloudsSettings: clouds, skyControllerSettings: sky, fogSettings: fog, onTimeOfDayChange: onTimeOfDayChange, onTimeUpdate: onTimeUpdate, onObjectReady: onObjectReady, onObjectDispose: onObjectDispose })] }));
|
|
50
|
+
return (_jsxs(_Fragment, { children: [_jsx(HdrEnvironment, { hdr: hdr, onObjectReady: onObjectReady, onObjectDispose: onObjectDispose }), _jsx(TerrainBuilder, { settings: terrain, skySettings: sky, timeSettings: timeSettings, sunIntensity: sunIntensity, onObjectReady: onObjectReady, onObjectDispose: onObjectDispose }), _jsx(LandscapeBuilder, { settings: landscape, onObjectReady: onObjectReady, onObjectDispose: onObjectDispose }), _jsx(OceanBuilder, { settings: ocean, skySettings: sky, timeSettings: timeSettings, sunIntensity: sunIntensity, onObjectReady: onObjectReady, onObjectDispose: onObjectDispose }), _jsx(SkySystem, { ref: ref, timeSettings: timeSettings, driveTime: driveTime, visible: true, sunSystemVisible: sunSystemVisible, sunSize: sky?.sunSystem?.sunSize, moonSize: sky?.sunSystem?.moonSize, skyboxScale: skyboxScale, sunIntensity: sunIntensity, castShadow: sky?.sunSystem?.castShadow, shadowMapSize: sky?.sunSystem?.shadowMapSize, playerPosition: playerPosition, cloudsSettings: clouds, skyControllerSettings: sky, fogSettings: fog, onTimeOfDayChange: onTimeOfDayChange, onTimeUpdate: onTimeUpdate, onObjectReady: onObjectReady, onObjectDispose: onObjectDispose })] }));
|
|
46
51
|
});
|
|
47
52
|
EnvironmentManager.displayName = 'EnvironmentManager';
|
|
48
53
|
export default EnvironmentManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SkyController.d.ts","sourceRoot":"","sources":["../../src/components/SkyController.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAS7D,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEvE,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IACxD,QAAQ,EAAE,WAAW,CAAC;IACtB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,KAAK,IAAI,CAAC;CACtD;AAED,iBAAS,aAAa,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,GAAG,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"SkyController.d.ts","sourceRoot":"","sources":["../../src/components/SkyController.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAS7D,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEvE,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IACxD,QAAQ,EAAE,WAAW,CAAC;IACtB,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,KAAK,IAAI,CAAC;CACtD;AAED,iBAAS,aAAa,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,GAAG,EAAE,kBAAkB,GAqL8H,GAAG,CACtQ;AA6BD,eAAe,aAAa,CAAC"}
|
|
@@ -74,8 +74,15 @@ function SkyController({ settings, timeSettings, scale = 1000, onSettingsChange,
|
|
|
74
74
|
azimuth: sunAzimuth,
|
|
75
75
|
...atmosphericParams,
|
|
76
76
|
};
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
// While time is advancing, the environment probe is already re-capturing
|
|
78
|
+
// the cube map on its own timer. Letting handleSettings capture as well
|
|
79
|
+
// meant six faces rendered from two independent schedulers for the same
|
|
80
|
+
// moving sun.
|
|
81
|
+
const applied = handleSettings(newSettings, state.advancing);
|
|
82
|
+
// Only on a real change, and only when time is not running: this runs
|
|
83
|
+
// every frame now, and an unconditional call would dispatch a settings
|
|
84
|
+
// write per frame in a host that supplies this callback.
|
|
85
|
+
if (applied && !state.advancing) {
|
|
79
86
|
onSettingsChange?.(newSettings);
|
|
80
87
|
}
|
|
81
88
|
}, [settings, onSettingsChange]);
|
|
@@ -132,22 +139,28 @@ function SkyController({ settings, timeSettings, scale = 1000, onSettingsChange,
|
|
|
132
139
|
isAnimatingRef.current = false;
|
|
133
140
|
cubeCameraManager.updateEnvironment();
|
|
134
141
|
};
|
|
135
|
-
|
|
142
|
+
/** Returns whether the settings were actually applied, so callers can tell a
|
|
143
|
+
* real change from a no-op. `skipEnvUpdate` leaves the cube-camera capture
|
|
144
|
+
* to whoever else is already scheduling it. */
|
|
145
|
+
const handleSettings = (newSettings, skipEnvUpdate = false) => {
|
|
136
146
|
if (!skyRef.current || isAnimatingRef.current || !newSettings)
|
|
137
|
-
return;
|
|
147
|
+
return false;
|
|
138
148
|
if (!hasActualChanges(newSettings, previousSettings.current))
|
|
139
|
-
return;
|
|
149
|
+
return false;
|
|
140
150
|
if (previousSettings.current?.visible !== newSettings.visible) {
|
|
141
151
|
toggleSky(newSettings.visible);
|
|
142
152
|
}
|
|
143
153
|
if (!skyRef.current.visible) {
|
|
144
154
|
previousSettings.current = { ...newSettings };
|
|
145
|
-
return;
|
|
155
|
+
return false;
|
|
146
156
|
}
|
|
147
157
|
updateUniforms(newSettings);
|
|
148
158
|
updateSun();
|
|
149
|
-
|
|
159
|
+
if (!skipEnvUpdate) {
|
|
160
|
+
cubeCameraManager.updateEnvironment();
|
|
161
|
+
}
|
|
150
162
|
previousSettings.current = { ...newSettings };
|
|
163
|
+
return true;
|
|
151
164
|
};
|
|
152
165
|
const handleMouseMove = (mouse) => {
|
|
153
166
|
const handlers = settings.handlers;
|
|
@@ -48,6 +48,18 @@ export interface SkySystemProps extends ObjectReadyProps {
|
|
|
48
48
|
fogSettings?: FogSettings;
|
|
49
49
|
onTimeOfDayChange?: (timeOfDay: string, elapsedTime: number) => void;
|
|
50
50
|
onTimeUpdate?: (timeOfDay: number) => void;
|
|
51
|
+
/** Whether this instance drives skySystemManager's clock.
|
|
52
|
+
*
|
|
53
|
+
* The manager is a singleton, so every mounted SkySystem shares one clock.
|
|
54
|
+
* A second one that writes to it — a market preview, a thumbnail canvas,
|
|
55
|
+
* an embed on the same page — pushes its own timeSettings in and stops
|
|
56
|
+
* whatever the first one was doing. Pass false for any secondary canvas:
|
|
57
|
+
* it then renders the scene's real time of day instead of fighting for it.
|
|
58
|
+
*
|
|
59
|
+
* Defaulting to true is safe because the manager hands the clock to the
|
|
60
|
+
* first claimant only; a forgotten `driveTime={false}` degrades to a
|
|
61
|
+
* read-only mount rather than to two components ticking the same clock. */
|
|
62
|
+
driveTime?: boolean;
|
|
51
63
|
}
|
|
52
64
|
declare const SkySystem: React.ForwardRefExoticComponent<SkySystemProps & React.RefAttributes<SkySystemRef>>;
|
|
53
65
|
export default SkySystem;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SkySystem.d.ts","sourceRoot":"","sources":["../../src/components/SkySystem.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAOtE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,YAAY;IACzB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,KAAK,CAAC,OAAO,CAAC;CACx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IAAI,CAAC;IACnD,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,KAAK,CAAC,OAAO,CAAC;CACxC;AAED,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACpD,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;yDAEqD;IACrD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC;IAC/B;;;uBAGmB;IACnB,cAAc,CAAC,EAAE,wBAAwB,CAAC;IAC1C,qBAAqB,CAAC,EAAE,WAAW,CAAC;IACpC;wDACoD;IACpD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IACrE,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C;;;;;;;;;;gFAU4E;IAC5E,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,QAAA,MAAM,SAAS,qFAwJb,CAAC;AAGH,eAAe,SAAS,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useObjectReady } from '../hooks/useObjectReady.js';
|
|
3
|
-
import { useEffect, useLayoutEffect, useRef, forwardRef, useImperativeHandle } from 'react';
|
|
3
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, forwardRef, useImperativeHandle } from 'react';
|
|
4
4
|
import { useFrame } from '@react-three/fiber';
|
|
5
5
|
import { skySystemManager } from '@3driseai/3drise-core';
|
|
6
6
|
import Skybox from './Skybox.js';
|
|
@@ -9,10 +9,15 @@ import SunLight from './SunLight.js';
|
|
|
9
9
|
import SkyController from './SkyController.js';
|
|
10
10
|
import SceneFog from './SceneFog.js';
|
|
11
11
|
import CloudsGenerator from './CloudsGenerator.js';
|
|
12
|
-
const SkySystem = forwardRef(({ timeSettings, visible = true, sunSystemVisible = false, sunSize = 1, moonSize = 1, skyboxScale = 100000, sunIntensity = 1, castShadow = true, shadowMapSize = 2048, playerPosition, cloudsSettings, skyControllerSettings, fogSettings, onTimeOfDayChange, onTimeUpdate, onObjectReady, onObjectDispose, }, ref) => {
|
|
12
|
+
const SkySystem = forwardRef(({ timeSettings, visible = true, sunSystemVisible = false, sunSize = 1, moonSize = 1, skyboxScale = 100000, sunIntensity = 1, castShadow = true, shadowMapSize = 2048, playerPosition, cloudsSettings, skyControllerSettings, fogSettings, onTimeOfDayChange, onTimeUpdate, driveTime = true, onObjectReady, onObjectDispose, }, ref) => {
|
|
13
13
|
const previousTimeOfDayRef = useRef(null);
|
|
14
14
|
const rootRef = useRef(null);
|
|
15
15
|
const ready = { onObjectReady, onObjectDispose };
|
|
16
|
+
// Identity for the driver claim. A plain object rather than a boolean flag so
|
|
17
|
+
// the manager can tell instances apart and release the clock to the next one
|
|
18
|
+
// when this one unmounts.
|
|
19
|
+
const driverToken = useMemo(() => ({}), []);
|
|
20
|
+
const isDriverRef = useRef(false);
|
|
16
21
|
useObjectReady(rootRef, { timeSettings, sunSystemVisible, skyboxScale, sunIntensity, skyControllerSettings, fogSettings }, onObjectReady, onObjectDispose);
|
|
17
22
|
useImperativeHandle(ref, () => ({
|
|
18
23
|
setTime: (h, m) => skySystemManager.setTime(h, m),
|
|
@@ -20,20 +25,51 @@ const SkySystem = forwardRef(({ timeSettings, visible = true, sunSystemVisible =
|
|
|
20
25
|
getTimeOfDay: () => skySystemManager.getTimeOfDay(),
|
|
21
26
|
getSunDirection: () => skySystemManager.getSunDirection(),
|
|
22
27
|
}));
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
28
|
+
// Claim the clock before anything reads it. useLayoutEffect for the same
|
|
29
|
+
// reason the settings push below uses one — a regular useEffect runs after
|
|
30
|
+
// paint, and the first rAF would find the manager still disabled.
|
|
26
31
|
useLayoutEffect(() => {
|
|
32
|
+
if (!driveTime) {
|
|
33
|
+
isDriverRef.current = false;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
isDriverRef.current = skySystemManager.claimDriver(driverToken);
|
|
37
|
+
return () => {
|
|
38
|
+
isDriverRef.current = false;
|
|
39
|
+
skySystemManager.releaseDriver(driverToken);
|
|
40
|
+
};
|
|
41
|
+
}, [driveTime, driverToken]);
|
|
42
|
+
// Only the driver writes. This is the push half of the loop; the manager
|
|
43
|
+
// ignores a timeOfDay that is merely its own echo coming back through the
|
|
44
|
+
// host's store, so a write-back during playback does not rewind the clock.
|
|
45
|
+
useLayoutEffect(() => {
|
|
46
|
+
if (!isDriverRef.current)
|
|
47
|
+
return;
|
|
27
48
|
skySystemManager.setTimeSettings(timeSettings);
|
|
28
|
-
}, [timeSettings]);
|
|
49
|
+
}, [timeSettings, driveTime]);
|
|
29
50
|
useEffect(() => {
|
|
30
|
-
if (!onTimeUpdate)
|
|
51
|
+
if (!onTimeUpdate || !driveTime)
|
|
31
52
|
return;
|
|
32
53
|
skySystemManager.setOnTimeSync(onTimeUpdate);
|
|
33
54
|
return () => { skySystemManager.setOnTimeSync(null); };
|
|
34
|
-
}, [onTimeUpdate]);
|
|
55
|
+
}, [onTimeUpdate, driveTime]);
|
|
56
|
+
// Ticked whenever time is enabled, not only while it animates: `elapsedTime`
|
|
57
|
+
// and `delta` come out of here, and those are what every consumer's colour
|
|
58
|
+
// smoothing and the stars' twinkle read. Gating this on autoAnimate froze
|
|
59
|
+
// both and collapsed every smoothing lerp to an instant snap, which is what
|
|
60
|
+
// made each discontinuity in the sun curve so visible.
|
|
35
61
|
useFrame((_, delta) => {
|
|
36
|
-
if (!
|
|
62
|
+
if (!isDriverRef.current) {
|
|
63
|
+
// Pick the clock up if the instance that held it has gone (a preview
|
|
64
|
+
// canvas unmounting, an embed swapping scenes). Without this a
|
|
65
|
+
// failed claim at mount time would leave the clock permanently
|
|
66
|
+
// unowned and nothing would ever tick it again.
|
|
67
|
+
if (!driveTime || !skySystemManager.claimDriver(driverToken))
|
|
68
|
+
return;
|
|
69
|
+
isDriverRef.current = true;
|
|
70
|
+
skySystemManager.setTimeSettings(timeSettings);
|
|
71
|
+
}
|
|
72
|
+
if (!timeSettings.enabled)
|
|
37
73
|
return;
|
|
38
74
|
skySystemManager.tick(delta);
|
|
39
75
|
const current = skySystemManager.getTimeOfDay();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Stars.d.ts","sourceRoot":"","sources":["../../src/components/Stars.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,cAAc,EAA4C,MAAM,OAAO,CAAC;AAQjF,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,MAAM,WAAW,UAAW,SAAQ,gBAAgB;IAChD,QAAQ,EAAE,qBAAqB,CAAC;IAChC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAOD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAuDnE;AAYD,QAAA,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"Stars.d.ts","sourceRoot":"","sources":["../../src/components/Stars.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,cAAc,EAA4C,MAAM,OAAO,CAAC;AAQjF,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,MAAM,WAAW,UAAW,SAAQ,gBAAgB;IAChD,QAAQ,EAAE,qBAAqB,CAAC;IAChC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAOD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAuDnE;AAYD,QAAA,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,CA2K/B,CAAC;AACF,eAAe,KAAK,CAAC"}
|
package/dist/components/Stars.js
CHANGED
|
@@ -165,8 +165,11 @@ const Stars = ({ settings, timeSettings, sunSystemEnabled = false, onObjectReady
|
|
|
165
165
|
},
|
|
166
166
|
});
|
|
167
167
|
const handleTimeUpdate = useCallback((state) => {
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
// Not gated on autoAnimate any more: scrubbing the time slider to
|
|
169
|
+
// midnight has to bring the stars up the same way playing into midnight
|
|
170
|
+
// does, and elapsedTime (the twinkle clock) now advances in manual mode.
|
|
171
|
+
const { normalizedTime, isDaytime, elapsedTime, delta } = state;
|
|
172
|
+
if (!sunSystemEnabled)
|
|
170
173
|
return;
|
|
171
174
|
if (!isDaytime) {
|
|
172
175
|
targetOpacityRef.current = 1;
|
|
@@ -22,7 +22,8 @@ export interface UseEnvironmentProbeOptions {
|
|
|
22
22
|
hdrActive: boolean;
|
|
23
23
|
/** Analytic sky or the sun rig is visible — something worth capturing. */
|
|
24
24
|
skyActive: boolean;
|
|
25
|
-
/** Time of day is
|
|
25
|
+
/** Time of day is advancing — autoAnimate OR real-time sync — so the capture
|
|
26
|
+
* goes stale and needs refreshing. */
|
|
26
27
|
autoAnimate: boolean;
|
|
27
28
|
resolution?: number;
|
|
28
29
|
intervalMs?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEnvironmentProbe.d.ts","sourceRoot":"","sources":["../../src/hooks/useEnvironmentProbe.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,0BAA0B;IACvC,sEAAsE;IACtE,SAAS,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,SAAS,EAAE,OAAO,CAAC;IACnB
|
|
1
|
+
{"version":3,"file":"useEnvironmentProbe.d.ts","sourceRoot":"","sources":["../../src/hooks/useEnvironmentProbe.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,WAAW,0BAA0B;IACvC,sEAAsE;IACtE,SAAS,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,SAAS,EAAE,OAAO,CAAC;IACnB;2CACuC;IACvC,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,mBAAmB,CAAC,EAChC,SAAS,EACT,SAAS,EACT,WAAW,EACX,UAAgB,EAChB,UAAgB,GACnB,EAAE,0BAA0B,GAAG,IAAI,CA6BnC;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSkySystem.d.ts","sourceRoot":"","sources":["../../src/hooks/useSkySystem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAIpC,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACxF,YA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BAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IACrE,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC;IAC5B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACnD,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,KAAK,CAAC,OAAO,CAAC;CACxC;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,kBAAkB,CA6D7E;AACD,eAAe,YAAY,CAAC"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import { useRef, useCallback, useEffect
|
|
1
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
2
2
|
import { useFrame } from '@react-three/fiber';
|
|
3
3
|
import { skySystemManager } from '@3driseai/3drise-core';
|
|
4
4
|
export function useSkySystem(options) {
|
|
5
5
|
const { timeSettings, onTimeUpdate, onTimeOfDayChange, enabled = true } = options;
|
|
6
6
|
const previousTimeOfDayRef = useRef(null);
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
// READ-ONLY, deliberately. This hook used to push timeSettings into the
|
|
8
|
+
// manager as well, which meant every leaf that used it — Skybox, SunLight,
|
|
9
|
+
// SkyController, Stars, Clouds — was a writer to a singleton clock. A
|
|
10
|
+
// preview canvas mounting its own Skybox with its own timeSettings could
|
|
11
|
+
// therefore stop the editor's day cycle and snap it to noon, and nothing
|
|
12
|
+
// put it back. SkySystem owns the write now; see its `driveTime` prop.
|
|
13
|
+
//
|
|
14
|
+
// Ordering is fine without a layout effect here: React runs child layout
|
|
15
|
+
// effects before the parent's, so SkySystem's push lands before the first
|
|
16
|
+
// rAF either way, and the manual-mode branch below computes from the passed
|
|
17
|
+
// timeOfDay rather than from manager state.
|
|
13
18
|
// Manual time mode: respond immediately when timeOfDay changes
|
|
14
19
|
useEffect(() => {
|
|
15
20
|
if (!enabled || !timeSettings.enabled || timeSettings.autoAnimate)
|
|
@@ -22,9 +27,11 @@ export function useSkySystem(options) {
|
|
|
22
27
|
previousTimeOfDayRef.current = state.timeOfDay;
|
|
23
28
|
onTimeUpdate?.(state);
|
|
24
29
|
}, [timeSettings.timeOfDay, timeSettings.enabled, timeSettings.autoAnimate, enabled, onTimeUpdate, onTimeOfDayChange]);
|
|
25
|
-
//
|
|
30
|
+
// Read manager state every frame while time is enabled. Not gated on
|
|
31
|
+
// autoAnimate: `delta` and `elapsedTime` advance in manual mode too now, and
|
|
32
|
+
// consumers use them for colour smoothing and twinkle.
|
|
26
33
|
useFrame(() => {
|
|
27
|
-
if (!enabled || !timeSettings.enabled
|
|
34
|
+
if (!enabled || !timeSettings.enabled)
|
|
28
35
|
return;
|
|
29
36
|
const state = skySystemManager.getState();
|
|
30
37
|
if (previousTimeOfDayRef.current !== null &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@3driseai/3drise-viewer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,6 +39,6 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@3driseai/3drise-common": "^1.0.1",
|
|
42
|
-
"@3driseai/3drise-core": "^1.0.
|
|
42
|
+
"@3driseai/3drise-core": "^1.0.8"
|
|
43
43
|
}
|
|
44
44
|
}
|