three+webgl实现一个液态球体旋转动画效果代码

代码语言:html

所属分类:三维

代码描述:three+webgl实现一个液态球体旋转动画效果代码

代码标签: 液态 球体 旋转 动画 效果

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

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

<head>

  <meta charset="UTF-8">
  

  
  
<style>
body {
  background: #000;
  -ms-scroll-chaining: none;
      overscroll-behavior: none;
}
#loading {
  background: #000;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  visibility: visible;
  opacity: 1;
  transition: visibility 1.6s, opacity 1.6s;
}
#loading .circle {
  width: 50px;
  height: 50px;
  background: #fff;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0, 0);
  -webkit-animation: circle-animation 1.6s ease-in-out 0s infinite normal none;
          animation: circle-animation 1.6s ease-in-out 0s infinite normal none;
}
#loading.loaded {
  visibility: hidden;
  opacity: 0;
}
#container {
  width: 100vw;
  height: 100vh;
}
#container canvas {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 0;
  outline: none;
}
/** css animation */
@-webkit-keyframes circle-animation {
  0% {
    opacity: 0;
    transform: scale(0, 0);
  }
  50% {
    opacity: 1;
    transform: scale(1, 1);
  }
}
@keyframes circle-animation {
  0% {
    opacity: 0;
    transform: scale(0, 0);
  }
  50% {
    opacity: 1;
    transform: scale(1, 1);
  }
}
</style>



</head>

<body >
  <div id="loading">
  <div class="circle"></div>
</div>
<div id="container"></div>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/Stats-16.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.126.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.126.js"></script>

      <script >
/**
 * I referenced the YouTube by Mr.Yuri Artyukh.
 * URL: https://www.youtube.com/watch?v=8K5wJeVgjrM&t=615s
 * CDN: from https://cdn.jsdelivr.net
 * Thank you so much :)
 */



/** vertex shader source */
const vertexShaderSource = `
uniform float time;
uniform vec2 pixels;

varying vec2 vUv;

float PI = 3.14159265359;

void main () {
  vUv = uv;
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}

`;

/** fragment shader source */
const fragmentShaderSource = `
uniform float time;
uniform float progress;
uniform sampler2D texture1;
uniform vec4 resolution;
uniform vec2 mouse;
uniform float wheel;

varying vec2 vUv;

vec3 palette( in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d ) {
  return a + b*cos( 6.28318*(c*t+d) );
}

mat4 rotationMatrix(vec3 axis, float angle) {
  axis = normalize(axis);
  float s = sin(angle);
  float c = cos(angle);
  float oc = 1.0 - c;

  return
    mat4(
      oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
      oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
      oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
      0.0, 0.0, 0.0, 1.0
    );
}

vec3 rotate(vec3 v, vec3 axis, float angle) {
	mat4 m = rotationMatrix(axis, angle);
	return (m * vec4(v, 1.0)).xyz;
}

float sineCrazy(vec3 p) {
  return 1.0 - (sin(p.x) + sin(p.y) + sin(p.z)) / 3.0;
}

float sphere(vec3 p) {
  return length(p) - 0.5;
}

float sdBox(vec3 p, ve.........完整代码请登录后点击上方下载按钮下载查看

网友评论0