mapping_node.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. function mapping_node_init() {
  2. array_push(nodes_material_utilities, mapping_node_def);
  3. map_set(parser_material_node_vectors, "MAPPING", mapping_node_vector);
  4. }
  5. function mapping_node_vector(node: ui_node_t, socket: ui_node_socket_t): string {
  6. let out: string = parser_material_parse_vector_input(node.inputs[0]);
  7. let node_translation: string = parser_material_parse_vector_input(node.inputs[1]);
  8. let node_rotation: string = parser_material_parse_vector_input(node.inputs[2]);
  9. let node_scale: string = parser_material_parse_vector_input(node.inputs[3]);
  10. if (node_scale != "float3(1, 1, 1)") {
  11. out = "(" + out + " * " + node_scale + ")";
  12. }
  13. if (node_rotation != "float3(0, 0, 0)") {
  14. // ZYX rotation, Z axis for now..
  15. let a: string = node_rotation + ".z * (3.1415926535 / 180)";
  16. // x * cos(theta) - y * sin(theta)
  17. // x * sin(theta) + y * cos(theta)
  18. out = "float3(" + out + ".x * cos(" + a + ") - " + out + ".y * sin(" + a + "), " + out + ".x * sin(" + a + ") + " + out + ".y * cos(" + a + "), 0.0)";
  19. }
  20. // if node.rotation[1] != 0.0:
  21. // a = node.rotation[1]
  22. // out = "float3({0}.x * {1} - {0}.z * {2}, {0}.x * {2} + {0}.z * {1}, 0.0)".format(out, math_cos(a), math_sin(a))
  23. // if node.rotation[0] != 0.0:
  24. // a = node.rotation[0]
  25. // out = "float3({0}.y * {1} - {0}.z * {2}, {0}.y * {2} + {0}.z * {1}, 0.0)".format(out, math_cos(a), math_sin(a))
  26. if (node_translation != "float3(0, 0, 0)") {
  27. out = "(" + out + " + " + node_translation + ")";
  28. }
  29. // if node.use_min:
  30. // out = "max({0}, float3({1}, {2}, {3}))".format(out, node.min[0], node.min[1])
  31. // if node.use_max:
  32. // out = "min({0}, float3({1}, {2}, {3}))".format(out, node.max[0], node.max[1])
  33. return out;
  34. }
  35. let mapping_node_def: ui_node_t = {
  36. id : 0,
  37. name : _tr("Mapping"),
  38. type : "MAPPING",
  39. x : 0,
  40. y : 0,
  41. color : 0xff522c99,
  42. inputs : [
  43. {
  44. id : 0,
  45. node_id : 0,
  46. name : _tr("Vector"),
  47. type : "VECTOR",
  48. color : 0xff6363c7,
  49. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  50. min : 0.0,
  51. max : 1.0,
  52. precision : 100,
  53. display : 1
  54. },
  55. {
  56. id : 0,
  57. node_id : 0,
  58. name : _tr("Location"),
  59. type : "VECTOR",
  60. color : 0xff6363c7,
  61. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  62. min : 0.0,
  63. max : 1.0,
  64. precision : 100,
  65. display : 1
  66. },
  67. {
  68. id : 0,
  69. node_id : 0,
  70. name : _tr("Rotation"),
  71. type : "VECTOR",
  72. color : 0xff6363c7,
  73. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  74. min : 0.0,
  75. max : 360.0,
  76. precision : 100,
  77. display : 1
  78. },
  79. {
  80. id : 0,
  81. node_id : 0,
  82. name : _tr("Scale"),
  83. type : "VECTOR",
  84. color : 0xff6363c7,
  85. default_value : f32_array_create_xyz(1.0, 1.0, 1.0),
  86. min : 0.0,
  87. max : 1.0,
  88. precision : 100,
  89. display : 1
  90. }
  91. ],
  92. outputs : [ {
  93. id : 0,
  94. node_id : 0,
  95. name : _tr("Vector"),
  96. type : "VECTOR",
  97. color : 0xff6363c7,
  98. default_value : f32_array_create_xyz(0.0, 0.0, 0.0),
  99. min : 0.0,
  100. max : 1.0,
  101. precision : 100,
  102. display : 0
  103. } ],
  104. buttons : [],
  105. width : 0,
  106. flags : 0
  107. };