-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
NavMeshLoader.tests.js
177 lines (107 loc) · 4.95 KB
/
NavMeshLoader.tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* @author Mugen87 / https://github.com/Mugen87
*/
const fs = require( 'fs' );
const path = require( 'path' );
const util = require( 'util' );
const expect = require( 'chai' ).expect;
const fetch = require( 'node-fetch' );
// provide implementation of browser APIs used in NavMeshLoader
global.fetch = fetch;
global.TextDecoder = util.TextDecoder;
const YUKA = require( '../../../../build/yuka.js' );
const NavMeshLoader = YUKA.NavMeshLoader;
const NavMesh = YUKA.NavMesh;
//
describe( 'NavMeshLoader', function () {
describe( '#load()', function () {
it( 'should return a promise that resolves if the navigation mesh with the given URL is successfully loaded', function ( done ) {
const loader = new NavMeshLoader();
const url = 'https://raw.githubusercontent.com/Mugen87/yuka/master/test/assets/navmesh/gltf/navmesh.gltf';
loader.load( url ).then( ( navMesh ) => {
expect( navMesh ).is.an.instanceof( NavMesh );
expect( navMesh.regions ).to.have.lengthOf( 5 );
expect( navMesh.graph.getNodeCount() ).is.equal( 5 );
expect( navMesh.graph.getEdgeCount() ).is.equal( 8 );
done();
} );
} );
// it's not possible with node-fetch to load a glTF file with embedded buffers since this fetch
// does not accept data URLs as input parameter.
it( 'should be able to load a glb file', function ( done ) {
const loader = new NavMeshLoader();
const url = 'https://raw.githubusercontent.com/Mugen87/yuka/master/test/assets/navmesh/glb/navmesh.glb';
loader.load( url ).then( ( navMesh ) => {
expect( navMesh ).is.an.instanceof( NavMesh );
expect( navMesh.regions ).to.have.lengthOf( 5 );
expect( navMesh.graph.getNodeCount() ).is.equal( 5 );
expect( navMesh.graph.getEdgeCount() ).is.equal( 8 );
done();
} );
} );
// it's possible to test glb files with embedded buffers since NavMeshLoader
// does not use fetch to return the buffer data in this case
it( 'should be able to load a glb file with embedded buffer data', function ( done ) {
const loader = new NavMeshLoader();
const url = 'https://raw.githubusercontent.com/Mugen87/yuka/master/test/assets/navmesh/glb-embedded/navmesh.glb';
loader.load( url ).then( ( navMesh ) => {
expect( navMesh ).is.an.instanceof( NavMesh );
expect( navMesh.regions ).to.have.lengthOf( 5 );
expect( navMesh.graph.getNodeCount() ).is.equal( 5 );
expect( navMesh.graph.getEdgeCount() ).is.equal( 8 );
done();
} );
} );
it( 'should be able to load a gltf file with no primitive mode definition', function ( done ) {
const loader = new NavMeshLoader();
const url = 'https://raw.githubusercontent.com/Mugen87/yuka/master/test/assets/navmesh/no-primitive-mode/navmesh.gltf';
loader.load( url ).then( ( navMesh ) => {
expect( navMesh ).is.an.instanceof( NavMesh );
expect( navMesh.regions ).to.have.lengthOf( 2 );
done();
} );
} );
it( 'should use the options parameter to config the navmesh', function ( done ) {
const loader = new NavMeshLoader();
const url = 'https://raw.githubusercontent.com/Mugen87/yuka/master/test/assets/navmesh/glb-embedded/navmesh.glb';
loader.load( url, { epsilonCoplanarTest: 0.5, mergeConvexRegions: false } ).then( ( navMesh ) => {
expect( navMesh.epsilonCoplanarTest ).is.equal( 0.5 );
expect( navMesh.mergeConvexRegions ).to.be.false;
done();
} );
} );
it( 'should reject the promise with an error if the URL das not exist', function ( done ) {
const loader = new NavMeshLoader();
const url = 'https://raw.githubusercontent.com/Mugen87/yuka/master/test/assets/navmesh/glb-embedded/error';
YUKA.Logger.setLevel( YUKA.Logger.LEVEL.SILENT );
loader.load( url ).then( () => {}, ( err ) =>{
expect( err ).to.be.a( 'Error' );
expect( err.message ).to.be.equal( 'Not Found' );
done();
} );
} );
it( 'should reject the promise with an error if the asset version is not supported', function ( done ) {
const loader = new NavMeshLoader();
const url = 'https://raw.githubusercontent.com/Mugen87/yuka/master/test/assets/navmesh/glb-embedded/navmeshUnsupportedAssetVersion.glb';
YUKA.Logger.setLevel( YUKA.Logger.LEVEL.SILENT );
loader.load( url ).then( ( ) => {}, ( err ) =>{
expect( err ).to.be.a( 'Error' );
expect( err.message ).to.be.equal( 'YUKA.NavMeshLoader: Unsupported asset version.' );
done();
} );
} );
} );
describe( '#parse()', function () {
it( 'should parse the given array buffer without using NavMeshLoader.load()', function ( done ) {
const data = fs.readFileSync( path.join( __dirname, '../../../assets/navmesh/glb-embedded/navmesh.glb' ) );
const loader = new NavMeshLoader();
loader.parse( data.buffer ).then( ( navMesh ) => {
expect( navMesh ).is.an.instanceof( NavMesh );
expect( navMesh.regions ).to.have.lengthOf( 5 );
expect( navMesh.graph.getNodeCount() ).is.equal( 5 );
expect( navMesh.graph.getEdgeCount() ).is.equal( 8 );
done();
} );
} );
} );
} );