- setWireFrameMode if you press key 'W' for all layers on map

This commit is contained in:
Arno Kaimbacher 2020-11-17 16:06:09 +01:00
parent b65fae11d3
commit ebc0c20892
3 changed files with 54 additions and 39 deletions

1
.gitignore vendored
View File

@ -30,3 +30,4 @@ desktop.ini
/notes.txt /notes.txt
/.env /.env
debug.log

View File

@ -20,6 +20,7 @@ class DxfLayer extends Layer {
this.visible = true; this.visible = true;
this.opacity = 1; this.opacity = 1;
this.materialParameter = []; this.materialParameter = [];
this.materialsArray = [];
for (var k in params) { for (var k in params) {
this[k] = params[k]; this[k] = params[k];
} }
@ -29,16 +30,23 @@ class DxfLayer extends Layer {
this.borderVisible = false; this.borderVisible = false;
} }
setWireframeMode (wireframe) {
this.materialsArray.forEach(function (mat) {
//if (m.w) return;
//m.mat.wireframe = wireframe;
mat.wireframe = wireframe;
});
}
setVisible(visible) { setVisible(visible) {
this.visible = visible; this.visible = visible;
// this.objectGroup.visible = visible; // this.objectGroup.visible = visible;
//Q3D.application.queryObjNeedsUpdate = true;
} }
async onAdd(map) { async onAdd(map) {
await this.build(this.getScene()); await this.build(this.getScene());
//this.update();
map.update(); map.update();
// this.emit('add');
} }
//build BufferGeometry with Index //build BufferGeometry with Index
@ -46,7 +54,7 @@ class DxfLayer extends Layer {
let geometry = new BufferGeometry(); let geometry = new BufferGeometry();
// let positions = new Float32BufferAttribute(this.vertices, 3); // let positions = new Float32BufferAttribute(this.vertices, 3);
let posArray = await (this.points(134)); let posArray = await (this.points(this.geomId));
console.log(posArray); console.log(posArray);
let positions = new Float32BufferAttribute(posArray, 3); let positions = new Float32BufferAttribute(posArray, 3);
geometry.setAttribute('position', positions); geometry.setAttribute('position', positions);
@ -55,7 +63,7 @@ class DxfLayer extends Layer {
//var indices = this.indices = new TypeArray(this.idx); //var indices = this.indices = new TypeArray(this.idx);
// let indexArray = this.indices = new Uint16Array(this.idx); // let indexArray = this.indices = new Uint16Array(this.idx);
let indexArray = await (this.edges(134)); let indexArray = await (this.edges(this.geomId));
let indices = new Uint16BufferAttribute(indexArray, 1);//.setDynamic(true); let indices = new Uint16BufferAttribute(indexArray, 1);//.setDynamic(true);
geometry.setIndex(indices); geometry.setIndex(indices);
@ -68,6 +76,7 @@ class DxfLayer extends Layer {
this.material = new MeshBasicMaterial({ this.material = new MeshBasicMaterial({
color: color color: color
}); });
this.materialsArray.push(this.material);
let mesh = this.mainMesh = new Mesh(geometry, this.material); let mesh = this.mainMesh = new Mesh(geometry, this.material);
// mesh.userData.layerId = this.index; // mesh.userData.layerId = this.index;
// this.addObject(mesh, true); // this.addObject(mesh, true);
@ -75,7 +84,6 @@ class DxfLayer extends Layer {
if (app_scene) { if (app_scene) {
app_scene.add(mesh); app_scene.add(mesh);
} }
// this.emit('add');
} }

View File

@ -18,7 +18,8 @@ class Application {
constructor(container) { constructor(container) {
this.container = container; this.container = container;
this.running = false; // this is public this.running = false;
this.wireframeMode = false;
this.objects = []; this.objects = [];
@ -100,23 +101,43 @@ class Application {
let dxfLayer = new DxfLayer({ let dxfLayer = new DxfLayer({
geomId: 134, q: true, type: "3dface", name: "Mittelpannon", description: "test" geomId: 134, q: true, type: "3dface", name: "Mittelpannon", description: "test"
}); });
dxfLayer.addListener('add', this.animate, this);
// dxfLayer.addListener('added', function(){
// console.log('added');
// });
// dxfLayer.idx = [0, 1, 2, 3, 4, 5]; // dxfLayer.idx = [0, 1, 2, 3, 4, 5];
// dxfLayer.vertices = new Float32Array([10.421, -20.878, 0.068, 11.241, -20.954, 0.055, 10.225, -20.297, 0.078, 0.161, -6.548, 0.535, -0.163, -6.675, 0.538, 0.116, -6.874, 0.537,]); // dxfLayer.vertices = new Float32Array([10.421, -20.878, 0.068, 11.241, -20.954, 0.055, 10.225, -20.297, 0.078, 0.161, -6.548, 0.535, -0.163, -6.675, 0.538, 0.116, -6.874, 0.537,]);
this.map.addLayer(dxfLayer); this.map.addLayer(dxfLayer);
// domEvent.on(window, 'click', this.onWindowResize, this); // domEvent.on(window, 'click', this.onWindowResize, this);
domEvent.on(window, 'keydown', this.keydown, this);
// util.setLoading("webgl"); // util.setLoading("webgl");
this.start(); this.start();
} }
keydown(e) {
if (e.ctrlKey || e.altKey) return;
let keyPressed = e.which;
if (!e.shiftKey) {
//if (keyPressed == 27) app.closePopup(); // ESC
if (keyPressed === 87) {
this.setWireframeMode(); // W
}
}
}
setWireframeMode() {
let wireframe = !this.wireframeMode;
if (wireframe === this.wireframeMode) return;
for (var key in this.map._layers) {
let layer = this.map._layers[key];
layer.setWireframeMode(wireframe);
}
this.wireframeMode = wireframe;
this.animate();
}
onWindowResize() { onWindowResize() {
if (this._fullWindow) { if (this._fullWindow) {
this._setCanvasSize(window.innerWidth, window.innerHeight); this._setCanvasSize(window.innerWidth, window.innerHeight);
@ -173,23 +194,8 @@ class Application {
} }
animate() { animate() {
if (this.running) {
// requestAnimationFrame(() => {
// this.animate();
// }, 1000 / 30);
// this.objects.forEach((object) => {
// object.update();
// });
}
this.renderer.render(this.scene, this.camera); this.renderer.render(this.scene, this.camera);
} }
// add(layer) {
// this.objects.push(layer);
// this.scene.add(layer.getMesh());
// }
} }
var container = document.getElementById("webgl"); var container = document.getElementById("webgl");