Skip to content

Commit

Permalink
fix(merge master conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
lzxue committed May 28, 2019
2 parents fe345e1 + 7bd67d7 commit a41ae2e
Show file tree
Hide file tree
Showing 18 changed files with 503 additions and 159 deletions.
3 changes: 1 addition & 2 deletions demos/02_contour.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
zoom: 14.82,
});
scene.on('loaded', () => {
$.get('./data/contour.geojson', data => {
// data.features = data.features.slice(0,1);
$.get('https://gw.alipayobjects.com/os/rmsportal/ZVfOvhVCzwBkISNsuKCc.json', data => {
scene.LineLayer({
zIndex: 2
})
Expand Down
55 changes: 55 additions & 0 deletions demos/dashline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="geometry" content="diagram">
<link rel="stylesheet" href="./assets/common.css">
<title>dashline demo</title>
<style>
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>

<body>
<div id="map"></div>
<script src="https://webapi.amap.com/maps?v=1.4.8&key=15cd8a57710d40c9b7c0e3cc120f1200&plugin=Map3D"></script>
<script src="./assets/jquery-3.2.1.min.js"></script>
<script src="./assets/dat.gui.min.js"></script>
<script src="../build/L7.js"></script>
<script>

const color1 = [ 'rgba(37, 140, 249, 0.8)', 'rgba(14, 241, 242, 0.8)', 'rgba(255, 255, 255, 0.8)' ];
const scene = new L7.Scene({
id: 'map',
mapStyle: 'dark', // 样式URL
center: [ 102.602992, 23.107329],
pitch: 15,
zoom: 14.82,
});
scene.on('loaded', () => {
$.get('https://gw.alipayobjects.com/os/rmsportal/ZVfOvhVCzwBkISNsuKCc.json', data => {
scene.LineLayer({
zIndex: 2
})
.source(data)
.size('ELEV',(value)=>{
return [2,(value-1000)*7];
})
.active(true)
.shape('line')
.style({
lineType: 'dash',
dashArray: 200,
dashOffset: 0.2,
dashRatio: 0.5
})
.color('ELEV',["#E8FCFF", "#CFF6FF", "#A1E9ff", "#65CEF7", "#3CB1F0", "#2894E0", "#1772c2", "#105CB3", "#0D408C", "#002466"].reverse())
.render();
});
});

</script>
</body>
</html>
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@
"earcut": "^2.1.3",
"fecha": "^2.3.3",
"gl-matrix": "^2.4.1",
"gl-vec2": "^1.3.0",
"lodash": "^4.17.5",
"polyline-normals": "^2.0.2",
"polyline-miter-util": "^1.0.1",
"rbush": "^2.0.2",
"simple-statistics": "^7.0.1",
"supercluster": "^6.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/core/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export default class Scene extends Base {

_initEngine(mapContainer) {
this._engine = new Engine(mapContainer, this);
// this.registerMapEvent();
this._engine.run();
this.registerMapEvent();
// this._engine.run();
// this.workerPool = new WorkerPool();
compileBuiltinModules();
}
Expand Down
10 changes: 6 additions & 4 deletions src/geom/buffer/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class LineBuffer extends BufferBase {
}
_getMeshLineAttributes() {
const layerData = this.get('layerData');
const { lineType } = this.get('style');
const { dashArray } = this.get('style');
const positions = [];
const pickingIds = [];
const normal = [];
Expand All @@ -84,11 +84,11 @@ export default class LineBuffer extends BufferBase {
const indexArray = [];
const sizes = [];
const attrDistance = [];
const attrDashArray = [];
layerData.forEach(item => {
const props = item;
const positionCount = positions.length / 3;
// TODO 处理多个线段的情况
const attr = lineShape.Line(item.coordinates, props, positionCount, (lineType !== 'soild'));
const attr = lineShape.Line(item.coordinates, props, positionCount, dashArray);
positions.push(...attr.positions);
normal.push(...attr.normal);
miter.push(...attr.miter);
Expand All @@ -97,6 +97,7 @@ export default class LineBuffer extends BufferBase {
sizes.push(...attr.sizes);
attrDistance.push(...attr.attrDistance);
pickingIds.push(...attr.pickingIds);
attrDashArray.push(...attr.dashArray);
});
return {
positions,
Expand All @@ -106,7 +107,8 @@ export default class LineBuffer extends BufferBase {
indexArray,
pickingIds,
sizes,
attrDistance
attrDistance,
attrDashArray
};
}

Expand Down
9 changes: 9 additions & 0 deletions src/geom/buffer/point/fillBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export default function fillBuffer(layerData) {
throw new Error('Invalid shape type: ' + shape);
}
toPointShapeAttributes(polygon, coordinates, { size, shape, color, id }, attribute);
// toPointShapeAttributes(polygon, null, {}, attribute);
// instanced attributes
// attribute.vertices.push(...coordinates);
// attribute.a_size.push(...size);
// attribute.colors.push(...color);
// attribute.pickingIds.push(id);

});
return attribute;
Expand Down Expand Up @@ -78,5 +84,8 @@ function toPointShapeAttributes(polygon, geo, style, attribute) {
attribute.colors.push(...color, ...color, ...color);
attribute.pickingIds.push(id, id, id);

// attribute.shapePositions.push(ax, ay, az, bx, by, bz, cx, cy, cz);
// attribute.normals.push(nx, ny, nz, nx, ny, nz, nx, ny, nz);

}
}
43 changes: 9 additions & 34 deletions src/geom/material/lineMaterial.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as THREE from '../../core/three';
import Material from './material';
import { getModule } from '../../util/shaderModule';
import { getModule, wrapUniforms } from '../../util/shaderModule';
import arcline_frag from '../shader/arcline_frag.glsl';
import arcline_vert from '../shader/arcline_vert.glsl';

import merge from '@antv/util/lib/deep-mix';

export function LineMaterial(options) {
const { vs, fs } = getModule('line');
Expand Down Expand Up @@ -40,43 +40,18 @@ export function ArcLineMaterial(options) {
return material;
}

export function MeshLineMaterial(options) {
const { vs, fs } = getModule('meshline');
export function MeshLineMaterial(options, defines) {
const { vs, fs, uniforms } = getModule('meshline');
const material = new Material({
uniforms: {
u_opacity: { value: options.u_opacity || 1.0 },
u_time: { value: options.u_time || 0 },
u_zoom: { value: options.u_zoom },
u_duration: { value: options.u_duration || 2.0 },
u_interval: { value: options.u_interval || 1.0 },
u_trailLength: { value: options.u_trailLength || 0.2 },
u_activeId: { value: options.activeId || 0 },
u_activeColor: { value: options.activeColor || [ 1.0, 0, 0, 1.0 ] }
},
uniforms: wrapUniforms(merge(uniforms, options, {
u_activeId: options.activeId,
u_activeColor: options.activeColor
})),
defines,
vertexShader: vs,
fragmentShader: fs,
transparent: true,
blending: THREE.AdditiveBlending
});
return material;
}
export function DashLineMaterial(options) {
const { vs, fs } = getModule('meshline');
const material = new Material({
uniforms: {
u_opacity: { value: options.u_opacity || 1.0 },
u_time: { value: options.u_time || 0 },
u_zoom: { value: options.u_zoom },
u_dashSteps: { value: options.u_dashSteps || 12 },
u_dashSmooth: { value: options.u_dashSmooth || 0.01 },
u_dashDistance: { value: options.u_dashDistance || 0.2 },
u_activeId: { value: options.activeId || 0 },
u_activeColor: { value: options.activeColor || [ 1.0, 0, 0, 1.0 ] }
},
vertexShader: vs,
fragmentShader: fs,
transparent: true
});
return material;
}

10 changes: 0 additions & 10 deletions src/geom/shader/dashline_frag.glsl

This file was deleted.

23 changes: 0 additions & 23 deletions src/geom/shader/dashline_vert.glsl

This file was deleted.

5 changes: 0 additions & 5 deletions src/geom/shader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import mesh_line_vert from '../shader/meshline_vert.glsl';
import line_frag from '../shader/line_frag.glsl';
import line_vert from '../shader/line_vert.glsl';

// 虚线
import dash_vert from '../shader/dashline_vert.glsl';
import dash_frag from '../shader/dashline_frag.glsl';

// 热力图
import heatmap_color_vert from '../shader/heatmap_colorize_vert.glsl';
import heatmap_color_frag from '../shader/heatmap_colorize_frag.glsl';
Expand Down Expand Up @@ -63,7 +59,6 @@ export function compileBuiltinModules() {
registerModule('pointline', { vs: point_line_vert, fs: point_line_frag });
registerModule('meshline', { vs: mesh_line_vert, fs: mesh_line_frag });
registerModule('line', { vs: line_vert, fs: line_frag });
registerModule('dashline', { vs: dash_vert, fs: dash_frag });
registerModule('heatmap_color', { vs: heatmap_color_vert, fs: heatmap_color_frag });
registerModule('heatmap_intensity', { vs: heatmap_intensity_vert, fs: heatmap_intensity_frag });
registerModule('text', { vs: text_vert, fs: text_frag });
Expand Down
29 changes: 23 additions & 6 deletions src/geom/shader/meshline_frag.glsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
precision highp float;
uniform float u_opacity;

uniform float u_opacity : 1.0;
uniform float u_dash_offset : 0.0;
uniform float u_dash_ratio : 0.0;
uniform float u_blur : 0.9;

varying vec4 v_color;
varying float vTime;
varying float v_distance;
varying float v_dash_array;
varying float v_time;
varying vec2 v_normal;

void main() {
gl_FragColor = v_color;
gl_FragColor = v_color;
#ifdef DASHLINE
gl_FragColor.a *= u_opacity * ceil(mod(v_distance + u_dash_offset, v_dash_array) - (v_dash_array * u_dash_ratio));
#else
gl_FragColor.a = v_color.a * u_opacity;
#ifdef ANIMATE
gl_FragColor.a *= vTime;
#endif
#endif
#ifdef ANIMATE
gl_FragColor.a *= v_time;
#endif

// anti-alias
float blur = 1. - smoothstep(u_blur, 1., length(v_normal));
gl_FragColor.a *= blur;
}
60 changes: 35 additions & 25 deletions src/geom/shader/meshline_vert.glsl
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
precision highp float;
attribute float a_miter;
attribute vec4 a_color;
attribute float a_size;
attribute float a_distance;
attribute float a_dash_array;

uniform float u_zoom;
uniform float u_time : 0;
uniform float u_activeId : 1;
uniform vec4 u_activeColor : [ 1.0, 0, 0, 1.0 ];

varying float v_time;
varying vec4 v_color;
uniform float u_time;
varying float vTime;
uniform float u_activeId;
uniform vec4 u_activeColor;
// animate
varying float v_distance;
varying float v_dash_array;
varying vec2 v_normal;

#ifdef ANIMATE
uniform float u_duration; // 动画持续时间
uniform float u_interval;
uniform float u_repeat;
uniform float u_trailLength;
uniform float u_duration : 2.0;
uniform float u_interval : 1.0;
uniform float u_trailLength : 0.2;
#endif


void main() {
mat4 matModelViewProjection = projectionMatrix * modelViewMatrix;
vec3 pointPos = vec3(position.xy,0.) + vec3(normal * a_size * pow(2.0,20.0-u_zoom) / 2.0 * a_miter);
v_color = a_color;
if(pickingId == u_activeId) {
v_color = u_activeColor;
}
#ifdef ANIMATE
//mod(a_distance,0.2) * 5.
float alpa =1.0 - fract( mod(1.0- a_distance,u_interval)* (1.0/u_interval) + u_time / u_duration);
alpa = (alpa + u_trailLength -1.0) / u_trailLength;
vTime = clamp(alpa,0.,1.);
// vTime = (28800. + mod(u_time* 1000.,28800.)- position.z) / 100.;
v_color = a_color;
v_distance = a_distance;
v_dash_array = a_dash_array;

// anti-alias
v_normal = vec2(normal * sign(a_miter));

// extrude along normal
float extrude_scale = pow(2.0, 20.0 - u_zoom);
vec3 offset = vec3(normal * a_size * extrude_scale / 2.0 * a_miter);
gl_Position = projectionMatrix * modelViewMatrix * vec4(position.xy + offset.xy, 0., 1.0);

#ifdef ANIMATE
float alpha =1.0 - fract( mod(1.0- a_distance,u_interval)* (1.0/u_interval) + u_time / u_duration);
alpha = (alpha + u_trailLength -1.0) / u_trailLength;
v_time = clamp(alpha,0.,1.);
#endif
worldId = id_toPickColor(pickingId);
gl_Position = matModelViewProjection * vec4(pointPos.xy, 0., 1.0);

// picking
if(pickingId == u_activeId) {
v_color = u_activeColor;
}
worldId = id_toPickColor(pickingId);
}
Loading

0 comments on commit a41ae2e

Please sign in to comment.