[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool ControlledExtrudeTool.java, 1.1, 1.2
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-09-22 13:55:23
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7257/src/net/sourceforge/bprocessor/gl/tool Modified Files: ControlledExtrudeTool.java Log Message: Continued implementation on controlled extrude Index: ControlledExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ControlledExtrudeTool.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ControlledExtrudeTool.java 7 Sep 2007 13:21:10 -0000 1.1 --- ControlledExtrudeTool.java 22 Sep 2007 13:55:25 -0000 1.2 *************** *** 16,23 **** --- 16,28 ---- import net.sourceforge.bprocessor.gl.GLView; + import net.sourceforge.bprocessor.gl.model.Intersection; + import net.sourceforge.bprocessor.gl.view.Transformation; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.model.Direction; + import net.sourceforge.bprocessor.model.Edge; + import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Selection; + import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; *************** *** 37,40 **** --- 42,46 ---- private HashSet<Surface> extrusion; private Map<Vertex, Direction> v2dir; + private Surface pressedSurface; /** *************** *** 52,56 **** @Override public void onVertex() { ! //TODO finish the extrusion } --- 58,67 ---- @Override public void onVertex() { ! if (pressedSurface != null) { ! Vertex normal = pressedSurface.normal(); ! Plane p = new Plane(normal.getX(), normal.getY(), normal.getZ(), current.vertex()); ! extrudeTo(p); ! finishTool(); ! } } *************** *** 58,89 **** @Override protected void moved(MouseEvent e) { ! if (extrusion.isEmpty()) { ! findTarget(e, View.HANDLES); glv.getView().makeTarget(target); } else { ! current = findIntersection(e); ! makeTarget(current); } } /** {@inheritDoc} */ @Override protected void pressed(MouseEvent e) { ! if (target != null && target instanceof Surface) { ! Surface workingSurface = (Surface)target; ! Surface top = workingSurface.extrusionControlled(1, extrusion, v2dir); ! if (top != null) { ! extrusion.add(top); ! } ! log.debug(extrusion.size()); ! ExtrusionTool.insert(Project.getInstance().getActiveSpace(), extrusion); } } /** {@inheritDoc} */ @Override public void prepare() { super.prepare(); ! Selection.primary().clear(); } --- 69,171 ---- @Override protected void moved(MouseEvent e) { ! findTarget(e, View.HANDLES); ! if (pressedSurface == null) { glv.getView().makeTarget(target); } else { ! double x = e.getX(); ! double y = View.getHeight() - e.getY(); ! ! Vertex near = new Vertex(x, y, 0.0); ! Vertex far = new Vertex(x, y, 1.0); ! Edge ray = new Edge(near, far); ! Transformation transformation = glv.getView().transformation(); ! ray = transformation.unProject(ray); ! Vertex hit = lockingPlane.intersection(ray); ! Vertex normal = pressedSurface.normal(); ! current = new Intersection(hit.minus(start.vertex()).projectOnto(normal).add(start.vertex()), ! Intersection.PLANE_INTERSECTION, lockingPlane); ! Plane p = new Plane(normal.getX(), normal.getY(), normal.getZ(), current.vertex()); ! if (v2dir.isEmpty()) { ! Vertex delta = current.vertex().minus(start.vertex()); ! double length = delta.length(); ! if (delta.angle(normal) > Math.PI / 2) { ! length *= -1; ! } ! Surface topSurface = pressedSurface.extrusionControlled(length, extrusion, v2dir); ! log.info("Elements in extrusion " + extrusion.size()); ! if (topSurface != pressedSurface) { ! extrusion.add(topSurface); ! } ! excluded(extrusion); ! excluded.add(pressedSurface); ! pressedSurface.getOwner().addProtected(extrusion); ! feedback(extrusion); ! ! } ! extrudeTo(p); } } + private void extrudeTo(Plane p) { + for (Vertex v : v2dir.keySet()) { + Direction d = v2dir.get(v); + Vertex intersection = p.intersection(d.getVertex(), d.getDirection(), true); + d.getVertex().set(intersection); + } + updateLength(); + } + /** {@inheritDoc} */ @Override protected void pressed(MouseEvent e) { ! current = findIntersection(e); ! if (v2dir.isEmpty() && target != null && target instanceof Surface) { ! start = current; ! pressedSurface = (Surface)target; ! lock = true; ! Transformation transformation = glv.getView().transformation(); ! double x = e.getX(); ! double y = View.getHeight() - e.getY(); ! ! Vertex near = new Vertex(x, y, 0.0); ! Vertex far = new Vertex(x, y, 1.0); ! Edge ray = new Edge(near, far); ! ray = transformation.unProject(ray); ! Vertex dir = ray.getDirection(); ! dir.normalize(); ! Vertex normal = pressedSurface.normal(); ! Vertex tmp = dir.cross(normal); ! dir = tmp.cross(normal); ! lockingPlane = new Plane(dir.getX(), dir.getY(), dir.getZ(), ! pressedSurface.intersection(ray)); ! } else { ! finishTool(); } } + private void finishTool() { + Space owner = pressedSurface.getOwner(); + owner.removeProtected(extrusion); + ExtrusionTool.insert(owner, extrusion); + Project.getInstance().checkpoint(); + cleanUp(); + } + /** {@inheritDoc} */ @Override public void prepare() { super.prepare(); ! if (!getSelection().isEmpty()) { ! Selection.primary().clear(); ! } ! } ! ! /** {@inheritDoc} */ ! @Override ! public void escape() { ! Vertex n = pressedSurface.normal(); ! extrudeTo(new Plane(n.getX(), n.getY(), n.getZ(), start.vertex())); ! pressedSurface.getOwner().removeProtected(extrusion); ! cleanUp(); } *************** *** 94,97 **** --- 176,180 ---- extrusion.clear(); v2dir.clear(); + pressedSurface = null; } |