Skip to content

Commit

Permalink
fix(raster layer): update raster triangle
Browse files Browse the repository at this point in the history
  • Loading branch information
lzxue committed Nov 4, 2019
1 parent cd8409e commit b0f6265
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
2 changes: 0 additions & 2 deletions packages/core/src/services/layer/IStyleAttributeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export interface IStyleAttribute extends IStyleAttributeInitializationOptions {

export type Triangulation = (
feature: IEncodeFeature,
parserData: IParseDataItem,
) => {
vertices: number[];
indices: number[];
Expand Down Expand Up @@ -161,7 +160,6 @@ export interface IStyleAttributeService {
createAttributesAndIndices(
encodedFeatures: IEncodeFeature[],
triangulation: Triangulation,
parserData: IParseDataItem[],
): {
attributes: {
[attributeName: string]: IAttribute;
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/services/layer/StyleAttributeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ export default class StyleAttributeService implements IStyleAttributeService {
public createAttributesAndIndices(
features: IEncodeFeature[],
triangulation: Triangulation,
parserData: IParseDataItem[],
): {
attributes: {
[attributeName: string]: IAttribute;
Expand All @@ -188,7 +187,7 @@ export default class StyleAttributeService implements IStyleAttributeService {
vertices: verticesForCurrentFeature,
normals: normalsForCurrentFeature,
size: vertexSize,
} = triangulation(feature, parserData[featureIdx]);
} = triangulation(feature);
indices.push(...indicesForCurrentFeature.map((i) => i + verticesNum));
vertices.push(...verticesForCurrentFeature);
if (normalsForCurrentFeature) {
Expand Down
1 change: 0 additions & 1 deletion packages/layers/src/core/BaseLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> implements ILayer {
} = this.styleAttributeService.createAttributesAndIndices(
this.encodedData,
triangulation,
parserData,
);
return createModel({
attributes,
Expand Down
5 changes: 1 addition & 4 deletions packages/layers/src/raster/buffers/triangulation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { IEncodeFeature, IParseDataItem } from '@l7/core';
// @ts-ignore
import Martini from '@mapbox/martini';
export function RasterTriangulation(
feature: IEncodeFeature,
parserData: IParseDataItem,
) {
export function RasterTriangulation(parserData: IParseDataItem) {
const { coordinates, data, min, max, width, height } = parserData;
const maxlength = Math.max(width, height);
const gridSize = Math.pow(2, Math.ceil(Math.log2(maxlength))) + 1;
Expand Down
64 changes: 44 additions & 20 deletions packages/layers/src/raster/raster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ interface IRasterLayerStyleOptions {
rampColors: IColorRamp;
}

export default class ImageLayer extends BaseLayer<IRasterLayerStyleOptions> {
public name: string = 'RasterLayer';
export default class RasterLayer extends BaseLayer<IRasterLayerStyleOptions> {
public name: string = 'e';
protected texture: ITexture2D;
protected colorTexture: ITexture2D;

Expand Down Expand Up @@ -81,24 +81,48 @@ export default class ImageLayer extends BaseLayer<IRasterLayerStyleOptions> {
height: imageData.height,
flipY: true,
});
this.models = [
this.buildLayerModel({
moduleName: 'Raster',
vertexShader: rasterVert,
fragmentShader: rasterFrag,
triangulation: RasterTriangulation,
primitive: gl.TRIANGLES,
depth: { enable: false },
blend: {
enable: true,
func: {
srcRGB: gl.SRC_ALPHA,
srcAlpha: 1,
dstRGB: gl.ONE_MINUS_SRC_ALPHA,
dstAlpha: 1,
},
},
this.models = [this.buildRasterModel()];
}
private buildRasterModel() {
const source = this.getSource();
const sourceFeature = source.data.dataArray[0];
const triangulation = RasterTriangulation(sourceFeature);
this.shaderModuleService.registerModule('raster', {
vs: rasterVert,
fs: rasterFrag,
});

const { vs, fs, uniforms } = this.shaderModuleService.getModule('raster');
const {
createAttribute,
createElements,
createBuffer,
createModel,
} = this.rendererService;
return createModel({
vs,
fs,
attributes: {
a_Position: createAttribute({
buffer: createBuffer({
data: triangulation.vertices,
type: gl.FLOAT,
}),
size: 2,
}),
},
primitive: gl.TRIANGLES,
uniforms: {
...uniforms,
},
depth: {
enable: true,
},
elements: createElements({
data: triangulation.indices,
type: gl.UNSIGNED_INT,
count: triangulation.indices.length,
}),
];
});
}
}

0 comments on commit b0f6265

Please sign in to comment.