Skip to content

Commit

Permalink
Path3D: Fixed bug where clone() didn't replace Path3Ds
Browse files Browse the repository at this point in the history
Renderer2D: Fixed bug where normal math modifed Path3D.Normal
  • Loading branch information
reportmill committed Jun 26, 2021
1 parent db25e4e commit 303ae3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/snap/gfx3d/CameraView.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public Rect getBoundsMarked()
protected void cameraChanged(PropChange aPC)
{
//_pcs.fireDeepChange(this, aPC);
relayout();
//relayout();
repaint();
}

Expand Down
13 changes: 9 additions & 4 deletions src/snap/gfx3d/Path3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class Path3D extends Shape3D implements Cloneable {
// The cached path (2d)
private Path _path;

// Cached array of this Path3D to efficiently satisfy getPath3Ds() method
private Path3D[] _path3Ds = { this };

// The Triangle path
private Path3D[] _trianglePaths;

Expand Down Expand Up @@ -600,6 +603,9 @@ public Path3D clone()
try { clone = (Path3D) super.clone(); }
catch(Exception e) { throw new RuntimeException(e); }

// Reset _path3ds
clone._path3Ds = new Path3D[] { clone };

// Copy elements
clone._elements = new ArrayList<>(_elements);
clone._points = new ArrayList<>(_points.size());
Expand All @@ -610,16 +616,15 @@ public Path3D clone()
for (Path3D path3D : _layers)
clone._layers.add(path3D.clone());
}

// Return clone
return clone;
}

/**
* Returns the array of Path3D that can render this shape.
*/
public Path3D[] getPath3Ds() { return _path3ds; }

// Cached array of this Path3D to efficiently satisfy super method
private Path3D[] _path3ds = { this };
public Path3D[] getPath3Ds() { return _path3Ds; }

/**
* Standard toString implementation.
Expand Down
2 changes: 1 addition & 1 deletion src/snap/gfx3d/Renderer2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected void addPathsForShape(Shape3D aShape)

// Get normal
Vector3D pathNormal = path3d.getNormal();
Vector3D camPathNormal = worldToCameraXfm.transform(pathNormal);
Vector3D camPathNormal = worldToCameraXfm.transform(pathNormal.clone());
camPathNormal.normalize();

// Backface culling : Only add paths that face the camera
Expand Down

0 comments on commit 303ae3e

Please sign in to comment.