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

iTowns / itowns / 5691913681

pending completion
5691913681

push

github

mgermerie
chore: update three to r154

3933 of 5864 branches covered (67.07%)

Branch coverage included in aggregate %.

7778 of 9456 relevant lines covered (82.25%)

1619.74 hits per line

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

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

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

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

45
    /**
46
     * Remove obj's children belonging to a layer.
47
     * Neither obj nor its children will be disposed!
48
     * @param {Layer} layer The layer that objects must belong to. Other object are ignored
49
     * @param {Object3D} obj The Object3D we want to clean
50
     * @return {Array} an array of removed Object3D from obj (not including the recursive removals)
51
     */
52
    removeChildren(layer, obj) {
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
    },
57

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

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

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