inputNodePropertyComponent.tsx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import * as React from "react";
  2. import { Vector2PropertyTabComponent } from '../../propertyTab/properties/vector2PropertyTabComponent';
  3. import { Vector3PropertyTabComponent } from '../../propertyTab/properties/vector3PropertyTabComponent';
  4. import { CheckBoxLineComponent } from '../../../sharedComponents/checkBoxLineComponent';
  5. import { GlobalState } from '../../../globalState';
  6. import { InputNodeModel } from './inputNodeModel';
  7. import { NodeMaterialBlockConnectionPointTypes } from 'babylonjs/Materials/Node/nodeMaterialBlockConnectionPointTypes';
  8. import { OptionsLineComponent } from '../../../sharedComponents/optionsLineComponent';
  9. import { NodeMaterialWellKnownValues } from 'babylonjs/Materials/Node/nodeMaterialWellKnownValues';
  10. import { TextLineComponent } from '../../../sharedComponents/textLineComponent';
  11. import { Color3PropertyTabComponent } from '../../propertyTab/properties/color3PropertyTabComponent';
  12. import { FloatPropertyTabComponent } from '../../propertyTab/properties/floatPropertyTabComponent';
  13. import { LineContainerComponent } from '../../../sharedComponents/lineContainerComponent';
  14. import { StringTools } from '../../../stringTools';
  15. import { AnimatedInputBlockTypes } from 'babylonjs/Materials/Node/Blocks/Input/animatedInputBlockTypes';
  16. import { TextInputLineComponent } from '../../../sharedComponents/textInputLineComponent';
  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 wellKnownOptions: {label: string, value: NodeMaterialWellKnownValues}[] = [];
  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. wellKnownOptions = [
  66. { label: "World", value: NodeMaterialWellKnownValues.World },
  67. { label: "WorldxView", value: NodeMaterialWellKnownValues.WorldView },
  68. { label: "WorldxViewxProjection", value: NodeMaterialWellKnownValues.WorldViewProjection },
  69. { label: "View", value: NodeMaterialWellKnownValues.View },
  70. { label: "ViewxProjection", value: NodeMaterialWellKnownValues.ViewProjection },
  71. { label: "Projection", value: NodeMaterialWellKnownValues.Projection }
  72. ];
  73. break;
  74. case NodeMaterialBlockConnectionPointTypes.Color3:
  75. wellKnownOptions = [
  76. { label: "Fog color", value: NodeMaterialWellKnownValues.FogColor }
  77. ];
  78. break;
  79. case NodeMaterialBlockConnectionPointTypes.Color3:
  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. wellKnownOptions = [
  92. { label: "Camera position", value: NodeMaterialWellKnownValues.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. return (
  108. <div>
  109. <LineContainerComponent title="GENERAL">
  110. <TextInputLineComponent label="Name" propertyName="name" target={inputBlock} onChange={() => this.props.globalState.onUpdateRequiredObservable.notifyObservers()} />
  111. <TextLineComponent label="Type" value={StringTools.GetBaseType(inputBlock.type)} />
  112. </LineContainerComponent>
  113. <LineContainerComponent title="PROPERTIES">
  114. {
  115. attributeOptions.length > 0 &&
  116. <CheckBoxLineComponent label="Is mesh attribute" onSelect={value => {
  117. if (!value) {
  118. inputBlock.isUniform = true;
  119. this.setDefaultValue();
  120. } else {
  121. inputBlock.setAsAttribute(attributeOptions[0].value);
  122. }
  123. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  124. this.forceUpdate();
  125. }} isSelected={() => inputBlock.isAttribute} />
  126. }
  127. {
  128. inputBlock.isAttribute &&
  129. <OptionsLineComponent label="Attribute" valuesAreStrings={true} options={attributeOptions} target={inputBlock} propertyName="name" onSelect={(value: any) => {
  130. inputBlock.setAsAttribute(value);
  131. this.forceUpdate();
  132. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  133. }} />
  134. }
  135. {
  136. inputBlock.isUniform && wellKnownOptions.length > 0 &&
  137. <CheckBoxLineComponent label="Is well known value" onSelect={value => {
  138. if (value) {
  139. inputBlock.setAsWellKnownValue(wellKnownOptions[0].value);
  140. } else {
  141. inputBlock.setAsWellKnownValue(null);
  142. this.setDefaultValue();
  143. }
  144. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  145. this.forceUpdate();
  146. }} isSelected={() => inputBlock.isWellKnownValue} />
  147. }
  148. {
  149. inputBlock.isUniform && animationOptions.length > 0 &&
  150. <OptionsLineComponent label="Animation type" options={animationOptions} target={inputBlock} propertyName="animationType" onSelect={(value: any) => {
  151. this.forceUpdate();
  152. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  153. }} />
  154. }
  155. {
  156. inputBlock.isUniform && !inputBlock.isWellKnownValue && inputBlock.animationType === AnimatedInputBlockTypes.None &&
  157. this.renderValue(this.props.globalState)
  158. }
  159. {
  160. inputBlock.isUniform && inputBlock.isWellKnownValue &&
  161. <OptionsLineComponent label="Well known value" options={wellKnownOptions} target={inputBlock} propertyName="wellKnownValue" onSelect={(value: any) => {
  162. inputBlock.setAsWellKnownValue(value);
  163. this.forceUpdate();
  164. this.props.globalState.onRebuildRequiredObservable.notifyObservers();
  165. }} />
  166. }
  167. </LineContainerComponent>
  168. </div>
  169. );
  170. }
  171. }