three实现三维柱状体数据排名对比动画效果代码

代码语言:html

所属分类:三维

代码描述:three实现三维柱状体数据排名对比动画效果代码

代码标签: three 三维 柱状体 数据 排名 对比 动画

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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3D Bar Chart with Three.js</title>
    <style>
        body { margin: 0; }
        canvas { display: block; }
    </style>
</head>
<body>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.128.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/tween.min.js"></script>
    <script>
        let scene, camera, renderer, bars = [];
        const barData = [
            { height: 5, text: "First", imageUrl: "//repo.bfw.wiki/bfwrepo/image/5fe5bbd800ea5.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" },
            { height: 3, text: "Second", imageUrl: "//repo.bfw.wiki/bfwrepo/image/60078a8d5f89d.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" },
            { height: 7, text: "Third", imageUrl: "//repo.bfw.wiki/bfwrepo/image/60d41f497bade.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" },
            { height: 2, text: "Fourth", imageUrl: "//repo.bfw.wiki/bfwrepo/image/60d41f5173b0d.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" },
            { height: 6, text: "Fifth", imageUrl: "//repo.bfw.wiki/bfwrepo/image/6257e9f53b418.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" }
        ];

        function init() {
            scene = new THREE.Scene();
            camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
            renderer = new THREE.WebGLRenderer({ antialias: true });
            renderer.setSize(window.innerWidth, window.innerHeight);
            renderer.shadowMap.enabled = true;
            document.body.appendChild(renderer.domElement);

            // Sunlight
            const sunLight = new THREE.DirectionalLight(0xffffaa, 1.2);
            sunLight.position.set(50, 100, 50);
            sunLight.castShadow = true;
            scene.add(sunLight);

            // Ambient light
            const ambientLight = new THREE.AmbientLight(0x404040, 0.5);
            scene.add(ambientLight);

            // Sky
            scene.background = new THREE.Color(0x87CEEB);

            // Ground
            const groundGeometry = new THREE.PlaneGeometry(1000, 1000);
            const groundMaterial = new THREE.MeshLambertMaterial({ color: 0x558833 });
            const ground = new THREE.Mesh(groundGeometry, groundMaterial);
            ground.rotation.x = -Math.PI / 2;
            ground.position.y = -0.1;
            ground.receiveShadow = true;
            scene.add(ground);

            // Mountains
            createMountains();

            // Create bars
            barData.forEach((data, index) => {
                createBar(data, index);
            });

            // Position camera
            camera.position.set(-10, 5, 10);
            camera.lookAt(bars[0].position);

            // Start animation
            animateCamera();
        }

        function createMountains() {
            const mountainGeometry = new THREE.ConeGeometry(50, 100, 4);
            const mountainMaterial = new THREE.MeshPhongMaterial({ color: 0x654321 }).........完整代码请登录后点击上方下载按钮下载查看

网友评论0