Skip to content

Commit b6c0d64

Browse files
committed
Implement API 1.1.0 and fix flickering with markers when zoomed out
1 parent 341c159 commit b6c0d64

File tree

13 files changed

+97
-29
lines changed

13 files changed

+97
-29
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ bin/
1414
bin/*
1515
*/bin/*
1616

17+
doc/
18+
doc/*
19+
*/doc/*
20+
1721
.classpath
1822
*/.classpath
1923

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/api/marker/ShapeMarkerImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class ShapeMarkerImpl extends MarkerImpl implements ShapeMarker {
4242

4343
private Shape shape;
4444
private float height;
45+
private boolean depthTest;
4546
private Color borderColor, fillColor;
4647

4748
private boolean hasUnsavedChanges;
@@ -82,6 +83,16 @@ public synchronized void setShape(Shape shape, float height) {
8283
this.height = height;
8384
this.hasUnsavedChanges = true;
8485
}
86+
87+
@Override
88+
public boolean isDepthTestEnabled() {
89+
return this.depthTest;
90+
}
91+
92+
@Override
93+
public void setDepthTestEnabled(boolean enabled) {
94+
this.depthTest = enabled;
95+
}
8596

8697
@Override
8798
public Color getBorderColor() {
@@ -118,6 +129,7 @@ public void load(BlueMapAPI api, ConfigurationNode markerNode, boolean overwrite
118129

119130
this.shape = readShape(markerNode.getNode("shape"));
120131
this.height = markerNode.getNode("height").getFloat(64);
132+
this.depthTest = markerNode.getNode("depthTest").getBoolean(true);
121133
this.borderColor = readColor(markerNode.getNode("borderColor"));
122134
this.fillColor = readColor(markerNode.getNode("fillColor"));
123135
}
@@ -128,6 +140,7 @@ public void save(ConfigurationNode markerNode) {
128140

129141
writeShape(markerNode.getNode("shape"), this.shape);
130142
markerNode.getNode("height").setValue(Math.round(height * 1000f) / 1000f);
143+
markerNode.getNode("depthTest").setValue(this.depthTest);
131144
writeColor(markerNode.getNode("borderColor"), this.borderColor);
132145
writeColor(markerNode.getNode("fillColor"), this.fillColor);
133146

BlueMapCore/src/main/webroot/js/libs/BlueMap.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default class BlueMap {
8080
this.skyColor = {
8181
value: new Vector3(0, 0, 0)
8282
};
83-
this.debugInfo = false;
83+
this.debugInfo = this.loadUserSetting("debugInfo", true);
8484

8585
this.fileLoader = new FileLoader();
8686
this.blobLoader = new FileLoader();
@@ -99,6 +99,7 @@ export default class BlueMap {
9999
await this.loadHiresMaterial();
100100
await this.loadLowresMaterial();
101101

102+
this.debugInfo = false;
102103
this.loadUserSettings();
103104
this.handleContainerResize();
104105

@@ -107,7 +108,7 @@ export default class BlueMap {
107108
await this.ui.load();
108109
this.start();
109110
}).catch(error => {
110-
this.onLoadError(error.toString());
111+
this.onLoadError("Initialization: " + error.toString());
111112
});
112113
}
113114

@@ -310,21 +311,25 @@ export default class BlueMap {
310311
async loadSettings() {
311312
return new Promise(resolve => {
312313
this.fileLoader.load(this.dataRoot + 'settings.json', settings => {
313-
this.settings = JSON.parse(settings);
314-
this.maps = [];
315-
for (let map in this.settings.maps) {
316-
if (this.settings["maps"].hasOwnProperty(map) && this.settings.maps[map].enabled){
317-
this.maps.push(map);
314+
try {
315+
this.settings = JSON.parse(settings);
316+
this.maps = [];
317+
for (let map in this.settings.maps) {
318+
if (this.settings["maps"].hasOwnProperty(map) && this.settings.maps[map].enabled) {
319+
this.maps.push(map);
320+
}
318321
}
319-
}
320322

321-
this.maps.sort((map1, map2) => {
322-
var sort = this.settings.maps[map1].ordinal - this.settings.maps[map2].ordinal;
323-
if (isNaN(sort)) return 0;
324-
return sort;
325-
});
323+
this.maps.sort((map1, map2) => {
324+
let sort = this.settings.maps[map1].ordinal - this.settings.maps[map2].ordinal;
325+
if (isNaN(sort)) return 0;
326+
return sort;
327+
});
326328

327-
resolve();
329+
resolve();
330+
} catch (e) {
331+
reject(e);
332+
}
328333
});
329334
});
330335
}
@@ -334,11 +339,10 @@ export default class BlueMap {
334339
this.quality = 1;
335340

336341
this.renderer = new WebGLRenderer({
337-
alpha: true,
338342
antialias: true,
339343
sortObjects: true,
340344
preserveDrawingBuffer: true,
341-
logarithmicDepthBuffer: false,
345+
logarithmicDepthBuffer: true,
342346
});
343347
this.renderer.autoClear = false;
344348

@@ -374,6 +378,7 @@ export default class BlueMap {
374378
this.quality = this.loadUserSetting("renderQuality", this.quality);
375379
this.hiresViewDistance = this.loadUserSetting("hiresViewDistance", this.hiresViewDistance);
376380
this.lowresViewDistance = this.loadUserSetting("lowresViewDistance", this.lowresViewDistance);
381+
this.controls.settings.zoom.max = this.loadUserSetting("maxZoomDistance", this.controls.settings.zoom.max);
377382
this.debugInfo = this.loadUserSetting("debugInfo", this.debugInfo);
378383
}
379384

@@ -387,6 +392,7 @@ export default class BlueMap {
387392
this.saveUserSetting("renderQuality", this.quality);
388393
this.saveUserSetting("hiresViewDistance", this.hiresViewDistance);
389394
this.saveUserSetting("lowresViewDistance", this.lowresViewDistance);
395+
this.saveUserSetting("maxZoomDistance", this.controls.settings.zoom.max);
390396
this.saveUserSetting("debugInfo", this.debugInfo);
391397
}
392398

BlueMapCore/src/main/webroot/js/libs/hud/HudInfo.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ export default class HudInfo {
6666

6767
//check markers first
6868
let intersects = this.raycaster.intersectObjects( this.blueMap.shapeScene.children );
69-
console.log(intersects);
7069
if (intersects.length !== 0){
70+
if (this.blueMap.debugInfo){
71+
console.debug("Tapped position data: ", intersects[0]);
72+
}
73+
7174
try {
7275
intersects[0].object.userData.marker.onClick(intersects[0].point);
7376
} catch (ignore) {}
@@ -163,7 +166,7 @@ export default class HudInfo {
163166
//add block marker
164167
if (hiresData){
165168
this.blockMarker.position.set(block.x, block.y, block.z);
166-
this.blueMap.hiresScene.add(this.blockMarker);
169+
this.blueMap.shapeScene.add(this.blockMarker);
167170
this.blockMarker.needsUpdate = true;
168171
}
169172

@@ -182,7 +185,7 @@ export default class HudInfo {
182185
this.onClose = undefined;
183186
}
184187
});
185-
this.blueMap.hiresScene.remove(this.blockMarker);
188+
this.blueMap.shapeScene.remove(this.blockMarker);
186189
this.blueMap.updateFrame = true;
187190
}
188191
};

BlueMapCore/src/main/webroot/js/libs/hud/MarkerManager.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import MarkerSet from "./MarkerSet";
22
import $ from "jquery";
33
import ToggleButton from "../ui/ToggleButton";
44
import Label from "../ui/Label";
5+
import {cachePreventionNr} from "../utils";
56

67
export default class MarkerManager {
78

@@ -13,18 +14,24 @@ export default class MarkerManager {
1314

1415
this.readyPromise =
1516
this.loadMarkerData()
16-
.catch(ignore => {})
17+
.catch(ignore => {
18+
if (this.blueMap.debugInfo) console.debug("Failed load markers:", ignore);
19+
})
1720
.then(this.loadMarkers);
1821

1922
$(document).on('bluemap-map-change', this.onBlueMapMapChange);
2023
}
2124

2225
loadMarkerData() {
2326
return new Promise((resolve, reject) => {
24-
this.blueMap.fileLoader.load(this.blueMap.dataRoot + 'markers.json',
27+
this.blueMap.fileLoader.load(this.blueMap.dataRoot + 'markers.json?' + cachePreventionNr(),
2528
markerData => {
26-
this.markerData = JSON.parse(markerData);
27-
resolve();
29+
try {
30+
this.markerData = JSON.parse(markerData);
31+
resolve();
32+
} catch (e){
33+
reject(e);
34+
}
2835
},
2936
xhr => {},
3037
error => {

BlueMapCore/src/main/webroot/js/libs/hud/ShapeMarker.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,27 @@ export default class ShapeMarker extends Marker {
2727

2828
this.fillColor = this.prepareColor(markerData.fillColor);
2929
this.borderColor = this.prepareColor(markerData.borderColor);
30+
this.depthTest = !!markerData.depthTest;
3031

3132
//fill
3233
let shape = new Shape(points);
3334
let fillGeo = new ShapeBufferGeometry(shape, 1);
3435
fillGeo.rotateX(Math.PI * 0.5);
35-
fillGeo.translate(0, this.height + 0.0172, 0);
36+
fillGeo.translate(0, this.height + 0.01456, 0);
3637
let fillMaterial = new MeshBasicMaterial({
3738
color: this.fillColor.rgb,
3839
opacity: this.fillColor.a,
3940
transparent: true,
4041
side: DoubleSide,
42+
depthTest: this.depthTest,
4143
});
4244
let fill = new Mesh( fillGeo, fillMaterial );
4345

4446
//border
4547
points.push(points[0]);
4648
let lineGeo = new BufferGeometry().setFromPoints(points);
4749
lineGeo.rotateX(Math.PI * 0.5);
48-
lineGeo.translate(0, this.height + 0.0072, 0);
50+
lineGeo.translate(0, this.height + 0.01456, 0);
4951
let lineMaterial = new LineBasicMaterial({
5052
color: this.borderColor.rgb,
5153
opacity: this.borderColor.a,
@@ -54,8 +56,12 @@ export default class ShapeMarker extends Marker {
5456
});
5557
let line = new Line( lineGeo, lineMaterial );
5658

57-
this.renderObject = fill;
58-
fill.add(line);
59+
if (this.fillColor.a > 0 || this.borderColor.a <= 0) {
60+
this.renderObject = fill;
61+
fill.add(line);
62+
} else {
63+
this.renderObject = line;
64+
}
5965

6066
this.renderObject.userData = {
6167
marker: this,

BlueMapCore/src/main/webroot/js/libs/shaders/HiresFragmentShader.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25+
import { ShaderChunk } from 'three';
2526

2627
const HIRES_FRAGMENT_SHADER = `
28+
${ShaderChunk.logdepthbuf_pars_fragment}
29+
2730
uniform sampler2D texture;
2831
uniform float sunlightStrength;
2932
uniform float ambientLight;
@@ -75,6 +78,8 @@ void main() {
7578
color.rgb *= max(light / 15.0, ambientLight);
7679
7780
gl_FragColor = color;
81+
82+
${ShaderChunk.logdepthbuf_fragment}
7883
}
7984
`;
8085

BlueMapCore/src/main/webroot/js/libs/shaders/HiresVertexShader.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25+
import { ShaderChunk } from 'three';
2526

2627
const HIRES_VERTEX_SHADER = `
28+
${ShaderChunk.logdepthbuf_pars_vertex}
29+
2730
attribute float ao;
2831
attribute float sunlight;
2932
attribute float blocklight;
@@ -51,7 +54,9 @@ void main() {
5154
projectionMatrix *
5255
viewMatrix *
5356
modelMatrix *
54-
vec4(position, 1);
57+
vec4(position, 1);
58+
59+
${ShaderChunk.logdepthbuf_vertex}
5560
}
5661
`;
5762

BlueMapCore/src/main/webroot/js/libs/shaders/LowresFragmentShader.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
* THE SOFTWARE.
2424
*/
25+
import { ShaderChunk } from 'three';
2526

2627
const LOWRES_FRAGMENT_SHADER = `
28+
${ShaderChunk.logdepthbuf_pars_fragment}
29+
2730
uniform float sunlightStrength;
2831
uniform float ambientLight;
2932
@@ -41,6 +44,8 @@ void main() {
4144
color *= max(sunlightStrength, ambientLight);
4245
4346
gl_FragColor = color;
47+
48+
${ShaderChunk.logdepthbuf_fragment}
4449
}
4550
`;
4651

0 commit comments

Comments
 (0)