Panorama1.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import * as THREE from "../../../libs/three.js/build/three.module.js";
  2. var texLoader = new THREE.TextureLoader()
  3. let standardMarkerMat = new THREE.MeshBasicMaterial({side: THREE.DoubleSide , map:texLoader.load('../resources/textures/marker.png') ,transparent:true})
  4. let panoHeight = 2.3;
  5. let planeGeo = new THREE.PlaneBufferGeometry(1,1);
  6. let sg = new THREE.SphereGeometry(1, 8, 8);
  7. let sm = new THREE.MeshBasicMaterial({side: THREE.BackSide});
  8. var rot90 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,1,0), Math.PI/2); //这里旋转还是基于原先的坐标轴,因为是先有图片的旋转后有skybox整体的旋转。但是角度不是负的是正的。
  9. class Panorama{
  10. constructor(o){//file, time, longitude, latitude, altitude, course, pitch, roll
  11. this.file = o.file;
  12. this.time = o.time;
  13. this.longitude = o.long;
  14. this.latitude = o.lat;
  15. this.altitude = o.alt;
  16. this.course = o.course;
  17. this.pitch = o.pitch;
  18. this.roll = o.roll;
  19. this.transform = o.transform
  20. this.mesh = null;
  21. let xy = this.transform.forward([this.longitude, this.latitude]);
  22. this.position = new THREE.Vector3(xy[0], xy[1], o.alt)
  23. this.build()
  24. }
  25. build(){
  26. let mesh = new THREE.Mesh(sg, sm);
  27. mesh.position.copy(this.position)
  28. mesh.scale.set(1, 1, 1);
  29. mesh.material.transparent = true;
  30. mesh.material.opacity = 0.75;
  31. mesh.pano = this;
  32. { // orientation
  33. var {course, pitch, roll} = this;
  34. mesh.rotation.set(
  35. THREE.Math.degToRad(+roll + 90),
  36. THREE.Math.degToRad(-pitch),
  37. THREE.Math.degToRad(-course + 90),
  38. "ZYX"
  39. );
  40. //add
  41. var quaternion = new THREE.Quaternion().multiplyQuaternions(mesh.quaternion, rot90);//改 为球目全
  42. this.panoMatrix = new THREE.Matrix4().makeRotationFromQuaternion(quaternion)
  43. }
  44. this.mesh = mesh;
  45. let marker = new THREE.Mesh(planeGeo, standardMarkerMat)
  46. marker.position.copy(mesh.position);
  47. marker.position.z -= panoHeight
  48. marker.scale.set(2,2,2)
  49. this.marker = marker
  50. }
  51. };
  52. export default Panorama