three实现三维空间一块布料挡住画像手动揭开真相有趣代码

代码语言:html

所属分类:三维

代码描述:three实现三维空间一块布料挡住画像手动揭开真相有趣代码,一个布料盖住一个画像,是世界上最丑的动物,你用鼠标揭开试试。

代码标签: three 三维 空间 一块 布料 挡住 画像 手动 揭开 真相 有趣 代码

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

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>世界上最丑的动物</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body { 
            overflow: hidden; 
            background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
            font-family: 'Microsoft YaHei', sans-serif;
        }
        #info {
            position: absolute;
            bottom: 30px;
            width: 100%;
            text-align: center;
            color: #fff;
            font-size: 16px;
            text-shadow: 0 2px 4px rgba(0,0,0,0.5);
            pointer-events: none;
            z-index: 100;
        }
        #loading {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: white;
            font-size: 20px;
            z-index: 1000;
        }
        .hidden { display: none !important; }
    </style>
</head>
<body>
    <div id="loading">正在加载摄像头...</div>
    <div id="info">🖱️ 拖拽红布揭开镜子的秘密</div>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>
    <script>
        // ============ 全局变量 ============
        let scene, camera, renderer;
        let cloth, clothParticles = [], clothConstraints = [];
        let mirror, mirrorFrame, sign;
        let video, videoTexture;
        let isDragging = false;
        let draggedParticle = null;
        let mouse = new THREE.Vector2();
        let raycaster = new THREE.Raycaster();
        let clothRevealed = false;
        
        // 布料参数
        const CLOTH_WIDTH = 2.5;
        const CLOTH_HEIGHT = 3.2;
        const CLOTH_SEG_W = 20;
        const CLOTH_SEG_H = 25;
        const DAMPING = 0.03;
        const GRAVITY = new THREE.Vector3(0, -0.5, 0);
        
        // ============ 粒子类 ============
        class Particle {
            constructor(x, y, z, mass = 1) {
                this.position = new THREE.Vector3(x, y, z);
                this.previous = new THREE.Vector3(x, y, z);
                this.original = new THREE.Vector3(x, y, z);
                this.acceleration = new THREE.Vector3();
                this.mass = mass;
                this.pinned = false;
            }
            
            addForce(force) {
                this.acceleration.addScaledVector(force, 1 / this.mass);
            }
            
            integrate(dt) {
                if (this.pinned) return;
                
                const velocity = this.position.clone().sub(this.previous);
                velocity.multiplyScalar(1 - DAMPING);
                
                const newPos = this.position.clone()
                    .add(velocity)
                    .addScaledVector(this.acceleration, dt * dt);
               .........完整代码请登录后点击上方下载按钮下载查看

网友评论0