Ignition Rendering

API Reference

6.3.1
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>
25 
31 
32 namespace ignition
33 {
34  namespace rendering
35  {
36  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
37  //
38  /* \class BaseGizmoVisual BaseGizmoVisuall.hh \
39  * ignition/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 
98 
101 
103  protected: VisualPtr activeVis;
104 
106  protected: bool modeDirty = false;
107 
110 
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, IGN_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(-IGN_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  this->visuals[TransformAxis::TA_TRANSLATION_Z << 1] = transOrigin;
499 
500  // translation handles
501  VisualPtr transHandleXVis = this->Scene()->CreateVisual();
502  transHandleXVis->AddGeometry(this->Scene()->CreateCylinder());
503  transHandleXVis->SetLocalPosition(0, 0, 0.35);
504  transHandleXVis->SetLocalScale(0.11, 0.11, 0.7);
505  transHandleXVis->SetMaterial(this->materials[AM_HANDLE], false);
506  transXVis->AddChild(transHandleXVis);
507 
508  VisualPtr transHandleYVis = this->Scene()->CreateVisual();
509  transHandleYVis->AddGeometry(this->Scene()->CreateCylinder());
510  transHandleYVis->SetLocalPosition(0, 0, 0.35);
511  transHandleYVis->SetLocalScale(0.11, 0.11, 0.7);
512  transHandleYVis->SetMaterial(this->materials[AM_HANDLE], false);
513  transYVis->AddChild(transHandleYVis);
514 
515  VisualPtr transHandleZVis = this->Scene()->CreateVisual();
516  transHandleZVis->AddGeometry(this->Scene()->CreateCylinder());
517  transHandleZVis->SetLocalPosition(0, 0, 0.35);
518  transHandleZVis->SetLocalScale(0.11, 0.11, 0.7);
519  transHandleZVis->SetMaterial(this->materials[AM_HANDLE], false);
520  transZVis->AddChild(transHandleZVis);
521 
522  this->handles[TransformAxis::TA_TRANSLATION_X] = transHandleXVis;
523  this->handles[TransformAxis::TA_TRANSLATION_Y] = transHandleYVis;
524  this->handles[TransformAxis::TA_TRANSLATION_Z] = transHandleZVis;
525 
526  this->AddChild(transVis);
527  }
528 
530  template <class T>
532  {
534  std::string rotMeshName = "gizmo_rotate";
535  if (!meshMgr->HasMesh(rotMeshName))
536  meshMgr->CreateTube(rotMeshName, 1.0f, 1.02f, 0.02f, 1, 64, IGN_PI);
537 
538  std::string rotFullMeshName = "gizmo_rotate_full";
539  if (!meshMgr->HasMesh(rotFullMeshName))
540  {
541  meshMgr->CreateTube(rotFullMeshName, 1.0f, 1.02f, 0.02f, 1, 64,
542  2 * IGN_PI);
543  }
544 
545  std::string rotHandleMeshName = "gizmo_rotate_handle";
546  if (!meshMgr->HasMesh(rotHandleMeshName))
547  {
548  meshMgr->CreateTube(rotHandleMeshName, 0.95f, 1.07f, 0.1f, 1, 64,
549  IGN_PI);
550  }
551 
552  VisualPtr rotVis = this->Scene()->CreateVisual();
553 
554  // rotation x
555  VisualPtr rotXVis = this->Scene()->CreateVisual();
556  rotXVis->AddGeometry(this->Scene()->CreateMesh(rotMeshName));
557  rotXVis->SetLocalRotation(0, IGN_PI * 0.5, 0);
558  rotXVis->SetLocalScale(0.5, 0.5, 0.5);
559  rotXVis->SetMaterial(this->materials[AM_X], false);
560  rotVis->AddChild(rotXVis);
561 
562  // rotation y
563  VisualPtr rotYVis = this->Scene()->CreateVisual();
564  rotYVis->AddGeometry(this->Scene()->CreateMesh(rotMeshName));
565  rotYVis->SetLocalRotation(IGN_PI * 0.5, 0, 0);
566  rotYVis->SetLocalScale(0.5, 0.5, 0.5);
567  rotYVis->SetMaterial(this->materials[AM_Y], false);
568  rotVis->AddChild(rotYVis);
569 
570  // rotation z
571  VisualPtr rotZVis = this->Scene()->CreateVisual();
572  rotZVis->AddGeometry(this->Scene()->CreateMesh(rotMeshName));
573  rotZVis->SetLocalScale(0.5, 0.5, 0.5);
574  rotZVis->SetMaterial(this->materials[AM_Z], false);
575  rotVis->AddChild(rotZVis);
576 
577  // rotation origin
578  VisualPtr rotFullVis = this->Scene()->CreateVisual();
579  rotFullVis->AddGeometry(this->Scene()->CreateMesh(rotFullMeshName));
580  rotFullVis->SetLocalScale(0.5, 0.5, 0.5);
581  rotFullVis->SetMaterial(this->materials[AM_O], false);
582  rotVis->AddChild(rotFullVis);
583 
584  this->visuals[TransformAxis::TA_ROTATION_X] = rotXVis;
585  this->visuals[TransformAxis::TA_ROTATION_Y] = rotYVis;
586  this->visuals[TransformAxis::TA_ROTATION_Z] = rotZVis;
587  this->visuals[TransformAxis::TA_ROTATION_Z << 1] = rotFullVis;
588 
589  // rotation handles
590  VisualPtr rotHandleXVis = this->Scene()->CreateVisual();
591  rotHandleXVis->AddGeometry(this->Scene()->CreateMesh(rotHandleMeshName));
592  rotHandleXVis->SetMaterial(this->materials[AM_HANDLE], false);
593  rotXVis->AddChild(rotHandleXVis);
594 
595  VisualPtr rotHandleYVis = this->Scene()->CreateVisual();
596  rotHandleYVis->AddGeometry(this->Scene()->CreateMesh(rotHandleMeshName));
597  rotHandleYVis->SetMaterial(this->materials[AM_HANDLE], false);
598  rotYVis->AddChild(rotHandleYVis);
599 
600  VisualPtr rotHandleZVis = this->Scene()->CreateVisual();
601  rotHandleZVis->AddGeometry(this->Scene()->CreateMesh(rotHandleMeshName));
602  rotHandleZVis->SetMaterial(this->materials[AM_HANDLE], false);
603  rotZVis->AddChild(rotHandleZVis);
604 
605  this->handles[TransformAxis::TA_ROTATION_X] = rotHandleXVis;
606  this->handles[TransformAxis::TA_ROTATION_Y] = rotHandleYVis;
607  this->handles[TransformAxis::TA_ROTATION_Z] = rotHandleZVis;
608 
609  this->AddChild(rotVis);
610  }
611 
613  template <class T>
615  {
616  VisualPtr scaleVis = this->Scene()->CreateVisual();
617 
618  // scale x
619  VisualPtr scaleXVis = this->Scene()->CreateVisual();
620  VisualPtr scaleShaftXVis = this->Scene()->CreateVisual();
621  scaleShaftXVis->AddGeometry(this->Scene()->CreateCylinder());
622  scaleShaftXVis->SetOrigin(0, 0, 0.5);
623  scaleShaftXVis->SetLocalPosition(0, 0, 0.5);
624  scaleShaftXVis->SetLocalScale(0.02, 0.02, 0.5);
625  scaleXVis->AddChild(scaleShaftXVis);
626 
627  VisualPtr scaleHeadXVis = this->Scene()->CreateVisual();
628  scaleHeadXVis->AddGeometry(this->Scene()->CreateBox());
629  scaleHeadXVis->SetOrigin(0, 0, -0.5);
630  scaleHeadXVis->SetLocalPosition(0, 0, 0.5);
631  scaleHeadXVis->SetLocalScale(0.07, 0.07, 0.07);
632  scaleXVis->AddChild(scaleHeadXVis);
633 
634  scaleXVis->SetMaterial(this->materials[AM_X], false);
635  scaleXVis->SetLocalRotation(0, IGN_PI * 0.5, 0);
636  scaleVis->AddChild(scaleXVis);
637 
638  // scale y
639  VisualPtr scaleYVis = this->Scene()->CreateVisual();
640  VisualPtr scaleShaftYVis = this->Scene()->CreateVisual();
641  scaleShaftYVis->AddGeometry(this->Scene()->CreateCylinder());
642  scaleShaftYVis->SetOrigin(0, 0, 0.5);
643  scaleShaftYVis->SetLocalPosition(0, 0, 0.5);
644  scaleShaftYVis->SetLocalScale(0.02, 0.02, 0.5);
645  scaleYVis->AddChild(scaleShaftYVis);
646 
647  VisualPtr scaleHeadYVis = this->Scene()->CreateVisual();
648  scaleHeadYVis->AddGeometry(this->Scene()->CreateBox());
649  scaleHeadYVis->SetOrigin(0, 0, -0.5);
650  scaleHeadYVis->SetLocalPosition(0, 0, 0.5);
651  scaleHeadYVis->SetLocalScale(0.07, 0.07, 0.07);
652  scaleYVis->AddChild(scaleHeadYVis);
653 
654  scaleYVis->SetMaterial(this->materials[AM_Y], false);
655  scaleYVis->SetLocalRotation(-IGN_PI * 0.5, 0, 0);
656  scaleVis->AddChild(scaleYVis);
657 
658  // scale z
659  VisualPtr scaleZVis = this->Scene()->CreateVisual();
660  VisualPtr scaleShaftZVis = this->Scene()->CreateVisual();
661  scaleShaftZVis->AddGeometry(this->Scene()->CreateCylinder());
662  scaleShaftZVis->SetOrigin(0, 0, 0.5);
663  scaleShaftZVis->SetLocalPosition(0, 0, 0.5);
664  scaleShaftZVis->SetLocalScale(0.02, 0.02, 0.5);
665  scaleZVis->AddChild(scaleShaftZVis);
666 
667  VisualPtr scaleHeadZVis = this->Scene()->CreateVisual();
668  scaleHeadZVis->AddGeometry(this->Scene()->CreateBox());
669  scaleHeadZVis->SetOrigin(0, 0, -0.5);
670  scaleHeadZVis->SetLocalPosition(0, 0, 0.5);
671  scaleHeadZVis->SetLocalScale(0.07, 0.07, 0.07);
672  scaleZVis->AddChild(scaleHeadZVis);
673 
674  scaleZVis->SetMaterial(this->materials[AM_Z], false);
675  scaleVis->AddChild(scaleZVis);
676 
677  this->visuals[TransformAxis::TA_SCALE_X] = scaleXVis;
678  this->visuals[TransformAxis::TA_SCALE_Y] = scaleYVis;
679  this->visuals[TransformAxis::TA_SCALE_Z] = scaleZVis;
680 
681  // scale handles
682  VisualPtr scaleHandleXVis = this->Scene()->CreateVisual();
683  scaleHandleXVis->AddGeometry(this->Scene()->CreateCylinder());
684  scaleHandleXVis->SetLocalPosition(0, 0, 0.285);
685  scaleHandleXVis->SetLocalScale(0.11, 0.11, 0.57);
686  scaleHandleXVis->SetMaterial(this->materials[AM_HANDLE], false);
687  scaleXVis->AddChild(scaleHandleXVis);
688 
689  VisualPtr scaleHandleYVis = this->Scene()->CreateVisual();
690  scaleHandleYVis->AddGeometry(this->Scene()->CreateCylinder());
691  scaleHandleYVis->SetLocalPosition(0, 0, 0.285);
692  scaleHandleYVis->SetLocalScale(0.11, 0.11, 0.57);
693  scaleHandleYVis->SetMaterial(this->materials[AM_HANDLE], false);
694  scaleYVis->AddChild(scaleHandleYVis);
695 
696  VisualPtr scaleHandleZVis = this->Scene()->CreateVisual();
697  scaleHandleZVis->AddGeometry(this->Scene()->CreateCylinder());
698  scaleHandleZVis->SetLocalPosition(0, 0, 0.285);
699  scaleHandleZVis->SetLocalScale(0.11, 0.11, 0.57);
700  scaleHandleZVis->SetMaterial(this->materials[AM_HANDLE], false);
701  scaleZVis->AddChild(scaleHandleZVis);
702 
703  this->handles[TransformAxis::TA_SCALE_X] = scaleHandleXVis;
704  this->handles[TransformAxis::TA_SCALE_Y] = scaleHandleYVis;
705  this->handles[TransformAxis::TA_SCALE_Z] = scaleHandleZVis;
706 
707  this->AddChild(scaleVis);
708  }
709 
711  template <class T>
712  VisualPtr BaseGizmoVisual<T>::ChildByAxis(unsigned int _axis) const
713  {
714  auto it = this->visuals.find(_axis);
715  if (it != this->visuals.end())
716  return it->second;
717 
718  return VisualPtr();
719  }
720  }
721  }
722 }
723 #endif
std::map< unsigned int, MaterialPtr > materials
A map of axis enums to materials.
Definition: BaseGizmoVisual.hh:112
TransformAxis
Unique identifiers for transformation axes.
Definition: TransformType.hh:34
Rotation in x.
Definition: TransformType.hh:45
virtual void Init() override
Definition: BaseGizmoVisual.hh:150
Translation mode.
Definition: TransformType.hh:65
virtual TransformMode Mode() const override
Get the current transform mode.
Definition: BaseGizmoVisual.hh:328
Rotation in y.
Definition: TransformType.hh:47
Scale in x.
Definition: TransformType.hh:51
void CreateRotationVisual()
Create gizmo visual for rotation.
Definition: BaseGizmoVisual.hh:531
Scale in y.
Definition: TransformType.hh:53
Origin.
Definition: BaseGizmoVisual.hh:127
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:97
Translation in z.
Definition: TransformType.hh:43
Z axis.
Definition: BaseGizmoVisual.hh:123
virtual TransformAxis AxisById(unsigned int _id) const override
Get the Transform axis associated with the given id.
Definition: BaseGizmoVisual.hh:353
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
STL class.
virtual ~BaseGizmoVisual()
Destructor.
Definition: BaseGizmoVisual.hh:144
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:712
X axis.
Definition: BaseGizmoVisual.hh:119
Scale mode.
Definition: TransformType.hh:69
void CreateMaterials()
Create materials used by the gizmo visual.
Definition: BaseGizmoVisual.hh:368
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:213
Manages a single scene-graph. This class updates scene-wide properties and holds the root scene node...
Definition: Scene.hh:49
virtual void SetActiveAxis(const math::Vector3d &_axis) override
Set the active axis in the gizmo visual.
Definition: BaseGizmoVisual.hh:335
static MeshManager * Instance()
Active axis.
Definition: BaseGizmoVisual.hh:125
Definition: BaseScene.hh:37
BaseGizmoVisual()
Constructor.
Definition: BaseGizmoVisual.hh:138
TransformMode
Unique identifiers for transformation modes.
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:121
AxisMaterial
Material used by axes.
Definition: BaseGizmoVisual.hh:116
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:100
virtual void Reset()
Reset the gizmo visual state.
Definition: BaseGizmoVisual.hh:165
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:315
void CreateTranslationVisual()
Create gizmo visual for translation.
Definition: BaseGizmoVisual.hh:425
No axis.
Definition: TransformType.hh:37
void CreateScaleVisual()
Create gizmo visual for scale.
Definition: BaseGizmoVisual.hh:614
A base implementation of the GizmoVisual class.
Definition: BaseGizmoVisual.hh:43
VisualPtr activeVis
Currently active visual.
Definition: BaseGizmoVisual.hh:103
virtual math::Vector3d ActiveAxis() const override
Get the current active axis.
Definition: BaseGizmoVisual.hh:346
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
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
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...