three实现三维铁水滴落下叶片涟漪动画效果代码

代码语言:html

所属分类:三维

代码描述:three实现三维铁水滴落下叶片涟漪动画效果代码

代码标签: three 三维 水滴 落下 叶片 涟漪 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">

  
  
<style>
@import url("https://fonts.googleapis.com/css2?family=Asap&display=swap");
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
  scroll-behavior: smooth;
}
body {
  font-family: "Asap", sans-serif;
  position: relative;
  width: 100%;
  max-width: 100vw;
  height: auto;
  min-height: 100vh;
  text-align: center;
  overflow-x: hidden;
  background: black;
  color: white;

  display: grid;
  place-items: center;
}
canvas {
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
  position: fixed;
  width: 100%;
  max-width: 100vw;
  height: auto;
  min-height: 100vh;
  top: 0;
  left: 0;
  z-index: 0;
}
</style>

  
  
</head>

<body >
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/es-module-shims.1.6.3.js"></script>
<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>

<p>Loading...</p>
  <script src='//repo.bfw.wiki/bfwrepo/js/module/three/examples/164/jsm/libs/ammo.wasm.js'></script>
      <script  type="module">

"use strict";
console.clear();
import * as THREE from "three";
import { OrbitControls as e } from "three/addons/controls/OrbitControls.js";
import { ParametricGeometry as t } from "three/addons/geometries/ParametricGeometry.js";
import * as BufferGeometryUtils from "three/addons/utils/BufferGeometryUtils.js";
import { RGBELoader as n } from "three/addons/loaders/RGBELoader.js";
const o = 25;
async function a() {
  if ("Ammo" in window == !1)
  return void console.error("AmmoPhysics: Couldn't find Ammo.js");
  const e = await Ammo(),
  t = new e.btDefaultCollisionConfiguration(),
  n = new e.btCollisionDispatcher(t),
  a = new e.btDbvtBroadphase(),
  i = new e.btSequentialImpulseConstraintSolver(),
  r = new e.btDiscreteDynamicsWorld(n, a, i, t);
  r.setGravity(new e.btVector3(0, -9.8, 0));
  const c = new e.btTransform();
  let l = new e.btVector3(0, 0, 0),
  d = new e.btQuaternion(0, 0, 0, 0);
  const u = [],
  m = new WeakMap();
  function h(t, n = 0, o = null) {
    const a = function (t, n) {
      t.parameters;
      let o = null;
      if ("convexhull" === n) {
        let n = t.attributes.position.array,
        a = new e.btVector3(0, 0, 0);
        o = new Ammo.btConvexHullShape();
        for (let e = 0, t = n.length; e < t; e += 3) {
          a.setValue(n[e], n[e + 1], n[e + 2]);
          const s = e >= t - 3;
          o.addPoint(a, s);
        }
      } else if ("terrain" === n) return null;
      return o.setMargin(0.05), o;
    }(t.geometry, o);
    null !== a && (
    t.isInstancedMesh ?
    function (t, n, o) {
      const a = t.instanceMatrix.array,
      s = [];
      for (let i = 0; i < t.count; i++) {
        const t = 16 * i,
        c = new e.btTransform();
        c.setFromOpenGLMatrix(a.slice(t, t + 16));
        const l = new e.btDefaultMotionState(c),
        d = new e.btVector3(0, 0, 0);
        o.calculateLocalInertia(n, d);
        const u = new e.btRigidBodyConstructionInfo(n, l, o, d),
        m = new e.btRigidBody(u);
        r.addRigidBody(m), s.push(m);
      }
      n > 0 && (u.push(t), m.set(t, s));
    }(t, n, a) :
    t.isMesh &&
    function (t, n, o) {
      const a = t.position,
      s = t.quaternion,
      i = new e.btTransform();
      i.setIdentity(),
      i.setOrigin(new e.btVector3(a.x, a.y, a.z)),
      i.setRotation(new e.btQuaternion(s.x, s.y, s.z, s.w));
      const c = new e.btDefaultMotionState(i),
      l = new e.btVector3(0, 0, 0);
      o.calculateLocalInertia(n, l);
      const d = new e.btRigidBodyConstructionInfo(n, c, o, l),
      h = new e.btRigidBody(d);
      r.addRigidBody(h), n > 0 && (u.push(t), m.set(t, h));
    }(t, n, a));
  }
  let w = 0;
  const f = -3;
  return (
    setInterval(function () {
      const e = performance.now();
      if (w > 0) {
        const t = (e - w) / 1e3;
        r.stepSimulation(t, 10);
        for (let e = 0, t = u.length; e < t; e++) {
          const t = u[e];
          if (t.isInstancedMesh) {
            const e = t.instanceMatrix.array,
            n = m.get(t);
            for (let t = 0; t < n.length; t++) {
              n[t].getMotionState().getWorldTransform(c);
              const a = c.getOrigin();
              if (a.y() < f) {
                let e = THREE.MathUtils.randFloat(-o / 2, o / 2),
                s = THREE.MathUtils.randFloat(3 * o, 7 * o),
                i = THREE.MathUtils.randFloat(-o / 2, o / 2);
                l.setValue(e, s, i),
                c.setIdentity(),
                c.setOrigin(l),
                n[t].setWorldTransform(c),
                l.setValue(0, 0, 0),
                n[t].setLinearVelocity(l),
                n[t].setAngularVelocity(l),
                n[t].clearForces(),
                a.setValue(e, s, i),
                d.setValue(0, 0, 0, 0);
              } else d.setValue(0, 0, 0, 0);
              s(a, d, e, 16 * t);
            }
            t.instanceMatrix.needsUpdate = !0, t.computeBoundingSphere();
          } else if.........完整代码请登录后点击上方下载按钮下载查看

网友评论0