forked from wikimedia/3d2png
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
106 lines (80 loc) · 2.58 KB
/
test.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
var assert = require( 'assert' );
describe( 'STL', function() {
var threed = require( './3d2png' ),
msssim = require( 'image-ms-ssim' ),
fs = require( 'fs' ),
PNG = require( 'pngjs' ).PNG,
uuid = require( 'uuid' ),
filename = uuid.v4() + '.png',
images = [];
function loaded( img, callback ) {
images.push( img );
if ( images.length === 2 ) {
callback( images );
}
}
function loadPNG( filePath, callback ) {
fs.createReadStream( filePath )
.pipe( new PNG() )
.on( 'parsed', function () {
loaded( {
data: this.data,
width: this.width,
height: this.height,
channels: 4
}, callback);
} );
}
function loadImages( file1, file2, callback ) {
loadPNG( file1, callback );
loadPNG( file2, callback );
}
after( function() {
fs.unlinkSync( './' + filename );
} );
it( 'Converts to PNG correctly', function( done ) {
this.timeout( 10000 );
var t = new threed.ThreeDtoPNG( 640, 480 );
function conversionDone() {
loadImages( './' + filename, './samples/DavidStatue.png', function( images ) {
var score = msssim.compare( images[0], images[1] );
assert( score.msssim > 0.99, 'MS-SSIM below threshold (David)' );
assert( score.ssim > 0.99, 'SSIM below threshold (David)' );
images.splice(0);
done();
} );
}
t.setupEnvironment();
t.convert( './samples/DavidStatue.stl', './' + filename, conversionDone );
} );
it( 'Converts to PNG correctly with reversed faces', function( done ) {
this.timeout( 10000 );
var t = new threed.ThreeDtoPNG( 640, 480 );
function conversionDone() {
loadImages( './' + filename, './samples/Half_Torus.png', function( images ) {
var score = msssim.compare( images[0], images[1] );
assert( score.msssim > 0.99, 'MS-SSIM below threshold (Torus)' );
assert( score.ssim > 0.99, 'SSIM below threshold (Torus)' );
images.splice(0);
done();
} );
}
t.setupEnvironment();
t.convert( './samples/Half_Torus.stl', './' + filename, conversionDone );
} );
it( 'Converts to PNG correctly with close-up model', function( done ) {
this.timeout( 10000 );
var t = new threed.ThreeDtoPNG( 640, 480 );
function conversionDone() {
loadImages( './' + filename, './samples/High_quality_skull.png', function( images ) {
var score = msssim.compare( images[0], images[1] );
assert( score.msssim > 0.99, 'MS-SSIM below threshold (Skull)' );
assert( score.ssim > 0.99, 'SSIM below threshold (Skull)' );
images.splice(0);
done();
} );
}
t.setupEnvironment();
t.convert( './samples/High_quality_skull.stl', './' + filename, conversionDone );
} );
} );