1

I try to disable the "zoom" functionality in my 3D .prc model using media9 package. How can I archive this?

\documentclass[12pt]{article}
\usepackage{media9}
\usepackage{graphicx}

\begin{document}
  \begin{figure}
    \centering
    \includemedia[
    label=simulator,
    3Dlights=Hard,
    3Drender=SolidOutline,
    width=0.8\linewidth,
    height=0.5\linewidth,
    3Dcoo=0.6134216785430908 0.6502042412757874 -0.855219304561615,
    3Dc2c=0.07265812903642654 -0.35867559909820557 0.9306302070617676,
    3Droo=76.98254038051421,
    3Droll=11.263210752688222,
    3Daac=60.000001669652114]
    {\includegraphics[scale=1.0]{./_CAD/TEST.png}}{./_CAD/TEST.prc}
  \end{figure}
\end{document}
2

In the example code below (which uses the 3D file dice.u3d from the media9 package), a JavaScript nozoom.js is attached that disables the 3D Zoom tool and zooming by turning the scroll wheel of the mouse. It also tries to cancel zooming due to other mouse gestures.

There is still the "Camera Properties" tool that allows the user to zoom into the 3D scene. Unfortunately, it cannot be disabled.

\documentclass[12pt]{article}
\usepackage{media9}

\usepackage{filecontents}
\begin{filecontents*}{nozoom.js}
/////////////////////////////////////////////////////////////////////
//
// nozoom.js
//
// suppress zooming
//
/////////////////////////////////////////////////////////////////////

//disable some tools that allow zooming
runtime.disableTool(runtime.TOOL_NAME_ZOOM);
runtime.disableTool(runtime.TOOL_NAME_WALK);
runtime.disableTool(runtime.TOOL_NAME_FLY);
runtime.disableTool(runtime.TOOL_NAME_PAN);

//////////////////////////
// some camera properties 
//////////////////////////

var camera_targ = new Vector3(); // target
var camera_pos = new Vector3(); // position
var camera_roo, camera_roll; // distance (radius of orbit), roll

//save camera view
function saveCameraView(c) {
  camera_targ.set(c.targetPosition);
  camera_pos.set(c.position);
  camera_roo = camera_pos.subtract(camera_targ).length;
  camera_roll = c.roll;
};

var camera = scene.cameras.getByIndex(0);
saveCameraView(camera);

//////////////////
// event handlers
//////////////////

// action to be taken on selecting a predefined view
var cameraEventHandler = new CameraEventHandler();
cameraEventHandler.onEvent = function (e) {
  saveCameraView(camera);
}
runtime.addEventHandler(cameraEventHandler);

// action to be taken on mouse move and scroll-wheel events
function restoreZoom(e) {
  if(e.ctrlKeyDown || e.shiftKeyDown) {
    camera.position.set(camera_pos);
    camera.targetPosition.set(camera_targ);
    camera.roll = camera_roll;
  } else {
    // camera-to-target vector
    var c2c = camera.position.subtract(camera_targ);
    c2c.normalize();// --> c2c.length == 1
    // restore original target and distance
    camera.targetPosition.set(camera_targ);
    camera.position.set(camera_targ.add(c2c.scale(camera_roo)));
    saveCameraView(camera); //update saved camera view
  }  
};

var mouseEventHandler = new MouseEventHandler();
mouseEventHandler.onMouseMove = true;
mouseEventHandler.onEvent = restoreZoom;
runtime.addEventHandler(mouseEventHandler);

var scrollWheelEventHandler = new ScrollWheelEventHandler();
scrollWheelEventHandler.onEvent = restoreZoom;
runtime.addEventHandler(scrollWheelEventHandler);
\end{filecontents*}

\begin{document}
  \begin{figure}
    \centering
    \includemedia[
      width=0.5\linewidth,height=0.5\linewidth,
      add3Djscript=nozoom.js,
      3Droo=27,
      3Dtoolbar,
    ]{}{dice.u3d}
  \end{figure}
\end{document}
  • Thanks! It works like it should! – PascalS Jul 15 at 12:50
  • @Passe The JS part has been improved. (Now, the only way to change the zoom is through the "Camera Properties" tool.) – AlexG Jul 15 at 14:06
  • 2
    +1: As usual, impressive. – Dr. Manuel Kuehner Jul 15 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.