javascript - 对象旋转控制三个js
问题描述
你好我想用三个js从github索引重建地球
var width = $('#3d-container').width(), height = $('#3d-container').height()
var scene, camera, renderer;
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(120, width/width);
camera.position.set(0,0,1000);
renderer = new THREE.WebGLRenderer({ alpha: true });
renderer.setClearColor( 0x000000, 0 );
renderer.setSize(width+100, width+100);
const geometry = new THREE.SphereGeometry(850, 850, 850);
var material = new THREE.MeshLambertMaterial({
color: 0x006099,
map: new THREE.TextureLoader().load('img/models/textures/texture.jpg')
})
const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
const ambiantlight = new THREE.AmbientLight( 0xffffff, .8 );
scene.add(ambiantlight)
const br_pointLight = new THREE.PointLight( 0x8cc0dc, 5, 700 );
br_pointLight.position.set(250,-250,1000);
const tl_pointLight = new THREE.PointLight( 0xffffff, 4, 500 );
tl_pointLight.position.set(-300,300,1000);
const controls = new THREE.OrbitControls(camera, renderer.domElement, mesh);
controls.rotateSpeed = .15;
controls.enableZoom = false;
controls.enableMove = false;
controls.enableDamping = true;
controls.enablePan = false;
controls.dampingFactor = 0.05;
controls.update();
var lightHolder = new THREE.Group();
lightHolder.add(br_pointLight);
lightHolder.add(tl_pointLight);
scene.add(lightHolder);
$('#3d-container').append(renderer.domElement)
function animate(){
requestAnimationFrame(animate);
renderer.render(scene, camera)
mesh.rotation.y += .0004
mesh.rotation.x += .0002
controls.update();
}
animate()
一切正常,但我想用鼠标移动它,但我添加的灯正在移动(我使用了轨道控制)
我想在不移动灯光的情况下用鼠标旋转行星并产生惯性效果
感谢您阅读本文
解决方案
推荐阅读
- r - 如何使用 gstat 使用 R studio 执行回归克里金法?
- python - cv2.Resize() 在 OpenCV 编译后不起作用
- python - 如何让这个“卡片”类生成卡片对象列表?
- node.js - 连接 ECONNREFUSED 127.0.0.1:587 (nodemailer + mailtrap)
- python - 将 PySpark 数据帧记录到 MLFlow 工件中
- python - Python3 - 如果另一个列表中的值足够接近,则平均一个列表中的值
- java - 调用 RMI 方法会释放同步锁吗?
- java - 如何在java中获取方法?
- mysql - SQL If field is '*' then select from another table
- javascript - 通过引用反应调用方法不起作用