# Interactive ViewHelper

**URL:** <https://discourse.threejs.org/t/interactive-viewhelper/46246>\
**Category:** Questions\
**Tags:** view-helper\
**Created:** [December 26, 2022, 11:47pm UTC](https://discourse.threejs.org/t/interactive-viewhelper/46246 "2022-12-26T23:47:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheCatalan](https://avatars.discourse-cdn.com/v4/letter/t/13edae/32.png) [@TheCatalan](https://discourse.threejs.org/u/TheCatalan)\
**Post date:** [December 26, 2022, 11:47pm UTC](https://discourse.threejs.org/t/interactive-viewhelper/46246/1 "2022-12-26T23:47:19Z")

</div>

Hi,

I added ViewHelper to my scene. Is it possible to change the camera position when clicking on an axis, as in the editor?

![Captura de pantalla 2022-12-27 a les 0.45.50](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/b/5/b55241494d1e2c593b750026d7c852b9a3cbf032.png)

Thanks,

TC

---

<div class="post-metadata">

**Author:** ![Fennec](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fennec/32/59265_2.png) [@Fennec](https://discourse.threejs.org/u/Fennec)\
**Post date:** [December 27, 2022, 9:33am UTC](https://discourse.threejs.org/t/interactive-viewhelper/46246/2 "2022-12-27T09:33:44Z")

</div>

Have you tried this plugin

> [@Blender like Orbit Controls Gizmo for Three.js](https://discourse.threejs.org/t/blender-like-orbit-controls-gizmo-for-three-js/27527):
>
> Hello everyone, Here’s a lightweight Blender like orientation gizmo for Three.js, it work in tandem with a slightly modified version of THREE.OrbitControls, it follow the orbit controls rotations changes and you can change the camera angle by dragging the gizmo or select an axis by clicking on it. [The live demo](https://fennec-hub.github.io/ThreeOrbitControlsGizmo/)[[image]](https://fennec-hub.github.io/ThreeOrbitControlsGizmo/)

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [December 27, 2022, 10:58am UTC](https://discourse.threejs.org/t/interactive-viewhelper/46246/3 "2022-12-27T10:58:15Z")

</div>

Here is the enhanced fiddle from [Implementing viewHelper to the project](https://discourse.threejs.org/t/implementing-viewhelper-to-the-project/45947) that makes the helper interactive like in the editor: [Interactive view helper. - JSFiddle - Code Playground](https://jsfiddle.net/7rdv6ox3/)

I hope we can refactor the helper slightly so the integration of an interactive helper becomes a bit easier.

---

<div class="post-metadata">

**Author:** ![TheCatalan](https://avatars.discourse-cdn.com/v4/letter/t/13edae/32.png) [@TheCatalan](https://discourse.threejs.org/u/TheCatalan)\
**Post date:** [December 27, 2022, 8:37pm UTC](https://discourse.threejs.org/t/interactive-viewhelper/46246/4 "2022-12-27T20:37:33Z")

</div>

Thank you! I’m trying to adapt. This code works when your canvas is full-width, but I have sidebars and it not working! 🙂 I will try to solve it and I will let you know the solution!

Thanks,

---

<div class="post-metadata">

**Author:** ![Fennec](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fennec/32/59265_2.png) [@Fennec](https://discourse.threejs.org/u/Fennec)\
**Post date:** [December 29, 2022, 2:37pm UTC](https://discourse.threejs.org/t/interactive-viewhelper/46246/5 "2022-12-29T14:37:24Z")

</div>

> [@Mugen87](#):
>
> I hope we can refactor the helper slightly so the integration of an interactive helper becomes a bit easier.

I gave it a shot and the [result](https://swc88o.csb.app/) ([codesandbox](https://codesandbox.io/s/ecstatic-rosalind-swc88o?file=/src/ViewHelper.js:2978-3115)) look promising, I improved the integration, it require less code now, encapsulated most of the outside variables, you only need to call `helper.render()` or `helper.update()` in the animation loop, also added some hover effects for the points and the background sphere.

But I’m not there yet, I’m having some problems with the gizmo rotation, it’s completely off, the `x` and `y` axes seems to be switched.

```javascript
     // Line 118
      this.rotation.y = rotationStart.y + mouseDelta.x;
      this.rotation.x = rotationStart.x + mouseDelta.y;

```

I can’t extract the camera position/rotation from the gizmo, first I tried with `quaternions`, got a mirrored rotation also tried to invert it, everything went sideways, now I’m using a `dummyGimbal` with a `dummyCamera` (null `Object3D`s) to emulate the camera position/rotation, I’m getting the same mirrored effect at best.

I also need to add a clamp on the Y axis, just like the `OrbitControls` so the camera don’t get flipped, and finally rewrite everything with the `Mrdoob's code style TM`

---

<div class="post-metadata">

**Author:** ![TheCatalan](https://avatars.discourse-cdn.com/v4/letter/t/13edae/32.png) [@TheCatalan](https://discourse.threejs.org/u/TheCatalan)\
**Post date:** [December 29, 2022, 3:29pm UTC](https://discourse.threejs.org/t/interactive-viewhelper/46246/6 "2022-12-29T15:29:53Z")

</div>

Hi

Thanks @Fennec, for sharing! 🙂 I’m trying to implement it! Looks easier to implement. I’m having some painting problems. It is confusing for me, because you are creating a Object3D (viewhelper) but I didn’t see when you add it! 🙂 I will keep investigating!

Thanks

TC

---

<div class="post-metadata">

**Author:** ![drcmda](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@drcmda](https://discourse.threejs.org/u/drcmda)\
**Post date:** [December 30, 2022, 1:18am UTC](https://discourse.threejs.org/t/interactive-viewhelper/46246/7 "2022-12-30T01:18:42Z")

</div>

maybe you can compare notes with [this implementation](https://github.com/pmndrs/drei/blob/377cd1fdddce2f89356016ff7268e48748b4dbae/src/core/GizmoHelper.tsx#L128-L164). it can deal with any control (orbit, trackball, arcball, …), as well as damping.

> **[Grid component - CodeSandbox](https://codesandbox.io/s/grid-component-19uq2u?file=%2Fsrc%2FApp.js)**
>
> Grid component by drcmda using @react-three/drei, @react-three/fiber, @types/three, leva, react, react-dom, react-scripts, three

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [December 30, 2022, 8:53am UTC](https://discourse.threejs.org/t/interactive-viewhelper/46246/8 "2022-12-30T08:53:22Z")

</div>

With `r149` the integration will be a bit easier since the helper works now with any controls. More information at GitHub:

> <https://github.com/mrdoob/three.js/pull/25202>
>
> Related issue: -
> 
> \*\*Description\*\*
> 
> \`ViewHelper\` has a dependency to \`EditorC…ontrols\` right now by relying on the control's \`center\` property. That makes it a bit inconvenient to us the helper with other controls like \`OrbitControls\`. You essentially have to do this:
> \`\`\`js
> const helper = new ViewHelper( camera, renderer.domElement );
> helper.controls = controls;
> helper.controls.center = controls.target; // hack
> \`\`\`
> The PR removes the dependency and introduces a new \`center\` property instead. \`ViewHelper.center\` can be directly modified by app level code or the center/target property of a control class can be assigned to it (like in \`editor/js/Viewport.js\`).

---

<div class="post-metadata">

**Author:** ![Fennec](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fennec/32/59265_2.png) [@Fennec](https://discourse.threejs.org/u/Fennec)\
**Post date:** [December 31, 2022, 11:08am UTC](https://discourse.threejs.org/t/interactive-viewhelper/46246/10 "2022-12-31T11:08:22Z")

</div>

It is done … It’s perfectly working now, a standalone and fully interactive version of the `viewHelper`, you can run it with or without the `orbitControls` or `trackballcontrols`.

Here is the demo, also updated the github repo

> **[determined-swartz-tsohn9 - CodeSandbox](https://codesandbox.io/s/xenodochial-aryabhata-pcdb5v?file=%2Fsrc%2FViewHelper.js)**
>
> determined-swartz-tsohn9 using parcel-bundler, three

@Mugen87, please tell me what you think and if I should commit a `ThreeJS` version, thanks.
