inputBlock.ts 25 KB

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