@soonspacejs/plugin-tiles 2.14.5 → 2.14.6
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/ArcgisTilesRenderer.d.ts +27 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +104 -29
- package/package.json +3 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Scene } from 'three';
|
|
2
|
+
import { TilesRenderer } from '3d-tiles-renderer';
|
|
3
|
+
import { TilesFadePlugin, UpdateOnChangePlugin, QuantizedMeshPlugin, ImageOverlayPlugin, ReorientationPlugin } from '3d-tiles-renderer/plugins';
|
|
4
|
+
import { default as SoonSpace } from 'soonspacejs';
|
|
5
|
+
declare class TileCustomMaterialPlugin {
|
|
6
|
+
priority: number;
|
|
7
|
+
processTileModel(scene: Scene): void;
|
|
8
|
+
}
|
|
9
|
+
declare class ArcgisTilesRenderer {
|
|
10
|
+
readonly ssp: SoonSpace;
|
|
11
|
+
tiles: TilesRenderer;
|
|
12
|
+
tilesFadePlugin: TilesFadePlugin;
|
|
13
|
+
updateOnChangePlugin: UpdateOnChangePlugin;
|
|
14
|
+
quantizedPlugin: QuantizedMeshPlugin;
|
|
15
|
+
customMaterialPlugin: TileCustomMaterialPlugin;
|
|
16
|
+
imageOverlayPlugin: ImageOverlayPlugin;
|
|
17
|
+
reorientationPlugin: ReorientationPlugin;
|
|
18
|
+
loedTilesSets: Set<() => void>;
|
|
19
|
+
constructor(ssp: SoonSpace);
|
|
20
|
+
render: () => void;
|
|
21
|
+
beforeRenderHandler: () => void;
|
|
22
|
+
enable(): void;
|
|
23
|
+
disable(): void;
|
|
24
|
+
invalidate(lon: number, lat: number, alt: number): () => void;
|
|
25
|
+
dispose(): void;
|
|
26
|
+
}
|
|
27
|
+
export { ArcgisTilesRenderer, };
|
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -1,28 +1,102 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { TilesRenderer as
|
|
3
|
-
import { GLTFLoader as
|
|
4
|
-
|
|
1
|
+
import c from "soonspacejs";
|
|
2
|
+
import { TilesRenderer as g } from "3d-tiles-renderer";
|
|
3
|
+
import { GLTFLoader as p } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
4
|
+
import { MathUtils as h, MeshBasicMaterial as m } from "three";
|
|
5
|
+
import { TilesFadePlugin as f, UpdateOnChangePlugin as v, QuantizedMeshPlugin as w, ImageOverlayPlugin as P, XYZTilesOverlay as T, ReorientationPlugin as C } from "3d-tiles-renderer/plugins";
|
|
6
|
+
class L {
|
|
5
7
|
constructor(t) {
|
|
6
8
|
this.parser = t, this.name = "KHR_texture_basisu_patch";
|
|
7
9
|
}
|
|
8
10
|
loadTexture(t) {
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
11
|
+
const s = this.parser, i = s.json, r = i.textures[t].source, a = i.images[r];
|
|
12
|
+
if (!a || a.mimeType !== "image/ktx2")
|
|
11
13
|
return null;
|
|
12
|
-
const
|
|
13
|
-
if (!
|
|
14
|
-
throw new Error(`${
|
|
15
|
-
return
|
|
14
|
+
const n = s.options.ktx2Loader;
|
|
15
|
+
if (!n)
|
|
16
|
+
throw new Error(`${c.utils.consoleSspTitle}请使用 setModelKtx2DecoderPath 设置 ktx2 解压库路径`);
|
|
17
|
+
return s.loadTextureImage(t, r, n);
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
|
-
class
|
|
20
|
+
class M {
|
|
21
|
+
priority = -999;
|
|
22
|
+
processTileModel(t) {
|
|
23
|
+
t.traverse((s) => {
|
|
24
|
+
s.material && (s.material = new m());
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const R = "https://sooncps.xwbuilders.com/api/ugis-dataprocess/v1/terrain/NhBLlMx3/";
|
|
29
|
+
class E {
|
|
30
|
+
constructor(t) {
|
|
31
|
+
this.ssp = t, this.tiles = new g(R), this.tiles.fetchData = async (s, i) => {
|
|
32
|
+
if (/layer\.json$/.test(s)) {
|
|
33
|
+
const e = await fetch(s, i).then((r) => r.json());
|
|
34
|
+
return e.metadataAvailability = -1, new Response(JSON.stringify(e));
|
|
35
|
+
}
|
|
36
|
+
return fetch(s, i);
|
|
37
|
+
}, this.tilesFadePlugin = new f({ maximumFadeOutTiles: 200 }), this.updateOnChangePlugin = new v(), this.quantizedPlugin = new w({}), this.customMaterialPlugin = new M(), this.imageOverlayPlugin = new P({
|
|
38
|
+
renderer: t.viewport.renderer,
|
|
39
|
+
overlays: [
|
|
40
|
+
new T({
|
|
41
|
+
url: "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
|
|
42
|
+
})
|
|
43
|
+
]
|
|
44
|
+
}), this.reorientationPlugin = new C({
|
|
45
|
+
lon: 120,
|
|
46
|
+
lat: 30,
|
|
47
|
+
height: 0.1
|
|
48
|
+
}), this.tiles.registerPlugin(this.tilesFadePlugin), this.tiles.registerPlugin(this.updateOnChangePlugin), this.tiles.registerPlugin(this.quantizedPlugin), this.tiles.registerPlugin(this.customMaterialPlugin), this.tiles.registerPlugin(this.imageOverlayPlugin), this.tiles.registerPlugin(this.reorientationPlugin), this.tiles.maxDepth = 20, this.tiles.errorTarget = 1, this.tiles.addEventListener("needs-render", this.render), this.tiles.addEventListener("needs-update", this.render);
|
|
49
|
+
}
|
|
50
|
+
tiles;
|
|
51
|
+
tilesFadePlugin;
|
|
52
|
+
updateOnChangePlugin;
|
|
53
|
+
quantizedPlugin;
|
|
54
|
+
customMaterialPlugin;
|
|
55
|
+
imageOverlayPlugin;
|
|
56
|
+
reorientationPlugin;
|
|
57
|
+
loedTilesSets = /* @__PURE__ */ new Set();
|
|
58
|
+
render = () => {
|
|
59
|
+
this.ssp.render();
|
|
60
|
+
};
|
|
61
|
+
beforeRenderHandler = () => {
|
|
62
|
+
this.ssp.viewport.camera.updateMatrixWorld(), this.tiles.setCamera(this.ssp.viewport.camera), this.tiles.setResolutionFromRenderer(
|
|
63
|
+
this.ssp.viewport.camera,
|
|
64
|
+
this.ssp.viewport.renderer
|
|
65
|
+
), this.tiles.update();
|
|
66
|
+
};
|
|
67
|
+
enable() {
|
|
68
|
+
this.ssp.addObject(this.tiles.group), this.ssp.signals.beforeRender.add(this.beforeRenderHandler);
|
|
69
|
+
}
|
|
70
|
+
disable() {
|
|
71
|
+
this.ssp.removeObject(this.tiles.group), this.ssp.signals.beforeRender.remove(this.beforeRenderHandler);
|
|
72
|
+
}
|
|
73
|
+
invalidate(t, s, i) {
|
|
74
|
+
const e = () => {
|
|
75
|
+
const a = h.degToRad(s), n = h.degToRad(t);
|
|
76
|
+
this.reorientationPlugin.transformLatLonHeightToOrigin(
|
|
77
|
+
a,
|
|
78
|
+
n,
|
|
79
|
+
i
|
|
80
|
+
), this.ssp.render(), r();
|
|
81
|
+
}, r = () => {
|
|
82
|
+
this.tiles.removeEventListener("load-tile-set", e), this.loedTilesSets.delete(e);
|
|
83
|
+
};
|
|
84
|
+
return this.tiles.addEventListener("load-tile-set", e), this.loedTilesSets.add(e), this.tiles.root && e(), r;
|
|
85
|
+
}
|
|
86
|
+
dispose() {
|
|
87
|
+
this.disable(), this.loedTilesSets.forEach(
|
|
88
|
+
(t) => this.tiles.removeEventListener("load-tile-set", t)
|
|
89
|
+
), this.loedTilesSets.clear(), this.tiles.removeEventListener("needs-render", this.render), this.tiles.removeEventListener("needs-update", this.render), this.tiles.dispose();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
class Q {
|
|
19
93
|
constructor(t) {
|
|
20
94
|
this.ssp = t;
|
|
21
|
-
const { controls:
|
|
22
|
-
this._tilesCamera =
|
|
23
|
-
this.cameraTransitionStart = !0,
|
|
24
|
-
}),
|
|
25
|
-
this.cameraTransitionStart = !1, this.needsUpdate = !0,
|
|
95
|
+
const { controls: s, viewport: i } = t;
|
|
96
|
+
this._tilesCamera = i.camera, s.addEventListener("transitionstart", () => {
|
|
97
|
+
this.cameraTransitionStart = !0, i.state.useFreq = 1;
|
|
98
|
+
}), s.addEventListener("rest", () => {
|
|
99
|
+
this.cameraTransitionStart = !1, this.needsUpdate = !0, i.state.useFreq = 60;
|
|
26
100
|
}), t.signals.beforeRender.add(() => {
|
|
27
101
|
this.needsUpdate && (this.needsUpdate = !1, t.viewport.camera.updateMatrixWorld(), this.tilesMap.forEach((e) => {
|
|
28
102
|
e.group.updateMatrixWorld(), e.update();
|
|
@@ -42,29 +116,30 @@ class g {
|
|
|
42
116
|
downloadQueue = null;
|
|
43
117
|
async loadTiles(t) {
|
|
44
118
|
if (this.tilesMap.has(t)) {
|
|
45
|
-
|
|
119
|
+
c.utils.warn(`${t} already loaded`);
|
|
46
120
|
return;
|
|
47
121
|
}
|
|
48
|
-
const { ssp:
|
|
122
|
+
const { ssp: s, ssp: { viewport: i } } = this, e = new g(t);
|
|
49
123
|
this.lruCache === null ? this.lruCache = e.lruCache : e.lruCache = this.lruCache, this.parseQueue === null ? this.parseQueue = e.parseQueue : e.parseQueue = this.parseQueue, this.downloadQueue === null ? this.downloadQueue = e.downloadQueue : e.downloadQueue = this.downloadQueue;
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
const { dracoLoader:
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
this.cameraTransitionStart || (this.needsUpdate = !0,
|
|
124
|
+
const r = new p(e.manager);
|
|
125
|
+
r.register((o) => new L(o));
|
|
126
|
+
const { dracoLoader: a, ktx2Loader: n, meshoptDecoder: d } = s.manager.store.modelManager.gltfLoader;
|
|
127
|
+
a && r.setDRACOLoader(a), n && r.setKTX2Loader(n), d && r.setMeshoptDecoder(d), e.manager.addHandler(/\.gltf$/, r), this.tilesMap.set(t, e), e.setCamera(this._tilesCamera), e.setResolutionFromRenderer(this._tilesCamera, i.renderer), e.lruCache.maxSize = 600, e.lruCache.minSize = 300, e.lruCache.unloadPercent = 0.8, s.addObject(e.group);
|
|
128
|
+
const u = () => {
|
|
129
|
+
this.cameraTransitionStart || (this.needsUpdate = !0, s.render());
|
|
56
130
|
};
|
|
57
|
-
return e.addEventListener("load-model",
|
|
131
|
+
return e.addEventListener("load-model", u), new Promise((o) => {
|
|
58
132
|
e.addEventListener("load-tile-set", () => {
|
|
59
|
-
|
|
133
|
+
u(), o(e);
|
|
60
134
|
});
|
|
61
135
|
});
|
|
62
136
|
}
|
|
63
137
|
removeTiles(t) {
|
|
64
|
-
const
|
|
65
|
-
return
|
|
138
|
+
const s = this.tilesMap.get(t);
|
|
139
|
+
return s ? (s.dispose(), this.tilesMap.delete(t), this.ssp.removeObject(s.group), !0) : !1;
|
|
66
140
|
}
|
|
67
141
|
}
|
|
68
142
|
export {
|
|
69
|
-
|
|
143
|
+
E as ArcgisTilesRenderer,
|
|
144
|
+
Q as default
|
|
70
145
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-tiles",
|
|
3
3
|
"pluginName": "TilesPlugin",
|
|
4
|
-
"version": "2.14.
|
|
4
|
+
"version": "2.14.6",
|
|
5
5
|
"description": "3D Tiles plugin for SoonSpace.js",
|
|
6
6
|
"main": "dist/index.esm.js",
|
|
7
7
|
"module": "dist/index.esm.js",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
],
|
|
15
15
|
"author": "xunwei",
|
|
16
16
|
"license": "UNLICENSED",
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "e2f676445b6db0317cff7bda0efa254aa30234b8",
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"3d-tiles-renderer": "^0.4.14",
|
|
20
|
-
"soonspacejs": "2.14.
|
|
20
|
+
"soonspacejs": "2.14.6"
|
|
21
21
|
}
|
|
22
22
|
}
|