前幾篇博客咱們瞭解了自定義點、線、面繪製,這篇咱們接着學習cesium自定義紋理貼圖。咱們完成點線面的繪製,只是繪製出了對象的框架,沒有逼真的外觀。逼真外觀是須要設置材質來實現:Material 。
再次查看appearance對象:app
屬性裏面的material就是設置對象的材質,查看material:框架
咱們發現,cesium提供不少材質接口,若是要自定義設置紋理貼圖,咱們使用fabric接口定義本身材質。
首先看cesium給出的demo:async
咱們看到在uniforms屬性設置經過type設置類型、經過uniforms設置對應值。函數
直接上示例源碼(由於我也不知道爲什麼這樣寫):post
var viewer = new Cesium.Viewer('cesiumContainer'); //封裝PrimitiveTexture var PrimitiveTexture= ( function () { var vertexShader; var fragmentShader; var materialShader; var viewer; var url; function _(options) { viewer = options.viewer; vertexShader = getVS(); fragmentShader = getFS(); materialShader = getMS(); url = options.url ? options.url : 'sampledata/images/texture1'; if (options.Cartesians && options.Cartesians.length >= 3) { var postionsTemp = []; var stsTemp = []; var indicesTesm = []; for (var i = 0; i < options.Cartesians.length; i++) { postionsTemp.push(options.Cartesians[i].x); postionsTemp.push(options.Cartesians[i].y); postionsTemp.push(options.Cartesians[i].z); } for (var i = 0; i < options.Cartesians.length; i+=3) { indicesTesm.push(i); indicesTesm.push(i+1); indicesTesm.push(i + 2); stsTemp.push(0); stsTemp.push(1); stsTemp.push(1); stsTemp.push(1); stsTemp.push(1); stsTemp.push(0); } this.positionArr = new Float64Array(postionsTemp); this.sts = new Uint8Array(stsTemp); this.indiceArr = new Uint16Array(indicesTesm); } else { var p1 = Cesium.Cartesian3.fromDegrees(0, 0, -10); var p2 = Cesium.Cartesian3.fromDegrees(0, 0.001, -10