ソースを参照

add Diffuse Wall Primitive

tags/2.2.3
Caven Chen 4年前
コミット
2169f6d412

+ 8
- 0
modules/material/shader/wall/WallDiffuseMaterial.glsl ファイルの表示

@@ -0,0 +1,8 @@
uniform vec4 color;
czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);
vec2 st = materialInput.st;
material.diffuse = color.rgb * 2.0;
material.alpha = color.a * (1.0-fract(st.t)) * 0.8;
return material;
}

+ 19
- 0
modules/material/type/wall.js ファイルの表示

@@ -5,10 +5,29 @@

import { Cesium } from '@dc-modules/namespace'

const WallDiffuseMaterial = require('../shader/wall/WallDiffuseMaterial.glsl')
const WallImageTrailMaterial = require('../shader/wall/WallImageTrailMaterial.glsl')
const WallLineTrailMaterial = require('../shader/wall/WallLineTrailMaterial.glsl')
const WallTrailMaterial = require('../shader/wall/WallTrailMaterial.glsl')

/**
* WallDiffuse
* @type {string}
*/
Cesium.Material.WallDiffuseType = 'WallDiffuse'
Cesium.Material._materialCache.addMaterial(Cesium.Material.WallDiffuseType, {
fabric: {
type: Cesium.Material.WallDiffuseType,
uniforms: {
color: new Cesium.Color(1.0, 0.0, 0.0, 0.7)
},
source: WallDiffuseMaterial
},
translucent: function(material) {
return true
}
})

/**
* WallImageTrail
* @type {string}

+ 1
- 0
modules/overlay/index.js ファイルの表示

@@ -42,6 +42,7 @@ export { default as TailedAttackArrow } from './plot/TailedAttackArrow'
* primitive
*/
export { default as BillboardPrimitive } from './primitive/BillboardPrimitive.js'
export { default as DiffuseWallPrimitive } from './primitive/DiffuseWallPrimitive.js'
export { default as ElecEllipsoidPrimitive } from './primitive/ElecEllipsoidPrimitive'
export { default as FlowLinePrimitive } from './primitive/FlowLinePrimitive'
export { default as LabelPrimitive } from './primitive/LabelPrimitive'

+ 216
- 0
modules/overlay/primitive/DiffuseWallPrimitive.js ファイルの表示

@@ -0,0 +1,216 @@
/**
* @Author: Caven
* @Date: 2021-06-04 20:38:39
*/

import { Cesium } from '@dc-modules/namespace'
import State from '@dc-modules/state/State'
import Parse from '@dc-modules/parse/Parse'
import { Util } from '@dc-modules/utils'
import { Transform } from '@dc-modules/transform'
import Overlay from '../Overlay'

const DEF_STYLE = {
minRadius: 10,
minHeight: 30,
color: Cesium.Color.RED
}

class DiffuseWallPrimitive extends Overlay {
constructor(center, radius, height, slices, speed) {
super()
this._center = Parse.parsePosition(center)
this._delegate = undefined
this._height = height
this._radius = radius
this._slices = slices || 128
this._speed = speed || 10
this._currentHeight = height || 0
this._currentRadius = 10
this._style = { ...DEF_STYLE }
this.type = Overlay.getOverlayType('diffuse_wall_primitive')
this._state = State.INITIALIZED
}

set center(position) {
this._center = Parse.parsePosition(position)
return this
}

get center() {
return this._center
}

set radius(radius) {
this._radius = radius
return this
}

get radius() {
return this._radius
}

set height(height) {
this._height = height
return this
}

get height() {
return this._height
}

set slices(slices) {
this._slices = slices
return this
}

get slices() {
return this._slices
}

set speed(speed) {
this._speed = speed
return this
}

get speed() {
return this._speed
}

/**
*
* @returns {*}
* @private
*/
_getPositions() {
let pnts = []
let modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(
Transform.transformWGS84ToCartesian(this._center)
)
for (let i = 0; i < this._slices; i++) {
let angle = (i / this._slices) * Cesium.Math.TWO_PI
let x = Math.cos(angle)
let y = Math.sin(angle)
let point = new Cesium.Cartesian3(
x * this._currentRadius,
y * this._currentRadius,
0.0
)
pnts.push(
Cesium.Matrix4.multiplyByPoint(
modelMatrix,
point,
new Cesium.Cartesian3()
)
)
}
pnts.push(pnts[0])
return pnts
}

/**
*
* @param length
* @param hegiht
* @returns {*[]}
* @private
*/
_getHeights(length, hegiht) {
let heights = []
for (let i = 0; i < length; i++) {
heights.push(hegiht)
}
return heights
}

/**
*
* @param layer
* @private
*/
_onAdd(layer) {
if (!layer) {
return
}
this._layer = layer
if (this._layer?.delegate?.add) {
this._layer.delegate.add(this)
}
this._addedHook && this._addedHook()
this._state = State.ADDED
}

/**
*
* @private
*/
_onRemove() {
if (!this._layer) {
return
}
if (this._layer?.delegate?.remove) {
this._layer.delegate.remove(this)
}
this._state = State.REMOVED
}

/**
*
* @param frameState
* @returns {boolean}
*/
update(frameState) {
this._delegate = this._delegate && this._delegate.destroy()
this._currentRadius += this._radius / this._speed / 20
this._currentHeight -= this._height / this._speed / 20
if (
this._currentRadius > this._radius ||
this._currentHeight < this._style.minHeight
) {
this._currentRadius = this._style.minRadius
this._currentHeight = this._height
}
if (!this._slices || this._slices < 3) {
return false
}
let positions = this._getPositions()
if (!positions || !positions.length) {
return false
}
let geometry = new Cesium.WallGeometry({
positions: positions,
minimumHeights: this._getHeights(positions.length, 0),
maximumHeights: this._getHeights(positions.length, this._currentHeight)
})

this._delegate = new Cesium.Primitive({
geometryInstances: new Cesium.GeometryInstance({
geometry
}),
appearance: new Cesium.MaterialAppearance({
material: Cesium.Material.fromType('WallDiffuse', {
color: this._style?.color
}),
flat: true
}),
asynchronous: false
})
this._delegate.update(frameState)
}
/**
*
* @param style
* @returns {DiffuseWallPrimitive}
*/
setStyle(style) {
if (!style || Object.keys(style).length === 0) {
return this
}
Util.merge(this._style, style)
return this
}
}

Overlay.registerType('diffuse_wall_primitive')

export default DiffuseWallPrimitive

+ 2
- 0
packages/core/src/components.js ファイルの表示

@@ -75,6 +75,7 @@ import {
GatheringPlace,
TailedAttackArrow,
BillboardPrimitive,
DiffuseWallPrimitive,
ElecEllipsoidPrimitive,
FlowLinePrimitive,
LabelPrimitive,
@@ -266,6 +267,7 @@ const components = {
GatheringPlace,
TailedAttackArrow,
BillboardPrimitive,
DiffuseWallPrimitive,
ElecEllipsoidPrimitive,
FlowLinePrimitive,
LabelPrimitive,

読み込み中…
キャンセル
保存