1- import type { FileRenderPlugin } from '../../modules/file-render- plugin.ts' ;
2- import { registerFileRenderPlugin } from '../../modules/file-render-plugin .ts' ;
1+ import type { FileRenderPlugin } from '../plugin.ts' ;
2+ import { extname } from '../../utils .ts' ;
33
4- /**
5- * 3D model file render plugin
6- *
7- * support common 3D model file formats, use online-3d-viewer library for rendering
8- */
9- export function register3DViewerPlugin ( ) : void {
10- // supported 3D file extensions
4+ // support common 3D model file formats, use online-3d-viewer library for rendering
5+ export function newRenderPlugin3DViewer ( ) : FileRenderPlugin {
6+ // Some extensions are text-based formats:
7+ // .3mf .amf .brep: XML
8+ // .fbx: XML or BINARY
9+ // .dae .gltf: JSON
10+ // .ifc, .igs, .iges, .stp, .step are: TEXT
11+ // .stl .ply: TEXT or BINARY
12+ // .obj .off .wrl: TEXT
13+ // TODO: So we need to be able to render when the file is recognized as plaintext file by backend
1114 const SUPPORTED_EXTENSIONS = [
1215 '.3dm' , '.3ds' , '.3mf' , '.amf' , '.bim' , '.brep' ,
1316 '.dae' , '.fbx' , '.fcstd' , '.glb' , '.gltf' ,
1417 '.ifc' , '.igs' , '.iges' , '.stp' , '.step' ,
1518 '.stl' , '.obj' , '.off' , '.ply' , '.wrl' ,
1619 ] ;
1720
18- // create and register plugin
19- const plugin : FileRenderPlugin = {
21+ return {
2022 name : '3d-model-viewer' ,
2123
22- // check if file extension is a supported 3D file
2324 canHandle ( filename : string , _mimeType : string ) : boolean {
24- const ext = filename . substring ( filename . lastIndexOf ( '.' ) ) . toLowerCase ( ) ;
25+ const ext = extname ( filename ) . toLowerCase ( ) ;
2526 return SUPPORTED_EXTENSIONS . includes ( ext ) ;
2627 } ,
2728
28- // render 3D model
2929 async render ( container : HTMLElement , fileUrl : string ) : Promise < void > {
3030 const OV = await import ( /* webpackChunkName: "online-3d-viewer" */ 'online-3d-viewer' ) ;
3131 container . classList . add ( 'model3d-content' ) ;
@@ -37,6 +37,4 @@ export function register3DViewerPlugin(): void {
3737 viewer . LoadModelFromUrlList ( [ fileUrl ] ) ;
3838 } ,
3939 } ;
40-
41- registerFileRenderPlugin ( plugin ) ;
4240}
0 commit comments