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

ThreeJS-移動(三)

這篇具有很好參考價值的文章主要介紹了ThreeJS-移動(三)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

關(guān)鍵代碼

通過設置定位信息進行移動

mesh.position.set(0, 0, 0);

拖動物體:按住ctrl+按住鼠標左鍵 進行拖動

代碼:?

<template>

? <div id="three_div">

? </div>

</template>

? <script>

import * as THREE from "three";

import {OrbitControls } from 'three/examples/jsm/controls/OrbitControls'

export default {

? name: "HOME",

? components: {

? ? // vueQr,

? ? // glHome,

? },

? data() {

? ? return {

? ? };

? },

? mounted() {

? ? //使用控制器控制3D拖動旋轉(zhuǎn)OrbitControls

? ? //控制3D物體移動

? ? //1.創(chuàng)建場景

? ? const scene = new THREE.Scene();

? ? console.log(scene)

? ?

? ? //2.創(chuàng)建相機

? ? const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);

? ? //設置相機位置

? ? camera.position.set(0,0,10);

? ? //將相機添加到場景

? ? scene.add(camera);

? ? //添加物體

? ? //創(chuàng)建幾何體

? ? const cubeGeometry = new THREE.BoxGeometry(2,2,2);

? ? const cubeMaterial = new THREE.MeshBasicMaterial({color: 0xffff00});

? ? //根據(jù)幾何體和材質(zhì)創(chuàng)建物體

? ? const mesh ?= new THREE.Mesh(cubeGeometry, cubeMaterial);

? ? //將物體加入到場景

? ? scene.add(mesh);

? ? //添加坐標軸輔助器

? ? const axesHepler = new THREE.AxesHelper(5)

? ? scene.add(axesHepler)

? ? //初始化渲染器

? ? const ?render = new THREE.WebGLRenderer();

? ? //設置渲染器的尺寸

? ? render.setSize(window.innerWidth, window.innerHeight);

? ? //使用渲染器,通過相機將場景渲染進來

? ? //創(chuàng)建軌道控制器,可以拖動,控制的是攝像頭

? ? const controls = new OrbitControls(camera, render.domElement);

? ? //將webgl渲染的canvas內(nèi)容添加到body上

? ? document.getElementById('three_div').appendChild(render.domElement);

? ? //修改3D位置

? ? mesh.position.set(0, 0, 0);

? ?// render.render(scene, camera);

? ? //渲染下一幀的時候就會調(diào)用回調(diào)函數(shù)

? ? let i=1;

? ? let renderFun = ()=>{

? ? ? mesh.position.x += 0.02*i;

? ? ? if(mesh.position.x >= 5){

? ? ? ? i = -1;

? ? ? }

? ? ? if(mesh.position.x <= 0){

? ? ? ? i = 1;

? ? ? }

? ? ? console.log(1)

? ? ? //需要重新繪制canvas畫布

? ? ? render.render(scene, camera);

? ? ? //監(jiān)聽屏幕刷新(60HZ,120HZ),每次刷新觸發(fā)一次requestAnimationFrame回調(diào)函數(shù)

? ? ? //但是requestAnimationFrame的回調(diào)函數(shù)注冊生命只有一次,因此需要循環(huán)注冊,才能達到一直調(diào)用的效果

? ? ? window.requestAnimationFrame(renderFun);

? ? }

? ?// window.requestAnimationFrame(renderFun);

? ? renderFun();


?

? },

? ?methods: {

? },

};

</script>

<style scoped lang="scss">

</style>

效果圖:

?ThreeJS-移動(三)文章來源地址http://www.zghlxwxcb.cn/news/detail-496510.html

到了這里,關(guān)于ThreeJS-移動(三)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

領(lǐng)支付寶紅包贊助服務器費用

相關(guān)文章

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包