mirror of https://gitee.com/antv-l7/antv-l7
merge
This commit is contained in:
commit
bff21a2718
|
@ -70,8 +70,11 @@ test
|
||||||
*.un~
|
*.un~
|
||||||
.idea
|
.idea
|
||||||
bin
|
bin
|
||||||
|
bundler
|
||||||
demos
|
demos
|
||||||
docs
|
docs
|
||||||
|
lib
|
||||||
|
src
|
||||||
temp
|
temp
|
||||||
webpack-dev.config.js
|
webpack-dev.config.js
|
||||||
webpack.config.js
|
webpack.config.js
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@antv/l7",
|
"name": "@antv/l7",
|
||||||
"version": "1.0.1",
|
"version": "1.0.3",
|
||||||
"description": "Large-scale WebGL-powered Geospatial Data Visualization",
|
"description": "Large-scale WebGL-powered Geospatial Data Visualization",
|
||||||
"main": "build/l7.js",
|
"main": "build/l7.js",
|
||||||
"browser": "build/l7.js",
|
"browser": "build/l7.js",
|
||||||
|
|
|
@ -9,10 +9,7 @@ class Picking {
|
||||||
this._camera = camera;
|
this._camera = camera;
|
||||||
this._raycaster = new THREE.Raycaster();
|
this._raycaster = new THREE.Raycaster();
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this._envents = [];
|
this._raycaster.linePrecision = 10;
|
||||||
|
|
||||||
// TODO: Match this with the line width used in the picking layers
|
|
||||||
this._raycaster.linePrecision = 3;
|
|
||||||
this._pickingScene = PickingScene;
|
this._pickingScene = PickingScene;
|
||||||
const size = this._renderer.getSize();
|
const size = this._renderer.getSize();
|
||||||
this._width = size.width;
|
this._width = size.width;
|
||||||
|
@ -21,7 +18,7 @@ class Picking {
|
||||||
magFilter: THREE.LinearFilter,
|
magFilter: THREE.LinearFilter,
|
||||||
format: THREE.RGBAFormat,
|
format: THREE.RGBAFormat,
|
||||||
stencilBuffer: false,
|
stencilBuffer: false,
|
||||||
depthBuffer: false
|
depthBuffer: true
|
||||||
};
|
};
|
||||||
|
|
||||||
this._pickingTexture = new THREE.WebGLRenderTarget(this._width, this._height, parameters);
|
this._pickingTexture = new THREE.WebGLRenderTarget(this._width, this._height, parameters);
|
||||||
|
@ -35,37 +32,14 @@ class Picking {
|
||||||
_initEvents() {
|
_initEvents() {
|
||||||
this._resizeHandler = this._resizeTexture.bind(this);
|
this._resizeHandler = this._resizeTexture.bind(this);
|
||||||
window.addEventListener('resize', this._resizeHandler, false);
|
window.addEventListener('resize', this._resizeHandler, false);
|
||||||
|
|
||||||
// this._mouseUpHandler = this._onMouseUp.bind(this);
|
|
||||||
// this._world._container.addEventListener('mouseup', this._mouseUpHandler, false);
|
|
||||||
// this._world._container.addEventListener('mousemove', this._mouseUpHandler, false);
|
|
||||||
// this._world._container.addEventListener('mousemove', this._onWorldMove.bind(this), false);
|
|
||||||
}
|
}
|
||||||
pickdata(event) {
|
pickdata(event) {
|
||||||
const point = { x: event.offsetX, y: event.offsetY, type: event.type };
|
const point = { x: event.pixel.x, y: event.pixel.y, type: event.type };
|
||||||
const normalisedPoint = { x: 0, y: 0 };
|
const normalisedPoint = { x: 0, y: 0 };
|
||||||
normalisedPoint.x = (point.x / this._width) * 2 - 1;
|
normalisedPoint.x = (point.x / this._width) * 2 - 1;
|
||||||
normalisedPoint.y = -(point.y / this._height) * 2 + 1;
|
normalisedPoint.y = -(point.y / this._height) * 2 + 1;
|
||||||
this._pickAllObject(point, normalisedPoint);
|
this._pickAllObject(point, normalisedPoint);
|
||||||
}
|
}
|
||||||
_onMouseUp(event) {
|
|
||||||
// Only react to main button click
|
|
||||||
// if (event.button !== 0) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
const point = { x: event.clientX, y: event.clientY, type: event.type };
|
|
||||||
const normalisedPoint = { x: 0, y: 0 };
|
|
||||||
normalisedPoint.x = (point.x / this._width) * 2 - 1;
|
|
||||||
normalisedPoint.y = -(point.y / this._height) * 2 + 1;
|
|
||||||
this._pickAllObject(point, normalisedPoint);
|
|
||||||
// this._pick(point, normalisedPoint);
|
|
||||||
}
|
|
||||||
_onWorldMove() {
|
|
||||||
|
|
||||||
this._needUpdate = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Ensure this doesn't get out of sync issue with the renderer resize
|
|
||||||
_resizeTexture() {
|
_resizeTexture() {
|
||||||
const size = this._renderer.getSize();
|
const size = this._renderer.getSize();
|
||||||
|
|
||||||
|
@ -79,28 +53,11 @@ class Picking {
|
||||||
_update(point) {
|
_update(point) {
|
||||||
|
|
||||||
const texture = this._pickingTexture;
|
const texture = this._pickingTexture;
|
||||||
// if (this._needUpdate) {
|
|
||||||
this._renderer.render(this._pickingScene, this._camera, this._pickingTexture);
|
this._renderer.render(this._pickingScene, this._camera, this._pickingTexture);
|
||||||
// this._needUpdate = false;
|
|
||||||
// }
|
|
||||||
this.pixelBuffer = new Uint8Array(4);
|
this.pixelBuffer = new Uint8Array(4);
|
||||||
this._renderer.readRenderTargetPixels(texture, point.x, this._height - point.y, 1, 1, this.pixelBuffer);
|
this._renderer.readRenderTargetPixels(texture, point.x, this._height - point.y, 1, 1, this.pixelBuffer);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
// 添加dom事件 支持 mousedown ,mouseenter mouseleave mousemove mouseover mouseout mouse up
|
|
||||||
on(type) {
|
|
||||||
|
|
||||||
this._mouseUpHandler = this._onMouseUp.bind(this);
|
|
||||||
this._world._container.addEventListener(type, this._mouseUpHandler, false);
|
|
||||||
this._envents.push([ type, this._mouseUpHandler ]);
|
|
||||||
}
|
|
||||||
off(type, hander) {
|
|
||||||
this._world._container.removeEventListener(type, this._mouseUpHandler, false);
|
|
||||||
this._envents = this._envents.filter(item => {
|
|
||||||
return item[0] === 'type' && hander === item[1];
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
_filterObject(id) {
|
_filterObject(id) {
|
||||||
this._pickingScene.children.forEach((object, index) => {
|
this._pickingScene.children.forEach((object, index) => {
|
||||||
|
@ -123,9 +80,7 @@ class Picking {
|
||||||
|
|
||||||
_pick(point, normalisedPoint, layerId) {
|
_pick(point, normalisedPoint, layerId) {
|
||||||
this._update(point);
|
this._update(point);
|
||||||
// Interpret the pixel as an ID
|
|
||||||
let id = (this.pixelBuffer[2] * 255 * 255) + (this.pixelBuffer[1] * 255) + (this.pixelBuffer[0]);
|
let id = (this.pixelBuffer[2] * 255 * 255) + (this.pixelBuffer[1] * 255) + (this.pixelBuffer[0]);
|
||||||
// Skip if ID is 16646655 (white) as the background returns this
|
|
||||||
if (id === 16646655 || this.pixelBuffer[3] === 0) {
|
if (id === 16646655 || this.pixelBuffer[3] === 0) {
|
||||||
id = -999;
|
id = -999;
|
||||||
// return;
|
// return;
|
||||||
|
@ -133,9 +88,6 @@ class Picking {
|
||||||
|
|
||||||
this._raycaster.setFromCamera(normalisedPoint, this._camera);
|
this._raycaster.setFromCamera(normalisedPoint, this._camera);
|
||||||
|
|
||||||
// Perform ray intersection on picking scene
|
|
||||||
//
|
|
||||||
// TODO: Only perform intersection test on the relevant picking mesh
|
|
||||||
const intersects = this._raycaster.intersectObjects(this._pickingScene.children, true);
|
const intersects = this._raycaster.intersectObjects(this._pickingScene.children, true);
|
||||||
const _point2d = { x: point.x, y: point.y };
|
const _point2d = { x: point.x, y: point.y };
|
||||||
|
|
||||||
|
@ -143,11 +95,6 @@ class Picking {
|
||||||
if (intersects.length > 0) {
|
if (intersects.length > 0) {
|
||||||
_point3d = intersects[0].point;
|
_point3d = intersects[0].point;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass along as much data as possible for now until we know more about how
|
|
||||||
// people use the picking API and what the returned data should be
|
|
||||||
//
|
|
||||||
// TODO: Look into the leak potential for passing so much by reference here
|
|
||||||
const item = {
|
const item = {
|
||||||
layerId,
|
layerId,
|
||||||
featureId: id - 1,
|
featureId: id - 1,
|
||||||
|
|
|
@ -6,6 +6,7 @@ import WorkerPool from './worker';
|
||||||
import { MapProvider } from '../map/provider';
|
import { MapProvider } from '../map/provider';
|
||||||
import GaodeMap from '../map/gaodeMap';
|
import GaodeMap from '../map/gaodeMap';
|
||||||
import Global from '../global';
|
import Global from '../global';
|
||||||
|
import { compileBuiltinModules } from '../geom/shader';
|
||||||
export default class Scene extends Base {
|
export default class Scene extends Base {
|
||||||
getDefaultCfg() {
|
getDefaultCfg() {
|
||||||
return Global.scene;
|
return Global.scene;
|
||||||
|
@ -22,6 +23,7 @@ export default class Scene extends Base {
|
||||||
this._engine = new Engine(mapContainer, this);
|
this._engine = new Engine(mapContainer, this);
|
||||||
this._engine.run();
|
this._engine.run();
|
||||||
this.workerPool = new WorkerPool();
|
this.workerPool = new WorkerPool();
|
||||||
|
compileBuiltinModules();
|
||||||
}
|
}
|
||||||
// 为pickup场景添加 object 对象
|
// 为pickup场景添加 object 对象
|
||||||
addPickMesh(object) {
|
addPickMesh(object) {
|
||||||
|
@ -94,11 +96,12 @@ export default class Scene extends Base {
|
||||||
'mousedown',
|
'mousedown',
|
||||||
'mouseleave',
|
'mouseleave',
|
||||||
'mouseup',
|
'mouseup',
|
||||||
|
'rightclick',
|
||||||
'click',
|
'click',
|
||||||
'dblclick'
|
'dblclick'
|
||||||
];
|
];
|
||||||
events.forEach(event => {
|
events.forEach(event => {
|
||||||
this._container.addEventListener(event, e => {
|
this.map.on(event, e => {
|
||||||
// 要素拾取
|
// 要素拾取
|
||||||
this._engine._picking.pickdata(e);
|
this._engine._picking.pickdata(e);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import polygon_frag from '../shader/polygon_frag.glsl';
|
|
||||||
import polygon_vert from '../shader/polygon_vert.glsl';
|
|
||||||
import Material from './material';
|
import Material from './material';
|
||||||
|
import { getModule } from '../../util/shaderModule';
|
||||||
// export default function PolygonMaterial(options) {
|
// export default function PolygonMaterial(options) {
|
||||||
// const material = new Material({
|
// const material = new Material({
|
||||||
// uniforms: {
|
// uniforms: {
|
||||||
|
@ -48,8 +47,10 @@ export default class PolygonMaterial extends Material {
|
||||||
this.uniforms = Object.assign(uniforms, this.setUniform(_uniforms));
|
this.uniforms = Object.assign(uniforms, this.setUniform(_uniforms));
|
||||||
this.type = 'PolygonMaterial';
|
this.type = 'PolygonMaterial';
|
||||||
this.defines = Object.assign(defines, _defines);
|
this.defines = Object.assign(defines, _defines);
|
||||||
this.vertexShader = polygon_vert;
|
|
||||||
this.fragmentShader = polygon_frag;
|
const { vs, fs } = getModule('polygon');
|
||||||
|
this.vertexShader = vs;
|
||||||
|
this.fragmentShader = fs;
|
||||||
this.transparent = true;
|
this.transparent = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
#define PI 3.14159265359
|
||||||
|
#define TWO_PI 6.28318530718
|
|
@ -1,14 +1,12 @@
|
||||||
import point_frag from '../shader/point_frag.glsl';
|
import point_frag from '../shader/point_frag.glsl';
|
||||||
import point_vert from '../shader/point_vert.glsl';
|
import point_vert from '../shader/point_vert.glsl';
|
||||||
const shaderslib = {
|
import polygon_frag from '../shader/polygon_frag.glsl';
|
||||||
pointShader: {
|
import polygon_vert from '../shader/polygon_vert.glsl';
|
||||||
fragment: point_frag,
|
import common from './common.glsl';
|
||||||
vertex: point_vert
|
import { registerModule } from '../../util/shaderModule';
|
||||||
}
|
|
||||||
};
|
export function compileBuiltinModules() {
|
||||||
// for (const programName in shaderslib) {
|
registerModule('point', { vs: point_vert, fs: point_frag });
|
||||||
// const program = shaderslib[programName];
|
registerModule('common', { vs: common, fs: common });
|
||||||
// program.fragment = ShaderFactory.parseIncludes(program.fragment);
|
registerModule('polygon', { vs: polygon_vert, fs: polygon_frag });
|
||||||
// program.vertex = ShaderFactory.parseIncludes(program.vertex);
|
}
|
||||||
// }
|
|
||||||
export default shaderslib;
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
|
||||||
precision highp float;
|
precision highp float;
|
||||||
#define PI 3.14159265359
|
|
||||||
#define TWO_PI 6.28318530718
|
#pragma import "common"
|
||||||
|
|
||||||
uniform float u_strokeWidth;
|
uniform float u_strokeWidth;
|
||||||
uniform vec4 u_stroke;
|
uniform vec4 u_stroke;
|
||||||
uniform float u_opacity;
|
uniform float u_opacity;
|
||||||
|
|
|
@ -7,7 +7,6 @@ import TextBuffer from '../geom/buffer/text';
|
||||||
import TextMaterial from '../geom/material/textMaterial';
|
import TextMaterial from '../geom/material/textMaterial';
|
||||||
import * as PointBuffer from '../geom/buffer/point/index';
|
import * as PointBuffer from '../geom/buffer/point/index';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* point shape 2d circle, traingle text,image
|
* point shape 2d circle, traingle text,image
|
||||||
* shape 3d cube,column, sphere
|
* shape 3d cube,column, sphere
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
const SHADER_TYPE = {
|
||||||
|
VS: 'vs',
|
||||||
|
FS: 'fs'
|
||||||
|
};
|
||||||
|
const moduleCache = {};
|
||||||
|
const rawContentCache = {};
|
||||||
|
const precisionRegExp = /precision\s+(high|low|medium)p\s+float/;
|
||||||
|
const globalDefaultprecision = '#ifdef GL_FRAGMENT_PRECISION_HIGH\n precision highp float;\n #else\n precision mediump float;\n#endif\n';
|
||||||
|
const includeRegExp = /#pragma include (["^+"]?["\ "[a-zA-Z_0-9](.*)"]*?)/g;
|
||||||
|
|
||||||
|
function processModule(rawContent, includeList, type) {
|
||||||
|
return rawContent.replace(includeRegExp, (_, strMatch) => {
|
||||||
|
const includeOpt = strMatch.split(' ');
|
||||||
|
const includeName = includeOpt[0].replace(/"/g, '');
|
||||||
|
|
||||||
|
if (includeList.indexOf(includeName) > -1) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
let txt = rawContentCache[includeName][type];
|
||||||
|
includeList.push(includeName);
|
||||||
|
|
||||||
|
txt = processModule(txt, includeList, type);
|
||||||
|
return txt;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function registerModule(moduleName, { vs, fs }) {
|
||||||
|
rawContentCache[moduleName] = {
|
||||||
|
[SHADER_TYPE.VS]: vs,
|
||||||
|
[SHADER_TYPE.FS]: fs
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getModule(moduleName) {
|
||||||
|
if (moduleCache[moduleName]) {
|
||||||
|
return moduleCache[moduleName];
|
||||||
|
}
|
||||||
|
|
||||||
|
let vs = rawContentCache[moduleName][SHADER_TYPE.VS];
|
||||||
|
let fs = rawContentCache[moduleName][SHADER_TYPE.FS];
|
||||||
|
|
||||||
|
vs = processModule(vs, [], SHADER_TYPE.VS);
|
||||||
|
fs = processModule(fs, [], SHADER_TYPE.FS);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set default precision for fragment shader
|
||||||
|
* https://stackoverflow.com/questions/28540290/why-it-is-necessary-to-set-precision-for-the-fragment-shader
|
||||||
|
*/
|
||||||
|
if (!precisionRegExp.test(fs)) {
|
||||||
|
fs = globalDefaultprecision + fs;
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleCache[moduleName] = {
|
||||||
|
[SHADER_TYPE.VS]: vs.trim(),
|
||||||
|
[SHADER_TYPE.FS]: fs.trim()
|
||||||
|
};
|
||||||
|
return moduleCache[moduleName];
|
||||||
|
}
|
|
@ -17,6 +17,5 @@ self.addEventListener('message', e => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
self.addEventListener('error', function(e) {
|
self.addEventListener('error', function(e) {
|
||||||
/* eslint-disable */
|
console.error('filename:' + e.filename + '\nmessage:' + e.message + '\nline:' + e.lineno);
|
||||||
console.log('filename:' + e.filename + '\nmessage:' + e.message + '\nline:' + e.lineno);
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import { registerModule, getModule } from '../../../src/util/shaderModule';
|
||||||
|
|
||||||
|
describe('test shader module', function() {
|
||||||
|
|
||||||
|
const vs = `
|
||||||
|
#define PI 3.14
|
||||||
|
`;
|
||||||
|
|
||||||
|
const commonModule = {
|
||||||
|
vs,
|
||||||
|
fs: vs
|
||||||
|
};
|
||||||
|
|
||||||
|
const module1 = {
|
||||||
|
vs: `
|
||||||
|
#pragma include "common"
|
||||||
|
`,
|
||||||
|
fs: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
registerModule('common', commonModule);
|
||||||
|
registerModule('module1', module1);
|
||||||
|
|
||||||
|
it('should import a module correctly.', function() {
|
||||||
|
const { vs, fs } = getModule('module1');
|
||||||
|
|
||||||
|
expect(vs).eq('#define PI 3.14');
|
||||||
|
expect(fs).eq('');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue