下面列出了javafx.scene.AmbientLight#javafx.scene.shape.DrawMode 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public ArbitraryMeshConfig.MeshInfo deserialize(
final JsonElement json,
final Type typeOfT,
final JsonDeserializationContext context) throws JsonParseException {
final JsonObject map = json.getAsJsonObject();
final String path = resolveIfRelative(map.get(PATH_KEY).getAsString(), projectDirectory.get());
final String className = map.get(FORMAT_KEY).getAsString();
try {
final ArbitraryMeshConfig.MeshInfo meshInfo = new ArbitraryMeshConfig.MeshInfo(
Paths.get(path),
((Class<TriangleMeshFormat>)Class.forName(className)).getConstructor().newInstance());
if (map.has(NAME_KEY)) meshInfo.nameProperty().set(map.get(NAME_KEY).getAsString());
if (map.has(IS_VISIBLE_KEY)) meshInfo.isVisibleProperty().set(map.get(IS_VISIBLE_KEY).getAsBoolean());
if (map.has(COLOR_KEY)) meshInfo.colorProperty().set(Color.web(map.get(COLOR_KEY).getAsString()));
if (map.has(SCALE_KEY)) meshInfo.scaleProperty().set(map.get(SCALE_KEY).getAsDouble());
if (map.has(TRANSLATE_X_KEY)) meshInfo.translateXProperty().set(map.get(TRANSLATE_X_KEY).getAsDouble());
if (map.has(TRANSLATE_Y_KEY)) meshInfo.translateYProperty().set(map.get(TRANSLATE_Y_KEY).getAsDouble());
if (map.has(TRANSLATE_Z_KEY)) meshInfo.translateZProperty().set(map.get(TRANSLATE_Z_KEY).getAsDouble());
if (map.has(CULL_FACE_KEY)) meshInfo.cullFaceProperty().set(context.deserialize(map.get(CULL_FACE_KEY), CullFace.class));
if (map.has(DRAW_MODE_KEY)) meshInfo.drawModeProperty().set(context.deserialize(map.get(DRAW_MODE_KEY), DrawMode.class));
return meshInfo;
} catch (Exception e) {
throw new JsonParseException(e);
}
}
public static MeshSettings deserializeInto(
final JsonObject map,
final MeshSettings settings,
final JsonDeserializationContext context) {
Optional.ofNullable(map.get(COARSEST_SCALE_LEVEL_KEY)).map(JsonElement::getAsInt).ifPresent(settings::setCoarsetsScaleLevel);
Optional.ofNullable(map.get(FINEST_SCALE_LEVEL_KEY)).map(JsonElement::getAsInt).ifPresent(settings::setFinestScaleLevel);
Optional.ofNullable(map.get(SIMPLIFICATION_ITERATIONS_KEY)).map(JsonElement::getAsInt).ifPresent(settings::setSimplificationIterations);
Optional.ofNullable(map.get(SMOOTHING_ITERATIONS_KEY)).map(JsonElement::getAsInt).ifPresent(settings::setSmoothingIterations);
Optional.ofNullable(map.get(SMOOTHING_LAMBDA_KEY)).map(JsonElement::getAsDouble).ifPresent(settings::setSmoothingLambda);
Optional.ofNullable(map.get(OPACITY_KEY)).map(JsonElement::getAsDouble).ifPresent(settings::setOpacity);
Optional.ofNullable(map.get(INFLATE_KEY)).map(JsonElement::getAsDouble).ifPresent(settings::setInflate);
Optional.ofNullable(map.get(DRAW_MODE_KEY)).map(el -> (DrawMode) context.deserialize(el, DrawMode.class)).ifPresent(settings::setDrawMode);
Optional.ofNullable(map.get(CULL_FACE_KEY)).map(el -> (CullFace) context.deserialize(el, CullFace.class)).ifPresent(settings::setCullFace);
Optional.ofNullable(map.get(IS_VISIBLE_KEY)).map(JsonElement::getAsBoolean).ifPresent(settings::setVisible);
Optional.ofNullable(map.get(MIN_LABEL_RATIO_KEY)).map(JsonElement::getAsDouble).ifPresent(settings::setMinLabelRatio);
Optional.ofNullable(map.get(LEVEL_OF_DETAIL_KEY)).map(JsonElement::getAsInt).ifPresent(settings::setLevelOfDetail);
return settings;
}
private static MeshView makeMeshView(final PainteraTriangleMesh verticesAndNormals)
{
final float[] vertices = verticesAndNormals.getVertices();
final float[] normals = verticesAndNormals.getNormals();
final TriangleMesh mesh = new TriangleMesh();
mesh.getPoints().addAll(vertices);
mesh.getNormals().addAll(normals);
mesh.getTexCoords().addAll(0, 0);
mesh.setVertexFormat(VertexFormat.POINT_NORMAL_TEXCOORD);
final int[] faceIndices = new int[vertices.length];
for (int i = 0, k = 0; i < faceIndices.length; i += 3, ++k)
{
faceIndices[i + 0] = k;
faceIndices[i + 1] = k;
faceIndices[i + 2] = 0;
}
mesh.getFaces().addAll(faceIndices);
final PhongMaterial material = Meshes.painteraPhongMaterial();
final MeshView mv = new MeshView(mesh);
mv.setOpacity(1.0);
mv.setCullFace(CullFace.FRONT);
mv.setMaterial(material);
mv.setDrawMode(DrawMode.FILL);
return mv;
}
public KnotMesh(double majorRadius, double minorRadius, double wireRadius, double p, double q,
int rDivs, int tDivs, int lengthCrop, int wireCrop) {
setMajorRadius(majorRadius);
setMinorRadius(minorRadius);
setWireRadius(wireRadius);
setP(p);
setQ(q);
setLengthDivisions(rDivs);
setWireDivisions(tDivs);
setLengthCrop(lengthCrop);
setWireCrop(wireCrop);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
public IcosahedronMesh(int level, float diameter){
setLevel(level);
setDiameter(diameter);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
diameterProperty().addListener((obs,f0,f1)->{
if(mesh!=null && f0!=null && f1!=null && f0.floatValue()>0 && f1.floatValue()>0){
updateVertices(f1.floatValue()/f0.floatValue());
}
});
levelProperty().addListener((obs,i0,i1)->{
if(mesh!=null && i1!=null && i1.intValue()>=0){
updateMesh();
}
});
}
public CurvedSpringMesh(double majorRadius, double minorRadius, double wireRadius, double pitch, double length,
int rDivs, int tDivs, int lengthCrop, int wireCrop) {
setMajorRadius(majorRadius);
setMinorRadius(minorRadius);
setWireRadius(wireRadius);
setPitch(pitch);
setLength(length);
setLengthDivisions(rDivs);
setWireDivisions(tDivs);
setLengthCrop(lengthCrop);
setWireCrop(wireCrop);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
public SpringMesh(double meanRadius, double wireRadius, double pitch, double length,
int rDivs, int tDivs, int lengthCrop, int wireCrop) {
setMeanRadius(meanRadius);
setWireRadius(wireRadius);
setPitch(pitch);
setLength(length);
factor=length/pitch;
setLengthDivisions(rDivs);
setWireDivisions(tDivs);
setLengthCrop(lengthCrop);
setWireCrop(wireCrop);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
private Node createBlockShape(final ShapeKey<T> key)
{
final Interval keyInterval = key.interval();
final double[] worldMin = new double[3], worldMax = new double[3];
Arrays.setAll(worldMin, d -> keyInterval.min(d));
Arrays.setAll(worldMax, d -> keyInterval.min(d) + keyInterval.dimension(d));
unshiftedWorldTransforms.apply(key.scaleIndex()).apply(worldMin, worldMin);
unshiftedWorldTransforms.apply(key.scaleIndex()).apply(worldMax, worldMax);
final RealInterval blockWorldInterval = new FinalRealInterval(worldMin, worldMax);
final double[] blockWorldSize = new double[blockWorldInterval.numDimensions()];
Arrays.setAll(blockWorldSize, d -> blockWorldInterval.realMax(d) - blockWorldInterval.realMin(d));
// the standard Box primitive is made up of triangles, so the unwanted diagonals are visible when using DrawMode.Line
// final Box box = new Box(
// blockWorldSize[0],
// blockWorldSize[1],
// blockWorldSize[2]
// );
final PolygonMeshView box = new PolygonMeshView(Meshes.createQuadrilateralMesh(
(float) blockWorldSize[0],
(float) blockWorldSize[1],
(float) blockWorldSize[2]
));
final double[] blockWorldTranslation = new double[blockWorldInterval.numDimensions()];
Arrays.setAll(blockWorldTranslation, d -> blockWorldInterval.realMin(d) + blockWorldSize[d] * 0.5);
box.setTranslateX(blockWorldTranslation[0]);
box.setTranslateY(blockWorldTranslation[1]);
box.setTranslateZ(blockWorldTranslation[2]);
final PhongMaterial material = Meshes.painteraPhongMaterial();
box.setCullFace(CullFace.NONE);
box.setMaterial(material);
box.setDrawMode(DrawMode.LINE);
return box;
}
public SegmentMeshInfoNode(final DataSource<?, ?> source, final SegmentMeshInfo meshInfo)
{
this.source = source;
this.meshInfo = meshInfo;
this.settings = meshInfo.getMeshSettings();
LOG.debug("Initializing MeshinfoNode with draw mode {}", settings.drawModeProperty());
visibleCheckBox = new CheckBox();
levelOfDetailSlider = new NumericSliderWithField(MeshSettings.Defaults.Values.getMinLevelOfDetail(), MeshSettings.Defaults.Values.getMaxLevelOfDetail(), settings.getLevelOfDetail());
coarsestScaleLevelSlider = new NumericSliderWithField(0, settings.getNumScaleLevels() - 1, settings.getCoarsetsScaleLevel());
finestScaleLevelSlider = new NumericSliderWithField(0, settings.getNumScaleLevels() - 1, settings.getFinestScaleLevel());
smoothingLambdaSlider = new NumericSliderWithField(0.0, 1.0, settings.getSmoothingLambda());
smoothingIterationsSlider = new NumericSliderWithField(0, 10, settings.getSmoothingIterations());
minLabelRatioSlider = new NumericSliderWithField(0.0, 1.0, settings.getMinLabelRatio());
this.opacitySlider = new NumericSliderWithField(0, 1.0, settings.getOpacity());
this.inflateSlider = new NumericSliderWithField(0.5, 2.0, settings.getInflate());
this.drawModeChoice = new ComboBox<>(FXCollections.observableArrayList(DrawMode.values()));
this.drawModeChoice.setValue(settings.getDrawMode());
this.cullFaceChoice = new ComboBox<>(FXCollections.observableArrayList(CullFace.values()));
this.cullFaceChoice.setValue(settings.getCullFace());
bindSlidersToSettings();
this.contents = createContents();
}
public CuboidMesh(double width, double height, double depth, int level, Point3D center){
setWidth(width);
setHeight(height);
setDepth(depth);
setLevel(level);
setCenter(center);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
public SurfacePlotMesh(Function<Point2D,Number> function, double rangeX, double rangeY, int divisionsX, int divisionsY, double functionScale) {
setFunction2D(function);
setRangeX(rangeX);
setRangeY(rangeY);
setDivisionsX(divisionsX);
setDivisionsY(divisionsY);
setFunctionScale(functionScale);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
public TriangulatedMesh(List<Point3D> points, List<List<Point3D>> pointsHole, int level, double height, double holeRadius, Bounds bounds) {
this.pointsExterior=points;
this.pointsHoles=pointsHole;
setLevel(level);
setHeight(height);
setHoleRadius(holeRadius);
setBounds(bounds);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
public PrismMesh(double radius, double height, int level, Point3D pIni, Point3D pEnd){
setAxisOrigin(pIni==null?new Point3D(0,(float)height/2f,0):pIni);
setAxisEnd(pEnd==null?new Point3D(0,-(float)height/2f,0):pEnd);
setRadius(radius);
setHeight(getAxisEnd().substract(getAxisOrigin()).magnitude());
setLevel(level);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
public SegmentedTorusMesh(int rDivs, int tDivs, int crop, double majorRadius, double minorRadius) {
setMajorRadiusDivisions(rDivs);
setMinorRadiusDivisions(tDivs);
setMajorRadiusCrop(crop);
setMajorRadius(majorRadius);
setMinorRadius(minorRadius);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
public CSGMesh(CSG primitive){
this.primitive=primitive;
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
public BezierMesh(BezierHelper spline, double wireRadius,
int rDivs, int tDivs, int lengthCrop, int wireCrop) {
setSpline(spline);
setWireRadius(wireRadius);
setLengthDivisions(rDivs);
setWireDivisions(tDivs);
setLengthCrop(lengthCrop);
setWireCrop(wireCrop);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
public SegmentedSphereMesh(int tDivs, int cropX, int cropY, double radius, Point3D center) {
setRadiusDivisions(tDivs);
setRadiusCropX(cropX);
setRadiusCropY(cropY);
setRadius(radius);
setzOffset(1);
setCenter(center);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
public FrustumMesh(double majorRadius, double minorRadius, double height, int level, Point3D pIni, Point3D pEnd){
setAxisOrigin(pIni==null?new Point3D(0,(float)height/2f,0):pIni);
setAxisEnd(pEnd==null?new Point3D(0,-(float)height/2f,0):pEnd);
setMajorRadius(majorRadius);
setMinorRadius(minorRadius);
setLevel(level);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
public TetrahedraMesh(double height, int level, Point3D center){
setHeight(height);
setLevel(level);
setCenter(center);
updateMesh();
setCullFace(CullFace.BACK);
setDrawMode(DrawMode.FILL);
setDepthTest(DepthTest.ENABLE);
}
private void generateShapes() {
for (int i = 0; i < 50; i++) {
Random r = new Random();
//A lot of magic numbers in here that just artificially constrain the math
double randomSmallSize = (double) ((r.nextDouble()*50) + 10);
double randomBigSize = (double) ((r.nextDouble()*100)+ 50);
double randomHeight = (double) ((r.nextDouble()*50)+ 25);
double randomDepth = (double) ((r.nextDouble()*50) + 25);
Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble());
Trapezoid trapezoid = new Trapezoid(randomSmallSize, randomBigSize,
randomHeight, randomDepth, randomColor);
// Trapezoid trapezoid = new Trapezoid(50, 100, 50, 50, randomColor);
trapezoid.setEmissiveLightingColor(randomColor);
trapezoid.setEmissiveLightingOn(r.nextBoolean());
trapezoid.setDrawMode(r.nextBoolean() ? DrawMode.FILL : DrawMode.LINE);
double translationX = Math.random() * 1024;
if (Math.random() >= 0.5) {
translationX *= -1;
}
double translationY = Math.random() * 1024;
if (Math.random() >= 0.5) {
translationY *= -1;
}
double translationZ = Math.random() * 1024;
if (Math.random() >= 0.5) {
translationZ *= -1;
}
Translate translate = new Translate(translationX, translationY, translationZ);
Rotate rotateX = new Rotate(Math.random() * 360, Rotate.X_AXIS);
Rotate rotateY = new Rotate(Math.random() * 360, Rotate.Y_AXIS);
Rotate rotateZ = new Rotate(Math.random() * 360, Rotate.Z_AXIS);
trapezoid.getTransforms().addAll(translate, rotateX, rotateY, rotateZ);
shapeGroup.getChildren().add(trapezoid);
}
}
private void generateShapes() {
for (int i = 0; i < 100; i++) {
Random r = new Random();
//A lot of magic numbers in here that just artificially constrain the math
float randomHypotenuse = (float) ((r.nextFloat()*300) + 25);
float randomHeight = (float) ((r.nextFloat()*200)+ 25);
Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble());
Octahedron octahedron = new Octahedron(randomHypotenuse, randomHeight, randomColor);
octahedron.setEmissiveLightingColor(randomColor);
octahedron.setEmissiveLightingOn(r.nextBoolean());
octahedron.setDrawMode(r.nextBoolean() ? DrawMode.FILL : DrawMode.LINE);
double translationX = Math.random() * 1024;
if (Math.random() >= 0.5) {
translationX *= -1;
}
double translationY = Math.random() * 1024;
if (Math.random() >= 0.5) {
translationY *= -1;
}
double translationZ = Math.random() * 1024;
if (Math.random() >= 0.5) {
translationZ *= -1;
}
Translate translate = new Translate(translationX, translationY, translationZ);
Rotate rotateX = new Rotate(Math.random() * 360, Rotate.X_AXIS);
Rotate rotateY = new Rotate(Math.random() * 360, Rotate.Y_AXIS);
Rotate rotateZ = new Rotate(Math.random() * 360, Rotate.Z_AXIS);
octahedron.getTransforms().addAll(translate, rotateX, rotateY, rotateZ);
shapeGroup.getChildren().add(octahedron);
}
}
public Fx3DRawDataFileDataset(RawDataFile dataFile, float[][] intensityValues, int rtResolution,
int mzResolution, double maxBinnedIntensity, String fileName, Color peakColor) {
super(dataFile, fileName, peakColor);
this.intensityValues = intensityValues;
this.rtResolution = rtResolution;
this.mzResolution = mzResolution;
this.maxBinnedIntensity = maxBinnedIntensity;
mesh = new TriangleMesh();
peakListIndices = new int[rtResolution][mzResolution];
float factorX = (float) SIZE / rtResolution;
float factorZ = (float) SIZE / mzResolution;
for (int i = 0; i < rtResolution; i++) {
for (int j = 0; j < mzResolution; j++) {
if (maxIntensityValue < intensityValues[i][j]) {
maxIntensityValue = intensityValues[i][j];
}
}
}
for (int x = 0; x < rtResolution; x++) {
for (int z = 0; z < mzResolution; z++) {
mesh.getPoints().addAll((float) x * factorX, -intensityValues[x][z] * AMPLIFI,
(float) z * factorZ);
if (intensityValues[x][z] > 0.022 * maxIntensityValue) {
peakListIndices[x][z] = 1;
}
}
}
int rtLength = rtResolution;
int mzLength = mzResolution;
float rtTotal = rtLength;
float mzTotal = mzLength;
for (float x = 0; x < rtLength - 1; x++) {
for (float y = 0; y < mzLength - 1; y++) {
float x0 = x / rtTotal;
float y0 = y / mzTotal;
float x1 = (x + 1) / rtTotal;
float y1 = (y + 1) / mzTotal;
mesh.getTexCoords().addAll( //
x0, y0, // 0, top-left
x0, y1, // 1, bottom-left
x1, y0, // 2, top-right
x1, y1 // 3, bottom-right
);
}
}
// faces
for (int x = 0; x < rtLength - 1; x++) {
for (int z = 0; z < mzLength - 1; z++) {
int tl = x * mzLength + z; // top-left
int bl = x * mzLength + z + 1; // bottom-left
int tr = (x + 1) * mzLength + z; // top-right
int br = (x + 1) * mzLength + z + 1; // bottom-right
int offset = (x * (mzLength - 1) + z) * 8 / 2; // div 2 because
// we have u AND
// v in the list
// working
mesh.getFaces().addAll(bl, offset + 1, tl, offset + 0, tr, offset + 2);
mesh.getFaces().addAll(tr, offset + 2, br, offset + 3, bl, offset + 1);
}
}
setNodeColor(peakColor);
meshView.setMesh(mesh);
meshView.setCullFace(CullFace.NONE);
meshView.setDrawMode(DrawMode.FILL);
meshView.setDepthTest(DepthTest.ENABLE);
logger.finest("Plot mesh is ready.");
}
public static void main(String[] args) throws IOException {
PlatformImpl.startup(() -> {});
final Path path = Paths.get(System.getProperty("user.home"), "Downloads", "catmaid-meshes", "Block3.json");
final TriangleMesh mesh = new CatmaidJsonLoader().loadMesh(path);
final double[] min = {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY};
final double[] max = {Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY};
for (int i = 0; i < mesh.getPoints().size(); i += 3) {
for (int d = 0; d < 3; ++d) {
min[d] = Math.min(min[d], mesh.getPoints().get(i + d));
max[d] = Math.max(max[d], mesh.getPoints().get(i + d));
}
}
System.out.print(Arrays.toString(min) +" " + Arrays.toString(max));
final Interval interval = Intervals.smallestContainingInterval(new FinalRealInterval(min, max));
final MeshView mv = new MeshView(mesh);
mv.setMaterial(Meshes.painteraPhongMaterial(Color.WHITE));
mv.setDrawMode(DrawMode.FILL);
mv.setCullFace(CullFace.BACK);
final Viewer3DFX viewer = new Viewer3DFX(800, 600);
viewer.meshesEnabledProperty().set(true);
mv.setOpacity(1.0);
viewer.setInitialTransformToInterval(interval);
final MeshView mv2 = new MeshView(mesh);
mv.setMaterial(Meshes.painteraPhongMaterial());
mv.setDrawMode(DrawMode.FILL);
mv.setCullFace(CullFace.BACK);
mv2.setTranslateX(100);
viewer.meshesGroup().getChildren().addAll(mv, mv2);
Platform.setImplicitExit(true);
Platform.runLater(() -> {
final Scene scene = new Scene(viewer);
final Stage stage = new Stage();
stage.setScene(scene);
stage.setWidth(800);
stage.setHeight(600);
stage.show();
});
// final String mesh = "<IndexedTriangleSet index='0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35'><Coordinate point='440474 99212 136120 440474 119212 136120 460474 99212 136120 460474 99212 136120 440474 119212 136120 460474 119212 136120 440474 99212 136120 460474 99212 136120 460474 99212 156120 440474 99212 136120 460474 99212 156120 440474 99212 156120 440474 119212 136120 440474 119212 156120 460474 119212 156120 440474 119212 136120 460474 119212 156120 460474 119212 136120 440474 99212 156120 460474 119212 156120 440474 119212 156120 440474 99212 156120 460474 99212 156120 460474 119212 156120 440474 99212 136120 440474 119212 156120 440474 119212 136120 440474 99212 136120 440474 99212 156120 440474 119212 156120 460474 99212 136120 460474 119212 136120 460474 99212 156120 460474 119212 136120 460474 119212 156120 460474 99212 156120'/></IndexedTriangleSet>";
// final Document doc = Jsoup.parse(mesh);
// System.out.println(doc);
// System.out.println(doc.select("IndexedTriangleSet").attr("index"));
}
public static void main(String[] args) throws IOException {
PlatformImpl.startup(() -> {});
// https://people.sc.fsu.edu/~jburkardt/data/obj/obj.html
// final String objFile = "al.obj";
// final String objFile = "diamond.obj";
final String objFile = "alfa147.obj";
final Path path = Paths.get(System.getProperty("user.home"), "Downloads", objFile);
final TriangleMesh mesh = new ObjLoader().loadMesh(path);
final double[] min = {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY};
final double[] max = {Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY};
for (int i = 0; i < mesh.getPoints().size(); i += 3) {
for (int d = 0; d < 3; ++d) {
min[d] = Math.min(min[d], mesh.getPoints().get(i + d));
max[d] = Math.max(max[d], mesh.getPoints().get(i + d));
}
}
final Interval interval = Intervals.smallestContainingInterval(new FinalRealInterval(min, max));
final MeshView mv = new MeshView(mesh);
mv.setMaterial(Meshes.painteraPhongMaterial(Color.WHITE));
mv.setDrawMode(DrawMode.FILL);
mv.setCullFace(CullFace.BACK);
final Viewer3DFX viewer = new Viewer3DFX(800, 600);
viewer.meshesEnabledProperty().set(true);
mv.setOpacity(1.0);
viewer.setInitialTransformToInterval(interval);
final MeshView mv2 = new MeshView(mesh);
mv.setMaterial(Meshes.painteraPhongMaterial());
mv.setDrawMode(DrawMode.FILL);
mv.setCullFace(CullFace.BACK);
mv2.setTranslateX(100);
viewer.meshesGroup().getChildren().addAll(mv, mv2);
// final double factor = 1;
// final double w = 1*factor, h = 2*factor, d = 3*factor;
// final Box box = new Box(w, h, d);
// box.setCullFace(CullFace.NONE);
// box.setOpacity(1.0);
// box.setMaterial(Meshes.painteraPhongMaterial(Color.RED));
// viewer.meshesGroup().getChildren().add(box);
Platform.setImplicitExit(true);
Platform.runLater(() -> {
final Scene scene = new Scene(viewer);
final Stage stage = new Stage();
stage.setScene(scene);
stage.setWidth(800);
stage.setHeight(600);
stage.show();
});
}
private void createQubit() {
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setNearClip(0.1);
camera.setFarClip(10000.0);
camera.getTransforms().addAll(rotateX, rotateY, new Translate(0, 0, -200));
FrustumMesh plane = new FrustumMesh(50, 50, 1, 1, new Point3D(0, -0.5f, 0), new Point3D(0, 0.5f, 0));
plane.setMaterial(new PhongMaterial(Color.web("#ccdd3320")));
SegmentedSphereMesh innerSphere = new SegmentedSphereMesh(40, 0, 0, 50, new Point3D(0, 0, 0));
innerSphere.setMaterial(new PhongMaterial(Color.web("#ff800080")));
SegmentedSphereMesh frameSphere = new SegmentedSphereMesh(20, 0, 0, 50, new Point3D(0, 0, 0));
frameSphere.setMaterial(new PhongMaterial(Color.BLACK));
frameSphere.setDrawMode(DrawMode.LINE);
FrustumMesh rod = new FrustumMesh(2, 2, 1, 1, new Point3D(0, 0, 0), new Point3D(50, 0, 0));
rod.setMaterial(new PhongMaterial(Color.web("#0080ff")));
SegmentedSphereMesh smallSphere = new SegmentedSphereMesh(20, 0, 0, 4, new Point3D(50, 0, 0));
smallSphere.setMaterial(new PhongMaterial(Color.web("#0080ff")));
rodSphere = new Group(smallSphere, rod);
Group group = new Group(plane, rodSphere, innerSphere, frameSphere, new AmbientLight(Color.BISQUE));
SubScene subScene = new SubScene(group, 100, 100, true, SceneAntialiasing.BALANCED);
subScene.setCamera(camera);
subScene.setOnMousePressed(event -> {
mouseOldX = event.getSceneX();
mouseOldY = event.getSceneY();
});
subScene.setOnMouseDragged(event -> {
rotateX.setAngle(rotateX.getAngle() - (event.getSceneY() - mouseOldY));
rotateY.setAngle(rotateY.getAngle() + (event.getSceneX() - mouseOldX));
mouseOldX = event.getSceneX();
mouseOldY = event.getSceneY();
});
getChildren().add(subScene);
rodSphere.getTransforms().setAll(myRotate);
}
public Fx3DRawDataFileDataset(RawDataFile dataFile,
float[][] intensityValues, int rtResolution, int mzResolution,
double maxBinnedIntensity, String fileName, Color peakColor) {
super(dataFile, fileName, peakColor);
this.intensityValues = intensityValues;
this.rtResolution = rtResolution;
this.mzResolution = mzResolution;
this.maxBinnedIntensity = maxBinnedIntensity;
mesh = new TriangleMesh();
peakListIndices = new int[rtResolution][mzResolution];
float factorX = (float) SIZE / rtResolution;
float factorZ = (float) SIZE / mzResolution;
for (int i = 0; i < rtResolution; i++) {
for (int j = 0; j < mzResolution; j++) {
if (maxIntensityValue < intensityValues[i][j]) {
maxIntensityValue = intensityValues[i][j];
}
}
}
for (int x = 0; x < rtResolution; x++) {
for (int z = 0; z < mzResolution; z++) {
mesh.getPoints().addAll((float) x * factorX,
-intensityValues[x][z] * AMPLIFI, (float) z * factorZ);
if (intensityValues[x][z] > 0.022 * maxIntensityValue) {
peakListIndices[x][z] = 1;
}
}
}
int rtLength = rtResolution;
int mzLength = mzResolution;
float rtTotal = rtLength;
float mzTotal = mzLength;
for (float x = 0; x < rtLength - 1; x++) {
for (float y = 0; y < mzLength - 1; y++) {
float x0 = x / rtTotal;
float y0 = y / mzTotal;
float x1 = (x + 1) / rtTotal;
float y1 = (y + 1) / mzTotal;
mesh.getTexCoords().addAll( //
x0, y0, // 0, top-left
x0, y1, // 1, bottom-left
x1, y0, // 2, top-right
x1, y1 // 3, bottom-right
);
}
}
// faces
for (int x = 0; x < rtLength - 1; x++) {
for (int z = 0; z < mzLength - 1; z++) {
int tl = x * mzLength + z; // top-left
int bl = x * mzLength + z + 1; // bottom-left
int tr = (x + 1) * mzLength + z; // top-right
int br = (x + 1) * mzLength + z + 1; // bottom-right
int offset = (x * (mzLength - 1) + z) * 8 / 2; // div 2 because
// we have u AND
// v in the list
// working
mesh.getFaces().addAll(bl, offset + 1, tl, offset + 0, tr,
offset + 2);
mesh.getFaces().addAll(tr, offset + 2, br, offset + 3, bl,
offset + 1);
}
}
setNodeColor(peakColor);
meshView.setMesh(mesh);
meshView.setCullFace(CullFace.NONE);
meshView.setDrawMode(DrawMode.FILL);
meshView.setDepthTest(DepthTest.ENABLE);
LOG.finest("Plot mesh is ready.");
}
public final void setDrawMode(DrawMode value) {
mesh.setDrawMode(value);
}
public final void setDrawMode(DrawMode value) {
mesh.setDrawMode(value);
}
public void setHeightData(float[][] arrayY, int spacing, Color color, boolean ambient, boolean fill) {
material = new PhongMaterial();
material.setSpecularColor(color);
material.setDiffuseColor(color);
mesh = new TriangleMesh();
// Fill Points
for (int x = 0; x < arrayY.length; x++) {
for (int z = 0; z < arrayY[0].length; z++) {
mesh.getPoints().addAll(x * spacing, arrayY[x][z], z * spacing);
}
}
//for now we'll just make an empty texCoordinate group
mesh.getTexCoords().addAll(0, 0);
int total = arrayY.length * arrayY.length;
int nextRow = arrayY.length;
//Add the faces "winding" the points generally counter clock wise
for (int i = 0; i < total - nextRow -1; i++) {
//Top upper left triangle
mesh.getFaces().addAll(i,0,i+nextRow,0,i+1,0);
//Top lower right triangle
mesh.getFaces().addAll(i+nextRow,0,i+nextRow + 1,0,i+1,0);
//Bottom
}
//Create a viewable MeshView to be added to the scene
//To add a TriangleMesh to a 3D scene you need a MeshView container object
meshView = new MeshView(mesh);
//The MeshView allows you to control how the TriangleMesh is rendered
if(fill) {
meshView.setDrawMode(DrawMode.FILL);
} else {
meshView.setDrawMode(DrawMode.LINE); //show lines only by default
}
meshView.setCullFace(CullFace.BACK); //Removing culling to show back lines
getChildren().add(meshView);
meshView.setMaterial(material);
if (ambient) {
selfLight.getScope().add(meshView);
if(!getChildren().contains(selfLight))
getChildren().add(selfLight);
}
else if(getChildren().contains(selfLight))
getChildren().remove(selfLight);
setDepthTest(DepthTest.ENABLE);
}
public PolyLine3D(List<Point3D> points, int width, Color color) {
this.points = points;
this.width = width;
this.color = color;
setDepthTest(DepthTest.ENABLE);
mesh = new TriangleMesh();
//add each point. For each point add another point shifted on Z axis by width
//This extra point allows us to build triangles later
for(Point3D point: points) {
mesh.getPoints().addAll(point.x,point.y,point.z);
mesh.getPoints().addAll(point.x,point.y,point.z+width);
}
//add dummy Texture Coordinate
mesh.getTexCoords().addAll(0,0);
//Now generate trianglestrips for each line segment
for(int i=2;i<points.size()*2;i+=2) { //add each segment
//Vertices wound counter-clockwise which is the default front face of any Triange
//These triangles live on the frontside of the line facing the camera
mesh.getFaces().addAll(i,0,i-2,0,i+1,0); //add primary face
mesh.getFaces().addAll(i+1,0,i-2,0,i-1,0); //add secondary Width face
//Add the same faces but wind them clockwise so that the color looks correct when camera is rotated
//These triangles live on the backside of the line facing away from initial the camera
mesh.getFaces().addAll(i+1,0,i-2,0,i,0); //add primary face
mesh.getFaces().addAll(i-1,0,i-2,0,i+1,0); //add secondary Width face
}
//Need to add the mesh to a MeshView before adding to our 3D scene
meshView = new MeshView(mesh);
meshView.setDrawMode(DrawMode.FILL); //Fill so that the line shows width
material = new PhongMaterial(color);
material.setDiffuseColor(color);
material.setSpecularColor(color);
meshView.setMaterial(material);
//Make sure you Cull the Back so that no black shows through
meshView.setCullFace(CullFace.BACK);
//Add some ambient light so folks can see it
AmbientLight light = new AmbientLight(Color.WHITE);
light.getScope().add(meshView);
getChildren().add(light);
getChildren().add(meshView);
}