three实现三维光照立体玻璃画作旋转动画效果代码

代码语言:html

所属分类:三维

代码描述:three实现三维光照立体玻璃画作旋转动画效果代码,玻璃表面有逼真反射。

代码标签: three 三维 光照 立体 玻璃 画作 旋转 动画

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

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

<head>

  <meta charset="UTF-8">
  

  
<style>
canvas {
  display: block;
  width: 100%;
  height: 100vh;
  cursor: -webkit-grab;
  cursor: grab;
}
</style>



</head>

<body  >
  <!-- 
  Conveyor animation
  - build your own conveyor in create_conveyor()

-->


<script async type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/es-module-shims.1.5.1.js" crossorigin="anonymous"></script>

<script type="importmap">
  {
    "imports": {
      "three": "//repo.bfw.wiki/bfwrepo/js/module/three/build/146/three.module.js",
      "three/addons/": "//repo.bfw.wiki/bfwrepo/js/module/three/examples/jsm/"
    }
  }
</script>


<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.9.1.js"></script>
      <script  type="module">
import * as THREE from 'three'
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'

// ----
// params
// ----

const LENGTH = 3.5 // conveyor curve related (see create_conveyor)
const RADIUS = 0.5 // ditto
const ITEM_THICKNESS = 0.2 // item thickness
const ITEM_TILT = 15 // in degree, tilt item around y
const ANIM_DURATION = 60 // in second

const IMG_URLS = [
  // (1) Mae Mu - https://unsplash.com/photos/_C5zsV_p-YI
  '//repo.bfw.wiki/bfwrepo/image/62c4c544027dd.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_400,h_600,/quality,q_90',
  // (2) Vincent van Zalinge - https://unsplash.com/photos/4Mu2bXIsn5Y
  '//repo.bfw.wiki/bfwrepo/image/62842707b1cc9.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_400,h_600,/quality,q_90',
  // (3) Elena G - https://unsplash.com/photos/wPEjA22-yxE
  '//repo.bfw.wiki/bfwrepo/image/62af9cad6c5db.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_400,h_600,/quality,q_90',
  // (4) Nick Fewings - https://unsplash.com/photos/BPDJLWz_Bog
  '//repo.bfw.wiki/bfwrepo/image/62c790deefa83.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_400,h_600,/quality,q_90',
  // (5) John Cameron - https://unsplash.com/photos/sc653L2oJrw
  '//repo.bfw.wiki/bfwrepo/image/630c61379ccb3.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_400,h_600,/quality,q_90',
  // (6) Chris Barbalis - https://unsplash.com/photos/3ZoBZzkUO58
  '//repo.bfw.wiki/bfwrepo/image/633122c2f1fd7.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_400,h_600,/quality,q_90',
  // (7) NordWood Themes - https://unsplash.com/photos/WPn2Z9bXOEk
  '//repo.bfw.wiki/bfwrepo/image/633122ce466bc.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_400,h_600,/quality,q_90',
  // (8) Morgane Perraud - https://unsplash.com/photos/z-O2zDMIEJg
  '//repo.bfw.wiki/bfwrepo/image/5d65ea7d8bc8b.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_400,h_600,/quality,q_90'
]

// credit: mrdoob - three.js/examples/textures/
const ENV_URL = '//repo.bfw.wiki/bfwrepo/image/636d9baf40a77.png'

// ----
// main
// ----

const renderer = new THREE.WebGLRenderer({ antialias: true })
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(75, 2, 0.1, 100)
const controls = new OrbitControls(camera, renderer.domElement)

scene.background = new THREE.Color('white')
camera.position.set(0.0, 2.0, 3.0)
controls.target.set(0.0, 0.2, 0.0)
controls.enableDamping = true
controls.maxPolarAngle = (95) * Math.PI / 180
renderer.toneMapping = THREE.ACESFilmicToneMapping
renderer.toneMappingExposure = 1.0
renderer.outputEncoding = THREE.sRGBEncoding
renderer.physicallyCorrectLights = true
renderer.shadowMap.enabled = true

new THREE.TextureLoader().load(ENV_URL, (tex) => {
  tex.mapping = THREE.EquirectangularReflectionMapping
  tex.encoding = THREE.sRGBEncoding
  const rt = new THREE.PMREMGenerator(renderer).fromEquirectangular(tex)
  scene.environment = rt.texture
})

const light = new THREE.DirectionalLight()
light.position.set(4, 4, 4)
light.castShadow = true
light.shadow.mapSize.setScalar(1024)
scene.add(light)
scene.add(new THREE.AmbientLight())

const grid = new THREE.GridHelper(3, 3)
scene.add(grid)

// ---
// create coveyor (a curve on XZ plane)
// ---

function create_conveyor(le.........完整代码请登录后点击上方下载按钮下载查看

网友评论0