Ignition Rendering

API Reference

4.1.0
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 IGNITION_RENDERING_BASE_BASEGIZMOVISUAL_HH_
19 #define IGNITION_RENDERING_BASE_BASEGIZMOVISUAL_HH_
20 
21 #include <map>
22 #include <string>
24 
30 
31 namespace ignition
32 {
33  namespace rendering
34  {
35  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
36  //
37  /* \class BaseGizmoVisual BaseGizmoVisuall.hh \
38  * ignition/rendering/base/BaseGizmoVisual.hh
39  */
41  template <class T>
43  public virtual GizmoVisual,
44  public virtual T
45  {
47  protected: BaseGizmoVisual();
48 
50  public: virtual ~BaseGizmoVisual();
51 
52  // Documentation inherited
53  public: virtual void Init() override;
54 
55  // Documentation inherited
56  public: virtual void PreRender() override;
57 
58  // Documentation inherited
59  public: virtual void SetTransformMode(TransformMode _mode) override;
60 
61  // Documentation inherited
62  public: virtual TransformMode Mode() const override;
63 
64  // Documentation inherited
65  public: virtual void SetActiveAxis(const math::Vector3d &_axis) override;
66 
67  // Documentation inherited
68  public: virtual math::Vector3d ActiveAxis() const override;
69 
70  // Documentation inherited
71  public: virtual TransformAxis AxisById(unsigned int _id) const override;
72 
73  // Documentation inherited
74  public: virtual VisualPtr ChildByAxis(unsigned int _axis) const override;
75 
77  public: virtual void Reset();
78 
80  protected: void CreateMaterials();
81 
83  protected: void CreateTranslationVisual();
84 
86  protected: void CreateRotationVisual();
87 
90  protected: void CreateScaleVisual();
91 
94 
97 
100 
102  protected: VisualPtr activeVis;
103 
105  protected: bool modeDirty = false;
106 
109 
112 
114  protected: enum AxisMaterial
115  {
127  AM_HANDLE
128  };
129 
131  private: friend class BaseScene;
132  };
133 
135  template <class T>
137  {
138  }
139 
141  template <class T>
143  {
144  }
145 
147  template <class T>
149  {
150  T::Init();
151 
152  this->CreateMaterials();
153  this->CreateTranslationVisual();
154  this->CreateRotationVisual();
155  this->CreateScaleVisual();
156 
157  for (auto v : this->visuals)
158  v.second->SetVisible(false);
159  }
160 
162  template <class T>
164  {
165  this->visuals[TransformAxis::TA_TRANSLATION_X]->SetMaterial(
166  this->materials[AM_X], false);
167  this->visuals[TransformAxis::TA_TRANSLATION_Y]->SetMaterial(
168  this->materials[AM_Y], false);
169  this->visuals[TransformAxis::TA_TRANSLATION_Z]->SetMaterial(
170  this->materials[AM_Z], false);
171  this->visuals[TransformAxis::TA_ROTATION_X]->SetMaterial(
172  this->materials[AM_X], false);
173  this->visuals[TransformAxis::TA_ROTATION_Y]->SetMaterial(
174  this->materials[AM_Y], false);
175  this->visuals[TransformAxis::TA_ROTATION_Z]->SetMaterial(
176  this->materials[AM_Z], false);
177  this->visuals[TransformAxis::TA_SCALE_X]->SetMaterial(
178  this->materials[AM_X], false);
179  this->visuals[TransformAxis::TA_SCALE_Y]->SetMaterial(
180  this->materials[AM_Y], false);
181  this->visuals[TransformAxis::TA_SCALE_Z]->SetMaterial(
182  this->materials[AM_Z], false);
183 
184  this->handles[TransformAxis::TA_TRANSLATION_X]->SetMaterial(
185  this->materials[AM_HANDLE], false);
186  this->handles[TransformAxis::TA_TRANSLATION_Y]->SetMaterial(
187  this->materials[AM_HANDLE], false);
188  this->handles[TransformAxis::TA_TRANSLATION_Z]->SetMaterial(
189  this->materials[AM_HANDLE], false);
190 
191  this->handles[TransformAxis::TA_ROTATION_X]->SetMaterial(
192  this->materials[AM_HANDLE], false);
193  this->handles[TransformAxis::TA_ROTATION_Y]->SetMaterial(
194  this->materials[AM_HANDLE], false);
195  this->handles[TransformAxis::TA_ROTATION_Z]->SetMaterial(
196  this->materials[AM_HANDLE], false);
197 
198  this->handles[TransformAxis::TA_SCALE_X]->SetMaterial(
199  this->materials[AM_HANDLE], false);
200  this->handles[TransformAxis::TA_SCALE_Y]->SetMaterial(
201  this->materials[AM_HANDLE], false);
202  this->handles[TransformAxis::TA_SCALE_Z]->SetMaterial(
203  this->materials[AM_HANDLE], false);
204 
205  for (auto v : this->visuals)
206  v.second->SetVisible(false);
207  }
208 
210  template <class T>
212  {
213  if (!this->modeDirty)
214  return;
215 
216  this->Reset();
217 
218  if (this->mode == TransformMode::TM_NONE)
219  {
220  this->modeDirty = false;
221  return;
222  }
223 
224  if (this->mode & TransformMode::TM_TRANSLATION)
225  {
226  this->visuals[TransformAxis::TA_TRANSLATION_X]->SetVisible(true);
227  this->visuals[TransformAxis::TA_TRANSLATION_Y]->SetVisible(true);
228  this->visuals[TransformAxis::TA_TRANSLATION_Z]->SetVisible(true);
229  this->visuals[TransformAxis::TA_TRANSLATION_Z << 1]->SetVisible(true);
230  if (this->axis.X() > 0)
231  {
232  this->visuals[TransformAxis::TA_TRANSLATION_X]->SetMaterial(
233  this->materials[AM_ACTIVE], false);
234  this->handles[TransformAxis::TA_TRANSLATION_X]->SetMaterial(
235  this->materials[AM_HANDLE], false);
236  }
237  if (this->axis.Y() > 0)
238  {
239  this->visuals[TransformAxis::TA_TRANSLATION_Y]->SetMaterial(
240  this->materials[AM_ACTIVE], false);
241  this->handles[TransformAxis::TA_TRANSLATION_Y]->SetMaterial(
242  this->materials[AM_HANDLE], false);
243  }
244  if (this->axis.Z() > 0)
245  {
246  this->visuals[TransformAxis::TA_TRANSLATION_Z]->SetMaterial(
247  this->materials[AM_ACTIVE], false);
248  this->handles[TransformAxis::TA_TRANSLATION_Z]->SetMaterial(
249  this->materials[AM_HANDLE], false);
250  }
251  }
252  else if (this->mode & TransformMode::TM_ROTATION)
253  {
254  this->visuals[TransformAxis::TA_ROTATION_X]->SetVisible(true);
255  this->visuals[TransformAxis::TA_ROTATION_Y]->SetVisible(true);
256  this->visuals[TransformAxis::TA_ROTATION_Z]->SetVisible(true);
257  this->visuals[TransformAxis::TA_ROTATION_Z << 1]->SetVisible(true);
258  if (this->axis.X() > 0)
259  {
260  this->visuals[TransformAxis::TA_ROTATION_X]->SetMaterial(
261  this->materials[AM_ACTIVE], false);
262  this->handles[TransformAxis::TA_ROTATION_X]->SetMaterial(
263  this->materials[AM_HANDLE], false);
264  }
265  if (this->axis.Y() > 0)
266  {
267  this->visuals[TransformAxis::TA_ROTATION_Y]->SetMaterial(
268  this->materials[AM_ACTIVE], false);
269  this->handles[TransformAxis::TA_ROTATION_Y]->SetMaterial(
270  this->materials[AM_HANDLE], false);
271  }
272  if (this->axis.Z() > 0)
273  {
274  this->visuals[TransformAxis::TA_ROTATION_Z]->SetMaterial(
275  this->materials[AM_ACTIVE], false);
276  this->handles[TransformAxis::TA_ROTATION_Z]->SetMaterial(
277  this->materials[AM_HANDLE], false);
278  }
279  }
280  else if (this->mode & TransformMode::TM_SCALE)
281  {
282  this->visuals[TransformAxis::TA_SCALE_X]->SetVisible(true);
283  this->visuals[TransformAxis::TA_SCALE_Y]->SetVisible(true);
284  this->visuals[TransformAxis::TA_SCALE_Z]->SetVisible(true);
285  if (this->axis.X() > 0)
286  {
287  this->visuals[TransformAxis::TA_SCALE_X]->SetMaterial(
288  this->materials[AM_ACTIVE], false);
289  this->handles[TransformAxis::TA_SCALE_X]->SetMaterial(
290  this->materials[AM_HANDLE], false);
291  }
292  if (this->axis.Y() > 0)
293  {
294  this->visuals[TransformAxis::TA_SCALE_Y]->SetMaterial(
295  this->materials[AM_ACTIVE], false);
296  this->handles[TransformAxis::TA_SCALE_Y]->SetMaterial(
297  this->materials[AM_HANDLE], false);
298  }
299  if (this->axis.Z() > 0)
300  {
301  this->visuals[TransformAxis::TA_SCALE_Z]->SetMaterial(
302  this->materials[AM_ACTIVE], false);
303  this->handles[TransformAxis::TA_SCALE_Z]->SetMaterial(
304  this->materials[AM_HANDLE], false);
305  }
306  }
307 
308  this->modeDirty = false;
309  }
310 
312  template <class T>
314  {
315  if (this->mode == _mode)
316  return;
317 
318  this->mode = _mode;
319  // clear active axis when mode changes
320  this->axis = math::Vector3d::Zero;
321  this->modeDirty = true;
322  }
323 
325  template <class T>
327  {
328  return this->mode;
329  }
330 
332  template <class T>
334  {
335  if (this->axis == _axis)
336  return;
337 
338  this->axis = _axis;
339  this->modeDirty = true;
340  }
341 
343  template <class T>
345  {
346  return this->axis;
347  }
348 
350  template <class T>
352  {
353  for (auto v : this->visuals)
354  {
355  // each axis visual has a child handle so also check children for
356  // matching id
357  if (v.second->Id() == _id || v.second->ChildById(_id))
358  return static_cast<TransformAxis>(v.first);
359  }
360  return TransformAxis::TA_NONE;
361  }
362 
363 
365  template <class T>
367  {
368  MaterialPtr xMat = this->Scene()->Material("Default/TransRed")->Clone();
369  MaterialPtr yMat = this->Scene()->Material("Default/TransGreen")->Clone();
370  MaterialPtr zMat = this->Scene()->Material("Default/TransBlue")->Clone();
371  MaterialPtr activeMat =
372  this->Scene()->Material("Default/TransYellow")->Clone();
373 
374  // disable depth checking and writing, make them overlays
375  xMat->SetDepthWriteEnabled(false);
376  xMat->SetDepthCheckEnabled(false);
377  yMat->SetDepthWriteEnabled(false);
378  yMat->SetDepthCheckEnabled(false);
379  zMat->SetDepthWriteEnabled(false);
380  zMat->SetDepthCheckEnabled(false);
381  activeMat->SetDepthWriteEnabled(false);
382  activeMat->SetDepthCheckEnabled(false);
383 
384  MaterialPtr oMat = this->Scene()->Material("GizmoGray");
385  if (!oMat)
386  {
387  oMat = this->Scene()->CreateMaterial("GizmoGray");
388  oMat->SetAmbient(0.5, 0.5, 0.5);
389  oMat->SetDiffuse(0.5, 0.5, 0.5);
390  oMat->SetEmissive(0.5, 0.5, 0.5);
391  oMat->SetTransparency(0.5);
392  oMat->SetCastShadows(false);
393  oMat->SetReceiveShadows(false);
394  oMat->SetLightingEnabled(false);
395  oMat->SetDepthWriteEnabled(false);
396  oMat->SetDepthCheckEnabled(false);
397  }
398 
399  MaterialPtr handleMat = this->Scene()->Material("GizmoHandle");
400  if (!handleMat)
401  {
402  handleMat = this->Scene()->CreateMaterial("GizmoHandle");
403  handleMat->SetAmbient(0.0, 0.0, 0.0);
404  handleMat->SetDiffuse(0.0, 0.0, 0.0);
405  handleMat->SetEmissive(0.0, 0.0, 0.0);
406  handleMat->SetTransparency(1.0);
407  handleMat->SetCastShadows(false);
408  handleMat->SetReceiveShadows(false);
409  handleMat->SetLightingEnabled(false);
410  handleMat->SetDepthWriteEnabled(false);
411  handleMat->SetDepthCheckEnabled(false);
412  }
413 
414  this->materials[AM_X] = xMat;
415  this->materials[AM_Y] = yMat;
416  this->materials[AM_Z] = zMat;
417  this->materials[AM_ACTIVE] = activeMat;
418  this->materials[AM_O] = oMat;
419  this->materials[AM_HANDLE] = handleMat;
420  }
422  template <class T>
424  {
425  VisualPtr transVis = this->Scene()->CreateVisual();
426 
427  // trans x
428  VisualPtr transXVis = this->Scene()->CreateVisual();
429  VisualPtr transShaftXVis = this->Scene()->CreateVisual();
430  transShaftXVis->AddGeometry(this->Scene()->CreateCylinder());
431  transShaftXVis->SetOrigin(0, 0, 0.5);
432  transShaftXVis->SetLocalPosition(0, 0, 0.5);
433  transShaftXVis->SetLocalScale(0.02, 0.02, 0.45);
434  transXVis->AddChild(transShaftXVis);
435 
436  VisualPtr transHeadXVis = this->Scene()->CreateVisual();
437  transHeadXVis->AddGeometry(this->Scene()->CreateCone());
438  transHeadXVis->SetOrigin(0, 0, -0.5);
439  transHeadXVis->SetLocalPosition(0, 0, 0.5);
440  transHeadXVis->SetLocalScale(0.07, 0.07, 0.2);
441  transXVis->AddChild(transHeadXVis);
442 
443  transXVis->SetMaterial(this->materials[AM_X], false);
444  transXVis->SetLocalRotation(0, IGN_PI * 0.5, 0);
445  transVis->AddChild(transXVis);
446 
447  // trans y
448  VisualPtr transYVis = this->Scene()->CreateVisual();
449  VisualPtr transShaftYVis = this->Scene()->CreateVisual();
450  transShaftYVis->AddGeometry(this->Scene()->CreateCylinder());
451  transShaftYVis->SetOrigin(0, 0, 0.5);
452  transShaftYVis->SetLocalPosition(0, 0, 0.5);
453  transShaftYVis->SetLocalScale(0.02, 0.02, 0.45);
454  transYVis->AddChild(transShaftYVis);
455 
456  VisualPtr transHeadYVis = this->Scene()->CreateVisual();
457  transHeadYVis->AddGeometry(this->Scene()->CreateCone());
458  transHeadYVis->SetOrigin(0, 0, -0.5);
459  transHeadYVis->SetLocalPosition(0, 0, 0.5);
460  transHeadYVis->SetLocalScale(0.07, 0.07, 0.2);
461  transYVis->AddChild(transHeadYVis);
462 
463  transYVis->SetMaterial(this->materials[AM_Y], false);
464  transYVis->SetLocalRotation(-IGN_PI * 0.5, 0, 0);
465  transVis->AddChild(transYVis);
466 
467  // trans z
468  VisualPtr transZVis = this->Scene()->CreateVisual();
469  VisualPtr transShaftZVis = this->Scene()->CreateVisual();
470  transShaftZVis->AddGeometry(this->Scene()->CreateCylinder());
471  transShaftZVis->SetOrigin(0, 0, 0.5);
472  transShaftZVis->SetLocalPosition(0, 0, 0.5);
473  transShaftZVis->SetLocalScale(0.02, 0.02, 0.45);
474  transZVis->AddChild(transShaftZVis);
475 
476  VisualPtr transHeadZVis = this->Scene()->CreateVisual();
477  transHeadZVis->AddGeometry(this->Scene()->CreateCone());
478  transHeadZVis->SetOrigin(0, 0, -0.5);
479  transHeadZVis->SetLocalPosition(0, 0, 0.5);
480  transHeadZVis->SetLocalScale(0.07, 0.07, 0.2);
481  transZVis->AddChild(transHeadZVis);
482 
483  transZVis->SetMaterial(this->materials[AM_Z], false);
484  transVis->AddChild(transZVis);
485 
486  // trans origin
487  VisualPtr transOrigin = this->Scene()->CreateVisual();
488  transOrigin->AddGeometry(this->Scene()->CreateSphere());
489  transOrigin->SetLocalScale(0.05, 0.05, 0.05);
490  transOrigin->SetMaterial(this->materials[AM_O], false);
491  transVis->AddChild(transOrigin);
492 
493  this->visuals[TransformAxis::TA_TRANSLATION_X] = transXVis;
494  this->visuals[TransformAxis::TA_TRANSLATION_Y] = transYVis;
495  this->visuals[TransformAxis::TA_TRANSLATION_Z] = transZVis;
496  this->visuals[TransformAxis::TA_TRANSLATION_Z << 1] = transOrigin;
497 
498  // translation handles
499  VisualPtr transHandleXVis = this->Scene()->CreateVisual();
500  transHandleXVis->AddGeometry(this->Scene()->CreateCylinder());
501  transHandleXVis->SetLocalPosition(0, 0, 0.35);
502  transHandleXVis->SetLocalScale(0.11, 0.11, 0.7);
503  transHandleXVis->SetMaterial(this->materials[AM_HANDLE], false);
504  transXVis->AddChild(transHandleXVis);
505 
506  VisualPtr transHandleYVis = this->Scene()->CreateVisual();
507  transHandleYVis->AddGeometry(this->Scene()->CreateCylinder());
508  transHandleYVis->SetLocalPosition(0, 0, 0.35);
509  transHandleYVis->SetLocalScale(0.11, 0.11, 0.7);
510  transHandleYVis->SetMaterial(this->materials[AM_HANDLE], false);
511  transYVis->AddChild(transHandleYVis);
512 
513  VisualPtr transHandleZVis = this->Scene()->CreateVisual();
514  transHandleZVis->AddGeometry(this->Scene()->CreateCylinder());
515  transHandleZVis->SetLocalPosition(0, 0, 0.35);
516  transHandleZVis->SetLocalScale(0.11, 0.11, 0.7);
517  transHandleZVis->SetMaterial(this->materials[AM_HANDLE], false);
518  transZVis->AddChild(transHandleZVis);
519 
520  this->handles[TransformAxis::TA_TRANSLATION_X] = transHandleXVis;
521  this->handles[TransformAxis::TA_TRANSLATION_Y] = transHandleYVis;
522  this->handles[TransformAxis::TA_TRANSLATION_Z] = transHandleZVis;
523 
524  this->AddChild(transVis);
525  }
526 
528  template <class T>
530  {
532  std::string rotMeshName = "gizmo_rotate";
533  if (!meshMgr->HasMesh(rotMeshName))
534  meshMgr->CreateTube(rotMeshName, 1.0, 1.02, 0.02, 1, 64, IGN_PI);
535 
536  std::string rotFullMeshName = "gizmo_rotate_full";
537  if (!meshMgr->HasMesh(rotFullMeshName))
538  meshMgr->CreateTube(rotFullMeshName, 1.0, 1.02, 0.02, 1, 64, 2*IGN_PI);
539 
540  std::string rotHandleMeshName = "gizmo_rotate_handle";
541  if (!meshMgr->HasMesh(rotHandleMeshName))
542  meshMgr->CreateTube(rotHandleMeshName, 0.95, 1.07, 0.1, 1, 64, IGN_PI);
543 
544  VisualPtr rotVis = this->Scene()->CreateVisual();
545 
546  // rotation x
547  VisualPtr rotXVis = this->Scene()->CreateVisual();
548  rotXVis->AddGeometry(this->Scene()->CreateMesh(rotMeshName));
549  rotXVis->SetLocalRotation(0, IGN_PI * 0.5, 0);
550  rotXVis->SetLocalScale(0.5, 0.5, 0.5);
551  rotXVis->SetMaterial(this->materials[AM_X], false);
552  rotVis->AddChild(rotXVis);
553 
554  // rotation y
555  VisualPtr rotYVis = this->Scene()->CreateVisual();
556  rotYVis->AddGeometry(this->Scene()->CreateMesh(rotMeshName));
557  rotYVis->SetLocalRotation(IGN_PI * 0.5, 0, 0);
558  rotYVis->SetLocalScale(0.5, 0.5, 0.5);
559  rotYVis->SetMaterial(this->materials[AM_Y], false);
560  rotVis->AddChild(rotYVis);
561 
562  // rotation z
563  VisualPtr rotZVis = this->Scene()->CreateVisual();
564  rotZVis->AddGeometry(this->Scene()->CreateMesh(rotMeshName));
565  rotZVis->SetLocalScale(0.5, 0.5, 0.5);
566  rotZVis->SetMaterial(this->materials[AM_Z], false);
567  rotVis->AddChild(rotZVis);
568 
569  // rotation origin
570  VisualPtr rotFullVis = this->Scene()->CreateVisual();
571  rotFullVis->AddGeometry(this->Scene()->CreateMesh(rotFullMeshName));
572  rotFullVis->SetLocalScale(0.5, 0.5, 0.5);
573  rotFullVis->SetMaterial(this->materials[AM_O], false);
574  rotVis->AddChild(rotFullVis);
575 
576  this->visuals[TransformAxis::TA_ROTATION_X] = rotXVis;
577  this->visuals[TransformAxis::TA_ROTATION_Y] = rotYVis;
578  this->visuals[TransformAxis::TA_ROTATION_Z] = rotZVis;
579  this->visuals[TransformAxis::TA_ROTATION_Z << 1] = rotFullVis;
580 
581  // rotation handles
582  VisualPtr rotHandleXVis = this->Scene()->CreateVisual();
583  rotHandleXVis->AddGeometry(this->Scene()->CreateMesh(rotHandleMeshName));
584  rotHandleXVis->SetMaterial(this->materials[AM_HANDLE], false);
585  rotXVis->AddChild(rotHandleXVis);
586 
587  VisualPtr rotHandleYVis = this->Scene()->CreateVisual();
588  rotHandleYVis->AddGeometry(this->Scene()->CreateMesh(rotHandleMeshName));
589  rotHandleYVis->SetMaterial(this->materials[AM_HANDLE], false);
590  rotYVis->AddChild(rotHandleYVis);
591 
592  VisualPtr rotHandleZVis = this->Scene()->CreateVisual();
593  rotHandleZVis->AddGeometry(this->Scene()->CreateMesh(rotHandleMeshName));
594  rotHandleZVis->SetMaterial(this->materials[AM_HANDLE], false);
595  rotZVis->AddChild(rotHandleZVis);
596 
597  this->handles[TransformAxis::TA_ROTATION_X] = rotHandleXVis;
598  this->handles[TransformAxis::TA_ROTATION_Y] = rotHandleYVis;
599  this->handles[TransformAxis::TA_ROTATION_Z] = rotHandleZVis;
600 
601  this->AddChild(rotVis);
602  }
603 
605  template <class T>
607  {
608  VisualPtr scaleVis = this->Scene()->CreateVisual();
609 
610  // scale x
611  VisualPtr scaleXVis = this->Scene()->CreateVisual();
612  VisualPtr scaleShaftXVis = this->Scene()->CreateVisual();
613  scaleShaftXVis->AddGeometry(this->Scene()->CreateCylinder());
614  scaleShaftXVis->SetOrigin(0, 0, 0.5);
615  scaleShaftXVis->SetLocalPosition(0, 0, 0.5);
616  scaleShaftXVis->SetLocalScale(0.02, 0.02, 0.5);
617  scaleXVis->AddChild(scaleShaftXVis);
618 
619  VisualPtr scaleHeadXVis = this->Scene()->CreateVisual();
620  scaleHeadXVis->AddGeometry(this->Scene()->CreateBox());
621  scaleHeadXVis->SetOrigin(0, 0, -0.5);
622  scaleHeadXVis->SetLocalPosition(0, 0, 0.5);
623  scaleHeadXVis->SetLocalScale(0.07, 0.07, 0.07);
624  scaleXVis->AddChild(scaleHeadXVis);
625 
626  scaleXVis->SetMaterial(this->materials[AM_X], false);
627  scaleXVis->SetLocalRotation(0, IGN_PI * 0.5, 0);
628  scaleVis->AddChild(scaleXVis);
629 
630  // scale y
631  VisualPtr scaleYVis = this->Scene()->CreateVisual();
632  VisualPtr scaleShaftYVis = this->Scene()->CreateVisual();
633  scaleShaftYVis->AddGeometry(this->Scene()->CreateCylinder());
634  scaleShaftYVis->SetOrigin(0, 0, 0.5);
635  scaleShaftYVis->SetLocalPosition(0, 0, 0.5);
636  scaleShaftYVis->SetLocalScale(0.02, 0.02, 0.5);
637  scaleYVis->AddChild(scaleShaftYVis);
638 
639  VisualPtr scaleHeadYVis = this->Scene()->CreateVisual();
640  scaleHeadYVis->AddGeometry(this->Scene()->CreateBox());
641  scaleHeadYVis->SetOrigin(0, 0, -0.5);
642  scaleHeadYVis->SetLocalPosition(0, 0, 0.5);
643  scaleHeadYVis->SetLocalScale(0.07, 0.07, 0.07);
644  scaleYVis->AddChild(scaleHeadYVis);
645 
646  scaleYVis->SetMaterial(this->materials[AM_Y], false);
647  scaleYVis->SetLocalRotation(-IGN_PI * 0.5, 0, 0);
648  scaleVis->AddChild(scaleYVis);
649 
650  // scale z
651  VisualPtr scaleZVis = this->Scene()->CreateVisual();
652  VisualPtr scaleShaftZVis = this->Scene()->CreateVisual();
653  scaleShaftZVis->AddGeometry(this->Scene()->CreateCylinder());
654  scaleShaftZVis->SetOrigin(0, 0, 0.5);
655  scaleShaftZVis->SetLocalPosition(0, 0, 0.5);
656  scaleShaftZVis->SetLocalScale(0.02, 0.02, 0.5);
657  scaleZVis->AddChild(scaleShaftZVis);
658 
659  VisualPtr scaleHeadZVis = this->Scene()->CreateVisual();
660  scaleHeadZVis->AddGeometry(this->Scene()->CreateBox());
661  scaleHeadZVis->SetOrigin(0, 0, -0.5);
662  scaleHeadZVis->SetLocalPosition(0, 0, 0.5);
663  scaleHeadZVis->SetLocalScale(0.07, 0.07, 0.07);
664  scaleZVis->AddChild(scaleHeadZVis);
665 
666  scaleZVis->SetMaterial(this->materials[AM_Z], false);
667  scaleVis->AddChild(scaleZVis);
668 
669  this->visuals[TransformAxis::TA_SCALE_X] = scaleXVis;
670  this->visuals[TransformAxis::TA_SCALE_Y] = scaleYVis;
671  this->visuals[TransformAxis::TA_SCALE_Z] = scaleZVis;
672 
673  // scale handles
674  VisualPtr scaleHandleXVis = this->Scene()->CreateVisual();
675  scaleHandleXVis->AddGeometry(this->Scene()->CreateCylinder());
676  scaleHandleXVis->SetLocalPosition(0, 0, 0.285);
677  scaleHandleXVis->SetLocalScale(0.11, 0.11, 0.57);
678  scaleHandleXVis->SetMaterial(this->materials[AM_HANDLE], false);
679  scaleXVis->AddChild(scaleHandleXVis);
680 
681  VisualPtr scaleHandleYVis = this->Scene()->CreateVisual();
682  scaleHandleYVis->AddGeometry(this->Scene()->CreateCylinder());
683  scaleHandleYVis->SetLocalPosition(0, 0, 0.285);
684  scaleHandleYVis->SetLocalScale(0.11, 0.11, 0.57);
685  scaleHandleYVis->SetMaterial(this->materials[AM_HANDLE], false);
686  scaleYVis->AddChild(scaleHandleYVis);
687 
688  VisualPtr scaleHandleZVis = this->Scene()->CreateVisual();
689  scaleHandleZVis->AddGeometry(this->Scene()->CreateCylinder());
690  scaleHandleZVis->SetLocalPosition(0, 0, 0.285);
691  scaleHandleZVis->SetLocalScale(0.11, 0.11, 0.57);
692  scaleHandleZVis->SetMaterial(this->materials[AM_HANDLE], false);
693  scaleZVis->AddChild(scaleHandleZVis);
694 
695  this->handles[TransformAxis::TA_SCALE_X] = scaleHandleXVis;
696  this->handles[TransformAxis::TA_SCALE_Y] = scaleHandleYVis;
697  this->handles[TransformAxis::TA_SCALE_Z] = scaleHandleZVis;
698 
699  this->AddChild(scaleVis);
700  }
701 
703  template <class T>
704  VisualPtr BaseGizmoVisual<T>::ChildByAxis(unsigned int _axis) const
705  {
706  auto it = this->visuals.find(_axis);
707  if (it != this->visuals.end())
708  return it->second;
709 
710  return VisualPtr();
711  }
712  }
713  }
714 }
715 #endif
std::map< unsigned int, MaterialPtr > materials
A map of axis enums to materials.
Definition: BaseGizmoVisual.hh:111
TransformAxis
Definition: TransformType.hh:34
Rotation in x.
Definition: TransformType.hh:45
virtual void Init() override
Definition: BaseGizmoVisual.hh:148
Translation mode.
Definition: TransformType.hh:65
virtual TransformMode Mode() const override
Get the current transform mode.
Definition: BaseGizmoVisual.hh:326
Rotation in y.
Definition: TransformType.hh:47
Scale in x.
Definition: TransformType.hh:51
void CreateRotationVisual()
Create gizmo visual for rotation.
Definition: BaseGizmoVisual.hh:529
Scale in y.
Definition: TransformType.hh:53
Origin.
Definition: BaseGizmoVisual.hh:125
Rotation mode.
Definition: TransformType.hh:67
Translation in x.
Definition: TransformType.hh:39
Rotation in z.
Definition: TransformType.hh:49
std::map< unsigned int, VisualPtr > visuals
A map of gizmo axis and their visuals.
Definition: BaseGizmoVisual.hh:96
Translation in z.
Definition: TransformType.hh:43
Z axis.
Definition: BaseGizmoVisual.hh:121
virtual TransformAxis AxisById(unsigned int _id) const override
Get the Transform axis associated with the given id.
Definition: BaseGizmoVisual.hh:351
STL class.
virtual ~BaseGizmoVisual()
Destructor.
Definition: BaseGizmoVisual.hh:142
STL class.
bool HasMesh(const std::string &_name) const
Translation in y.
Definition: TransformType.hh:41
virtual VisualPtr ChildByAxis(unsigned int _axis) const override
Get the child visual by axis.
Definition: BaseGizmoVisual.hh:704
X axis.
Definition: BaseGizmoVisual.hh:117
Scale mode.
Definition: TransformType.hh:69
void CreateMaterials()
Create materials used by the gizmo visual.
Definition: BaseGizmoVisual.hh:366
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
Definition: BaseGizmoVisual.hh:211
Manages a single scene-graph. This class updates scene-wide properties and holds the root scene node...
Definition: Scene.hh:48
virtual void SetActiveAxis(const math::Vector3d &_axis) override
Set the active axis in the gizmo visual.
Definition: BaseGizmoVisual.hh:333
static MeshManager * Instance()
Active axis.
Definition: BaseGizmoVisual.hh:123
Definition: BaseScene.hh:36
BaseGizmoVisual()
Constructor.
Definition: BaseGizmoVisual.hh:136
TransformMode
Definition: TransformType.hh:60
virtual MaterialPtr CreateMaterial(const std::string &_name="")=0
Create new material with the given name. Created material will have default properties.
Y axis.
Definition: BaseGizmoVisual.hh:119
AxisMaterial
Material used by axes.
Definition: BaseGizmoVisual.hh:114
void CreateTube(const std::string &_name, const float _innerRadius, const float _outterRadius, const float _height, const int _rings, const int _segments, const double _arc=2.0 *IGN_PI)
std::map< unsigned int, VisualPtr > handles
A map of gizmo axis and their handle visuals.
Definition: BaseGizmoVisual.hh:99
virtual void Reset()
Reset the gizmo visual state.
Definition: BaseGizmoVisual.hh:163
Inactive state.
Definition: TransformType.hh:63
virtual void SetTransformMode(TransformMode _mode) override
Set the transform mode of the gizmo. This controls the visual appearance of the gizmo. Only the visuals in the specified mode will be visible, e.g. if set to TM_TRANSLATION mode, then only the translation axis visuals will be visible.
Definition: BaseGizmoVisual.hh:313
void CreateTranslationVisual()
Create gizmo visual for translation.
Definition: BaseGizmoVisual.hh:423
No axis.
Definition: TransformType.hh:37
void CreateScaleVisual()
Create gizmo visual for scale.
Definition: BaseGizmoVisual.hh:606
A base implementation of the GizmoVisual class.
Definition: BaseGizmoVisual.hh:42
VisualPtr activeVis
Currently active visual.
Definition: BaseGizmoVisual.hh:102
virtual math::Vector3d ActiveAxis() const override
Get the current active axis.
Definition: BaseGizmoVisual.hh:344
static const Vector3 Zero
virtual VisualPtr CreateVisual()=0
Create new visual. A unique ID and name will automatically be assigned to the visual.
#define IGN_PI
A gizmo that contains rotate, translate, and scale visuals.
Definition: GizmoVisual.hh:34
Scale in z.
Definition: TransformType.hh:55
virtual MaterialPtr Material(const std::string &_name) const =0
Get material registered under the given name. If no material is registered under the given name...