[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Surface.java, 1.197, 1.198
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-10-29 18:09:27
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv22693/src/net/sourceforge/bprocessor/model Modified Files: Surface.java Log Message: First try on smoothnormals calc Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.197 retrieving revision 1.198 diff -C2 -d -r1.197 -r1.198 *** Surface.java 23 Oct 2007 07:20:48 -0000 1.197 --- Surface.java 29 Oct 2007 18:09:30 -0000 1.198 *************** *** 400,410 **** */ public void flip() { ! List lst = new ArrayList(edges.size()); ! Edge[] edges = new Edge[getEdges().size()]; ! getEdges().toArray(edges); ! for (int i = 0; i < edges.length; i++) { ! lst.add(edges[edges.length - i - 1]); } - setEdges(lst); Space holeBack = this.getBackDomain(); Space holeFront = this.getFrontDomain(); --- 400,413 ---- */ public void flip() { ! Collections.reverse(getEdges()); ! if (normals != null) { ! List<Vertex> toReverse = normals.subList(1, normals.size()); ! Collections.reverse(toReverse); ! int index = 1; ! for (Vertex v : toReverse) { ! normals.set(index, v); ! index++; ! } } Space holeBack = this.getBackDomain(); Space holeFront = this.getFrontDomain(); *************** *** 1977,1989 **** /** {@inheritDoc} */ public String getGeneralName() { ! if (getOwner() == Project.getInstance().world()) { ! return "Space Surface"; ! } ! ! if (getOwner().getOwner() == Project.getInstance().world()) { ! return "Element Surface"; ! } else { ! return "Part Surface"; } } --- 1980,2001 ---- /** {@inheritDoc} */ public String getGeneralName() { ! String res = ""; ! switch (getOwner().getLevel() + 1) { ! case Space.PROJECT_LEVEL: ! res = "Project Surface"; ! break; ! case Space.SPACE_LEVEL: ! res = "Space Surface"; ! break; ! case Space.ELEMENT_LEVEL: ! res = "Element Surface"; ! break; ! case Space.PART_LEVEL: ! res = "Part Surface"; ! break; ! default: ! break; } + return res; } *************** *** 2136,2138 **** --- 2148,2175 ---- this.normals = normals; } + + /** + * Calculate smooth normals for a surface + */ + public void calcNormals() { + List<Vertex> vertices = getVertices(); + List<Vertex> normals = new ArrayList<Vertex>(vertices.size()); + Vertex normal, other, addon; + for (Vertex v : vertices) { + double x = 0, y = 0, z = 0; + Set<Edge> edges = v.getEdges(); + for (Edge e : edges) { + other = e.otherVertex(v); + addon = v.minus(other); + addon.normalize(); + x += addon.getX(); + y += addon.getY(); + z += addon.getZ(); + } + normal = new Vertex(x, y, z); + normal.normalize(); + normals.add(normal); + } + this.setNormals(normals); + } } |