three实现三维发光圣诞树亮灯圣诞节快乐场景代码
代码语言:html
所属分类:三维
代码描述:three实现三维发光圣诞树亮灯圣诞节快乐场景代码
代码标签: three 三维 发光 圣诞树 亮灯 圣诞节 快乐
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> * { -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; user-select: none; margin: 0; padding: 0; } canvas { position: fixed; width: 100%; height: 100%; top: 0; left: 0; margin: 0; padding: 0; } </style> </head> <body > <!-- using three.js --> <script type="x-shader/x-vertex" id="vertexshader"> varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); } </script> <script type="x-shader/x-fragment" id="fragmentshader"> uniform sampler2D baseTexture; uniform sampler2D bloomTexture; varying vec2 vUv; void main() { gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) ); } </script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.146.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.145.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/MeshSurfaceSampler.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/EffectComposer.146.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/RenderPass.146.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/ShaderPass.146.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/UnrealBloomPass.146.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/LuminosityHighPassShader.146.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/CopyShader.146.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/FontLoader.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/TextGeometry.145.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/CurveModifier.js"></script> <script> !function () { "use strict"; let e,t,n,o,a,r,s,i,E,d,l,h,c = 1,w = ""; const m = 1,R = new THREE.Layers(); R.set(m); const T = { exposure: 2, bloomStrength: 2, bloomThreshold: 0, bloomRadius: 0 }, H = new THREE.MeshBasicMaterial({ color: "black" }), u = {},p = new THREE.Vector3(),M = new THREE.Matrix4(); let g = new THREE.Vector3(); const f = new THREE.Euler(); let b = new THREE.Quaternion(); const y = new THREE.Vector3(1, 1, 1),S = new THREE.Vector3(0, 0, 0); new THREE.Matrix4(), new THREE.Vector3(0, 1, 0); function x(e, n, o) { let a = n.length,r = new THREE.InstancedMesh(i.geometry, i.material, a); r.castShadow = !0, b.set(0, 0, 0, 0); for (let t = 0; t < a; t++) { let a; p.set(n[t][0], n[t][1], n[t][2]), g = p, "ico" != o && "green" != o || (f.set(Math.random() * Math.PI, Math.random() * Math.PI, Math.random() * Math.PI), b.setFromEuler(f)), 1 != e && y.set(e, e, e), M.compose(g, b, y), a = "green" == o ? new THREE.Color().setHSL(THREE.MathUtils.randFloat(.25, .4), 1, .3) : new THREE.Color(16777215 * Math.random()), r.setMatrixAt(t, M), r.setColorAt(t, a); } if ("bloom" == o) { setInterval(function () { r.layers.toggle(m), z(); }, 1e3); } t.add(r); } function v() { const t = window.innerWidth,o = window.innerHeight; e.aspect = t / o, e.updateProjectionMatrix(), n.setSize(t, o), l.setSize(t, o), h.setSize(t, o), z(); } function P(e) { (e.isMesh || e.isInstancedMesh) && !1 === R.test(e.layers) && (u[e.uuid] = e.material, e.material = H); } function C(e) { u[e.uuid] && (e.material = u[e.uuid], delete u[e.uuid]); } function I() { requestAnimationFrame(I), o.update(), d && d.moveAlongCurve(.002), z(); } function z() { t.traverse(P), l.render(), t.traverse(C), h.render(); } !function () { const m = document.createElement("div"); document.body.appendChild(m), (t = new THREE.Scene()).background = 0, (n = new THREE.WebGLRenderer({ antialias: !0 })). setPixelRatio(window.devicePixelRatio), n.setSize(window.innerWidth, window.innerHeight), n.outputEncoding = THREE.sRGBEncoding, n.shadowMap.enabled = !0, m.appendChild(n.domElement), new .........完整代码请登录后点击上方下载按钮下载查看
网友评论0