inputNodePropertyComponent.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import * as React from "react";
  2. import { Vector2PropertyTabComponent } from '../../propertyTab/properties/vector2PropertyTabComponent';
  3. import { Vector3PropertyTabComponent } from '../../propertyTab/properties/vector3PropertyTabComponent';
  4. import { GlobalState } from '../../../globalState';
  5. import { InputNodeModel } from './inputNodeModel';
  6. import { NodeMaterialBlockConnectionPointTypes } from 'babylonjs/Materials/Node/Enums/nodeMaterialBlockConnectionPointTypes';
  7. import { OptionsLineComponent } from '../../../sharedComponents/optionsLineComponent';
  8. import { NodeMaterialSystemValues } from 'babylonjs/Materials/Node/Enums/nodeMaterialSystemValues';
  9. import { TextLineComponent } from '../../../sharedComponents/textLineComponent';
  10. import { Color3PropertyTabComponent } from '../../propertyTab/properties/color3PropertyTabComponent';
  11. import { FloatPropertyTabComponent } from '../../propertyTab/properties/floatPropertyTabComponent';
  12. import { LineContainerComponent } from '../../../sharedComponents/lineContainerComponent';
  13. import { StringTools } from '../../../stringTools';
  14. import { AnimatedInputBlockTypes } from 'babylonjs/Materials/Node/Blocks/Input/animatedInputBlockTypes';
  15. import { TextInputLineComponent } from '../../../sharedComponents/textInputLineComponent';
  16. import { Vector4PropertyTabComponent } from '../../propertyTab/properties/vector4PropertyTabComponent';
  17. import { MatrixPropertyTabComponent } from '../../propertyTab/properties/matrixPropertyTabComponent';
  18. import { FloatLineComponent } from '../../../sharedComponents/floatLineComponent';
  19. import { SliderLineComponent } from '../../../sharedComponents/sliderLineComponent';
  20. interface IInputPropertyTabComponentProps {
  21. globalState: GlobalState;
  22. inputNode: InputNodeModel;
  23. }
  24. export class InputPropertyTabComponentProps extends React.Component<IInputPropertyTabComponentProps> {
  25. constructor(props: IInputPropertyTabComponentProps) {
  26. super(props)
  27. }
  28. renderValue(globalState: GlobalState) {
  29. let inputBlock = this.props.inputNode.inputBlock;
  30. switch (inputBlock.type) {
  31. case NodeMaterialBlockConnectionPointTypes.Float: {
  32. let cantDisplaySlider = (isNaN(inputBlock.min) || isNaN(inputBlock.max) || inputBlock.min === inputBlock.max);
  33. return (
  34. <>
  35. <FloatLineComponent label="Min" target={inputBlock} propertyName="min" onChange={() => {
  36. this.forceUpdate();
  37. }}></FloatLineComponent>
  38. <FloatLineComponent label="Max" target={inputBlock} propertyName="max" onChange={() => {
  39. this.forceUpdate();
  40. }}></FloatLineComponent>
  41. {
  42. cantDisplaySlider &&
  43. <FloatPropertyTabComponent globalState={globalState} inputBlock={inputBlock} />
  44. }
  45. {
  46. !cantDisplaySlider &&
  47. <SliderLineComponent label="Value" target={inputBlock} propertyName="value" step={(inputBlock.max - inputBlock.min) / 100.0} minimum={inputBlock.min} maximum={inputBlock.max} onChange={() => {
  48. this.props.globalState.onUpdateRequiredObservable.notifyObservers();
  49. }}/>
  50. }
  51. </>
  52. );
  53. }
  54. case NodeMaterialBlockConnectionPointTypes.Vector2:
  55. return (
  56. <Vector2PropertyTabComponent globalState={globalState} inputBlock={inputBlock} />
  57. );
  58. case NodeMaterialBlockConnectionPointTypes.Color3:
  59. case NodeMaterialBlockConnectionPointTypes.Color4:
  60. return (
  61. <Color3PropertyTabComponent globalState={globalState} inputBlock={inputBlock} />
  62. );
  63. case NodeMaterialBlockConnectionPointTypes.Vector3:
  64. return (
  65. <Vector3PropertyTabComponent globalState={globalState} inputBlock={inputBlock} />
  66. );
  67. case NodeMaterialBlockConnectionPointTypes.Vector4:
  68. return (
  69. <Vector4PropertyTabComponent globalState={globalState} inputBlock={inputBlock} />
  70. );
  71. case NodeMaterialBlockConnectionPointTypes.Matrix:
  72. return (
  73. <MatrixPropertyTabComponent globalState={globalState} inputBlock={inputBlock} />
  74. );
  75. }
  76. return null;
  77. }
  78. setDefaultValue() {
  79. let inputBlock = this.props.inputNode.inputBlock;
  80. inputBlock.setDefaultValue();
  81. }
  82. render() {
  83. let inputBlock = this.props.inputNode.inputBlock;
  84. var systemValuesOptions: {label: string, value: NodeMaterialSystemValues}[] = [];
  85. var attributeOptions: {label: string, value: string}[] = [];
  86. var animationOptions: {label: string, value: AnimatedInputBlockTypes}[] = [];
  87. switch(inputBlock.type) {
  88. case NodeMaterialBlockConnectionPointTypes.Float:
  89. animationOptions = [
  90. { label: "None", value: AnimatedInputBlockTypes.None },
  91. { label: "Time", value: AnimatedInputBlockTypes.Time },
  92. ];
  93. systemValuesOptions = [
  94. { label: "Delta time", value: NodeMaterialSystemValues.DeltaTime }
  95. ]
  96. break;
  97. case NodeMaterialBlockConnectionPointTypes.Matrix:
  98. systemValuesOptions = [
  99. { label: "World", value: NodeMaterialSystemValues.World },
  100. { label: "World x View", value: NodeMaterialSystemValues.WorldView },
  101. { label: "World x ViewxProjection", value: NodeMaterialSystemValues.WorldViewProjection },
  102. { label: "View", value: NodeMaterialSystemValues.View },
  103. { label: "View x Projection", value: NodeMaterialSystemValues.ViewProjection },
  104. { label: "Projection", value: NodeMaterialSystemValues.Projection }
  105. ];
  106. break;
  107. case NodeMaterialBlockConnectionPointTypes.Color3:
  108. systemValuesOptions = [
  109. { label: "Fog color", value: NodeMaterialSystemValues.FogColor }
  110. ];
  111. break;
  112. case NodeMaterialBlockConnectionPointTypes.Color4:
  113. attributeOptions = [
  114. { label: "color", value: "color" }
  115. ];
  116. break;
  117. case NodeMaterialBlockConnectionPointTypes.Vector2:
  118. attributeOptions = [
  119. { label: "uv", value: "uv" },
  120. { label: "uv2", value: "uv2" },
  121. ];
  122. break;
  123. case NodeMaterialBlockConnectionPointTypes.Vector3:
  124. systemValuesOptions = [
  125. { label: "Camera position", value: NodeMaterialSystemValues.CameraPosition }
  126. ];
  127. attributeOptions = [
  128. { label: "position", value: "position" },
  129. { label: "normal", value: "normal" },
  130. { label: "tangent", value: "tangent" },
  131. ];
  132. break;
  133. case NodeMaterialBlockConnectionPointTypes.Vector4:
  134. attributeOptions = [
  135. { label: "matricesIndices", value: "matricesIndices" },
  136. { label: "matricesWeights", value: "matricesWeights" }
  137. ];
  138. break;
  139. }
  140. var modeOptions = [
  141. { label: "User-defined", value: 0 }
  142. ];
  143. if (attributeOptions.length > 0) {
  144. modeOptions.push({ label: "Mesh attribute", value: 1 });
  145. }
  146. if (systemValuesOptions.length > 0) {
  147. modeOptions.push({ label: "System value", value: 2 });
  148. }
  149. var typeOptions = [
  150. { label: "None", value: 0 },
  151. { label: "Visible in the inspector", value: 1 },
  152. { label: "Constant", value: 2 }
  153. ];
  154. return (
  155. <div>
  156. <LineContainerComponent title="GENERAL">
  157. {
  158. !inputBlock.isAttribute &&
  159. <TextInputLineComponent globalState={this.props.globalState} label="Name" propertyName="name" target={inputBlock} onChange={() => this.props.globalState.onUpdateRequiredObservable.notifyObservers()} />
  160. }
  161. <TextLineComponent label="Type" value={StringTools.GetBaseType(inputBlock.type)} />
  162. </LineContainerComponent>
  163. <LineContainerComponent title="PROPERTIES">
  164. {
  165. inputBlock.isUniform && !inputBlock.isSystemValue && inputBlock.animationType === AnimatedInputBlockTypes.None &&
  166. <OptionsLineComponent label="Type" options={typeOptions} target={inputBlock}
  167. noDirectUpdate={true}
  168. getSelection={(block) => {
  169. if (block.visibleInInspector) {
  170. return 1;
  171. }
  172. if (block.isConstant) {
  173. return 2;
  174. }
  175. return 0;
  176. }}
  177. onSelect={(value: any) => {
  178. switch (value) {
  179. case 0:
  180. inputBlock.visibleInInspector = false;
  181. inputBlock.isConstant = false;
  182. break;
  183. case 1:
  184. inputBlock.visibleInInspector = true;
  185. inputBlock.isConstant = false;
  186. break;
  187. case 2:
  188. inputBlock.visibleInInspector = false;
  189. inputBlock.isConstant = true;
  190. break;
  191. }
  192. this.forceUpdate();
  193. this.props.globalState.onUpdateRequiredObservable.notifyObservers();
  194. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  195. }} />
  196. }
  197. <OptionsLineComponent label="Mode" options={modeOptions} target={inputBlock}
  198. noDirectUpdate={true}
  199. getSelection={(block) => {
  200. if (block.isAttribute) {
  201. return 1;
  202. }
  203. if (block.isSystemValue) {
  204. return 2;
  205. }
  206. return 0;
  207. }}
  208. onSelect={(value: any) => {
  209. switch (value) {
  210. case 0:
  211. inputBlock.isUniform = true;
  212. inputBlock.setAsSystemValue(null);
  213. this.setDefaultValue();
  214. break;
  215. case 1:
  216. inputBlock.setAsAttribute(attributeOptions[0].value);
  217. break;
  218. case 2:
  219. inputBlock.setAsSystemValue(systemValuesOptions[0].value);
  220. break;
  221. }
  222. this.forceUpdate();
  223. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  224. }} />
  225. {
  226. inputBlock.isAttribute &&
  227. <OptionsLineComponent label="Attribute" valuesAreStrings={true} options={attributeOptions} target={inputBlock} propertyName="name" onSelect={(value: any) => {
  228. inputBlock.setAsAttribute(value);
  229. this.forceUpdate();
  230. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  231. }} />
  232. }
  233. {
  234. inputBlock.isUniform && animationOptions.length > 0 &&
  235. <OptionsLineComponent label="Animation type" options={animationOptions} target={inputBlock} propertyName="animationType" onSelect={(value: any) => {
  236. this.forceUpdate();
  237. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  238. }} />
  239. }
  240. {
  241. inputBlock.isUniform && !inputBlock.isSystemValue && inputBlock.animationType === AnimatedInputBlockTypes.None &&
  242. this.renderValue(this.props.globalState)
  243. }
  244. {
  245. inputBlock.isUniform && inputBlock.isSystemValue &&
  246. <OptionsLineComponent label="System value" options={systemValuesOptions} target={inputBlock} propertyName="systemValue" onSelect={(value: any) => {
  247. inputBlock.setAsSystemValue(value);
  248. this.forceUpdate();
  249. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  250. }} />
  251. }
  252. </LineContainerComponent>
  253. </div>
  254. );
  255. }
  256. }