1 Star 0 Fork 24

枫中看雨/threejs-demo

forked from 石头/threejs-demo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
bg.html 1.93 KB
一键复制 编辑 原始数据 按行查看 历史
石头 提交于 2022-11-03 09:26 . 增加3d轮播图
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>threejs</title>
</head>
<body style="margin: 0">
<div id="container"></div>
</body>
<script type="importmap">
{
"imports": {
"three": "./node_modules/three/build/three.module.js",
"three/": "./node_modules/three/"
}
}
</script>
<script type="module">
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
// 初始化webgl
const renderer = new THREE.WebGLRenderer( { antialias: true } )
renderer.setPixelRatio( window.devicePixelRatio )
renderer.setSize( window.innerWidth, window.innerHeight )
document.getElementById('container').appendChild( renderer.domElement )
// 初始化相机
const camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 )
camera.position.setZ(10)
// 初始化场景
const scene = new THREE.Scene()
// 相机插件
const controls = new OrbitControls(camera, renderer.domElement)
// 初始化天空盒
const path = './images/skybox1/'
const urls = [
path + '6.png',
path + '3.png',
path + '2.png',
path + '1.png',
path + '5.png',
path + '4.png'
]
const textCube = new THREE.CubeTextureLoader().load(urls)
// textCube.encoding = THREE.sRGBEncoding
scene.background = textCube
// 灯光
const light = new THREE.AmbientLight( 0xff8800, 0.3 )
scene.add( light )
// 窗口自适应
window.addEventListener( 'resize', () => {
camera.aspect = window.innerWidth / window.innerHeight
camera.updateProjectionMatrix()
renderer.setSize( window.innerWidth, window.innerHeight )
})
// 渲染
function animate() {
controls.update()
renderer.render( scene, camera )
requestAnimationFrame(animate)
}
animate()
</script>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/fyypll/threejs-demo.git
git@gitee.com:fyypll/threejs-demo.git
fyypll
threejs-demo
threejs-demo
master

搜索帮助