18 #ifndef GZ_RENDERING_BASE_BASEGIZMOVISUAL_HH_
19 #define GZ_RENDERING_BASE_BASEGIZMOVISUAL_HH_
23 #include <gz/common/MeshManager.hh>
24 #include <gz/utils/SuppressWarning.hh>
36 inline namespace GZ_RENDERING_VERSION_NAMESPACE {
54 public:
virtual void Init()
override;
95 GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
106 protected:
bool modeDirty =
false;
113 GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
154 this->CreateMaterials();
155 this->CreateTranslationVisual();
156 this->CreateRotationVisual();
157 this->CreateScaleVisual();
159 for (
auto v : this->visuals)
160 v.second->SetVisible(
false);
168 this->materials[AM_X],
false);
170 this->materials[AM_Y],
false);
172 this->materials[AM_Z],
false);
174 this->materials[AM_X],
false);
176 this->materials[AM_Y],
false);
178 this->materials[AM_Z],
false);
180 this->materials[AM_X],
false);
182 this->materials[AM_Y],
false);
184 this->materials[AM_Z],
false);
187 this->materials[AM_HANDLE],
false);
189 this->materials[AM_HANDLE],
false);
191 this->materials[AM_HANDLE],
false);
194 this->materials[AM_HANDLE],
false);
196 this->materials[AM_HANDLE],
false);
198 this->materials[AM_HANDLE],
false);
201 this->materials[AM_HANDLE],
false);
203 this->materials[AM_HANDLE],
false);
205 this->materials[AM_HANDLE],
false);
207 for (
auto v : this->visuals)
208 v.second->SetVisible(
false);
215 if (!this->modeDirty)
222 this->modeDirty =
false;
232 if (this->axis.X() > 0)
235 this->materials[AM_ACTIVE],
false);
237 this->materials[AM_HANDLE],
false);
239 if (this->axis.Y() > 0)
242 this->materials[AM_ACTIVE],
false);
244 this->materials[AM_HANDLE],
false);
246 if (this->axis.Z() > 0)
249 this->materials[AM_ACTIVE],
false);
251 this->materials[AM_HANDLE],
false);
260 if (this->axis.X() > 0)
263 this->materials[AM_ACTIVE],
false);
265 this->materials[AM_HANDLE],
false);
267 if (this->axis.Y() > 0)
270 this->materials[AM_ACTIVE],
false);
272 this->materials[AM_HANDLE],
false);
274 if (this->axis.Z() > 0)
277 this->materials[AM_ACTIVE],
false);
279 this->materials[AM_HANDLE],
false);
287 if (this->axis.X() > 0)
290 this->materials[AM_ACTIVE],
false);
292 this->materials[AM_HANDLE],
false);
294 if (this->axis.Y() > 0)
297 this->materials[AM_ACTIVE],
false);
299 this->materials[AM_HANDLE],
false);
301 if (this->axis.Z() > 0)
304 this->materials[AM_ACTIVE],
false);
306 this->materials[AM_HANDLE],
false);
310 this->modeDirty =
false;
317 if (this->mode == _mode)
323 this->modeDirty =
true;
337 if (this->axis == _axis)
341 this->modeDirty =
true;
355 for (
auto v : this->visuals)
359 if (v.second->Id() == _id || v.second->ChildById(_id))
377 xMat->SetDepthWriteEnabled(
false);
378 xMat->SetDepthCheckEnabled(
false);
379 yMat->SetDepthWriteEnabled(
false);
380 yMat->SetDepthCheckEnabled(
false);
381 zMat->SetDepthWriteEnabled(
false);
382 zMat->SetDepthCheckEnabled(
false);
383 activeMat->SetDepthWriteEnabled(
false);
384 activeMat->SetDepthCheckEnabled(
false);
390 oMat->SetAmbient(0.5, 0.5, 0.5);
391 oMat->SetDiffuse(0.5, 0.5, 0.5);
392 oMat->SetEmissive(0.5, 0.5, 0.5);
393 oMat->SetTransparency(0.5);
394 oMat->SetCastShadows(
false);
395 oMat->SetReceiveShadows(
false);
396 oMat->SetLightingEnabled(
false);
397 oMat->SetDepthWriteEnabled(
false);
398 oMat->SetDepthCheckEnabled(
false);
405 handleMat->SetAmbient(0.0, 0.0, 0.0);
406 handleMat->SetDiffuse(0.0, 0.0, 0.0);
407 handleMat->SetEmissive(0.0, 0.0, 0.0);
408 handleMat->SetTransparency(1.0);
409 handleMat->SetCastShadows(
false);
410 handleMat->SetReceiveShadows(
false);
411 handleMat->SetLightingEnabled(
false);
412 handleMat->SetDepthWriteEnabled(
false);
413 handleMat->SetDepthCheckEnabled(
false);
416 this->materials[AM_X] = xMat;
417 this->materials[AM_Y] = yMat;
418 this->materials[AM_Z] = zMat;
419 this->materials[AM_ACTIVE] = activeMat;
420 this->materials[AM_O] = oMat;
421 this->materials[AM_HANDLE] = handleMat;
432 transShaftXVis->AddGeometry(this->
Scene()->CreateCylinder());
433 transShaftXVis->SetOrigin(0, 0, 0.5);
434 transShaftXVis->SetLocalPosition(0, 0, 0.5);
435 transShaftXVis->SetLocalScale(0.02, 0.02, 0.45);
436 transXVis->AddChild(transShaftXVis);
439 transHeadXVis->AddGeometry(this->
Scene()->CreateCone());
440 transHeadXVis->SetOrigin(0, 0, -0.5);
441 transHeadXVis->SetLocalPosition(0, 0, 0.5);
442 transHeadXVis->SetLocalScale(0.07, 0.07, 0.2);
443 transXVis->AddChild(transHeadXVis);
445 transXVis->SetMaterial(this->materials[AM_X],
false);
446 transXVis->SetLocalRotation(0,
GZ_PI * 0.5, 0);
447 transVis->AddChild(transXVis);
452 transShaftYVis->AddGeometry(this->
Scene()->CreateCylinder());
453 transShaftYVis->SetOrigin(0, 0, 0.5);
454 transShaftYVis->SetLocalPosition(0, 0, 0.5);
455 transShaftYVis->SetLocalScale(0.02, 0.02, 0.45);
456 transYVis->AddChild(transShaftYVis);
459 transHeadYVis->AddGeometry(this->
Scene()->CreateCone());
460 transHeadYVis->SetOrigin(0, 0, -0.5);
461 transHeadYVis->SetLocalPosition(0, 0, 0.5);
462 transHeadYVis->SetLocalScale(0.07, 0.07, 0.2);
463 transYVis->AddChild(transHeadYVis);
465 transYVis->SetMaterial(this->materials[AM_Y],
false);
466 transYVis->SetLocalRotation(-
GZ_PI * 0.5, 0, 0);
467 transVis->AddChild(transYVis);
472 transShaftZVis->AddGeometry(this->
Scene()->CreateCylinder());
473 transShaftZVis->SetOrigin(0, 0, 0.5);
474 transShaftZVis->SetLocalPosition(0, 0, 0.5);
475 transShaftZVis->SetLocalScale(0.02, 0.02, 0.45);
476 transZVis->AddChild(transShaftZVis);
479 transHeadZVis->AddGeometry(this->
Scene()->CreateCone());
480 transHeadZVis->SetOrigin(0, 0, -0.5);
481 transHeadZVis->SetLocalPosition(0, 0, 0.5);
482 transHeadZVis->SetLocalScale(0.07, 0.07, 0.2);
483 transZVis->AddChild(transHeadZVis);
485 transZVis->SetMaterial(this->materials[AM_Z],
false);
486 transVis->AddChild(transZVis);
490 transOrigin->AddGeometry(this->
Scene()->CreateSphere());
491 transOrigin->SetLocalScale(0.05, 0.05, 0.05);
492 transOrigin->SetMaterial(this->materials[AM_O],
false);
493 transVis->AddChild(transOrigin);
504 transHandleXVis->AddGeometry(this->
Scene()->CreateCylinder());
505 transHandleXVis->SetLocalPosition(0, 0, 0.35);
506 transHandleXVis->SetLocalScale(0.11, 0.11, 0.7);
507 transHandleXVis->SetMaterial(this->materials[AM_HANDLE],
false);
508 transXVis->AddChild(transHandleXVis);
511 transHandleYVis->AddGeometry(this->
Scene()->CreateCylinder());
512 transHandleYVis->SetLocalPosition(0, 0, 0.35);
513 transHandleYVis->SetLocalScale(0.11, 0.11, 0.7);
514 transHandleYVis->SetMaterial(this->materials[AM_HANDLE],
false);
515 transYVis->AddChild(transHandleYVis);
518 transHandleZVis->AddGeometry(this->
Scene()->CreateCylinder());
519 transHandleZVis->SetLocalPosition(0, 0, 0.35);
520 transHandleZVis->SetLocalScale(0.11, 0.11, 0.7);
521 transHandleZVis->SetMaterial(this->materials[AM_HANDLE],
false);
522 transZVis->AddChild(transHandleZVis);
528 this->AddChild(transVis);
537 if (!meshMgr->
HasMesh(rotMeshName))
541 if (!meshMgr->
HasMesh(rotFullMeshName))
543 meshMgr->
CreateTube(rotFullMeshName, 1.0f, 1.02f, 0.02f, 1, 64,
547 std::string rotHandleMeshName =
"gizmo_rotate_handle";
548 if (!meshMgr->
HasMesh(rotHandleMeshName))
550 meshMgr->
CreateTube(rotHandleMeshName, 0.95f, 1.07f, 0.1f, 1, 64,
558 rotXVis->AddGeometry(this->
Scene()->CreateMesh(rotMeshName));
559 rotXVis->SetLocalRotation(0,
GZ_PI * 0.5, 0);
560 rotXVis->SetLocalScale(0.5, 0.5, 0.5);
561 rotXVis->SetMaterial(this->materials[AM_X],
false);
562 rotVis->AddChild(rotXVis);
566 rotYVis->AddGeometry(this->
Scene()->CreateMesh(rotMeshName));
567 rotYVis->SetLocalRotation(
GZ_PI * 0.5, 0, 0);
568 rotYVis->SetLocalScale(0.5, 0.5, 0.5);
569 rotYVis->SetMaterial(this->materials[AM_Y],
false);
570 rotVis->AddChild(rotYVis);
574 rotZVis->AddGeometry(this->
Scene()->CreateMesh(rotMeshName));
575 rotZVis->SetLocalScale(0.5, 0.5, 0.5);
576 rotZVis->SetMaterial(this->materials[AM_Z],
false);
577 rotVis->AddChild(rotZVis);
581 rotFullVis->AddGeometry(this->
Scene()->CreateMesh(rotFullMeshName));
582 rotFullVis->SetLocalScale(0.5, 0.5, 0.5);
583 rotFullVis->SetMaterial(this->materials[AM_O],
false);
584 rotVis->AddChild(rotFullVis);
595 rotHandleXVis->AddGeometry(this->
Scene()->CreateMesh(rotHandleMeshName));
596 rotHandleXVis->SetMaterial(this->materials[AM_HANDLE],
false);
597 rotXVis->AddChild(rotHandleXVis);
600 rotHandleYVis->AddGeometry(this->
Scene()->CreateMesh(rotHandleMeshName));
601 rotHandleYVis->SetMaterial(this->materials[AM_HANDLE],
false);
602 rotYVis->AddChild(rotHandleYVis);
605 rotHandleZVis->AddGeometry(this->
Scene()->CreateMesh(rotHandleMeshName));
606 rotHandleZVis->SetMaterial(this->materials[AM_HANDLE],
false);
607 rotZVis->AddChild(rotHandleZVis);
613 this->AddChild(rotVis);
625 scaleShaftXVis->AddGeometry(this->
Scene()->CreateCylinder());
626 scaleShaftXVis->SetOrigin(0, 0, 0.5);
627 scaleShaftXVis->SetLocalPosition(0, 0, 0.5);
628 scaleShaftXVis->SetLocalScale(0.02, 0.02, 0.5);
629 scaleXVis->AddChild(scaleShaftXVis);
632 scaleHeadXVis->AddGeometry(this->
Scene()->CreateBox());
633 scaleHeadXVis->SetOrigin(0, 0, -0.5);
634 scaleHeadXVis->SetLocalPosition(0, 0, 0.5);
635 scaleHeadXVis->SetLocalScale(0.07, 0.07, 0.07);
636 scaleXVis->AddChild(scaleHeadXVis);
638 scaleXVis->SetMaterial(this->materials[AM_X],
false);
639 scaleXVis->SetLocalRotation(0,
GZ_PI * 0.5, 0);
640 scaleVis->AddChild(scaleXVis);
645 scaleShaftYVis->AddGeometry(this->
Scene()->CreateCylinder());
646 scaleShaftYVis->SetOrigin(0, 0, 0.5);
647 scaleShaftYVis->SetLocalPosition(0, 0, 0.5);
648 scaleShaftYVis->SetLocalScale(0.02, 0.02, 0.5);
649 scaleYVis->AddChild(scaleShaftYVis);
652 scaleHeadYVis->AddGeometry(this->
Scene()->CreateBox());
653 scaleHeadYVis->SetOrigin(0, 0, -0.5);
654 scaleHeadYVis->SetLocalPosition(0, 0, 0.5);
655 scaleHeadYVis->SetLocalScale(0.07, 0.07, 0.07);
656 scaleYVis->AddChild(scaleHeadYVis);
658 scaleYVis->SetMaterial(this->materials[AM_Y],
false);
659 scaleYVis->SetLocalRotation(-
GZ_PI * 0.5, 0, 0);
660 scaleVis->AddChild(scaleYVis);
665 scaleShaftZVis->AddGeometry(this->
Scene()->CreateCylinder());
666 scaleShaftZVis->SetOrigin(0, 0, 0.5);
667 scaleShaftZVis->SetLocalPosition(0, 0, 0.5);
668 scaleShaftZVis->SetLocalScale(0.02, 0.02, 0.5);
669 scaleZVis->AddChild(scaleShaftZVis);
672 scaleHeadZVis->AddGeometry(this->
Scene()->CreateBox());
673 scaleHeadZVis->SetOrigin(0, 0, -0.5);
674 scaleHeadZVis->SetLocalPosition(0, 0, 0.5);
675 scaleHeadZVis->SetLocalScale(0.07, 0.07, 0.07);
676 scaleZVis->AddChild(scaleHeadZVis);
678 scaleZVis->SetMaterial(this->materials[AM_Z],
false);
679 scaleVis->AddChild(scaleZVis);
687 scaleHandleXVis->AddGeometry(this->
Scene()->CreateCylinder());
688 scaleHandleXVis->SetLocalPosition(0, 0, 0.285);
689 scaleHandleXVis->SetLocalScale(0.11, 0.11, 0.57);
690 scaleHandleXVis->SetMaterial(this->materials[AM_HANDLE],
false);
691 scaleXVis->AddChild(scaleHandleXVis);
694 scaleHandleYVis->AddGeometry(this->
Scene()->CreateCylinder());
695 scaleHandleYVis->SetLocalPosition(0, 0, 0.285);
696 scaleHandleYVis->SetLocalScale(0.11, 0.11, 0.57);
697 scaleHandleYVis->SetMaterial(this->materials[AM_HANDLE],
false);
698 scaleYVis->AddChild(scaleHandleYVis);
701 scaleHandleZVis->AddGeometry(this->
Scene()->CreateCylinder());
702 scaleHandleZVis->SetLocalPosition(0, 0, 0.285);
703 scaleHandleZVis->SetLocalScale(0.11, 0.11, 0.57);
704 scaleHandleZVis->SetMaterial(this->materials[AM_HANDLE],
false);
705 scaleZVis->AddChild(scaleHandleZVis);
711 this->AddChild(scaleVis);
718 auto it = this->visuals.find(_axis);
719 if (it != this->visuals.end())