mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-06 03:58:04 +08:00
fix: 解决了三维地球不能被截图的bug
This commit is contained in:
parent
cdc3184931
commit
5387be85ce
@ -1,62 +1,63 @@
|
|||||||
/**
|
/**
|
||||||
* 创建 threejs 四大天王
|
* 创建 threejs 四大天王
|
||||||
* 场景、相机、渲染器、控制器
|
* 场景、相机、渲染器、控制器
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as THREE from 'three'
|
import * as THREE from 'three'
|
||||||
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
|
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
|
||||||
|
|
||||||
export class Basic {
|
export class Basic {
|
||||||
public scene!: THREE.Scene
|
public scene!: THREE.Scene
|
||||||
public camera!: THREE.PerspectiveCamera
|
public camera!: THREE.PerspectiveCamera
|
||||||
public renderer!: THREE.WebGLRenderer
|
public renderer!: THREE.WebGLRenderer
|
||||||
public controls!: OrbitControls
|
public controls!: OrbitControls
|
||||||
public dom: HTMLElement
|
public dom: HTMLElement
|
||||||
|
|
||||||
constructor(dom: HTMLElement) {
|
constructor(dom: HTMLElement) {
|
||||||
this.dom = dom
|
this.dom = dom
|
||||||
this.initScenes()
|
this.initScenes()
|
||||||
this.setControls()
|
this.setControls()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化场景
|
* 初始化场景
|
||||||
*/
|
*/
|
||||||
initScenes() {
|
initScenes() {
|
||||||
this.scene = new THREE.Scene()
|
this.scene = new THREE.Scene()
|
||||||
|
|
||||||
this.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 100000)
|
this.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 100000)
|
||||||
this.camera.position.set(0, 30, -250)
|
this.camera.position.set(0, 30, -250)
|
||||||
|
|
||||||
this.renderer = new THREE.WebGLRenderer({
|
this.renderer = new THREE.WebGLRenderer({
|
||||||
// canvas: this.dom,
|
// canvas: this.dom,
|
||||||
alpha: true, // 透明
|
alpha: true, // 透明
|
||||||
antialias: true // 抗锯齿
|
antialias: true, // 抗锯齿
|
||||||
})
|
preserveDrawingBuffer: true
|
||||||
this.renderer.setPixelRatio(window.devicePixelRatio) // 设置屏幕像素比
|
})
|
||||||
this.renderer.setSize(window.innerWidth, window.innerHeight) // 设置渲染器宽高
|
this.renderer.setPixelRatio(window.devicePixelRatio) // 设置屏幕像素比
|
||||||
this.dom.appendChild(this.renderer.domElement) // 添加到dom中
|
this.renderer.setSize(window.innerWidth, window.innerHeight) // 设置渲染器宽高
|
||||||
}
|
this.dom.appendChild(this.renderer.domElement) // 添加到dom中
|
||||||
|
}
|
||||||
/**
|
|
||||||
* 设置控制器
|
/**
|
||||||
*/
|
* 设置控制器
|
||||||
setControls() {
|
*/
|
||||||
// 鼠标控制 相机,渲染dom
|
setControls() {
|
||||||
this.controls = new OrbitControls(this.camera, this.renderer.domElement)
|
// 鼠标控制 相机,渲染dom
|
||||||
|
this.controls = new OrbitControls(this.camera, this.renderer.domElement)
|
||||||
this.controls.autoRotateSpeed = 3
|
|
||||||
// 使动画循环使用时阻尼或自转 意思是否有惯性
|
this.controls.autoRotateSpeed = 3
|
||||||
this.controls.enableDamping = true
|
// 使动画循环使用时阻尼或自转 意思是否有惯性
|
||||||
// 动态阻尼系数 就是鼠标拖拽旋转灵敏度
|
this.controls.enableDamping = true
|
||||||
this.controls.dampingFactor = 0.05
|
// 动态阻尼系数 就是鼠标拖拽旋转灵敏度
|
||||||
// 是否可以缩放
|
this.controls.dampingFactor = 0.05
|
||||||
this.controls.enableZoom = true
|
// 是否可以缩放
|
||||||
// 设置相机距离原点的最远距离
|
this.controls.enableZoom = true
|
||||||
this.controls.minDistance = 100
|
// 设置相机距离原点的最远距离
|
||||||
// 设置相机距离原点的最远距离
|
this.controls.minDistance = 100
|
||||||
this.controls.maxDistance = 300
|
// 设置相机距离原点的最远距离
|
||||||
// 是否开启右键拖拽
|
this.controls.maxDistance = 300
|
||||||
this.controls.enablePan = false
|
// 是否开启右键拖拽
|
||||||
}
|
this.controls.enablePan = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user