cesium流動材質(zhì)應(yīng)用特效


采用vue+cesium實現(xiàn)

引入js部分

import?Cesium?from?"cesium/Cesium";

export?class?PolylineTrailMaterialProperty?{

????constructor(options)?{

????????options?=?Cesium.defaultValue(options,?Cesium.defaultValue.EMPTY_OBJECT);

????????this._definitionChanged?=?new?Cesium.Event();

????????this._color?=?undefined;

????????this._colorSubscription?=?undefined;

????????this.color?=?options.color;

????????this.duration?=?options.duration;

????????this.trailImage?=?options.trailImage;

????????this._time?=?performance.now();

????}

}

Cesium.defineProperties(PolylineTrailMaterialProperty.prototype,?{

????isConstant:?{

????????get:?function()?{

????????????return?false;

????????}

????},

????definitionChanged:?{

????????get:?function()?{

????????????return?this._definitionChanged;

????????}

????},

????color:?Cesium.createPropertyDescriptor('color')

});

PolylineTrailMaterialProperty.prototype.getType?=?function(time)?{

????return?'PolylineTrail';

}

PolylineTrailMaterialProperty.prototype.getValue?=?function(time,?result)?{

????if?(!Cesium.defined(result))?{

????????result?=?{};

????}

????result.color?=?Cesium.Property.getValueOrClonedDefault(this._color,?time,?Cesium.Color.WHITE,?result.color);

????//result.image?=?Cesium.Material.PolylineTrailImage;

????result.image?=?this.trailImage;

????result.time?=?((performance.now()?-?this._time)?%?this.duration)?/?this.duration;

????return?result;

}

PolylineTrailMaterialProperty.prototype.equals?=?function(other)?{

????return?this?===?other?||

????????(other?instanceof?PolylineTrailMaterialProperty?&&

????????????Cesium.Property.equals(this._color,?other._color))

}

Cesium.Material.PolylineTrailType?=?'PolylineTrail';

Cesium.Material.PolylineTrailImage?=?"images/colors.png";

Cesium.Material.PolylineTrailSource?=?"czm_material?czm_getMaterial(czm_materialInput?materialInput)\n"?+

??????????????????????????????????????????????????????"{\n"?+?

????????????????????????????????????????????????????????"czm_material?material?=?czm_getDefaultMaterial(materialInput);\n"?+

??????????????????????????????????????????????????????????"vec2?st?=?materialInput.st;\n"?+

??????????????????????????????????????????????????????????"vec4?colorImage?=?texture2D(image,?vec2(fract(st.s?-?time),?st.t));\n"?+

??????????????????????????????????????????????????????????"material.alpha?=?colorImage.a?*?color.a;\n"+

??????????????????????????????????????????????????????????"material.diffuse?=?(colorImage.rgb+color.rgb)/2.0;\n"+

??????????????????????????????????????????????????????????"return?material;\n"?+

??????????????????????????????????????????????????????"}";

Cesium.Material._materialCache.addMaterial(Cesium.Material.PolylineTrailType,?{

????fabric:?{

????????type:?Cesium.Material.PolylineTrailType,

????????uniforms:?{

????????????color:?new?Cesium.Color(1.0,?0.0,?0.0,?0.5),

????????????image:?Cesium.Material.PolylineTrailImage,

????????????time:?0

????????},

????????source:?Cesium.Material.PolylineTrailSource

????},

????translucent:?function(material)?{

????????return?true;

????}

});

Cesium.PolylineTrailMaterialProperty?=?PolylineTrailMaterialProperty;

vue應(yīng)用部分

<template>

??<div?class="fullSize"?id="cesiumContainer"></div>

</template>

<script>

import?"cesium/Widgets/widgets.css";

import?Cesium?from?"cesium/Cesium";

import?PolylineTrailMaterialProperty?from?"@/unit/PolylineTrailMaterialProperty";

export?default?{

??name:?"CesiumDynamicLine1",

??//

??data()?{

????return?{

??????viewer:?null

????};

??},

??mounted()?{

????let?viewerOption?=?{

??????geocoder:?false,?//?地理位置查詢定位控件

??????homeButton:?false,?//?默認相機位置控件

??????timeline:?false,?//?時間滾動條控件

??????navigationHelpButton:?false,?//?默認的相機控制提示控件

??????fullscreenButton:?false,?//?全屏控件

??????scene3DOnly:?true,?//?每個幾何實例僅以3D渲染以節(jié)省GPU內(nèi)存

??????baseLayerPicker:?false,?//?底圖切換控件

??????shouldAnimate:?true,?//是否開始動畫

??????//?useDefaultRenderLoop?:?true,//如果需要控制渲染循環(huán)氮帐,則設(shè)為true

??????selectionIndicator:?true,?//是否顯示選取指示器組件

??????//?targetFrameRate:60,

??????vrButton:?true,

??????showRenderLoopErrors:?true,

??????requestAnimationFrame:?true,

??????//?showRenderLoopErrors?:?false,

??????animation:?false?//?控制場景動畫的播放速度控件

????};

????this.viewer?=?new?Cesium.Viewer(this.$el,?viewerOption);

????this.create();

??},

??methods:?{

????create()?{

??????//創(chuàng)建射線

??????var?data?=?{

????????startPoint:?{

??????????id:?0,

??????????lon:?114.302312702,

??????????lat:?30.598026044,

??????????size:?20,

??????????height:?0,

??????????url:"3d/leida/leida.gltf",

??????????color:?Cesium.Color.PURPLE

????????},

????????center:?

??????????{

????????????id:?1,

????????????lon:?115.028495718,

????????????lat:?30.200814617,

????????????height:?100000,

????????????color:?Cesium.Color.YELLOW,

????????????url:"3d/weixing_1.gltf",

????????????size:?15

??????????},

????????endPoint:?{

??????????id:?0,

??????????lon:?116.302312702,

??????????lat:?30.598026044,

??????????size:?20,

??????????height:?0,

??????????url:"3d/junjian/junjian.gltf",

??????????color:?Cesium.Color.PURPLE

????????},

????????options:?{

??????????name:?"",

??????????polyline:?{

????????????width:?2,

????????????trailImage:?"images/color.png",??

????????????trailImage1:?"images/green.png",??

????????????material:?[Cesium.Color.GREEN,?3000]

??????????}

????????}

??????};

??????this.createFlyLines(data);

????},

????createFlyLines(data)?{

??????var?self?=?this;

????????/*****?創(chuàng)建發(fā)送目標*****/

??????const?hpRoll?=?new?Cesium.HeadingPitchRoll(Cesium.Math.toRadians(-90),?0,?0);

??????const?startPoint?=?Cesium.Cartesian3.fromDegrees(

????????????????data.startPoint.lon,

????????????????data.startPoint.lat,

????????????????data.startPoint.height

????????);

??????const?centerPoint?=?Cesium.Cartesian3.fromDegrees(

????????????????data.center.lon,

????????????????data.center.lat,

????????????????data.center.height

????????);

??????const?endPoint?=?Cesium.Cartesian3.fromDegrees(

????????data.endPoint.lon,

????????data.endPoint.lat,

????????data.endPoint.height

????????);

??????this.viewer.entities.add({

????????position:?startPoint,

????????orientation:?this.Cesium.Transforms.headingPitchRollQuaternion(startPoint,?hpRoll),

????????model:{

??????????uri:?data.startPoint.url,

??????????minimumPixelSize:?32

????????}

??????});?

??????//大批量操作時萧福,臨時禁用事件可以提高性能

??????this.viewer.entities.suspendEvents();?//散點


????????//?創(chuàng)建材質(zhì)

????????let?material?=?new?Cesium.PolylineTrailMaterialProperty({?//創(chuàng)建材質(zhì)

??????????color:?Cesium.Color.GREEN.withAlpha(0.5),

??????????duration:?3000,

??????????trailImage:?data.options.polyline.trailImage1

????????});

????????let?material1?=?new?Cesium.PolylineTrailMaterialProperty({?//創(chuàng)建材質(zhì)1

??????????color:?Cesium.Color.YELLOW.withAlpha(0.5),

??????????duration:?3000,

??????????trailImage:?data.options.polyline.trailImage

????????});

????????//?創(chuàng)建中轉(zhuǎn)目標

????????this.viewer.entities.add({

??????????position:?centerPoint,

??????????orientation:?this.Cesium.Transforms.headingPitchRollQuaternion(centerPoint,?hpRoll),

??????????model:?{

??????????uri:?data.center.url,

??????????minimumPixelSize:?128

????????}

????????});

????????//?創(chuàng)建接收目標

????????this.viewer.entities.add({

??????????position:??Cesium.Cartesian3.fromDegrees(

????????????????data.endPoint.lon,

????????????????data.endPoint.lat,

????????????????data.endPoint.height

??????????),

??????????orientation:?this.Cesium.Transforms.headingPitchRollQuaternion(endPoint,?hpRoll),

??????????model:?{

??????????uri:?data.endPoint.url,

??????????minimumPixelSize:?128

????????}

????????});

????????//?創(chuàng)建第一條信號線

????????this.viewer.entities.add({

??????????polyline:?{

????????????positions:?self.generateCurve(startPoint,?centerPoint),

????????????width:?2,

????????????material:?material

??????????}

????????});

????????this.viewer.entities.add({

??????????polyline:?{

????????????positions:?self.generateCurve(centerPoint,?endPoint),

????????????width:?2,

????????????material:?material1

??????????}

????????});

??????this.viewer.entities.resumeEvents();

??????//鏡頭順時針旋轉(zhuǎn)九十度蝶棋,即東向

??????var?heading?=?Cesium.Math.toRadians(0);

??????//鏡頭傾斜30度俯視

??????var?pitch?=?Cesium.Math.toRadians(-0);

??????this.viewer.zoomTo(

????????this.viewer.entities,

????????new?Cesium.HeadingPitchRange(heading,?pitch,490000)

??????);

????}?

???/**

????*?生成流動曲線

????*?@param?startPoint?起點

????*?@param?endPoint?終點

????*?@returns?{Array}

????*/,

????generateCurve(startPoint,?endPoint)?{

??????let?addPointCartesian?=?new?Cesium.Cartesian3();

??????Cesium.Cartesian3.add(startPoint,?endPoint,?addPointCartesian);

??????let?midPointCartesian?=?new?Cesium.Cartesian3();

??????Cesium.Cartesian3.divideByScalar(addPointCartesian,?2,?midPointCartesian);

??????let?midPointCartographic?=?Cesium.Cartographic.fromCartesian(

????????midPointCartesian

??????);

??????midPointCartographic.height?=

????????Cesium.Cartesian3.distance(startPoint,?endPoint)?/?2.5;

??????let?midPoint?=?new?Cesium.Cartesian3();

??????Cesium.Ellipsoid.WGS84.cartographicToCartesian(

????????midPointCartographic,

????????midPoint

??????);

??????let?spline?=?new?Cesium.CatmullRomSpline({

????????times:?[0.0,?0.5,?1.0],

????????points:?[startPoint,?midPoint,?endPoint]

??????});

??????let?curvePoints?=?[];

??????for?(let?i?=?0,?len?=?200;?i?<?len;?i++)?{

????????curvePoints.push(spline.evaluate(i?/?len));

??????}

//???????console.log(curvePoints);

??????return?curvePoints;

????}

??}

};

</script>

<style?lang="scss"?>

</style>

總結(jié):此特效為三者傳遞信號烹植,以流動材質(zhì)作為傳遞信號源蹲坷。注:材質(zhì)圖片采用漸變色,盡量與材質(zhì)本事顏色色差凸顯出來沙峻,否則效果不明顯箩祥。在此也非常感謝Cesium流動線紋理的作者-happy_port。給我在他效果的基本上實現(xiàn)此效果的靈感驯鳖。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末闲询,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子浅辙,更是在濱河造成了極大的恐慌莲兢,老刑警劉巖有鹿,帶你破解...
    沈念sama閱讀 206,968評論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件佑笋,死亡現(xiàn)場離奇詭異寺滚,居然都是意外死亡,警方通過查閱死者的電腦和手機氨淌,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,601評論 2 382
  • 文/潘曉璐 我一進店門泊愧,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人盛正,你說我怎么就攤上這事删咱。” “怎么了豪筝?”我有些...
    開封第一講書人閱讀 153,220評論 0 344
  • 文/不壞的土叔 我叫張陵痰滋,是天一觀的道長摘能。 經(jīng)常有香客問我,道長敲街,這世上最難降的妖魔是什么团搞? 我笑而不...
    開封第一講書人閱讀 55,416評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮多艇,結(jié)果婚禮上逻恐,老公的妹妹穿的比我還像新娘。我一直安慰自己峻黍,他們只是感情好复隆,可當我...
    茶點故事閱讀 64,425評論 5 374
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著姆涩,像睡著了一般挽拂。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上骨饿,一...
    開封第一講書人閱讀 49,144評論 1 285
  • 那天亏栈,我揣著相機與錄音,去河邊找鬼样刷。 笑死仑扑,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的置鼻。 我是一名探鬼主播,決...
    沈念sama閱讀 38,432評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼蜓竹,長吁一口氣:“原來是場噩夢啊……” “哼箕母!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起俱济,我...
    開封第一講書人閱讀 37,088評論 0 261
  • 序言:老撾萬榮一對情侶失蹤嘶是,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后蛛碌,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體聂喇,經(jīng)...
    沈念sama閱讀 43,586評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,028評論 2 325
  • 正文 我和宋清朗相戀三年蔚携,在試婚紗的時候發(fā)現(xiàn)自己被綠了希太。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 38,137評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡酝蜒,死狀恐怖誊辉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情亡脑,我是刑警寧澤堕澄,帶...
    沈念sama閱讀 33,783評論 4 324
  • 正文 年R本政府宣布邀跃,位于F島的核電站,受9級特大地震影響蛙紫,放射性物質(zhì)發(fā)生泄漏拍屑。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,343評論 3 307
  • 文/蒙蒙 一坑傅、第九天 我趴在偏房一處隱蔽的房頂上張望丽涩。 院中可真熱鬧,春花似錦裁蚁、人聲如沸矢渊。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,333評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽矮男。三九已至,卻和暖如春室谚,著一層夾襖步出監(jiān)牢的瞬間毡鉴,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,559評論 1 262
  • 我被黑心中介騙來泰國打工秒赤, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留猪瞬,地道東北人。 一個月前我還...
    沈念sama閱讀 45,595評論 2 355
  • 正文 我出身青樓入篮,卻偏偏與公主長得像陈瘦,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子潮售,可洞房花燭夜當晚...
    茶點故事閱讀 42,901評論 2 345