/sources/tools/Stride.Assimp/MaterialStack.cs

https://github.com/xenko3d/xenko · C# · 302 lines · 148 code · 1 blank · 153 comment · 1 complexity · 14397b7725e4eafe41300944b565582c MD5 · raw file

  1. // Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
  2. // Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using Stride.Core.Mathematics;
  10. namespace Stride
  11. {
  12. namespace AssimpNet
  13. {
  14. namespace Material
  15. {
  16. /// <summary>
  17. /// Enumeration of the different types of node in the new Assimp's material stack.
  18. /// </summary>
  19. public enum StackType
  20. {
  21. Color = 0,
  22. Texture,
  23. Operation
  24. }
  25. /// <summary>
  26. /// Enumeration of the new Assimp's flags.
  27. /// </summary>
  28. public enum Flags
  29. {
  30. Invert = 1,
  31. ReplaceAlpha = 2
  32. }
  33. /// <summary>
  34. /// Enumeration of the different operations in the new Assimp's material stack.
  35. /// </summary>
  36. public enum Operation
  37. {
  38. Add = 0,
  39. Add3ds,
  40. AddMaya,
  41. Average,
  42. Color,
  43. ColorBurn,
  44. ColorDodge,
  45. Darken3ds,
  46. DarkenMaya,
  47. Desaturate,
  48. Difference3ds,
  49. DifferenceMaya,
  50. Divide,
  51. Exclusion,
  52. HardLight,
  53. HardMix,
  54. Hue,
  55. Illuminate,
  56. In,
  57. Lighten3ds,
  58. LightenMaya,
  59. LinearBurn,
  60. LinearDodge,
  61. Multiply3ds,
  62. MultiplyMaya,
  63. None,
  64. Out,
  65. Over3ds,
  66. Overlay3ds,
  67. OverMaya,
  68. PinLight,
  69. Saturate,
  70. Saturation,
  71. Screen,
  72. SoftLight,
  73. Substract3ds,
  74. SubstractMaya,
  75. Value,
  76. Mask
  77. }
  78. /// <summary>
  79. /// Enumeration of the different mapping modes in the new Assimp's material stack.
  80. /// </summary>
  81. public enum MappingMode
  82. {
  83. Wrap,
  84. Clamp,
  85. Decal,
  86. Mirror
  87. }
  88. /// <summary>
  89. /// Class representing an element in the new Assimp's material stack.
  90. /// </summary>
  91. public abstract class StackElement
  92. {
  93. /// <summary>
  94. /// Initializes a new instance of the <see cref="StackElement"/> class.
  95. /// </summary>
  96. /// <param name="Alpha">The alpha of the node.</param>
  97. /// <param name="Blend">The blending coefficient of the node.</param>
  98. /// <param name="flags">The flags of the node.</param>
  99. /// <param name="Type">The type of the node.</param>
  100. public StackElement(float Alpha, float Blend, int flags, StackType Type)
  101. {
  102. alpha = Alpha;
  103. blend = Blend;
  104. type = Type;
  105. }
  106. /// <summary>
  107. /// Gets the alpha of the node.
  108. /// </summary>
  109. /// <value>
  110. /// The alpha of the node.
  111. /// </value>
  112. public float alpha { get; private set; }
  113. /// <summary>
  114. /// Gets the blending coefficient of the node.
  115. /// </summary>
  116. /// <value>
  117. /// The blending coefficient of the node.
  118. /// </value>
  119. public float blend { get; private set; }
  120. /// <summary>
  121. /// Gets the flags of the node.
  122. /// </summary>
  123. /// <value>
  124. /// The flags of the node.
  125. /// </value>
  126. public int flags { get; private set; }
  127. /// <summary>
  128. /// Gets the type of the node.
  129. /// </summary>
  130. /// <value>
  131. /// The type of the node.
  132. /// </value>
  133. public StackType type { get; private set; }
  134. }
  135. /// <summary>
  136. /// Class representing an operation in the new Assimp's material stack.
  137. /// </summary>
  138. public class StackOperation : StackElement
  139. {
  140. /// <summary>
  141. /// Initializes a new instance of the <see cref="StackOperation"/> class.
  142. /// </summary>
  143. /// <param name="Operation">The operation of the node.</param>
  144. /// <param name="Alpha">The alpha of the node.</param>
  145. /// <param name="Blend">The blending coefficient of the node.</param>
  146. /// <param name="Flags">The flags.</param>
  147. public StackOperation(Operation Operation, float Alpha = 1.0f, float Blend = 1.0f, int Flags = 0)
  148. : base(Alpha, Blend, Flags, StackType.Operation)
  149. {
  150. operation = Operation;
  151. }
  152. /// <summary>
  153. /// Gets the operation of the node.
  154. /// </summary>
  155. /// <value>
  156. /// The operation of the node.
  157. /// </value>
  158. public Operation operation { get; private set; }
  159. }
  160. /// <summary>
  161. /// Class representing a color in the new Assimp's material stack.
  162. /// </summary>
  163. public class StackColor : StackElement
  164. {
  165. /// <summary>
  166. /// Initializes a new instance of the <see cref="StackColor"/> class.
  167. /// </summary>
  168. /// <param name="Color">The color of the node.</param>
  169. /// <param name="Alpha">The alpha of the node.</param>
  170. /// <param name="Blend">The blending coefficient of the node.</param>
  171. /// <param name="Flags">The flags of the node.</param>
  172. public StackColor(Color3 Color, float Alpha = 1.0f, float Blend = 1.0f, int Flags = 0)
  173. : base(Alpha, Blend, Flags, StackType.Color)
  174. {
  175. color = Color;
  176. }
  177. /// <summary>
  178. /// Gets the color of the node.
  179. /// </summary>
  180. /// <value>
  181. /// The color of the node.
  182. /// </value>
  183. public Color3 color { get; private set; }
  184. }
  185. /// <summary>
  186. /// Class representing a texture in the new Assimp's material stack.
  187. /// </summary>
  188. public class StackTexture : StackElement
  189. {
  190. /// <summary>
  191. /// Initializes a new instance of the <see cref="StackTexture"/> class.
  192. /// </summary>
  193. /// <param name="TexturePath">The texture path.</param>
  194. /// <param name="Channel">The uv channel used by the texture.</param>
  195. /// <param name="MappingModeU">The U mapping mode.</param>
  196. /// <param name="MappingModeV">The V mapping mode.</param>
  197. /// <param name="Alpha">The alpha of the node.</param>
  198. /// <param name="Blend">The blending coefficient of the node.</param>
  199. /// <param name="Flags">The flags of the node.</param>
  200. public StackTexture(String TexturePath, int Channel, MappingMode MappingModeU, MappingMode MappingModeV, float Alpha = 1.0f, float Blend = 1.0F, int Flags = 0)
  201. : base(Alpha, Blend, Flags, StackType.Texture)
  202. {
  203. texturePath = TexturePath;
  204. channel = Channel;
  205. mappingModeU = MappingModeU;
  206. mappingModeV = MappingModeV;
  207. }
  208. /// <summary>
  209. /// Gets the texture path.
  210. /// </summary>
  211. /// <value>
  212. /// The texture path.
  213. /// </value>
  214. public String texturePath { get; private set; }
  215. /// <summary>
  216. /// Gets the uv channel.
  217. /// </summary>
  218. /// <value>
  219. /// The uv channel.
  220. /// </value>
  221. public int channel { get; private set; }
  222. /// <summary>
  223. /// Gets the U mapping mode.
  224. /// </summary>
  225. /// <value>
  226. /// The U mapping mode.
  227. /// </value>
  228. public MappingMode mappingModeU { get; private set; }
  229. /// <summary>
  230. /// Gets the Vmapping mode.
  231. /// </summary>
  232. /// <value>
  233. /// The V mapping mode.
  234. /// </value>
  235. public MappingMode mappingModeV { get; private set; }
  236. }
  237. /// <summary>
  238. /// Class representing the new Assimp's material stack in c#.
  239. /// </summary>
  240. public class Stack
  241. {
  242. /// <summary>
  243. /// Initializes a new instance of the <see cref="Stack"/> class.
  244. /// </summary>
  245. public Stack()
  246. {
  247. stack = new Stack<StackElement>();
  248. }
  249. /// <summary>
  250. /// The internal stack.
  251. /// </summary>
  252. private Stack<StackElement> stack;
  253. /// <summary>
  254. /// Gets the size of the stack.
  255. /// </summary>
  256. /// <value>
  257. /// The size of the stack.
  258. /// </value>
  259. private int Count { get { return stack.Count; } }
  260. /// <summary>
  261. /// Gets a value indicating whether the stack is empty.
  262. /// </summary>
  263. /// <value>
  264. /// <c>true</c> if the stack is empty; otherwise, <c>false</c>.
  265. /// </value>
  266. public bool IsEmpty { get { return stack.Count == 0; } }
  267. /// <summary>
  268. /// Pushes the specified element.
  269. /// </summary>
  270. /// <param name="element">The element.</param>
  271. public void Push(StackElement element)
  272. {
  273. stack.Push(element);
  274. }
  275. /// <summary>
  276. /// Pops an element.
  277. /// </summary>
  278. /// <returns>The element.</returns>
  279. public StackElement Pop()
  280. {
  281. return stack.Pop();
  282. }
  283. /// <summary>
  284. /// Gets the top element of the stack.
  285. /// </summary>
  286. /// <returns>The top element of the stack.</returns>
  287. public StackElement Peek()
  288. {
  289. return stack.Peek();
  290. }
  291. /// <summary>
  292. /// Clears the stack.
  293. /// </summary>
  294. public void Clear()
  295. {
  296. stack.Clear();
  297. }
  298. }
  299. }
  300. }
  301. }