• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iTowns / itowns / 15994794586

01 Jul 2025 09:02AM UTC coverage: 87.031%. First build
15994794586

Pull #2557

github

web-flow
Merge ddf98ecce into 651c88ad2
Pull Request #2557: Migrate TileMesh-related modules to typescript

2783 of 3726 branches covered (74.69%)

Branch coverage included in aggregate %.

426 of 433 new or added lines in 15 files covered. (98.38%)

26086 of 29445 relevant lines covered (88.59%)

1099.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.02
/packages/Main/src/Core/TileMesh.ts
1
import * as THREE from 'three';
1✔
2
import { geoidLayerIsVisible } from 'Layer/GeoidLayer';
1✔
3
import { tiledCovering } from 'Core/Tile/Tile';
1✔
4

1✔
5
import type { Extent } from '@itowns/geographic';
1✔
6
import type { TileGeometry } from 'Core/TileGeometry';
1✔
7
import type Tile from 'Core/Tile/Tile';
1✔
8
import OBB from 'Renderer/OBB';
1✔
9
import type { LayeredMaterial } from 'Renderer/LayeredMaterial';
1✔
10
import type LayerUpdateState from 'Layer/LayerUpdateState';
1✔
11

1✔
12
interface TileLayerLike {
1✔
13
    tileMatrixSets: string[];
1✔
14
}
1✔
15

1✔
16
/**
1✔
17
 * A TileMesh is a THREE.Mesh with a geometricError and an OBB.
1✔
18
 * The objectId property of the layered material is assigned to the id of the
1✔
19
 * TileMesh.
1✔
20
 * @param geometry - The tile geometry
1✔
21
 * @param material - A THREE.Material compatible with THREE.Mesh
1✔
22
 * @param layer - The layer the tile is added to
1✔
23
 * @param extent - The tile extent
1✔
24
 * @param level - The tile level (default = 0)
1✔
25
 */
1✔
26
class TileMesh extends THREE.Mesh<TileGeometry, LayeredMaterial> {
1✔
27
    readonly isTileMesh: true;
91✔
28

91✔
29
    layer: TileLayerLike;
91✔
30
    extent: Extent;
91✔
31
    level: number;
91✔
32
    obb: OBB;
91✔
33
    boundingSphere: THREE.Sphere;
91✔
34
    layerUpdateState: Record<string, LayerUpdateState>;
91✔
35
    geoidHeight: number;
91✔
36
    link: Record<string, unknown>;
91✔
37
    horizonCullingPoint: THREE.Vector3 | undefined;
91✔
38
    horizonCullingPointElevationScaled: THREE.Vector3 | undefined;
91✔
39

91✔
40
    private _tms = new Map<string, Tile[]>();
91✔
41

91✔
42
    constructor(
91✔
43
        geometry: TileGeometry,
91✔
44
        material: LayeredMaterial,
91✔
45
        layer: TileLayerLike,
91✔
46
        extent: Extent,
91✔
47
        level = 0,
91✔
48
    ) {
91✔
49
        super(geometry, material);
91✔
50

91✔
51
        if (!extent) {
91✔
52
            throw new Error('extent is mandatory to build a TileMesh');
1✔
53
        }
1✔
54
        this.layer = layer;
90✔
55
        this.extent = extent;
90✔
56

90✔
57
        this.level = level;
90✔
58

90✔
59
        this.material.setUniform('objectId', this.id);
90✔
60

90✔
61
        this.obb = this.geometry.OBB!.clone();
90✔
62
        this.boundingSphere = new THREE.Sphere();
90✔
63
        this.obb.box3D.getBoundingSphere(this.boundingSphere);
90✔
64

90✔
65
        for (const tms of layer.tileMatrixSets) {
91✔
66
            this._tms.set(tms, tiledCovering(this.extent, tms));
150✔
67
        }
150✔
68

90✔
69
        this.frustumCulled = false;
90✔
70
        this.matrixAutoUpdate = false;
90✔
71

90✔
72
        this.layerUpdateState = {};
90✔
73
        this.isTileMesh = true;
90✔
74

90✔
75
        this.geoidHeight = 0;
90✔
76

90✔
77
        this.link = {};
90✔
78

90✔
79
        let _visible = true;
90✔
80
        Object.defineProperty(this, 'visible', {
90✔
81
            get() { return _visible; },
90✔
82
            set(v) {
90✔
83
                if (_visible != v) {
78✔
84
                    _visible = v;
70✔
85
                    this.dispatchEvent({ type: v ? 'shown' : 'hidden' });
70✔
86
                }
70✔
87
            },
78✔
88
        });
90✔
89
    }
90✔
90

91✔
91
    /**
91✔
92
     * If specified, updates the min and max elevation of the OBB
91✔
93
     * and updates accordingly the bounding sphere and the geometric error.
91✔
94
     *
91✔
95
     * @param elevation - Elevation parameters
91✔
96
     */
91✔
97
    setBBoxZ(elevation: { min?: number, max?: number, scale?: number, geoidHeight?: number }) {
91✔
98
        elevation.geoidHeight = geoidLayerIsVisible(this.layer) ? this.geoidHeight : 0;
18!
99
        this.obb.updateZ(elevation);
18✔
100
        if (this.horizonCullingPointElevationScaled && this.horizonCullingPoint) {
18✔
101
            this.horizonCullingPointElevationScaled.setLength(
4✔
102
                this.obb.z.delta + this.horizonCullingPoint.length(),
4✔
103
            );
4✔
104
        }
4✔
105
        this.obb.box3D.getBoundingSphere(this.boundingSphere);
18✔
106
    }
18✔
107

91✔
108
    getExtentsByProjection(tms: string) {
91✔
109
        return this._tms.get(tms);
33✔
110
    }
33✔
111

91✔
112
    /**
91✔
113
     * Finds the common ancestor between this tile and another one. It goes
91✔
114
     * through parents on each side until one is found.
91✔
115
     *
91✔
116
     * @param tile - The tile to find common ancestor with
91✔
117
     * @returns The common ancestor between those two tiles, or undefined if
91✔
118
     * not found
91✔
119
     */
91✔
120
    findCommonAncestor(tile: TileMesh): TileMesh | undefined {
91✔
121
        if (!tile) {
11!
NEW
122
            return undefined;
×
NEW
123
        }
×
124
        if (tile.level == this.level) {
11✔
125
            if (tile.id == this.id) {
8✔
126
                return tile;
4✔
127
            } else if (tile.level != 0) {
4✔
128
                // @ts-expect-error By invariant, parent is always a TileMesh
4✔
129
                return this.parent.findCommonAncestor(tile.parent);
4✔
130
            } else {
4!
NEW
131
                return undefined;
×
NEW
132
            }
×
133
        } else if (tile.level < this.level) {
11✔
134
            // @ts-expect-error By invariant, parent is always a TileMesh
1✔
135
            return this.parent.findCommonAncestor(tile);
1✔
136
        } else {
3✔
137
            // @ts-expect-error By invariant, parent is always a TileMesh
2✔
138
            return this.findCommonAncestor(tile.parent);
2✔
139
        }
2✔
140
    }
11✔
141

91✔
142
    onBeforeRender() {
91✔
143
        this.material.updateLayersUniforms();
2✔
144
    }
2✔
145
}
91✔
146

1✔
147
export default TileMesh;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc