Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added short strut mechanism #931

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ protected void resetStrutAttributes( Strut strut )
AlgebraicNumber len = axis .getLength( offset );

Polyhedron prototypeLengthShape = shapes .getStrutShape( orbit, len );
if ( prototypeLengthShape == null )
return; // This happens for very short struts, when the shape would be inside-out
this .mShape = prototypeLengthShape;

int orn = axis .getOrientation();
Expand Down
25 changes: 19 additions & 6 deletions core/src/main/java/com/vzome/core/viewing/ExportedVEFShapes.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.vzome.core.math.symmetry.Axis;
import com.vzome.core.math.symmetry.Direction;
import com.vzome.core.math.symmetry.Symmetry;
import com.vzome.core.parts.FastDefaultStrutGeometry;
import com.vzome.core.parts.StrutGeometry;
import com.vzome.core.render.Colors;
import com.vzome.xml.ResourceLoader;
Expand Down Expand Up @@ -121,14 +122,26 @@ protected Polyhedron buildConnectorShape(String pkgName) {
}

@Override
protected StrutGeometry createStrutGeometry(Direction dir) {
protected StrutGeometry createStrutGeometry(Direction dir)
{
// automatic struts don't use VEF so don't waste time trying
if (!dir.isAutomatic()) {
String vefData = loadVefData(dir.getName());
if ( ! dir.isAutomatic() ) {

StrutGeometry shortGeometry = new FastDefaultStrutGeometry( dir );
String vefData = loadVefData( dir.getName() + "-short" );
if (vefData != null) {
VefToShape parser = new VefToShape();
parser .parseVEF( vefData, mSymmetry.getField() );
shortGeometry = parser .getStrutGeometry( dir.getAxis( Symmetry.PLUS, 0 ) .normal());
}

vefData = loadVefData( dir.getName( ));
if (vefData != null) {
VefToShape parser = new VefToShape();
parser.parseVEF(vefData, mSymmetry.getField());
return parser.getStrutGeometry(dir.getAxis(Symmetry.PLUS, 0).normal());
parser .parseVEF( vefData, mSymmetry.getField() );
ExportedVEFStrutGeometry geometry = parser .getStrutGeometry( dir.getAxis( Symmetry.PLUS, 0 ) .normal());
geometry .setShortGeometry( shortGeometry );
return geometry;
}
// strut uses finer logging level than connector since strut fallback is more common.
final Level logLevel = Level.FINER;
Expand Down Expand Up @@ -204,7 +217,7 @@ private class VefToShape extends VefParser

private boolean invertSnubBall = false;

public StrutGeometry getStrutGeometry( AlgebraicVector prototype )
public ExportedVEFStrutGeometry getStrutGeometry( AlgebraicVector prototype )
{
// next, get the arbitrary axis that the strut model lies along
Axis tipAxis = mSymmetry .getAxis( tipVertex );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class ExportedVEFStrutGeometry implements StrutGeometry

public final Set<Integer> fullScaleVertices, halfScaleVertices; // the polyhedron vertices that must adjust for different strut lengths

private StrutGeometry shortGeometry = null;

public ExportedVEFStrutGeometry( List<AlgebraicVector> vertices, List< List<Integer> > faces, AlgebraicVector prototype, Set<Integer> fullScaleVertices, Set<Integer> halfScaleVertices, AlgebraicField field )
{
prototypeVertices = vertices;
Expand All @@ -54,6 +56,10 @@ public List<Face.Triangle> getTriangles()
public Polyhedron getStrutPolyhedron( AlgebraicNumber length )
{
AlgebraicVector tipVertex = prototypeVector .scale( length );

double maxNonTipDistance = 0;
double minTipDistance = tipVertex .toRealVector() .length();

AlgebraicVector midpoint = tipVertex .scale( this .field .createRational( 1, 2 ) );
if ( field .getName() .equals( "snubDodec" ) && LOGGER.isLoggable(Level.FINE) )
{
Expand All @@ -67,16 +73,35 @@ public Polyhedron getStrutPolyhedron( AlgebraicNumber length )
AlgebraicVector vertex = prototypeVertices .get( i );
if ( fullScaleVertices .contains(i) ) {
vertex = vertex .plus( tipVertex );
} else if ( halfScaleVertices != null && halfScaleVertices .contains(i) ) {
vertex = vertex .plus( midpoint );
minTipDistance = Math.min( minTipDistance, vertex .toRealVector() .length() );
} else {
if ( halfScaleVertices != null && halfScaleVertices .contains(i) ) {
vertex = vertex .plus( midpoint );
}
maxNonTipDistance = Math.max( maxNonTipDistance, vertex .toRealVector() .length() );
}
result .addVertex( vertex );
}

if ( maxNonTipDistance > minTipDistance ) {
// The strut shape will be partially inverted, so we don't want to use it.
if ( shortGeometry != null ) {
return shortGeometry .getStrutPolyhedron( length );
}
else
return null;
}

for (List<Integer> prototypeFace : prototypeFaces) {
Polyhedron.Face face = result .newFace();
face .addAll( prototypeFace );
result .addFace( face );
}
return result;
}

public void setShortGeometry( StrutGeometry shortGeometry )
{
this.shortGeometry = shortGeometry;
}
}
Loading
Loading