Cesium-Examples/examples/cesiumEx/7.1.0、Primitive.html

122 lines
4.3 KiB
HTML
Raw Normal View History

2025-03-11 08:25:45 +00:00
<!--********************************************************************
* by jiawanlong
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
2025-03-19 03:00:22 +00:00
<link rel="stylesheet" href="./../../libs/cesium/Cesium1.98/Widgets/widgets.css" />
<script type="text/javascript" src="./../../libs/cesium/Cesium1.98/Cesium.js"></script>
2025-03-11 08:25:45 +00:00
</head>
<body style="
margin: 0;
overflow: hidden;
background: #fff;
width: 100%;
height: 100%;
position: absolute;
top: 0;
">
<div id="map" style="margin: 0 auto; width: 100%; height: 100%"></div>
<script type="text/javascript">
Cesium.Ion.defaultAccessToken =
2025-05-18 11:30:00 +00:00
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJjM2EzNGJmNy02N2RmLTQ0MDMtYjI2MS1hZTJiMTIwZGYwMTYiLCJpZCI6MzA0MzEyLCJpYXQiOjE3NDc3MjM3MTV9.ePQNhuoVuDsi_z00lTm5W26wyW1Adcr1AWetGM6WSXI";
2025-03-11 08:25:45 +00:00
const viewer = new Cesium.Viewer("map", {
contextOptions: {
// requestWebgl1: true,
},
});
viewer.scene.debugShowFramesPerSecond = true;
viewer.scene.globe.depthTestAgainstTerrain = true;
/*
----------------------------------Material-----------------------------
*/
// Primitive对象的自定义可视化Cesium为其提供了Appearance和Material对象。
// 其中Material只负责片段着色器中材质部分的代码
// 而Appearance负责该Primitive整个Shader的代码包括顶点着色器和片段着色器两个部分。
// 可以理解为Appearance为Material之上的又一层封装负责将Material赋给对应的Primitive对象。
// Appearance中的属性值Materia的三种创建方式
// 1、Material.fromType
// 2、new Cesium.Material()
// 3、fabric
/*
var appearance = new Cesium.MaterialAppearance();
viewer.scene.primitives.add(
new Cesium.Primitive({
geometryInstances: instances,
appearance: appearance
}));
// 1、Material.fromType
appearance.material = Cesium.Material.fromType('Color');
appearance.material.uniforms.color = new Cesium.Color(1.0, 1.0, 0.0, 1.0);
// 2、new Cesium.Material()
appearance.material = new Cesium.Material();
// 3、fabric
appearance.material = new Cesium.Material({
fabric: {
type: 'Color',
uniforms: {
color: new Cesium.Color(1.0, 1.0, 0.0, 1.0)
},
source: fs
}
});
*/
let source = `czm_material czm_getMaterial(czm_materialInput materialInput)
{
czm_material material = czm_getDefaultMaterial(materialInput);
vec2 st = materialInput.st;
vec4 colorImage = texture(image, vec2(fract((st.s - speed * czm_frameNumber * 0.001)), st.t));
material.alpha = colorImage.a * color.a;
material.diffuse = color.rgb;
return material;
}`;
2025-03-31 02:42:55 +00:00
2025-03-11 08:25:45 +00:00
let material = new Cesium.Material({
fabric: {
uniforms: {
color: Cesium.Color.fromCssColorString('#7ffeff'),
image: "./line1.png",
speed: 10,
},
source: source,
},
translucent: function () {
return true
},
});
var appearance = new Cesium.PolylineMaterialAppearance();
appearance.material = material;
viewer.scene.primitives.add(
new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry: new Cesium.PolylineGeometry({
positions: Cesium.Cartesian3.fromDegreesArray([
-112, 36,
-100, 38,
-90, 42
]),
width: 5.0,
}),
}),
appearance: appearance
})
);
</script>
</body>
</html>