Gazebo Rendering

API Reference

7.4.2
gz/rendering/base/BaseGizmoVisual.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef GZ_RENDERING_BASE_BASEGIZMOVISUAL_HH_
19 #define GZ_RENDERING_BASE_BASEGIZMOVISUAL_HH_
20 
21 #include <map>
22 #include <string>
23 #include <gz/common/MeshManager.hh>
24 #include <gz/utils/SuppressWarning.hh>
25 
29 #include "gz/rendering/Camera.hh"
31 
32 namespace gz
33 {
34  namespace rendering
35  {
36  inline namespace GZ_RENDERING_VERSION_NAMESPACE {
37  //
38  /* \class BaseGizmoVisual BaseGizmoVisuall.hh \
39  * gz/rendering/base/BaseGizmoVisual.hh
40  */
42  template <class T>
44  public virtual GizmoVisual,
45  public virtual T
46  {
48  protected: BaseGizmoVisual();
49 
51  public: virtual ~BaseGizmoVisual();
52 
53  // Documentation inherited
54  public: virtual void Init() override;
55 
56  // Documentation inherited
57  public: virtual void PreRender() override;
58 
59  // Documentation inherited
60  public: virtual void SetTransformMode(TransformMode _mode) override;
61 
62  // Documentation inherited
63  public: virtual TransformMode Mode() const override;
64 
65  // Documentation inherited
66  public: virtual void SetActiveAxis(const math::Vector3d &_axis) override;
67 
68  // Documentation inherited
69  public: virtual math::Vector3d ActiveAxis() const override;
70 
71  // Documentation inherited
72  public: virtual TransformAxis AxisById(unsigned int _id) const override;
73 
74  // Documentation inherited
75  public: virtual VisualPtr ChildByAxis(unsigned int _axis) const override;
76 
78  public: virtual void Reset();
79 
81  protected: void CreateMaterials();
82 
84  protected: void CreateTranslationVisual();
85 
87  protected: void CreateRotationVisual();
88 
90  protected: void CreateScaleVisual();
91 
94 
95  GZ_UTILS_WARN_IGNORE__DLL_INTERFACE_MISSING
98 
101 
103  protected: VisualPtr activeVis;
104 
106  protected: bool modeDirty = false;
107 
110 
113  GZ_UTILS_WARN_RESUME__DLL_INTERFACE_MISSING
114 
116  protected: enum AxisMaterial
117  {
129  AM_HANDLE
130  };
131 
133  private: friend class BaseScene;
134  };
135 
137  template <class T>
139  {
140  }
141 
143  template <class T>
145  {
146  }
147 
149  template <class T>
151  {
152  T::Init();
153 
154  this->CreateMaterials();
155  this->CreateTranslationVisual();
156  this->CreateRotationVisual();
157  this->CreateScaleVisual();
158 
159  for (auto v : this->visuals)
160  v.second->SetVisible(false);
161  }
162 
164  template <class T>
166  {
167  this->visuals[TransformAxis::TA_TRANSLATION_X]->SetMaterial(
168  this->materials[AM_X], false);
169  this->visuals[TransformAxis::TA_TRANSLATION_Y]->SetMaterial(
170  this->materials[AM_Y], false);
171  this->visuals[TransformAxis::TA_TRANSLATION_Z]->SetMaterial(
172  this->materials[AM_Z], false);
173  this->visuals[TransformAxis::TA_ROTATION_X]->SetMaterial(
174  this->materials[AM_X], false);
175  this->visuals[TransformAxis::TA_ROTATION_Y]->SetMaterial(
176  this->materials[AM_Y], false);
177  this->visuals[TransformAxis::TA_ROTATION_Z]->SetMaterial(
178  this->materials[AM_Z], false);
179  this->visuals[TransformAxis::TA_SCALE_X]->SetMaterial(
180  this->materials[AM_X], false);
181  this->visuals[TransformAxis::TA_SCALE_Y]->SetMaterial(
182  this->materials[AM_Y], false);
183  this->visuals[TransformAxis::TA_SCALE_Z]->SetMaterial(
184  this->materials[AM_Z], false);
185 
186  this->handles[TransformAxis::TA_TRANSLATION_X]->SetMaterial(
187  this->materials[AM_HANDLE], false);
188  this->handles[TransformAxis::TA_TRANSLATION_Y]->SetMaterial(
189  this->materials[AM_HANDLE], false);
190  this->handles[TransformAxis::TA_TRANSLATION_Z]->SetMaterial(
191  this->materials[AM_HANDLE], false);
192 
193  this->handles[TransformAxis::TA_ROTATION_X]->SetMaterial(
194  this->materials[AM_HANDLE], false);
195  this->handles[TransformAxis::TA_ROTATION_Y]->SetMaterial(
196  this->materials[AM_HANDLE], false);
197  this->handles[TransformAxis::TA_ROTATION_Z]->SetMaterial(
198  this->materials[AM_HANDLE], false);
199 
200  this->handles[TransformAxis::TA_SCALE_X]->SetMaterial(
201  this->materials[AM_HANDLE], false);
202  this->handles[TransformAxis::TA_SCALE_Y]->SetMaterial(
203  this->materials[AM_HANDLE], false);
204  this->handles[TransformAxis::TA_SCALE_Z]->SetMaterial(
205  this->materials[AM_HANDLE], false);
206 
207  for (auto v : this->visuals)
208  v.second->SetVisible(false);
209  }
210 
212  template <class T>
214  {
215  if (!this->modeDirty)
216  return;
217 
218  this->Reset();
219 
220  if (this->mode == TransformMode::TM_NONE)
221  {
222  this->modeDirty = false;
223  return;
224  }
225 
226  if (this->mode & TransformMode::TM_TRANSLATION)
227  {
228  this->visuals[TransformAxis::TA_TRANSLATION_X]->SetVisible(true);
229  this->visuals[TransformAxis::TA_TRANSLATION_Y]->SetVisible(true);
230  this->visuals[TransformAxis::TA_TRANSLATION_Z]->SetVisible(true);
231  this->visuals[TransformAxis::TA_TRANSLATION_Z << 1]->SetVisible(true);
232  if (this->axis.X() > 0)
233  {
234  this->visuals[TransformAxis::TA_TRANSLATION_X]->SetMaterial(
235  this->materials[AM_ACTIVE], false);
236  this->handles[TransformAxis::TA_TRANSLATION_X]->SetMaterial(
237  this->materials[AM_HANDLE], false);
238  }
239  if (this->axis.Y() > 0)
240  {
241  this->visuals[TransformAxis::TA_TRANSLATION_Y]->SetMaterial(
242  this->materials[AM_ACTIVE], false);
243  this->handles[TransformAxis::TA_TRANSLATION_Y]->SetMaterial(
244  this->materials[AM_HANDLE], false);
245  }
246  if (this->axis.Z() > 0)
247  {
248  this->visuals[TransformAxis::TA_TRANSLATION_Z]->SetMaterial(
249  this->materials[AM_ACTIVE], false);
250  this->handles[TransformAxis::TA_TRANSLATION_Z]->SetMaterial(
251  this->materials[AM_HANDLE], false);
252  }
253  }
254  else if (this->mode & TransformMode::TM_ROTATION)
255  {
256  this->visuals[TransformAxis::TA_ROTATION_X]->SetVisible(true);
257  this->visuals[TransformAxis::TA_ROTATION_Y]->SetVisible(true);
258  this->visuals[TransformAxis::TA_ROTATION_Z]->SetVisible(true);
259  this->visuals[TransformAxis::TA_ROTATION_Z << 1]->SetVisible(true);
260  if (this->axis.X() > 0)
261  {
262  this->visuals[TransformAxis::TA_ROTATION_X]->SetMaterial(
263  this->materials[AM_ACTIVE], false);
264  this->handles[TransformAxis::TA_ROTATION_X]->SetMaterial(
265  this->materials[AM_HANDLE], false);
266  }
267  if (this->axis.Y() > 0)
268  {
269  this->visuals[TransformAxis::TA_ROTATION_Y]->SetMaterial(
270  this->materials[AM_ACTIVE], false);
271  this->handles[TransformAxis::TA_ROTATION_Y]->SetMaterial(
272  this->materials[AM_HANDLE], false);
273  }
274  if (this->axis.Z() > 0)
275  {
276  this->visuals[TransformAxis::TA_ROTATION_Z]->SetMaterial(
277  this->materials[AM_ACTIVE], false);
278  this->handles[TransformAxis::TA_ROTATION_Z]->SetMaterial(
279  this->materials[AM_HANDLE], false);
280  }
281  }
282  else if (this->mode & TransformMode::TM_SCALE)
283  {
284  this->visuals[TransformAxis::TA_SCALE_X]->SetVisible(true);
285  this->visuals[TransformAxis::TA_SCALE_Y]->SetVisible(true);
286  this->visuals[TransformAxis::TA_SCALE_Z]->SetVisible(true);
287  if (this->axis.X() > 0)
288  {
289  this->visuals[TransformAxis::TA_SCALE_X]->SetMaterial(
290  this->materials[AM_ACTIVE], false);
291  this->handles[TransformAxis::TA_SCALE_X]->SetMaterial(
292  this->materials[AM_HANDLE], false);
293  }
294  if (this->axis.Y() > 0)
295  {
296  this->visuals[TransformAxis::TA_SCALE_Y]->SetMaterial(
297  this->materials[AM_ACTIVE], false);
298  this->handles[TransformAxis::TA_SCALE_Y]->SetMaterial(
299  this->materials[AM_HANDLE], false);
300  }
301  if (this->axis.Z() > 0)
302  {
303  this->visuals[TransformAxis::TA_SCALE_Z]->SetMaterial(
304  this->materials[AM_ACTIVE], false);
305  this->handles[TransformAxis::TA_SCALE_Z]->SetMaterial(
306  this->materials[AM_HANDLE], false);
307  }
308  }
309 
310  this->modeDirty = false;
311  }
312 
314  template <class T>
316  {
317  if (this->mode == _mode)
318  return;
319 
320  this->mode = _mode;
321  // clear active axis when mode changes
322  this->axis = math::Vector3d::Zero;
323  this->modeDirty = true;
324  }
325 
327  template <class T>
329  {
330  return this->mode;
331  }
332 
334  template <class T>
336  {
337  if (this->axis == _axis)
338  return;
339 
340  this->axis = _axis;
341  this->modeDirty = true;
342  }
343 
345  template <class T>
347  {
348  return this->axis;
349  }
350 
352  template <class T>
354  {
355  for (auto v : this->visuals)
356  {
357  // each axis visual has a child handle so also check children for
358  // matching id
359  if (v.second->Id() == _id || v.second->ChildById(_id))
360  return static_cast<TransformAxis>(v.first);
361  }
362  return TransformAxis::TA_NONE;
363  }
364 
365 
367  template <class T>
369  {
370  MaterialPtr xMat = this->Scene()->Material("Default/TransRed")->Clone();
371  MaterialPtr yMat = this->Scene()->Material("Default/TransGreen")->Clone();
372  MaterialPtr zMat = this->Scene()->Material("Default/TransBlue")->Clone();
373  MaterialPtr activeMat =
374  this->Scene()->Material("Default/TransYellow")->Clone();
375 
376  // disable depth checking and writing, make them overlays
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);
385 
386  MaterialPtr oMat = this->Scene()->Material("GizmoGray");
387  if (!oMat)
388  {
389  oMat = this->Scene()->CreateMaterial("GizmoGray");
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);
399  }
400 
401  MaterialPtr handleMat = this->Scene()->Material("GizmoHandle");
402  if (!handleMat)
403  {
404  handleMat = this->Scene()->CreateMaterial("GizmoHandle");
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);
414  }
415 
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;
422  }
424  template <class T>
426  {
427  VisualPtr transVis = this->Scene()->CreateVisual();
428 
429  // trans x
430  VisualPtr transXVis = this->Scene()->CreateVisual();
431  VisualPtr transShaftXVis = this->Scene()->CreateVisual();
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);
437 
438  VisualPtr transHeadXVis = this->Scene()->CreateVisual();
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);
444 
445  transXVis->SetMaterial(this->materials[AM_X], false);
446  transXVis->SetLocalRotation(0, GZ_PI * 0.5, 0);
447  transVis->AddChild(transXVis);
448 
449  // trans y
450  VisualPtr transYVis = this->Scene()->CreateVisual();
451  VisualPtr transShaftYVis = this->Scene()->CreateVisual();
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);
457 
458  VisualPtr transHeadYVis = this->Scene()->CreateVisual();
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);
464 
465  transYVis->SetMaterial(this->materials[AM_Y], false);
466  transYVis->SetLocalRotation(-GZ_PI * 0.5, 0, 0);
467  transVis->AddChild(transYVis);
468 
469  // trans z
470  VisualPtr transZVis = this->Scene()->CreateVisual();
471  VisualPtr transShaftZVis = this->Scene()->CreateVisual();
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);
477 
478  VisualPtr transHeadZVis = this->Scene()->CreateVisual();
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);
484 
485  transZVis->SetMaterial(this->materials[AM_Z], false);
486  transVis->AddChild(transZVis);
487 
488  // trans origin
489  VisualPtr transOrigin = this->Scene()->CreateVisual();
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);
494 
495  this->visuals[TransformAxis::TA_TRANSLATION_X] = transXVis;
496  this->visuals[TransformAxis::TA_TRANSLATION_Y] = transYVis;
497  this->visuals[TransformAxis::TA_TRANSLATION_Z] = transZVis;
498  // Store the translation origin visual in this->visuals using a key
499  // that's not already occupied by the TransformAxis enum
500  this->visuals[TransformAxis::TA_TRANSLATION_Z << 1] = transOrigin;
501 
502  // translation handles
503  VisualPtr transHandleXVis = this->Scene()->CreateVisual();
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);
509 
510  VisualPtr transHandleYVis = this->Scene()->CreateVisual();
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);
516 
517  VisualPtr transHandleZVis = this->Scene()->CreateVisual();
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);
523 
524  this->handles[TransformAxis::TA_TRANSLATION_X] = transHandleXVis;
525  this->handles[TransformAxis::TA_TRANSLATION_Y] = transHandleYVis;
526  this->handles[TransformAxis::TA_TRANSLATION_Z] = transHandleZVis;
527 
528  this->AddChild(transVis);
529  }
530 
532  template <class T>
534  {
536  std::string rotMeshName = "gizmo_rotate";
537  if (!meshMgr->HasMesh(rotMeshName))
538  meshMgr->CreateTube(rotMeshName, 1.0f, 1.02f, 0.02f, 1, 64, GZ_PI);
539 
540  std::string rotFullMeshName = "gizmo_rotate_full";
541  if (!meshMgr->HasMesh(rotFullMeshName))
542  {
543  meshMgr->CreateTube(rotFullMeshName, 1.0f, 1.02f, 0.02f, 1, 64,
544  2 * GZ_PI);
545  }
546 
547  std::string rotHandleMeshName = "gizmo_rotate_handle";
548  if (!meshMgr->HasMesh(rotHandleMeshName))
549  {
550  meshMgr->CreateTube(rotHandleMeshName, 0.95f, 1.07f, 0.1f, 1, 64,
551  GZ_PI);
552  }
553 
554  VisualPtr rotVis = this->Scene()->CreateVisual();
555 
556  // rotation x
557  VisualPtr rotXVis = this->Scene()->CreateVisual();
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);
563 
564  // rotation y
565  VisualPtr rotYVis = this->Scene()->CreateVisual();
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);
571 
572  // rotation z
573  VisualPtr rotZVis = this->Scene()->CreateVisual();
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);
578 
579  // rotation origin
580  VisualPtr rotFullVis = this->Scene()->CreateVisual();
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);
585 
586  this->visuals[TransformAxis::TA_ROTATION_X] = rotXVis;
587  this->visuals[TransformAxis::TA_ROTATION_Y] = rotYVis;
588  this->visuals[TransformAxis::TA_ROTATION_Z] = rotZVis;
589  // Store the full rotation visual in this->visuals using a key
590  // that's not already occupied by the TransformAxis enum
591  this->visuals[TransformAxis::TA_ROTATION_Z << 1] = rotFullVis;
592 
593  // rotation handles
594  VisualPtr rotHandleXVis = this->Scene()->CreateVisual();
595  rotHandleXVis->AddGeometry(this->Scene()->CreateMesh(rotHandleMeshName));
596  rotHandleXVis->SetMaterial(this->materials[AM_HANDLE], false);
597  rotXVis->AddChild(rotHandleXVis);
598 
599  VisualPtr rotHandleYVis = this->Scene()->CreateVisual();
600  rotHandleYVis->AddGeometry(this->Scene()->CreateMesh(rotHandleMeshName));
601  rotHandleYVis->SetMaterial(this->materials[AM_HANDLE], false);
602  rotYVis->AddChild(rotHandleYVis);
603 
604  VisualPtr rotHandleZVis = this->Scene()->CreateVisual();
605  rotHandleZVis->AddGeometry(this->Scene()->CreateMesh(rotHandleMeshName));
606  rotHandleZVis->SetMaterial(this->materials[AM_HANDLE], false);
607  rotZVis->AddChild(rotHandleZVis);
608 
609  this->handles[TransformAxis::TA_ROTATION_X] = rotHandleXVis;
610  this->handles[TransformAxis::TA_ROTATION_Y] = rotHandleYVis;
611  this->handles[TransformAxis::TA_ROTATION_Z] = rotHandleZVis;
612 
613  this->AddChild(rotVis);
614  }
615 
617  template <class T>
619  {
620  VisualPtr scaleVis = this->Scene()->CreateVisual();
621 
622  // scale x
623  VisualPtr scaleXVis = this->Scene()->CreateVisual();
624  VisualPtr scaleShaftXVis = this->Scene()->CreateVisual();
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);
630 
631  VisualPtr scaleHeadXVis = this->Scene()->CreateVisual();
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);
637 
638  scaleXVis->SetMaterial(this->materials[AM_X], false);
639  scaleXVis->SetLocalRotation(0, GZ_PI * 0.5, 0);
640  scaleVis->AddChild(scaleXVis);
641 
642  // scale y
643  VisualPtr scaleYVis = this->Scene()->CreateVisual();
644  VisualPtr scaleShaftYVis = this->Scene()->CreateVisual();
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);
650 
651  VisualPtr scaleHeadYVis = this->Scene()->CreateVisual();
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);
657 
658  scaleYVis->SetMaterial(this->materials[AM_Y], false);
659  scaleYVis->SetLocalRotation(-GZ_PI * 0.5, 0, 0);
660  scaleVis->AddChild(scaleYVis);
661 
662  // scale z
663  VisualPtr scaleZVis = this->Scene()->CreateVisual();
664  VisualPtr scaleShaftZVis = this->Scene()->CreateVisual();
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);
670 
671  VisualPtr scaleHeadZVis = this->Scene()->CreateVisual();
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);
677 
678  scaleZVis->SetMaterial(this->materials[AM_Z], false);
679  scaleVis->AddChild(scaleZVis);
680 
681  this->visuals[TransformAxis::TA_SCALE_X] = scaleXVis;
682  this->visuals[TransformAxis::TA_SCALE_Y] = scaleYVis;
683  this->visuals[TransformAxis::TA_SCALE_Z] = scaleZVis;
684 
685  // scale handles
686  VisualPtr scaleHandleXVis = this->Scene()->CreateVisual();
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);
692 
693  VisualPtr scaleHandleYVis = this->Scene()->CreateVisual();
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);
699 
700  VisualPtr scaleHandleZVis = this->Scene()->CreateVisual();
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);
706 
707  this->handles[TransformAxis::TA_SCALE_X] = scaleHandleXVis;
708  this->handles[TransformAxis::TA_SCALE_Y] = scaleHandleYVis;
709  this->handles[TransformAxis::TA_SCALE_Z] = scaleHandleZVis;
710 
711  this->AddChild(scaleVis);
712  }
713 
715  template <class T>
716  VisualPtr BaseGizmoVisual<T>::ChildByAxis(unsigned int _axis) const
717  {
718  auto it = this->visuals.find(_axis);
719  if (it != this->visuals.end())
720  return it->second;
721 
722  return VisualPtr();
723  }
724  }
725  }
726 }
727 #endif