1

我尝试将在服务器上渲染的图片与在 Web 客户端渲染的边界框连接起来。我在 web 客户端上使用极坐标系统,所以当 angel phi 超过 90 时,camera.Up 从 (0,1,0) 变为 (0,-1,0),但是当我将这些选项设置为 Vtk 相机时它工作正常,直到向量 Up 变为 (0,-1,0) 之后,如果 camera.Up 向量没有变化,服务器上的摄像头开始工作,就像 web 客户端一样。

这里有一些代码示例:

JS:

renderer.domElement.addEventListener('mousemove', function(e) {
            e.preventDefault();

            if ( paused ) {
                return;
            }

            if ( !moving ) {
                lastLeft = e.clientX;
                lastTop = e.clientY;
                moving = true;
            }

            // horizontal
            theta = - ( ( event.clientX - lastLeft ) * 360 /window.innerWidth ) + onMouseDownTheta;
            phi = ( ( event.clientY - lastTop ) * 360 /window.innerHeight ) + onMouseDownPhi;



            //phi = Math.min( 90, Math.max( -90, phi ) );
            var cosPhi = Math.cos( phi * Math.PI / 180 );
            var sinPhi = Math.sin( phi * Math.PI / 180 );
            var sinTheta = Math.sin( theta * Math.PI / 180 );
            var cosTheta = Math.cos( theta * Math.PI / 180 );


            //trace('data_move');trace(radious);trace(theta);trace(phi);trace(camera.up);   
            camera.position.x = radious * cosTheta * cosPhi;
            camera.position.y = radious * sinPhi;
            camera.position.z = radious * sinTheta * cosPhi;


            if (phi<0)  phi=2*180+phi;
            if (phi>2*180)  phi=phi-2*180;
        if (theta>2*180)    theta=theta-2*180;
        if (theta<-2*180)   theta=theta+2*180;
            if ((phi>180/2)&&(phi<3*180/2))
                camera.up.y=-1;
            else
                camera.up.y=1;


            camera.lookAt(new THREE.Vector3(0,0,0));

            //trace('data_move');trace(FocalPoint);trace(camera.up);    
        trace('data_move');trace(camera.position);trace(camera.up); 
            camera.updateMatrix();

        $('#info').html('<div>Up.X:'+camera.up.x+' Up.Y:'+camera.up.y+' Up.Z:'+camera.up.z+'</div><div>X:'+camera.position.x+' Y:'+camera.position.y+' Z:'+camera.position.z+'</div><div>Phi:'+phi+' Theta:'+theta+' Radious:'+radious+'</div><div>'+FocalPoint+'</div>')

        });
        renderer.domElement.addEventListener('mousedown', function(e) {
            paused = false;
            lastLeft = e.clientX;
            lastTop = e.clientY;
            onMouseDownTheta = theta;
            onMouseDownPhi = phi;
             //$('#vtkPic').show();
        });
        renderer.domElement.addEventListener('mouseup', function(e) {
            moving = paused = true;
            counter = 0
            trace('data_move');trace(camera.position);trace(camera.up); 
        //$('#vtkPic').hide();
        if(camera.up.y == 1)
            comm.makeRequest("vtk", {
                mode: curVtkConf.mode,
                command: "set_camera",
                up: {'x': camera.up.x,'y': camera.up.y,'z': camera.up.z},
                position: {'x': camera.position.x,'y': camera.position.y,'z': camera.position.z},
            });         
        });

飞腾:

    def set_camera(self, position, up):
            '''
            Поворот в жестко заданную позицию.
            '''
            self.move_to_origin()
            bounds = self.src_actor.GetBounds()
            camera = self.renderer.GetActiveCamera()
            x, y, z = camera.GetPosition()
            edge = None
            camera.SetPosition(position['x'], position['y'], position['z'])

            camera.SetViewUp(up['x'], up['y'], up['z'])
            self.world_coords_to_pixel_ratio = self._get_world_coords_to_pixel_ratio()
            camera.OrthogonalizeViewUp()

            self.renderer.ResetCameraClippingRange()
            self.renderer.ResetCamera()   

我解决了这个问题,但知道围绕 Y 旋转存在问题

在此处输入图像描述

4

0 回答 0