three+perlin-noise实现上下起伏干旱开裂土地地形代码

代码语言:html

所属分类:三维

代码描述:three+perlin-noise实现上下起伏干旱开裂土地地形代码

代码标签: three perlin-noise 上下 起伏 干旱 开裂 土地 地形 代码

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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
    <style>
        body { margin: 0; }
        canvas { display: block; }
    </style>
</head>
<body>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/three.133.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/GLTFLoader.133.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/OrbitControls.133.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/perlin-noise.js"></script>
    <script>
        let scene, camera, renderer, soldier, mixer, clock;
        let moveForward = false, moveBackward = false, moveLeft = false, moveRight = false;
        let controls;
        let idleAction, walkAction;
        const speed = 0.0001;
        const terrainSize = 1000;
        const maxTerrainHeight = 5;

        init();
        animate();

        function init() {
            scene = new THREE.Scene();
            scene.background = new THREE.Color(0x87CEEB); // Sky blue background

            camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
            camera.position.set(0, 20, 20);

            renderer = new THREE.WebGLRenderer();
            renderer.setSize(window.innerWidth, window.innerHeight);
            document.body.appendChild(renderer.domElement);

            const ambientLight = new THREE.AmbientLight(0xffffff, 0.1);
            scene.add(ambientLight);

            const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
            directionalLight.position.set(10, 20, 10);
            scene.add(directionalLight);
  // Sun
            const sunGeometry = new THREE.SphereGeometry(1, 32, 32);
            const sunMaterial = new THREE.MeshBasicMaterial({ color: 0xffffcc });
            const sun = new THREE.Mesh(sunGeometry, sunMaterial);
            sun.position.set(5, 20, -5);
            scene.add(sun);

            clock = new THREE.Clock();

            // Create terrain with texture
            createTerrain();

            controls = new THREE.OrbitControls(camera, renderer.domElement);
            controls.target.set(0, 0, 0);
            controls.update();

            window.addEventListener('resize', onWindowResize, false);
        }

        function createTerrain() {
            const geometry = new THREE.PlaneGeometry(terrainSize, terrainSize, terrainSize - 1, terrainSize - 1);
            geo.........完整代码请登录后点击上方下载按钮下载查看

网友评论0