Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Button 放大3.js的按钮_Button_Three.js_Zooming - Fatal编程技术网

Button 放大3.js的按钮

Button 放大3.js的按钮,button,three.js,zooming,Button,Three.js,Zooming,我使用三个.js和三个.js控件制作动画 我不知道如何改变按钮点击缩放 我如何理解..对于缩放回答此函数 this.dollyIn = function ( dollyScale ) { if ( dollyScale === undefined ) { dollyScale = getZoomScale(); } scale /= dollyScale; }; this.dollyOut = funct

我使用三个.js和三个.js控件制作动画 我不知道如何改变按钮点击缩放 我如何理解..对于缩放回答此函数

this.dollyIn = function ( dollyScale ) {
        if ( dollyScale === undefined ) {
            dollyScale = getZoomScale();
        }
        scale /= dollyScale;

    };

    this.dollyOut = function ( dollyScale ) {
        if ( dollyScale === undefined ) {
            dollyScale = getZoomScale();
        }
        scale *= dollyScale;

    };
我需要发送什么来递增或递减缩放 我怎么做这个按钮的形式

<input id="clickMe" type="button" value="+" onclick="..." /> 

在OrbitControls.js中查看如何在update()-函数中将缩放值应用于相机围绕其目标的半径,以及如何实现getZoomScale()

比例与总半径相乘。因此,要缩小,比例值必须大于1;要放大,比例值必须小于1。此外,在OrbitControls更新功能结束时,比例将重置为1.0。 另一方面,如果zoomSpeed设置为1.0,则getZoomScale()始终返回0.95


简言之,如果您只在按钮单击事件上调用controls.dollyOut()或controls.dollyIn(),您的缩放将发生变化,就像您在鼠标滚轮上打勾一样,因为这使用相同的函数调用

我在我的一个项目中做过这个

没错,您可以使用OrbitControls中的dollyIn()dollyOut()函数进行放大或缩小

以下是步骤和代码片段:

  • 您需要初始化OrbitControl以及相机和渲染器组件:

    var controls=新的三个.OrbitControls(摄影机、渲染器.doElement)

  • 创建放大和缩小功能:

  • 将事件侦听器添加到按钮中以调用zoomModel函数:

对于较新的THREEjs版本(在r74和r75上试用过),您可以在按钮单击事件时调用这些事件:

controls.constraint.dollyOut(/*Add your desired scale here*/) //Zoom in

dollyIn()和dollyOut()是OrbitControl的内部函数,不能公开访问。修订版116.1
 $("#clickMe").on("click", function(){
  // call this to make the model larger/ zoom in
  zoomModel(true, 4);

  // call this to make it smaller / zoom out
  //zoomModel(false, 4);
});
controls.constraint.dollyOut(/*Add your desired scale here*/) //Zoom in
controls.constraint.dollyIn(/*Add your desired scale here*/) //Zoom out