three实现可调节参数的莫比乌斯带三维模型效果代码

代码语言:html

所属分类:三维

代码描述:three实现可调节参数的莫比乌斯带三维模型效果代码

代码标签: three 调节 参数 莫比乌斯带 三维 模型

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

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

<head>
  <meta charset="UTF-8">

  
  
<style>
html, body {
    padding: 0;
    margin: 0;
}

body {
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

#mobius {
	 cursor: pointer;
 	 padding-top: 75px; /* for codepen preview */
}

.lil-gui {
    --width: 450px;
    max-width: 90%;
    --widget-height: 20px;
    font-size: 15px;
    --input-font-size: 15px;
    --padding: 10px;
    --spacing: 10px;
    --slider-knob-width: 5px;
    --background-color: rgba(5, 0, 15, .8);
    --widget-color: rgba(255, 255, 255, .3);
    --focus-color: rgba(255, 255, 255, .4);
    --hover-color: rgba(255, 255, 255, .5);

    --font-family: monospace;
}
</style>

  
</head>

<body >
  <canvas id="mobius"></canvas>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/es-module-shims.1.6.2.js"></script>
<script type="importmap">
  {
    "imports": {      
      "three": "//repo.bfw.wiki/bfwrepo/js/module/three/build/154/three.module.js",
      "three/addons/": "//repo.bfw.wiki/bfwrepo/js/module/three/examples/154/jsm/"
    }
  }
</script>
  
      <script  type="module">
import * as THREE from "three";
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
import { GUI } from "//repo.bfw.wiki/bfwrepo/js/lil-gui.esm.js";


const canvasEl = document.querySelector("#mobius");

let renderer, scene, camera, clock, orbit, strip;

const params = {
  stripeWidth: 1,
  canvasSize: 250,
  segments: 20,
  color: {
    r: 2, g: .5, b: -.4 } };



initScene();
render();
createControls();

function initScene() {

  scene = new THREE.Scene();

  camera = new THREE.PerspectiveCamera(40, 1, 1, 50);
  camera.position.set(0, 1, 5);
  camera.lookAt(0, 0, 0);

  clock = new THREE.Clock();

  renderer = new THREE.WebGLRenderer({
    antialias: true,
    alpha: true,
    canvas: canvasEl });

  renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
  renderer.setSize(params.canvasSize, params.canvasSize);

  const material = new THREE.MeshNormalMaterial({
    side: THREE.DoubleSide });

  material.userData.color_addition = { value: new THREE.Vector3(params.color.r, params.color.g, params.color.b) };
  material.onBeforeCompi.........完整代码请登录后点击上方下载按钮下载查看

网友评论0