当前位置:网站首页>【three.js】WEB3D初次体验
【three.js】WEB3D初次体验
2022-06-30 00:41:00 【Justkang前端】
什么是three.js
目前公司项目需要的原因,我要进行学习web大屏可视化,除了要展示一些图表外,还需要展示一些大楼的3D模型,于是webGL three.js
这两个名词就进入了我的大脑词库。 像是打开了新世界的大门一样,发现许多网站的特效(github 的大地球)都是three.js
写的,那我们就一起来探究吧
vite 开启一个 vue3项目(正好练练vue3+ts)
npm init [email protected] my-vue-app --template vue
vite真的快
npm 安装three.js
npm i three
// vue引入
import * as THREE from 'three';
根据官网写出我的一个 3D 模型
// demo1.js //
import * as THREE from 'three';
// 创建场景
const scene = new THREE.Scene();
// 创建相机 (四个参数:FOV(场景范围 单位:度),纵横比,near(近), far(远))
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
// 创建一个渲染器
const renderer = new THREE.WebGLRenderer();
// 设置渲染器的大小
renderer.setSize( window.innerWidth/2,window.innerHeight/2 );
// 把渲染器挂到body上 这是渲染器用来向我们显示场景的 <canvas> 元素。
document.body.appendChild( renderer.domElement );
//几何
const geometry = new THREE.BoxGeometry( 2, 2, 10 );
//材料
const material = new THREE.MeshBasicMaterial( {
color: 0xFF0000 } );
//数据集
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 10;
// cube.rotation.x = 5;
// cube.rotation.y = 5;
function animate() {
requestAnimationFrame( animate );
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render( scene, camera );
}
animate();
export default animate
<template>
</template>
<script setup lang="ts"> import animate from "./three/demo1.js"; animate(); </script>
<style> * {
padding: 0; margin: 0; } #app {
font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } </style>
效果

边栏推荐
- 【mysql篇-基础篇】通用语法2
- 初始I/O及其基本操作
- 炒股开户选择哪家券商公司比较好哪家平台更安全
- 视频转图像-cv2.VideoCapture()用法
- 【云原生】容器场景下的内核安全
- [spark] basic Scala operations (continuous update)
- 网工常见面试题分享:Telnet、TTL、路由器与交换机
- The third bullet of wechat payment app application for refund
- Intermittent sampling and forwarding interference
- Comparison between strings localecompare
猜你喜欢

学位论文的引用

@Bugs caused by improper use of configurationproperties

【云原生】容器场景下的内核安全

手写C语言之函数的嵌套调用和链式访问

YuMinHong: my retreat and advance; The five best software architecture patterns that architects must understand; Redis kills 52 consecutive questions | manong weekly VIP member exclusive email weekly

网络方向哪个发展更好?数据通信工程师学习路线分享

Live broadcast configuration of crmeb knowledge payment system program configuration (method 2)

Developers, why does the maturity of container technology herald the arrival of cloud native era?

科创人·味多美CIO胡博:数字化是不流血的革命,正确答案藏在业务的田间地头

IDEA中的常用设置
随机推荐
【服装软件】服装出产办理体系选型的准则有哪些?
How about stock online account opening and account opening process? Also, is it safe to open an account online?
手写C语言之函数的嵌套调用和链式访问
【PHP】PHP变量内存释放
Developers, why does the maturity of container technology herald the arrival of cloud native era?
Top performance version 2 reading notes (IV) -- memory monitoring
Arlo felt lost
@Bugs caused by improper use of configurationproperties
岁月不饶人
leetcode-1. Sum of two numbers
Time does not spare
A Yu's Rainbow Bridge
Database learning notes (sql03)
网络方向哪个发展更好?数据通信工程师学习路线分享
Sofaregistry source code | data synchronization module analysis
Applying for let's encrypt SSL certificate with certbot
About the case of SQL statements
开发者,为什么说容器技术的成熟预示着云原生时代的到来?
mysql 死锁
How to seamlessly transition from traditional microservice framework to service grid ASM