|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | /* global DracoEncoderModule */ |
18 | | - var DRACOExporter = function () {}; |
19 | | - |
20 | | - DRACOExporter.prototype = { |
21 | | - constructor: DRACOExporter, |
22 | | - parse: function ( object, options ) { |
| 18 | + class DRACOExporter { |
| 19 | + |
| 20 | + parse( object, options = { |
| 21 | + decodeSpeed: 5, |
| 22 | + encodeSpeed: 5, |
| 23 | + encoderMethod: DRACOExporter.MESH_EDGEBREAKER_ENCODING, |
| 24 | + quantization: [ 16, 8, 8, 8, 8 ], |
| 25 | + exportUvs: true, |
| 26 | + exportNormals: true, |
| 27 | + exportColor: false |
| 28 | + } ) { |
23 | 29 |
|
24 | 30 | if ( object.isBufferGeometry === true ) { |
25 | 31 |
|
|
33 | 39 |
|
34 | 40 | } |
35 | 41 |
|
36 | | - if ( options === undefined ) { |
37 | | - |
38 | | - options = { |
39 | | - decodeSpeed: 5, |
40 | | - encodeSpeed: 5, |
41 | | - encoderMethod: DRACOExporter.MESH_EDGEBREAKER_ENCODING, |
42 | | - quantization: [ 16, 8, 8, 8, 8 ], |
43 | | - exportUvs: true, |
44 | | - exportNormals: true, |
45 | | - exportColor: false |
46 | | - }; |
47 | | - |
48 | | - } |
49 | | - |
50 | | - var geometry = object.geometry; |
51 | | - var dracoEncoder = DracoEncoderModule(); |
52 | | - var encoder = new dracoEncoder.Encoder(); |
53 | | - var builder; |
54 | | - var dracoObject; |
| 42 | + const geometry = object.geometry; |
| 43 | + const dracoEncoder = DracoEncoderModule(); |
| 44 | + const encoder = new dracoEncoder.Encoder(); |
| 45 | + let builder; |
| 46 | + let dracoObject; |
55 | 47 |
|
56 | 48 | if ( geometry.isBufferGeometry !== true ) { |
57 | 49 |
|
|
63 | 55 |
|
64 | 56 | builder = new dracoEncoder.MeshBuilder(); |
65 | 57 | dracoObject = new dracoEncoder.Mesh(); |
66 | | - var vertices = geometry.getAttribute( 'position' ); |
| 58 | + const vertices = geometry.getAttribute( 'position' ); |
67 | 59 | builder.AddFloatAttributeToMesh( dracoObject, dracoEncoder.POSITION, vertices.count, vertices.itemSize, vertices.array ); |
68 | | - var faces = geometry.getIndex(); |
| 60 | + const faces = geometry.getIndex(); |
69 | 61 |
|
70 | 62 | if ( faces !== null ) { |
71 | 63 |
|
72 | 64 | builder.AddFacesToMesh( dracoObject, faces.count / 3, faces.array ); |
73 | 65 |
|
74 | 66 | } else { |
75 | 67 |
|
76 | | - var faces = new ( vertices.count > 65535 ? Uint32Array : Uint16Array )( vertices.count ); |
| 68 | + const faces = new ( vertices.count > 65535 ? Uint32Array : Uint16Array )( vertices.count ); |
77 | 69 |
|
78 | | - for ( var i = 0; i < faces.length; i ++ ) { |
| 70 | + for ( let i = 0; i < faces.length; i ++ ) { |
79 | 71 |
|
80 | 72 | faces[ i ] = i; |
81 | 73 |
|
|
87 | 79 |
|
88 | 80 | if ( options.exportNormals === true ) { |
89 | 81 |
|
90 | | - var normals = geometry.getAttribute( 'normal' ); |
| 82 | + const normals = geometry.getAttribute( 'normal' ); |
91 | 83 |
|
92 | 84 | if ( normals !== undefined ) { |
93 | 85 |
|
|
99 | 91 |
|
100 | 92 | if ( options.exportUvs === true ) { |
101 | 93 |
|
102 | | - var uvs = geometry.getAttribute( 'uv' ); |
| 94 | + const uvs = geometry.getAttribute( 'uv' ); |
103 | 95 |
|
104 | 96 | if ( uvs !== undefined ) { |
105 | 97 |
|
|
111 | 103 |
|
112 | 104 | if ( options.exportColor === true ) { |
113 | 105 |
|
114 | | - var colors = geometry.getAttribute( 'color' ); |
| 106 | + const colors = geometry.getAttribute( 'color' ); |
115 | 107 |
|
116 | 108 | if ( colors !== undefined ) { |
117 | 109 |
|
|
125 | 117 |
|
126 | 118 | builder = new dracoEncoder.PointCloudBuilder(); |
127 | 119 | dracoObject = new dracoEncoder.PointCloud(); |
128 | | - var vertices = geometry.getAttribute( 'position' ); |
| 120 | + const vertices = geometry.getAttribute( 'position' ); |
129 | 121 | builder.AddFloatAttribute( dracoObject, dracoEncoder.POSITION, vertices.count, vertices.itemSize, vertices.array ); |
130 | 122 |
|
131 | 123 | if ( options.exportColor === true ) { |
132 | 124 |
|
133 | | - var colors = geometry.getAttribute( 'color' ); |
| 125 | + const colors = geometry.getAttribute( 'color' ); |
134 | 126 |
|
135 | 127 | if ( colors !== undefined ) { |
136 | 128 |
|
|
147 | 139 | } //Compress using draco encoder |
148 | 140 |
|
149 | 141 |
|
150 | | - var encodedData = new dracoEncoder.DracoInt8Array(); //Sets the desired encoding and decoding speed for the given options from 0 (slowest speed, but the best compression) to 10 (fastest, but the worst compression). |
| 142 | + const encodedData = new dracoEncoder.DracoInt8Array(); //Sets the desired encoding and decoding speed for the given options from 0 (slowest speed, but the best compression) to 10 (fastest, but the worst compression). |
151 | 143 |
|
152 | | - var encodeSpeed = options.encodeSpeed !== undefined ? options.encodeSpeed : 5; |
153 | | - var decodeSpeed = options.decodeSpeed !== undefined ? options.decodeSpeed : 5; |
| 144 | + const encodeSpeed = options.encodeSpeed !== undefined ? options.encodeSpeed : 5; |
| 145 | + const decodeSpeed = options.decodeSpeed !== undefined ? options.decodeSpeed : 5; |
154 | 146 | encoder.SetSpeedOptions( encodeSpeed, decodeSpeed ); // Sets the desired encoding method for a given geometry. |
155 | 147 |
|
156 | 148 | if ( options.encoderMethod !== undefined ) { |
|
163 | 155 |
|
164 | 156 | if ( options.quantization !== undefined ) { |
165 | 157 |
|
166 | | - for ( var i = 0; i < 5; i ++ ) { |
| 158 | + for ( let i = 0; i < 5; i ++ ) { |
167 | 159 |
|
168 | 160 | if ( options.quantization[ i ] !== undefined ) { |
169 | 161 |
|
|
175 | 167 |
|
176 | 168 | } |
177 | 169 |
|
178 | | - var length; |
| 170 | + let length; |
179 | 171 |
|
180 | 172 | if ( object.isMesh === true ) { |
181 | 173 |
|
|
196 | 188 | } //Copy encoded data to buffer. |
197 | 189 |
|
198 | 190 |
|
199 | | - var outputData = new Int8Array( new ArrayBuffer( length ) ); |
| 191 | + const outputData = new Int8Array( new ArrayBuffer( length ) ); |
200 | 192 |
|
201 | | - for ( var i = 0; i < length; i ++ ) { |
| 193 | + for ( let i = 0; i < length; i ++ ) { |
202 | 194 |
|
203 | 195 | outputData[ i ] = encodedData.GetValue( i ); |
204 | 196 |
|
|
210 | 202 | return outputData; |
211 | 203 |
|
212 | 204 | } |
213 | | - }; // Encoder methods |
| 205 | + |
| 206 | + } // Encoder methods |
| 207 | + |
214 | 208 |
|
215 | 209 | DRACOExporter.MESH_EDGEBREAKER_ENCODING = 1; |
216 | 210 | DRACOExporter.MESH_SEQUENTIAL_ENCODING = 0; // Geometry type |
|
0 commit comments