@juun-roh/cesium-utils 0.2.7 → 0.3.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/README.md CHANGED
@@ -106,6 +106,17 @@ Additional utilities for advanced usage:
106
106
  import { Deprecate, TerrainVisualizer, isGetterOnly } from "@juun-roh/cesium-utils/dev";
107
107
  ```
108
108
 
109
+ ### Experimental Features
110
+
111
+ ⚠️ **Warning**: Experimental features use Cesium's internal APIs and may break in future versions.
112
+
113
+ ```typescript
114
+ import Sunlight from "@juun-roh/cesium-utils/experimental/sunlight";
115
+
116
+ const sunlight = new Sunlight(viewer);
117
+ const result = sunlight.analyze(point, JulianDate.now());
118
+ ```
119
+
109
120
  ## License
110
121
 
111
122
  MIT © Juun
@@ -0,0 +1 @@
1
+ "use strict";var y=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var b=(r,t)=>{for(var e in t)y(r,e,{get:t[e],enumerable:!0})},C=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of m(t))!S.call(r,s)&&s!==e&&y(r,s,{get:()=>t[s],enumerable:!(i=v(t,s))||i.enumerable});return r};var f=r=>C(y({},"__esModule",{value:!0}),r);var E={};b(E,{Sunlight:()=>g});module.exports=f(E);var o=require("cesium"),n=require("cesium"),d=class{_sunPositionWC;_sunDirectionWC;_viewer;_analyzing=!1;_pointEntityId;_debugEntities=[];constructor(t){let{sunPositionWC:e,sunDirectionWC:i}=t.scene.context.uniformState;this._sunPositionWC=e,this._sunDirectionWC=i,this._viewer=t}get sunPositionWC(){return this._sunPositionWC}get sunDirectionWC(){return this._sunDirectionWC}get isAnalyzing(){return this._analyzing}getVirtualSunPosition(t,e=1e3){let i=n.Cartesian3.normalize(n.Cartesian3.subtract(this._sunPositionWC,t,new n.Cartesian3),new n.Cartesian3);return n.Cartesian3.multiplyByScalar(i,e,i),n.Cartesian3.add(t,i,new n.Cartesian3)}analyze(t,e,i){let s=[],c=!this._analyzing,p=c?this._viewer.clock.currentTime.clone():void 0;c&&(this._viewer.entities.add(this._createPointEntity(t,i?.debugShowPoints,i?.errorBoundary)),this._analyzing=!0);try{if(e instanceof n.JulianDate){this._viewer.clock.currentTime=e,this._viewer.scene.render();let h=new o.Ray(this.getVirtualSunPosition(t),this._sunDirectionWC),l=this._viewer.scene.picking,{object:u,position:a}=l.pickFromRay(l,this._viewer.scene,h,i?.objectsToExclude),w=u instanceof o.Entity&&u.id===this._pointEntityId;if(i?.debugShowPoints&&a){let _=new o.Entity({point:{show:!0,pixelSize:5},position:a});this._viewer.entities.add(_),this._debugEntities.push(_)}return{timestamp:e.toString(),result:w}}else{let{start:h,end:l,step:u}=e,a=h.clone();for(;n.JulianDate.compare(a,l)<=0;)s.push(this.analyze(t,a,i)),n.JulianDate.addSeconds(a,u,a)}}finally{c&&p&&(this._viewer.clock.currentTime=p,this._viewer.scene.render(),this._analyzing=!1,this._pointEntityId&&!i?.debugShowPoints&&this._viewer.entities.removeById(this._pointEntityId))}return s}_createPointEntity(t,e,i){let s=new o.Entity({point:{show:e,pixelSize:i??5},position:t});return this._pointEntityId=s.id,s}clear(){this._debugEntities.forEach(t=>{this._viewer.entities.contains(t)&&this._viewer.entities.remove(t)}),this._debugEntities=[],this._pointEntityId&&this._viewer.entities.getById(this._pointEntityId)&&this._viewer.entities.removeById(this._pointEntityId)}},g=d;
@@ -0,0 +1,92 @@
1
+ import { Viewer, Cartesian3, JulianDate } from 'cesium';
2
+
3
+ /**
4
+ * @since Cesium 1.132.0
5
+ * @experimental
6
+ * Point sunlight analysis utility for shadow calculations.
7
+ *
8
+ * ⚠️ **Warning**: This is an experimental feature that uses Cesium's internal APIs.
9
+ * The API may change or break in future versions of Cesium or cesium-utils.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const sunlight = new Sunlight(viewer);
14
+ * sunlight.analyze(point, JulianDate.now());
15
+ * ```
16
+ */
17
+ declare class Sunlight {
18
+ private _sunPositionWC;
19
+ private _sunDirectionWC;
20
+ private _viewer;
21
+ private _analyzing;
22
+ private _pointEntityId?;
23
+ private _debugEntities;
24
+ constructor(viewer: Viewer);
25
+ /** The sun position in 3D world coordinates at the current scene time. */
26
+ get sunPositionWC(): Cartesian3;
27
+ /** A normalized vector to the sun in 3D world coordinates at the current scene time. */
28
+ get sunDirectionWC(): Cartesian3;
29
+ /** Whether sunlight analysis is currently in progress. */
30
+ get isAnalyzing(): boolean;
31
+ /**
32
+ * Gets a virtual position of the sun to reduce calculation overhead.
33
+ *
34
+ * @param from target point to start from
35
+ * @param radius virtual distance between target point and the sun. Defaults to 1000 (1km)
36
+ */
37
+ getVirtualSunPosition(from: Cartesian3, radius?: number): Cartesian3;
38
+ /**
39
+ * Analyze the sunlight acceptance from a given point at a given time.
40
+ * @param from target point to analyze
41
+ * @param at time to analyze
42
+ * @param options {@link Sunlight.AnalyzeOptions}
43
+ */
44
+ analyze(from: Cartesian3, at: JulianDate, options?: Sunlight.AnalyzeOptions): Sunlight.AnalysisResult;
45
+ /**
46
+ * Analyze the sunlight acceptance from a given point at a given time range.
47
+ * @param from target point to analyze
48
+ * @param range time range to analyze
49
+ * @param options {@link Sunlight.AnalyzeOptions}
50
+ */
51
+ analyze(from: Cartesian3, range: Sunlight.TimeRange, options?: Sunlight.AnalyzeOptions): Sunlight.AnalysisResult[];
52
+ /**
53
+ * Create a point entity for collision detection
54
+ * @param at where to create the entity
55
+ * @param show whether to show point entity
56
+ * @param errorBoundary size of the point entity for error tolerance
57
+ */
58
+ private _createPointEntity;
59
+ /**
60
+ * Remove all instances created for debug purpose
61
+ */
62
+ clear(): void;
63
+ }
64
+ declare namespace Sunlight {
65
+ /** for time-range analysis */
66
+ interface TimeRange {
67
+ /** When to start analysis */
68
+ start: JulianDate;
69
+ /** When to end analysis */
70
+ end: JulianDate;
71
+ /** Step interval (seconds) inside the range */
72
+ step: number;
73
+ }
74
+ interface AnalyzeOptions {
75
+ /** List of objects to exclude from ray pick */
76
+ objectsToExclude?: any[];
77
+ /** size of the point entity for error tolerance */
78
+ errorBoundary?: number;
79
+ /** Whether to show sunlight paths, NOT IMPLEMENTED YET */
80
+ debugShowRays?: boolean;
81
+ /** Whether to show points */
82
+ debugShowPoints?: boolean;
83
+ }
84
+ interface AnalysisResult {
85
+ /** ISO time string */
86
+ timestamp: string;
87
+ /** Whether the sunlight has reached */
88
+ result: boolean;
89
+ }
90
+ }
91
+
92
+ export { Sunlight };
@@ -0,0 +1,92 @@
1
+ import { Viewer, Cartesian3, JulianDate } from 'cesium';
2
+
3
+ /**
4
+ * @since Cesium 1.132.0
5
+ * @experimental
6
+ * Point sunlight analysis utility for shadow calculations.
7
+ *
8
+ * ⚠️ **Warning**: This is an experimental feature that uses Cesium's internal APIs.
9
+ * The API may change or break in future versions of Cesium or cesium-utils.
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const sunlight = new Sunlight(viewer);
14
+ * sunlight.analyze(point, JulianDate.now());
15
+ * ```
16
+ */
17
+ declare class Sunlight {
18
+ private _sunPositionWC;
19
+ private _sunDirectionWC;
20
+ private _viewer;
21
+ private _analyzing;
22
+ private _pointEntityId?;
23
+ private _debugEntities;
24
+ constructor(viewer: Viewer);
25
+ /** The sun position in 3D world coordinates at the current scene time. */
26
+ get sunPositionWC(): Cartesian3;
27
+ /** A normalized vector to the sun in 3D world coordinates at the current scene time. */
28
+ get sunDirectionWC(): Cartesian3;
29
+ /** Whether sunlight analysis is currently in progress. */
30
+ get isAnalyzing(): boolean;
31
+ /**
32
+ * Gets a virtual position of the sun to reduce calculation overhead.
33
+ *
34
+ * @param from target point to start from
35
+ * @param radius virtual distance between target point and the sun. Defaults to 1000 (1km)
36
+ */
37
+ getVirtualSunPosition(from: Cartesian3, radius?: number): Cartesian3;
38
+ /**
39
+ * Analyze the sunlight acceptance from a given point at a given time.
40
+ * @param from target point to analyze
41
+ * @param at time to analyze
42
+ * @param options {@link Sunlight.AnalyzeOptions}
43
+ */
44
+ analyze(from: Cartesian3, at: JulianDate, options?: Sunlight.AnalyzeOptions): Sunlight.AnalysisResult;
45
+ /**
46
+ * Analyze the sunlight acceptance from a given point at a given time range.
47
+ * @param from target point to analyze
48
+ * @param range time range to analyze
49
+ * @param options {@link Sunlight.AnalyzeOptions}
50
+ */
51
+ analyze(from: Cartesian3, range: Sunlight.TimeRange, options?: Sunlight.AnalyzeOptions): Sunlight.AnalysisResult[];
52
+ /**
53
+ * Create a point entity for collision detection
54
+ * @param at where to create the entity
55
+ * @param show whether to show point entity
56
+ * @param errorBoundary size of the point entity for error tolerance
57
+ */
58
+ private _createPointEntity;
59
+ /**
60
+ * Remove all instances created for debug purpose
61
+ */
62
+ clear(): void;
63
+ }
64
+ declare namespace Sunlight {
65
+ /** for time-range analysis */
66
+ interface TimeRange {
67
+ /** When to start analysis */
68
+ start: JulianDate;
69
+ /** When to end analysis */
70
+ end: JulianDate;
71
+ /** Step interval (seconds) inside the range */
72
+ step: number;
73
+ }
74
+ interface AnalyzeOptions {
75
+ /** List of objects to exclude from ray pick */
76
+ objectsToExclude?: any[];
77
+ /** size of the point entity for error tolerance */
78
+ errorBoundary?: number;
79
+ /** Whether to show sunlight paths, NOT IMPLEMENTED YET */
80
+ debugShowRays?: boolean;
81
+ /** Whether to show points */
82
+ debugShowPoints?: boolean;
83
+ }
84
+ interface AnalysisResult {
85
+ /** ISO time string */
86
+ timestamp: string;
87
+ /** Whether the sunlight has reached */
88
+ result: boolean;
89
+ }
90
+ }
91
+
92
+ export { Sunlight };
@@ -0,0 +1 @@
1
+ import{Entity as c,Ray as g}from"cesium";import{Cartesian3 as s,JulianDate as h}from"cesium";var y=class{_sunPositionWC;_sunDirectionWC;_viewer;_analyzing=!1;_pointEntityId;_debugEntities=[];constructor(t){let{sunPositionWC:e,sunDirectionWC:i}=t.scene.context.uniformState;this._sunPositionWC=e,this._sunDirectionWC=i,this._viewer=t}get sunPositionWC(){return this._sunPositionWC}get sunDirectionWC(){return this._sunDirectionWC}get isAnalyzing(){return this._analyzing}getVirtualSunPosition(t,e=1e3){let i=s.normalize(s.subtract(this._sunPositionWC,t,new s),new s);return s.multiplyByScalar(i,e,i),s.add(t,i,new s)}analyze(t,e,i){let r=[],l=!this._analyzing,d=l?this._viewer.clock.currentTime.clone():void 0;l&&(this._viewer.entities.add(this._createPointEntity(t,i?.debugShowPoints,i?.errorBoundary)),this._analyzing=!0);try{if(e instanceof h){this._viewer.clock.currentTime=e,this._viewer.scene.render();let u=new g(this.getVirtualSunPosition(t),this._sunDirectionWC),a=this._viewer.scene.picking,{object:o,position:n}=a.pickFromRay(a,this._viewer.scene,u,i?.objectsToExclude),_=o instanceof c&&o.id===this._pointEntityId;if(i?.debugShowPoints&&n){let p=new c({point:{show:!0,pixelSize:5},position:n});this._viewer.entities.add(p),this._debugEntities.push(p)}return{timestamp:e.toString(),result:_}}else{let{start:u,end:a,step:o}=e,n=u.clone();for(;h.compare(n,a)<=0;)r.push(this.analyze(t,n,i)),h.addSeconds(n,o,n)}}finally{l&&d&&(this._viewer.clock.currentTime=d,this._viewer.scene.render(),this._analyzing=!1,this._pointEntityId&&!i?.debugShowPoints&&this._viewer.entities.removeById(this._pointEntityId))}return r}_createPointEntity(t,e,i){let r=new c({point:{show:e,pixelSize:i??5},position:t});return this._pointEntityId=r.id,r}clear(){this._debugEntities.forEach(t=>{this._viewer.entities.contains(t)&&this._viewer.entities.remove(t)}),this._debugEntities=[],this._pointEntityId&&this._viewer.entities.getById(this._pointEntityId)&&this._viewer.entities.removeById(this._pointEntityId)}},w=y;export{w as Sunlight};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juun-roh/cesium-utils",
3
- "version": "0.2.7",
3
+ "version": "0.3.0",
4
4
  "description": "Solve common Cesium.js challenges: combine multiple terrain sources, tag and filter entity collections, and add visual highlights.",
5
5
  "keywords": [
6
6
  "cesium",
@@ -66,6 +66,11 @@
66
66
  "import": "./dist/dev/index.js",
67
67
  "require": "./dist/dev/index.cjs"
68
68
  },
69
+ "./experimental": {
70
+ "types": "./dist/experimental/index.d.ts",
71
+ "import": "./dist/experimental/index.js",
72
+ "require": "./dist/experimental/index.cjs"
73
+ },
69
74
  "./viewer": {
70
75
  "types": "./dist/viewer/index.d.ts",
71
76
  "import": "./dist/viewer/index.js",
@@ -95,22 +100,22 @@
95
100
  "@commitlint/types": "^19.8.1",
96
101
  "@eslint/js": "^9.33.0",
97
102
  "@types/node": "^24.3.0",
98
- "@typescript-eslint/eslint-plugin": "^8.39.1",
99
- "@typescript-eslint/parser": "^8.39.1",
103
+ "@typescript-eslint/eslint-plugin": "^8.40.0",
104
+ "@typescript-eslint/parser": "^8.40.0",
100
105
  "@vitest/coverage-v8": "^3.2.4",
101
106
  "cesium": "^1.132.0",
102
107
  "eslint": "^9.33.0",
103
- "eslint-plugin-jsdoc": "^54.1.0",
108
+ "eslint-plugin-jsdoc": "^54.1.1",
104
109
  "eslint-plugin-prettier": "^5.5.4",
105
110
  "eslint-plugin-simple-import-sort": "^12.1.1",
106
- "eslint-plugin-unused-imports": "^4.1.4",
111
+ "eslint-plugin-unused-imports": "^4.2.0",
107
112
  "husky": "^9.1.7",
108
113
  "jsdom": "^26.1.0",
109
114
  "rimraf": "^6.0.1",
110
115
  "tsup": "^8.5.0",
111
116
  "typedoc": "^0.28.10",
112
117
  "typescript": "^5.9.2",
113
- "vite": "^7.1.2",
118
+ "vite": "^7.1.3",
114
119
  "vitest": "^3.2.4"
115
120
  },
116
121
  "scripts": {