media9:如何禁用 3D 视图中的缩放

media9:如何禁用 3D 视图中的缩放

我尝试使用 media9 包禁用 3D .prc 模型中的“缩放”功能。我该如何存档?

\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}

答案1

在下面的示例代码中(使用包dice.u3d中的3D 文件media9),附加了一个 JavaScript nozoom.js,用于禁用 3D 缩放工具和通过转动鼠标滚轮进行缩放。它还会尝试取消由于其他鼠标手势而进行的缩放。

仍有“相机属性”工具可供用户放大 3D 场景。遗憾的是,该工具无法禁用。

\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}

相关内容