Thread: [Bprocessor-commit] /gl/src/net/sourceforge/bprocessor/gl/tool ControlledExtrudeTool.java, 1.2, 1.3
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-09-27 10:49:15
|
Update of /cvsroot/bprocessor//gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14698/src/net/sourceforge/bprocessor/gl/tool Modified Files: ControlledExtrudeTool.java Log Message: Improvements on ControlledExtrude Index: ControlledExtrudeTool.java =================================================================== RCS file: /cvsroot/bprocessor//gl/src/net/sourceforge/bprocessor/gl/tool/ControlledExtrudeTool.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ControlledExtrudeTool.java 22 Sep 2007 13:55:25 -0000 1.2 --- ControlledExtrudeTool.java 27 Sep 2007 10:49:17 -0000 1.3 *************** *** 9,12 **** --- 9,14 ---- import java.awt.Cursor; import java.awt.event.MouseEvent; + import java.util.ArrayList; + import java.util.Collection; import java.util.HashMap; import java.util.HashSet; *************** *** 21,24 **** --- 23,27 ---- import net.sourceforge.bprocessor.model.Direction; import net.sourceforge.bprocessor.model.Edge; + import net.sourceforge.bprocessor.model.Mesh; import net.sourceforge.bprocessor.model.Plane; import net.sourceforge.bprocessor.model.Project; *************** *** 43,46 **** --- 46,54 ---- private Map<Vertex, Direction> v2dir; private Surface pressedSurface; + private Plane dragPlane; + private Collection<Surface> affected; + private Vertex normal; + private double maxExtrude; + private double minExtrude; /** *************** *** 52,55 **** --- 60,64 ---- super(glv, cursor); extrusion = new HashSet<Surface>(); + affected = new HashSet<Surface>(); v2dir = new HashMap<Vertex, Direction>(); } *************** *** 59,63 **** public void onVertex() { if (pressedSurface != null) { - Vertex normal = pressedSurface.normal(); Plane p = new Plane(normal.getX(), normal.getY(), normal.getZ(), current.vertex()); extrudeTo(p); --- 68,71 ---- *************** *** 71,75 **** findTarget(e, View.HANDLES); if (pressedSurface == null) { ! glv.getView().makeTarget(target); } else { double x = e.getX(); --- 79,85 ---- findTarget(e, View.HANDLES); if (pressedSurface == null) { ! if (target instanceof Surface) { ! glv.getView().makeTarget(target); ! } } else { double x = e.getX(); *************** *** 81,90 **** 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(); --- 91,111 ---- Transformation transformation = glv.getView().transformation(); ray = transformation.unProject(ray); ! Vertex hit = dragPlane.intersection(ray); current = new Intersection(hit.minus(start.vertex()).projectOnto(normal).add(start.vertex()), ! Intersection.PLANE_INTERSECTION, dragPlane); ! //Find the plane to extrude to ! Plane p = null; ! if (target instanceof Surface && !affected.contains(target)) { ! p = ((Surface)target).plane(); ! if (Math.abs((Math.abs(p.normal().angle(normal)) - Math.PI / 2)) < 0.01) { ! p = null; ! } ! } ! if (p == null) { ! p = new Plane(normal.getX(), normal.getY(), normal.getZ(), current.vertex()); ! } ! if (v2dir.isEmpty()) { + // If the extrusion isn't started start it Vertex delta = current.vertex().minus(start.vertex()); double length = delta.length(); *************** *** 92,111 **** 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); --- 113,158 ---- length *= -1; } + + Collection feed = new ArrayList(); + feed.add(new Edge(start.vertex(), start.vertex().add(normal))); + feedback(feed); + Surface topSurface = pressedSurface.extrusionControlled(length, extrusion, v2dir); if (topSurface != pressedSurface) { extrusion.add(topSurface); } ! affected.add(pressedSurface); ! affected.addAll(extrusion); ! affected.addAll(Edge.surfaces(topSurface.getEdges())); ! excluded(affected); ! Project.getInstance().getActiveSpace().addProtected(extrusion); ! maxExtrude = Double.POSITIVE_INFINITY; ! minExtrude = Double.NEGATIVE_INFINITY; ! for (Vertex v : v2dir.keySet()) { ! Direction d = v2dir.get(v); ! if (d.upper() < maxExtrude) { ! maxExtrude = d.upper(); ! } ! if (d.lower() > minExtrude) { ! minExtrude = d.lower(); ! } ! } ! } else { ! //there is a extrusion move it to the apropiate location ! extrudeTo(p); } } } private void extrudeTo(Plane p) { + double dist = p.distance(start.vertex()) * -1; + if (dist < minExtrude) { + p.moveDelta(dist - minExtrude); + } + if (dist > maxExtrude) { + p.moveDelta(dist - maxExtrude); + } + current.vertex().set(p.intersection(start.vertex(), normal, true)); + for (Vertex v : v2dir.keySet()) { Direction d = v2dir.get(v); *************** *** 121,127 **** 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(); --- 168,174 ---- current = findIntersection(e); if (v2dir.isEmpty() && target != null && target instanceof Surface) { + active = true; start = current; pressedSurface = (Surface)target; Transformation transformation = glv.getView().transformation(); double x = e.getX(); *************** *** 134,141 **** 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 { --- 181,188 ---- Vertex dir = ray.getDirection(); dir.normalize(); ! normal = pressedSurface.normal(); Vertex tmp = dir.cross(normal); dir = tmp.cross(normal); ! dragPlane = new Plane(dir.getX(), dir.getY(), dir.getZ(), pressedSurface.intersection(ray)); } else { *************** *** 145,152 **** private void finishTool() { ! Space owner = pressedSurface.getOwner(); owner.removeProtected(extrusion); ! ExtrusionTool.insert(owner, extrusion); ! Project.getInstance().checkpoint(); cleanUp(); } --- 192,204 ---- private void finishTool() { ! Space owner = Project.getInstance().getActiveSpace(); owner.removeProtected(extrusion); ! if (pressedSurface != null && !start.vertex().minus(current.vertex()).isZero()) { ! excluded(new ArrayList()); ! Mesh m = new Mesh(extrusion); ! owner.insert(m); ! owner.changed(); ! Project.getInstance().checkpoint(); ! } cleanUp(); } *************** *** 164,170 **** @Override public void escape() { ! Vertex n = pressedSurface.normal(); ! extrudeTo(new Plane(n.getX(), n.getY(), n.getZ(), start.vertex())); ! pressedSurface.getOwner().removeProtected(extrusion); cleanUp(); } --- 216,223 ---- @Override public void escape() { ! if (pressedSurface != null) { ! extrudeTo(new Plane(normal.getX(), normal.getY(), normal.getZ(), start.vertex())); ! Project.getInstance().getActiveSpace().removeProtected(extrusion); ! } cleanUp(); } *************** *** 175,180 **** --- 228,238 ---- super.cleanUp(); extrusion.clear(); + affected.clear(); v2dir.clear(); pressedSurface = null; + normal = null; + active = false; + maxExtrude = Double.POSITIVE_INFINITY; + minExtrude = Double.NEGATIVE_INFINITY; } |