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);
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);
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);
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);
207 for (
auto v : this->visuals)
208 v.second->SetVisible(
false);
215 if (!this->modeDirty)
220 if (this->mode == TransformMode::TM_NONE)
222 this->modeDirty =
false;
226 if (this->mode & TransformMode::TM_TRANSLATION)
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)
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);
239 if (this->axis.Y() > 0)
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);
246 if (this->axis.Z() > 0)
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);
254 else if (this->mode & TransformMode::TM_ROTATION)
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)
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);
267 if (this->axis.Y() > 0)
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);
274 if (this->axis.Z() > 0)
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);
282 else if (this->mode & TransformMode::TM_SCALE)
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)
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);
294 if (this->axis.Y() > 0)
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);
301 if (this->axis.Z() > 0)
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);
310 this->modeDirty =
false;
377 xMat->SetDepthWriteEnabled(
false);
378 xMat->SetDepthCheckEnabled(
false);
379 yMat->SetDepthWriteEnabled(
false);
380 yMat->SetDepthCheckEnabled(
false);
381 zMat->SetDepthWriteEnabled(
false);
382 zMat->SetDepthCheckEnabled(
false);
383 activeMat->SetDepthWriteEnabled(
false);
384 activeMat->SetDepthCheckEnabled(
false);
390 oMat->SetAmbient(0.5, 0.5, 0.5);
391 oMat->SetDiffuse(0.5, 0.5, 0.5);
392 oMat->SetEmissive(0.5, 0.5, 0.5);
393 oMat->SetTransparency(0.5);
394 oMat->SetCastShadows(
false);
395 oMat->SetReceiveShadows(
false);
396 oMat->SetLightingEnabled(
false);
397 oMat->SetDepthWriteEnabled(
false);
398 oMat->SetDepthCheckEnabled(
false);
405 handleMat->SetAmbient(0.0, 0.0, 0.0);
406 handleMat->SetDiffuse(0.0, 0.0, 0.0);
407 handleMat->SetEmissive(0.0, 0.0, 0.0);
408 handleMat->SetTransparency(1.0);
409 handleMat->SetCastShadows(
false);
410 handleMat->SetReceiveShadows(
false);
411 handleMat->SetLightingEnabled(
false);
412 handleMat->SetDepthWriteEnabled(
false);
413 handleMat->SetDepthCheckEnabled(
false);
416 this->materials[AM_X] = xMat;
417 this->materials[AM_Y] = yMat;
418 this->materials[AM_Z] = zMat;
419 this->materials[AM_ACTIVE] = activeMat;
420 this->materials[AM_O] = oMat;
421 this->materials[AM_HANDLE] = handleMat;
432 transShaftXVis->AddGeometry(this->
Scene()->CreateCylinder());
433 transShaftXVis->SetOrigin(0, 0, 0.5);
434 transShaftXVis->SetLocalPosition(0, 0, 0.5);
435 transShaftXVis->SetLocalScale(0.02, 0.02, 0.45);
436 transXVis->AddChild(transShaftXVis);
439 transHeadXVis->AddGeometry(this->
Scene()->CreateCone());
440 transHeadXVis->SetOrigin(0, 0, -0.5);
441 transHeadXVis->SetLocalPosition(0, 0, 0.5);
442 transHeadXVis->SetLocalScale(0.07, 0.07, 0.2);
443 transXVis->AddChild(transHeadXVis);
445 transXVis->SetMaterial(this->materials[AM_X],
false);
446 transXVis->SetLocalRotation(0,
GZ_PI * 0.5, 0);
447 transVis->AddChild(transXVis);
452 transShaftYVis->AddGeometry(this->
Scene()->CreateCylinder());
453 transShaftYVis->SetOrigin(0, 0, 0.5);
454 transShaftYVis->SetLocalPosition(0, 0, 0.5);
455 transShaftYVis->SetLocalScale(0.02, 0.02, 0.45);
456 transYVis->AddChild(transShaftYVis);
459 transHeadYVis->AddGeometry(this->
Scene()->CreateCone());
460 transHeadYVis->SetOrigin(0, 0, -0.5);
461 transHeadYVis->SetLocalPosition(0, 0, 0.5);
462 transHeadYVis->SetLocalScale(0.07, 0.07, 0.2);
463 transYVis->AddChild(transHeadYVis);
465 transYVis->SetMaterial(this->materials[AM_Y],
false);
466 transYVis->SetLocalRotation(-
GZ_PI * 0.5, 0, 0);
467 transVis->AddChild(transYVis);
472 transShaftZVis->AddGeometry(this->
Scene()->CreateCylinder());
473 transShaftZVis->SetOrigin(0, 0, 0.5);
474 transShaftZVis->SetLocalPosition(0, 0, 0.5);
475 transShaftZVis->SetLocalScale(0.02, 0.02, 0.45);
476 transZVis->AddChild(transShaftZVis);
479 transHeadZVis->AddGeometry(this->
Scene()->CreateCone());
480 transHeadZVis->SetOrigin(0, 0, -0.5);
481 transHeadZVis->SetLocalPosition(0, 0, 0.5);
482 transHeadZVis->SetLocalScale(0.07, 0.07, 0.2);
483 transZVis->AddChild(transHeadZVis);
485 transZVis->SetMaterial(this->materials[AM_Z],
false);
486 transVis->AddChild(transZVis);
490 transOrigin->AddGeometry(this->
Scene()->CreateSphere());
491 transOrigin->SetLocalScale(0.05, 0.05, 0.05);
492 transOrigin->SetMaterial(this->materials[AM_O],
false);
493 transVis->AddChild(transOrigin);
495 this->visuals[TransformAxis::TA_TRANSLATION_X] = transXVis;
496 this->visuals[TransformAxis::TA_TRANSLATION_Y] = transYVis;
497 this->visuals[TransformAxis::TA_TRANSLATION_Z] = transZVis;
500 this->visuals[TransformAxis::TA_TRANSLATION_Z << 1] = transOrigin;
504 transHandleXVis->AddGeometry(this->
Scene()->CreateCylinder());
505 transHandleXVis->SetLocalPosition(0, 0, 0.35);
506 transHandleXVis->SetLocalScale(0.11, 0.11, 0.7);
507 transHandleXVis->SetMaterial(this->materials[AM_HANDLE],
false);
508 transXVis->AddChild(transHandleXVis);
511 transHandleYVis->AddGeometry(this->
Scene()->CreateCylinder());
512 transHandleYVis->SetLocalPosition(0, 0, 0.35);
513 transHandleYVis->SetLocalScale(0.11, 0.11, 0.7);
514 transHandleYVis->SetMaterial(this->materials[AM_HANDLE],
false);
515 transYVis->AddChild(transHandleYVis);
518 transHandleZVis->AddGeometry(this->
Scene()->CreateCylinder());
519 transHandleZVis->SetLocalPosition(0, 0, 0.35);
520 transHandleZVis->SetLocalScale(0.11, 0.11, 0.7);
521 transHandleZVis->SetMaterial(this->materials[AM_HANDLE],
false);
522 transZVis->AddChild(transHandleZVis);
524 this->handles[TransformAxis::TA_TRANSLATION_X] = transHandleXVis;
525 this->handles[TransformAxis::TA_TRANSLATION_Y] = transHandleYVis;
526 this->handles[TransformAxis::TA_TRANSLATION_Z] = transHandleZVis;
528 this->AddChild(transVis);
537 if (!meshMgr->
HasMesh(rotMeshName))
541 if (!meshMgr->
HasMesh(rotFullMeshName))
543 meshMgr->
CreateTube(rotFullMeshName, 1.0f, 1.02f, 0.02f, 1, 64,
547 std::string rotHandleMeshName =
"gizmo_rotate_handle";
548 if (!meshMgr->
HasMesh(rotHandleMeshName))
550 meshMgr->
CreateTube(rotHandleMeshName, 0.95f, 1.07f, 0.1f, 1, 64,
558 rotXVis->AddGeometry(this->
Scene()->CreateMesh(rotMeshName));
559 rotXVis->SetLocalRotation(0,
GZ_PI * 0.5, 0);
560 rotXVis->SetLocalScale(0.5, 0.5, 0.5);
561 rotXVis->SetMaterial(this->materials[AM_X],
false);
562 rotVis->AddChild(rotXVis);
566 rotYVis->AddGeometry(this->
Scene()->CreateMesh(rotMeshName));
567 rotYVis->SetLocalRotation(
GZ_PI * 0.5, 0, 0);
568 rotYVis->SetLocalScale(0.5, 0.5, 0.5);
569 rotYVis->SetMaterial(this->materials[AM_Y],
false);
570 rotVis->AddChild(rotYVis);
574 rotZVis->AddGeometry(this->
Scene()->CreateMesh(rotMeshName));
575 rotZVis->SetLocalScale(0.5, 0.5, 0.5);
576 rotZVis->SetMaterial(this->materials[AM_Z],
false);
577 rotVis->AddChild(rotZVis);
581 rotFullVis->AddGeometry(this->
Scene()->CreateMesh(rotFullMeshName));
582 rotFullVis->SetLocalScale(0.5, 0.5, 0.5);
583 rotFullVis->SetMaterial(this->materials[AM_O],
false);
584 rotVis->AddChild(rotFullVis);
586 this->visuals[TransformAxis::TA_ROTATION_X] = rotXVis;
587 this->visuals[TransformAxis::TA_ROTATION_Y] = rotYVis;
588 this->visuals[TransformAxis::TA_ROTATION_Z] = rotZVis;
591 this->visuals[TransformAxis::TA_ROTATION_Z << 1] = rotFullVis;
595 rotHandleXVis->AddGeometry(this->
Scene()->CreateMesh(rotHandleMeshName));
596 rotHandleXVis->SetMaterial(this->materials[AM_HANDLE],
false);
597 rotXVis->AddChild(rotHandleXVis);
600 rotHandleYVis->AddGeometry(this->
Scene()->CreateMesh(rotHandleMeshName));
601 rotHandleYVis->SetMaterial(this->materials[AM_HANDLE],
false);
602 rotYVis->AddChild(rotHandleYVis);
605 rotHandleZVis->AddGeometry(this->
Scene()->CreateMesh(rotHandleMeshName));
606 rotHandleZVis->SetMaterial(this->materials[AM_HANDLE],
false);
607 rotZVis->AddChild(rotHandleZVis);
609 this->handles[TransformAxis::TA_ROTATION_X] = rotHandleXVis;
610 this->handles[TransformAxis::TA_ROTATION_Y] = rotHandleYVis;
611 this->handles[TransformAxis::TA_ROTATION_Z] = rotHandleZVis;
613 this->AddChild(rotVis);
625 scaleShaftXVis->AddGeometry(this->
Scene()->CreateCylinder());
626 scaleShaftXVis->SetOrigin(0, 0, 0.5);
627 scaleShaftXVis->SetLocalPosition(0, 0, 0.5);
628 scaleShaftXVis->SetLocalScale(0.02, 0.02, 0.5);
629 scaleXVis->AddChild(scaleShaftXVis);
632 scaleHeadXVis->AddGeometry(this->
Scene()->CreateBox());
633 scaleHeadXVis->SetOrigin(0, 0, -0.5);
634 scaleHeadXVis->SetLocalPosition(0, 0, 0.5);
635 scaleHeadXVis->SetLocalScale(0.07, 0.07, 0.07);
636 scaleXVis->AddChild(scaleHeadXVis);
638 scaleXVis->SetMaterial(this->materials[AM_X],
false);
639 scaleXVis->SetLocalRotation(0,
GZ_PI * 0.5, 0);
640 scaleVis->AddChild(scaleXVis);
645 scaleShaftYVis->AddGeometry(this->
Scene()->CreateCylinder());
646 scaleShaftYVis->SetOrigin(0, 0, 0.5);
647 scaleShaftYVis->SetLocalPosition(0, 0, 0.5);
648 scaleShaftYVis->SetLocalScale(0.02, 0.02, 0.5);
649 scaleYVis->AddChild(scaleShaftYVis);
652 scaleHeadYVis->AddGeometry(this->
Scene()->CreateBox());
653 scaleHeadYVis->SetOrigin(0, 0, -0.5);
654 scaleHeadYVis->SetLocalPosition(0, 0, 0.5);
655 scaleHeadYVis->SetLocalScale(0.07, 0.07, 0.07);
656 scaleYVis->AddChild(scaleHeadYVis);
658 scaleYVis->SetMaterial(this->materials[AM_Y],
false);
659 scaleYVis->SetLocalRotation(-
GZ_PI * 0.5, 0, 0);
660 scaleVis->AddChild(scaleYVis);
665 scaleShaftZVis->AddGeometry(this->
Scene()->CreateCylinder());
666 scaleShaftZVis->SetOrigin(0, 0, 0.5);
667 scaleShaftZVis->SetLocalPosition(0, 0, 0.5);
668 scaleShaftZVis->SetLocalScale(0.02, 0.02, 0.5);
669 scaleZVis->AddChild(scaleShaftZVis);
672 scaleHeadZVis->AddGeometry(this->
Scene()->CreateBox());
673 scaleHeadZVis->SetOrigin(0, 0, -0.5);
674 scaleHeadZVis->SetLocalPosition(0, 0, 0.5);
675 scaleHeadZVis->SetLocalScale(0.07, 0.07, 0.07);
676 scaleZVis->AddChild(scaleHeadZVis);
678 scaleZVis->SetMaterial(this->materials[AM_Z],
false);
679 scaleVis->AddChild(scaleZVis);
681 this->visuals[TransformAxis::TA_SCALE_X] = scaleXVis;
682 this->visuals[TransformAxis::TA_SCALE_Y] = scaleYVis;
683 this->visuals[TransformAxis::TA_SCALE_Z] = scaleZVis;
687 scaleHandleXVis->AddGeometry(this->
Scene()->CreateCylinder());
688 scaleHandleXVis->SetLocalPosition(0, 0, 0.285);
689 scaleHandleXVis->SetLocalScale(0.11, 0.11, 0.57);
690 scaleHandleXVis->SetMaterial(this->materials[AM_HANDLE],
false);
691 scaleXVis->AddChild(scaleHandleXVis);
694 scaleHandleYVis->AddGeometry(this->
Scene()->CreateCylinder());
695 scaleHandleYVis->SetLocalPosition(0, 0, 0.285);
696 scaleHandleYVis->SetLocalScale(0.11, 0.11, 0.57);
697 scaleHandleYVis->SetMaterial(this->materials[AM_HANDLE],
false);
698 scaleYVis->AddChild(scaleHandleYVis);
701 scaleHandleZVis->AddGeometry(this->
Scene()->CreateCylinder());
702 scaleHandleZVis->SetLocalPosition(0, 0, 0.285);
703 scaleHandleZVis->SetLocalScale(0.11, 0.11, 0.57);
704 scaleHandleZVis->SetMaterial(this->materials[AM_HANDLE],
false);
705 scaleZVis->AddChild(scaleHandleZVis);
707 this->handles[TransformAxis::TA_SCALE_X] = scaleHandleXVis;
708 this->handles[TransformAxis::TA_SCALE_Y] = scaleHandleYVis;
709 this->handles[TransformAxis::TA_SCALE_Z] = scaleHandleZVis;
711 this->AddChild(scaleVis);