three实现三维立方体盒子内粒子重力滚动动画效果代码
代码语言:html
所属分类:三维
代码描述:three实现三维立方体盒子内粒子重力滚动动画效果代码
代码标签: three 三维 立方体 盒子 粒子 重力 滚动 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
html, body {
padding: 0;
margin: 0;
}
.container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
}
</style>
</head>
<body >
<div class="container">
<canvas id="canvas"></canvas>
</div>
<script type="importmap">{
"imports": {
"three": "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.145.0/three.module.min.js",
"three/addons/": "https://threejs.org/examples/jsm/"
}
}
</script>
<script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>
<script type="module">
import * as CANNON from "https://cdn.skypack.dev/cannon-es";
import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
import { RoundedBoxGeometry } from "three/addons/geometries/RoundedBoxGeometry.js";
const canvasEl = document.querySelector("#canvas");
const containerEl = document.querySelector(".container");
let renderer,scene,camera,orbit,physicsWorld,boxMaterial,dummy,instancedBoxesMesh,boxesBodies = [];
const params = {
boxesNumber: 100,
boxSize: .03,
containerSize: 1,
gravity: 10 };
initPhysics();
initScene();
throwBoxes();
boxMaterial.visible = true;
render();
window.addEventListener("resize", updateSceneSize);
containerEl.addEventListener("dblclick", throwBoxes);
function initScene() {
renderer = new THREE.WebGLRenderer({
antialias: true,
canvas.........完整代码请登录后点击上方下载按钮下载查看
网友评论0