Primitive外观(appearance)
//PerInstanceColorAppearance的意思是直接使用实例的颜色去着色(几何实例自身的颜色属性是什么颜色就是什么颜色)
//let appearance = new Cesium.PerInstanceColorAppearance({
//flat: true,
//})
//和Entity的材质属性设置不同(Entity使用的是MaterialProperty) primitive使用的类是Material
//fromType方法作用是 生成一个已存在的材质类型 下面就是生成一个颜色材质类型
let materialPrimitive=Cesium.Material.fromType("Color",{
color:Cesium.Color.AQUA.withAlpha(0.5),
});
//EllipsoidSurfaceAppearance 创建一个椭球面外观(这个外观可以在计算大量顶点属性的时候节省内存) 这个是比较常用的
// 当前图元的appearance是EllipsoidSurfaceAppearance时,几何体实例里的几何体的vertexFormat(顶点格式)也要是对应的外观顶点格式 也就是 EllipsoidSurfaceAppearance.VERTEX_FORMAT
//let appearance1=new Cesium.EllipsoidSurfaceAppearance({
//material:materialPrimitive,
//})
//使用MaterialAppearance
let appearance1=new Cesium.MaterialAppearance({
material:materialPrimitive,
})
//添加几何体实例
let primitive = new Cesium.Primitive({
geometryInstances: [instance, instance2],
appearance: appearance1,
})
primitive 材质类型
从Cesium官网可以看到,材质类型非常多。
下面记录几个常用的
Color
前面已经使用了
let materialPrimitive=Cesium.Material.fromType("Color",{
color:Cesium.Color.AQUA.withAlpha(0.5),
});
Image
let materialPrimitive=Cesium.Material.fromType("Image",{
image:"./Assets/Images/dog.png",
repeat:new Cesium.Cartesian2(1,1),
});
DiffuseMap
let materialPrimitive=Cesium.Material.fromType("DiffuseMap",{
image:"./Assets/Images/dog.png",
repeat:new Cesium.Cartesian2(2,2),
});
两个image显示效果 好像看不出啥区别
Grid
let materialPrimitive=Cesium.Material.fromType("Grid",{
color:Cesium.Color.AQUA.withAlpha(0.5),
cellAlpha:0, //网格单元透明度 网格直接没有了
lineCount:new Cesium.Cartesian2(7,8), //网格数
lineThickness:new Cesium.Cartesian2(6,2), //网格线粗
});
Dot
let materialPrimitive=Cesium.Material.fromType("Dot",{
lightColor:Cesium.Color.AQUA.withAlpha(0.5), //点的颜色
darkColor:Cesium.Color.BLACK.withAlpha(0.5), //点所在的背景颜色
repeat:new Cesium.Cartesian2(2,2), //几行几列 点
});
Water
let materialPrimitive=Cesium.Material.fromType("Water",{
baseWaterColor:Cesium.Color.AQUA.withAlpha(0.5),
blendColor:Cesium.Color.BLACK.withAlpha(0.5),
specularIntensity:0.5,
normalMap:"./Assets/Textures/waterNormals.jpg",
frequency:1000.0, //波浪的数量
animationSpeed:0.01, //波浪动画的速度
amplitude:10.0, //波浪的振幅
});
这个水的效果最强