fix(raster layer): update raster triangle

This commit is contained in:
thinkinggis 2019-11-04 11:19:45 +08:00
parent cd8409e4cb
commit b0f6265cd3
5 changed files with 46 additions and 29 deletions

View File

@ -131,7 +131,6 @@ export interface IStyleAttribute extends IStyleAttributeInitializationOptions {
export type Triangulation = (
feature: IEncodeFeature,
parserData: IParseDataItem,
) => {
vertices: number[];
indices: number[];
@ -161,7 +160,6 @@ export interface IStyleAttributeService {
createAttributesAndIndices(
encodedFeatures: IEncodeFeature[],
triangulation: Triangulation,
parserData: IParseDataItem[],
): {
attributes: {
[attributeName: string]: IAttribute;

View File

@ -167,7 +167,6 @@ export default class StyleAttributeService implements IStyleAttributeService {
public createAttributesAndIndices(
features: IEncodeFeature[],
triangulation: Triangulation,
parserData: IParseDataItem[],
): {
attributes: {
[attributeName: string]: IAttribute;
@ -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) {

View File

@ -351,7 +351,6 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> implements ILayer {
} = this.styleAttributeService.createAttributesAndIndices(
this.encodedData,
triangulation,
parserData,
);
return createModel({
attributes,

View File

@ -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;

View File

@ -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;
@ -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,
}),
];
});
}
}