Java examples for javafx.scene.shape:MeshView
Converts the specified mesh to a JavaFX MeshView node that can be added to the scene graph.
/*// w ww . j av a2 s . c o m * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import javafx.event.EventHandler; import javafx.event.EventType; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.TriangleMesh; import javafx.scene.shape.MeshView; import javafx.scene.paint.PhongMaterial; import javafx.scene.shape.DrawMode; import javafx.scene.shape.CullFace; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; import javafx.scene.transform.Rotate; public class Main{ /** * * @param prev previous container (will be reused if possible) * @param mesh mesh * @return container that contains the visualization of the specified mesh */ public static GeometryContainer meshToNode(GeometryContainer prev, TriangleMesh mesh) { return meshToNode(prev, mesh, Color.ORANGE, Color.AQUA); } /** * Converts the specified mesh to a MeshView node that can be added to the * scene graph. * * @param prev previous container (will be reused if possible) * @param mesh mesh * @param diffuse diffuse color * @param specular specular color * @return container that contains the visualization of the specified mesh */ public static GeometryContainer meshToNode(GeometryContainer prev, TriangleMesh mesh, Color diffuse, Color specular) { // material that shall be used to visualize the mesh PhongMaterial material = new PhongMaterial(); // setup material material.setDiffuseColor(diffuse); material.setSpecularColor(specular); MeshView meshView; // reuse mesh view from prev container if avalable if (prev != null && prev.getView() != null) { meshView = prev.getView(); meshView.setMesh(mesh); } else { meshView = new MeshView(mesh); } // setup material & draw mode meshView.setMaterial(material); meshView.setDrawMode(DrawMode.FILL); // fill the mesh (wire also possible) meshView.setCullFace(CullFace.NONE); // show both sides of the mesh GeometryContainer result; // reuse previous container if available if (prev != null) { result = prev; result.setView(meshView); } else { result = new GeometryContainer(meshView); } return result; } }