three+lil-gui实现可调节参数的三维场景聚光灯spotlight照射物体效果代码

代码语言:html

所属分类:三维

代码描述:three+lil-gui实现可调节参数的三维场景聚光灯spotlight照射物体效果代码

代码标签: three lil-gui 调节 参数 三维 场景 聚光灯 spotlight 照射 物体

下面为部分代码预览,完整代码请点击下载或在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>
  <script type="importmap">
  {
    "imports": {
      "three": "//repo.bfw.wiki/bfwrepo/js/module/three/build/155/three.module.js",
      "three/addons/": "//repo.bfw.wiki/bfwrepo/js/module/three/examples/155/jsm/",
      "lil-gui": "//repo.bfw.wiki/bfwrepo/js/lil-gui.esm.js"
    }
  }
</script>
  
      <script  type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';
import { GUI } from 'lil-gui';

// ----
// 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);

camera.position.set(0, 3, 6);
controls.enableDamping = true;
controls.maxPolarAngle = Math.PI / 2.1;
renderer.shadowMap.enabled = true;

{// cyc wall and grid
  const mat = new THREE.MeshStandardMaterial({ roughness: 1, side: THREE.BackSide });
  const geom = new RoundedBoxGeometry(10, 10, 10, 10, 1).translate(0, 5, 0);
  const mesh = new THREE.Mesh(geom, [null, mat, null, mat, null, mat]);
  mesh.castShadow = mesh.receiveShadow = true;
  scene.add(mesh);
  scene.add(new THREE.GridHelper(10, 10));
}

{// models (2m tall box, 1.8m tall capsule)
  const mat = new THREE.MeshStandardMaterial({ roughness: 1 });
  const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 2, 1), mat);
  mesh.position.y = 1;
  mesh.castShadow = mesh.receiveShadow = true;
  scene.add(mesh);

  const mesh1 = new THREE.Mesh(new THREE.CapsuleGeometry(0.2, 1.4), mat);
  mesh1.pos.........完整代码请登录后点击上方下载按钮下载查看

网友评论0