VariableMapping.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright (c) 2009-2012 jMonkeyEngine
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are
  7. * met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. package com.jme3.shader;
  33. import com.jme3.export.InputCapsule;
  34. import com.jme3.export.JmeExporter;
  35. import com.jme3.export.JmeImporter;
  36. import com.jme3.export.OutputCapsule;
  37. import com.jme3.export.Savable;
  38. import java.io.IOException;
  39. /**
  40. * represents a mapping between 2 ShaderNodeVariables
  41. *
  42. * @author Nehon
  43. */
  44. public class VariableMapping implements Savable {
  45. private ShaderNodeVariable leftVariable;
  46. private ShaderNodeVariable rightVariable;
  47. private String condition;
  48. private String leftSwizzling = "";
  49. private String rightSwizzling = "";
  50. /**
  51. * creates a VariableMapping
  52. */
  53. public VariableMapping() {
  54. }
  55. /**
  56. * creates a VariableMapping
  57. *
  58. * @param leftVariable the left hand side variable of the expression
  59. * @param leftSwizzling the swizzling of the left variable
  60. * @param rightVariable the right hand side variable of the expression
  61. * @param rightSwizzling the swizzling of the right variable
  62. * @param condition the condition for this mapping
  63. */
  64. public VariableMapping(ShaderNodeVariable leftVariable, String leftSwizzling, ShaderNodeVariable rightVariable, String rightSwizzling, String condition) {
  65. this.leftVariable = leftVariable;
  66. this.rightVariable = rightVariable;
  67. this.condition = condition;
  68. this.leftSwizzling = leftSwizzling;
  69. this.rightSwizzling = rightSwizzling;
  70. }
  71. /**
  72. *
  73. * @return the left variable
  74. */
  75. public ShaderNodeVariable getLeftVariable() {
  76. return leftVariable;
  77. }
  78. /**
  79. * sets the left variable
  80. *
  81. * @param leftVariable the left variable
  82. */
  83. public void setLeftVariable(ShaderNodeVariable leftVariable) {
  84. this.leftVariable = leftVariable;
  85. }
  86. /**
  87. *
  88. * @return the right variable
  89. */
  90. public ShaderNodeVariable getRightVariable() {
  91. return rightVariable;
  92. }
  93. /**
  94. * sets the right variable
  95. *
  96. * @param leftVariable the right variable
  97. */
  98. public void setRightVariable(ShaderNodeVariable rightVariable) {
  99. this.rightVariable = rightVariable;
  100. }
  101. /**
  102. *
  103. * @return the condition
  104. */
  105. public String getCondition() {
  106. return condition;
  107. }
  108. /**
  109. * sets the condition
  110. *
  111. * @param condition the condition
  112. */
  113. public void setCondition(String condition) {
  114. this.condition = condition;
  115. }
  116. /**
  117. *
  118. * @return the left swizzle
  119. */
  120. public String getLeftSwizzling() {
  121. return leftSwizzling;
  122. }
  123. /**
  124. * sets the left swizzle
  125. *
  126. * @param leftSwizzling the left swizzle
  127. */
  128. public void setLeftSwizzling(String leftSwizzling) {
  129. this.leftSwizzling = leftSwizzling;
  130. }
  131. /**
  132. *
  133. * @return the right swizzle
  134. */
  135. public String getRightSwizzling() {
  136. return rightSwizzling;
  137. }
  138. /**
  139. * sets the right swizzle
  140. *
  141. * @param leftSwizzling the right swizzle
  142. */
  143. public void setRightSwizzling(String rightSwizzling) {
  144. this.rightSwizzling = rightSwizzling;
  145. }
  146. /**
  147. * jme seralization (not used)
  148. *
  149. * @param ex the exporter
  150. * @throws IOException
  151. */
  152. public void write(JmeExporter ex) throws IOException {
  153. OutputCapsule oc = (OutputCapsule) ex.getCapsule(this);
  154. oc.write(leftVariable, "leftVariable", null);
  155. oc.write(rightVariable, "rightVariable", null);
  156. oc.write(condition, "condition", "");
  157. oc.write(leftSwizzling, "leftSwizzling", "");
  158. oc.write(rightSwizzling, "rightSwizzling", "");
  159. }
  160. /**
  161. * jme seralization (not used)
  162. *
  163. * @param im the importer
  164. * @throws IOException
  165. */
  166. public void read(JmeImporter im) throws IOException {
  167. InputCapsule ic = (InputCapsule) im.getCapsule(this);
  168. leftVariable = (ShaderNodeVariable) ic.readSavable("leftVariable", null);
  169. rightVariable = (ShaderNodeVariable) ic.readSavable("rightVariable", null);
  170. condition = ic.readString("condition", "");
  171. leftSwizzling = ic.readString("leftSwizzling", "");
  172. rightSwizzling = ic.readString("rightSwizzling", "");
  173. }
  174. @Override
  175. public String toString() {
  176. return "\n{" + leftVariable.toString() + (leftSwizzling.length() > 0 ? ("." + leftSwizzling) : "") + " = " + rightVariable.getType() + " " + rightVariable.getNameSpace() + "." + rightVariable.getName() + (rightSwizzling.length() > 0 ? ("." + rightSwizzling) : "") + " : " + condition + "}";
  177. }
  178. }