Currently working on a project using JavaScript OOP and Observer pattern. In the initial method, the model g is inserted into the mesh, which is then placed inside the scene. This allows us to locate our model g within scene.children. However, in the second method, although we can find our model g in intersected[i].object, any modifications made to intersected[i].object do not reflect back to the model g.
g = new GeometryModel();
tjsv = new ThreeJSView(document.getElementById('maincanvas'), g);
GeometryModel.prototype.populateScene = function(scene) {
var i;
for (i = 0; i < this.geometries.length; i++) {
var g = this.geometries[i];//<----- g is the model
var material = new THREE.MeshBasicMaterial( { color: g.color, transparent: g.transparent, opacity: g.opacity });
var mesh = new THREE.Mesh(g, material);
this.addLabels(g, mesh);
scene.add(mesh);
if (g.lineWidth > 0) {
var egh = new THREE.EdgesHelper( mesh, g.lineColor );
egh.material.linewidth = g.lineWidth;
scene.add( egh );
}
}
}
ThreeJSView.prototype.selectByRaycaster = function(x, y){
var i;
var intersected;
var mouse = {x: (x / this.width) * 2 - 1, y: 1 - (y / this.height) * 2};
var raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouse, this.camera);
intersected = raycaster.intersectObjects(this.scene.children);
console.log();
for ( var i = 0; i < intersected.length; i++ ) {
if (intersected[i].object instanceof THREE.Mesh){
intersected[i].object.selected = true;// I modify my model
changed = true;
console.log( intersected[i].object);
}
}
console.log(this.model);//my model but here there are no modify!
if (changed)
this.model.notifyListeners();
}