three实现三维星球星环上跑汽车动画效果代码
代码语言:html
所属分类:三维
代码描述:three实现三维星球星环上跑汽车动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
body {
height: 100vh;
margin: 0;
}
.object-hover {
cursor: pointer;
}
.loading {
position: absolute;
inset: 0;
background: #2d2826;
}
.loading p {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
translate: -50% -50%;
width: 60dvmin;
height: 60dvmin;
}
.loading .letter {
position: absolute;
color: #fed;
font: bold italic 5dvmin/1 georgia;
text-transform: uppercase;
-webkit-text-stroke: .033em #2f2a2e;
-webkit-animation:
letter-wave
1s calc(var(--i) * 200ms)
steps(3) infinite,
letter-wiggle
.6s calc(var(--i) * -100ms)
steps(1) infinite;
animation:
letter-wave
1s calc(var(--i) * 200ms)
steps(3) infinite,
letter-wiggle
.6s calc(var(--i) * -100ms)
steps(1) infinite;
}
@-webkit-keyframes letter-wave {
50% {
scale: 1.66;
}
}
@keyframes letter-wave {
50% {
scale: 1.66;
}
}
@-webkit-keyframes letter-wiggle {
from, to {
rotate: 0;
}
20% {
rotate: -15deg;
}
40% {
rotate: 10deg;
}
60% {
rotate: -13deg;
}
80% {
rotate: 14deg;
}
}
@keyframes letter-wiggle {
from, to {
rotate: 0;
}
20% {
rotate: -15deg;
}
40% {
rotate: 10deg;
}
60% {
rotate: -13deg;
}
80% {
rotate: 14deg;
}
}
:nth-child(1 of .letter) {
top: 26%;
left: 4%;
}
:nth-child(2 of .letter) {
top: 30%;
left: 20%;
}
:nth-child(3 of .letter) {
top: 41%;
left: 39%;
}
:nth-child(4 of .letter) {
top: 50%;
left: 48%;
}
:nth-child(5 of .letter) {
top: 49%;
left: 64%;
}
:nth-child(6 of .letter) {
top: 57%;
left: 82%;
}
:nth-child(7 of .letter) {
top: 52%;
left: 91%;
}
:nth-child(1 of .letter) { --i: 0; }
:nth-child(2 of .letter) { --i: 1; }
:nth-child(3 of .letter) { --i: 2; }
:nth-child(4 of .letter) { --i: 3; }
:nth-child(5 of .letter) { --i: 4; }
:nth-child(6 of .letter) { --i: 5; }
:nth-child(7 of .letter) { --i: 6; }
.loading img {
position: absolute;
top: 50%;
left: 50%;
translate: -50% -50%;
width: 60dvmin;
vertical-align: middle;
}
.loaded .loading {
display: none;
}
.log {
position: absolute;
bottom: 0;
left: 0;
translate: 0 calc(100% * var(--i) * -1);
background: black;
color: white;
font-style: normal;
font-family: monospace;
font-size: calc(.8em + pow(var(--i), 2) * .001em);
padding: .4em;
pointer-events: none;
-webkit-animation:
disappear
var(--fade-duration)
var(--duration)
forwards 1;
animation:
disappear
var(--fade-duration)
var(--duration)
forwards 1;
}
@-webkit-keyframes disappear {
to {
opacity: 0;
}
}
@keyframes disappear {
to {
opacity: 0;
}
}
.log em {
color: cyan;
margin-right: .5em;
}
:nth-child(1 of .log) { --i: 0; }
:nth-child(2 of .log) { --i: 1; }
:nth-child(3 of .log) { --i: 2; }
:nth-child(4 of .log) { --i: 3; }
:nth-child(5 of .log) { --i: 4; }
:nth-child(6 of .log) { --i: 5; }
:nth-child(7 of .log) { --i: 6; }
:nth-child(8 of .log) { --i: 7; }
:nth-child(9 of .log) { --i: 8; }
:nth-child(10 of .log) { --i: 9; }
:nth-child(11 of .log) { --i: 10; }
:nth-child(12 of .log) { --i: 11; }
:nth-child(13 of .log) { --i: 12; }
:nth-child(14 of .log) { --i: 13; }
:nth-child(15 of .log) { --i: 14; }
:nth-child(16 of .log) { --i: 15; }
:nth-child(17 of .log) { --i: 16; }
:nth-child(18 of .log) { --i: 17; }
:nth-child(19 of .log) { --i: 18; }
:nth-child(20 of .log) { --i: 19; }
.css-scene {
position: absolute;
top: 0;
pointer-events: none;
}
.css-scene__car-label {
font-size: .15dvmin;
font-family: monospace;
padding: .15em .15em 0;
color: yellow;
background: #000b;
}
.css-scene__car-label span {
color: lime;
}
</style>
</head>
<body translate="no">
<div class="loading">
<img src="//repo.bfw.wiki/bfwrepo/image/5df86dc72ff0f.png" alt="intelligent drum and bass vol. 2">
<p>
<span class="letter">l</span>
<span class="letter">o</span>
<span class="letter">a</span>
<span class="letter">d</span>
<span class="letter">i</span>
<span class="letter">n</span>
<span class="letter">g</span>
</p>
</div>
<script type="importmap">
{
"imports": {
"./three": "https://assets.codepen.io/25387/three.webgpu.min.js",
"three/webgpu": "https://assets.codepen.io/25387/three.webgpu.min.js",
"./three/tsl": "https://assets.codepen.io/25387/three.tsl.js",
"./three/addons/": "https://esm.sh/three@0.172.0/examples/jsm/"
}
}
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/three.js/0.172.0/three.tsl.js'></script>
<script type="module">
import * as THREE from "./three"
import { GLTFLoader } from "./three/addons/loaders/GLTFLoader.js"
import { DRACOLoader } from './three/addons/loaders/DRACOLoader.js'
import { FontLoader } from './three/addons/loaders/FontLoader.js'
import { TextGeometry } from './three/addons/geometries/TextGeometry.js'
import { OrbitControls } from "./three/addons/controls/OrbitControls.js"
import { CSS3DRenderer, CSS3DObject } from "./three/addons/renderers/CSS3DRenderer.js"
import { lights } from "./three/tsl"
import Stats from './three/addons/libs/stats.module.js'
const { sin, cos, atan2, max, abs, PI, random } = Math
const YOUTUBE_LINK = 'h'
const DRACO_DECODER_PATH = 'https://threejs.org/examples/jsm/libs/draco/'
const asset = (name) => `https://assets.codepen.io/25387/${name}`
let stats, frustum, cameraViewProjectionMatrix, raycaster, mouse,
textureLoader, gltfLoader, dracoLoader,
scene, camera, renderer, controls, cssRenderer, cssScene,
light, sky, saturn, cars, text
const state = {
freeCamera: 0,
wasHula: 0,
hula: 0,
frame: 0,
lastTap: 0
}
const inspection = {
fps: 0,
loadingTimes: 0,
labels: 0
}
const cameraFinalPosition = {
x: 0,
y: 500,
z: 850
}
const entrySpeed = {
x: .4,
y: 1,
z: .6
}
const center = {
x: 32,
y: 26.5,
z: 0,
}
const minPan = new THREE.Vector3(-150, -75, -150)
const maxPan = new THREE.Vector3(150, 75, 150)
const outerLane = 67
const innerLane = 56
const outerSpeed = .0025
const innerSpeed = .0035
const carScale = .975
const carsConfig = {
outer: [{
model: '1965_pontiac_gto.glb',
modelScale: .08,
modelAxisFix: PI * .2,
spotLightIntensity: 10,
orbitProgress: .3
}, {
model: '1970_chrysler_300.glb',
modelScale: .0075,
modelAltitudeFix: .5,
spotLightIntensity: 5,
orbitProgress: .55
}, {
model: '1962_pontiac_catalina.glb',
modelScale: 1.8,
modelAxisFix: PI / -2,
orbitProgress: .7
}, {
model: '80s_american_wagon.glb',
modelScale: .05,
modelAxisFix: PI / 2,
spotLightIntensity: 30,
orbitProgress: .83
}, {
model: '1971_pontiac_lemans.glb',
modelScale: .2,
spotLightIntensity: 5,
orbitProgress: .9
}],
inner: [{
model: '1971_datsun_510.glb',
modelScale: .057,
modelAxisFix: PI / -2,
orbitProgress: -.1
}, {
model: '1971_chrysler_newyorker.glb',
modelAxisFix: PI / -2,
modelScale: 7.7,
orbitProgress: -.02
}, {
model: '1961_chevrolet_impala.glb',
modelScale: .018,
modelAxisFix: PI,
modelAltitudeFix: 1.5,
spotLightIntensity: 5,
orbitProgress: .06
}, {
model: '1966_pontiac_bonneville.glb',
modelScale: .0077,
modelAltitudeFix: 1,
spotLightIntensity: 25,
orbitProgress: .14
}, {
model: '1968_chevrolet_impala.glb',
modelScale: .0085,
modelAxisFix: PI,
modelAltitudeFix: .25,
spotLightIntensity: 1,
orbitProgress: .35
}, {
model: '1960_chrysler_saragota.glb',
modelScale: .018,
modelAxisFix: PI,
spotLightIntensity: 10,
orbitProgress: .5
}, {
model: '1969_dodge_coronet.glb',
modelScale: .125,
modelAxisFix: PI,
orbitProgress: .675,
}]
}
function ease(t, total = 2200) {
const prog = t / total
return total - (sin(prog / (PI / 6)) * total)
}
function HTMLToDOM(html) {
const parser = new DOMParser()
const doc = parser.parseFromString(html, 'text/html')
return doc.body.firstElementChild
}
function lo.........完整代码请登录后点击上方下载按钮下载查看
网友评论0