Javascript oop instances -
i developing javascript oop , observer pattern. in first method model g put inside mesh , mesh inside scene. can find our g model in scene.children. in second method in intersected[i].object can find our model g. problem if modify property of intersected[i].object not reflected model g.
g = new geometrymodel(); tjsv = new threejsview(document.getelementbyid('maincanvas'), g); geometrymodel.prototype.populatescene = function(scene) { var i; (i = 0; < this.geometries.length; i++) { var g = this.geometries[i];//<----- g 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(); ( var = 0; < intersected.length; i++ ) { if (intersected[i].object instanceof three.mesh){ intersected[i].object.selected = true;// modify model changed = true; console.log( intersected[i].object); } } console.log(this.model);//my model here there no modify! if (changed) this.model.notifylisteners(); }
i think g referring geometry while intersected[i].object referring object3d - different objects.
you need write this: intersected[i].object.geometry.selected = true;
Comments
Post a Comment