Threejs 地图插件

20 篇文章 1 订阅
20 篇文章 7 订阅

import { GUI } from "three/examples/jsm/libs/lil-gui.module.min.js";
// 初始化地图
const mapViewer = new MapViewer({
    target: "container",
    center: mapCenter,
    camera: {
        near: 0.001
    },
    imageryTileProivder: new TdtImageryTileProvider()
});

//测试threejs场景
class TestData {
    public static init(mapViewer: MapViewer) {
        this.addAxesHelper(mapViewer);
        this.addLight(mapViewer);
    }

    private static addAxesHelper(mapViewer: MapViewer) {
        const axesHelper = new AxesHelper(50000000);
        mapViewer.renderer.scene.add(axesHelper);
    }

    private static addLight(mapViewer: MapViewer) {
        let scene = mapViewer.renderer.scene;
        let renderer = mapViewer.renderer.renderer;
        renderer.shadowMap.enabled = true;
        const gui = new GUI();
        renderer.physicallyCorrectLights = true;
        // 做一个球体
        const SphereGeometry = new THREE.SphereGeometry(10, 30, 30);
        // 材质
        const material = new THREE.MeshStandardMaterial();
        const sphere = new THREE.Mesh(SphereGeometry, material);
        sphere.position.set(0, 5, 0);
        // 投射阴影
        sphere.castShadow = true;
        scene.add(sphere);

        // 创建平面
        const planeGeometry = new THREE.PlaneGeometry(500, 500);
        const plane = new THREE.Mesh(planeGeometry, material);
        plane.position.set(0, -1, 0);
        plane.rotation.x = -Math.PI / 2;
        // 接收阴影
        plane.receiveShadow = true;
        scene.add(plane);

        // 灯光
        // 环境光
        const light = new THREE.AmbientLight(0xffffff);

        // 聚光源
        const spotLight = new THREE.SpotLight(0xffffff, 2);
        spotLight.position.set(50, 50, 50);
        spotLight.intensity = 2;
        // 设置直线光源产生阴影
        spotLight.castShadow = true;
        //设置阴影贴图模糊度
        spotLight.shadow.radius = 20;
        //设置阴影贴图的分辨率(让它变得更加细致)
        spotLight.shadow.mapSize.set(4096, 4096);
        //设置打在小球上
        spotLight.target = sphere;
        //聚光灯的角度
        spotLight.angle = Math.PI / 6;
        //聚光灯的衰减
        spotLight.distance = 0;
        //聚光灯的半影的衰减
        spotLight.penumbra = 0.5;
        //聚光灯 沿着光照距离的衰减
        spotLight.decay = 0;
        // 透视相机的属性设置(一般不用更改)

        scene.add(spotLight);
        scene.add(light);
        gui.add(sphere.position, "x").min(-500).max(500).step(0.1).name("球体x轴位置");
        gui
            .add(spotLight, "angle")
            .min(0)
            .max(Math.PI / 2)
            .step(0.01)
            .name("聚光灯角度");
        gui.add(spotLight, "distance").min(0).max(100).step(1).name("聚光灯距离");
        gui.add(spotLight, "penumbra").min(0).max(10).step(0.1).name("聚光灯半影");
        gui.add(spotLight, "decay").min(0).max(1).step(0.1).name("聚光灯衰减");
    }
}

TestData.init(mapViewer);

  • 8
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苹果园dog

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值