阿里云国际,腾讯云国际,AWS 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov8 |
1 创建场景
2 创建相机
3 创建地球模型
4 创建卫星中心
5 创建卫星圆环及卫星
6 创建控制器
7 创建渲染器
<template>
<div class="home3dMap" id="home3dMap"></div>
</template>
<script>
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
export default {
name:"home3dMap",
data(){
return {
scene:null,
camera:null,
meshMaterial:null,
controls:null,
renderer:null,
satellites:[],
}
},
components:{},
created(){},
beforeDestroy(){},
mounted(){
this.init();
},
methods:{
init(){
this.createScene();
this.createMesh();
this.createLight();
this.createCamera();
this.createRender();
this.createControls();
this.animate();
},
createScene(){
let scene = new THREE.Scene();
this.scene = scene;
},
createMesh(){
let geometry = new THREE.SphereGeometry( 70, 32, 16);
let earthImgSrc = require('@/assets/img/home/home3dMapBackground.png');
let earthMater = new THREE.MeshPhongMaterial({
map: new THREE.TextureLoader().load(earthImgSrc),
transparent:true,
depthWrite:false,
});
let meshMaterial = new THREE.Mesh(geometry,earthMater);
this.meshMaterial = meshMaterial;
this.scene.add(meshMaterial);
this.initSatellite(meshMaterial);
},
initSatellite(meshMaterial){
let sadImgSrc = require('@/assets/img/control/satellite.png');
for(let i=0; i<3; i++){
let satelliteSize = 12,satelliteRadius=0,rotation={x:0,y:0,z:0},speed=0;
if(i==0){
satelliteRadius = 80;
rotation.x = -Math.PI * 0.35;
rotation.y = Math.PI * 0.25;
rotation.z = 0;
speed = 0.004;
}else if(i==1){
satelliteRadius =100;
rotation.x = -Math.PI * 0.35;
rotation.y = -Math.PI * 0.2;
rotation.z = 0;
speed = 0.005;
}else{
satelliteRadius = 86;
rotation.x = -Math.PI * 0.25;
rotation.y = Math.PI * 0.15;
rotation.z = 0;
speed = 0.003;
}
let earthGeometry = new THREE.SphereGeometry(0,0,0);
let earthMater = new THREE.MeshPhongMaterial({
color:0xa0a0a0,
});
let centerMesh = new THREE.Mesh(earthGeometry,earthMater);
let circleGeometry = new THREE.RingGeometry(satelliteRadius, satelliteRadius + 0.3, 100, 1);
let circleMater = new THREE.MeshBasicMaterial({
color:0xffffff,
side: THREE.DoubleSide
})
let track = new THREE.Mesh(circleGeometry,circleMater);
let satellite = new THREE.Sprite(new THREE.SpriteMaterial({
map: new THREE.TextureLoader().load(sadImgSrc),
blending: THREE.AdditiveBlending
}));
satellite.scale.x = satellite.scale.y = satellite.scale.z = 12;
satellite.position.set(satelliteRadius, 0, 0);
let pivotPoint = new THREE.Object3D();
pivotPoint.add(satellite);
pivotPoint.add(track);
centerMesh.add(pivotPoint);
centerMesh.rotation.set(rotation.x, rotation.y, rotation.z);
this.scene.add(centerMesh);
this.satellites.push({satellite:centerMesh, speed:speed, address:rotation});
}
},
createLight(){
const ambientLight = new THREE.AmbientLight(0xcccccc, 2)
this.scene.add(ambientLight)
let directionalLight = new THREE.DirectionalLight(0xffffff, 0.2)
directionalLight.position.set(1, 0.2, 0).normalize()
let directionalLight2 = new THREE.DirectionalLight(0xff2ffff, 0.2)
directionalLight2.position.set(1, 0.2, 0.1).normalize()
this.scene.add(directionalLight)
this.scene.add(directionalLight2)
let directionalLight3 = new THREE.DirectionalLight(0xffffff, 0)
directionalLight3.castShadow = true
this.scene.add(directionalLight3)
},
createCamera(){
let camera = new THREE.PerspectiveCamera(60, 960 / 685, 1, 10000)
camera.position.set(50, -10, 200)
camera.lookAt(0, 0, 0)
this.camera = camera;
this.scene.add(this.camera);
},
createRender(){
let element = document.getElementById("home3dMap");
let renderer = new THREE.WebGLRenderer({antialias:true, alpha:true})
renderer.setSize(960,685)
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x3f3f3f, 0);
this.renderer = renderer;
element.appendChild(this.renderer.domElement)
},
createControls(){
let controls = new OrbitControls(this.camera, this.renderer.domElement);
controls.enableDamping = true;
controls.maxZoom = Infinity;
this.controls = controls;
},
animate(){
this.controls.update();
this.meshMaterial.rotation.y += 0.0015;
this.renderer.render(this.scene, this.camera);
for(let i=0; i<this.satellites.length; i++){
this.satellites[i].satellite.rotation.z -= this.satellites[i].speed;
}
requestAnimationFrame(this.animate.bind(this));
},
},
}
</script>
<style>
.home3dMap{
width:100%;
height:100%;
}
</style>

阿里云国际,腾讯云国际,AWS 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov8 |