three实现三维立体质感数字时钟显示当前时间代码
代码语言:html
所属分类:三维
代码描述:three实现三维立体质感数字时钟显示当前时间代码,显示星期、日期、当前时分等信息。
代码标签: three 三维 立体 质感 数字 时钟 显示 当前 时间 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body{ overflow: hidden; margin: 0; } </style> </head> <body> <script type="importmap"> { "imports": { "three": "//repo.bfw.wiki/bfwrepo/js/module/three/build/162/three.module.js", "three/addons/": "//repo.bfw.wiki/bfwrepo/js/module/three/examples/162/jsm/" } } </script> <script> let snoise2d = `// Simplex 2D noise // vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); } float snoise(vec2 v){ const vec4 C = vec4(0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439); vec2 i = floor(v + dot(v, C.yy) ); vec2 x0 = v - i + dot(i, C.xx); vec2 i1; i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0); vec4 x12 = x0.xyxy + C.xxzz; x12.xy -= i1; i = mod(i, 289.0); vec3 p = permute( permute( i.y + vec3(0.0, i1.y, 1.0 )) + i.x + vec3(0.0, i1.x, 1.0 )); vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0); m = m*m ; m = m*m ; vec3 x = 2.0 * fract(p * C.www) - 1.0; vec3 h = abs(x) - 0.5; vec3 ox = floor(x + 0.5); vec3 a0 = x - ox; m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h ); vec3 g; g.x = a0.x * x0.x + h.x * x0.y; g.yz = a0.yz * x12.xz + h.yz * x12.yw; return 130.0 * dot(m, g); } float udSegment( in vec2 p, in vec2 a, in vec2 b ) { vec2 ba = b-a; vec2 pa = p-a; float h =clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 ); return length(pa-h*ba); } `; </script> <script type="module"> import * as THREE from "three"; import { OrbitControls } from "three/addons/controls/OrbitControls.js"; import { mergeGeometries } from "three/addons/utils/BufferGeometryUtils.js"; import { EffectComposer } from "three/addons/postprocessing/EffectComposer.js"; import { RenderPass } from "three/addons/postprocessing/RenderPass.js"; import { UnrealBloomPass } from "three/addons/postprocessing/UnrealBloomPass.js"; import { OutputPass } from "three/addons/postprocessing/OutputPass.js"; import { RoomEnvironment } from "three/addons/environments/RoomEnvironment.js"; console.clear(); // load fonts await (async function () { async function loadFont(fontface) { await fontface.load(); document.fonts.add(fontface); } let fonts = [ new FontFace( "KodeMono", "url(https://fonts.gstatic.com/s/kodemono/v1/A2BYn5pb0QgtVEPFnlYOnYLw.woff2) format('woff2')" ) ]; for (let font in fonts) { //console.log(fonts[font]); await loadFont(fonts[font]); } })(); class GlowLayer extends EffectComposer { constructor(renderer) { const target = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight, { type: THREE.HalfFloatType, format: THREE.RGBAFormat, colorSpace: THREE.SRGBColorSpace, samples: 8 } ); super(renderer, target); const renderScene = new RenderPass(scene, camera); const bloomPass = new UnrealBloomPass( new THREE.Vector2(window.innerWidth, window.innerHeight), 0.1, 0, 5 ); const outputPass = new OutputPass(); this.uniforms = { aspect: { value: camera.aspect } }; outputPass.material.onBeforeCompile = (shader) => { shader.uniforms.aspect = this.uniforms.aspect; shader.uniforms.watermark = {value: (function () { let c = document.createElement("canvas"); c.width = 1024; c.height = 128; let $ = c.getContext("2d"); $.clearRect(0, 0, c.width, c.height); $.font = `bold ${c.height * 0.5}px KodeMono`; $.textAlign = "left"; $.textBaseline = "middle"; $.fillStyle = "#fff"; $.fillText("dig clock", c.width * 0.01, c.height * 0.5); let cTex = new THREE.CanvasTexture(c); cTex.colorSpace = THREE.SRGBColorSpace; return cTex; })() } shader.fragmentShader = ` ${shader.fragmentShader} ` .replace( `precision highp float;`, `precision highp float; uniform float aspect; uniform sampler2D watermark; ` ) .replace( `}`, ` // signature vec2 sUv = vUv * 14. * vec2(aspect / 8., 1.); sUv -= vec2(0.05, 0.05); float sig = texture2D(watermark, sUv).r; vec3 sigColor = vec3(0.75); //////////// gl_FragColor.rgb = mix(gl_FragColor.rgb, sigColor, sig); } ` ); //console.log(shader.fragmentShader) }; this.addPass(renderScene); this.addPass(bloomPass); this.addPass(outputPass); //console.log(outputPass); } } class Logo extends THREE.BufferGeometry { constructor() { super(); let baseVector = new THREE.Vector2(0, 1); let center = new THREE.Vector2(); let shift = new THREE.Vector2(0, -0.25); let a = 3 / Math.sqrt(3); let hA = a * 0.5; let hStep = 1.5; let hHeight = 0.75; let steps = 4; let scale = 0.85; let baseTri = [ baseVector.clone().multiplyScalar(scale).add(shift), baseVector .clone() .rotateAround(center, (-Math.PI * 2) / 3) .multiplyScalar(scale) .add(shift), baseVector .clone() .rotateAround(center, (Math.PI * 2) / 3) .multiplyScalar(scale) .add(shift) ]; let baseTriFlip = [ baseVector .clone() .rotateAround(center, Math.PI) .multiplyScalar(scale) .sub(shift), baseVector .clone() .rotateAround(center, Math.PI / 3) .multiplyScalar(scale) .sub(shift), baseVector .........完整代码请登录后点击上方下载按钮下载查看
网友评论0