position_3d.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*************************************************************************/
  2. /* position_3d.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  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 "position_3d.h"
  31. #include "scene/resources/mesh.h"
  32. RES Position3D::_get_gizmo_geometry() const {
  33. Ref<Mesh> mesh = memnew(Mesh);
  34. DVector<Vector3> cursor_points;
  35. DVector<Color> cursor_colors;
  36. float cs = 0.25;
  37. cursor_points.push_back(Vector3(+cs, 0, 0));
  38. cursor_points.push_back(Vector3(-cs, 0, 0));
  39. cursor_points.push_back(Vector3(0, +cs, 0));
  40. cursor_points.push_back(Vector3(0, -cs, 0));
  41. cursor_points.push_back(Vector3(0, 0, +cs));
  42. cursor_points.push_back(Vector3(0, 0, -cs));
  43. cursor_colors.push_back(Color(1, 0.5, 0.5, 1));
  44. cursor_colors.push_back(Color(1, 0.5, 0.5, 1));
  45. cursor_colors.push_back(Color(0.5, 1, 0.5, 1));
  46. cursor_colors.push_back(Color(0.5, 1, 0.5, 1));
  47. cursor_colors.push_back(Color(0.5, 0.5, 1, 1));
  48. cursor_colors.push_back(Color(0.5, 0.5, 1, 1));
  49. Ref<FixedMaterial> mat = memnew(FixedMaterial);
  50. mat->set_flag(Material::FLAG_UNSHADED, true);
  51. mat->set_line_width(3);
  52. Array d;
  53. d[Mesh::ARRAY_VERTEX] = cursor_points;
  54. d[Mesh::ARRAY_COLOR] = cursor_colors;
  55. mesh->add_surface(Mesh::PRIMITIVE_LINES, d);
  56. mesh->surface_set_material(0, mat);
  57. return mesh;
  58. }
  59. Position3D::Position3D() {
  60. }