spring_bone_3d_gizmo_plugin.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /**************************************************************************/
  2. /* spring_bone_3d_gizmo_plugin.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "spring_bone_3d_gizmo_plugin.h"
  31. #include "editor/editor_settings.h"
  32. #include "scene/3d/spring_bone_collision_capsule_3d.h"
  33. #include "scene/3d/spring_bone_collision_plane_3d.h"
  34. #include "scene/3d/spring_bone_collision_sphere_3d.h"
  35. // SpringBoneSimulator3D
  36. SpringBoneSimulator3DGizmoPlugin::SelectionMaterials SpringBoneSimulator3DGizmoPlugin::selection_materials;
  37. SpringBoneSimulator3DGizmoPlugin::SpringBoneSimulator3DGizmoPlugin() {
  38. selection_materials.unselected_mat.instantiate();
  39. selection_materials.unselected_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  40. selection_materials.unselected_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  41. selection_materials.unselected_mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
  42. selection_materials.unselected_mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
  43. selection_materials.unselected_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  44. selection_materials.selected_mat.instantiate();
  45. Ref<Shader> sh;
  46. sh.instantiate();
  47. sh->set_code(R"(
  48. // Skeleton 3D gizmo bones shader.
  49. shader_type spatial;
  50. render_mode unshaded, shadows_disabled;
  51. void vertex() {
  52. if (!OUTPUT_IS_SRGB) {
  53. COLOR.rgb = mix( pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb* (1.0 / 12.92), lessThan(COLOR.rgb,vec3(0.04045)) );
  54. }
  55. VERTEX = VERTEX;
  56. POSITION = PROJECTION_MATRIX * VIEW_MATRIX * MODEL_MATRIX * vec4(VERTEX.xyz, 1.0);
  57. POSITION.z = mix(POSITION.z, POSITION.w, 0.998);
  58. }
  59. void fragment() {
  60. ALBEDO = COLOR.rgb;
  61. ALPHA = COLOR.a;
  62. }
  63. )");
  64. selection_materials.selected_mat->set_shader(sh);
  65. }
  66. SpringBoneSimulator3DGizmoPlugin::~SpringBoneSimulator3DGizmoPlugin() {
  67. selection_materials.unselected_mat.unref();
  68. selection_materials.selected_mat.unref();
  69. }
  70. bool SpringBoneSimulator3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
  71. return Object::cast_to<SpringBoneSimulator3D>(p_spatial) != nullptr;
  72. }
  73. String SpringBoneSimulator3DGizmoPlugin::get_gizmo_name() const {
  74. return "SpringBoneSimulator3D";
  75. }
  76. int SpringBoneSimulator3DGizmoPlugin::get_priority() const {
  77. return -1;
  78. }
  79. void SpringBoneSimulator3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
  80. SpringBoneSimulator3D *simulator = Object::cast_to<SpringBoneSimulator3D>(p_gizmo->get_node_3d());
  81. p_gizmo->clear();
  82. if (!simulator->get_setting_count()) {
  83. return;
  84. }
  85. Skeleton3D *skeleton = simulator->get_skeleton();
  86. if (!skeleton) {
  87. return;
  88. }
  89. Ref<ArrayMesh> mesh = get_joints_mesh(skeleton, simulator, p_gizmo->is_selected());
  90. Transform3D skel_tr = simulator->get_global_transform().inverse() * skeleton->get_global_transform();
  91. p_gizmo->add_mesh(mesh, Ref<Material>(), skel_tr, skeleton->register_skin(skeleton->create_skin_from_rest_transforms()));
  92. }
  93. Ref<ArrayMesh> SpringBoneSimulator3DGizmoPlugin::get_joints_mesh(Skeleton3D *p_skeleton, SpringBoneSimulator3D *p_simulator, bool p_is_selected) {
  94. Color bone_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/spring_bone_joint");
  95. Ref<SurfaceTool> surface_tool;
  96. surface_tool.instantiate();
  97. surface_tool->begin(Mesh::PRIMITIVE_LINES);
  98. if (p_is_selected) {
  99. surface_tool->set_material(selection_materials.selected_mat);
  100. } else {
  101. selection_materials.unselected_mat->set_albedo(bone_color);
  102. surface_tool->set_material(selection_materials.unselected_mat);
  103. }
  104. LocalVector<int> bones;
  105. LocalVector<float> weights;
  106. bones.resize(4);
  107. weights.resize(4);
  108. for (int i = 0; i < 4; i++) {
  109. bones[i] = 0;
  110. weights[i] = 0;
  111. }
  112. weights[0] = 1;
  113. for (int i = 0; i < p_simulator->get_setting_count(); i++) {
  114. int current_bone = -1;
  115. int prev_bone = -1;
  116. int joint_end = p_simulator->get_joint_count(i) - 1;
  117. for (int j = 0; j <= joint_end; j++) {
  118. current_bone = p_simulator->get_joint_bone(i, j);
  119. if (j > 0) {
  120. Transform3D parent_global_pose = p_skeleton->get_bone_global_rest(prev_bone);
  121. Transform3D global_pose = p_skeleton->get_bone_global_rest(current_bone);
  122. draw_line(surface_tool, parent_global_pose.origin, global_pose.origin, bone_color);
  123. draw_sphere(surface_tool, global_pose.basis, global_pose.origin, p_simulator->get_joint_radius(i, j - 1), bone_color);
  124. }
  125. if (j == joint_end && p_simulator->is_end_bone_extended(i) && p_simulator->get_end_bone_length(i) > 0) {
  126. Vector3 axis = p_simulator->get_end_bone_axis(current_bone, p_simulator->get_end_bone_direction(i));
  127. if (axis.is_zero_approx()) {
  128. continue;
  129. }
  130. bones[0] = current_bone;
  131. surface_tool->set_bones(bones);
  132. surface_tool->set_weights(weights);
  133. Transform3D global_pose = p_skeleton->get_bone_global_rest(current_bone);
  134. axis = global_pose.xform(axis * p_simulator->get_end_bone_length(i));
  135. draw_line(surface_tool, global_pose.origin, axis, bone_color);
  136. draw_sphere(surface_tool, global_pose.basis, axis, p_simulator->get_joint_radius(i, j), bone_color);
  137. } else {
  138. bones[0] = current_bone;
  139. surface_tool->set_bones(bones);
  140. surface_tool->set_weights(weights);
  141. }
  142. prev_bone = current_bone;
  143. }
  144. }
  145. return surface_tool->commit();
  146. }
  147. void SpringBoneSimulator3DGizmoPlugin::draw_sphere(Ref<SurfaceTool> &p_surface_tool, const Basis &p_basis, const Vector3 &p_center, float p_radius, const Color &p_color) {
  148. static const Vector3 VECTOR3_RIGHT = Vector3(1, 0, 0);
  149. static const Vector3 VECTOR3_UP = Vector3(0, 1, 0);
  150. static const Vector3 VECTOR3_FORWARD = Vector3(0, 0, 1);
  151. static const int STEP = 16;
  152. static const float SPPI = Math::TAU / (float)STEP;
  153. for (int i = 1; i <= STEP; i++) {
  154. p_surface_tool->set_color(p_color);
  155. p_surface_tool->add_vertex(p_center + ((p_basis.xform(VECTOR3_UP * p_radius)).rotated(p_basis.xform(VECTOR3_RIGHT), SPPI * ((i - 1) % STEP))));
  156. p_surface_tool->set_color(p_color);
  157. p_surface_tool->add_vertex(p_center + ((p_basis.xform(VECTOR3_UP * p_radius)).rotated(p_basis.xform(VECTOR3_RIGHT), SPPI * (i % STEP))));
  158. }
  159. for (int i = 1; i <= STEP; i++) {
  160. p_surface_tool->set_color(p_color);
  161. p_surface_tool->add_vertex(p_center + ((p_basis.xform(VECTOR3_RIGHT * p_radius)).rotated(p_basis.xform(VECTOR3_FORWARD), SPPI * ((i - 1) % STEP))));
  162. p_surface_tool->set_color(p_color);
  163. p_surface_tool->add_vertex(p_center + ((p_basis.xform(VECTOR3_RIGHT * p_radius)).rotated(p_basis.xform(VECTOR3_FORWARD), SPPI * (i % STEP))));
  164. }
  165. for (int i = 1; i <= STEP; i++) {
  166. p_surface_tool->set_color(p_color);
  167. p_surface_tool->add_vertex(p_center + ((p_basis.xform(VECTOR3_FORWARD * p_radius)).rotated(p_basis.xform(VECTOR3_UP), SPPI * ((i - 1) % STEP))));
  168. p_surface_tool->set_color(p_color);
  169. p_surface_tool->add_vertex(p_center + ((p_basis.xform(VECTOR3_FORWARD * p_radius)).rotated(p_basis.xform(VECTOR3_UP), SPPI * (i % STEP))));
  170. }
  171. }
  172. void SpringBoneSimulator3DGizmoPlugin::draw_line(Ref<SurfaceTool> &p_surface_tool, const Vector3 &p_begin_pos, const Vector3 &p_end_pos, const Color &p_color) {
  173. p_surface_tool->set_color(p_color);
  174. p_surface_tool->add_vertex(p_begin_pos);
  175. p_surface_tool->set_color(p_color);
  176. p_surface_tool->add_vertex(p_end_pos);
  177. }
  178. // SpringBoneCollision3D
  179. SpringBoneCollision3DGizmoPlugin::SelectionMaterials SpringBoneCollision3DGizmoPlugin::selection_materials;
  180. SpringBoneCollision3DGizmoPlugin::SpringBoneCollision3DGizmoPlugin() {
  181. selection_materials.unselected_mat.instantiate();
  182. selection_materials.unselected_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
  183. selection_materials.unselected_mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
  184. selection_materials.unselected_mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
  185. selection_materials.unselected_mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
  186. selection_materials.unselected_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);
  187. selection_materials.selected_mat.instantiate();
  188. Ref<Shader> sh;
  189. sh.instantiate();
  190. sh->set_code(R"(
  191. // Skeleton 3D gizmo bones shader.
  192. shader_type spatial;
  193. render_mode unshaded, shadows_disabled;
  194. void vertex() {
  195. if (!OUTPUT_IS_SRGB) {
  196. COLOR.rgb = mix( pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb* (1.0 / 12.92), lessThan(COLOR.rgb,vec3(0.04045)) );
  197. }
  198. VERTEX = VERTEX;
  199. POSITION = PROJECTION_MATRIX * VIEW_MATRIX * MODEL_MATRIX * vec4(VERTEX.xyz, 1.0);
  200. POSITION.z = mix(POSITION.z, POSITION.w, 0.998);
  201. }
  202. void fragment() {
  203. ALBEDO = COLOR.rgb;
  204. ALPHA = COLOR.a;
  205. }
  206. )");
  207. selection_materials.selected_mat->set_shader(sh);
  208. }
  209. SpringBoneCollision3DGizmoPlugin::~SpringBoneCollision3DGizmoPlugin() {
  210. selection_materials.unselected_mat.unref();
  211. selection_materials.selected_mat.unref();
  212. }
  213. bool SpringBoneCollision3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
  214. return Object::cast_to<SpringBoneCollision3D>(p_spatial) != nullptr;
  215. }
  216. String SpringBoneCollision3DGizmoPlugin::get_gizmo_name() const {
  217. return "SpringBoneCollision3D";
  218. }
  219. int SpringBoneCollision3DGizmoPlugin::get_priority() const {
  220. return -1;
  221. }
  222. void SpringBoneCollision3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
  223. SpringBoneCollision3D *collision = Object::cast_to<SpringBoneCollision3D>(p_gizmo->get_node_3d());
  224. p_gizmo->clear();
  225. Ref<ArrayMesh> mesh = get_collision_mesh(collision, p_gizmo->is_selected());
  226. p_gizmo->add_mesh(mesh);
  227. }
  228. Ref<ArrayMesh> SpringBoneCollision3DGizmoPlugin::get_collision_mesh(SpringBoneCollision3D *p_collision, bool p_is_selected) {
  229. Color collision_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/spring_bone_collision");
  230. Color inside_collision_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/spring_bone_inside_collision");
  231. Ref<SurfaceTool> surface_tool;
  232. surface_tool.instantiate();
  233. surface_tool->begin(Mesh::PRIMITIVE_LINES);
  234. if (p_is_selected) {
  235. surface_tool->set_material(selection_materials.selected_mat);
  236. } else {
  237. selection_materials.unselected_mat->set_albedo(collision_color);
  238. surface_tool->set_material(selection_materials.unselected_mat);
  239. }
  240. SpringBoneCollisionSphere3D *sphere = Object::cast_to<SpringBoneCollisionSphere3D>(p_collision);
  241. if (sphere) {
  242. draw_sphere(surface_tool, sphere->get_radius(), sphere->is_inside() ? inside_collision_color : collision_color);
  243. return surface_tool->commit();
  244. }
  245. SpringBoneCollisionCapsule3D *capsule = Object::cast_to<SpringBoneCollisionCapsule3D>(p_collision);
  246. if (capsule) {
  247. draw_capsule(surface_tool, capsule->get_radius(), capsule->get_height(), capsule->is_inside() ? inside_collision_color : collision_color);
  248. return surface_tool->commit();
  249. }
  250. SpringBoneCollisionPlane3D *plane = Object::cast_to<SpringBoneCollisionPlane3D>(p_collision);
  251. if (plane) {
  252. draw_plane(surface_tool, collision_color);
  253. return surface_tool->commit();
  254. }
  255. return surface_tool->commit();
  256. }
  257. void SpringBoneCollision3DGizmoPlugin::draw_sphere(Ref<SurfaceTool> &p_surface_tool, float p_radius, const Color &p_color) {
  258. static const Vector3 VECTOR3_RIGHT = Vector3(1, 0, 0);
  259. static const Vector3 VECTOR3_UP = Vector3(0, 1, 0);
  260. static const Vector3 VECTOR3_FORWARD = Vector3(0, 0, 1);
  261. static const int STEP = 16;
  262. static const float SPPI = Math::TAU / (float)STEP;
  263. for (int i = 1; i <= STEP; i++) {
  264. p_surface_tool->set_color(p_color);
  265. p_surface_tool->add_vertex((VECTOR3_UP * p_radius).rotated(VECTOR3_RIGHT, SPPI * ((i - 1) % STEP)));
  266. p_surface_tool->set_color(p_color);
  267. p_surface_tool->add_vertex((VECTOR3_UP * p_radius).rotated(VECTOR3_RIGHT, SPPI * (i % STEP)));
  268. }
  269. for (int i = 1; i <= STEP; i++) {
  270. p_surface_tool->set_color(p_color);
  271. p_surface_tool->add_vertex((VECTOR3_RIGHT * p_radius).rotated(VECTOR3_FORWARD, SPPI * ((i - 1) % STEP)));
  272. p_surface_tool->set_color(p_color);
  273. p_surface_tool->add_vertex((VECTOR3_RIGHT * p_radius).rotated(VECTOR3_FORWARD, SPPI * (i % STEP)));
  274. }
  275. for (int i = 1; i <= STEP; i++) {
  276. p_surface_tool->set_color(p_color);
  277. p_surface_tool->add_vertex((VECTOR3_FORWARD * p_radius).rotated(VECTOR3_UP, SPPI * ((i - 1) % STEP)));
  278. p_surface_tool->set_color(p_color);
  279. p_surface_tool->add_vertex((VECTOR3_FORWARD * p_radius).rotated(VECTOR3_UP, SPPI * (i % STEP)));
  280. }
  281. }
  282. void SpringBoneCollision3DGizmoPlugin::draw_capsule(Ref<SurfaceTool> &p_surface_tool, float p_radius, float p_height, const Color &p_color) {
  283. static const Vector3 VECTOR3_RIGHT = Vector3(1, 0, 0);
  284. static const Vector3 VECTOR3_UP = Vector3(0, 1, 0);
  285. static const Vector3 VECTOR3_FORWARD = Vector3(0, 0, 1);
  286. static const int STEP = 16;
  287. static const int HALF_STEP = 8;
  288. static const float SPPI = Math::TAU / (float)STEP;
  289. static const float HALF_PI = Math::PI * 0.5;
  290. Vector3 top = VECTOR3_UP * (p_height * 0.5 - p_radius);
  291. Vector3 bottom = -top;
  292. for (int i = 1; i <= STEP; i++) {
  293. p_surface_tool->set_color(p_color);
  294. p_surface_tool->add_vertex((i - 1 < HALF_STEP ? top : bottom) + (VECTOR3_UP * p_radius).rotated(VECTOR3_RIGHT, -HALF_PI + SPPI * ((i - 1) % STEP)));
  295. p_surface_tool->set_color(p_color);
  296. p_surface_tool->add_vertex((i - 1 < HALF_STEP ? top : bottom) + (VECTOR3_UP * p_radius).rotated(VECTOR3_RIGHT, -HALF_PI + SPPI * (i % STEP)));
  297. }
  298. for (int i = 1; i <= STEP; i++) {
  299. p_surface_tool->set_color(p_color);
  300. p_surface_tool->add_vertex((i - 1 < HALF_STEP ? top : bottom) + (VECTOR3_RIGHT * p_radius).rotated(VECTOR3_FORWARD, SPPI * ((i - 1) % STEP)));
  301. p_surface_tool->set_color(p_color);
  302. p_surface_tool->add_vertex((i - 1 < HALF_STEP ? top : bottom) + (VECTOR3_RIGHT * p_radius).rotated(VECTOR3_FORWARD, SPPI * (i % STEP)));
  303. }
  304. for (int i = 1; i <= STEP; i++) {
  305. p_surface_tool->set_color(p_color);
  306. p_surface_tool->add_vertex(top + (VECTOR3_FORWARD * p_radius).rotated(VECTOR3_UP, SPPI * ((i - 1) % STEP)));
  307. p_surface_tool->set_color(p_color);
  308. p_surface_tool->add_vertex(top + (VECTOR3_FORWARD * p_radius).rotated(VECTOR3_UP, SPPI * (i % STEP)));
  309. }
  310. for (int i = 1; i <= STEP; i++) {
  311. p_surface_tool->set_color(p_color);
  312. p_surface_tool->add_vertex(bottom + (VECTOR3_FORWARD * p_radius).rotated(VECTOR3_UP, SPPI * ((i - 1) % STEP)));
  313. p_surface_tool->set_color(p_color);
  314. p_surface_tool->add_vertex(bottom + (VECTOR3_FORWARD * p_radius).rotated(VECTOR3_UP, SPPI * (i % STEP)));
  315. }
  316. LocalVector<Vector3> directions;
  317. directions.resize(4);
  318. directions[0] = VECTOR3_RIGHT;
  319. directions[1] = -VECTOR3_RIGHT;
  320. directions[2] = VECTOR3_FORWARD;
  321. directions[3] = -VECTOR3_FORWARD;
  322. for (int i = 0; i < 4; i++) {
  323. Vector3 dir = directions[i] * p_radius;
  324. p_surface_tool->set_color(p_color);
  325. p_surface_tool->add_vertex(top + dir);
  326. p_surface_tool->add_vertex(bottom + dir);
  327. }
  328. }
  329. void SpringBoneCollision3DGizmoPlugin::draw_plane(Ref<SurfaceTool> &p_surface_tool, const Color &p_color) {
  330. static const Vector3 VECTOR3_UP = Vector3(0, 1, 0);
  331. static const float HALF_PI = Math::PI * 0.5;
  332. static const float ARROW_LENGTH = 0.3;
  333. static const float ARROW_HALF_WIDTH = 0.05;
  334. static const float ARROW_TOP_HALF_WIDTH = 0.1;
  335. static const float ARROW_TOP = 0.5;
  336. static const float RECT_SIZE = 1.0;
  337. static const int RECT_STEP_COUNT = 9;
  338. static const float RECT_HALF_SIZE = RECT_SIZE * 0.5;
  339. static const float RECT_STEP = RECT_SIZE / (float)RECT_STEP_COUNT;
  340. p_surface_tool->set_color(p_color);
  341. // Draw arrow of the normal.
  342. LocalVector<Vector3> arrow;
  343. arrow.resize(7);
  344. arrow[0] = Vector3(0, ARROW_TOP, 0);
  345. arrow[1] = Vector3(-ARROW_TOP_HALF_WIDTH, ARROW_LENGTH, 0);
  346. arrow[2] = Vector3(-ARROW_HALF_WIDTH, ARROW_LENGTH, 0);
  347. arrow[3] = Vector3(-ARROW_HALF_WIDTH, 0, 0);
  348. arrow[4] = Vector3(ARROW_HALF_WIDTH, 0, 0);
  349. arrow[5] = Vector3(ARROW_HALF_WIDTH, ARROW_LENGTH, 0);
  350. arrow[6] = Vector3(ARROW_TOP_HALF_WIDTH, ARROW_LENGTH, 0);
  351. for (int i = 0; i < 2; i++) {
  352. Basis ma(VECTOR3_UP, HALF_PI * i);
  353. for (uint32_t j = 0; j < arrow.size(); j++) {
  354. Vector3 v1 = arrow[j];
  355. Vector3 v2 = arrow[(j + 1) % arrow.size()];
  356. p_surface_tool->add_vertex(ma.xform(v1));
  357. p_surface_tool->add_vertex(ma.xform(v2));
  358. }
  359. }
  360. // Draw dashed line of the rect.
  361. for (int i = 0; i < 4; i++) {
  362. Basis ma(VECTOR3_UP, HALF_PI * i);
  363. for (int j = 0; j < RECT_STEP_COUNT; j++) {
  364. if (j % 2 == 1) {
  365. continue;
  366. }
  367. Vector3 v1 = Vector3(RECT_HALF_SIZE, 0, RECT_HALF_SIZE - RECT_STEP * j);
  368. Vector3 v2 = Vector3(RECT_HALF_SIZE, 0, RECT_HALF_SIZE - RECT_STEP * (j + 1));
  369. p_surface_tool->add_vertex(ma.xform(v1));
  370. p_surface_tool->add_vertex(ma.xform(v2));
  371. }
  372. }
  373. }