blockTools.ts 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. import { DiscardBlock } from 'babylonjs/Materials/Node/Blocks/Fragment/discardBlock';
  2. import { BonesBlock } from 'babylonjs/Materials/Node/Blocks/Vertex/bonesBlock';
  3. import { InstancesBlock } from 'babylonjs/Materials/Node/Blocks/Vertex/instancesBlock';
  4. import { MorphTargetsBlock } from 'babylonjs/Materials/Node/Blocks/Vertex/morphTargetsBlock';
  5. import { ImageProcessingBlock } from 'babylonjs/Materials/Node/Blocks/Fragment/imageProcessingBlock';
  6. import { ColorMergerBlock } from 'babylonjs/Materials/Node/Blocks/colorMergerBlock';
  7. import { VectorMergerBlock } from 'babylonjs/Materials/Node/Blocks/vectorMergerBlock';
  8. import { ColorSplitterBlock } from 'babylonjs/Materials/Node/Blocks/colorSplitterBlock';
  9. import { VectorSplitterBlock } from 'babylonjs/Materials/Node/Blocks/vectorSplitterBlock';
  10. import { RemapBlock } from 'babylonjs/Materials/Node/Blocks/remapBlock';
  11. import { TextureBlock } from 'babylonjs/Materials/Node/Blocks/Dual/textureBlock';
  12. import { ReflectionTextureBlock } from 'babylonjs/Materials/Node/Blocks/Dual/reflectionTextureBlock';
  13. import { LightBlock } from 'babylonjs/Materials/Node/Blocks/Dual/lightBlock';
  14. import { FogBlock } from 'babylonjs/Materials/Node/Blocks/Dual/fogBlock';
  15. import { VertexOutputBlock } from 'babylonjs/Materials/Node/Blocks/Vertex/vertexOutputBlock';
  16. import { FragmentOutputBlock } from 'babylonjs/Materials/Node/Blocks/Fragment/fragmentOutputBlock';
  17. import { NormalizeBlock } from 'babylonjs/Materials/Node/Blocks/normalizeBlock';
  18. import { AddBlock } from 'babylonjs/Materials/Node/Blocks/addBlock';
  19. import { ModBlock } from 'babylonjs/Materials/Node/Blocks/modBlock';
  20. import { ScaleBlock } from 'babylonjs/Materials/Node/Blocks/scaleBlock';
  21. import { TrigonometryBlock, TrigonometryBlockOperations } from 'babylonjs/Materials/Node/Blocks/trigonometryBlock';
  22. import { ClampBlock } from 'babylonjs/Materials/Node/Blocks/clampBlock';
  23. import { CrossBlock } from 'babylonjs/Materials/Node/Blocks/crossBlock';
  24. import { DotBlock } from 'babylonjs/Materials/Node/Blocks/dotBlock';
  25. import { MultiplyBlock } from 'babylonjs/Materials/Node/Blocks/multiplyBlock';
  26. import { TransformBlock } from 'babylonjs/Materials/Node/Blocks/transformBlock';
  27. import { NodeMaterialBlockConnectionPointTypes } from 'babylonjs/Materials/Node/Enums/nodeMaterialBlockConnectionPointTypes';
  28. import { FresnelBlock } from 'babylonjs/Materials/Node/Blocks/fresnelBlock';
  29. import { LerpBlock } from 'babylonjs/Materials/Node/Blocks/lerpBlock';
  30. import { NLerpBlock } from 'babylonjs/Materials/Node/Blocks/nLerpBlock';
  31. import { DivideBlock } from 'babylonjs/Materials/Node/Blocks/divideBlock';
  32. import { SubtractBlock } from 'babylonjs/Materials/Node/Blocks/subtractBlock';
  33. import { StepBlock } from 'babylonjs/Materials/Node/Blocks/stepBlock';
  34. import { SmoothStepBlock } from 'babylonjs/Materials/Node/Blocks/smoothStepBlock';
  35. import { InputBlock } from 'babylonjs/Materials/Node/Blocks/Input/inputBlock';
  36. import { NodeMaterialSystemValues } from 'babylonjs/Materials/Node/Enums/nodeMaterialSystemValues';
  37. import { AnimatedInputBlockTypes } from 'babylonjs/Materials/Node/Blocks/Input/animatedInputBlockTypes';
  38. import { OneMinusBlock } from 'babylonjs/Materials/Node/Blocks/oneMinusBlock';
  39. import { ViewDirectionBlock } from 'babylonjs/Materials/Node/Blocks/viewDirectionBlock';
  40. import { LightInformationBlock } from 'babylonjs/Materials/Node/Blocks/Vertex/lightInformationBlock';
  41. import { MaxBlock } from 'babylonjs/Materials/Node/Blocks/maxBlock';
  42. import { MinBlock } from 'babylonjs/Materials/Node/Blocks/minBlock';
  43. import { PerturbNormalBlock } from 'babylonjs/Materials/Node/Blocks/Fragment/perturbNormalBlock';
  44. import { LengthBlock } from 'babylonjs/Materials/Node/Blocks/lengthBlock';
  45. import { DistanceBlock } from 'babylonjs/Materials/Node/Blocks/distanceBlock';
  46. import { FrontFacingBlock } from 'babylonjs/Materials/Node/Blocks/Fragment/frontFacingBlock';
  47. import { NegateBlock } from 'babylonjs/Materials/Node/Blocks/negateBlock';
  48. import { PowBlock } from 'babylonjs/Materials/Node/Blocks/powBlock';
  49. import { Scene } from 'babylonjs/scene';
  50. import { RandomNumberBlock } from 'babylonjs/Materials/Node/Blocks/randomNumberBlock';
  51. import { ReplaceColorBlock } from 'babylonjs/Materials/Node/Blocks/replaceColorBlock';
  52. import { PosterizeBlock } from 'babylonjs/Materials/Node/Blocks/posterizeBlock';
  53. import { ArcTan2Block } from 'babylonjs/Materials/Node/Blocks/arcTan2Block';
  54. import { ReciprocalBlock } from 'babylonjs/Materials/Node/Blocks/reciprocalBlock';
  55. import { GradientBlock } from 'babylonjs/Materials/Node/Blocks/gradientBlock';
  56. import { WaveBlock, WaveBlockKind } from 'babylonjs/Materials/Node/Blocks/waveBlock';
  57. import { NodeMaterial } from 'babylonjs/Materials/Node/nodeMaterial';
  58. import { WorleyNoise3DBlock } from 'babylonjs/Materials/Node/Blocks/worleyNoise3DBlock';
  59. import { SimplexPerlin3DBlock } from 'babylonjs/Materials/Node/Blocks/simplexPerlin3DBlock';
  60. import { NormalBlendBlock } from 'babylonjs/Materials/Node/Blocks/normalBlendBlock';
  61. import { Rotate2dBlock } from 'babylonjs/Materials/Node/Blocks/rotate2dBlock';
  62. import { DerivativeBlock } from 'babylonjs/Materials/Node/Blocks/Fragment/derivativeBlock';
  63. import { RefractBlock } from 'babylonjs/Materials/Node/Blocks/refractBlock';
  64. import { ReflectBlock } from 'babylonjs/Materials/Node/Blocks/reflectBlock';
  65. import { DesaturateBlock } from 'babylonjs/Materials/Node/Blocks/desaturateBlock';
  66. import { PBRMetallicRoughnessBlock } from 'babylonjs/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock';
  67. import { SheenBlock } from 'babylonjs/Materials/Node/Blocks/PBR/sheenBlock';
  68. import { AmbientOcclusionBlock } from 'babylonjs/Materials/Node/Blocks/PBR/ambientOcclusionBlock';
  69. import { ReflectivityBlock } from 'babylonjs/Materials/Node/Blocks/PBR/reflectivityBlock';
  70. import { AnisotropyBlock } from 'babylonjs/Materials/Node/Blocks/PBR/anisotropyBlock';
  71. import { ReflectionBlock } from 'babylonjs/Materials/Node/Blocks/PBR/reflectionBlock';
  72. import { ClearCoatBlock } from 'babylonjs/Materials/Node/Blocks/PBR/clearCoatBlock';
  73. import { RefractionBlock } from 'babylonjs/Materials/Node/Blocks/PBR/refractionBlock';
  74. import { SubSurfaceBlock } from 'babylonjs/Materials/Node/Blocks/PBR/subSurfaceBlock';
  75. import { CurrentScreenBlock } from 'babylonjs/Materials/Node/Blocks/Dual/currentScreenBlock';
  76. import { ParticleTextureBlock } from 'babylonjs/Materials/Node/Blocks/Particle/particleTextureBlock';
  77. import { ParticleRampGradientBlock } from 'babylonjs/Materials/Node/Blocks/Particle/particleRampGradientBlock';
  78. import { ParticleBlendMultiplyBlock } from 'babylonjs/Materials/Node/Blocks/Particle/particleBlendMultiplyBlock';
  79. import { NodeMaterialModes } from 'babylonjs/Materials/Node/Enums/nodeMaterialModes';
  80. import { FragCoordBlock } from 'babylonjs/Materials/Node/Blocks/Fragment/fragCoordBlock';
  81. import { ScreenSizeBlock } from 'babylonjs/Materials/Node/Blocks/Fragment/screenSizeBlock';
  82. export class BlockTools {
  83. public static GetBlockFromString(data: string, scene: Scene, nodeMaterial: NodeMaterial) {
  84. switch (data) {
  85. case "DesaturateBlock":
  86. return new DesaturateBlock("Desaturate");
  87. case "RefractBlock":
  88. return new RefractBlock("Refract");
  89. case "ReflectBlock":
  90. return new ReflectBlock("Reflect");
  91. case "DerivativeBlock":
  92. return new DerivativeBlock("Derivative");
  93. case "Rotate2dBlock":
  94. return new Rotate2dBlock("Rotate2d");
  95. case "NormalBlendBlock":
  96. return new NormalBlendBlock("NormalBlend");
  97. case "WorleyNoise3DBlock":
  98. return new WorleyNoise3DBlock("WorleyNoise3D");
  99. case "SimplexPerlin3DBlock":
  100. return new SimplexPerlin3DBlock("SimplexPerlin3D");
  101. case "BonesBlock":
  102. return new BonesBlock("Bones");
  103. case "InstancesBlock":
  104. return new InstancesBlock("Instances");
  105. case "MorphTargetsBlock":
  106. return new MorphTargetsBlock("MorphTargets");
  107. case "DiscardBlock":
  108. return new DiscardBlock("Discard");
  109. case "ImageProcessingBlock":
  110. return new ImageProcessingBlock("ImageProcessing");
  111. case "ColorMergerBlock":
  112. return new ColorMergerBlock("ColorMerger");
  113. case "VectorMergerBlock":
  114. return new VectorMergerBlock("VectorMerger");
  115. case "ColorSplitterBlock":
  116. return new ColorSplitterBlock("ColorSplitter");
  117. case "VectorSplitterBlock":
  118. return new VectorSplitterBlock("VectorSplitter");
  119. case "TextureBlock":
  120. return new TextureBlock("Texture", nodeMaterial.mode === NodeMaterialModes.Particle);
  121. case "ReflectionTextureBlock":
  122. return new ReflectionTextureBlock("Reflection texture");
  123. case "LightBlock":
  124. return new LightBlock("Lights");
  125. case "FogBlock":
  126. return new FogBlock("Fog");
  127. case "VertexOutputBlock":
  128. return new VertexOutputBlock("VertexOutput");
  129. case "FragmentOutputBlock":
  130. return new FragmentOutputBlock("FragmentOutput");
  131. case "AddBlock":
  132. return new AddBlock("Add");
  133. case "ClampBlock":
  134. return new ClampBlock("Clamp");
  135. case "ScaleBlock":
  136. return new ScaleBlock("Scale");
  137. case "CrossBlock":
  138. return new CrossBlock("Cross");
  139. case "DotBlock":
  140. return new DotBlock("Dot");
  141. case "PowBlock":
  142. return new PowBlock("Pow");
  143. case "MultiplyBlock":
  144. return new MultiplyBlock("Multiply");
  145. case "TransformBlock":
  146. return new TransformBlock("Transform");
  147. case "TrigonometryBlock":
  148. return new TrigonometryBlock("Trigonometry");
  149. case "RemapBlock":
  150. return new RemapBlock("Remap");
  151. case "NormalizeBlock":
  152. return new NormalizeBlock("Normalize");
  153. case "FresnelBlock":
  154. return new FresnelBlock("Fresnel");
  155. case "LerpBlock":
  156. return new LerpBlock("Lerp");
  157. case "NLerpBlock":
  158. return new NLerpBlock("NLerp");
  159. case "DivideBlock":
  160. return new DivideBlock("Divide");
  161. case "SubtractBlock":
  162. return new SubtractBlock("Subtract");
  163. case "ModBlock":
  164. return new ModBlock("Mod");
  165. case "StepBlock":
  166. return new StepBlock("Step");
  167. case "SmoothStepBlock":
  168. return new SmoothStepBlock("Smooth step");
  169. case "OneMinusBlock":
  170. return new OneMinusBlock("One minus");
  171. case "ReciprocalBlock":
  172. return new ReciprocalBlock("Reciprocal");
  173. case "ViewDirectionBlock":
  174. return new ViewDirectionBlock("View direction");
  175. case "LightInformationBlock":
  176. let lightInformationBlock = new LightInformationBlock("Light information");
  177. lightInformationBlock.light = scene.lights.length ? scene.lights[0] : null;
  178. return lightInformationBlock;
  179. case "MaxBlock":
  180. return new MaxBlock("Max");
  181. case "MinBlock":
  182. return new MinBlock("Min");
  183. case "LengthBlock":
  184. return new LengthBlock("Length");
  185. case "DistanceBlock":
  186. return new DistanceBlock("Distance");
  187. case "NegateBlock":
  188. return new NegateBlock("Negate");
  189. case "PerturbNormalBlock":
  190. return new PerturbNormalBlock("Perturb normal");
  191. case "RandomNumberBlock":
  192. return new RandomNumberBlock("Random number");
  193. case "ReplaceColorBlock":
  194. return new ReplaceColorBlock("Replace color");
  195. case "PosterizeBlock":
  196. return new PosterizeBlock("Posterize");
  197. case "ArcTan2Block":
  198. return new ArcTan2Block("ArcTan2");
  199. case "GradientBlock":
  200. return new GradientBlock("Gradient");
  201. case "FrontFacingBlock":
  202. return new FrontFacingBlock("Front facing");
  203. case "CosBlock": {
  204. let cosBlock = new TrigonometryBlock("Cos");
  205. cosBlock.operation = TrigonometryBlockOperations.Cos;
  206. return cosBlock;
  207. }
  208. case "SinBlock": {
  209. let sinBlock = new TrigonometryBlock("Sin");
  210. sinBlock.operation = TrigonometryBlockOperations.Sin;
  211. return sinBlock;
  212. }
  213. case "AbsBlock": {
  214. let absBlock = new TrigonometryBlock("Abs");
  215. absBlock.operation = TrigonometryBlockOperations.Abs;
  216. return absBlock;
  217. }
  218. case "SqrtBlock": {
  219. let sqrtBlock = new TrigonometryBlock("Sqrt");
  220. sqrtBlock.operation = TrigonometryBlockOperations.Sqrt;
  221. return sqrtBlock;
  222. }
  223. case "ArcCosBlock": {
  224. let acosBlock = new TrigonometryBlock("ArcCos");
  225. acosBlock.operation = TrigonometryBlockOperations.ArcCos;
  226. return acosBlock;
  227. }
  228. case "ArcSinBlock": {
  229. let asinBlock = new TrigonometryBlock("ArcSin");
  230. asinBlock.operation = TrigonometryBlockOperations.ArcSin;
  231. return asinBlock;
  232. }
  233. case "TanBlock": {
  234. let tanBlock = new TrigonometryBlock("Tan");
  235. tanBlock.operation = TrigonometryBlockOperations.Tan;
  236. return tanBlock;
  237. }
  238. case "ArcTanBlock": {
  239. let atanBlock = new TrigonometryBlock("ArcTan");
  240. atanBlock.operation = TrigonometryBlockOperations.ArcTan;
  241. return atanBlock;
  242. }
  243. case "FractBlock": {
  244. let fractBlock = new TrigonometryBlock("Fract");
  245. fractBlock.operation = TrigonometryBlockOperations.Fract;
  246. return fractBlock;
  247. }
  248. case "SignBlock": {
  249. let signBlock = new TrigonometryBlock("Sign");
  250. signBlock.operation = TrigonometryBlockOperations.Sign;
  251. return signBlock;
  252. }
  253. case "LogBlock": {
  254. let logBlock = new TrigonometryBlock("Log");
  255. logBlock.operation = TrigonometryBlockOperations.Log;
  256. return logBlock;
  257. }
  258. case "ExpBlock": {
  259. let expBlock = new TrigonometryBlock("Exp");
  260. expBlock.operation = TrigonometryBlockOperations.Exp;
  261. return expBlock;
  262. }
  263. case "Exp2Block": {
  264. let exp2Block = new TrigonometryBlock("Exp2");
  265. exp2Block.operation = TrigonometryBlockOperations.Exp2;
  266. return exp2Block;
  267. }
  268. case "DegreesToRadiansBlock": {
  269. let degreesToRadiansBlock = new TrigonometryBlock("Degrees to radians");
  270. degreesToRadiansBlock.operation = TrigonometryBlockOperations.Radians;
  271. return degreesToRadiansBlock;
  272. }
  273. case "RadiansToDegreesBlock": {
  274. let radiansToDegreesBlock = new TrigonometryBlock("Radians to degrees");
  275. radiansToDegreesBlock.operation = TrigonometryBlockOperations.Degrees;
  276. return radiansToDegreesBlock;
  277. }
  278. case "RoundBlock": {
  279. let roundBlock = new TrigonometryBlock("Round");
  280. roundBlock.operation = TrigonometryBlockOperations.Round;
  281. return roundBlock;
  282. }
  283. case "CeilingBlock": {
  284. let ceilingBlock = new TrigonometryBlock("Ceiling");
  285. ceilingBlock.operation = TrigonometryBlockOperations.Ceiling;
  286. return ceilingBlock;
  287. }
  288. case "FloorBlock": {
  289. let floorBlock = new TrigonometryBlock("Floor");
  290. floorBlock.operation = TrigonometryBlockOperations.Floor;
  291. return floorBlock;
  292. }
  293. case "SawToothWaveBlock": {
  294. let sawToothWaveBlock = new WaveBlock("SawTooth wave");
  295. sawToothWaveBlock.kind = WaveBlockKind.SawTooth;
  296. return sawToothWaveBlock;
  297. }
  298. case "SquareWaveBlock": {
  299. let squareWaveBlock = new WaveBlock("Square wave");
  300. squareWaveBlock.kind = WaveBlockKind.Square;
  301. return squareWaveBlock;
  302. }
  303. case "TriangleWaveBlock": {
  304. let triangleWaveBlock = new WaveBlock("Triangle wave");
  305. triangleWaveBlock.kind = WaveBlockKind.Triangle;
  306. return triangleWaveBlock;
  307. }
  308. case "WorldMatrixBlock": {
  309. let worldMatrixBlock = new InputBlock("World");
  310. worldMatrixBlock.setAsSystemValue(NodeMaterialSystemValues.World);
  311. return worldMatrixBlock;
  312. }
  313. case "WorldViewMatrixBlock": {
  314. let worldViewMatrixBlock = new InputBlock("World x View");
  315. worldViewMatrixBlock.setAsSystemValue(NodeMaterialSystemValues.WorldView);
  316. return worldViewMatrixBlock;
  317. }
  318. case "WorldViewProjectionMatrixBlock": {
  319. let worldViewProjectionMatrixBlock = new InputBlock("World x View x Projection");
  320. worldViewProjectionMatrixBlock.setAsSystemValue(NodeMaterialSystemValues.WorldViewProjection);
  321. return worldViewProjectionMatrixBlock;
  322. }
  323. case "ViewMatrixBlock": {
  324. let viewMatrixBlock = new InputBlock("View");
  325. viewMatrixBlock.setAsSystemValue(NodeMaterialSystemValues.View);
  326. return viewMatrixBlock;
  327. }
  328. case "ViewProjectionMatrixBlock": {
  329. let viewProjectionMatrixBlock = new InputBlock("View x Projection");
  330. viewProjectionMatrixBlock.setAsSystemValue(NodeMaterialSystemValues.ViewProjection);
  331. return viewProjectionMatrixBlock;
  332. }
  333. case "ProjectionMatrixBlock": {
  334. let projectionMatrixBlock = new InputBlock("Projection");
  335. projectionMatrixBlock.setAsSystemValue(NodeMaterialSystemValues.Projection);
  336. return projectionMatrixBlock;
  337. }
  338. case "CameraPositionBlock": {
  339. let cameraPosition = new InputBlock("Camera position");
  340. cameraPosition.setAsSystemValue(NodeMaterialSystemValues.CameraPosition);
  341. return cameraPosition;
  342. }
  343. case "FogColorBlock": {
  344. let FogColor = new InputBlock("Fog color");
  345. FogColor.setAsSystemValue(NodeMaterialSystemValues.FogColor);
  346. return FogColor;
  347. }
  348. case "PositionBlock": {
  349. let meshPosition = new InputBlock("position");
  350. meshPosition.setAsAttribute("position");
  351. return meshPosition;
  352. }
  353. case "ScreenPositionBlock": {
  354. let meshPosition = new InputBlock("position");
  355. meshPosition.setAsAttribute("position2d");
  356. return meshPosition;
  357. }
  358. case "UVBlock": {
  359. let meshUV = new InputBlock("uv");
  360. meshUV.setAsAttribute("uv");
  361. return meshUV;
  362. }
  363. case "ColorBlock": {
  364. let meshColor = new InputBlock("color");
  365. meshColor.setAsAttribute("color");
  366. return meshColor;
  367. }
  368. case "NormalBlock": {
  369. let meshNormal = new InputBlock("normal");
  370. meshNormal.setAsAttribute("normal");
  371. return meshNormal;
  372. }
  373. case "TangentBlock": {
  374. let meshTangent = new InputBlock("tangent");
  375. meshTangent.setAsAttribute("tangent");
  376. return meshTangent;
  377. }
  378. case "MatrixIndicesBlock": {
  379. let meshMatrixIndices = new InputBlock("matricesIndices");
  380. meshMatrixIndices.setAsAttribute("matricesIndices");
  381. return meshMatrixIndices;
  382. }
  383. case "MatrixWeightsBlock": {
  384. let meshMatrixWeights = new InputBlock("matricesWeights");
  385. meshMatrixWeights.setAsAttribute("matricesWeights");
  386. return meshMatrixWeights;
  387. }
  388. case "TimeBlock": {
  389. let timeBlock = new InputBlock("Time", undefined, NodeMaterialBlockConnectionPointTypes.Float);
  390. timeBlock.animationType = AnimatedInputBlockTypes.Time;
  391. return timeBlock;
  392. }
  393. case "DeltaTimeBlock": {
  394. let deltaTimeBlock = new InputBlock("Delta time");
  395. deltaTimeBlock.setAsSystemValue(NodeMaterialSystemValues.DeltaTime);
  396. return deltaTimeBlock;
  397. }
  398. case "WorldPositionBlock": {
  399. let worldPositionBlock = nodeMaterial.getInputBlockByPredicate((b) => b.isAttribute && b.name === "position");
  400. if (!worldPositionBlock) {
  401. worldPositionBlock = new InputBlock("position");
  402. worldPositionBlock.setAsAttribute("position");
  403. }
  404. let worldMatrixBlock = nodeMaterial.getInputBlockByPredicate((b) => b.isSystemValue && b.systemValue === NodeMaterialSystemValues.World);
  405. if (!worldMatrixBlock) {
  406. worldMatrixBlock = new InputBlock("World");
  407. worldMatrixBlock.setAsSystemValue(NodeMaterialSystemValues.World);
  408. }
  409. let transformBlock = new TransformBlock("World position");
  410. worldPositionBlock.connectTo(transformBlock);
  411. worldMatrixBlock.connectTo(transformBlock);
  412. return transformBlock;
  413. }
  414. case "WorldNormalBlock": {
  415. let worldNormalBlock = nodeMaterial.getInputBlockByPredicate((b) => b.isAttribute && b.name === "normal");
  416. if (!worldNormalBlock) {
  417. worldNormalBlock = new InputBlock("normal");
  418. worldNormalBlock.setAsAttribute("normal");
  419. }
  420. let worldMatrixBlock = nodeMaterial.getInputBlockByPredicate((b) => b.isSystemValue && b.systemValue === NodeMaterialSystemValues.World);
  421. if (!worldMatrixBlock) {
  422. worldMatrixBlock = new InputBlock("World");
  423. worldMatrixBlock.setAsSystemValue(NodeMaterialSystemValues.World);
  424. }
  425. let transformBlock = new TransformBlock("World normal");
  426. worldNormalBlock.connectTo(transformBlock);
  427. worldMatrixBlock.connectTo(transformBlock);
  428. return transformBlock;
  429. }
  430. case "WorldTangentBlock": {
  431. let worldTangentBlock = nodeMaterial.getInputBlockByPredicate((b) => b.isAttribute && b.name === "tangent");
  432. if (!worldTangentBlock) {
  433. worldTangentBlock = new InputBlock("tangent");
  434. worldTangentBlock.setAsAttribute("tangent");
  435. }
  436. let worldMatrixBlock = nodeMaterial.getInputBlockByPredicate((b) => b.isSystemValue && b.systemValue === NodeMaterialSystemValues.World);
  437. if (!worldMatrixBlock) {
  438. worldMatrixBlock = new InputBlock("World");
  439. worldMatrixBlock.setAsSystemValue(NodeMaterialSystemValues.World);
  440. }
  441. let transformBlock = new TransformBlock("World tangent");
  442. worldTangentBlock.connectTo(transformBlock);
  443. worldMatrixBlock.connectTo(transformBlock);
  444. return transformBlock;
  445. }
  446. case "PBRMetallicRoughnessBlock":
  447. return new PBRMetallicRoughnessBlock("PBRMetallicRoughness");
  448. case "SheenBlock":
  449. return new SheenBlock("Sheen");
  450. case "AmbientOcclusionBlock":
  451. return new AmbientOcclusionBlock("AmbientOcclusion");
  452. case "ReflectivityBlock":
  453. return new ReflectivityBlock("Reflectivity");
  454. case "AnisotropyBlock":
  455. return new AnisotropyBlock("Anisotropy");
  456. case "ReflectionBlock":
  457. return new ReflectionBlock("Reflection");
  458. case "ClearCoatBlock":
  459. return new ClearCoatBlock("ClearCoat");
  460. case "RefractionBlock":
  461. return new RefractionBlock("Refraction");
  462. case "SubSurfaceBlock":
  463. return new SubSurfaceBlock("SubSurface");
  464. case "CurrentScreenBlock":
  465. return new CurrentScreenBlock("CurrentScreen");
  466. case "ParticleUVBlock": {
  467. let uv = new InputBlock("uv");
  468. uv.setAsAttribute("particle_uv");
  469. return uv;
  470. }
  471. case "ParticleTextureBlock":
  472. return new ParticleTextureBlock("ParticleTexture");
  473. case "ParticleColorBlock": {
  474. let color = new InputBlock("Color");
  475. color.setAsAttribute("particle_color");
  476. return color;
  477. }
  478. case "ParticleTextureMaskBlock": {
  479. let u = new InputBlock("TextureMask");
  480. u.setAsAttribute("particle_texturemask");
  481. return u;
  482. }
  483. case "ParticlePositionWorldBlock": {
  484. let pos = new InputBlock("PositionWorld");
  485. pos.setAsAttribute("particle_positionw");
  486. return pos;
  487. }
  488. case "ParticleRampGradientBlock":
  489. return new ParticleRampGradientBlock("ParticleRampGradient");
  490. case "ParticleBlendMultiplyBlock":
  491. return new ParticleBlendMultiplyBlock("ParticleBlendMultiply");
  492. case "FragCoordBlock":
  493. return new FragCoordBlock("FragCoord");
  494. case "ScreenSizeBlock":
  495. return new ScreenSizeBlock("ScreenSize");
  496. }
  497. return null;
  498. }
  499. public static GetColorFromConnectionNodeType(type: NodeMaterialBlockConnectionPointTypes) {
  500. let color = "#880000";
  501. switch (type) {
  502. case NodeMaterialBlockConnectionPointTypes.Float:
  503. color = "#cb9e27";
  504. break;
  505. case NodeMaterialBlockConnectionPointTypes.Vector2:
  506. color = "#16bcb1";
  507. break;
  508. case NodeMaterialBlockConnectionPointTypes.Vector3:
  509. case NodeMaterialBlockConnectionPointTypes.Color3:
  510. color = "#b786cb";
  511. break;
  512. case NodeMaterialBlockConnectionPointTypes.Vector4:
  513. case NodeMaterialBlockConnectionPointTypes.Color4:
  514. color = "#be5126";
  515. break;
  516. case NodeMaterialBlockConnectionPointTypes.Matrix:
  517. color = "#591990";
  518. break;
  519. }
  520. return color;
  521. }
  522. public static GetConnectionNodeTypeFromString(type: string) {
  523. switch (type) {
  524. case "Float":
  525. return NodeMaterialBlockConnectionPointTypes.Float;
  526. case "Vector2":
  527. return NodeMaterialBlockConnectionPointTypes.Vector2;
  528. case "Vector3":
  529. return NodeMaterialBlockConnectionPointTypes.Vector3;
  530. case "Vector4":
  531. return NodeMaterialBlockConnectionPointTypes.Vector4;
  532. case "Matrix":
  533. return NodeMaterialBlockConnectionPointTypes.Matrix;
  534. case "Color3":
  535. return NodeMaterialBlockConnectionPointTypes.Color3;
  536. case "Color4":
  537. return NodeMaterialBlockConnectionPointTypes.Color4;
  538. }
  539. return NodeMaterialBlockConnectionPointTypes.AutoDetect;
  540. }
  541. public static GetStringFromConnectionNodeType(type: NodeMaterialBlockConnectionPointTypes) {
  542. switch (type){
  543. case NodeMaterialBlockConnectionPointTypes.Float:
  544. return "Float";
  545. case NodeMaterialBlockConnectionPointTypes.Vector2:
  546. return "Vector2";
  547. case NodeMaterialBlockConnectionPointTypes.Vector3:
  548. return "Vector3";
  549. case NodeMaterialBlockConnectionPointTypes.Vector4:
  550. return "Vector4";
  551. case NodeMaterialBlockConnectionPointTypes.Color3:
  552. return "Color3";
  553. case NodeMaterialBlockConnectionPointTypes.Color4:
  554. return "Color4";
  555. case NodeMaterialBlockConnectionPointTypes.Matrix:
  556. return "Matrix";
  557. }
  558. return "";
  559. }
  560. }