three实现三维空灵模型几何体生成旋转效果代码
代码语言:html
所属分类:三维
代码描述:three实现三维空灵模型几何体生成旋转效果代码
代码标签: three 三维 空灵 模型 几何体 生成 旋转
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { margin: 0; overflow: hidden; font-family: Avenir, Montserrat, Corbel, "URW Gothic", source-sans-pro, sans-serif; font-weight: 900; } canvas { display: block; } #container { position: fixed; width: 100%; height: 100%; background: #0a192f; } #controls { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 20px; align-items: center; background: rgba(0, 0, 0, 0.3); padding: 15px 25px; border-radius: 8px; backdrop-filter: blur(5px); } .button { padding: 10px 20px; font-family: inherit; font-size: 14px; color: white; background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 4px; cursor: pointer; transition: all 0.3s ease; } .button:hover { background: rgba(255, 255, 255, 0.2); } .button:disabled { opacity: 0.5; cursor: not-allowed; } .checkbox-wrapper { display: flex; align-items: center; gap: 8px; color: white; font-size: 14px; } input[type="checkbox"] { cursor: pointer; width: 16px; height: 16px; } #title { color: white; top: 10px; position: absolute; width: 100%; text-align: center; user-select: none; pointer-events: none; font-size: 48pt; color: rgba(255, 165, 0, 0.4); font-weight: 900; letter-spacing: 2px; color: transparent; text-shadow: 0 0 10px black; background: linear-gradient( hsla(39, 100%, 80%, 0.8), hsla(39, 100%, 80%, 0.8) ); -webkit-background-clip: text; background-clip: text; } // Add this to the style section .button-group { display: flex; gap: 8px; align-items: center; } .name { position: absolute; z-index: 10; bottom: 10px; right: 10px; font-family: sans-serif; color: white; } </style> </head> <body translate="no"> <div id="container"></div> <div id="title">Ethereal Rotations</div> <div id="subtitle">Each view creates a unique perspective</div> <div id="controls"> <button id="generateButton" class="button">Generate New Shape</button> <div class="button-group"> <div class="checkbox-wrapper"> <input type="checkbox" checked id="surfaceToggle"> <label for="surfaceToggle">Surface</label> </div> <div class="checkbox-wrapper"> <input type="checkbox"id="realSurfaceToggle" /> <label for="realSurfaceToggle">Real Surface</label> </div> </div> <button id="downloadButton" class="button">Download View as SVG</button> </div> <script type="importmap"> { "imports": { "three": "//repo.bfw.wiki/bfwrepo/js/module/three/build/164/three.module.js", "three/addons/": "//repo.bfw.wiki/bfwrepo/js/module/three/examples/164/jsm/" } } </script> <script type="module"> import * as THREE from "three"; import { OrbitControls } from "three/addons/controls/OrbitControls.js"; import { SVGRenderer } from "three/addons/renderers/SVGRenderer.js"; let scene, camera, renderer, controls; let pathLines = []; let surfaces = []; let isBuilding = false; let buildIndex = 0; let basePath = []; let hue; let generateButton, surfaceToggle, downloadButton; // Add these variables to the top of the script let lights = []; let realSurfaceToggle; let isRealSurface = false; function init() { scene = new THREE.Scene(); camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000); camera.position.set(5, 3, 5); renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); renderer.setClearColor(0x0a192f); document.getElementById("container").appendChild(renderer.domElement); controls = new OrbitControls(camera, renderer.domElement); controls.enableDamping = true; controls.dampingFactor = 0.05; generateButton = document.getElementById("generateButton"); surfaceToggle = document.getElementById("surfaceToggle"); downloadButton = document.getElementById("downloadButton"); generateButton.addEventListener("click", generateNewPath); surfaceToggle.addEventListener("change", toggleSurfaces); downloadButton.addEventListener("click", downloadSVG); generateNewPath(); animate(); window.addEventListener("resize", onWindowResize, false); // Setup lights const ambientLight = new THREE.AmbientLight(0x404040); const directionalLight = new THREE.DirectionalLight(0xffffff, 1); directionalLight.position.set(5, 5, 5); const pointLight = new THREE.PointLight(0xffffff, 1); pointLight.position.set(-5, -5, -5); lights.push(ambientLight, directionalLight, pointLight); lights.forEach(light => { light.visible = false; scene.add(light); }); realSurfaceToggle = document.getElementById("realSurfaceToggle"); realSurfaceToggle.addEventListener("change", toggleRealSurface); } // Add this new function function toggleRealSurface() { isRealSurface = realSurfaceToggle.checked; // Toggle lights lights.forEach(light => { light.visible = isRealSurface; }); // Update materials for all surfaces surfaces.forEach(surface => { if (isRealSurface) { const color = surface.material.color; surface.material = new THREE.MeshPhongMaterial({ color: color, transparent: true, opacity: 0.7, side: THREE.DoubleSide, shininess: 100, specular: 0x444444 }); } else { const color = surface.material.color; surface.material = new THREE.MeshBasicMaterial({ color: color, transparent: true, opacity: 0.1, side: THREE.DoubleSide }); } }); } function generateRandomPath() { const points = []; const numPoints = 5; const radius = 2; for (let i = 0; i <= numPoints; i++) { po.........完整代码请登录后点击上方下载按钮下载查看
网友评论0