inputNodePropertyComponent.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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/nodeMaterialBlockConnectionPointTypes';
  7. import { OptionsLineComponent } from '../../../sharedComponents/optionsLineComponent';
  8. import { NodeMaterialSystemValues } from 'babylonjs/Materials/Node/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 { CheckBoxLineComponent } from '../../../sharedComponents/checkBoxLineComponent';
  17. interface IInputPropertyTabComponentProps {
  18. globalState: GlobalState;
  19. inputNode: InputNodeModel;
  20. }
  21. export class InputPropertyTabComponentProps extends React.Component<IInputPropertyTabComponentProps> {
  22. constructor(props: IInputPropertyTabComponentProps) {
  23. super(props)
  24. }
  25. renderValue(globalState: GlobalState) {
  26. let inputBlock = this.props.inputNode.inputBlock;
  27. switch (inputBlock.type) {
  28. case NodeMaterialBlockConnectionPointTypes.Float:
  29. return (
  30. <FloatPropertyTabComponent globalState={globalState} inputBlock={inputBlock} />
  31. );
  32. case NodeMaterialBlockConnectionPointTypes.Vector2:
  33. return (
  34. <Vector2PropertyTabComponent globalState={globalState} inputBlock={inputBlock} />
  35. );
  36. case NodeMaterialBlockConnectionPointTypes.Color3:
  37. case NodeMaterialBlockConnectionPointTypes.Color4:
  38. return (
  39. <Color3PropertyTabComponent globalState={globalState} inputBlock={inputBlock} />
  40. );
  41. case NodeMaterialBlockConnectionPointTypes.Vector3:
  42. return (
  43. <Vector3PropertyTabComponent globalState={globalState} inputBlock={inputBlock} />
  44. );
  45. }
  46. return null;
  47. }
  48. setDefaultValue() {
  49. let inputBlock = this.props.inputNode.inputBlock;
  50. inputBlock.setDefaultValue();
  51. }
  52. render() {
  53. let inputBlock = this.props.inputNode.inputBlock;
  54. var systemValuesOptions: {label: string, value: NodeMaterialSystemValues}[] = [];
  55. var attributeOptions: {label: string, value: string}[] = [];
  56. var animationOptions: {label: string, value: AnimatedInputBlockTypes}[] = [];
  57. switch(inputBlock.type) {
  58. case NodeMaterialBlockConnectionPointTypes.Float:
  59. animationOptions = [
  60. { label: "None", value: AnimatedInputBlockTypes.None },
  61. { label: "Time", value: AnimatedInputBlockTypes.Time },
  62. ];
  63. break;
  64. case NodeMaterialBlockConnectionPointTypes.Matrix:
  65. systemValuesOptions = [
  66. { label: "World", value: NodeMaterialSystemValues.World },
  67. { label: "World x View", value: NodeMaterialSystemValues.WorldView },
  68. { label: "World x ViewxProjection", value: NodeMaterialSystemValues.WorldViewProjection },
  69. { label: "View", value: NodeMaterialSystemValues.View },
  70. { label: "View x Projection", value: NodeMaterialSystemValues.ViewProjection },
  71. { label: "Projection", value: NodeMaterialSystemValues.Projection }
  72. ];
  73. break;
  74. case NodeMaterialBlockConnectionPointTypes.Color3:
  75. systemValuesOptions = [
  76. { label: "Fog color", value: NodeMaterialSystemValues.FogColor }
  77. ];
  78. break;
  79. case NodeMaterialBlockConnectionPointTypes.Color4:
  80. attributeOptions = [
  81. { label: "color", value: "color" }
  82. ];
  83. break;
  84. case NodeMaterialBlockConnectionPointTypes.Vector2:
  85. attributeOptions = [
  86. { label: "uv", value: "uv" },
  87. { label: "uv2", value: "uv2" },
  88. ];
  89. break;
  90. case NodeMaterialBlockConnectionPointTypes.Vector3:
  91. systemValuesOptions = [
  92. { label: "Camera position", value: NodeMaterialSystemValues.CameraPosition }
  93. ];
  94. attributeOptions = [
  95. { label: "position", value: "position" },
  96. { label: "normal", value: "normal" },
  97. { label: "tangent", value: "tangent" },
  98. ];
  99. break;
  100. case NodeMaterialBlockConnectionPointTypes.Vector4:
  101. attributeOptions = [
  102. { label: "matricesIndices", value: "matricesIndices" },
  103. { label: "matricesWeights", value: "matricesWeights" }
  104. ];
  105. break;
  106. }
  107. var modeOptions = [
  108. { label: "User-defined", value: 0 }
  109. ];
  110. if (attributeOptions.length > 0) {
  111. modeOptions.push({ label: "Mesh attribute", value: 1 });
  112. }
  113. if (systemValuesOptions.length > 0) {
  114. modeOptions.push({ label: "System value", value: 2 });
  115. }
  116. return (
  117. <div>
  118. <LineContainerComponent title="GENERAL">
  119. {
  120. !inputBlock.isAttribute &&
  121. <TextInputLineComponent globalState={this.props.globalState} label="Name" propertyName="name" target={inputBlock} onChange={() => this.props.globalState.onUpdateRequiredObservable.notifyObservers()} />
  122. }
  123. <TextLineComponent label="Type" value={StringTools.GetBaseType(inputBlock.type)} />
  124. </LineContainerComponent>
  125. <LineContainerComponent title="PROPERTIES">
  126. {
  127. inputBlock.isUniform && !inputBlock.isSystemValue && inputBlock.animationType === AnimatedInputBlockTypes.None &&
  128. <CheckBoxLineComponent label="Visible in the Inspector" target={inputBlock} propertyName="visibleInInspector"/>
  129. }
  130. <OptionsLineComponent label="Mode" options={modeOptions} target={inputBlock}
  131. noDirectUpdate={true}
  132. getSelection={(block) => {
  133. if (block.isAttribute) {
  134. return 1;
  135. }
  136. if (block.isSystemValue) {
  137. return 2;
  138. }
  139. return 0;
  140. }}
  141. onSelect={(value: any) => {
  142. switch (value) {
  143. case 0:
  144. inputBlock.isUniform = true;
  145. inputBlock.setAsSystemValue(null);
  146. this.setDefaultValue();
  147. break;
  148. case 1:
  149. inputBlock.setAsAttribute(attributeOptions[0].value);
  150. break;
  151. case 2:
  152. inputBlock.setAsSystemValue(systemValuesOptions[0].value);
  153. break;
  154. }
  155. this.forceUpdate();
  156. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  157. }} />
  158. {
  159. inputBlock.isAttribute &&
  160. <OptionsLineComponent label="Attribute" valuesAreStrings={true} options={attributeOptions} target={inputBlock} propertyName="name" onSelect={(value: any) => {
  161. inputBlock.setAsAttribute(value);
  162. this.forceUpdate();
  163. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  164. }} />
  165. }
  166. {
  167. inputBlock.isUniform && animationOptions.length > 0 &&
  168. <OptionsLineComponent label="Animation type" options={animationOptions} target={inputBlock} propertyName="animationType" onSelect={(value: any) => {
  169. this.forceUpdate();
  170. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  171. }} />
  172. }
  173. {
  174. inputBlock.isUniform && !inputBlock.isSystemValue && inputBlock.animationType === AnimatedInputBlockTypes.None &&
  175. this.renderValue(this.props.globalState)
  176. }
  177. {
  178. inputBlock.isUniform && inputBlock.isSystemValue &&
  179. <OptionsLineComponent label="System value" options={systemValuesOptions} target={inputBlock} propertyName="systemValue" onSelect={(value: any) => {
  180. inputBlock.setAsSystemValue(value);
  181. this.forceUpdate();
  182. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  183. }} />
  184. }
  185. </LineContainerComponent>
  186. </div>
  187. );
  188. }
  189. }