|
97 | 97 | set_gui_position(); |
98 | 98 | </script> |
99 | 99 |
|
| 100 | + <script src="../static/assimpjs/assimpjs.min.js" defer></script> |
100 | 101 | <script src="../static/js/upng/UPNG.min.js" defer></script> |
101 | 102 | <script src="../static/js/omggif/omggif.min.js" defer></script> |
102 | 103 | <script src="../static/js/pako/dist/pako.min.js" defer></script> |
|
380 | 381 | <option title="PLY - Polygon File Format binary" value="ply" onclick="export_ply( true );">PLY_b</option> |
381 | 382 | <option title="STL - Stereolithography Format" value="stl" onclick="export_stl();">STL</option> |
382 | 383 | <option title="USDZ - Universal Scene Description Format" value="usdz" onclick="export_usdz();">USDZ</option> |
| 384 | + <option title="ASSIMP Export Formats" value="assimp" disabled>ASSIMP</option> |
| 385 | + <option title="FBX - Filmbox Format" value="fbx" onclick="export_assimp( 'fbx' );">FBX</option> |
| 386 | + <option title="ASSJSON - Assimp JSON Format" value="assjson" onclick="export_assimp( 'assjson' );">JSON</option> |
| 387 | + <option title="STEP Format" value="stp" onclick="export_assimp( 'stp' );">STEP</option> |
| 388 | + <option title="X3D - Extensible 3D Graphics Format" value="x3d" onclick="export_assimp( 'x3d' );">X3D</option> |
383 | 389 | <option title="Animated Graphics Exports" value="ani" disabled>- ANI -</option> |
384 | 390 | <option title="GIF - Animated GIF" value="gif" onclick="export_animated_gif();">GIF</option> |
385 | 391 | <option title="PNG - Animated PNG (APNG)" value="apng" onclick="export_animated_png();">PNG</option> |
|
1104 | 1110 | let options; |
1105 | 1111 |
|
1106 | 1112 | if (animations.length > 0) { |
1107 | | - options = { binary: binary, maxTextureSize: tex_res, animations: animations }; |
| 1113 | + options = { binary: binary, maxTextureSize: (binary === true ? Infinity : tex_res), animations: animations }; |
1108 | 1114 | } else { |
1109 | | - options = { binary: binary, maxTextureSize: tex_res }; |
| 1115 | + options = { binary: binary, maxTextureSize: (binary === true ? Infinity : tex_res) }; |
1110 | 1116 | } |
1111 | 1117 |
|
1112 | 1118 | gltf_exporter.parse( skeletonUtils.clone( gltf_obj ), async json => { |
|
1120 | 1126 | blob = new Blob( [ await draco_compress( new Uint8Array( json ) ) ], { type: type } ); |
1121 | 1127 | } else if (meshopt === true) { |
1122 | 1128 | blob = new Blob( [ await meshopt_compress( new Uint8Array( json ) ) ], { type: type } ); |
1123 | | - } else if (tex_fmt !== '') { |
| 1129 | + } else if (tex_fmt !== '' || tex_res !== Infinity || tex_flip === true) { |
1124 | 1130 | blob = new Blob( [ await texture_compress( new Uint8Array( json ) ) ], { type: type } ); |
1125 | 1131 | } else { |
1126 | 1132 | blob = new Blob( [ await simplify( new Uint8Array( json ) ) ], { type: type } ); |
|
1158 | 1164 | } |
1159 | 1165 | } |
1160 | 1166 |
|
| 1167 | + async function export_assimp( format = 'fbx' ) { |
| 1168 | + if (gltf_obj) { |
| 1169 | + await start_export(); |
| 1170 | + |
| 1171 | + const { GLTFExporter } = await import( "../static/jsm/exporters/GLTFExporter.min.js" ); |
| 1172 | + |
| 1173 | + let gltf_exporter = new GLTFExporter( manager ); |
| 1174 | + |
| 1175 | + let options; |
| 1176 | + |
| 1177 | + if (animations.length > 0) { |
| 1178 | + options = { binary: true, animations: animations }; |
| 1179 | + } else { |
| 1180 | + options = { binary: true }; |
| 1181 | + } |
| 1182 | + |
| 1183 | + gltf_exporter.parse( (skeletonUtils.clone( gltf_obj )), async function( json ) { |
| 1184 | + let simplified = await texture_compress( new Uint8Array( json ) ); |
| 1185 | + |
| 1186 | + // Use ASSIMPJS to export files |
| 1187 | + assimpjs().then( async function( ajs ) { |
| 1188 | + let result = ajs.ConvertFile( filename, format, simplified, undefined, undefined ); |
| 1189 | + let fileCount = result.FileCount(); |
| 1190 | + |
| 1191 | + // check if the conversion succeeded |
| 1192 | + if (result.IsSuccess() === false || fileCount === 0) { |
| 1193 | + handle_export_error( result.GetErrorCode() ); |
| 1194 | + ajs = null; |
| 1195 | + result = null; |
| 1196 | + return; |
| 1197 | + } |
| 1198 | + |
| 1199 | + // get the first result file and convert it to blob |
| 1200 | + let resultFile = await result.GetFile( 0 ); |
| 1201 | + let jsonContent = resultFile.GetContent(); |
| 1202 | + let blob = new Blob( [ jsonContent ], { type: 'application/octet-stream' } ); |
| 1203 | + |
| 1204 | + // Possible ASSIMP export formats, some with binary / ascii options: |
| 1205 | + // assjson, assbin, assxml, collada, x, stp, obj, objnomtl, 3ds, 3mf, pbrt |
| 1206 | + // gltf, gltf2, glb, glb2, stl, stlb, ply, plyb, fbx, fbxa, x3d |
| 1207 | + // m3d / m3da - disabled since no longer maintained within ASSIMP |
| 1208 | + // For proper file extension, shorten the format before zipping it up |
| 1209 | + let ext_to_change = { 'fbxa': 'fbx', 'assjson': 'json', 'collada': 'dae' }; // 'plyb': 'ply' ... etc |
| 1210 | + if (ext_to_change[ format ]) format = ext_to_change[ format ]; |
| 1211 | + |
| 1212 | + zip.file( filename + '.' + format, blob ); |
| 1213 | + |
| 1214 | + ajs = null; |
| 1215 | + result = null; |
| 1216 | + resultFile = null; |
| 1217 | + |
| 1218 | + await process_zip( '_' + format.toUpperCase() ); |
| 1219 | + }); |
| 1220 | + }, function( error ) { handle_export_error( error ); }, options); |
| 1221 | + } |
| 1222 | + } |
| 1223 | + |
1161 | 1224 | async function export_json() { |
1162 | 1225 | if (gltf_obj) { |
1163 | 1226 | await start_export(); |
|
0 commit comments