184 linhas
5.1 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2010-2015 Sam Hocevar <sam@hocevar.net>
  5. // (c) 2009-2015 Cédric Lecacheur <jordx@free.fr>
  6. // (c) 2009-2015 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the Do What The Fuck You Want To
  9. // Public License, Version 2, as published by Sam Hocevar. See
  10. // http://www.wtfpl.net/ for more details.
  11. //
  12. //
  13. // The EasyMesh class
  14. // ------------------
  15. //
  16. #include <lol/engine-internal.h>
  17. namespace lol
  18. {
  19. //-----------------------------------------------------------------------------
  20. void EasyMesh::LoopStart(int loopnb)
  21. {
  22. if (BD()->IsEnabled(MeshBuildOperation::CommandRecording))
  23. {
  24. BD()->CmdStack().AddCmd(EasyMeshCmdType::LoopStart);
  25. BD()->CmdStack() << loopnb;
  26. return;
  27. }
  28. //Loop is only available when executing a command recording
  29. else if (BD()->IsEnabled(MeshBuildOperation::CommandExecution))
  30. {
  31. //Only register if we're not the current loop command
  32. if (!BD()->LoopStack().Count() || BD()->LoopStack().Last().m1 != BD()->Cmdi())
  33. BD()->LoopStack().Push(BD()->Cmdi(), loopnb);
  34. }
  35. }
  36. //-----------------------------------------------------------------------------
  37. void EasyMesh::LoopEnd()
  38. {
  39. if (BD()->IsEnabled(MeshBuildOperation::CommandRecording))
  40. {
  41. BD()->CmdStack().AddCmd(EasyMeshCmdType::LoopEnd);
  42. return;
  43. }
  44. //Loop is only available when executing a command recording
  45. else if (BD()->IsEnabled(MeshBuildOperation::CommandExecution))
  46. {
  47. //Only register if we're not the current loop command
  48. if (BD()->LoopStack().Count())
  49. {
  50. BD()->LoopStack().Last().m2--;
  51. if (BD()->LoopStack().Last().m2 > 0)
  52. BD()->Cmdi() = BD()->LoopStack().Last().m1 - 1;
  53. else
  54. BD()->LoopStack().Pop();
  55. }
  56. }
  57. }
  58. //-----------------------------------------------------------------------------
  59. void EasyMesh::OpenBrace()
  60. {
  61. if (BD()->IsEnabled(MeshBuildOperation::CommandRecording))
  62. {
  63. BD()->CmdStack().AddCmd(EasyMeshCmdType::OpenBrace);
  64. return;
  65. }
  66. m_cursors.Push((int)m_vert.Count(), (int)m_indices.Count());
  67. }
  68. //-----------------------------------------------------------------------------
  69. void EasyMesh::CloseBrace()
  70. {
  71. if (BD()->IsEnabled(MeshBuildOperation::CommandRecording))
  72. {
  73. BD()->CmdStack().AddCmd(EasyMeshCmdType::CloseBrace);
  74. return;
  75. }
  76. m_cursors.Pop();
  77. }
  78. //-----------------------------------------------------------------------------
  79. void EasyMesh::ToggleScaleWinding()
  80. {
  81. if (BD()->IsEnabled(MeshBuildOperation::CommandRecording))
  82. {
  83. BD()->CmdStack().AddCmd(EasyMeshCmdType::ScaleWinding);
  84. return;
  85. }
  86. BD()->Toggle(MeshBuildOperation::ScaleWinding);
  87. }
  88. //-----------------------------------------------------------------------------
  89. void EasyMesh::ToggleQuadWeighting()
  90. {
  91. if (BD()->IsEnabled(MeshBuildOperation::CommandRecording))
  92. {
  93. BD()->CmdStack().AddCmd(EasyMeshCmdType::QuadWeighting);
  94. return;
  95. }
  96. BD()->Toggle(MeshBuildOperation::QuadWeighting);
  97. }
  98. //-----------------------------------------------------------------------------
  99. void EasyMesh::TogglePostBuildNormal()
  100. {
  101. if (BD()->IsEnabled(MeshBuildOperation::CommandRecording))
  102. {
  103. BD()->CmdStack().AddCmd(EasyMeshCmdType::PostBuildNormal);
  104. return;
  105. }
  106. BD()->Toggle(MeshBuildOperation::PostBuildComputeNormals);
  107. }
  108. //-----------------------------------------------------------------------------
  109. void EasyMesh::ToggleVerticeNoCleanup()
  110. {
  111. if (BD()->IsEnabled(MeshBuildOperation::CommandRecording))
  112. {
  113. BD()->CmdStack().AddCmd(EasyMeshCmdType::PreventVertCleanup);
  114. return;
  115. }
  116. BD()->Toggle(MeshBuildOperation::PreventVertCleanup);
  117. }
  118. //-----------------------------------------------------------------------------
  119. void EasyMesh::SetCurColor(vec4 const &color)
  120. {
  121. SetCurColorA(color);
  122. SetCurColorB(color);
  123. }
  124. //-----------------------------------------------------------------------------
  125. void EasyMesh::SetCurColorA(vec4 const &color)
  126. {
  127. if (BD()->IsEnabled(MeshBuildOperation::CommandRecording))
  128. {
  129. BD()->CmdStack().AddCmd(EasyMeshCmdType::SetColorA);
  130. BD()->CmdStack() << color;
  131. return;
  132. }
  133. BD()->ColorA() = color;
  134. }
  135. //-----------------------------------------------------------------------------
  136. void EasyMesh::SetCurColorB(vec4 const &color)
  137. {
  138. if (BD()->IsEnabled(MeshBuildOperation::CommandRecording))
  139. {
  140. BD()->CmdStack().AddCmd(EasyMeshCmdType::SetColorB);
  141. BD()->CmdStack() << color;
  142. return;
  143. }
  144. BD()->ColorB() = color;
  145. }
  146. //-----------------------------------------------------------------------------
  147. void EasyMesh::SetVertColor(vec4 const &color)
  148. {
  149. if (BD()->IsEnabled(MeshBuildOperation::CommandRecording))
  150. {
  151. BD()->CmdStack().AddCmd(EasyMeshCmdType::SetVertColor);
  152. BD()->CmdStack() << color;
  153. return;
  154. }
  155. for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++)
  156. m_vert[i].m_color = color;
  157. }
  158. } /* namespace lol */