Skip to content

Commit

Permalink
feat(tile): add tile
Browse files Browse the repository at this point in the history
  • Loading branch information
lzxue committed Apr 17, 2019
1 parent 4297de6 commit 5e494fe
Show file tree
Hide file tree
Showing 18 changed files with 208 additions and 222 deletions.
4 changes: 2 additions & 2 deletions demos/01_point_circle.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@
.source(data,{
isCluster:true
})
.shape('hexagon')
.shape('circle')
.size('point_count', [ 5, 40]) // default 1
//.size('value', [ 10, 300]) // default 1
.active(true)
.color('point_count',colorObj.blue)
.color('point_count',["#002466","#105CB3","#2894E0","#CFF6FF","#FFF5B8","#FFAB5C","#F27049","#730D1C"])
.style({
stroke: 'rgb(255,255,255)',
strokeWidth: 1,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
},
"dependencies": {
"@antv/g": "^3.1.3",
"@antv/geo-coord": "^1.0.8",
"@antv/util": "~2.0.1",
"@mapbox/tiny-sdf": "^1.1.0",
"@turf/bbox": "^6.0.1",
Expand Down
12 changes: 1 addition & 11 deletions src/core/engine/picking/picking.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,11 @@ class Picking {
id = -999;
// return;
}
this._raycaster.setFromCamera(normalisedPoint, this._camera);

const intersects = this._raycaster.intersectObjects(this._pickingScene.children, true);
const _point2d = { x: point.x, y: point.y };

let _point3d;
if (intersects.length > 0) {
_point3d = intersects[0].point;
}
const item = {
layerId,
featureId: id,
point2d: _point2d,
point3d: _point3d,
intersects
point2d: _point2d
};
return item;

Expand Down
2 changes: 1 addition & 1 deletion src/core/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class Source extends Base {
// 数据转换 统计,聚合,分类
this._executeTrans();
// 坐标转换
this._projectCoords();
// this._projectCoords();
}
setData(data, cfg = {}) {
Object.assign(this._attrs, cfg);
Expand Down
File renamed without changes.
Empty file added src/geo/point.js
Empty file.
2 changes: 1 addition & 1 deletion src/geom/buffer/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class ImageBuffer extends BufferBase {
const uv = [ 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 ];
const texture = new THREE.Texture(image);
texture.magFilter = THREE.LinearFilter;
texture.minFilter = THREE.LinearFilter;
texture.minFilter = THREE.LinearMipMapLinearFilter;
texture.needsUpdate = true;
const attributes = {
vertices: new Float32Array(positions),
Expand Down
10 changes: 5 additions & 5 deletions src/geom/extrude.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ export default function extrudePolygon(points, extrude) {
const flattengeo = earcut.flatten(points);
const positions = [];
let cells = [];

const { dimensions } = flattengeo;
const triangles = earcut(flattengeo.vertices, flattengeo.holes, flattengeo.dimensions);
cells = triangles;

const pointCount = flattengeo.vertices.length / 3;
const pointCount = flattengeo.vertices.length / dimensions;
const { vertices } = flattengeo;
extrude ? full() : flat();


function flat() {
for (let i = 0; i < pointCount; i++) {
positions.push([ vertices[ i * 3 ], vertices[i * 3 + 1 ], 0 ]);
positions.push([ vertices[ i * dimensions ], vertices[i * dimensions + 1 ], 0 ]);
}
}
function full() {
Expand All @@ -41,10 +41,10 @@ export default function extrudePolygon(points, extrude) {
// 顶部坐标

for (let i = 0; i < pointCount; i++) {
positions.push([ vertices[ i * 3 ], vertices[i * 3 + 1 ], 1 ]);
positions.push([ vertices[ i * dimensions ], vertices[i * dimensions + 1 ], 1 ]);
}
for (let i = 0; i < pointCount; i++) {
positions.push([ vertices[ i * 3 ], vertices[i * 3 + 1 ], 0 ]);
positions.push([ vertices[ i * dimensions ], vertices[i * dimensions + 1 ], 0 ]);
}
for (let i = 0; i < n; i++) {
if (i === (n - 1)) {
Expand Down
5 changes: 5 additions & 0 deletions src/geom/shader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import image_frag from '../shader/image_frag.glsl';
import raster_vert from '../shader/raster_vert.glsl';
import raster_frag from '../shader/raster_frag.glsl';

// tile
import tile_polygon_vert from '../shader/tile/polygon_vert.glsl';
import tile_polygon_frag from '../shader/tile/polygon_frag.glsl';

import common from './common.glsl';
import { registerModule } from '../../util/shaderModule';
import pick_color from './shaderChunks/pick_color.glsl';
Expand All @@ -60,5 +64,6 @@ export function compileBuiltinModules() {
registerModule('text', { vs: text_vert, fs: text_frag });
registerModule('image', { vs: image_vert, fs: image_frag });
registerModule('raster', { vs: raster_vert, fs: raster_frag });
registerModule('tilepolygon', { vs: tile_polygon_vert, fs: tile_polygon_frag });

}
13 changes: 12 additions & 1 deletion src/geom/shader/polygon_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ float sdRect(vec2 p, vec2 sz) {
float inside = min(max(d.x, d.y), 0.);
return outside + inside;
}

float circle(in vec2 _st, in float _radius){
vec2 dist = _st-vec2(0.5);
return 1.-smoothstep(_radius-(_radius*0.01),
_radius+(_radius*0.01),
dot(dist,dist)*4.0);
}

void main() {
if(v_color.w == 0.0) {
Expand Down Expand Up @@ -106,6 +111,12 @@ void main() {
gl_FragColor = vec4(foggedColor,1.0);
}
#else
// #ifdef SHAPE
// vec2 st = gl_FragCoord.xy / v_size ;
// vec3 color = vec3(circle(st,0.5));
// gl_FragColor = vec4(color, 1.0 );
// return;
// #endif
gl_FragColor = vec4(v_color.xyz , v_color.w);
#endif

Expand Down
3 changes: 2 additions & 1 deletion src/geom/shader/polygon_vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void main() {
if(pickingId == u_activeId) {
v_color = u_activeColor;
}
v_size = a_size.x * scale;
gl_Position = matModelViewProjection * vec4(newposition, 1.0);
return;
}
Expand All @@ -49,7 +50,7 @@ void main() {
float lightWeight = ambientRatio + diffuseRatio * lambert + specularRatio * specular;
v_texCoord = faceUv;
v_lightWeight = lightWeight;
// v_size = a_size;

v_color =vec4(a_color.rgb*lightWeight, a_color.w);
if(pickingId == u_activeId) {
v_color = u_activeColor;
Expand Down
6 changes: 3 additions & 3 deletions src/geom/shape/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function triangle() {
return polygonPath(3);
}
function hexagon() {
return polygonPath(6);
return polygonPath(6, 1);
}
export {
circle,
Expand All @@ -29,11 +29,11 @@ export {
square as squareColumn
};

export function polygonPath(pointCount) {
export function polygonPath(pointCount, start = 0) {
const step = Math.PI * 2 / pointCount;
const line = [];
for (let i = 0; i < pointCount; i++) {
line.push(step * i - Math.PI / 12);
line.push(step * i - start * Math.PI / 12);
}
const path = line.map(t => {
const x = Math.sin(t + Math.PI / 4),
Expand Down
13 changes: 13 additions & 0 deletions src/layer/render/image/drawImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as THREE from '../../../core/three';
import ImageMaterial from '../../../geom/material/imageMaterial';
export default function DrawImage(attributes, style) {
this.geometry = new THREE.BufferGeometry();
this.geometry.addAttribute('position', new THREE.Float32BufferAttribute(attributes.vertices, 3));
this.geometry.addAttribute('uv', new THREE.Float32BufferAttribute(attributes.uvs, 2));
const { opacity } = style;
const material = new ImageMaterial({
u_texture: attributes.texture,
u_opacity: opacity
});
return new THREE.Mesh(this.geometry, material);
}
12 changes: 10 additions & 2 deletions src/layer/render/polygon/drawFill.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import * as THREE from '../../../core/three';
import PolygonMaterial from '../../../geom/material/polygonMaterial';
// import PolygonMaterial from '../../../geom/material/polygonMaterial';
import TileMaterial from '../../../geom/material/tile/polygon';

export default function DrawPolygonFill(attributes, style) {
const { opacity, activeColor } = style;
const geometry = new THREE.BufferGeometry();
geometry.addAttribute('position', new THREE.Float32BufferAttribute(attributes.vertices, 3));
geometry.addAttribute('a_color', new THREE.Float32BufferAttribute(attributes.colors, 4));
geometry.addAttribute('pickingId', new THREE.Float32BufferAttribute(attributes.pickingIds, 1));
geometry.addAttribute('normal', new THREE.Float32BufferAttribute(attributes.normals, 3));
const material = new PolygonMaterial({
// const material = new PolygonMaterial({
// u_opacity: opacity,
// u_activeColor: activeColor
// }, {
// SHAPE: false
// });
const material = new TileMaterial({
u_opacity: opacity,
u_activeColor: activeColor
}, {
Expand Down
Loading

0 comments on commit 5e494fe

Please sign in to comment.