湛江seo网站推广,西安app制作开发公司,新闻热点事件2022,怎么免费做网站推广上一节课#xff0c;我们能在 Primitive 里徒手写着色器#xff1b;今天把“魔杖”伸回 Entity——让它也用上完全自定义的材质。 思路一句话#xff1a;Entity 只认 MaterialProperty 接口#xff0c;我们手写一个类#xff0c;把 Fabric GLSL 塞进去#xff0c;就能像…上一节课我们能在 Primitive 里徒手写着色器今天把“魔杖”伸回Entity——让它也用上完全自定义的材质。思路一句话Entity 只认MaterialProperty接口我们手写一个类把 Fabric GLSL 塞进去就能像官方材质一样随取随用。一、MaterialProperty 接口长啥样官方把MaterialProperty当“抽象基类”规定必须实现getType()—— 返回材质字符串 IDgetValue(time, result)—— 每帧把最新 uniform 值写进 resultdefinitionChanged—— 事件对象通知 Entity“我变了请重绘”。照猫画虎自己写个类即可。二、最小能跑的案例CustomMaterialProperty步骤先在 Cesium 材质缓存里注册一个同名 Fabric再在getValue里不停刷新 uniformEntity 里当普通材质用。class CustomMaterialProperty { constructor() { // 1. 通知系统“我要变”的事件 this.definitionChanged new Cesium.Event(); // 2. 把 Fabric 写进全局缓存ID 叫 CustomMaterial Cesium.Material._materialCache.addMaterial(CustomMaterial, { fabric: { type: CustomMaterial, uniforms: { uTime: 0.0 // 初始值 }, source: czm_material czm_getMaterial(czm_materialInput materialInput) { czm_material mat czm_getDefaultMaterial(materialInput); mat.diffuse vec3(materialInput.st, uTime); // UV时间当颜色 return mat; } } }); } // 3. 返回材质 ID getType() { return CustomMaterial; } // 4. 每帧被 Entity 调用把最新时间写回 uniform getValue(time, result) { result.uTime (performance.now() / 1000) % 1; // 0~1 循环 return result; } }代码写完后当普通材质直接用const customMaterial new CustomMaterialProperty(); viewer.entities.add({ name: Red translucent rectangle, rectangle: { coordinates: Cesium.Rectangle.fromDegrees(114.0, 23.4, 114.4, 23.6), extrudedHeight: 30000.0, material: customMaterial, // 自己的材质 }, });刷新场景矩形立刻带上“UV 彩条”并且红色通道随时间流动——自定义成功三、想更平滑交给 GSAP 去补间performance.now()虽然简单但节奏固定。想要“呼吸”效果可把 uniform 外包给 GSAP// 1. 先在构造函数里准备参数对象 this.params { uTime: 0.0 }; gsap.to(this.params, { uTime: 1.0, duration: 2.0, repeat: -1, ease: linear }); // 2. getValue 只负责“搬运” getValue(time, result) { result.uTime this.params.uTime; return result; }现在条纹会像扫描线一样来回走动完全平滑。四、常见坑提醒ID 必须对应Fabric 的type/getType()/ 缓存 key 三处要完全一致getValue里一定要return result否则 Entity 拿不到新值想刷新画面就触发this.definitionChanged.raiseEvent(this)Entity 才会重绘。五、小结与展望Entity 自定义材质 实现MaterialProperty接口 注册同名 Fabric。时间动画既能用performance.now()也能让 GSAP 补间参数。下一步把“UV时间”换成“距离时间”一个标准“雷达扫描圈”就呼之欲出了。