-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
796 additions
and
344 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
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
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,46 @@ | ||
import BufferBase, { IEncodeFeature, Position } from '../../core/BaseBuffer'; | ||
import extrudePolygon, { | ||
fillPolygon, | ||
IExtrudeGeomety, | ||
} from '../../point/shape/extrude'; | ||
import { | ||
geometryShape, | ||
ShapeType2D, | ||
ShapeType3D, | ||
} from '../../point/shape/Path'; | ||
export default class GridHeatMapBuffer extends BufferBase { | ||
private verticesOffset: number = 0; | ||
protected buildFeatures() { | ||
this.verticesOffset = 0; | ||
const layerData = this.data as IEncodeFeature[]; | ||
layerData.forEach((feature: IEncodeFeature) => { | ||
this.calculateFill(feature); | ||
}); | ||
} | ||
protected calculateFeatures() { | ||
const layerData = this.data as IEncodeFeature[]; | ||
const shape = layerData[0].shape as ShapeType3D | ShapeType2D; | ||
this.verticesCount = layerData.length; | ||
this.indexCount = 0; | ||
this.instanceGeometry = this.getGeometry(shape as | ||
| ShapeType2D | ||
| ShapeType3D); | ||
} | ||
protected calculateFill(feature: IEncodeFeature) { | ||
feature.bufferInfo = { verticesOffset: this.verticesOffset }; | ||
const coordinates = feature.coordinates as Position; | ||
this.encodeArray(feature, 1); | ||
this.attributes.positions.set([...coordinates, 1], this.verticesOffset * 3); | ||
this.verticesOffset++; | ||
} | ||
private getGeometry(shape: ShapeType2D | ShapeType3D): IExtrudeGeomety { | ||
const path = geometryShape[shape] | ||
? geometryShape[shape]() | ||
: geometryShape.circle(); | ||
// const geometry = ShapeType2D[str as ShapeType2D] | ||
// ? fillPolygon([path]) | ||
// : extrudePolygon([path]); | ||
const geometry = fillPolygon([path]); | ||
return geometry; | ||
} | ||
} |
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,114 @@ | ||
import { | ||
gl, | ||
IRendererService, | ||
IShaderModuleService, | ||
lazyInject, | ||
TYPES, | ||
} from '@l7/core'; | ||
import BaseLayer from '../core/BaseLayer'; | ||
import GridHeatMapBuffer from './buffers/GridBuffer'; | ||
import hexagon_frag from './shaders/hexagon_frag.glsl'; | ||
import hexagon_vert from './shaders/hexagon_vert.glsl'; | ||
|
||
export default class HeatMapLayer extends BaseLayer { | ||
public name: string = 'HeatMapLayer'; | ||
|
||
@lazyInject(TYPES.IShaderModuleService) | ||
private readonly shaderModule: IShaderModuleService; | ||
|
||
@lazyInject(TYPES.IRendererService) | ||
private readonly renderer: IRendererService; | ||
|
||
protected renderModels() { | ||
this.models.forEach((model) => | ||
model.draw({ | ||
uniforms: { | ||
u_ModelMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], | ||
}, | ||
}), | ||
); | ||
return this; | ||
} | ||
|
||
protected buildModels(): void { | ||
this.shaderModule.registerModule('grid', { | ||
vs: hexagon_vert, | ||
fs: hexagon_frag, | ||
}); | ||
this.models = []; | ||
const { vs, fs, uniforms } = this.shaderModule.getModule('grid'); | ||
const buffer = new GridHeatMapBuffer({ | ||
data: this.getEncodedData(), | ||
}); | ||
console.log(this.getSource()); | ||
console.log(buffer); | ||
const { | ||
createAttribute, | ||
createBuffer, | ||
createElements, | ||
createModel, | ||
} = this.renderer; | ||
|
||
this.models.push( | ||
createModel({ | ||
attributes: { | ||
a_miter: createAttribute({ | ||
buffer: createBuffer({ | ||
data: buffer.instanceGeometry.positions, | ||
type: gl.FLOAT, | ||
}), | ||
size: 3, | ||
divisor: 0, | ||
}), | ||
// a_normal: createAttribute({ | ||
// buffer: createBuffer({ | ||
// data: buffer.attributes.normals, | ||
// type: gl.FLOAT, | ||
// }), | ||
// size: 3, | ||
// }), | ||
a_color: createAttribute({ | ||
buffer: createBuffer({ | ||
data: buffer.attributes.colors, | ||
type: gl.FLOAT, | ||
}), | ||
size: 4, | ||
divisor: 1, | ||
}), | ||
// a_size: createAttribute({ | ||
// buffer: createBuffer({ | ||
// data: buffer.attributes.sizes, | ||
// type: gl.FLOAT, | ||
// }), | ||
// size: 1, | ||
// divisor: 1, | ||
// }), | ||
a_Position: createAttribute({ | ||
buffer: createBuffer({ | ||
data: buffer.attributes.positions, | ||
type: gl.FLOAT, | ||
}), | ||
size: 3, | ||
divisor: 1, | ||
}), | ||
}, | ||
uniforms: { | ||
...uniforms, | ||
u_opacity: (this.styleOption.opacity as number) || 1.0, | ||
u_radius: [ | ||
this.getSource().data.xOffset, | ||
this.getSource().data.yOffset, | ||
], | ||
}, | ||
fs, | ||
vs, | ||
count: buffer.instanceGeometry.index.length, | ||
instances: buffer.verticesCount, | ||
elements: createElements({ | ||
data: buffer.instanceGeometry.index, | ||
type: gl.UNSIGNED_INT, | ||
}), | ||
}), | ||
); | ||
} | ||
} |
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,7 @@ | ||
precision highp float; | ||
varying vec4 v_color; | ||
uniform float u_opacity: 0.1; | ||
void main() { | ||
gl_FragColor = v_color; | ||
gl_FragColor.a *= u_opacity; | ||
} |
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,18 @@ | ||
precision highp float; | ||
attribute vec3 a_Position; | ||
attribute vec3 a_miter; | ||
attribute float a_size; | ||
attribute vec4 a_color; | ||
uniform vec2 u_radius; | ||
uniform float u_coverage: 1.; | ||
uniform float u_angle: 0; | ||
uniform mat4 u_ModelMatrix; | ||
varying vec4 v_color; | ||
#pragma include "projection" | ||
void main() { | ||
v_color = a_color; | ||
mat2 rotationMatrix = mat2(cos(u_angle), sin(u_angle), -sin(u_angle), cos(u_angle)); | ||
vec2 offset =(vec2(a_miter.xy * u_radius * u_coverage * rotationMatrix)); | ||
vec4 project_pos = project_position(vec4(a_Position.xy + offset, 0, 1.0)); | ||
gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy, 0., 1.0)); | ||
} |
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,5 +1,16 @@ | ||
import BaseLayer from './core/BaseLayer'; | ||
import HeatMapLayer from './heatmap'; | ||
import Line from './line'; | ||
import PointLayer from './point'; | ||
import Point from './point/point'; | ||
import PolygonLayer from './polygon'; | ||
export { BaseLayer, PointLayer, PolygonLayer, Point }; | ||
import ImageLayer from './raster'; | ||
export { | ||
BaseLayer, | ||
PointLayer, | ||
PolygonLayer, | ||
Point, | ||
Line, | ||
ImageLayer, | ||
HeatMapLayer, | ||
}; |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
uniform float u_blur : 0.9; | ||
uniform float u_blur : 0.99; | ||
varying vec4 v_color; | ||
varying vec3 v_normal; | ||
void main() { | ||
gl_FragColor = v_color; | ||
// anti-alias | ||
// float blur = 1. - smoothstep(u_blur, 1., length(v_normal)); | ||
// gl_FragColor.a *= blur; | ||
float blur = smoothstep(u_blur, 1., length(v_normal.xy)); | ||
gl_FragColor.a *= blur; | ||
} |
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
Oops, something went wrong.