国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Vue.js2+Cesium1.103.0 十、加載 Three.js

這篇具有很好參考價(jià)值的文章主要介紹了Vue.js2+Cesium1.103.0 十、加載 Three.js。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

Vue.js2+Cesium1.103.0 十、加載 Three.js

Vue.js2+Cesium1.103.0 十、加載 Three.js,javascript,vue.js,前端,gis

Demo

ThreeModel.vue

<template>
  <div
    id="three_container"
    class="three_container"
  />
</template>

<script>
/* eslint-disable eqeqeq */
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */
/* eslint-disable no-caller */
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader'
// import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js'
// import { FBXLoader } from 'three/examples/jsm/loaders/FBXLoader.js'
export default {
  name: 'ThreeModel',
  props: {},
  data() {
    return {
      modelMixer: null,
      modelClock: null,
      modelAnimationAction: null,
      modelAnimationAction2: null,
      model: null,
      scene: null,
      camera: null,
      renderer: null,
      textureLoader: null,
      groupBox: null,
      control: null,
      enableRotate: null
    }
  },
  computed: {},
  watch: {},
  mounted() {
    window.cancelAnimationFrame(this.clearAnim)
    this.init()
  },
  beforeDestroy() {
    window.cancelAnimationFrame(this.clearAnim)
  },
  methods: {
    async init() {
      const _this = this
      const element = document.getElementById('three_container')
      const width = element.clientWidth // 窗口寬度
      const height = element.clientHeight // 窗口高度
      // 場(chǎng)景
      this.scene = new THREE.Scene()
      // this.scene.background = new THREE.Color(0x000000, 0)
      this.scene.background = null

      // 相機(jī)
      const k = width / height // 窗口寬高比
      const s = 400 // 三維場(chǎng)景顯示范圍控制系數(shù),系數(shù)越大,顯示的范圍越大
      // this.camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.1, 1000) // 透視攝像機(jī)
      this.camera = new THREE.OrthographicCamera(-s * k, s * k, s, -s, 1, 1000) // 正交攝像機(jī)
      // 設(shè)置攝像機(jī)位置,相機(jī)方向逆X軸方向,傾斜向下看
      this.camera.position.set(0, 180, 360)
      // this.camera.rotation.order = 'YXZ'
      // 指向場(chǎng)景中心
      this.camera.lookAt(this.scene.position)

      // 渲染器
      this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true })
      // 設(shè)置環(huán)境
      this.renderer.setClearColor(0x000000, 0)
      // 設(shè)置場(chǎng)景大小
      this.renderer.setSize(600, 600)
      // 渲染器開啟陰影效果
      this.renderer.shadowMap.enabled = true

      // 紋理加載器
      this.textureLoader = new THREE.TextureLoader()

      // 組合對(duì)象
      this.groupBox = new THREE.Group()

      // 坐標(biāo)軸
      // const axes = new THREE.AxesHelper(1000)
      // this.scene.add(axes)

      // 點(diǎn)光源
      const point = new THREE.PointLight(0xffffff)
      point.position.set(500, 300, 400) // 點(diǎn)光源位置
      this.scene.add(point) // 點(diǎn)光源添加到場(chǎng)景中

      // 環(huán)境光
      const ambient = new THREE.AmbientLight(0xffffff, 0.8)
      this.scene.add(ambient)

      element.appendChild(this.renderer.domElement)

      // 相機(jī)控件
      this.control = new OrbitControls(this.camera, this.renderer.domElement)
      this.control.enableDamping = true
      // 動(dòng)態(tài)阻尼系數(shù) 就是鼠標(biāo)拖拽旋轉(zhuǎn)靈敏度,阻尼越小越靈敏
      this.control.dampingFactor = 0.5
      // 是否可以縮放
      this.control.enableZoom = true
      // 是否自動(dòng)旋轉(zhuǎn)
      this.control.autoRotate = false
      // 設(shè)置相機(jī)距離原點(diǎn)的最近距離
      this.control.minDistance = 20
      // 設(shè)置相機(jī)距離原點(diǎn)的最遠(yuǎn)距離
      this.control.maxDistance = 1000
      // 是否開啟右鍵拖拽
      this.control.enablePan = true
      // 上下翻轉(zhuǎn)的最大角度
      this.control.maxPolarAngle = 1.5
      // 上下翻轉(zhuǎn)的最小角度
      this.control.minPolarAngle = 0.0
      // 是否可以旋轉(zhuǎn)
      this.enableRotate = true

      // 加載模型
      const loader = new GLTFLoader()
      await loader.load(
        'model/Cesium_Air.glb',
        gltf => {
          gltf.scene.name = 'Cesium_Air'
          gltf.scene.scale.set(20, 20, 20) //  設(shè)置模型大小縮放
          gltf.scene.position.set(0, 0, 0)
          gltf.scene.translateY(0)
          _this.modelMixer = new THREE.AnimationMixer(gltf.scene)
          _this.modelClock = new THREE.Clock()
          // http://www.yanhuangxueyuan.com/threejs/docs/index.html#api/zh/animation/AnimationAction
          _this.modelAnimationAction = _this.modelMixer.clipAction(
            gltf.animations[0]
          )
          _this.modelAnimationAction.timeScale = 1
          // _this.modelAnimationAction.loop = THREE.LoopOnce // 播放一次
          _this.modelAnimationAction.clampWhenFinished = true
          _this.modelAnimationAction2 = _this.modelMixer.clipAction(
            gltf.animations[1]
          )
          _this.modelAnimationAction2.timeScale = 1
          // _this.modelAnimationAction2.loop = THREE.LoopOnce // 播放一次
          _this.modelAnimationAction2.clampWhenFinished = true
          _this.scene.add(gltf.scene)
          _this.model = gltf.scene
        },
        _xhr => {
          // console.log((_xhr.loaded / _xhr.total) * 100 + '% loaded')
        },
        _error => {
          // console.error(_error)
        }
      )

      const animate = () => {
        // 循環(huán)調(diào)用函數(shù)
        this.clearAnim = requestAnimationFrame(animate)
        // 更新相機(jī)控件
        this.control.update()
        // 渲染界面
        this.renderer.render(this.scene, this.camera)
        if (this.modelMixer) {
          // modelClock.getDelta() 方法獲得兩幀的時(shí)間間隔
          // 更新混合器相關(guān)的時(shí)間
          this.modelMixer.update(this.modelClock.getDelta())
        }
      }
      animate()
    }
  }
}
</script>

<style lang="scss" scoped>
.three_container {
  position: absolute;
  z-index: 999;
  top: 50%;
  left: 50%;
  width: 600px;
  height: 600px;
  transform: translateX(-50%) translateY(-50%);
  overflow: hidden;
}
</style>

index.vue文章來源地址http://www.zghlxwxcb.cn/news/detail-679753.html

<template>
  <div
    id="cesium-container"
    style="width: 100%; height: 100%;"
  >
    <div style="position: absolute;right: 50px;top: 100px;z-index: 9;">
      <div>
        <button @click="handlePlay('play')">播放動(dòng)畫</button>
        <button @click="handlePlay('reverse')">播放動(dòng)畫(反)</button>
        <button @click="handlePlay('paused')">暫停</button>
        <button @click="handlePlay('stop')">停止動(dòng)畫</button>
      </div>
      <div>
        <button @click="handlePlay2('play')">播放動(dòng)畫</button>
        <button @click="handlePlay2('stop')">停止動(dòng)畫</button>
      </div>
    </div>
    <ThreeModel ref="ThreeModel" />
  </div>
</template>

<script>
/* eslint-disable no-undef */
/* eslint-disable no-caller */
/* eslint-disable eqeqeq */
import ThreeModel from './components/ThreeModel.vue'

export default {
  components: {
    ThreeModel
  },
  data() {
    return {
      paused: false
    }
  },
  computed: {},
  watch: {},
  mounted() {
    window.$InitMap()
  },
  methods: {
    handlePlay2(val) {
      if (val === 'play') {
        this.$refs.ThreeModel.modelAnimationAction2.play()
      } else if (val === 'stop') {
        this.$refs.ThreeModel.modelAnimationAction2.stop()
      }
    },
    handlePlay(val) {
      if (val === 'play') {
        this.$refs.ThreeModel.modelAnimationAction.paused = true
        this.$refs.ThreeModel.modelAnimationAction.timeScale = 1
        this.$refs.ThreeModel.modelAnimationAction.paused = false
        this.$refs.ThreeModel.modelAnimationAction.play()
      } else if (val === 'reverse') {
        this.$refs.ThreeModel.modelAnimationAction.paused = true
        this.$refs.ThreeModel.modelAnimationAction.timeScale = -1
        this.$refs.ThreeModel.modelAnimationAction.paused = false
        this.$refs.ThreeModel.modelAnimationAction.play()
      } else if (val === 'paused') {
        this.paused = !this.paused
        this.$refs.ThreeModel.modelAnimationAction.paused = this.paused
      } else if (val === 'stop') {
        this.$refs.ThreeModel.modelAnimationAction.stop()
      }
    }
  }
}
</script>

<style lang="scss">
.btns_container {
  position: absolute;
  z-index: 9;
  color: #fff;
  padding: 20px;
  width: 100%;
  box-sizing: border-box;
  bottom: 100px;
  left: 0;
}
</style>

到了這里,關(guān)于Vue.js2+Cesium1.103.0 十、加載 Three.js的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 【three.js / React-three-fiber】加載3D模型性能優(yōu)化

    【three.js / React-three-fiber】加載3D模型性能優(yōu)化

    無論是大型虛擬世界還是簡(jiǎn)單的網(wǎng)站,性能優(yōu)化都是必要的。 特別是在運(yùn)用三維模型的情況下,我們需要更加深入的優(yōu)化。因?yàn)?三維模型通常包含大量的數(shù)據(jù)和復(fù)雜的幾何形狀 ,如果不進(jìn)行性能優(yōu)化,瀏覽器可能會(huì)因?yàn)樨?fù)載過重而崩潰。 在本文中,我們將探討如何在 thre

    2024年02月02日
    瀏覽(24)
  • Three.js--》建模軟件如何加載外部3D模型?

    Three.js--》建模軟件如何加載外部3D模型?

    目錄 三維建模軟件的介紹 Blender官方文檔介紹 Blender軟件安裝 GLTF格式簡(jiǎn)介 gltf不同文件形式 ????????看過我之前講解的three文章的人都知道,我在創(chuàng)建模型的時(shí)候都沒有使用three.js自帶的一些簡(jiǎn)單模型,而是引入外部的模型并加載到頁面上, 簡(jiǎn)言之 :對(duì)于簡(jiǎn)單的立方體、

    2024年02月06日
    瀏覽(26)
  • Three.js加載FBX模型并解析骨骼動(dòng)畫

    Three.js加載FBX模型并解析骨骼動(dòng)畫

    通過Threejs先加載一個(gè).FBX格式的三維模型文件,然后解析該文件中的骨骼動(dòng)畫信息。? FBX 加載器 FBXLoader.js 加載fbx模型文件 加載模型文件,加載完成后,如果模型顯示位置不符合要求,可以通過Threejs程序進(jìn)行平移、縮放等操作。 查看FBX模型幀動(dòng)畫數(shù)據(jù) stl、obj都是靜態(tài)模型,

    2024年02月07日
    瀏覽(46)
  • Three.js一學(xué)就會(huì)系列:05 加載3D模型

    Three.js一學(xué)就會(huì)系列:05 加載3D模型

    Three.js一學(xué)就會(huì)系列:01 第一個(gè)3D網(wǎng)站 Three.js一學(xué)就會(huì)系列:02 畫線 Three.js一學(xué)就會(huì)系列:03 炫酷3D劃線 Three.js一學(xué)就會(huì)系列:04 炫酷3D文字 最近開始入坑前端3D建站,跟大家一起慢慢深入three.js做網(wǎng)站3D 這篇文章給大家講下 如何加載一個(gè)3D模型 GLTFLoader : 加載GLTF加載器,glT

    2024年02月02日
    瀏覽(20)
  • 【THREE.JS學(xué)習(xí)(3)】使用THREEJS加載GeoJSON地圖數(shù)據(jù)

    【THREE.JS學(xué)習(xí)(3)】使用THREEJS加載GeoJSON地圖數(shù)據(jù)

    本文接著系列文章(2)進(jìn)行介紹,以VUE2為開發(fā)框架,該文涉及代碼存放在HelloWorld.vue中。 相較于上一篇文章對(duì)div命名class等,該文簡(jiǎn)潔許多。 接著引入核心庫 其中,{OrbitControls}為控制器,加載后可以通過鼠標(biāo)來移動(dòng)加載數(shù)據(jù)的方向、放縮等 Three.js中的坐標(biāo)系是以單位為米(

    2023年04月09日
    瀏覽(106)
  • Three.js開發(fā)神器-結(jié)合3DTiles插件加載傾斜攝影模型

    Three.js開發(fā)神器-結(jié)合3DTiles插件加載傾斜攝影模型

    首先我們通過鏈接和圖片來看看效果 演示Demo鏈接地址:https://n3gis.github.io/exportToThree(3.0).html?scene=Demo_4 使用到的軟件(軟件大家到Unity商城上搜索,Unity商城地址:https://assetstore.unity.com) Unity3D 3DTiles(Unity3D插件,用于加載OSGB格式的傾斜攝影數(shù)據(jù)) Export To Three.js(Unity3D插件,

    2023年04月20日
    瀏覽(112)
  • 通過mars3d1.8+cesium1.6根據(jù)坐標(biāo)獲取對(duì)應(yīng)坐標(biāo)在3dtiles模型上的高度

    在前端開發(fā)中,使用地圖和3D模型的需求越來越常見。然而,對(duì)于一些開發(fā)者來說,如何在3D模型上獲取對(duì)應(yīng)坐標(biāo)的高度可能是一個(gè)挑戰(zhàn)。在本文中,我們將介紹如何使用mars3d1.8和cesium1.6這兩個(gè)強(qiáng)大的前端庫來實(shí)現(xiàn)這一功能。 mars3d是一個(gè)基于Cesium的地圖開發(fā)引擎,可以幫助您

    2024年02月12日
    瀏覽(20)
  • Three.js加載外部glb,fbx,gltf,obj 模型文件

    Three.js加載外部glb,fbx,gltf,obj 模型文件

    vue3使用Three.js加載外部模型文件 1.安裝Three.js 2.新建一個(gè)renderModel.js 用于處理Three.js相關(guān)邏輯 3.modelPage.vue 中使用頁面 6.效果圖:

    2024年02月15日
    瀏覽(30)
  • vue結(jié)合Cesium加載gltf模型

    vue結(jié)合Cesium加載gltf模型

    Cesium支持什么格式? ????????Cesium支持的格式包括:3D模型格式(如COLLADA、gITF、OBJ)、影像格式(如JPEG、PNG、GeoTIFF)、地形格式(如STL、Heightmap)、矢量數(shù)據(jù)格式(如GeoJSON、KMZ)、時(shí)間動(dòng)態(tài)數(shù)據(jù)格式(如CZML),以及其他各種數(shù)據(jù)格式。此外,Cesium還通過插件支持其他特

    2024年02月01日
    瀏覽(26)
  • vue中使用cesium 加載shp文件

    vue中使用cesium 加載shp文件

    在cesium中加載shp文件,將shp文件打包為zip,直接加載zip文件,shp文件中需包含這四個(gè)文件 加載代碼 ?

    2024年02月12日
    瀏覽(35)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包