nodeMaterialBlock.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. import { NodeMaterialBlockConnectionPointTypes } from './Enums/nodeMaterialBlockConnectionPointTypes';
  2. import { NodeMaterialBuildState } from './nodeMaterialBuildState';
  3. import { Nullable } from '../../types';
  4. import { NodeMaterialConnectionPoint, NodeMaterialConnectionPointDirection } from './nodeMaterialBlockConnectionPoint';
  5. import { NodeMaterialBlockTargets } from './Enums/nodeMaterialBlockTargets';
  6. import { Effect } from '../effect';
  7. import { AbstractMesh } from '../../Meshes/abstractMesh';
  8. import { Mesh } from '../../Meshes/mesh';
  9. import { NodeMaterial, NodeMaterialDefines } from './nodeMaterial';
  10. import { InputBlock } from './Blocks/Input/inputBlock';
  11. import { UniqueIdGenerator } from '../../Misc/uniqueIdGenerator';
  12. import { Scene } from '../../scene';
  13. import { _TypeStore } from '../../Misc/typeStore';
  14. import { EffectFallbacks } from '../effectFallbacks';
  15. /**
  16. * Defines a block that can be used inside a node based material
  17. */
  18. export class NodeMaterialBlock {
  19. private _buildId: number;
  20. private _buildTarget: NodeMaterialBlockTargets;
  21. private _target: NodeMaterialBlockTargets;
  22. private _isFinalMerger = false;
  23. private _isInput = false;
  24. protected _isUnique = false;
  25. /** Gets or sets a boolean indicating that only one input can be connected at a time */
  26. public inputsAreExclusive = false;
  27. /** @hidden */
  28. public _codeVariableName = "";
  29. /** @hidden */
  30. public _inputs = new Array<NodeMaterialConnectionPoint>();
  31. /** @hidden */
  32. public _outputs = new Array<NodeMaterialConnectionPoint>();
  33. /** @hidden */
  34. public _preparationId: number;
  35. /**
  36. * Gets or sets the name of the block
  37. */
  38. public name: string;
  39. /**
  40. * Gets or sets the unique id of the node
  41. */
  42. public uniqueId: number;
  43. /**
  44. * Gets or sets the comments associated with this block
  45. */
  46. public comments: string = "";
  47. /**
  48. * Gets a boolean indicating that this block can only be used once per NodeMaterial
  49. */
  50. public get isUnique() {
  51. return this._isUnique;
  52. }
  53. /**
  54. * Gets a boolean indicating that this block is an end block (e.g. it is generating a system value)
  55. */
  56. public get isFinalMerger(): boolean {
  57. return this._isFinalMerger;
  58. }
  59. /**
  60. * Gets a boolean indicating that this block is an input (e.g. it sends data to the shader)
  61. */
  62. public get isInput(): boolean {
  63. return this._isInput;
  64. }
  65. /**
  66. * Gets or sets the build Id
  67. */
  68. public get buildId(): number {
  69. return this._buildId;
  70. }
  71. public set buildId(value: number) {
  72. this._buildId = value;
  73. }
  74. /**
  75. * Gets or sets the target of the block
  76. */
  77. public get target() {
  78. return this._target;
  79. }
  80. public set target(value: NodeMaterialBlockTargets) {
  81. if ((this._target & value) !== 0) {
  82. return;
  83. }
  84. this._target = value;
  85. }
  86. /**
  87. * Gets the list of input points
  88. */
  89. public get inputs(): NodeMaterialConnectionPoint[] {
  90. return this._inputs;
  91. }
  92. /** Gets the list of output points */
  93. public get outputs(): NodeMaterialConnectionPoint[] {
  94. return this._outputs;
  95. }
  96. /**
  97. * Find an input by its name
  98. * @param name defines the name of the input to look for
  99. * @returns the input or null if not found
  100. */
  101. public getInputByName(name: string) {
  102. let filter = this._inputs.filter((e) => e.name === name);
  103. if (filter.length) {
  104. return filter[0];
  105. }
  106. return null;
  107. }
  108. /**
  109. * Find an output by its name
  110. * @param name defines the name of the outputto look for
  111. * @returns the output or null if not found
  112. */
  113. public getOutputByName(name: string) {
  114. let filter = this._outputs.filter((e) => e.name === name);
  115. if (filter.length) {
  116. return filter[0];
  117. }
  118. return null;
  119. }
  120. /**
  121. * Creates a new NodeMaterialBlock
  122. * @param name defines the block name
  123. * @param target defines the target of that block (Vertex by default)
  124. * @param isFinalMerger defines a boolean indicating that this block is an end block (e.g. it is generating a system value). Default is false
  125. * @param isInput defines a boolean indicating that this block is an input (e.g. it sends data to the shader). Default is false
  126. */
  127. public constructor(name: string, target = NodeMaterialBlockTargets.Vertex, isFinalMerger = false, isInput = false) {
  128. this.name = name;
  129. this._target = target;
  130. this._isFinalMerger = isFinalMerger;
  131. this._isInput = isInput;
  132. this.uniqueId = UniqueIdGenerator.UniqueId;
  133. }
  134. /**
  135. * Initialize the block and prepare the context for build
  136. * @param state defines the state that will be used for the build
  137. */
  138. public initialize(state: NodeMaterialBuildState) {
  139. // Do nothing
  140. }
  141. /**
  142. * Bind data to effect. Will only be called for blocks with isBindable === true
  143. * @param effect defines the effect to bind data to
  144. * @param nodeMaterial defines the hosting NodeMaterial
  145. * @param mesh defines the mesh that will be rendered
  146. */
  147. public bind(effect: Effect, nodeMaterial: NodeMaterial, mesh?: Mesh) {
  148. // Do nothing
  149. }
  150. protected _declareOutput(output: NodeMaterialConnectionPoint, state: NodeMaterialBuildState): string {
  151. return `${state._getGLType(output.type)} ${output.associatedVariableName}`;
  152. }
  153. protected _writeVariable(currentPoint: NodeMaterialConnectionPoint): string {
  154. let connectionPoint = currentPoint.connectedPoint;
  155. if (connectionPoint) {
  156. return `${currentPoint.associatedVariableName}`;
  157. }
  158. return `0.`;
  159. }
  160. protected _writeFloat(value: number) {
  161. let stringVersion = value.toString();
  162. if (stringVersion.indexOf(".") === -1) {
  163. stringVersion += ".0";
  164. }
  165. return `${stringVersion}`;
  166. }
  167. /**
  168. * Gets the current class name e.g. "NodeMaterialBlock"
  169. * @returns the class name
  170. */
  171. public getClassName() {
  172. return "NodeMaterialBlock";
  173. }
  174. /**
  175. * Register a new input. Must be called inside a block constructor
  176. * @param name defines the connection point name
  177. * @param type defines the connection point type
  178. * @param isOptional defines a boolean indicating that this input can be omitted
  179. * @param target defines the target to use to limit the connection point (will be VertexAndFragment by default)
  180. * @param point an already created connection point. If not provided, create a new one
  181. * @returns the current block
  182. */
  183. public registerInput(name: string, type: NodeMaterialBlockConnectionPointTypes, isOptional: boolean = false, target?: NodeMaterialBlockTargets, point?: NodeMaterialConnectionPoint) {
  184. point = point ?? new NodeMaterialConnectionPoint(name, this, NodeMaterialConnectionPointDirection.Input);
  185. point.type = type;
  186. point.isOptional = isOptional;
  187. if (target) {
  188. point.target = target;
  189. }
  190. this._inputs.push(point);
  191. return this;
  192. }
  193. /**
  194. * Register a new output. Must be called inside a block constructor
  195. * @param name defines the connection point name
  196. * @param type defines the connection point type
  197. * @param target defines the target to use to limit the connection point (will be VertexAndFragment by default)
  198. * @param point an already created connection point. If not provided, create a new one
  199. * @returns the current block
  200. */
  201. public registerOutput(name: string, type: NodeMaterialBlockConnectionPointTypes, target?: NodeMaterialBlockTargets, point?: NodeMaterialConnectionPoint) {
  202. point = point ?? new NodeMaterialConnectionPoint(name, this, NodeMaterialConnectionPointDirection.Output);
  203. point.type = type;
  204. if (target) {
  205. point.target = target;
  206. }
  207. this._outputs.push(point);
  208. return this;
  209. }
  210. /**
  211. * Will return the first available input e.g. the first one which is not an uniform or an attribute
  212. * @param forOutput defines an optional connection point to check compatibility with
  213. * @returns the first available input or null
  214. */
  215. public getFirstAvailableInput(forOutput: Nullable<NodeMaterialConnectionPoint> = null) {
  216. for (var input of this._inputs) {
  217. if (!input.connectedPoint) {
  218. if (!forOutput || (forOutput.type === input.type) || (input.type === NodeMaterialBlockConnectionPointTypes.AutoDetect)) {
  219. return input;
  220. }
  221. }
  222. }
  223. return null;
  224. }
  225. /**
  226. * Will return the first available output e.g. the first one which is not yet connected and not a varying
  227. * @param forBlock defines an optional block to check compatibility with
  228. * @returns the first available input or null
  229. */
  230. public getFirstAvailableOutput(forBlock: Nullable<NodeMaterialBlock> = null) {
  231. for (var output of this._outputs) {
  232. if (!forBlock || !forBlock.target || forBlock.target === NodeMaterialBlockTargets.Neutral || (forBlock.target & output.target) !== 0) {
  233. return output;
  234. }
  235. }
  236. return null;
  237. }
  238. /**
  239. * Gets the sibling of the given output
  240. * @param current defines the current output
  241. * @returns the next output in the list or null
  242. */
  243. public getSiblingOutput(current: NodeMaterialConnectionPoint) {
  244. let index = this._outputs.indexOf(current);
  245. if (index === -1 || index >= this._outputs.length) {
  246. return null;
  247. }
  248. return this._outputs[index + 1];
  249. }
  250. /**
  251. * Connect current block with another block
  252. * @param other defines the block to connect with
  253. * @param options define the various options to help pick the right connections
  254. * @returns the current block
  255. */
  256. public connectTo(other: NodeMaterialBlock, options?: {
  257. input?: string,
  258. output?: string,
  259. outputSwizzle?: string
  260. }) {
  261. if (this._outputs.length === 0) {
  262. return;
  263. }
  264. let output = options && options.output ? this.getOutputByName(options.output) : this.getFirstAvailableOutput(other);
  265. let notFound = true;
  266. while (notFound) {
  267. let input = options && options.input ? other.getInputByName(options.input) : other.getFirstAvailableInput(output);
  268. if (output && input && output.canConnectTo(input)) {
  269. output.connectTo(input);
  270. notFound = false;
  271. } else if (!output) {
  272. throw "Unable to find a compatible match";
  273. } else {
  274. output = this.getSiblingOutput(output);
  275. }
  276. }
  277. return this;
  278. }
  279. protected _buildBlock(state: NodeMaterialBuildState) {
  280. // Empty. Must be defined by child nodes
  281. }
  282. /**
  283. * Add uniforms, samplers and uniform buffers at compilation time
  284. * @param state defines the state to update
  285. * @param nodeMaterial defines the node material requesting the update
  286. * @param defines defines the material defines to update
  287. * @param uniformBuffers defines the list of uniform buffer names
  288. */
  289. public updateUniformsAndSamples(state: NodeMaterialBuildState, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines, uniformBuffers: string[]) {
  290. // Do nothing
  291. }
  292. /**
  293. * Add potential fallbacks if shader compilation fails
  294. * @param mesh defines the mesh to be rendered
  295. * @param fallbacks defines the current prioritized list of fallbacks
  296. */
  297. public provideFallbacks(mesh: AbstractMesh, fallbacks: EffectFallbacks) {
  298. // Do nothing
  299. }
  300. /**
  301. * Initialize defines for shader compilation
  302. * @param mesh defines the mesh to be rendered
  303. * @param nodeMaterial defines the node material requesting the update
  304. * @param defines defines the material defines to update
  305. * @param useInstances specifies that instances should be used
  306. */
  307. public initializeDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines, useInstances: boolean = false) {
  308. }
  309. /**
  310. * Update defines for shader compilation
  311. * @param mesh defines the mesh to be rendered
  312. * @param nodeMaterial defines the node material requesting the update
  313. * @param defines defines the material defines to update
  314. * @param useInstances specifies that instances should be used
  315. */
  316. public prepareDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines, useInstances: boolean = false) {
  317. // Do nothing
  318. }
  319. /**
  320. * Lets the block try to connect some inputs automatically
  321. * @param material defines the hosting NodeMaterial
  322. */
  323. public autoConfigure(material: NodeMaterial) {
  324. // Do nothing
  325. }
  326. /**
  327. * Function called when a block is declared as repeatable content generator
  328. * @param vertexShaderState defines the current compilation state for the vertex shader
  329. * @param fragmentShaderState defines the current compilation state for the fragment shader
  330. * @param mesh defines the mesh to be rendered
  331. * @param defines defines the material defines to update
  332. */
  333. public replaceRepeatableContent(vertexShaderState: NodeMaterialBuildState, fragmentShaderState: NodeMaterialBuildState, mesh: AbstractMesh, defines: NodeMaterialDefines) {
  334. // Do nothing
  335. }
  336. /**
  337. * Checks if the block is ready
  338. * @param mesh defines the mesh to be rendered
  339. * @param nodeMaterial defines the node material requesting the update
  340. * @param defines defines the material defines to update
  341. * @param useInstances specifies that instances should be used
  342. * @returns true if the block is ready
  343. */
  344. public isReady(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines, useInstances: boolean = false) {
  345. return true;
  346. }
  347. protected _linkConnectionTypes(inputIndex0: number, inputIndex1: number) {
  348. this._inputs[inputIndex0]._linkedConnectionSource = this._inputs[inputIndex1];
  349. this._inputs[inputIndex1]._linkedConnectionSource = this._inputs[inputIndex0];
  350. }
  351. private _processBuild(block: NodeMaterialBlock, state: NodeMaterialBuildState, input: NodeMaterialConnectionPoint, activeBlocks: NodeMaterialBlock[]) {
  352. block.build(state, activeBlocks);
  353. const localBlockIsFragment = (state._vertexState != null);
  354. const otherBlockWasGeneratedInVertexShader = block._buildTarget === NodeMaterialBlockTargets.Vertex && block.target !== NodeMaterialBlockTargets.VertexAndFragment;
  355. if (localBlockIsFragment && (
  356. ((block.target & block._buildTarget) === 0) ||
  357. ((block.target & input.target) === 0) ||
  358. (this.target !== NodeMaterialBlockTargets.VertexAndFragment && otherBlockWasGeneratedInVertexShader)
  359. )) { // context switch! We need a varying
  360. if ((!block.isInput && state.target !== block._buildTarget) // block was already emitted by vertex shader
  361. || (block.isInput && (block as InputBlock).isAttribute) // block is an attribute
  362. ) {
  363. let connectedPoint = input.connectedPoint!;
  364. if (state._vertexState._emitVaryingFromString("v_" + connectedPoint.associatedVariableName, state._getGLType(connectedPoint.type))) {
  365. state._vertexState.compilationString += `${"v_" + connectedPoint.associatedVariableName} = ${connectedPoint.associatedVariableName};\r\n`;
  366. }
  367. input.associatedVariableName = "v_" + connectedPoint.associatedVariableName;
  368. input._enforceAssociatedVariableName = true;
  369. }
  370. }
  371. }
  372. /**
  373. * Compile the current node and generate the shader code
  374. * @param state defines the current compilation state (uniforms, samplers, current string)
  375. * @param activeBlocks defines the list of active blocks (i.e. blocks to compile)
  376. * @returns true if already built
  377. */
  378. public build(state: NodeMaterialBuildState, activeBlocks: NodeMaterialBlock[]): boolean {
  379. if (this._buildId === state.sharedData.buildId) {
  380. return true;
  381. }
  382. if (!this.isInput) {
  383. /** Prepare outputs */
  384. for (var output of this._outputs) {
  385. if (!output.associatedVariableName) {
  386. output.associatedVariableName = state._getFreeVariableName(output.name);
  387. }
  388. }
  389. }
  390. // Check if "parent" blocks are compiled
  391. for (var input of this._inputs) {
  392. if (!input.connectedPoint) {
  393. if (!input.isOptional) { // Emit a warning
  394. state.sharedData.checks.notConnectedNonOptionalInputs.push(input);
  395. }
  396. continue;
  397. }
  398. if (this.target !== NodeMaterialBlockTargets.Neutral) {
  399. if ((input.target & this.target!) === 0) {
  400. continue;
  401. }
  402. if ((input.target & state.target!) === 0) {
  403. continue;
  404. }
  405. }
  406. let block = input.connectedPoint.ownerBlock;
  407. if (block && block !== this) {
  408. this._processBuild(block, state, input, activeBlocks);
  409. }
  410. }
  411. if (this._buildId === state.sharedData.buildId) {
  412. return true; // Need to check again as inputs can be connected multiple time to this endpoint
  413. }
  414. // Logs
  415. if (state.sharedData.verbose) {
  416. console.log(`${state.target === NodeMaterialBlockTargets.Vertex ? "Vertex shader" : "Fragment shader"}: Building ${this.name} [${this.getClassName()}]`);
  417. }
  418. // Checks final outputs
  419. if (this.isFinalMerger) {
  420. switch (state.target) {
  421. case NodeMaterialBlockTargets.Vertex:
  422. state.sharedData.checks.emitVertex = true;
  423. break;
  424. case NodeMaterialBlockTargets.Fragment:
  425. state.sharedData.checks.emitFragment = true;
  426. break;
  427. }
  428. }
  429. if (!this.isInput && state.sharedData.emitComments) {
  430. state.compilationString += `\r\n//${this.name}\r\n`;
  431. }
  432. this._buildBlock(state);
  433. this._buildId = state.sharedData.buildId;
  434. this._buildTarget = state.target;
  435. // Compile connected blocks
  436. for (var output of this._outputs) {
  437. if ((output.target & state.target) === 0) {
  438. continue;
  439. }
  440. for (var endpoint of output.endpoints) {
  441. let block = endpoint.ownerBlock;
  442. if (block && (block.target & state.target) !== 0 && activeBlocks.indexOf(block) !== -1) {
  443. this._processBuild(block, state, endpoint, activeBlocks);
  444. }
  445. }
  446. }
  447. return false;
  448. }
  449. protected _inputRename(name: string) {
  450. return name;
  451. }
  452. protected _outputRename(name: string) {
  453. return name;
  454. }
  455. protected _dumpPropertiesCode() {
  456. return "";
  457. }
  458. /** @hidden */
  459. public _dumpCode(uniqueNames: string[], alreadyDumped: NodeMaterialBlock[]) {
  460. alreadyDumped.push(this);
  461. let codeString: string;
  462. // Get unique name
  463. let nameAsVariableName = this.name.replace(/[^A-Za-z_]+/g, "");
  464. this._codeVariableName = nameAsVariableName || `${this.getClassName()}_${this.uniqueId}`;
  465. if (uniqueNames.indexOf(this._codeVariableName) !== -1) {
  466. let index = 0;
  467. do {
  468. index++;
  469. this._codeVariableName = nameAsVariableName + index;
  470. }
  471. while (uniqueNames.indexOf(this._codeVariableName) !== -1);
  472. }
  473. uniqueNames.push(this._codeVariableName);
  474. // Declaration
  475. codeString = `\r\n// ${this.getClassName()}\r\n`;
  476. if (this.comments) {
  477. codeString += `// ${this.comments}\r\n`;
  478. }
  479. codeString += `var ${this._codeVariableName} = new BABYLON.${this.getClassName()}("${this.name}");\r\n`;
  480. // Properties
  481. codeString += this._dumpPropertiesCode();
  482. // Inputs
  483. for (var input of this.inputs) {
  484. if (!input.isConnected) {
  485. continue;
  486. }
  487. var connectedOutput = input.connectedPoint!;
  488. var connectedBlock = connectedOutput.ownerBlock;
  489. if (alreadyDumped.indexOf(connectedBlock) === -1) {
  490. codeString += connectedBlock._dumpCode(uniqueNames, alreadyDumped);
  491. }
  492. }
  493. // Outputs
  494. for (var output of this.outputs) {
  495. if (!output.hasEndpoints) {
  496. continue;
  497. }
  498. for (var endpoint of output.endpoints) {
  499. var connectedBlock = endpoint.ownerBlock;
  500. if (connectedBlock && alreadyDumped.indexOf(connectedBlock) === -1) {
  501. codeString += connectedBlock._dumpCode(uniqueNames, alreadyDumped);
  502. }
  503. }
  504. }
  505. return codeString;
  506. }
  507. /** @hidden */
  508. public _dumpCodeForOutputConnections(alreadyDumped: NodeMaterialBlock[]) {
  509. let codeString = "";
  510. if (alreadyDumped.indexOf(this) !== -1) {
  511. return codeString;
  512. }
  513. alreadyDumped.push(this);
  514. for (var input of this.inputs) {
  515. if (!input.isConnected) {
  516. continue;
  517. }
  518. var connectedOutput = input.connectedPoint!;
  519. var connectedBlock = connectedOutput.ownerBlock;
  520. codeString += connectedBlock._dumpCodeForOutputConnections(alreadyDumped);
  521. codeString += `${connectedBlock._codeVariableName}.${connectedBlock._outputRename(connectedOutput.name)}.connectTo(${this._codeVariableName}.${this._inputRename(input.name)});\r\n`;
  522. }
  523. return codeString;
  524. }
  525. /**
  526. * Clone the current block to a new identical block
  527. * @param scene defines the hosting scene
  528. * @param rootUrl defines the root URL to use to load textures and relative dependencies
  529. * @returns a copy of the current block
  530. */
  531. public clone(scene: Scene, rootUrl: string = "") {
  532. let serializationObject = this.serialize();
  533. let blockType = _TypeStore.GetClass(serializationObject.customType);
  534. if (blockType) {
  535. let block: NodeMaterialBlock = new blockType();
  536. block._deserialize(serializationObject, scene, rootUrl);
  537. return block;
  538. }
  539. return null;
  540. }
  541. /**
  542. * Serializes this block in a JSON representation
  543. * @returns the serialized block object
  544. */
  545. public serialize(): any {
  546. let serializationObject: any = {};
  547. serializationObject.customType = "BABYLON." + this.getClassName();
  548. serializationObject.id = this.uniqueId;
  549. serializationObject.name = this.name;
  550. serializationObject.comments = this.comments;
  551. serializationObject.inputs = [];
  552. for (var input of this.inputs) {
  553. serializationObject.inputs.push(input.serialize());
  554. }
  555. return serializationObject;
  556. }
  557. /** @hidden */
  558. public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {
  559. this.name = serializationObject.name;
  560. this.comments = serializationObject.comments;
  561. }
  562. /**
  563. * Release resources
  564. */
  565. public dispose() {
  566. for (var input of this.inputs) {
  567. input.dispose();
  568. }
  569. for (var output of this.outputs) {
  570. output.dispose();
  571. }
  572. }
  573. }