-
-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shared): ✨ added custom material
VcLineTrail
- Loading branch information
Showing
13 changed files
with
145 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,11 @@ | |
* @Date: 2023-08-18 00:56:13 | ||
* @Description: Do not edit | ||
* @LastEditors: zouyaoji [email protected] | ||
* @LastEditTime: 2023-12-06 15:54:24 | ||
* @LastEditTime: 2024-02-29 00:41:04 | ||
* @FilePath: \vue-cesium\packages\shared\extends\materials\MaterialExtend.ts | ||
*/ | ||
|
||
import { VcCircleWaveMaterial, VcLineFlowMaterial } from '@vue-cesium/shared/shaders/materials' | ||
import { VcCircleWaveMaterial, VcLineFlowMaterial, VcLineTrailMaterial } from '@vue-cesium/shared/shaders/materials' | ||
|
||
let isExtended = false | ||
export default class MaterialExtend { | ||
|
@@ -19,12 +19,14 @@ export default class MaterialExtend { | |
const { Material, Color, Cartesian2 } = Cesium | ||
const webgl2 = viewer.scene.context?.webgl2 | ||
|
||
let shaderSourceTextVcLine = VcLineFlowMaterial | ||
let shaderSourceTextVcLineFlow = VcLineFlowMaterial | ||
let shaderSourceTextVcCircle = VcCircleWaveMaterial | ||
let shaderSourceTextVcLineTrail = VcLineTrailMaterial | ||
|
||
if (!webgl2) { | ||
shaderSourceTextVcLine = shaderSourceTextVcLine.replace(/texture\(/g, 'texture2D(') | ||
shaderSourceTextVcLineFlow = shaderSourceTextVcLineFlow.replace(/texture\(/g, 'texture2D(') | ||
shaderSourceTextVcCircle = shaderSourceTextVcCircle.replace(/texture\(/g, 'texture2D(') | ||
shaderSourceTextVcLineTrail = shaderSourceTextVcLineTrail.replace(/texture\(/g, 'texture2D(') | ||
} | ||
|
||
/** | ||
|
@@ -71,7 +73,30 @@ export default class MaterialExtend { | |
color2: new Color(1, 1, 1), | ||
globalAlpha: 1 | ||
}, | ||
source: shaderSourceTextVcLine | ||
source: shaderSourceTextVcLineFlow | ||
}, | ||
translucent() { | ||
return true | ||
} | ||
}) | ||
|
||
/** | ||
* Gets the name of the VcLineTrail material. | ||
* @type {string} | ||
* @readonly | ||
*/ | ||
Material['VcLineTrail'] = 'VcLineTrail' | ||
Cesium.Material['_materialCache'].addMaterial(Material['VcLineTrail'], { | ||
fabric: { | ||
type: Material['VcLineTrail'], | ||
uniforms: { | ||
image: Material.DefaultImageId, | ||
color: new Color(1, 0, 0, 1), | ||
repeat: new Cartesian2(1, 1), | ||
time: 0, | ||
axisY: false | ||
}, | ||
source: shaderSourceTextVcLineTrail | ||
}, | ||
translucent() { | ||
return true | ||
|
68 changes: 68 additions & 0 deletions
68
packages/shared/extends/materials/VcLineTrailMaterialProperty.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* @Author: zouyaoji@https://github.com/zouyaoji | ||
* @Date: 2023-08-17 23:55:24 | ||
* @Description: Do not edit | ||
* @LastEditors: zouyaoji [email protected] | ||
* @LastEditTime: 2024-02-29 00:43:57 | ||
* @FilePath: \vue-cesium\packages\shared\extends\materials\VcLineTrailMaterialProperty.ts | ||
*/ | ||
import { getCesiumColor, getCesiumValue } from '@vue-cesium/utils/util' | ||
import VcBaseMaterialProperty from './VcBaseMaterialProperty' | ||
|
||
export default class VcLineTrailMaterialProperty extends VcBaseMaterialProperty { | ||
image: string | ||
color: Cesium.Color | ||
axisY: boolean | ||
time: number | ||
duration: number | ||
repeat: Cesium.Cartesian2 | ||
loop: boolean | ||
lastTime: number | ||
_time: number | ||
|
||
constructor(options: any = {}) { | ||
super(options) | ||
const { Color, Cartesian2, defined } = Cesium | ||
this.image = options.image ?? options.url | ||
this.color = options.color ?? new Color(1, 0, 0, 1) | ||
this.axisY = options.axisY ?? false | ||
this.time = options.time ?? 0 | ||
this.repeat = options.repeat ?? new Cartesian2(1, 1) | ||
this.loop = options.loop ?? true | ||
this.duration = options.duration ?? 3 | ||
this._time = (new Date()).getTime() | ||
} | ||
|
||
getType(value) { | ||
return 'VcLineTrail' | ||
} | ||
|
||
getValue(time: Cesium.JulianDate, result?): VcLineTrailMaterialProperty { | ||
const { Color, Cartesian2, defined } = Cesium | ||
!defined(result) && (result = {}) | ||
|
||
if (this.lastTime >= 0.99 && !this.loop) { | ||
return result | ||
} | ||
|
||
result.image = this.image | ||
result.color = getCesiumColor(this.color, new Color(1, 1, 1, 0), time) | ||
result.repeat = getCesiumValue(this.repeat, Cartesian2, time) | ||
result.axisY = this.axisY | ||
result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration | ||
this.lastTime = result.time | ||
return result as VcLineTrailMaterialProperty | ||
} | ||
|
||
equals(other: VcLineTrailMaterialProperty) { | ||
const reData = | ||
this === other || | ||
(other instanceof VcLineTrailMaterialProperty && | ||
Cesium.Property['equals'](this.color, other.color) && | ||
Cesium.Property['equals'](this.repeat, other.repeat) && | ||
this.image === other.image && | ||
this.axisY === other.axisY && | ||
this.duration === other.duration) | ||
return reData | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* @Author: zouyaoji@https://github.com/zouyaoji | ||
* @Date: 2023-08-17 00:10:56 | ||
* @Description: Do not edit | ||
* @LastEditors: zouyaoji [email protected] | ||
* @LastEditTime: 2024-02-29 00:35:07 | ||
* @FilePath: \vue-cesium\packages\shared\shaders\materials\VcLineTrailMaterial.ts | ||
*/ | ||
export default ` | ||
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 - time), st.t)); | ||
material.alpha = colorImage.a * color.a; | ||
material.diffuse = (colorImage.rgb+color.rgb)/2.0; | ||
return material; | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import VcCircleWaveMaterial from './VcCircleWaveMaterial' | ||
import VcLineFlowMaterial from './VcLineFlowMaterial' | ||
import VcLineTrailMaterial from './VcLineTrailMaterial' | ||
|
||
export { VcCircleWaveMaterial, VcLineFlowMaterial } | ||
export { VcCircleWaveMaterial, VcLineFlowMaterial, VcLineTrailMaterial } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.