three实现三维立方体盒子悬浮空间转动效果代码
代码语言:html
所属分类:三维
代码描述:three实现三维立方体盒子悬浮空间转动效果代码
代码标签: three 三维 立方体 盒子 悬浮 空间 转动
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body{ background-color: black; overflow: hidden; } canvas{ position: fixed; top: 0; left: 0; } </style> <script type="importmap"> { "imports": { "three": "//repo.bfw.wiki/bfwrepo/js/module/three/build/164/three.module.js", "three/addons/": "//repo.bfw.wiki/bfwrepo/js/module/three/examples/164/jsm/" } } </script> </head> <body translate="no"> <canvas id="bg1"></canvas> <script type="module"> import * as THREE from 'three'; import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; const scene = new THREE.Scene(); scene.background = new THREE.Color(0x000); const camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 10000); camera.position.setZ(30); const renderer = new THREE.WebGLRenderer({ canvas: document.querySelector("#bg1"), }) renderer.setPixelRatio(window.devicePixelRatio); renderer.setSize(window.innerWidth, window.innerHeight); renderer.render(scene, camera); const controls = new OrbitControls(camera, renderer.domElement); const lights = new THREE.AmbientLight(0xffffff, 10); scene.add(lights) let index = 0; function addBox(){ const boxgeometry = new THREE.BoxGeometry(6, 6, 6); const boxmaterial = [ new THREE.MeshBasicMaterial({color: 0xffffff, side: THREE.DoubleSide, wirefr.........完整代码请登录后点击上方下载按钮下载查看
网友评论0