inputBlock.ts 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. import { NodeMaterialBlock } from '../../nodeMaterialBlock';
  2. import { NodeMaterialBlockConnectionPointTypes } from '../../Enums/nodeMaterialBlockConnectionPointTypes';
  3. import { NodeMaterialBlockConnectionPointMode } from '../../Enums/nodeMaterialBlockConnectionPointMode';
  4. import { NodeMaterialSystemValues } from '../../Enums/nodeMaterialSystemValues';
  5. import { Nullable } from '../../../../types';
  6. import { Effect } from '../../../../Materials/effect';
  7. import { Matrix, Vector2, Vector3, Vector4 } from '../../../../Maths/math.vector';
  8. import { Scene } from '../../../../scene';
  9. import { NodeMaterialConnectionPoint } from '../../nodeMaterialBlockConnectionPoint';
  10. import { NodeMaterialBuildState } from '../../nodeMaterialBuildState';
  11. import { NodeMaterialBlockTargets } from '../../Enums/nodeMaterialBlockTargets';
  12. import { _TypeStore } from '../../../../Misc/typeStore';
  13. import { Color3, Color4 } from '../../../../Maths/math';
  14. import { AnimatedInputBlockTypes } from './animatedInputBlockTypes';
  15. /**
  16. * Block used to expose an input value
  17. */
  18. export class InputBlock extends NodeMaterialBlock {
  19. private _mode = NodeMaterialBlockConnectionPointMode.Undefined;
  20. private _associatedVariableName: string;
  21. private _storedValue: any;
  22. private _valueCallback: () => any;
  23. private _type: NodeMaterialBlockConnectionPointTypes;
  24. private _animationType = AnimatedInputBlockTypes.None;
  25. /** Gets or set a value used to limit the range of float values */
  26. public min: number = 0;
  27. /** Gets or set a value used to limit the range of float values */
  28. public max: number = 0;
  29. /** Gets or set a value indicating that this input can only get 0 and 1 values */
  30. public isBoolean: boolean = false;
  31. /** Gets or sets a value used by the Node Material editor to determine how to configure the current value if it is a matrix */
  32. public matrixMode: number = 0;
  33. /** @hidden */
  34. public _systemValue: Nullable<NodeMaterialSystemValues> = null;
  35. /** Gets or sets a boolean indicating that this input can be edited in the Inspector (false by default) */
  36. public visibleInInspector = false;
  37. /** Gets or sets a boolean indicating that the value of this input will not change after a build */
  38. public isConstant = false;
  39. /** Gets or sets the group to use to display this block in the Inspector */
  40. public groupInInspector = "";
  41. /**
  42. * Gets or sets the connection point type (default is float)
  43. */
  44. public get type(): NodeMaterialBlockConnectionPointTypes {
  45. if (this._type === NodeMaterialBlockConnectionPointTypes.AutoDetect) {
  46. if (this.isUniform && this.value != null) {
  47. if (!isNaN(this.value)) {
  48. this._type = NodeMaterialBlockConnectionPointTypes.Float;
  49. return this._type;
  50. }
  51. switch (this.value.getClassName()) {
  52. case "Vector2":
  53. this._type = NodeMaterialBlockConnectionPointTypes.Vector2;
  54. return this._type;
  55. case "Vector3":
  56. this._type = NodeMaterialBlockConnectionPointTypes.Vector3;
  57. return this._type;
  58. case "Vector4":
  59. this._type = NodeMaterialBlockConnectionPointTypes.Vector4;
  60. return this._type;
  61. case "Color3":
  62. this._type = NodeMaterialBlockConnectionPointTypes.Color3;
  63. return this._type;
  64. case "Color4":
  65. this._type = NodeMaterialBlockConnectionPointTypes.Color4;
  66. return this._type;
  67. case "Matrix":
  68. this._type = NodeMaterialBlockConnectionPointTypes.Matrix;
  69. return this._type;
  70. }
  71. }
  72. if (this.isAttribute) {
  73. switch (this.name) {
  74. case "position":
  75. case "normal":
  76. case "tangent":
  77. this._type = NodeMaterialBlockConnectionPointTypes.Vector3;
  78. return this._type;
  79. case "uv":
  80. case "uv2":
  81. this._type = NodeMaterialBlockConnectionPointTypes.Vector2;
  82. return this._type;
  83. case "matricesIndices":
  84. case "matricesWeights":
  85. case "world0":
  86. case "world1":
  87. case "world2":
  88. case "world3":
  89. this._type = NodeMaterialBlockConnectionPointTypes.Vector4;
  90. return this._type;
  91. case "color":
  92. this._type = NodeMaterialBlockConnectionPointTypes.Color4;
  93. return this._type;
  94. }
  95. }
  96. if (this.isSystemValue) {
  97. switch (this._systemValue) {
  98. case NodeMaterialSystemValues.World:
  99. case NodeMaterialSystemValues.WorldView:
  100. case NodeMaterialSystemValues.WorldViewProjection:
  101. case NodeMaterialSystemValues.View:
  102. case NodeMaterialSystemValues.ViewProjection:
  103. case NodeMaterialSystemValues.Projection:
  104. this._type = NodeMaterialBlockConnectionPointTypes.Matrix;
  105. return this._type;
  106. case NodeMaterialSystemValues.CameraPosition:
  107. this._type = NodeMaterialBlockConnectionPointTypes.Vector3;
  108. return this._type;
  109. case NodeMaterialSystemValues.FogColor:
  110. this._type = NodeMaterialBlockConnectionPointTypes.Color3;
  111. return this._type;
  112. case NodeMaterialSystemValues.DeltaTime:
  113. this._type = NodeMaterialBlockConnectionPointTypes.Float;
  114. return this._type;
  115. }
  116. }
  117. }
  118. return this._type;
  119. }
  120. /**
  121. * Creates a new InputBlock
  122. * @param name defines the block name
  123. * @param target defines the target of that block (Vertex by default)
  124. * @param type defines the type of the input (can be set to NodeMaterialBlockConnectionPointTypes.AutoDetect)
  125. */
  126. public constructor(name: string, target = NodeMaterialBlockTargets.Vertex, type: NodeMaterialBlockConnectionPointTypes = NodeMaterialBlockConnectionPointTypes.AutoDetect) {
  127. super(name, target, false, true);
  128. this._type = type;
  129. this.setDefaultValue();
  130. this.registerOutput("output", type);
  131. }
  132. /**
  133. * Gets the output component
  134. */
  135. public get output(): NodeMaterialConnectionPoint {
  136. return this._outputs[0];
  137. }
  138. /**
  139. * Set the source of this connection point to a vertex attribute
  140. * @param attributeName defines the attribute name (position, uv, normal, etc...). If not specified it will take the connection point name
  141. * @returns the current connection point
  142. */
  143. public setAsAttribute(attributeName?: string): InputBlock {
  144. if (attributeName) {
  145. this.name = attributeName;
  146. }
  147. this._mode = NodeMaterialBlockConnectionPointMode.Attribute;
  148. return this;
  149. }
  150. /**
  151. * Set the source of this connection point to a system value
  152. * @param value define the system value to use (world, view, etc...) or null to switch to manual value
  153. * @returns the current connection point
  154. */
  155. public setAsSystemValue(value: Nullable<NodeMaterialSystemValues>): InputBlock {
  156. this.systemValue = value;
  157. return this;
  158. }
  159. /**
  160. * Gets or sets the value of that point.
  161. * Please note that this value will be ignored if valueCallback is defined
  162. */
  163. public get value(): any {
  164. return this._storedValue;
  165. }
  166. public set value(value: any) {
  167. if (this.type === NodeMaterialBlockConnectionPointTypes.Float) {
  168. if (this.isBoolean) {
  169. value = value ? 1 : 0;
  170. }
  171. else if (this.min !== this.max) {
  172. value = Math.max(this.min, value);
  173. value = Math.min(this.max, value);
  174. }
  175. }
  176. this._storedValue = value;
  177. this._mode = NodeMaterialBlockConnectionPointMode.Uniform;
  178. }
  179. /**
  180. * Gets or sets a callback used to get the value of that point.
  181. * Please note that setting this value will force the connection point to ignore the value property
  182. */
  183. public get valueCallback(): () => any {
  184. return this._valueCallback;
  185. }
  186. public set valueCallback(value: () => any) {
  187. this._valueCallback = value;
  188. this._mode = NodeMaterialBlockConnectionPointMode.Uniform;
  189. }
  190. /**
  191. * Gets or sets the associated variable name in the shader
  192. */
  193. public get associatedVariableName(): string {
  194. return this._associatedVariableName;
  195. }
  196. public set associatedVariableName(value: string) {
  197. this._associatedVariableName = value;
  198. }
  199. /** Gets or sets the type of animation applied to the input */
  200. public get animationType() {
  201. return this._animationType;
  202. }
  203. public set animationType(value: AnimatedInputBlockTypes) {
  204. this._animationType = value;
  205. }
  206. /**
  207. * Gets a boolean indicating that this connection point not defined yet
  208. */
  209. public get isUndefined(): boolean {
  210. return this._mode === NodeMaterialBlockConnectionPointMode.Undefined;
  211. }
  212. /**
  213. * Gets or sets a boolean indicating that this connection point is coming from an uniform.
  214. * In this case the connection point name must be the name of the uniform to use.
  215. * Can only be set on inputs
  216. */
  217. public get isUniform(): boolean {
  218. return this._mode === NodeMaterialBlockConnectionPointMode.Uniform;
  219. }
  220. public set isUniform(value: boolean) {
  221. this._mode = value ? NodeMaterialBlockConnectionPointMode.Uniform : NodeMaterialBlockConnectionPointMode.Undefined;
  222. this.associatedVariableName = "";
  223. }
  224. /**
  225. * Gets or sets a boolean indicating that this connection point is coming from an attribute.
  226. * In this case the connection point name must be the name of the attribute to use
  227. * Can only be set on inputs
  228. */
  229. public get isAttribute(): boolean {
  230. return this._mode === NodeMaterialBlockConnectionPointMode.Attribute;
  231. }
  232. public set isAttribute(value: boolean) {
  233. this._mode = value ? NodeMaterialBlockConnectionPointMode.Attribute : NodeMaterialBlockConnectionPointMode.Undefined;
  234. this.associatedVariableName = "";
  235. }
  236. /**
  237. * Gets or sets a boolean indicating that this connection point is generating a varying variable.
  238. * Can only be set on exit points
  239. */
  240. public get isVarying(): boolean {
  241. return this._mode === NodeMaterialBlockConnectionPointMode.Varying;
  242. }
  243. public set isVarying(value: boolean) {
  244. this._mode = value ? NodeMaterialBlockConnectionPointMode.Varying : NodeMaterialBlockConnectionPointMode.Undefined;
  245. this.associatedVariableName = "";
  246. }
  247. /**
  248. * Gets a boolean indicating that the current connection point is a system value
  249. */
  250. public get isSystemValue(): boolean {
  251. return this._systemValue != null;
  252. }
  253. /**
  254. * Gets or sets the current well known value or null if not defined as a system value
  255. */
  256. public get systemValue(): Nullable<NodeMaterialSystemValues> {
  257. return this._systemValue;
  258. }
  259. public set systemValue(value: Nullable<NodeMaterialSystemValues>) {
  260. this._mode = NodeMaterialBlockConnectionPointMode.Uniform;
  261. this.associatedVariableName = "";
  262. this._systemValue = value;
  263. }
  264. /**
  265. * Gets the current class name
  266. * @returns the class name
  267. */
  268. public getClassName() {
  269. return "InputBlock";
  270. }
  271. /**
  272. * Animate the input if animationType !== None
  273. * @param scene defines the rendering scene
  274. */
  275. public animate(scene: Scene) {
  276. switch (this._animationType) {
  277. case AnimatedInputBlockTypes.Time: {
  278. if (this.type === NodeMaterialBlockConnectionPointTypes.Float) {
  279. this.value += scene.getAnimationRatio() * 0.01;
  280. }
  281. break;
  282. }
  283. }
  284. }
  285. private _emitDefine(define: string): string {
  286. if (define[0] === "!") {
  287. return `#ifndef ${define.substring(1)}\r\n`;
  288. }
  289. return `#ifdef ${define}\r\n`;
  290. }
  291. public initialize(state: NodeMaterialBuildState) {
  292. this.associatedVariableName = "";
  293. }
  294. /**
  295. * Set the input block to its default value (based on its type)
  296. */
  297. public setDefaultValue() {
  298. switch (this.type) {
  299. case NodeMaterialBlockConnectionPointTypes.Float:
  300. this.value = 0;
  301. break;
  302. case NodeMaterialBlockConnectionPointTypes.Vector2:
  303. this.value = Vector2.Zero();
  304. break;
  305. case NodeMaterialBlockConnectionPointTypes.Vector3:
  306. this.value = Vector3.Zero();
  307. break;
  308. case NodeMaterialBlockConnectionPointTypes.Vector4:
  309. this.value = Vector4.Zero();
  310. break;
  311. case NodeMaterialBlockConnectionPointTypes.Color3:
  312. this.value = Color3.White();
  313. break;
  314. case NodeMaterialBlockConnectionPointTypes.Color4:
  315. this.value = new Color4(1, 1, 1, 1);
  316. break;
  317. case NodeMaterialBlockConnectionPointTypes.Matrix:
  318. this.value = Matrix.Identity();
  319. break;
  320. }
  321. }
  322. private _emitConstant(state: NodeMaterialBuildState) {
  323. switch (this.type) {
  324. case NodeMaterialBlockConnectionPointTypes.Float:
  325. return `${state._emitFloat(this.value)}`;
  326. case NodeMaterialBlockConnectionPointTypes.Vector2:
  327. return `vec2(${this.value.x}, ${this.value.y})`;
  328. case NodeMaterialBlockConnectionPointTypes.Vector3:
  329. return `vec3(${this.value.x}, ${this.value.y}, ${this.value.z})`;
  330. case NodeMaterialBlockConnectionPointTypes.Vector4:
  331. return `vec4(${this.value.x}, ${this.value.y}, ${this.value.z}, ${this.value.w})`;
  332. case NodeMaterialBlockConnectionPointTypes.Color3:
  333. return `vec3(${this.value.r}, ${this.value.g}, ${this.value.b})`;
  334. case NodeMaterialBlockConnectionPointTypes.Color4:
  335. return `vec4(${this.value.r}, ${this.value.g}, ${this.value.b}, ${this.value.a})`;
  336. }
  337. return "";
  338. }
  339. private _emit(state: NodeMaterialBuildState, define?: string) {
  340. // Uniforms
  341. if (this.isUniform) {
  342. if (!this.associatedVariableName) {
  343. this.associatedVariableName = state._getFreeVariableName("u_" + this.name);
  344. }
  345. if (this.isConstant) {
  346. if (state.constants.indexOf(this.associatedVariableName) !== -1) {
  347. return;
  348. }
  349. state.constants.push(this.associatedVariableName);
  350. state._constantDeclaration += this._declareOutput(this.output, state) + ` = ${this._emitConstant(state)};\r\n`;
  351. return;
  352. }
  353. if (state.uniforms.indexOf(this.associatedVariableName) !== -1) {
  354. return;
  355. }
  356. state.uniforms.push(this.associatedVariableName);
  357. if (define) {
  358. state._uniformDeclaration += this._emitDefine(define);
  359. }
  360. state._uniformDeclaration += `uniform ${state._getGLType(this.type)} ${this.associatedVariableName};\r\n`;
  361. if (define) {
  362. state._uniformDeclaration += `#endif\r\n`;
  363. }
  364. // well known
  365. let hints = state.sharedData.hints;
  366. if (this._systemValue !== null && this._systemValue !== undefined) {
  367. switch (this._systemValue) {
  368. case NodeMaterialSystemValues.WorldView:
  369. hints.needWorldViewMatrix = true;
  370. break;
  371. case NodeMaterialSystemValues.WorldViewProjection:
  372. hints.needWorldViewProjectionMatrix = true;
  373. break;
  374. }
  375. } else {
  376. if (this._animationType !== AnimatedInputBlockTypes.None) {
  377. state.sharedData.animatedInputs.push(this);
  378. }
  379. }
  380. return;
  381. }
  382. // Attribute
  383. if (this.isAttribute) {
  384. this.associatedVariableName = this.name;
  385. if (this.target === NodeMaterialBlockTargets.Vertex && state._vertexState) { // Attribute for fragment need to be carried over by varyings
  386. this._emit(state._vertexState, define);
  387. return;
  388. }
  389. if (state.attributes.indexOf(this.associatedVariableName) !== -1) {
  390. return;
  391. }
  392. state.attributes.push(this.associatedVariableName);
  393. if (define) {
  394. state._attributeDeclaration += this._emitDefine(define);
  395. }
  396. state._attributeDeclaration += `attribute ${state._getGLType(this.type)} ${this.associatedVariableName};\r\n`;
  397. if (define) {
  398. state._attributeDeclaration += `#endif\r\n`;
  399. }
  400. }
  401. }
  402. /** @hidden */
  403. public _transmitWorld(effect: Effect, world: Matrix, worldView: Matrix, worldViewProjection: Matrix) {
  404. if (!this._systemValue) {
  405. return;
  406. }
  407. let variableName = this.associatedVariableName;
  408. switch (this._systemValue) {
  409. case NodeMaterialSystemValues.World:
  410. effect.setMatrix(variableName, world);
  411. break;
  412. case NodeMaterialSystemValues.WorldView:
  413. effect.setMatrix(variableName, worldView);
  414. break;
  415. case NodeMaterialSystemValues.WorldViewProjection:
  416. effect.setMatrix(variableName, worldViewProjection);
  417. break;
  418. }
  419. }
  420. /** @hidden */
  421. public _transmit(effect: Effect, scene: Scene) {
  422. if (this.isAttribute) {
  423. return;
  424. }
  425. let variableName = this.associatedVariableName;
  426. if (this._systemValue) {
  427. switch (this._systemValue) {
  428. case NodeMaterialSystemValues.World:
  429. case NodeMaterialSystemValues.WorldView:
  430. case NodeMaterialSystemValues.WorldViewProjection:
  431. return;
  432. case NodeMaterialSystemValues.View:
  433. effect.setMatrix(variableName, scene.getViewMatrix());
  434. break;
  435. case NodeMaterialSystemValues.Projection:
  436. effect.setMatrix(variableName, scene.getProjectionMatrix());
  437. break;
  438. case NodeMaterialSystemValues.ViewProjection:
  439. effect.setMatrix(variableName, scene.getTransformMatrix());
  440. break;
  441. case NodeMaterialSystemValues.CameraPosition:
  442. effect.setVector3(variableName, scene.activeCamera!.globalPosition);
  443. break;
  444. case NodeMaterialSystemValues.FogColor:
  445. effect.setColor3(variableName, scene.fogColor);
  446. break;
  447. case NodeMaterialSystemValues.DeltaTime:
  448. effect.setFloat(variableName, scene.deltaTime / 1000.0);
  449. }
  450. return;
  451. }
  452. let value = this._valueCallback ? this._valueCallback() : this._storedValue;
  453. if (value === null) {
  454. return;
  455. }
  456. switch (this.type) {
  457. case NodeMaterialBlockConnectionPointTypes.Float:
  458. effect.setFloat(variableName, value);
  459. break;
  460. case NodeMaterialBlockConnectionPointTypes.Int:
  461. effect.setInt(variableName, value);
  462. break;
  463. case NodeMaterialBlockConnectionPointTypes.Color3:
  464. effect.setColor3(variableName, value);
  465. break;
  466. case NodeMaterialBlockConnectionPointTypes.Color4:
  467. effect.setDirectColor4(variableName, value);
  468. break;
  469. case NodeMaterialBlockConnectionPointTypes.Vector2:
  470. effect.setVector2(variableName, value);
  471. break;
  472. case NodeMaterialBlockConnectionPointTypes.Vector3:
  473. effect.setVector3(variableName, value);
  474. break;
  475. case NodeMaterialBlockConnectionPointTypes.Vector4:
  476. effect.setVector4(variableName, value);
  477. break;
  478. case NodeMaterialBlockConnectionPointTypes.Matrix:
  479. effect.setMatrix(variableName, value);
  480. break;
  481. }
  482. }
  483. protected _buildBlock(state: NodeMaterialBuildState) {
  484. super._buildBlock(state);
  485. if (this.isUniform || this.isSystemValue) {
  486. state.sharedData.inputBlocks.push(this);
  487. }
  488. this._emit(state);
  489. }
  490. protected _dumpPropertiesCode() {
  491. let variableName = this._codeVariableName;
  492. if (this.isAttribute) {
  493. return `${variableName}.setAsAttribute("${this.name}");\r\n`;
  494. }
  495. if (this.isSystemValue) {
  496. return `${variableName}.setAsSystemValue(BABYLON.NodeMaterialSystemValues.${NodeMaterialSystemValues[this._systemValue!]});\r\n`;
  497. }
  498. if (this.isUniform) {
  499. let valueString = "";
  500. switch (this.type) {
  501. case NodeMaterialBlockConnectionPointTypes.Float:
  502. let returnValue = `${variableName}.value = ${this.value};\r\n`;
  503. returnValue += `${variableName}.min = ${this.min};\r\n`;
  504. returnValue += `${variableName}.max = ${this.max};\r\n`;
  505. returnValue += `${variableName}.isBoolean = ${this.isBoolean};\r\n`;
  506. returnValue += `${variableName}.matrixMode = ${this.matrixMode};\r\n`;
  507. returnValue += `${variableName}.animationType = BABYLON.AnimatedInputBlockTypes.${AnimatedInputBlockTypes[this.animationType]};\r\n`;
  508. return returnValue;
  509. case NodeMaterialBlockConnectionPointTypes.Vector2:
  510. valueString = `new BABYLON.Vector2(${this.value.x}, ${this.value.y})`;
  511. break;
  512. case NodeMaterialBlockConnectionPointTypes.Vector3:
  513. valueString = `new BABYLON.Vector3(${this.value.x}, ${this.value.y}, ${this.value.z})`;
  514. break;
  515. case NodeMaterialBlockConnectionPointTypes.Vector4:
  516. valueString = `new BABYLON.Vector4(${this.value.x}, ${this.value.y}, ${this.value.z}, ${this.value.w})`;
  517. break;
  518. case NodeMaterialBlockConnectionPointTypes.Color3:
  519. valueString = `new BABYLON.Color3(${this.value.r}, ${this.value.g}, ${this.value.b})`;
  520. break;
  521. case NodeMaterialBlockConnectionPointTypes.Color4:
  522. valueString = `new BABYLON.Color4(${this.value.r}, ${this.value.g}, ${this.value.b}, ${this.value.a})`;
  523. break;
  524. case NodeMaterialBlockConnectionPointTypes.Matrix:
  525. valueString = `BABYLON.Matrix.FromArray([${(this.value as Matrix).m.toString()}])`;
  526. break;
  527. }
  528. let finalOutput = `${variableName}.value = ${valueString};\r\n`;
  529. finalOutput += `${variableName}.isConstant = ${this.isConstant ? "true" : "false"};\r\n`;
  530. finalOutput += `${variableName}.visibleInInspector = ${this.visibleInInspector ? "true" : "false"};\r\n`;
  531. return finalOutput;
  532. }
  533. return "";
  534. }
  535. public serialize(): any {
  536. let serializationObject = super.serialize();
  537. serializationObject.type = this.type;
  538. serializationObject.mode = this._mode;
  539. serializationObject.systemValue = this._systemValue;
  540. serializationObject.animationType = this._animationType;
  541. serializationObject.visibleInInspector = this.visibleInInspector;
  542. serializationObject.min = this.min;
  543. serializationObject.max = this.max;
  544. serializationObject.isBoolean = this.isBoolean;
  545. serializationObject.matrixMode = this.matrixMode;
  546. serializationObject.isConstant = this.isConstant;
  547. serializationObject.groupInInspector = this.groupInInspector;
  548. if (this._storedValue != null && this._mode === NodeMaterialBlockConnectionPointMode.Uniform) {
  549. if (this._storedValue.asArray) {
  550. serializationObject.valueType = "BABYLON." + this._storedValue.getClassName();
  551. serializationObject.value = this._storedValue.asArray();
  552. } else {
  553. serializationObject.valueType = "number";
  554. serializationObject.value = this._storedValue;
  555. }
  556. }
  557. return serializationObject;
  558. }
  559. public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {
  560. super._deserialize(serializationObject, scene, rootUrl);
  561. this._type = serializationObject.type;
  562. this._mode = serializationObject.mode;
  563. this._systemValue = serializationObject.systemValue || serializationObject.wellKnownValue;
  564. this._animationType = serializationObject.animationType;
  565. this.visibleInInspector = serializationObject.visibleInInspector;
  566. this.min = serializationObject.min || 0;
  567. this.max = serializationObject.max || 0;
  568. this.isBoolean = !!serializationObject.isBoolean;
  569. this.matrixMode = serializationObject.matrixMode || 0;
  570. this.isConstant = !!serializationObject.isConstant;
  571. this.groupInInspector = serializationObject.groupInInspector || "";
  572. if (!serializationObject.valueType) {
  573. return;
  574. }
  575. if (serializationObject.valueType === "number") {
  576. this._storedValue = serializationObject.value;
  577. } else {
  578. let valueType = _TypeStore.GetClass(serializationObject.valueType);
  579. if (valueType) {
  580. this._storedValue = valueType.FromArray(serializationObject.value);
  581. }
  582. }
  583. }
  584. }
  585. _TypeStore.RegisteredTypes["BABYLON.InputBlock"] = InputBlock;