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

iTowns / itowns / 10635241580

30 Aug 2024 03:26PM UTC coverage: 86.966% (-2.8%) from 89.766%
10635241580

push

github

jailln
feat(3dtiles): add new OGC3DTilesLayer using 3d-tiles-renderer-js

Deprecate C3DTilesLayer (replaced by OGC3DTilesLayer).
Add new iGLTFLoader that loads gltf 1.0 and 2.0 files.

2791 of 3694 branches covered (75.55%)

Branch coverage included in aggregate %.

480 of 644 new or added lines in 8 files covered. (74.53%)

2144 existing lines in 111 files now uncovered.

24319 of 27479 relevant lines covered (88.5%)

1024.72 hits per line

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

88.52
/src/Process/ObjectRemovalHelper.js
1
function disposeSingleMaterialAndTextures(material) {
3✔
2
    material.dispose();
3✔
3
    // dispose textures
3✔
4
    for (const key of Object.keys(material)) {
3✔
5
        const val = material[key];
207✔
6
        if (val && val.isTexture) {
207!
UNCOV
7
            val.dispose();
×
UNCOV
8
        }
×
9
    }
207✔
10
}
3✔
11

1✔
12
export default {
1✔
13
    /**
1✔
14
     * Cleanup obj to release three.js allocated resources
1✔
15
     * @param {Object3D} obj object to release
1✔
16
     */
1✔
17
    cleanup(obj) {
1✔
18
        obj.layer = null;
4✔
19

4✔
20
        // THREE.Scene dispose function displays a deprecation message
4✔
21
        if (!obj.isScene && typeof obj.dispose === 'function') {
4!
UNCOV
22
            obj.dispose();
×
23
        } else {
4✔
24
            if (obj.geometry) {
4✔
25
                obj.geometry.dispose();
3✔
26
                // the Object Removal Helper causes inconsistencies
3✔
27
                // when it assigns null to a geometry present in the Cache.
3✔
28
                // Actually, the cache can provide a mesh whose geometry is null.
3✔
29
                // see https://github.com/iTowns/itowns/issues/869
3✔
30
                // obj.geometry = null;
3✔
31
            }
3✔
32
            if (obj.material) {
4✔
33
                if (Array.isArray(obj.material)) {
3!
UNCOV
34
                    for (const material of obj.material) {
×
UNCOV
35
                        disposeSingleMaterialAndTextures(material);
×
UNCOV
36
                    }
×
37
                } else {
3✔
38
                    disposeSingleMaterialAndTextures(obj.material);
3✔
39
                }
3✔
40
            }
3✔
41
            obj.dispatchEvent({ type: 'dispose' });
4✔
42
        }
4✔
43
    },
1✔
44

1✔
45
    /**
1✔
46
     * Remove obj's children belonging to a layer.
1✔
47
     * Neither obj nor its children will be disposed!
1✔
48
     * @param {Layer} layer The layer that objects must belong to. Other object are ignored
1✔
49
     * @param {Object3D} obj The Object3D we want to clean
1✔
50
     * @return {Array} an array of removed Object3D from obj (not including the recursive removals)
1✔
51
     */
1✔
52
    removeChildren(layer, obj) {
1✔
53
        const toRemove = obj.children.filter(c => (c.layer && c.layer.id) === layer.id);
1✔
54
        obj.remove(...toRemove);
1✔
55
        return toRemove;
1✔
56
    },
1✔
57

1✔
58
    /**
1✔
59
     * Remove an obj and all its children belonging to a layer and only cleanup the obj (and not its children).
1✔
60
     * obj will be disposed but its children **won't**!
1✔
61
     * @param {Layer} layer The layer that objects must belong to. Other object are ignored
1✔
62
     * @param {Object3D} obj The Object3D we want to clean
1✔
63
     * @return {Array} an array of removed Object3D from obj (not including the recursive removals)
1✔
64
     */
1✔
65
    removeChildrenAndCleanup(layer, obj) {
1✔
66
        const toRemove = obj.children.filter(c => (c.layer && c.layer.id) === layer.id);
5✔
67

5✔
68
        obj.remove(...toRemove);
5✔
69
        if (obj.layer === layer) {
5✔
70
            this.cleanup(obj);
1✔
71
        }
1✔
72
        return toRemove;
5✔
73
    },
1✔
74

1✔
75
    /**
1✔
76
     * Recursively remove an obj and all its children belonging to a layer.
1✔
77
     * All removed obj will have their geometry/material disposed.
1✔
78
     * @param {Layer} layer The layer that objects must belong to. Other object are ignored
1✔
79
     * @param {Object3D} obj The Object3D we want to clean
1✔
80
     * @return {Array} an array of removed Object3D from obj (not including the recursive removals)
1✔
81
     */
1✔
82
    removeChildrenAndCleanupRecursively(layer, obj) {
1✔
83
        // Objects are filtered by id because the obj hierarchy may also contain labels that have been added as childs
4✔
84
        // of the objects which have their own removal logic
4✔
85
        let toRemove = obj.children.filter(c => c.layer && c.layer.id === layer.id);
4✔
86
        const linked = obj.link && obj.link[layer.id];
4✔
87
        if (linked?.children.length) {
4!
UNCOV
88
            toRemove = toRemove.concat(linked.children);
×
UNCOV
89
            delete obj.link[layer.id];
×
UNCOV
90
        }
×
91
        for (const c of toRemove) {
4✔
92
            this.removeChildrenAndCleanupRecursively(layer, c);
2✔
93
        }
2✔
94
        obj.remove(...toRemove);
4✔
95
        if (obj.layer && obj.layer.id === layer.id) {
4✔
96
            this.cleanup(obj);
2✔
97
        }
2✔
98
        return toRemove;
4✔
99
    },
4✔
100
};
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