001/** 002 * J3DGeomList -- A Java3D node that represents a GeomList in a J3D scene graph. 003 * 004 * Copyright (C) 2009-2023, Joseph A. Huwaldt 005 * All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or modify it under the terms 008 * of the GNU Lesser General Public License as published by the Free Software Foundation; 009 * either version 2.1 of the License, or (at your option) any later version. 010 * 011 * This library is distributed in the hope that it will be useful, but WITHOUT ANY 012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 013 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License along with 016 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - 017 * Suite 330, Boston, MA 02111-1307, USA. Or visit: http://www.gnu.org/licenses/lgpl.html 018 */ 019package geomss.j3d; 020 021import org.jogamp.java3d.*; 022import geomss.geom.GeomElement; 023import geomss.geom.GeometryList; 024import geomss.geom.AbstractGeomList; 025import geomss.app.GeomSSCanvas3D; 026import static java.util.Objects.requireNonNull; 027 028/** 029 * A Java 3D node that represents a GeometryList in a Java 3D scene graph. 030 * 031 * <p> Modified by: Joseph A. Huwaldt </p> 032 * 033 * @author Joseph A. Huwaldt, Date: April 13, 2009 034 * @version June 4, 2023 035 */ 036public class J3DGeomList extends J3DGeomGroup<AbstractGeomList> { 037 038 /** 039 * Construct a J3DGeomList using the specified GeomList as a reference. 040 * 041 * @param canvas The canvas that the geometry is rendered into. 042 * @param geometry The GeomSS geometry to be turned into a Java3D node. 043 */ 044 public J3DGeomList(GeomSSCanvas3D canvas, AbstractGeomList geometry) { 045 super(requireNonNull(canvas), requireNonNull(geometry)); 046 } 047 048 /** 049 * Sets the display of this geometry group to either DISPLAYED (true) or NOT_DISPLAYED 050 * (false). 051 * 052 * @param visible Flag indicating if the geometry is displayed or not. 053 */ 054 @Override 055 public void setDisplayed(boolean visible) { 056 super.setDisplayed(visible); 057 058 // Simply pass the message on to the elements in this list. 059 Group geomG = getSceneGraph(); 060 int size = geomG.numChildren(); 061 for (int i = 0; i < size; ++i) { 062 J3DGeomGroup node = (J3DGeomGroup)geomG.getChild(i); 063 node.setDisplayed(visible); 064 } 065 } 066 067 /** 068 * Set the display of a copy of this geometry mirrored across the XZ plane to either 069 * DISPLAYED (true) or NOT_DISPLAYED (false). 070 * 071 * @param mirrored Flag indicating if the mirrored geometry should be displayed or 072 * not. 073 */ 074 @Override 075 public void setMirrored(boolean mirrored) { 076 super.setMirrored(mirrored); 077 078 // Simply pass the message on to the elements in this list. 079 Group geomG = getSceneGraph(); 080 int size = geomG.numChildren(); 081 for (int i = 0; i < size; ++i) { 082 J3DGeomGroup node = (J3DGeomGroup)geomG.getChild(i); 083 node.setMirrored(mirrored); 084 } 085 } 086 087 /** 088 * Create a new Java 3D <code>Group</code> that contains the geometry contained in 089 * this object. This method is called from <code>createSceneGraph</code>. This 090 * implementation loops over all the elements in the list and creates J3DGeomGroups 091 * for each adding them to the returned Group. 092 * 093 * @return New Java 3D Group that contains the geometry in this object. 094 * @see #createSceneGraph 095 */ 096 @Override 097 protected Group createGeometry() { 098 099 // Create a group to contain our geometry. 100 Switch geomG = new Switch(Switch.CHILD_ALL); 101 geomG.setCapability(Group.ALLOW_CHILDREN_WRITE); 102 103 // Add the geometry in this list to the switch group. 104 AbstractGeomList<? extends AbstractGeomList, GeomElement> list = this.getGeomElement(); 105 for (GeomElement element : list) { 106 if (element instanceof GeometryList) 107 // Skip any empty lists. 108 if (!((GeometryList)element).containsGeometry()) 109 continue; 110 J3DGeomGroup group = J3DGeomGroupFactory.newGroup(getCanvas3D(), element); 111 if (group != null) 112 geomG.addChild(group); 113 } 114 115 return geomG; 116 } 117 118 /** 119 * Set the render type used for this group. 120 * 121 * @param type Value indicating the way that some objects should be rendered. 122 * @see #getRenderType() 123 */ 124 @Override 125 public void setRenderType(RenderType type) { 126 super.setRenderType(requireNonNull(type)); 127 128 // Simply pass the message on to the elements in this list. 129 Group geomG = getSceneGraph(); 130 int size = geomG.numChildren(); 131 for (int i = 0; i < size; ++i) { 132 J3DGeomGroup node = (J3DGeomGroup)geomG.getChild(i); 133 node.setRenderType(type); 134 } 135 } 136 137 /** 138 * Creates a new instance of the node. This routine is called by 139 * <code>cloneTree</code> to duplicate the current node. 140 * 141 * @param forceDuplicate when set to <code>true</code>, causes the 142 * <code>duplicateOnCloneTree</code> flag to be ignored. When 143 * <code>false</code>, the value of each node's 144 * <code>duplicateOnCloneTree</code> variable determines whether 145 * NodeComponent data is duplicated or copied. 146 * @return A new instance of this Java3D node. 147 */ 148 @Override 149 public Node cloneNode(boolean forceDuplicate) { 150 J3DGeomList node = new J3DGeomList(getCanvas3D(), this.getGeomElement()); 151 node.duplicateNode(this, forceDuplicate); 152 return node; 153 } 154}