Skip to content

Commit c5b302a

Browse files
committed
feat(shared): ✨ added custom material VcLineTrail
1 parent c104d9c commit c5b302a

File tree

13 files changed

+145
-18
lines changed

13 files changed

+145
-18
lines changed

CHANGELOG.en-US.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@ _2024-02-29_
88

99
- Added formatting functions to the `vc-measurements` component for measurement results. `distanceFormatter`, `areaFormatter`, `angleFormatter`.
1010
- Adapt for compatibility with dc-sdk version 3.x.
11+
- Added custom material `VcLineTrail`.
1112

1213
#### Bug fixes
1314

1415
- Fixed the issue that parameter configuration of areaMeasurementOpts in the vc-measurements component, setting both showAngleLabel and showDistanceLabel to false, results in an error.[#518](https://github.com/zouyaoji/vue-cesium/issues/518)
1516
- Fixed the issue that Cesium.VERSION being undefined, causing an error.
1617

17-
1818
### 3.2.5
1919

2020
_2023-12-27_
2121

2222
#### Bug fixes
2323

24-
- The browser crash issue occurs when using `ref` or `reactive` to wrap the `hierarchy` prop in the `vc-graphics-polygon` component.
25-
- In native Cesium, there is an error when loading SuperMap iServer map services using `vc-provider-imagery-supermap`.
26-
- Fixed the issue of consecutive mouse clicks not taking effect in the `vc-navigation-sm` component. **[Removed the functionality of double-clicking the outer dial to realign with the north direction]**
24+
- The browser crash issue occurs when using `ref` or `reactive` to wrap the `hierarchy` prop in the `vc-graphics-polygon` component.
25+
- In native Cesium, there is an error when loading SuperMap iServer map services using `vc-provider-imagery-supermap`.
26+
- Fixed the issue of consecutive mouse clicks not taking effect in the `vc-navigation-sm` component. **[Removed the functionality of double-clicking the outer dial to realign with the north direction]**
2727

2828
### 3.2.4
2929

3030
_2023-10-23_
3131

3232
#### Bug fixes
3333

34-
- The npm release for version 3.2.3 has an error.
34+
- The npm release for version 3.2.3 has an error.
3535

3636
### 3.2.3
3737

CHANGELOG.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _2024-02-29_
88

99
- `vc-measurements` 组件为量算结果添加格式化函数。`distanceFormatter``areaFormatter``angleFormatter`
1010
- 适配 `dc-sdk` 3.x 版本。
11+
- 添加 `VcLineTrail` 自定义材质。
1112

1213
#### Bug 修复
1314

packages/shared/extends/materials/MaterialExtend.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* @Date: 2023-08-18 00:56:13
44
* @Description: Do not edit
55
* @LastEditors: zouyaoji 370681295@qq.com
6-
* @LastEditTime: 2023-12-06 15:54:24
6+
* @LastEditTime: 2024-02-29 00:41:04
77
* @FilePath: \vue-cesium\packages\shared\extends\materials\MaterialExtend.ts
88
*/
99

10-
import { VcCircleWaveMaterial, VcLineFlowMaterial } from '@vue-cesium/shared/shaders/materials'
10+
import { VcCircleWaveMaterial, VcLineFlowMaterial, VcLineTrailMaterial } from '@vue-cesium/shared/shaders/materials'
1111

1212
let isExtended = false
1313
export default class MaterialExtend {
@@ -19,12 +19,14 @@ export default class MaterialExtend {
1919
const { Material, Color, Cartesian2 } = Cesium
2020
const webgl2 = viewer.scene.context?.webgl2
2121

22-
let shaderSourceTextVcLine = VcLineFlowMaterial
22+
let shaderSourceTextVcLineFlow = VcLineFlowMaterial
2323
let shaderSourceTextVcCircle = VcCircleWaveMaterial
24+
let shaderSourceTextVcLineTrail = VcLineTrailMaterial
2425

2526
if (!webgl2) {
26-
shaderSourceTextVcLine = shaderSourceTextVcLine.replace(/texture\(/g, 'texture2D(')
27+
shaderSourceTextVcLineFlow = shaderSourceTextVcLineFlow.replace(/texture\(/g, 'texture2D(')
2728
shaderSourceTextVcCircle = shaderSourceTextVcCircle.replace(/texture\(/g, 'texture2D(')
29+
shaderSourceTextVcLineTrail = shaderSourceTextVcLineTrail.replace(/texture\(/g, 'texture2D(')
2830
}
2931

3032
/**
@@ -71,7 +73,30 @@ export default class MaterialExtend {
7173
color2: new Color(1, 1, 1),
7274
globalAlpha: 1
7375
},
74-
source: shaderSourceTextVcLine
76+
source: shaderSourceTextVcLineFlow
77+
},
78+
translucent() {
79+
return true
80+
}
81+
})
82+
83+
/**
84+
* Gets the name of the VcLineTrail material.
85+
* @type {string}
86+
* @readonly
87+
*/
88+
Material['VcLineTrail'] = 'VcLineTrail'
89+
Cesium.Material['_materialCache'].addMaterial(Material['VcLineTrail'], {
90+
fabric: {
91+
type: Material['VcLineTrail'],
92+
uniforms: {
93+
image: Material.DefaultImageId,
94+
color: new Color(1, 0, 0, 1),
95+
repeat: new Cartesian2(1, 1),
96+
time: 0,
97+
axisY: false
98+
},
99+
source: shaderSourceTextVcLineTrail
75100
},
76101
translucent() {
77102
return true
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* @Author: zouyaoji@https://github.com/zouyaoji
3+
* @Date: 2023-08-17 23:55:24
4+
* @Description: Do not edit
5+
* @LastEditors: zouyaoji 370681295@qq.com
6+
* @LastEditTime: 2024-02-29 00:43:57
7+
* @FilePath: \vue-cesium\packages\shared\extends\materials\VcLineTrailMaterialProperty.ts
8+
*/
9+
import { getCesiumColor, getCesiumValue } from '@vue-cesium/utils/util'
10+
import VcBaseMaterialProperty from './VcBaseMaterialProperty'
11+
12+
export default class VcLineTrailMaterialProperty extends VcBaseMaterialProperty {
13+
image: string
14+
color: Cesium.Color
15+
axisY: boolean
16+
time: number
17+
duration: number
18+
repeat: Cesium.Cartesian2
19+
loop: boolean
20+
lastTime: number
21+
_time: number
22+
23+
constructor(options: any = {}) {
24+
super(options)
25+
const { Color, Cartesian2, defined } = Cesium
26+
this.image = options.image ?? options.url
27+
this.color = options.color ?? new Color(1, 0, 0, 1)
28+
this.axisY = options.axisY ?? false
29+
this.time = options.time ?? 0
30+
this.repeat = options.repeat ?? new Cartesian2(1, 1)
31+
this.loop = options.loop ?? true
32+
this.duration = options.duration ?? 3
33+
this._time = (new Date()).getTime()
34+
}
35+
36+
getType(value) {
37+
return 'VcLineTrail'
38+
}
39+
40+
getValue(time: Cesium.JulianDate, result?): VcLineTrailMaterialProperty {
41+
const { Color, Cartesian2, defined } = Cesium
42+
!defined(result) && (result = {})
43+
44+
if (this.lastTime >= 0.99 && !this.loop) {
45+
return result
46+
}
47+
48+
result.image = this.image
49+
result.color = getCesiumColor(this.color, new Color(1, 1, 1, 0), time)
50+
result.repeat = getCesiumValue(this.repeat, Cartesian2, time)
51+
result.axisY = this.axisY
52+
result.time = (((new Date()).getTime() - this._time) % this.duration) / this.duration
53+
this.lastTime = result.time
54+
return result as VcLineTrailMaterialProperty
55+
}
56+
57+
equals(other: VcLineTrailMaterialProperty) {
58+
const reData =
59+
this === other ||
60+
(other instanceof VcLineTrailMaterialProperty &&
61+
Cesium.Property['equals'](this.color, other.color) &&
62+
Cesium.Property['equals'](this.repeat, other.repeat) &&
63+
this.image === other.image &&
64+
this.axisY === other.axisY &&
65+
this.duration === other.duration)
66+
return reData
67+
}
68+
}

packages/shared/extends/materials/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
import MaterialExtend from './MaterialExtend'
1010
import VcCircleWaveMaterialProperty from './VcCircleWaveMaterialProperty'
1111
import VcLineFlowMaterialProperty from './VcLineFlowMaterialProperty'
12+
import VcLineTrailMaterialProperty from './VcLineTrailMaterialProperty'
1213

13-
export { MaterialExtend, VcCircleWaveMaterialProperty, VcLineFlowMaterialProperty }
14+
export { MaterialExtend, VcCircleWaveMaterialProperty, VcLineFlowMaterialProperty, VcLineTrailMaterialProperty }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* @Author: zouyaoji@https://github.com/zouyaoji
3+
* @Date: 2023-08-17 00:10:56
4+
* @Description: Do not edit
5+
* @LastEditors: zouyaoji 370681295@qq.com
6+
* @LastEditTime: 2024-02-29 00:35:07
7+
* @FilePath: \vue-cesium\packages\shared\shaders\materials\VcLineTrailMaterial.ts
8+
*/
9+
export default `
10+
czm_material czm_getMaterial(czm_materialInput materialInput)
11+
{
12+
czm_material material = czm_getDefaultMaterial(materialInput);
13+
vec2 st = materialInput.st;
14+
vec4 colorImage = texture(image, vec2(fract(st.s - time), st.t));
15+
material.alpha = colorImage.a * color.a;
16+
material.diffuse = (colorImage.rgb+color.rgb)/2.0;
17+
return material;
18+
}
19+
`
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import VcCircleWaveMaterial from './VcCircleWaveMaterial'
22
import VcLineFlowMaterial from './VcLineFlowMaterial'
3+
import VcLineTrailMaterial from './VcLineTrailMaterial'
34

4-
export { VcCircleWaveMaterial, VcLineFlowMaterial }
5+
export { VcCircleWaveMaterial, VcLineFlowMaterial, VcLineTrailMaterial }

packages/utils/cesium-helpers.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import type {
5050
} from './types'
5151
import { compare, CompareOperator } from 'compare-versions'
5252
import { hasOwn, isFunction, isArray, isString, isPlainObject, isEmptyObj, getObjClassName, isUndefined } from './util'
53-
import { VcCircleWaveMaterialProperty, VcLineFlowMaterialProperty } from '@vue-cesium/shared/extends/materials'
53+
import { VcCircleWaveMaterialProperty, VcLineFlowMaterialProperty, VcLineTrailMaterialProperty } from '@vue-cesium/shared/extends/materials'
5454
import { cloneDeep } from 'lodash'
5555

5656
/**
@@ -446,7 +446,8 @@ export function makeMaterialProperty(val: VcMaterialProperty, isConstant = false
446446
val instanceof PolylineOutlineMaterialProperty ||
447447
val instanceof StripeMaterialProperty ||
448448
val instanceof VcCircleWaveMaterialProperty ||
449-
val instanceof VcLineFlowMaterialProperty
449+
val instanceof VcLineFlowMaterialProperty ||
450+
val instanceof VcLineTrailMaterialProperty
450451
// getObjClassName(val as any).indexOf('MaterialProperty') !== -1
451452
) {
452453
return val as CesiumMaterialProperty
@@ -543,6 +544,16 @@ export function makeMaterialProperty(val: VcMaterialProperty, isConstant = false
543544
time: defaultValue(value.fabric.uniforms.time, -1)
544545
})
545546
}
547+
case 'VcLineTrail': {
548+
return new VcLineTrailMaterialProperty({
549+
image: defaultValue(value.fabric.uniforms.image, Material.DefaultImageId),
550+
color: makeColor(defaultValue(value.fabric.uniforms.color, new Color(1, 0, 0, 1))),
551+
repeat: makeCartesian2(defaultValue(value.fabric.uniforms.repeat, new Cartesian2(1, 1))),
552+
axisY: defaultValue(value.fabric.uniforms.axisY, false),
553+
duration: defaultValue(value.fabric.uniforms.duration, 3000),
554+
loop: defaultValue(value.fabric.uniforms.loop, true)
555+
})
556+
}
546557
}
547558
}
548559

packages/utils/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ interface MaterialOption {
8787
mixt?: boolean
8888
speed?: number
8989
time?: number
90+
loop?: boolean
9091
}
9192
}
9293
strict?: boolean

website/docs/zh-CN/analyses/vc-measurements.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ ctrl + 右键取消绘制。
160160
[108.95499, 34.21761]
161161
]
162162
],
163-
showAngleLabel: false,
164-
showDistanceLabel: false,
163+
// showAngleLabel: false,
164+
// showDistanceLabel: false,
165165
areaFormatter: (value, defaultUnits, defaultLocale, defaultDecimals) => {
166166
return `${(value * 0.0015).toFixed(4)}`
167167
}

website/docs/zh-CN/graphics/vc-graphics-wall.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
:positions="[[-115,50],[-112,50],[-107.5,50],[-105,50],[-102.5,50],[-100,50],[-97.5,50],[-95,50],[-92.5,50],[-90,50]]"
3939
:material="{
4040
fabric: {
41-
type: 'VcLineFlow',
42-
uniforms: { image: 'https://zouyaoji.top/vue-cesium/images/textures/arrow.png', color: 'yellow', repeat: { x: 30, y: 1 }, speed: 10 }
41+
type: 'VcLineTrail',
42+
uniforms: { image: 'https://zouyaoji.top/vue-cesium/images/textures/colors.png', }
4343
}
4444
}"
4545
outlineColor="black"
652 Bytes
Loading
332 Bytes
Loading

0 commit comments

Comments
 (0)