Skip to content

Commit

Permalink
Merge pull request Duet3D#383 from Duet3D/feature/heightmap_updates
Browse files Browse the repository at this point in the history
Change initial camera position
  • Loading branch information
chrishamm authored Aug 27, 2021
2 parents d41953f + 06cd39a commit faee442
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 33 deletions.
3 changes: 2 additions & 1 deletion src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,8 @@ export default {
topView: 'Top view',
range : 'Range',
fixed : 'Fixed',
deviation : 'Deviation'
deviation : 'Deviation',
resetView : 'Reset View'
},
objectModelBrowser: {
menuCaption: 'Object Model'
Expand Down
72 changes: 41 additions & 31 deletions src/plugins/HeightMap/3dbjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { PointerEventTypes } from '@babylonjs/core/Events/pointerEvents';
import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';
import { Mesh } from '@babylonjs/core/Meshes/mesh';
import Axes from '../../plugins/GCodeViewer/viewer/axes'
import "@babylonjs/core/Culling"

import i18n from '../../i18n'

Expand Down Expand Up @@ -129,11 +130,11 @@ export default class {
resolve();
});



}

renderScene(){
renderScene() {
this.light1.position = this.scene.cameras[0].position;
this.scene.render();
}
Expand All @@ -156,7 +157,7 @@ export default class {
this.heightPointMeshes.push(sphere);
}

renderHeightMap(bedPoints, invertZ, colorScheme = "terrain", deviationColor = 'fixed') {
renderHeightMap(bedPoints, invertZ, colorScheme = "terrain", deviationColor = 'fixed') {
this.clearHeightMapData();

this.minZ = 999999999;
Expand Down Expand Up @@ -237,12 +238,12 @@ export default class {
var bedSize = this.getSize();
if (this.isDelta) {
this.scene.activeCamera.radius = bedCenter.x;
this.scene.activeCamera.target = new Vector3(bedCenter.x, -2, bedCenter.y);
this.scene.activeCamera.position = new Vector3(-bedSize.x, bedSize.z, -bedSize.x);
this.scene.activeCamera.setTarget(new Vector3(bedCenter.x, -2, bedCenter.y));
this.scene.activeCamera.setPosition(new Vector3(bedCenter.x, this.buildVolume.z.max , this.buildVolume.y.min - bedSize.y / 2));
} else {
this.scene.activeCamera.radius = 250;
this.scene.activeCamera.target = new Vector3(bedCenter.x, -2, bedCenter.y);
this.scene.activeCamera.position = new Vector3(-bedSize.x / 2, bedSize.z, -bedSize.y / 2);
this.scene.activeCamera.setTarget(new Vector3(bedCenter.x, -2, bedCenter.y));
this.scene.activeCamera.setPosition(new Vector3(bedCenter.x, this.buildVolume.z.max , this.buildVolume.y.min - bedSize.y / 2));
}
this.renderScene();
}
Expand All @@ -251,7 +252,7 @@ export default class {
let center = this.getCenter();
let bedSize = this.getSize();
this.scene.activeCamera.setPosition(new Vector3(center.x, bedSize.y * 1.5, center.y));
this.scene.activeCamera.setTarget(new Vector3(0, 0, 0));
this.scene.activeCamera.setTarget(new Vector3(center.x, 0, center.y));
this.scene.activeCamera.alpha = - Math.PI / 2;
this.scene.activeCamera.beta = 0;
this.renderScene();
Expand Down Expand Up @@ -307,26 +308,26 @@ export default class {

this.advancedTexture = AdvancedDynamicTexture.CreateFullscreenUI("UI", true, this.scene);
//build axes labels
this.axesLabelMeshes.forEach(mesh => mesh.dispose());
this.axesLabelMeshes = [];
let xOff = this.buildVolume.x.min %25;
for (let x = this.buildVolume.x.min - xOff; x <= this.buildVolume.x.max; x += this.gridSize) {
let anchor = new Mesh("anchor", this.scene);
anchor.position = new Vector3(x, 0, this.buildVolume.y.min);
this.buildAxesLabel(anchor, `${x}`);
}
this.axesLabelMeshes.forEach(mesh => mesh.dispose());
this.axesLabelMeshes = [];
let xOff = this.buildVolume.x.min % 25;
for (let x = this.buildVolume.x.min - xOff; x <= this.buildVolume.x.max; x += this.gridSize) {
let anchor = new Mesh("anchor", this.scene);
anchor.position = new Vector3(x, 0, this.buildVolume.y.min);
this.buildAxesLabel(anchor, `${x}`);
}

let yOff = this.buildVolume.y.min % 25;
let yOff = this.buildVolume.y.min % 25;

for (let y = this.buildVolume.y.min - yOff; y <= this.buildVolume.y.max; y += this.gridSize) {
let anchor = new Mesh("anchor", this.scene);
anchor.position = new Vector3(this.buildVolume.x.min, 0, y);
this.axesLabelMeshes.push(anchor);
this.buildAxesLabel(anchor, `${y}`);
}
for (let y = this.buildVolume.y.min - yOff; y <= this.buildVolume.y.max; y += this.gridSize) {
let anchor = new Mesh("anchor", this.scene);
anchor.position = new Vector3(this.buildVolume.x.min, 0, y);
this.axesLabelMeshes.push(anchor);
this.buildAxesLabel(anchor, `${y}`);
}
this.bedRendered = true;
this.renderScene();

}

buildAxesLabel(anchor, text) {
Expand All @@ -339,11 +340,20 @@ export default class {


getCenter() {
return {
x: (this.buildVolume.x.max + this.buildVolume.x.min) / 2,
y: (this.buildVolume.y.max + this.buildVolume.y.min) / 2,
z: (this.buildVolume.z.max + this.buildVolume.z.min) / 2,
};
try {
return {
x: (this.buildVolume.x.max + this.buildVolume.x.min) / 2,
y: (this.buildVolume.y.max + this.buildVolume.y.min) / 2,
z: (this.buildVolume.z.max + this.buildVolume.z.min) / 2,
};
}
catch {
return {
x: 0,
y: 0,
z: 0,
}
}
}
getSize() {
return {
Expand Down Expand Up @@ -384,10 +394,10 @@ export default class {
case PointerEventTypes.POINTERPICK:
case PointerEventTypes.POINTERMOVE: {
this.handlePointerMove(pickInfo);
}break;
} break;
case PointerEventTypes.POINTERWHEEL: {
this.renderScene();
}break;
} break;
}
});
}
Expand Down
11 changes: 10 additions & 1 deletion src/plugins/HeightMap/HeightMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ h1 {
<v-icon class="mr-1" small>mdi-format-vertical-align-bottom</v-icon>
{{ $t('plugins.heightmap.topView') }}
</v-btn>
<v-btn :disabled="uiFrozen || loading || !ready" :elevation="1" @click="resetView" class="ml-0 mt-3">
<v-icon class="mr-1" small>mdi-camera</v-icon>
{{ $t('plugins.heightmap.resetView') }}
</v-btn>
</v-card-text>
</v-card>
</v-col>
Expand Down Expand Up @@ -363,7 +367,9 @@ export default {
topView() {
heightMapViewer.topView();
},
resetView(){
heightMapViewer.resetCamera();
},
async refresh() {
if (!this.isConnected) {
this.ready = false;
Expand Down Expand Up @@ -530,6 +536,9 @@ export default {
// Keep track of file changes
this.$root.$on(Events.filesOrDirectoriesChanged, this.filesOrDirectoriesChanged);
//Kill the wheel on the canvas
this.$refs.canvas.addEventListener('wheel', evt => evt.preventDefault());
// Trigger resize event once more to avoid rendering glitches
setTimeout(this.resize.bind(this), 250);
this.ready = true;
Expand Down

0 comments on commit faee442

Please sign in to comment.