public GWTDragObjectControler(Scene scene, Projector projector) { this.projector = projector; // maybe should black&transparent like js-sample mouseCatchPlane = THREE.Mesh( THREE.PlaneGeometry(2000, 2000, 10, 10), THREE.MeshBasicMaterial().color(0x00ffff).wireFrame().build()); mouseCatchPlane.setVisible(false); scene.add(mouseCatchPlane); }
@Override public void start( final WebGLRenderer renderer, final int width, final int height, FocusPanel panel) { if (timer != null) { timer.cancel(); timer = null; } renderer.setClearColorHex(0xcccccc, 1); final Map<Integer, Mesh> meshs = new HashMap<Integer, Mesh>(); final Camera camera = THREE.PerspectiveCamera(35, (double) width / height, .1, 10000); camera.getPosition().set(0, 0, 50); camera.getRotation().set(0, 0, 0); final Scene scene = THREE.Scene(); final Material material = THREE.MeshLambertMaterial().color(0xff00ff).build(); final Mesh mesh = THREE.Mesh(THREE.CylinderGeometry(5, 5, 5, 6), material); scene.add(mesh); final Mesh mesh2 = THREE.Mesh( THREE.CylinderGeometry(5, 5, 5, 15), THREE.MeshLambertMaterial().color(0x00ff00).build()); mesh2.setPosition(0, 10, 0); scene.add(mesh2); final Mesh mesh3 = THREE.Mesh( THREE.CylinderGeometry(5, 1, 5, 15), THREE.MeshLambertMaterial().color(0x0000ff).build()); mesh3.setPosition(0, -10, 0); scene.add(mesh3); final Mesh mesh4 = THREE.Mesh( THREE.CylinderGeometry(5, 4.5, 5, 5), THREE.MeshLambertMaterial().color(0xffff00).build()); mesh4.setPosition(-10, 0, 0); scene.add(mesh4); final Light light = THREE.PointLight(0xffffff); light.setPosition(10, 0, 10); scene.add(light); meshs.put(mesh.getId(), mesh); meshs.put(mesh2.getId(), mesh2); meshs.put(mesh3.getId(), mesh3); meshs.put(mesh4.getId(), mesh4); MainWidget.cameraMove.setX(0); MainWidget.cameraMove.setY(0); MainWidget.cameraMove.setZ(50); timer = new Timer() { public void run() { mesh.getRotation().incrementX(0.02); mesh.getRotation().incrementY(0.02); renderer.render(scene, camera); camera.setPosition( MainWidget.cameraMove.getX(), MainWidget.cameraMove.getY(), MainWidget.cameraMove.getZ()); } }; timer.scheduleRepeating(1000 / 60); final Projector projector = THREE.Projector(); panel.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { JsArray<Intersect> intersects = projector.gwtPickIntersects( event.getX(), event.getY(), width, height, camera, scene); if (intersects.length() > 0) {} for (int i = 0; i < intersects.length(); i++) { Intersect sect = intersects.get(i); final Mesh target = meshs.get(sect.getObject().getId()); log(target); final int old = target.getMaterial().getColor().getHex(); target.getMaterial().getColor().setHex(0xeeeeee); Timer timer = new Timer() { @Override public void run() { target.getMaterial().getColor().setHex(old); } }; timer.schedule(1000); } } }); }