u-space 0.0.19 → 0.0.21

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.
@@ -1,38 +1,38 @@
1
- import { NodeMaterial as M, MeshBasicNodeMaterial as m, Mesh as a, MathUtils as o } from "three/webgpu";
2
- import { TilesRenderer as T } from "3d-tiles-renderer";
3
- import { TilesFadePlugin as R, TileCompressionPlugin as E, UpdateOnChangePlugin as w, ReorientationPlugin as y, XYZTilesPlugin as F } from "3d-tiles-renderer/plugins";
4
- import { FadeMaterialManager as _ } from "3d-tiles-renderer/src/three/plugins/fade/FadeMaterialManager.js";
1
+ import { NodeMaterial as M, MeshBasicNodeMaterial as P, Mesh as d, Matrix4 as R, Vector3 as u, MathUtils as n } from "three/webgpu";
2
+ import { TilesRenderer as w } from "3d-tiles-renderer";
3
+ import { TilesFadePlugin as E, TileCompressionPlugin as y, UpdateOnChangePlugin as _, ReorientationPlugin as x, XYZTilesPlugin as F } from "3d-tiles-renderer/plugins";
4
+ import { FadeMaterialManager as L } from "3d-tiles-renderer/src/three/plugins/fade/FadeMaterialManager.js";
5
5
  import { wrapFadeMaterial as b } from "3d-tiles-renderer/src/three/plugins/fade/wrapFadeMaterial.js";
6
- import { uniform as c, Fn as L, screenCoordinate as x, If as d, Discard as u, output as A } from "three/tsl";
7
- import { reinterpretType as s } from "@takram/three-geospatial";
8
- import { FnLayout as f } from "@takram/three-geospatial/webgpu";
9
- const h = /* @__PURE__ */ Symbol("FADE_PARAMS"), p = f({
6
+ import { uniform as f, Fn as C, screenCoordinate as D, If as h, Discard as p, output as A } from "three/tsl";
7
+ import { reinterpretType as l } from "@takram/three-geospatial";
8
+ import { FnLayout as T } from "@takram/three-geospatial/webgpu";
9
+ const g = /* @__PURE__ */ Symbol("FADE_PARAMS"), c = T({
10
10
  name: "bayerDither2x2",
11
11
  type: "float",
12
12
  inputs: [{ name: "v", type: "vec2" }]
13
- })(([t]) => (s(t), t.y.mul(3).add(t.x.mul(2)).mod(4))), C = f({
13
+ })(([t]) => (l(t), t.y.mul(3).add(t.x.mul(2)).mod(4))), O = T({
14
14
  name: "bayerDither4x4",
15
15
  type: "float",
16
16
  inputs: [{ name: "v", type: "vec2" }]
17
17
  })(([t]) => {
18
- s(t);
18
+ l(t);
19
19
  const e = t.mod(2), i = t.mod(4).mul(0.5).floor();
20
- return p(e).mul(4).add(p(i));
21
- }), D = c(0).onObjectUpdate(
20
+ return c(e).mul(4).add(c(i));
21
+ }), S = f(0).onObjectUpdate(
22
22
  ({ material: t }) => t != null ? t?.params?.fadeIn.value ?? 0 : 0
23
- ), O = c(0).onObjectUpdate(
23
+ ), U = f(0).onObjectUpdate(
24
24
  ({ material: t }) => t != null ? t?.params?.fadeOut.value ?? 0 : 0
25
- ), S = L(() => {
26
- const i = C(x.xy.mod(4).floor()).add(0.5).div(16);
27
- return d(i.greaterThanEqual(D), () => {
28
- u();
29
- }), d(i.lessThan(O), () => {
30
- u();
25
+ ), H = C(() => {
26
+ const i = O(D.xy.mod(4).floor()).add(0.5).div(16);
27
+ return h(i.greaterThanEqual(S), () => {
28
+ p();
29
+ }), h(i.lessThan(U), () => {
30
+ p();
31
31
  }), A;
32
32
  })();
33
- function U(t) {
34
- if (s(t), t[h] != null)
35
- return t[h];
33
+ function W(t) {
34
+ if (l(t), t[g] != null)
35
+ return t[g];
36
36
  const e = {
37
37
  fadeIn: { value: 0 },
38
38
  fadeOut: { value: 0 },
@@ -43,54 +43,54 @@ function U(t) {
43
43
  get FEATURE_FADE() {
44
44
  return i;
45
45
  },
46
- set FEATURE_FADE(n) {
47
- n !== i && (i = n, t.outputNode = n === 1 ? S : null);
46
+ set FEATURE_FADE(s) {
47
+ s !== i && (i = s, t.outputNode = s === 1 ? H : null);
48
48
  }
49
49
  }, e;
50
50
  }
51
- class H extends _ {
51
+ class I extends L {
52
52
  // HACK: Override "wrapFadeMaterial" to support NodeMaterial:
53
53
  prepareMaterial(e) {
54
54
  const i = this._fadeParams;
55
55
  if (i.has(e))
56
56
  return;
57
- let n;
58
- e instanceof M ? n = U(e) : n = b(e, e.onBeforeCompile), i.set(e, n);
57
+ let s;
58
+ e instanceof M ? s = W(e) : s = b(e, e.onBeforeCompile), i.set(e, s);
59
59
  }
60
60
  }
61
- class I extends R {
61
+ class N extends E {
62
62
  constructor(...e) {
63
- super(...e), this._fadeMaterialManager = new H();
63
+ super(...e), this._fadeMaterialManager = new I();
64
64
  }
65
65
  }
66
- function g(t, e) {
66
+ function m(t, e) {
67
67
  const i = t.material;
68
68
  if (Array.isArray(i))
69
69
  throw new Error("Multiple materials are not supported yet.");
70
- const n = new e();
71
- "map" in i && i.map != null && "map" in n && (s(i.map), s(n.map), i.map.flipY = !1, n.map = i.map.clone()), t.material = n, i.dispose();
70
+ const s = new e();
71
+ "map" in i && i.map != null && "map" in s && (l(i.map), l(s.map), i.map.flipY = !1, s.map = i.map.clone()), t.material = s, i.dispose();
72
72
  }
73
- class N {
73
+ class z {
74
74
  tiles;
75
75
  overrideMaterial;
76
- constructor(e = m) {
76
+ constructor(e = P) {
77
77
  this.overrideMaterial = e;
78
78
  }
79
79
  // Plugin method
80
80
  init(e) {
81
81
  this.tiles = e, e.group.traverse((i) => {
82
- i instanceof a && g(i, this.overrideMaterial);
82
+ i instanceof d && m(i, this.overrideMaterial);
83
83
  }), e.addEventListener("load-model", this.handleLoadModel), e.addEventListener("dispose-model", this.handleDisposeModel);
84
84
  }
85
85
  handleLoadModel = ({ scene: e }) => {
86
86
  e.traverse((i) => {
87
- i instanceof a && g(i, this.overrideMaterial);
87
+ i instanceof d && m(i, this.overrideMaterial);
88
88
  });
89
89
  };
90
90
  // eslint-disable-next-line @typescript-eslint/class-methods-use-this
91
91
  handleDisposeModel = ({ scene: e }) => {
92
92
  e.traverse((i) => {
93
- i instanceof a && i.material.dispose();
93
+ i instanceof d && i.material.dispose();
94
94
  });
95
95
  };
96
96
  // Plugin method
@@ -98,7 +98,7 @@ class N {
98
98
  this.tiles?.removeEventListener("load-model", this.handleLoadModel), this.tiles?.removeEventListener("dispose-model", this.handleDisposeModel);
99
99
  }
100
100
  }
101
- class z {
101
+ class B {
102
102
  tiles;
103
103
  tileCompressionPlugin;
104
104
  updateOnChangePlugin;
@@ -110,19 +110,19 @@ class z {
110
110
  this.tiles = this._initTilesRenderer(), this.tileCompressionPlugin = this._initTileCompressionPlugin(), this.updateOnChangePlugin = this._initUpdateOnChangePlugin(), this.reorientationPlugin = this._initReorientationPlugin(), this.xyzTilesPlugin = this._initXYZTilesPlugin(), this.tilesFadePlugin = this._initTilesFadePlugin(), this.tileMaterialReplacementPlugin = this._initTileMaterialReplacementPlugin();
111
111
  }
112
112
  _initTilesRenderer() {
113
- const e = new T();
113
+ const e = new w();
114
114
  return e.maxDepth = 20, e.errorTarget = 1, e;
115
115
  }
116
116
  _initTileCompressionPlugin() {
117
- const e = new E();
117
+ const e = new y();
118
118
  return this.tiles.registerPlugin(e), e;
119
119
  }
120
120
  _initUpdateOnChangePlugin() {
121
- const e = new w();
121
+ const e = new _();
122
122
  return this.tiles.registerPlugin(e), e;
123
123
  }
124
124
  _initReorientationPlugin() {
125
- const e = new y();
125
+ const e = new x();
126
126
  return this.tiles.registerPlugin(e), e;
127
127
  }
128
128
  _initXYZTilesPlugin() {
@@ -134,17 +134,20 @@ class z {
134
134
  return this.tiles.registerPlugin(e), e;
135
135
  }
136
136
  _initTilesFadePlugin() {
137
- const e = new I();
137
+ const e = new N();
138
138
  return this.tiles.registerPlugin(e), e;
139
139
  }
140
140
  _initTileMaterialReplacementPlugin() {
141
- const e = new N(m);
141
+ const e = new z(P);
142
142
  return this.tiles.registerPlugin(e), e;
143
143
  }
144
144
  }
145
- class G extends z {
145
+ class J extends B {
146
146
  viewer;
147
147
  loedTilesSets = /* @__PURE__ */ new Set();
148
+ gisOrigin = null;
149
+ _worldToEllipsoidMatrix = new R();
150
+ _ellipsoidPosition = new u();
148
151
  constructor(e) {
149
152
  super(), this.viewer = e, this.tiles.addEventListener("needs-render", this.render), this.tiles.addEventListener("needs-update", this.render);
150
153
  }
@@ -160,20 +163,27 @@ class G extends z {
160
163
  disable() {
161
164
  return this.viewer.scene.remove(this.tiles.group), this.viewer.removeEventListener("beforeRender", this.beforeRenderHandler), this;
162
165
  }
163
- invalidate(e, i, n) {
166
+ invalidate(e, i, s) {
164
167
  const r = () => {
165
- const P = o.degToRad(i), v = o.degToRad(e);
166
- this.reorientationPlugin.transformLatLonHeightToOrigin(P, v, n), this.render(), l();
167
- }, l = () => {
168
+ const o = n.degToRad(i), v = n.degToRad(e);
169
+ this.reorientationPlugin.transformLatLonHeightToOrigin(o, v, s), this.gisOrigin = { lon: e, lat: i, height: s }, this.render(), a();
170
+ }, a = () => {
168
171
  this.tiles.removeEventListener("load-root-tileset", r), this.loedTilesSets.delete(r);
169
172
  };
170
- return this.tiles.addEventListener("load-root-tileset", r), this.loedTilesSets.add(r), this.tiles.root && r(), l;
173
+ return this.tiles.addEventListener("load-root-tileset", r), this.loedTilesSets.add(r), this.tiles.root && r(), a;
174
+ }
175
+ lonLatHeightToPosition(e, i, s = 0, r = new u()) {
176
+ const a = n.degToRad(i), o = n.degToRad(e);
177
+ return this.tiles.ellipsoid.getCartographicToPosition(a, o, s, r), this.tiles.group.updateWorldMatrix(!0, !1), r.applyMatrix4(this.tiles.group.matrixWorld);
178
+ }
179
+ positionToLonLatHeight(e, i = { lon: 0, lat: 0, height: 0 }) {
180
+ return this.tiles.group.updateWorldMatrix(!0, !1), this._worldToEllipsoidMatrix.copy(this.tiles.group.matrixWorld).invert(), this._ellipsoidPosition.copy(e).applyMatrix4(this._worldToEllipsoidMatrix), this.tiles.ellipsoid.getPositionToCartographic(this._ellipsoidPosition, i), i.lon = n.radToDeg(i.lon), i.lat = n.radToDeg(i.lat), i;
171
181
  }
172
182
  dispose() {
173
183
  this.disable(), this.loedTilesSets.forEach((e) => this.tiles.removeEventListener("load-root-tileset", e)), this.loedTilesSets.clear(), this.tiles.removeEventListener("needs-render", this.render), this.tiles.removeEventListener("needs-update", this.render), this.tiles.dispose();
174
184
  }
175
185
  }
176
186
  export {
177
- G as ArcgisTilesRenderer,
178
- z as Globe
187
+ J as ArcgisTilesRenderer,
188
+ B as Globe
179
189
  };