This commit is contained in:
ann 2023-03-08 11:47:24 +08:00
parent dd4d96a057
commit 8427fac534
1 changed files with 58 additions and 12 deletions

View File

@ -42,7 +42,7 @@ export default {
getEarthRegion().then(res => {
const demo = res.data
const that = this
for (let i = 0; i < demo.length; i++) {
for (let i = 0; i < 6; i++) {
const modelItem = []
const value = []
modelItem['name'] = demo[i].area
@ -69,7 +69,6 @@ export default {
// cancelAnimationFrame(this.aniId)
this.orbitControls.autoRotate = false//
// this.camera.zoom = 2.3
console.log()
this.scene.children[6].visible = false
this.scene.children[7].visible = false
this.scene.children[8].visible = false
@ -89,15 +88,16 @@ export default {
// var zoom = { val: this.camera.zoom }
// var zoomEnd = { value: 2.3 }
const tweenL2 = new TWEEN.Tween(this.camera).to({ left: -s * k, right: s * k, top: s, bottom: -s }, 1000).easing(TWEEN.Easing.Sinusoidal.InOut)
// .onUpdate(() => {
// this.camera.zoom = 2.3
// })
.onUpdate(() => {
// this.camera.zoom = 2.3
this.scene.children[4].material.color.copy(new Three.Color(0x0a263e))
})
tweenL1.chain(tweenL2).start()
this.renderChinaDetailData()
},
renderChinaDetailData() {
// chinamap
// this.scene.children[2].visible = false
// this.scene.children[4].visible = false
// this.setRandomDot(this.mapMarks)
const groupLines = new Three.Group()
this.mapMarks.forEach(r => {
@ -107,6 +107,52 @@ export default {
}
})
this.scene.add(groupLines)
// this.setChinaMark(this.mapMarks)
},
setChinaMark(_markData) {
for (var i = 0; i < _markData.length; i++) {
var markPos = this.getPosition(_markData[i].value[0] + 90, _markData[i].value[1], 100)
// mark.position.set(markPos.x, markPos.y, markPos.z)
var textureLoader = new Three.TextureLoader()
var material = new Three.MeshBasicMaterial({
map: textureLoader.load(process.env.VUE_APP_PUBLIC_SOURCE_API + '/point.png'),
transparent: true, // 使png
blending: Three.AdditiveBlending,
// side: THREE.DoubleSide, //
depthWrite: false //
})
var mesh = new Three.Mesh(new Three.PlaneGeometry(8, 8, 3, 3), material)
// var size = 10 * 0.04// Mesh
// mesh.scale.set(size, size, size)// mesh
// mesh
mesh.position.set(markPos.x, markPos.y, markPos.z)
// mesh线()
var coordVec3 = new Three.Vector3(markPos.x, markPos.y, markPos.z).normalize()
// meshXOY线沿znew THREE.Vector3(0, 0, 1)
var meshNormal = new Three.Vector3(0, 0, 1)
// .quaternionmesh
// .setFromUnitVectors();
mesh.quaternion.setFromUnitVectors(meshNormal, coordVec3)
this.marking.add(mesh)
// eg: 18
var texture = new Three.CanvasTexture(this.getCanvasFont(_markData[i].name + '' + _markData[i].count + '个'))
//
const fontNumber = _markData[i].count.toString().length * 5.8642578125 + _markData[i].name.length * 10 + 10 + 2.4072265625 + 5
texture.needsUpdate = true
var fontMesh = new Three.Sprite(
new Three.SpriteMaterial({
map: texture
})
)
fontMesh.scale.x = fontNumber
fontMesh.scale.y = 10
fontMesh.position.set(markPos.x + 10, markPos.y + 10, markPos.z - 20)
this.textMarking.add(fontMesh)
}
this.scene.add(this.marking)
this.scene.add(this.textMarking)
},
lineConnect(posStart, posEnd) {
// 3D z
@ -259,7 +305,7 @@ export default {
},
initLight() {
const ambientLight = new Three.AmbientLight(0xcccccc, 1.1)
this.scene.add(ambientLight) // 1
this.scene.add(ambientLight) // 0
var directionalLight = new Three.DirectionalLight(0xffffff)
directionalLight.position.set(1, 500, -20)
directionalLight.castShadow = true
@ -267,7 +313,7 @@ export default {
directionalLight.shadow.camera.bottom = -10
directionalLight.shadow.camera.left = -52
directionalLight.shadow.camera.right = 12
this.scene.add(directionalLight) // 2
this.scene.add(directionalLight) // 1
},
initControl() {
this.orbitControls = new OrbitControls(this.camera, this.renderer.domElement)
@ -288,7 +334,7 @@ export default {
var textureLoader = new Three.TextureLoader()
textureLoader.load(process.env.VUE_APP_PUBLIC_SOURCE_API + '/earth.jpg', (texture) => {
var material = new Three.MeshLambertMaterial({
// color: 0x0000ff,
// color: 0x0a263e,
transparent: true,
opacity: 0.96,
map: texture
@ -301,7 +347,7 @@ export default {
})
this.mesh = new Three.Mesh(geometry, material)
this.mesh2 = new Three.Mesh(geometry, material2)
this.scene.add(this.mesh) // 4
this.scene.add(this.mesh) // 4
this.scene.add(this.mesh2) // 5
this.setMark(this.mapMarks) //
this.setAreaMark(this.area)
@ -343,7 +389,7 @@ export default {
const coordinates = elem.geometry.coordinates
coordinates.forEach(multiPolygon => {
multiPolygon.forEach(polygon => {
const lineMaterial = new Three.LineBasicMaterial({ color: 0x3BFA9E })
const lineMaterial = new Three.LineBasicMaterial({ color: 0x3EDFFC })
const positions = []
const lineGeometry = new Three.BufferGeometry()
for (let i = 0; i < polygon.length; i++) {
@ -538,7 +584,7 @@ export default {
fontMesh.position.set(markPos.x - 30, markPos.y - 10, markPos.z - 20)
this.scene.add(fontMesh) // 8
},
//
//
setMark(_markData) {
this.marking = new Three.Group() // 6
this.textMarking = new Three.Group() // 7