当前位置:网站首页>【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>
效果

边栏推荐
- What is the essential difference between get and post requests?
- 阿四的情绪波动
- 【PHP】PHP变量内存释放
- MySQL foundation 2
- DL:深度学习模型优化之模型训练技巧总结之适时自动调整学习率实现代码
- Interviewer: why does database connection consume resources? I can't even answer.. I was stunned!
- 炒股开户选择哪家证券公司比较好哪家平台更安全
- Traffic, but no sales? 6 steps to increase website sales
- @ConfigurationProperties使用不当引发的bug
- modbus-tcp-rtu协议图表
猜你喜欢

干外包3年,真废了...

Too voluminous ~ eight part essay, the strongest king of interview!

分布式任务调度 ElasticJob demo

太卷了~ 八股文,面试最强王者!

Yunna | fixed assets system management, NC system management where are the fixed assets

MySQL deadlock

如何在IDEA中自定義模板、快速生成完整的代碼?

外包干了三年,废的一踏糊涂...

Interviewer: why does database connection consume resources? I can't even answer.. I was stunned!

Sword finger offer II 037 Asteroid collision
随机推荐
In 2022, the latest and most detailed idea associated database method and visual operation of database in idea (including graphic process)
Modbus TCP RTU protocol chart
leetcode-1. Sum of two numbers
降低打新的预期
HDCP Paring
Go out and protect yourself
博途V16 更改PLC的型号和固件版本
[graduation season 𞓜 advanced technology Er] employees who have worked for seven years do not want you to take another detour
MySQL Foundation 2
@ConfigurationProperties使用不当引发的bug
Sofaregistry source code | data synchronization module analysis
Go 中的 UDP 服务器和客户端
岁月不饶人
【UML】UML的几种关系(依赖-关联-聚合-组合-继承-实现)
【云原生】容器场景下的内核安全
Byte, word, doubleword relationship
网络方向哪个发展更好?数据通信工程师学习路线分享
月薪没到30K的程序员必须要背的面试八股,我先啃为敬!
玉米地里的小鸟
MySQL基础篇1