Ignition Rendering

API Reference

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