001/** 002 * GeomShape3D -- A Java 3D Shape3D object that knows what GeomElement it is associated 003 * with. 004 * 005 * Copyright (C) 2011-2023 by Joseph A. Huwaldt. 006 * All rights reserved. 007 * 008 * This library is free software; you can redistribute it and/or modify it under the terms 009 * of the GNU Lesser General Public License as published by the Free Software Foundation; 010 * either version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, but WITHOUT ANY 013 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 014 * PARTICULAR PURPOSE. See the GNU Library General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License along with 017 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - 018 * Suite 330, Boston, MA 02111-1307, USA. Or visit: http://www.gnu.org/licenses/lgpl.html 019 */ 020package geomss.j3d; 021 022import geomss.geom.GeomElement; 023import static java.util.Objects.requireNonNull; 024import org.jogamp.java3d.Appearance; 025import org.jogamp.java3d.Geometry; 026import org.jogamp.java3d.Node; 027import org.jogamp.java3d.Shape3D; 028 029/** 030 * A Shape3D object that maintains a reference to the GeomElement with which it is 031 * associated. 032 * 033 * <p> Modified by: Joseph A. Huwaldt </p> 034 * 035 * @author Joseph A. Huwaldt, Date: October 19, 2011 036 * @version June 4, 2023 037 */ 038public class GeomShape3D extends Shape3D { 039 040 private GeomElement parent = null; 041 042 /** 043 * Constructs a Shape3D node with default parameters. 044 * 045 * @param parent The GeomSS geometry element that this Shape3D is associated with. 046 */ 047 public GeomShape3D(GeomElement parent) { 048 this.parent = requireNonNull(parent); 049 } 050 051 /** 052 * Constructs and initializes a Shape3D node with the specified geometry component and 053 * a null appearance component. The list of geometry components is initialized with 054 * the specified geometry component as the single element with an index of 0. A null 055 * appearance component specifies that default values are used for all appearance 056 * attributes. 057 * 058 * @param parent The GeomSS geometry element that this Shape3D is associated with. 059 * @param geometry The geometry component with which to initialize this shape node. 060 */ 061 public GeomShape3D(GeomElement parent, Geometry geometry) { 062 super(requireNonNull(geometry)); 063 this.parent = requireNonNull(parent); 064 } 065 066 /** 067 * Constructs and initializes a Shape3D node with the specified geometry and 068 * appearance components. The list of geometry components is initialized with the 069 * specified geometry component as the single element with an index of 0. 070 * 071 * @param parent The GeomSS geometry element that this Shape3D is associated with. 072 * @param geometry The geometry component with which to initialize this shape node. 073 * @param appearance The appearance component of the shape node. 074 */ 075 public GeomShape3D(GeomElement parent, Geometry geometry, Appearance appearance) { 076 super(requireNonNull(geometry), requireNonNull(appearance)); 077 this.parent = requireNonNull(parent); 078 } 079 080 /** 081 * Return a reference to the GeomSS geometry element that this shape is associated 082 * with. 083 * 084 * @return A reference to the GeomElement that this shape is associated with. 085 */ 086 public GeomElement getGeometryElement() { 087 return parent; 088 } 089 090 /** 091 * Used to create a new instance of the node. This routine is called by cloneTree to 092 * duplicate the current node. cloneNode should be overridden by any user sub-classed 093 * objects. 094 * 095 * @param forceDuplicate when set to <code>true</code>, causes the 096 * <code>duplicateOnCloneTree</code> flag to be ignored. When 097 * <code>false</code>, the value of each node's 098 * <code>duplicateOnCloneTree</code> variable determines whether 099 * NodeComponent data is duplicated or copied. 100 * @return A new instance of this Java3D node. 101 */ 102 @Override 103 public Node cloneNode(boolean forceDuplicate) { 104 GeomShape3D usc = new GeomShape3D(parent); 105 usc.duplicateNode(this, forceDuplicate); 106 return usc; 107 } 108}