Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

Commit ee29c24

Browse files
Update multiple viewers
1 parent bc2f165 commit ee29c24

File tree

3 files changed

+127
-7
lines changed

3 files changed

+127
-7
lines changed

viewers/templates/GLTF WebGPU.html

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
set_gui_position();
9898
</script>
9999

100+
<script src="../static/assimpjs/assimpjs.min.js" defer></script>
100101
<script src="../static/js/upng/UPNG.min.js" defer></script>
101102
<script src="../static/js/omggif/omggif.min.js" defer></script>
102103
<script src="../static/js/pako/dist/pako.min.js" defer></script>
@@ -380,6 +381,11 @@
380381
<option title="PLY - Polygon File Format binary" value="ply" onclick="export_ply( true );">PLY_b</option>
381382
<option title="STL - Stereolithography Format" value="stl" onclick="export_stl();">STL</option>
382383
<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>
383389
<option title="Animated Graphics Exports" value="ani" disabled>- ANI -</option>
384390
<option title="GIF - Animated GIF" value="gif" onclick="export_animated_gif();">GIF</option>
385391
<option title="PNG - Animated PNG (APNG)" value="apng" onclick="export_animated_png();">PNG</option>
@@ -1104,9 +1110,9 @@
11041110
let options;
11051111

11061112
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 };
11081114
} else {
1109-
options = { binary: binary, maxTextureSize: tex_res };
1115+
options = { binary: binary, maxTextureSize: (binary === true ? Infinity : tex_res) };
11101116
}
11111117

11121118
gltf_exporter.parse( skeletonUtils.clone( gltf_obj ), async json => {
@@ -1120,7 +1126,7 @@
11201126
blob = new Blob( [ await draco_compress( new Uint8Array( json ) ) ], { type: type } );
11211127
} else if (meshopt === true) {
11221128
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) {
11241130
blob = new Blob( [ await texture_compress( new Uint8Array( json ) ) ], { type: type } );
11251131
} else {
11261132
blob = new Blob( [ await simplify( new Uint8Array( json ) ) ], { type: type } );
@@ -1158,6 +1164,63 @@
11581164
}
11591165
}
11601166

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+
11611224
async function export_json() {
11621225
if (gltf_obj) {
11631226
await start_export();

viewers/templates/OBJ WebGPU.html

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
<script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js" defer></script>
2929
<script src="https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js" defer></script>
30+
<script src="../static/assimpjs/assimpjs.min.js" defer></script>
3031

3132
<!-- For encoding GLB exports with draco compression -->
3233
<script src="https://cdn.jsdelivr.net/npm/three@0.170.0/examples/jsm/libs/draco/draco_encoder.min.js" defer></script>
@@ -1639,6 +1640,11 @@
16391640
<option title="PLY - Polygon File Format binary" value="ply" onclick="export_ply( true );">PLY_b</option>
16401641
<option title="STL - Stereolithography Format" value="stl" onclick="export_stl();">STL</option>
16411642
<option title="USDZ - Universal Scene Description Format" value="usdz" onclick="export_usdz();">USDZ</option>
1643+
<option title="ASSIMP Export Formats" value="assimp" disabled>ASSIMP</option>
1644+
<option title="FBX - Filmbox Format" value="fbx" onclick="export_assimp( 'fbx' );">FBX</option>
1645+
<option title="ASSJSON - Assimp JSON Format" value="assjson" onclick="export_assimp( 'assjson' );">JSON</option>
1646+
<option title="STEP Format" value="stp" onclick="export_assimp( 'stp' );">STEP</option>
1647+
<option title="X3D - Extensible 3D Graphics Format" value="x3d" onclick="export_assimp( 'x3d' );">X3D</option>
16421648
</select>
16431649
<select title="Maximum Exported Texture Resolution and Y flip" id="export_tex_res" disabled>
16441650
<option title="Original" value="original" onclick="tex_res = Infinity; tex_flip = false;" selected>None</option>
@@ -2254,7 +2260,7 @@
22542260

22552261
let gltf_exporter = new GLTFExporter( manager );
22562262

2257-
let options = { binary: binary, maxTextureSize: tex_res };
2263+
let options = { binary: binary, maxTextureSize: (binary === true ? Infinity : tex_res) };
22582264

22592265
gltf_exporter.parse( Obj.clone(), async json => {
22602266
let blob;
@@ -2267,7 +2273,7 @@
22672273
blob = new Blob( [ await draco_compress( new Uint8Array( json ) ) ], { type: type } );
22682274
} else if (meshopt === true) {
22692275
blob = new Blob( [ await meshopt_compress( new Uint8Array( json ) ) ], { type: type } );
2270-
} else if (tex_fmt !== '') {
2276+
} else if (tex_fmt !== '' || tex_res !== Infinity || tex_flip === true) {
22712277
blob = new Blob( [ await texture_compress( new Uint8Array( json ) ) ], { type: type } );
22722278
} else {
22732279
blob = new Blob( [ await simplify( new Uint8Array( json ) ) ], { type: type } );
@@ -2305,6 +2311,57 @@
23052311
}
23062312
}
23072313

2314+
async function export_assimp( format = 'fbx' ) {
2315+
if (Obj) {
2316+
await start_export();
2317+
2318+
const { GLTFExporter } = await import( "../static/jsm/exporters/GLTFExporter.min.js" );
2319+
2320+
let gltf_exporter = new GLTFExporter( manager );
2321+
2322+
let options = { binary: true };
2323+
2324+
gltf_exporter.parse( Obj.clone(), async function( json ) {
2325+
let simplified = await texture_compress( new Uint8Array( json ) );
2326+
2327+
// Use ASSIMPJS to export files
2328+
assimpjs().then( async function( ajs ) {
2329+
let result = ajs.ConvertFile( filename, format, simplified, undefined, undefined );
2330+
let fileCount = result.FileCount();
2331+
2332+
// check if the conversion succeeded
2333+
if (result.IsSuccess() === false || fileCount === 0) {
2334+
handle_export_error( result.GetErrorCode() );
2335+
ajs = null;
2336+
result = null;
2337+
return;
2338+
}
2339+
2340+
// get the first result file and convert it to blob
2341+
let resultFile = await result.GetFile( 0 );
2342+
let jsonContent = resultFile.GetContent();
2343+
let blob = new Blob( [ jsonContent ], { type: 'application/octet-stream' } );
2344+
2345+
// Possible ASSIMP export formats, some with binary / ascii options:
2346+
// assjson, assbin, assxml, collada, x, stp, obj, objnomtl, 3ds, 3mf, pbrt
2347+
// gltf, gltf2, glb, glb2, stl, stlb, ply, plyb, fbx, fbxa, x3d
2348+
// m3d / m3da - disabled since no longer maintained within ASSIMP
2349+
// For proper file extension, shorten the format before zipping it up
2350+
let ext_to_change = { 'fbxa': 'fbx', 'assjson': 'json', 'collada': 'dae' }; // 'plyb': 'ply' ... etc
2351+
if (ext_to_change[ format ]) format = ext_to_change[ format ];
2352+
2353+
zip.file( filename + '.' + format, blob );
2354+
2355+
ajs = null;
2356+
result = null;
2357+
resultFile = null;
2358+
2359+
await process_zip( '_' + format.toUpperCase() );
2360+
});
2361+
}, function( error ) { handle_export_error( error ); }, options);
2362+
}
2363+
}
2364+
23082365
async function export_json() {
23092366
if (Obj) {
23102367
await start_export();

viewers/templates/PDB WebGPU.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@
997997

998998
let gltf_exporter = new GLTFExporter( manager );
999999

1000-
let options = { binary: binary, maxTextureSize: 1024 };
1000+
let options = { binary: binary };
10011001

10021002
let mesh_clone = await create_meshes();
10031003

@@ -1055,7 +1055,7 @@
10551055

10561056
let gltf_exporter = new GLTFExporter( manager );
10571057

1058-
let options = { binary: true, maxTextureSize: 1024 };
1058+
let options = { binary: true };
10591059

10601060
let mesh_clone = await create_meshes();
10611061

0 commit comments

Comments
 (0)