Three.js实现VR看房

准备工作:

1、three . js/r/2019/07/01/l3d 137 S8 endiaddwayui 5l 7 Glu F3 p3ws 888 _ 3000 x 4000 . jpg?x-oss-process=image/resize,m_fill,w_1600,h_920/format,webp ')

?//创建一个材质

?常数材料=新三。MeshBasicMaterial({ map:texture })

?//渲染球体的两侧

?material.side =三。双面;

?//创建网格对象

?const mesh =新三。网格(几何体,材质)

?//网格对象被添加到场景中。

?scene.add(网格)

?//将摄像机放在球体的中心

?相机位置设置(-0.3,0,0)

?//控制器(如果报错,去github复制一个orbitcontrols . js/mrdoob/three . js/blob/dev/examples/js/controls/orbitcontrols . js)。

?const controls = new THREE。OrbitControls(camera,renderer . DOM element);

?controls . addevent listener(" change ",()= & gt{

renderer.render(场景、相机);

?});

?controls . mindistance = 1;

?controls . max distance = 2000;

?controls.enablePan = false

?//调整最大值

?controls . min distance = 1//controls . max distance = 200;

?controls.maxDistance = 2

?函数animate () {

requestAnimationFrame(动画)

renderer.render(场景、相机)

?}

?动画()

?window.onresize = function () {

camera . aspect = window . inner width/window . inner height

camera.updateProjectionMatrix()

renderer . setsize(window . inner width,window.innerHeight)

?}

})()