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

iTowns / itowns / 7743821661

01 Feb 2024 03:41PM UTC coverage: 77.306% (-0.05%) from 77.36%
7743821661

Pull #2124

github

web-flow
Merge 9b8011e0b into 47d0c7cab
Pull Request #2124: Feat/google3d tiles

4108 of 6059 branches covered (0.0%)

Branch coverage included in aggregate %.

53 of 92 new or added lines in 3 files covered. (57.61%)

1 existing line in 1 file now uncovered.

8097 of 9729 relevant lines covered (83.23%)

1940.33 hits per line

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

52.63
/src/Parser/GLTFParser.js
1
import * as THREE from 'three';
1✔
2
import { GLTFLoader } from 'ThreeExtended/loaders/GLTFLoader';
1✔
3
import { DRACOLoader } from 'ThreeExtended/loaders/DRACOLoader';
1✔
4
import { KTX2Loader } from 'ThreeExtended/loaders/KTX2Loader';
1✔
5
import LegacyGLTFLoader from 'Parser/deprecated/LegacyGLTFLoader';
1,676✔
6

7
const matrixChangeUpVectorYtoZ = (new THREE.Matrix4()).makeRotationX(Math.PI / 2);
1✔
8

9
export const glTFLoader = new GLTFLoader();
1✔
10
export const legacyGLTFLoader = new LegacyGLTFLoader();
1✔
11

12
/**
13
 * @module GLTFParser
14
 * @description Parses [glTF](https://www.khronos.org/gltf/) 1.0 and 2.0 files.
15
 *
16
 * Under the hood, glTF 2.0 files are parsed with THREE.GltfLoader() and GLTF 1.0 are parsed with the previous THREE
17
 * GltfLoader (for 1.0 glTF) that has been kept and maintained in iTowns.
18
 */
19

20
/**
1✔
21
 * Enable loading gltf files with [Draco](https://google.github.io/draco/) geometry extension.
22
 *
23
 * @param {String} path path to draco library folder containing the JS and WASM decoder libraries. They can be found in
24
 * [itowns examples](https://github.com/iTowns/itowns/tree/master/examples/libs/draco).
25
 * @param {Object} [config] optional configuration for Draco decoder (see threejs'
26
 * [setDecoderConfig](https://threejs.org/docs/index.html?q=draco#examples/en/loaders/DRACOLoader.setDecoderConfig) that
27
 * is called under the hood with this configuration for details.
28
 */
29
export function enableDracoLoader(path, config) {
NEW
30
    if (!path) {
×
NEW
31
        throw new Error('Path to draco folder is mandatory');
×
32
    }
NEW
33
    const dracoLoader = new DRACOLoader();
×
NEW
34
    dracoLoader.setDecoderPath(path);
×
NEW
35
    if (config) {
×
NEW
36
        dracoLoader.setDecoderConfig(config);
×
37
    }
NEW
38
    glTFLoader.setDRACOLoader(dracoLoader);
×
39
}
40

41
/**
42
 * Enable loading gltf files with [KTX2](https://www.khronos.org/ktx/) texture extension.
43
 *
44
 * @param {String} path path to ktx2 library folder containing the JS and WASM decoder libraries. They can be found in
45
 * [itowns examples](https://github.com/iTowns/itowns/tree/master/examples/libs/basis).
46
 * @param {THREE.WebGLRenderer} renderer the threejs renderer
47
 */
48
export function enableKtx2Loader(path, renderer) {
NEW
49
    if (!path || !renderer) {
×
NEW
50
        throw new Error('Path to ktx2 folder and renderer are mandatory');
×
51
    }
NEW
52
    const ktx2Loader = new KTX2Loader();
×
NEW
53
    ktx2Loader.setTranscoderPath(path);
×
NEW
54
    ktx2Loader.detectSupport(renderer);
×
NEW
55
    glTFLoader.setKTX2Loader(ktx2Loader);
×
56
}
57

58
export default {
1✔
59
    /** Parses a gltf buffer to an object with threejs structures and applies a y-up to z-up conversion to align with
60
     * itowns convention. Essentially calls THREE.GltfLoader.parse() for glTF 2.0 files and the legacy threejs parser
61
     * for gtTF 1.0 files.
62
     * @param {ArrayBuffer} buffer - the glTF asset to parse, as an ArrayBuffer, JSON string or object.
63
     * @param {String} path - the base path from which to find subsequent glTF resources such as textures and .bin data files.
64
     * @return {Promise} - a promise that resolves with an object containing an Object that contains loaded parts:
65
     * .scene, .scenes, .cameras, .animations, and .asset.
66
     */
67
    parse(buffer, path) {
68
        return new Promise((resolve, reject) => {
4✔
69
            if (!buffer || !path) {
4!
NEW
70
                reject(new Error('[GLTFParser]: Buffer and path are mandatory to parse a glTF.'));
×
NEW
71
                return;
×
72
            }
73

74
            // Apply y-up (gltf convention) to z-up (itowns convention) conversion
75
            const onload = (gltf) => {
4✔
76
                gltf.scene.applyMatrix4(matrixChangeUpVectorYtoZ);
3✔
77
                resolve(gltf);
3✔
78
            };
79
            const onError = (e) => {
4✔
NEW
80
                reject(new Error(`[GLTFParser]: Failed to parse gltf with error: ${e}`));
×
81
            };
82
            const headerView = new DataView(buffer, 0, 20);
4✔
83
            const version = headerView.getUint32(4, true);
3✔
84

85
            if (version === 1) {
3!
NEW
86
                legacyGLTFLoader.parse(buffer, path, onload, onError);
×
87
            } else {
88
                glTFLoader.parse(buffer, path, onload, onError);
3✔
89
            }
90
        });
91
    },
92
};
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