import { nextTick, onMounted, ref } from 'vue'
import * as Cesium from 'cesium '
import gsap from 'gsap' onMounted ( ( ) => { ... } )
let rectGeometry = new Cesium. RectangleGeometry ( { rectangle : Cesium. Rectangle. fromDegrees ( 115 , 20 , 135 , 30 ) , height : 0 , ` vertexFormat:顶点格式,这里使用 ` PerInstanceColorAppearance` 的顶点格式,允许每个实例有独立的颜色 ` ` 如果使用【Cesium.Material.fromType】这里的【vertexFormat】就必须用这个EllipsoidSurfaceAppearance ` vertexFormat : Cesium. EllipsoidSurfaceAppearance. VERTEX_FORMAT
} )
let instance = new Cesium. GeometryInstance ( { id : 'redRect' , geometry : rectGeometry, attributes : { color : Cesium. ColorGeometryInstanceAttribute. fromColor ( Cesium. Color. RED . withAlpha ( 0.5 ) ) }
} ) let rectGeometry_1 = new Cesium. RectangleGeometry ( { rectangle : Cesium. Rectangle. fromDegrees ( 140 , 20 , 160 , 30 ) , height : 0
} )
let instance_1 = new Cesium. GeometryInstance ( { id : 'blueRect' , geometry : rectGeometry_1, attributes : { color : Cesium. ColorGeometryInstanceAttribute. fromColor ( Cesium. Color. BLUE . withAlpha ( 0.5 ) ) } , vertexFormat : Cesium. EllipsoidSurfaceAppearance. VERTEX_FORMAT
} )
let material_1 = new Cesium. Material ( { fabric : { type : 'Color' , uniforms : { color : new Cesium. Color ( 1.0 , 0.0 , 0.0 , 0.5 ) } }
} )
let material_1 = new Cesium. Material ( { fabric : { type : 'Image' , uniforms : { image : '../public/texture/logo.png' } }
} )
console. log ( 'material_1=' , material_1)
console. log ( 'material_1=' , material_1. shaderSource) ` 【编写着色器材质】 `
let material_1 = new Cesium. Material ( { ` 【 ` fabric` 属性,是Cesium材质的核心,它允许你使用GLSL(OpenGL Shading Language)代码来自定义材质的行为】 ` fabric : { uniforms : { uTime : 0 } , source : ` // czm_getMaterial(), 是GLSL函数的开始, 是Cesium材质系统的核心czm_material czm_getMaterial(czm_materialInput materialInput){// 调用 czm_getDefaultMaterial 函数, 初始化为Cesium的默认材质, 这允许你在默认材质的基础上进行修改czm_material material = czm_getDefaultMaterial(materialInput); // 官方默认// ----------- 自定义内容-start -----------// 效果一// 将材质的, 漫反射颜色, 设置为红色(RGB: 1.0, 0.0, 0.0), 这意味着对象将显示为红色// material.diffuse = vec3(1.0, 0.0, 0.0);// 效果二: materialInput.st ,是一个包含纹理坐标的二维向量// material.diffuse = vec3(materialInput.st, 0.0);// 效果三material.diffuse = vec3(materialInput.st+uTime, 0.0);// 效果四:条纹效果// float strength = mod((materialInput.st.s+uTime) * 10.0, 1.0); // 加减的作用:调整方向// float strength = mod((materialInput.st.s-uTime)*10.0, 1.0);// float strength = mod((materialInput.st.t-uTime)*10.0, 1.0);// material.diffuse = vec3(strength, 0.0, 0.0);// ----------- 自定义内容-end -----------return material; // 官方默认} ` }
} ) gsap. to ( material_1. uniforms, { uTime : 1 , duration : 2 , repeat : - 1 , ease : 'linear'
} ) ` ` EllipsoidSurfaceAppearance` :设置,几何体都是与地球的椭球体平行,假定,几何体 与 地球的椭球体 平行,就可以,在计算大量顶点属性的时候节省内存。 `
let appearance = new Cesium. EllipsoidSurfaceAppearance ( { material : material_1, aboveGround : true , translucent : true
} )
let primitive = new Cesium. Primitive ( { geometryInstances : [ instance, instance_1] , appearance : appearance, show : true
} ) nextTick ( ( ) => { setView ( ) viewer. value. scene. primitives. add ( primitive)
} )