Skip to content

Commit

Permalink
* Added Patterns and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jperedadnr committed Feb 19, 2015
1 parent 6f2f50b commit 6043d6b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 94 deletions.
42 changes: 17 additions & 25 deletions FXyz-Core/src/main/java/org/fxyz/scene/paint/Patterns.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,7 @@ public Patterns(int width, int height) {
}

public Image createPattern(boolean save) {
ImagePattern pattern = createCarbonPattern();
Rectangle rectangle = new Rectangle(width, height);
rectangle.setFill(pattern);
rectangle.setStrokeWidth(0);
imgPattern = rectangle.snapshot(new SnapshotParameters(), null);
if (save) {
saveImage();
}
return imgPattern;
return createPattern(CarbonPatterns.DARK_CARBON, save);
}

public Image createPattern(CarbonPatterns cp, boolean save) {
Expand Down Expand Up @@ -242,8 +234,8 @@ public static final ImagePattern createLightCarbonPattern() {
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
0, 0.5 * HEIGHT + offsetY * HEIGHT,
false, CycleMethod.NO_CYCLE,
new Stop(0, Color.rgb(38, 38, 38)),
new Stop(1, Color.rgb(30, 30, 30))));
new Stop(0, Color.rgb(138, 138, 138)),
new Stop(1, Color.rgb(130, 130, 130))));
CTX.fill();

CTX.beginPath();
Expand All @@ -253,8 +245,8 @@ public static final ImagePattern createLightCarbonPattern() {
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
0, 0.416666 * HEIGHT + offsetY * HEIGHT,
false, CycleMethod.NO_CYCLE,
new Stop(0, Color.rgb(42, 42, 42)),
new Stop(1, Color.rgb(30, 30, 30))));
new Stop(0, Color.rgb(142, 142, 142)),
new Stop(1, Color.rgb(130, 130, 130))));
CTX.fill();

CTX.beginPath();
Expand All @@ -264,8 +256,8 @@ public static final ImagePattern createLightCarbonPattern() {
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
0, 0.5 * HEIGHT + offsetY * HEIGHT,
false, CycleMethod.NO_CYCLE,
new Stop(0, Color.rgb(38, 38, 38)),
new Stop(1, Color.rgb(30, 30, 30))));
new Stop(0, Color.rgb(138, 138, 138)),
new Stop(1, Color.rgb(130, 130, 130))));
CTX.fill();

CTX.beginPath();
Expand All @@ -275,8 +267,8 @@ public static final ImagePattern createLightCarbonPattern() {
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
0, 0.416666 * HEIGHT + offsetY * HEIGHT,
false, CycleMethod.NO_CYCLE,
new Stop(0, Color.rgb(42, 42, 42)),
new Stop(1, Color.rgb(30, 30, 30))));
new Stop(0, Color.rgb(142, 142, 142)),
new Stop(1, Color.rgb(130, 130, 130))));
CTX.fill();

CTX.beginPath();
Expand All @@ -286,8 +278,8 @@ public static final ImagePattern createLightCarbonPattern() {
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
0, 0.5 * HEIGHT + offsetY * HEIGHT,
false, CycleMethod.NO_CYCLE,
new Stop(0, Color.rgb(52, 52, 52)),
new Stop(1, Color.rgb(46, 46, 46))));
new Stop(0, Color.rgb(152, 152, 152)),
new Stop(1, Color.rgb(146, 146, 146))));
CTX.fill();

CTX.beginPath();
Expand All @@ -297,8 +289,8 @@ public static final ImagePattern createLightCarbonPattern() {
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
0, 0.416666 * HEIGHT + offsetY * HEIGHT,
false, CycleMethod.NO_CYCLE,
new Stop(0, Color.rgb(60, 60, 60)),
new Stop(1, Color.rgb(52, 52, 52))));
new Stop(0, Color.rgb(160, 160, 160)),
new Stop(1, Color.rgb(152, 152, 152))));
CTX.fill();

CTX.beginPath();
Expand All @@ -308,8 +300,8 @@ public static final ImagePattern createLightCarbonPattern() {
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
0, 0.5 * HEIGHT + offsetY * HEIGHT,
false, CycleMethod.NO_CYCLE,
new Stop(0, Color.rgb(52, 52, 52)),
new Stop(1, Color.rgb(46, 46, 46))));
new Stop(0, Color.rgb(152, 152, 152)),
new Stop(1, Color.rgb(146, 146, 146))));
CTX.fill();

CTX.beginPath();
Expand All @@ -319,8 +311,8 @@ public static final ImagePattern createLightCarbonPattern() {
CTX.setFill(new LinearGradient(0, offsetY * HEIGHT,
0, 0.416666 * HEIGHT + offsetY * HEIGHT,
false, CycleMethod.NO_CYCLE,
new Stop(0, Color.rgb(60, 60, 60)),
new Stop(1, Color.rgb(52, 52, 52))));
new Stop(0, Color.rgb(160, 160, 160)),
new Stop(1, Color.rgb(152, 152, 152))));
CTX.fill();

final Image PATTERN_IMAGE = CANVAS.snapshot(new SnapshotParameters(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import javafx.scene.shape.DrawMode;
import javafx.scene.shape.TriangleMesh;
import org.fxyz.geometry.Face3;
import org.fxyz.geometry.Point3D;
import org.fxyz.shapes.primitives.helper.CurvedSpringHelper;

/**
Expand Down Expand Up @@ -77,15 +76,15 @@ public CurvedSpringMesh(double majorRadius, double minorRadius, double wireRadiu
}

public CurvedSpringMesh(double majorRadius, double minorRadius, double wireRadius, double pitch, double length,
int rDivs, int tDivs, int lengthCrop, int wireCrop) {
int lengthDivisions, int wireDivisions, int lengthCrop, int wireCrop) {

setMajorRadius(majorRadius);
setMinorRadius(minorRadius);
setWireRadius(wireRadius);
setPitch(pitch);
setLength(length);
setLengthDivisions(rDivs);
setWireDivisions(tDivs);
setLengthDivisions(lengthDivisions);
setWireDivisions(wireDivisions);
setLengthCrop(lengthCrop);
setWireCrop(wireCrop);

Expand Down Expand Up @@ -388,9 +387,7 @@ private TriangleMesh createSpring(float majorRadius, float minorRadius, float wi
listTextures.clear();
listFaces.clear();

int numDivLength = subDivLength + 1-2*cropLength;
int numDivWire = subDivWire + 1-2*cropWire;
float pointX, pointY, pointZ;
double arc=length/pitch;
double a=wireRadius;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ protected final void updateMesh(){
@Override
protected void invalidated() {
if(mesh!=null){
System.out.println("d: "+get());
updateMesh();
//updateVertices(f1.floatValue()/f0.floatValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.fxyz.geometry.Face3;
import org.fxyz.geometry.Point3D;
import org.fxyz.scene.paint.Patterns.CarbonPatterns;
import static org.fxyz.scene.paint.Patterns.CarbonPatterns.DARK_CARBON;
import org.fxyz.shapes.primitives.helper.MeshHelper;
import org.fxyz.shapes.primitives.helper.TriangleMeshHelper;
import static org.fxyz.shapes.primitives.helper.TriangleMeshHelper.DEFAULT_COLORS;
Expand Down Expand Up @@ -85,34 +84,15 @@ public abstract class TexturedMesh extends MeshView {
protected TexturedMesh() {
sectionType.set(SectionType.CIRCLE);
textureType.set(TextureType.NONE);
carbonPatterns.set(CarbonPatterns.DARK_CARBON);
textureType.addListener((ob, o, o1) -> {
if (mesh != null) {
updateTexture();
updateTextureOnFaces();
// updateTexture();
// updateTextureOnFaces();
}
});
}

private final ObjectProperty<CarbonPatterns> carbonPatterns = new SimpleObjectProperty<CarbonPatterns>(DARK_CARBON){
@Override
protected void invalidated() {
if (mesh != null) {
setMaterial(helper.getMaterialWithPattern(get()));
}
}
};
public final CarbonPatterns getCarbonPattern(){
return carbonPatterns.get();
}
public final void setCarbonPattern(CarbonPatterns cp){
carbonPatterns.set(cp);
}

public ObjectProperty<CarbonPatterns> getCarbonPatterns() {
return carbonPatterns;
}


private final ObjectProperty<SectionType> sectionType = new SimpleObjectProperty<SectionType>() {

@Override
Expand All @@ -136,7 +116,16 @@ public ObjectProperty sectionTypeProperty() {
return sectionType;
}

private final ObjectProperty<TextureType> textureType = new SimpleObjectProperty<TextureType>();
private final ObjectProperty<TextureType> textureType = new SimpleObjectProperty<TextureType>(){
@Override
protected void invalidated() {
if(mesh!=null){
// updateMesh();
updateTexture();
updateTextureOnFaces();
}
}
};

public void setTextureModeNone() {
setTextureModeNone(Color.WHITE);
Expand All @@ -158,31 +147,36 @@ public void setTextureModeImage(String image) {
}
}

public void setTextureModePattern(double scale) {
public void setTextureModePattern(CarbonPatterns pattern, double scale) {
helper.setTextureType(TextureType.PATTERN);
carbonPatterns.set(pattern);
setMaterial(helper.getMaterialWithPattern(pattern));
patternScale.set(scale);

setMaterial(helper.getMaterialWithPattern(carbonPatterns.get()));
setTextureType(helper.getTextureType());
}

public void setTextureModeVertices3D(int colors, Function<Point3D, Number> dens) {
helper.setTextureType(TextureType.COLORED_VERTICES_3D);
setColors(colors);
setDensity(dens);
createPalette(getColors());
setDensity(dens);
helper.setDensity(dens);
setTextureType(helper.getTextureType());
}

public void setTextureModeVertices1D(int colors, Function<Number, Number> function) {
helper.setTextureType(TextureType.COLORED_VERTICES_1D);
setColors(colors);
setFunction(function);
createPalette(getColors());
setFunction(function);
helper.setFunction(function);
setTextureType(helper.getTextureType());
}

public void setTextureModeFaces(int colors) {
helper.setTextureType(TextureType.COLORED_FACES);
setColors(colors);
createPalette(getColors());
setTextureType(helper.getTextureType());
}

Expand Down Expand Up @@ -219,6 +213,23 @@ public DoubleProperty patternScaleProperty() {
return patternScale;
}

private final ObjectProperty<CarbonPatterns> carbonPatterns = new SimpleObjectProperty<CarbonPatterns>(CarbonPatterns.DARK_CARBON){
@Override
protected void invalidated() {
setMaterial(helper.getMaterialWithPattern(get()));
}
};
public final CarbonPatterns getCarbonPattern(){
return carbonPatterns.get();
}
public final void setCarbonPattern(CarbonPatterns cp){
carbonPatterns.set(cp);
}

public ObjectProperty<CarbonPatterns> getCarbonPatterns() {
return carbonPatterns;
}

private final ObjectProperty<Color> diffuseColor = new SimpleObjectProperty<Color>(DEFAULT_DIFFUSE_COLOR) {

@Override
Expand All @@ -244,8 +255,8 @@ public ObjectProperty diffuseColorProperty() {
@Override
protected void invalidated() {
createPalette(getColors());
updateTexture();
updateTextureOnFaces();
// updateTexture();
// updateTextureOnFaces();
}
};

Expand Down
Loading

0 comments on commit 6043d6b

Please sign in to comment.