supermap iclient3d for cesium场景加载雨雪效果,并加载相应材质

首先新建一个文件夹来存放材质,我选择src/assets/MaterialJson

snow.json,复制粘贴,雨雪用一个就行了

{
  "material": {
    "id": "DA82AFCB-129A-4E66-995A-9F519894F58D",
    "cullMode": "none",
    "alphaMode": "opaque",
    "alphaCutoff": 0.009999999776482582,
    "vertexShaderName": "",
    "fragmentShaderName": "",
    "pbrMetallicRoughness": {
      "emissiveFactor": { "x": 0.0, "y": 0.0, "z": 0.0 },
      "emissiveTextureIndex": -1,
      "emissiveTextureCoordIndex": -1,
      "emissiveTextureMotion": {
        "OffsetSpeedU": 0.0,
        "OffsetSpeedV": 0.0,
        "OffsetPeriod": 0.0,
        "TilingSpeedU": 1.0,
        "TilingSpeedV": 1.0,
        "TilingPeriod": 0.0
      },
      "normalTextureIndex": -1,
      "normalTextureCoordIndex": 0,
      "normalTextureScale": 0.1,
      "occlusionTextureIndex": -1,
      "occlusionTextureCoordIndex": -1,
      "occlusionTextureStrength": 1.0,
      "baseColor": { "x": 1.0, "y": 1.0, "z": 1.0, "w": 1.0 },
      "baseColorTextureIndex": -1,
      "baseColorTextureCoordIndex": 0,
      "baseColorTextureMotion": {
        "OffsetSpeedU": 0.0,
        "OffsetSpeedV": 0.0,
        "OffsetPeriod": 0.0,
        "TilingSpeedU": 1.0,
        "TilingSpeedV": 1.0,
        "TilingPeriod": 0.0
      },
      "metallicRoughnessTextureIndex": 1,
      "metallicRoughnessTextureCoordIndex": 0,
      "metallicFactor": 0.1,
      "roughnessFactor": 1.0,
      "snowEffect": {
        "snowMaskTextureIndex": 4,
        "snowNormalTextureIndex": 5,
        "snow_coverage": 0.32
      }
    },
    "textureunitstates": [
      {
        "textureunitstate": {
          "id": "M_Brick_Clay_Old_BaseTexMap",
          "url": "M_Brick_Clay_Old_BaseTexMap.png",
          "addressmode": { "u": 0, "v": 0, "w": 0 },
          "filteringoption": 0,
          "filtermin": 2,
          "filtermax": 2,
          "texmodmatrix": [
            1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
            0.0, 0.0, 1.0
          ]
        }
      },
      {
        "textureunitstate": {
          "id": "M_Brick_Clay_Old_MetallicRoughMap",
          "url": "M_Brick_Clay_Old_MetallicRoughMap.png",
          "addressmode": { "u": 0, "v": 0, "w": 0 },
          "filteringoption": 0,
          "filtermin": 2,
          "filtermax": 2,
          "texmodmatrix": [
            1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
            0.0, 0.0, 1.0
          ]
        }
      },
      {
        "textureunitstate": {
          "id": "M_Brick_Clay_Old_NormalMap",
          "url": "M_Brick_Clay_Old_NormalMap.png",
          "addressmode": { "u": 0, "v": 0, "w": 0 },
          "filteringoption": 0,
          "filtermin": 2,
          "filtermax": 2,
          "texmodmatrix": [
            1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
            0.0, 0.0, 1.0
          ]
        }
      },
      {
        "textureunitstate": {
          "id": "M_Brick_Clay_Old_Ripple",
          "url": "Ripple_Sheet.png",
          "addressmode": { "u": 0, "v": 0, "w": 0 },
          "filteringoption": 0,
          "filtermin": 2,
          "filtermax": 2,
          "texmodmatrix": [
            1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
            0.0, 0.0, 1.0
          ]
        }
      },
      {
        "textureunitstate": {
          "id": "Snow_masks",
          "url": "Snow_masks.png",
          "addressmode": { "u": 0, "v": 0, "w": 0 },
          "filteringoption": 0,
          "filtermin": 2,
          "filtermax": 2,
          "texmodmatrix": [
            1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
            0.0, 0.0, 1.0
          ]
        }
      },
      {
        "textureunitstate": {
          "id": "Snow_normal",
          "url": "Snow_normal.png",
          "addressmode": { "u": 0, "v": 0, "w": 0 },
          "filteringoption": 0,
          "filtermin": 2,
          "filtermax": 2,
          "texmodmatrix": [
            1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
            0.0, 0.0, 1.0
          ]
        }
      }
    ]
  }
}

然后需要加载一个三维模型,我就用iserver里面的CBD演示,

有这五个图层,等会就把树换下材质

选择树

let treeLayer = scene.layers.find("Tree@CBD") 
//设置材质
treeLayer.setPBRMaterialFromJSON(snow)

开启雪模式

        viewer.scene.postProcessStages.rain.enabled = false
        viewer.scene.postProcessStages.snow.enabled = true
		viewer.scene.postProcessStages.snow.uniforms.density = 10;
		viewer.scene.postProcessStages.snow.uniforms.angle = 0;
		viewer.scene.postProcessStages.snow.uniforms.speed = 3;

可以看到树都是白白的

开启雨

         viewer.scene.postProcessStages.rain.enabled = true
      viewer.scene.postProcessStages.snow.enabled = false
          viewer.scene.postProcessStages.rain.uniforms.angle = 6;
          viewer.scene.postProcessStages.rain.uniforms.speed = 6;

完整代码

<!-- 拖动滑块控制球体属性 -->
<template>
    <div class="PartOneBox">
        <div id="cesiumContainer"></div>
        <button style="border:1px solid red;padding:5px;" @click="type=!type">点我晴雪天切换</button>
    </div>
</template>

<script setup lang='ts'>
import { ref, reactive,onMounted, watchEffect} from 'vue'
import snow from "../assets/MaterialJson/snow.json"
//true是雨天,false雪天
let type=ref(true)
let scene:any={}
let viewer:any={}

onMounted(()=>
{
        viewer = new Cesium.Viewer('cesiumContainer')
         scene = viewer.scene

        //设置时间,会影响光线
        var utc=Cesium.JulianDate.fromDate(new Date("2024/08/26 9:30:00"))
        viewer.clock.currentTime=Cesium.JulianDate.addHours(utc,8,new Cesium.JulianDate())
        var labelImagery = new Cesium.TiandituImageryProvider({
            mapStyle: Cesium.TiandituMapsStyle["IMG_C"],//天地图全球中文注记服务
            token: "这是你的,你需要申请,也可以不加载底图" //由天地图官网申请的密钥
        })
        viewer.imageryLayers.addImageryProvider(labelImagery)
        //加载里面全部模型,也可以单个加载但不是用这个API
       scene.open("http://localhost:8090/iserver/services/3D-CBD/rest/realspace")

})

watchEffect(()=>
{
    if(type.value)
{
    if(scene.layers)
{
    let treeLayer = scene.layers.find("Tree@CBD") 
        treeLayer.removePBRMaterial()
        viewer.scene.postProcessStages.rain.enabled = false
        viewer.scene.postProcessStages.snow.enabled = true
		viewer.scene.postProcessStages.snow.uniforms.density = 10;
		viewer.scene.postProcessStages.snow.uniforms.angle = 0;
		viewer.scene.postProcessStages.snow.uniforms.speed = 3;
        treeLayer.setPBRMaterialFromJSON(snow)
}
}
else
{
    let treeLayer = scene.layers.find("Tree@CBD") 
        treeLayer.removePBRMaterial()     
         viewer.scene.postProcessStages.rain.enabled = true
      viewer.scene.postProcessStages.snow.enabled = false
          viewer.scene.postProcessStages.rain.uniforms.angle = 6;
          viewer.scene.postProcessStages.rain.uniforms.speed = 6;
        treeLayer.setPBRMaterialFromJSON(snow)
}

})

</script>

<style scoped lang='scss'>
.PartOneBox
{
    width:1200px;
    height:1000px;
    margin:50px auto;
    position:relative;
    .cesiumContainer
    {
        width:100%;
        height:100%;
    }
}


</style>
相关推荐
是小崔啊5 分钟前
开源轮子 - EasyExcel02(深入实践)
java·开源·excel
VVVVWeiYee11 分钟前
项目2路由交换
运维·服务器·网络·网络协议·信息与通信
myNameGL37 分钟前
linux安装idea
java·ide·intellij-idea
青春男大39 分钟前
java栈--数据结构
java·开发语言·数据结构·学习·eclipse
HaiFan.1 小时前
SpringBoot 事务
java·数据库·spring boot·sql·mysql
我要学编程(ಥ_ಥ)1 小时前
一文详解“二叉树中的深搜“在算法中的应用
java·数据结构·算法·leetcode·深度优先
music0ant1 小时前
Idea 添加tomcat 并发布到tomcat
java·tomcat·intellij-idea
小伍_Five2 小时前
透视网络世界:计算机网络习题的深度解析与总结【前3章】
服务器·网络·计算机网络
计算机徐师兄2 小时前
Java基于SSM框架的无中介租房系统小程序【附源码、文档】
java·微信小程序·小程序·无中介租房系统小程序·java无中介租房系统小程序·无中介租房微信小程序
源码哥_博纳软云2 小时前
JAVA智慧养老养老护理帮忙代办陪诊陪护小程序APP源码
java·开发语言·微信小程序·小程序·微信公众平台