Skip to content

Commit 5e75d3b

Browse files
committed
1 parent 4d020be commit 5e75d3b

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

packages/gl/src/layer/mask/Mask.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export default class Mask extends Polygon {
184184
for (let i = 1; i < coordinates.length - 1; i++) {
185185
const point1 = map.coordToPointAtRes(coordinates[i], glRes, TEMP_POINT1);
186186
const point2 = map.coordToPointAtRes(coordinates[i + 1], glRes, TEMP_POINT2);
187-
area += Math.abs(det(point0, point1, point2)) / 2;
187+
area += det(point0, point1, point2) / 2;
188188
}
189189
return area;
190190
}

packages/layer-gltf/test/AddMaskSpec.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,36 @@ describe('setMask', () => {
176176
gltflayer.setMask(mask);
177177
});
178178

179+
it('transparent color mask(issues/791)', done => {
180+
const gltflayer = new maptalks.GLTFLayer('gltf');
181+
const marker = new maptalks.GLTFGeometry(center, {
182+
symbol: {
183+
url: url4,
184+
scaleX: 60,
185+
scaleY: 60,
186+
scaleZ: 60
187+
}
188+
}).addTo(gltflayer);
189+
marker.once('load', () => {
190+
setTimeout(function() {
191+
const pixel1 = pickPixel(map, map.width / 2, map.height / 2, 1, 1);
192+
expect(pixelMatch([9, 14, 15, 255], pixel1)).to.be.eql(true);
193+
const pixel2 = pickPixel(map, map.width / 2 + 100, map.height / 2, 1, 1);
194+
expect(pixelMatch([0, 0, 0, 0], pixel2)).to.be.eql(true);
195+
done();
196+
}, 100);
197+
});
198+
const symbol = {
199+
polygonFill: "#0f0",
200+
polygonOpacity: 0
201+
}
202+
new maptalks.GroupGLLayer('gl', [gltflayer], { sceneConfig }).addTo(map);
203+
const mask = new maptalks.ColorMask(coord1, {
204+
symbol
205+
});
206+
gltflayer.setMask(mask);
207+
});
208+
179209
it('clear mask', done => {//TODO 做像素判断
180210
const gltflayer = new maptalks.GLTFLayer('gltf');
181211
const marker = new maptalks.GLTFGeometry(center, {
@@ -581,9 +611,9 @@ describe('setMask', () => {
581611
expect(resultsInHole[0].data instanceof maptalks.GLTFMarker).to.be.eql(true);
582612

583613
const resultsOutHole = gltflayer.identify(center.add(0.00043980278442308, 0));
584-
expect(resultsOutHole.length).to.be.eql(2);
585-
expect(resultsOutHole[0] instanceof maptalks.ColorMask).to.be.eql(true);
586-
expect(resultsOutHole[1].data instanceof maptalks.GLTFMarker).to.be.eql(true);
614+
expect(resultsOutHole.length).to.be.eql(1);
615+
expect(resultsOutHole[0] instanceof maptalks.ColorMask).to.be.eql(false);
616+
expect(resultsOutHole[0].data instanceof maptalks.GLTFMarker).to.be.eql(true);
587617
done();
588618
}, 100);
589619
});

packages/layer-gltf/test/FixBugSpec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ describe('bug', () => {
4242
marker.setScale(20, 20, 20);
4343
marker.on('load', () => {
4444
setTimeout(function() {
45-
const expectMatrix = maptalksgl.mat4.fromValues(10.000000000000002, 0, -17.32050807568877, 0, 0, 20, 0, 0, 17.32050807568877, 0, 10.000000000000002, 0, 0.13082664542728, 0.1308266454209729, 0.1707822812928094, 1);
45+
const expectMatrix = maptalks.mat4.fromValues(10.000000000000002, 0, -17.32050807568877, 0, 0, 20, 0, 0, 17.32050807568877, 0, 10.000000000000002, 0, 0.13082664542728, 0.1308266454209729, 0.1707822812928094, 1);
4646
const modelMatrix = marker.getModelMatrix();
47-
expect(maptalksgl.mat4.equals(expectMatrix, modelMatrix)).to.be.ok();
47+
expect(maptalks.mat4.equals(expectMatrix, modelMatrix)).to.be.ok();
4848
done();
4949
}, 100);
5050
});
@@ -931,8 +931,8 @@ describe('bug', () => {
931931
gltflayer.on('modelload', () => {
932932
const mesh = marker.getMeshes()[0];
933933
const copyMesh = marker.getMeshes()[0];
934-
const scale1 = maptalksgl.mat4.getScaling([], mesh.localTransform);
935-
const scale2 = maptalksgl.mat4.getScaling([], copyMesh.localTransform);
934+
const scale1 = maptalks.mat4.getScaling([], mesh.localTransform);
935+
const scale2 = maptalks.mat4.getScaling([], copyMesh.localTransform);
936936
expect(scale1).to.be.eql(scale2);
937937
done();
938938
});

packages/layer-gltf/test/GLTFLayerSpec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('maptalks.gltf', function () {
5858
const mesh2 = marker2.getMeshes(null, null, 100)[0];
5959
const localTransform1 = mesh1.localTransform;
6060
const localTransform2 = mesh2.localTransform;
61-
expect(maptalksgl.mat4.equals(localTransform1, localTransform2)).not.to.be.ok();
61+
expect(maptalks.mat4.equals(localTransform1, localTransform2)).not.to.be.ok();
6262
done();
6363
}, 200);
6464
});
@@ -557,9 +557,9 @@ describe('maptalks.gltf', function () {
557557
const marker = new maptalks.GLTFGeometry([center.x, center.y, 0], { symbol: { url: url1 }});
558558
marker.on('load', () => {
559559
marker.setCoordinates([center.x + 0.1, center.y, 10]);
560-
const expectMatrix = maptalksgl.mat4.fromValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
560+
const expectMatrix = maptalks.mat4.fromValues(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
561561
const modelMatrix = marker.getModelMatrix();
562-
expect(maptalksgl.mat4.equals(expectMatrix, modelMatrix)).to.be.ok();
562+
expect(maptalks.mat4.equals(expectMatrix, modelMatrix)).to.be.ok();
563563
done();
564564
});
565565
gltflayer.addGeometry(marker);

packages/reshader.gl/src/shader/glsl/maskColorExtent.frag

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ void main() {
1111
gl_FragColor = texture2D(maskTexture, uv);
1212
gl_FragColor.a = maskColor.a;
1313
#else
14+
if (maskColor.a == 0.0) {
15+
discard;
16+
}
1417
gl_FragColor = maskColor;
1518
#endif
1619
}

0 commit comments

Comments
 (0)