cesium设置近地天空盒 天空会倾斜

上篇文章讲解了如何设置近地天空盒,效果出来了还是发现天空是斜的

https://blog.csdn.net/m0_63701303/article/details/135618244

效果:

这里需要修改Cesium.skyBox的代码,代码如下直接全部复制组件内调用即可

skybox_nearground.js:


/* eslint-disable */
(function () {
    const Cesium = window.Cesium;
    const BoxGeometry = Cesium.BoxGeometry;
    const Cartesian3 = Cesium.Cartesian3;
    const defaultValue = Cesium.defaultValue;
    const defined = Cesium.defined;
    const destroyObject = Cesium.destroyObject;
    const DeveloperError = Cesium.DeveloperError;
    const GeometryPipeline = Cesium.GeometryPipeline;
    const Matrix3 = Cesium.Matrix3;
    const Matrix4 = Cesium.Matrix4;
    const Transforms = Cesium.Transforms;
    const VertexFormat = Cesium.VertexFormat;
    const BufferUsage = Cesium.BufferUsage;
    const CubeMap = Cesium.CubeMap;
    const DrawCommand = Cesium.DrawCommand;
    const loadCubeMap = Cesium.loadCubeMap;
    const RenderState = Cesium.RenderState;
    const VertexArray = Cesium.VertexArray;
    const BlendingState = Cesium.BlendingState;
    const SceneMode = Cesium.SceneMode;
    const ShaderProgram = Cesium.ShaderProgram;
    const ShaderSource = Cesium.ShaderSource;
    //片元着色器,直接从源码复制
    const SkyBoxFS = `uniform samplerCube u_cubeMap;
    varying vec3 v_texCoord;
    void main()
    {
    vec4 color = textureCube(u_cubeMap, normalize(v_texCoord));
    gl_FragColor = vec4(czm_gammaCorrect(color).rgb, czm_morphTime);
    }
    `;

    //顶点着色器有修改,主要是乘了一个旋转矩阵
    const SkyBoxVS = `attribute vec3 position;
    varying vec3 v_texCoord;
    uniform mat3 u_rotateMatrix;
    void main()
    {
    vec3 p = czm_viewRotation * u_rotateMatrix * (czm_temeToPseudoFixed * (czm_entireFrustum.y * position));
    gl_Position = czm_projection * vec4(p, 1.0);
    v_texCoord = position.xyz;
    }
    `;
    /**
    * 为了兼容高版本的Cesium,因为新版cesium中getRotation被移除
    */
    if (!Cesium.defined(Cesium.Matrix4.getRotation)) {
        Cesium.Matrix4.getRotation = Cesium.Matrix4.getMatrix3
    }
    function SkyBoxOnGround(options) {
        /**
        * 近景天空盒
        * @type Object
        * @default undefined
        */
        this.sources = options.sources;
        this._sources = undefined;

        /**
        * Determines if the sky box will be shown.
        *
        * @type {Boolean}
        * @default true
        */
        this.show = defaultValue(options.show, true);

        this._command = new DrawCommand({
            modelMatrix: Matrix4.clone(Matrix4.IDENTITY),
            owner: this
        });
        this._cubeMap = undefined;

        this._attributeLocations = undefined;
        this._useHdr = undefined;
    }

    const skyboxMatrix3 = new Matrix3();
    SkyBoxOnGround.prototype.update = function (frameState, useHdr) {
        const that = this;

        if (!this.show) {
            return undefined;
        }

        if ((frameState.mode !== SceneMode.SCENE3D) &&
            (frameState.mode !== SceneMode.MORPHING)) {
            return undefined;
        }

        if (!frameState.passes.render) {
            return undefined;
        }

        const context = frameState.context;

        if (this._sources !== this.sources) {
            this._sources = this.sources;
            const sources = this.sources;

            if ((!defined(sources.positiveX)) ||
                (!defined(sources.negativeX)) ||
                (!defined(sources.positiveY)) ||
                (!defined(sources.negativeY)) ||
                (!defined(sources.positiveZ)) ||
                (!defined(sources.negativeZ))) {
                throw new DeveloperError('this.sources is required and must have positiveX, negativeX, positiveY, negativeY, positiveZ, and negativeZ properties.');
            }

            if ((typeof sources.positiveX !== typeof sources.negativeX) ||
                (typeof sources.positiveX !== typeof sources.positiveY) ||
                (typeof sources.positiveX !== typeof sources.negativeY) ||
                (typeof sources.positiveX !== typeof sources.positiveZ) ||
                (typeof sources.positiveX !== typeof sources.negativeZ)) {
                throw new DeveloperError('this.sources properties must all be the same type.');
            }

            if (typeof sources.positiveX === 'string') {
                // Given urls for cube-map images. Load them.
                loadCubeMap(context, this._sources).then(function (cubeMap) {
                    that._cubeMap = that._cubeMap && that._cubeMap.destroy();
                    that._cubeMap = cubeMap;
                });
            } else {
                this._cubeMap = this._cubeMap && this._cubeMap.destroy();
                this._cubeMap = new CubeMap({
                    context: context,
                    source: sources
                });
            }
        }

        const command = this._command;

        command.modelMatrix = Transforms.eastNorthUpToFixedFrame(frameState.camera._positionWC);
        if (!defined(command.vertexArray)) {
            command.uniformMap = {
                u_cubeMap: function () {
                    return that._cubeMap;
                },
                u_rotateMatrix: function () {
                    return Matrix4.getRotation(command.modelMatrix, skyboxMatrix3);
                },
            };

            const geometry = BoxGeometry.createGeometry(BoxGeometry.fromDimensions({
                dimensions: new Cartesian3(2.0, 2.0, 2.0),
                vertexFormat: VertexFormat.POSITION_ONLY
            }));
            const attributeLocations = this._attributeLocations = GeometryPipeline.createAttributeLocations(geometry);

            command.vertexArray = VertexArray.fromGeometry({
                context: context,
                geometry: geometry,
                attributeLocations: attributeLocations,
                bufferUsage: BufferUsage._DRAW
            });

            command.renderState = RenderState.fromCache({
                blending: BlendingState.ALPHA_BLEND
            });
        }

        if (!defined(command.shaderProgram) || this._useHdr !== useHdr) {
            const fs = new ShaderSource({
                defines: [useHdr ? 'HDR' : ''],
                sources: [SkyBoxFS]
            });
            command.shaderProgram = ShaderProgram.fromCache({
                context: context,
                vertexShaderSource: SkyBoxVS,
                fragmentShaderSource: fs,
                attributeLocations: this._attributeLocations
            });
            this._useHdr = useHdr;
        }

        if (!defined(this._cubeMap)) {
            return undefined;
        }

        return command;
    };
    SkyBoxOnGround.prototype.isDestroyed = function () {
        return false
    };
    SkyBoxOnGround.prototype.destroy = function () {
        const command = this._command;
        command.vertexArray = command.vertexArray && command.vertexArray.destroy();
        command.shaderProgram = command.shaderProgram && command.shaderProgram.destroy();
        this._cubeMap = this._cubeMap && this._cubeMap.destroy();
        return destroyObject(this);
    }
    Cesium.GroundSkyBox = SkyBoxOnGround
})();

组件内引入skybox_nearground.js就可使用

注意结尾这是Cesium.GroundSkyBox = SkyBoxOnGround 所以设置天空盒的时候需要从new Cesium.SkyBox()改为new Cesium.GroundSkyBox()

import "./skybox_nearground.js";

const wanxiaSkybox = new Cesium.GroundSkyBox({
  sources: {
    positiveX: "../../imgs/天空盒2/wanxia/SunSetRight.png",
    negativeX: "../../imgs/天空盒2/wanxia/SunSetLeft.png",
    positiveY: "../../imgs/天空盒2/wanxia/SunSetFront.png",
    negativeY: "../../imgs/天空盒2/wanxia/SunSetBack.png",
    positiveZ: "../../imgs/天空盒2/wanxia/SunSetUp.png",
    negativeZ: "../../imgs/天空盒2/wanxia/SunSetDown.png",
  },
});

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/325507.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

福州真兰水表有限公司精益六西格玛项目总结发布会:推动质量改进的成功案例展示

2024年1月3日,福州真兰水表有限公司2023年度DMAIC项目总结发布会如期举行。ZENNER真兰集团中国区总裁杨燕明先生,张驰咨询公司精益六西格玛黑带大师朱成朝老师,福州真兰水表有限公司副总经理杨岚琴女士,以及生产经理(倡…

一些平时很少用,但关键时刻很有用的华为手机功能

天灾,自古以来就是威不可知亦不可测的东西,但大自然中的很多意外,其实可以做到有迹可循。 地震预警功能 前段时间频繁地震,一个月内先是积石山,而后是日本能登。 这时候,手机上的地震预警功能就是能够帮…

复旦、交大、清华等公布2023届本科生毕业数据

近日多所高校发布《2022-2023学年本科教学质量报告》,包含各高校本科毕业生就业升学情况,一起来看看吧~ 01 清华大学 清华大学推免率超60% 据报告显示,2023年清华大学本科毕业生总数 3609 人,授予学士学位3519 人。应…

什么样的耳机适合游泳?游泳耳机对人体有危害吗?

游泳是一项深受大家喜爱的运动,不仅可以锻炼身体,还能让我们享受到水中的乐趣。然而,对于喜欢在水中听音乐的人来说,选择一款适合游泳的耳机就显得尤为重要了。 游泳耳机是一种专为水上运动设计的防水耳机,可以在游泳、…

48-DOM

1.DOM基础 Document Object Module,文档对象模型,window对象,document文档,都可以获取和操作 1)文档节点 2)属性节点(标签内的属性href,src) 3)文本节点(标签内的文字) 4)注释节点 5)元素节点(标签) 2.获取元素节点 2.1通过标签名获取 <p>1</p><…

Apache StringUtils:Java字符串处理工具类

简介 在我们的代码中经常需要对字符串判空&#xff0c;截取字符串、转换大小写、分隔字符串、比较字符串、去掉多余空格、拼接字符串、使用正则表达式等等。如果只用 String 类提供的那些方法&#xff0c;我们需要手写大量的额外代码&#xff0c;不然容易出现各种异常。现在有…

chatgpt实用技巧之二反问式提示

大家好&#xff0c;今天跟大家讲实用gpt的小技巧二、反问式提示 有时候不知道怎么给 GPT 提示词&#xff0c;这时候&#xff0c;就可以反问 GPT 如何更好地给提示词。如图片所示 更详细内容可以看下这篇&#xff1a; 按照 GPT 给出的&#xff1a;故事设定角色故事发展主题结局…

git提交文本或者word到git教程,git创建仓库时候自带

简易的命令行入门教程: Git 全局设置: git config --global user.name “XX” git config --global user.email “XXXqq.com” 创建 git 仓库: mkdir test cd test git init touch README.md git add README.md git commit -m “first commit” git remote add origin https:…

Verilog语法——5.测试文件

参考资料 【明德扬_verilog零基础入门语法HDL仿真快速掌握-手把手教你写FPGA/ASIC代码设计流程中的应用】 5. 测试文件 5.1 认识测试文件&#xff08;testbench&#xff09; testbench是一种验证的手段。首先&#xff0c;任何设计都是会有输入输出的。 但是在软环境中没有激励…

50天精通Golang(第18天)

web开发介绍、iris框架安装、HTTP请求和返回、Iris路由处理 一 Web项目开发介绍及实战项目介绍 1.1 引言 本系列课程我们将学些Golang语言中的Web开发框架Iris的相关知识和用法。通过本系列视频课程&#xff0c;大家能够从零到一经历一个完整项目的开发&#xff0c;并在课程…

壹基金“安全家园”项目瑞金市城北社区志愿者救援队成立

项目介绍&#xff1a;阿里巴巴公益&壹基金安全家园项目 -社区志愿者救援队专项行动是一个以社区为本的防灾减灾公益项目。据介绍&#xff0c;该项目通过推动社区建立自己的志愿者救援队伍&#xff0c;为队伍“配物资”“办培训”&#xff0c;并协助他们动员居民参与“家庭—…

宝宝洗衣机买几公斤?婴儿专用洗衣机测评

由于幼龄时期的宝宝的皮肤比较娇嫩&#xff0c;很容易受到伤害。所以小宝宝的衣服一般都是棉质的&#xff0c;很柔软&#xff0c;很亲肤的&#xff0c;为的就是保护宝贝们娇嫩的肌肤。而宝宝们在日常中更换衣物会相对频繁&#xff0c;换的衣物也必须及时清洗晾晒&#xff0c;以…

1-数组-有效的数独

这是数组的第一题&#xff0c;从现在开始开启数组篇章。力扣链接。 请你判断一个 9 x 9 的数独是否有效。只需要 根据以下规则 &#xff0c;验证已经填入的数字是否有效即可。 数字 1-9 在每一行只能出现一次。数字 1-9 在每一列只能出现一次。数字 1-9 在每一个以粗实线分隔的…

锐意进取,蓬勃发展|爱基百客2023全景图

岁序更迭&#xff0c;2023年已悄然离去。对我们来说&#xff0c;这是充满挑战与机遇的一年。爱基百客作为一家专注于测序服务的公司&#xff0c;我们在这一年里经历了许多挑战&#xff0c;也取得了令人鼓舞的成绩。前面我们盘点了表观产品和单细胞产品&#xff0c;今天再邀您回…

.Net 8.0 Web API Controllers 添加到 windows 服务

示例源码下载&#xff1a;https://download.csdn.net/download/hefeng_aspnet/88747022 创建 Windows 服务的方法之一是从工作线程服务模板开始。 但是&#xff0c;如果您希望能够让它托管 API 控制器&#xff08;也许是为了查看它正在运行的进程的状态&#xff09;&#xff0…

企业知识库搭建全流程,中小型企业必看

知识库是企业知识管理和信息查询的重要平台&#xff0c;对企业效率提升&#xff0c;业务流程规范和企业文化建设有着重要的影响。那么&#xff0c;如何为企业搭建一个合适&#xff0c;高效&#xff0c;易用的知识库呢&#xff1f;接下来就为中小型企业详解企业知识库搭建全流程…

什么是二维码?带你快速了解二维码的原理

二维条码是指在一维条码的基础上扩展出另一维具有可读性的条码&#xff0c;使用黑白矩形图案表示二进制数据&#xff0c;被设备扫描后可获取其中所包含的信息。与一维条码不同的是&#xff0c;二维条码的长度和宽度都可以记载数据&#xff0c;而一维条码仅宽度记载数据。二维条…

yolo使用tensorboard查看训练过程

在终端打开并将此处的路径替换成绝对路径即可。 # tensorboard --logdir "绝对路径" tensorboard --logdir"D:\Learning\PycharmProjects\yolov8\ultralytics-main\runs\detect\train4" 参考&#xff1a;查看训练过程

Samtec工程师分享ADS Design Guide Developer Studio | Keysight EDA创新论坛上的思维碰撞

【摘要/前言】 "Samtec 始终为客户提供卓越的信号完整性支持。有时&#xff0c;我们协助客户通过模拟来评估通道。不同的参数设置会导致不同的模拟结果&#xff0c;为了避免这一情况发生&#xff0c;我们利用 ADS Design Guide Developer Studio统一了通道配置。" …

C++——STL标准模板库——容器详解——list

一、基本概念 &#xff08;一&#xff09;定义 list&#xff1a;双向链表。list是一种分布式存储的线性表&#xff0c;每个节点分为数据域和指针域&#xff0c;其中指针域中包含一个指向前驱节点的指针和一个指向后续节点的指针&#xff0c;基本模型如下&#xff1a; &#…
最新文章