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;
}
html,
body {
  background: black;
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
}
body {
  font-family: "Asap", sans-serif;
  position: relative;
  width: 100vw;
  min-height: 100vh;
  text-align: center;
  overflow-x: hidden;
  color: white;
}

canvas {
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
  position: fixed;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
  z-index: 1;
}
</style>


  
</head>

<body>

<canvas id="canvas"></canvas>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/es-module-shims.1.6.2.js"></script>
<script type="importmap">
  {
    "imports": {      
      "three": "//repo.bfw.wiki/bfwrepo/js/module/three/build/154/three.module.js",
      "three/addons/": "//repo.bfw.wiki/bfwrepo/js/module/three/examples/154/jsm/"
    }
  }
</script>

  
      <script type="module">
/*!
 Summer bunny 2023
 https://codepen.io/wakana-k/pen/JjeZjrq
 @wakana-k
*/
import * as THREE from "three";

import * as BufferGeometryUtils from "three/addons/utils/BufferGeometryUtils.js";

import { OrbitControls as e } from "three/addons/controls/OrbitControls.js";

!function () {
  "use strict";
  function t() {
    a.aspect = window.innerWidth / window.innerHeight,
    a.updateProjectionMatrix(),
    r.setSize(window.innerWidth, window.innerHeight);
  }
  function o() {
    requestAnimationFrame(o),
    d.update(),
    function () {
      (S > p || S < c) && (w *= -1);
      E.rotation.set(0, 0, S += w), r.render(n, a);
    }();
  }
  let a,
  n,
  r,
  d,
  l,
  i,
  s = [];
  const h = 7;
  let E;
  const p = -Math.PI / 1.95,
  c = -Math.PI / 1.2;
  let w = 0.05,
  S = p;
  const u = window.innerWidth < window.innerHeight;
  !function () {
    (n = new THREE.Scene()).background = new THREE.Color("black"),
    (r = new THREE.WebGLRenderer({
      antialias: !0,
      canvas: canvas })).
    setPixelRatio(window.devicePixelRatio),
    r.setSize(window.innerWidth, window.innerHeight),
    r.useLegacyLights = !1,
    r.shadowMap.enabled = !0,
    a = new THREE.PerspectiveCamera(
    40,
    window.innerWidth / window.innerHeight,
    0.01,
    500),

    u ? a.position.set(0, 4, 13) : a.position.set(0, 3, 12),
    a.lookAt(0, 0, 0);
    const p = new THREE.AmbientLight(16777215, 1.5);
    n.add(p);
    const c = new THREE.DirectionalLight(16777215, 1.5);
    c.castShadow = !0, c.position.set(0, 3, 3), n.add(c);
    let w = new THREE.Mesh(
    new THREE.SphereGeometry(50, 4, 4),
    new THREE.MeshBasicMaterial({
      color: "lightcyan",
      side: THREE.BackSide }));


    n.add(w),
    s = [],
    i = new THREE.MeshLambertMaterial({
      color: "limegreen",
      side: THREE.DoubleSide }),

    (l = new THREE.SphereGeometry(1.5, 11, 5, 0, 6.3, 1.865, 3.14)).rotateX(
    Math.PI),

    l.rotateZ(Math.PI / 10),
    l.translate(0.2, 2.85, 0);
    const S = new THREE.Mesh(l, i);
    (l = new THREE.SphereGeometry(0.35, 10, 10)).translate(0.4, 2.8, 0),
    s.push(l),
    (l = l.clone()).translate(-0.3, 0.25, 0.3),
    s.push(l),
    l = BufferGeometryUtils.mergeBufferGeometries(s),
    (i = i.clone()).color.set("yellow");
    const T = new THREE.Mesh(l, i);
    T.castShadow = !0,
    S.add(T),
    (l = new THREE.CylinderGeometry(0.13, 0.3, 4.3, 8)).translate(0, 1.3, 0),
    s.push(l),
    (i = i.clone()).color.set("peru");
    const C = new THREE.Mesh(l, i);
    C.castShadow = !0,
    S.add(C),
    S.position.set(-3, 0.15, 0),
    S.name = "tree",
    S.castShadow = !0,
    n.add(S),
    l = new THREE.SphereGeometry(0.6, 12, 10);
    let R = i.clone();
    R.color.set("white"),
    R.map = function () {
      let e = document.createElement("canvas");
      e.width = 300, e.height = 300;
      let t = e.getContext("2d");
      var o = t.createLinearGradient(0, 0, e.width, 0);
      o.addColorStop(0, "white"),
      o.addColorStop(0.5, "white"),
      o.addColorStop(0.5, "orange"),
      o.addColorStop(1, "orange"),
      t.fillStyle = o,
      t.fillRect(0, 0, e.width, e.height);
      let a = new THREE.CanvasTexture(e);
      return (
        a.wrapS = a.wrapT = THREE.RepeatWrapping, a.repeat.set(3, 1), a);

    }();
    const m = new THREE.Mesh(l, R);
    m.position.set(2.3, 0.4, 1.5),
    m.name = "beachball",
    m.castShadow = !0,
    n.add(m),
    s = [],
    (l = new THREE.CapsuleGeometry(0.5, 0.7, 4, 10)).translate(0, 0, 0),
    s.push(l),
    (l = new THREE.CapsuleGeometry(0.15, 0.8, 4, 10)).rotateZ(Math.PI / 3.5),
    l.translate(0.65, 0.2, 0),
    s.push(l),
    (l = new THREE.CapsuleGeometry(0.18, 0.5, 4, 10)).translate(0.2, -1, 0),
    s.push(l),
    (l = new THREE.CapsuleGeometry(0.18, 0.5, 4, 10)).translate(-0.2, -1, 0),
    s.push(l),
    (l = new THREE.SphereGeometry(0.5, 10, 10)).translate(0, 1.2, 0),
    s.push(l),
    (l = new THREE.CapsuleGeometry(0.15, 0.5, 4, 8)).translate(0.2, 1.8, 0),
    s.push(l),
    (l = new THREE.CapsuleGeometry(0.15, 0.5, 4, 8)).translate(-0.2, 1.8, 0),
    s.push(l),
    l = BufferGeometryUtils.mergeBufferGeometries(s),
    (i = i.clone()).color.set("bisque");
    const f = new THREE.Mesh(l, i);
    (l = new THREE.SphereGeometry(0.15, 5, 5)).translate(0, -0.3, -0.5),
    s.push(l),
    (i = i.clone()).color.set("white");
    const H = new THREE.Mesh(l, i);
    H.castShadow = !0,
    f.add(H),
    (l = new THREE.CylinderGeometry(0, 4.5, 0.2, 30)).translate(0, -1.4, 0),
    s.push(l),
    (i = i.clone()).color.set("lightcyan");
    const g = new THREE.Mesh(l, i);
    g.receiveShadow = !0,
    f.add(g),
    (l = new THREE.SphereGeometry(0.07, 10, 10)).translate(0.18, 1.3, 0.4),
    (i = i.clone()).color.set("black");
    const y = new THREE.Mesh(l, i);
    f.add(y), (l = l.clone()).translate(-0.36, 0, 0);
    const M = new THREE.Mesh(l, i);
    f.add(M);
    const v = new THREE.Shape();
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0