| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import { StringInput, Element } from 'flow';
- import { BaseNodeEditor } from '../BaseNodeEditor.js';
- import { NodeUtils } from 'three/webgpu';
- import { arrayBuffer } from 'three/tsl';
- export class FileEditor extends BaseNodeEditor {
- constructor( buffer = null, name = 'File' ) {
- super( 'File', arrayBuffer( buffer ), 250 );
- this.nameInput = new StringInput( name ).setReadOnly( true );
- this.add( new Element().add( this.nameInput ) );
- this.url = null;
- }
- set buffer( arrayBuffer ) {
- if ( this.url !== null ) {
- URL.revokeObjectUR( this.url );
- }
- this.value.value = arrayBuffer;
- this.url = null;
- }
- get buffer() {
- return this.value.value;
- }
- getURL() {
- if ( this.url === null ) {
- const blob = new Blob( [ this.buffer ], { type: 'application/octet-stream' } );
- this.url = URL.createObjectURL( blob );
- }
- return this.url;
- }
- serialize( data ) {
- super.serialize( data );
- data.buffer = NodeUtils.arrayBufferToBase64( this.buffer );
- data.name = this.nameInput.getValue();
- }
- deserialize( data ) {
- super.deserialize( data );
- this.buffer = NodeUtils.base64ToArrayBuffer( data.buffer );
- this.nameInput.setValue( data.name );
- }
- }
|