Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/layer-gltf/src/GLTFMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,13 @@ export default class GLTFMarker extends Marker {
//此处涉及到材质的更新,比较耗费性能,对于不需要更新材质的操作尽量不去更新
if (markerUniforms && this.isDirty() && this._isUniformsDirty()) {
for (const u in markerUniforms) {
mesh.setUniform(u, markerUniforms[u]);
if (this._uniformNodeIndex && defined(this._uniformNodeIndex[u])) {
if (Number(mesh.properties.nodeIndex) === this._uniformNodeIndex[u]) {
mesh.setUniform(u, markerUniforms[u]);
}
} else {
mesh.setUniform(u, markerUniforms[u]);
}
}
}
if (this._isTransparent()) {
Expand Down Expand Up @@ -1136,11 +1142,13 @@ export default class GLTFMarker extends Marker {
return symbol && symbol.uniforms;
}

setUniform(key, value) {
setUniform(key, value, nodeIndex) {
const uniforms = this.getUniforms() || {};
uniforms[key] = value;
super.updateSymbol({ uniforms });
this._uniformDirty = true;
this._uniformNodeIndex = this._uniformNodeIndex || {};
this._uniformNodeIndex[key] = nodeIndex;
return this;
}

Expand Down
25 changes: 25 additions & 0 deletions packages/layer-gltf/test/FixBugSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2068,4 +2068,29 @@ describe('bug', () => {
const vLayer = new maptalks.VectorLayer('v', { enableAltitude: true }).addTo(map);
new maptalks.Marker([0, 0, 100]).addTo(vLayer);
});

it('set uniform for specific nodeIndex(#issues/886)', done => {
const gltflayer = new maptalks.GLTFLayer('gltf');
const marker = new maptalks.GLTFGeometry(center, {
symbol: {
scaleX: 50,
scaleY: 50,
scaleZ: 50,
url: url2,
uniforms: {
polygonFill: [1, 1, 1, 1],
polygonOpacity: 1
}
}
}).addTo(gltflayer);
marker.on('load', () => {
marker.setUniform('polygonFill', [1, 0, 0, 1], 1);
setTimeout(function() {
const pixel = pickPixel(map, map.width / 2, map.height / 2, 1, 1);
expect(pixelMatch([168, 3, 3, 255], pixel)).to.be.eql(true);
done();
}, 100);
});
new maptalks.GroupGLLayer('gl', [gltflayer], { sceneConfig }).addTo(map);
});
});