📄 shape3d.java
字号:
*/ public void addGeometry(Geometry geometry) { if (isLiveOrCompiled()) if (!this.getCapability(ALLOW_GEOMETRY_WRITE)) throw new CapabilityNotSetException(J3dI18N.getString("Shape3D2")); ((Shape3DRetained)retained).addGeometry(geometry); } /** * Returns the number of geometry components in this Shape3D node's * list of geometry components. * @return the number of geometry components in this Shape3D node's * list of geometry components. * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * * @since Java 3D 1.2 */ public int numGeometries() { if (isLiveOrCompiled()) if (!this.getCapability(ALLOW_GEOMETRY_READ)) throw new CapabilityNotSetException(J3dI18N.getString("Shape3D3")); return ((Shape3DRetained)retained).numGeometries(id); } /** * Retrieves the index of the specified geometry component in * this Shape3D node's list of geometry components. * * @param geometry the geometry component to be looked up. * @return the index of the specified geometry component; * returns -1 if the object is not in the list. * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * * @since Java 3D 1.3 */ public int indexOfGeometry(Geometry geometry) { if (isLiveOrCompiled()) if (!this.getCapability(ALLOW_GEOMETRY_READ)) throw new CapabilityNotSetException(J3dI18N.getString("Shape3D3")); return ((Shape3DRetained)retained).indexOfGeometry(geometry); } /** * Removes the specified geometry component from this * Shape3D node's list of geometry components. * If the specified object is not in the list, the list is not modified. * * @param geometry the geometry component to be removed. * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * * @since Java 3D 1.3 */ public void removeGeometry(Geometry geometry) { if (isLiveOrCompiled()) if (!this.getCapability(ALLOW_GEOMETRY_WRITE)) throw new CapabilityNotSetException(J3dI18N.getString("Shape3D2")); ((Shape3DRetained)retained).removeGeometry(geometry); } /** * Removes all geometry components from this Shape3D node. * * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * * @since Java 3D 1.3 */ public void removeAllGeometries() { if (isLiveOrCompiled()) if (!this.getCapability(ALLOW_GEOMETRY_WRITE)) throw new CapabilityNotSetException(J3dI18N.getString("Shape3D2")); ((Shape3DRetained)retained).removeAllGeometries(); } /** * Sets the appearance component of this Shape3D node. Setting it to null * specifies that default values are used for all appearance attributes. * @param appearance the new appearance component for this shape node * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph */ public void setAppearance(Appearance appearance) { if (isLiveOrCompiled()) if (!this.getCapability(ALLOW_APPEARANCE_WRITE)) throw new CapabilityNotSetException(J3dI18N.getString("Shape3D4")); ((Shape3DRetained)this.retained).setAppearance(appearance); } /** * Retrieves the appearance component of this shape node. * @return the appearance component of this shape node * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph */ public Appearance getAppearance() { if (isLiveOrCompiled()) if (!this.getCapability(ALLOW_APPEARANCE_READ)) throw new CapabilityNotSetException(J3dI18N.getString("Shape3D5")); return ((Shape3DRetained)this.retained).getAppearance(); } /** * Checks whether the geometry in this shape node intersects with * the specified pickShape. * * @param path the SceneGraphPath to this shape node * @param pickShape the PickShape to be intersected * * @return true if the pick shape intersects this node; false * otherwise. * * @exception IllegalArgumentException if pickShape is a PickPoint. * Java 3D doesn't have spatial information of the surface. * Use PickBounds with BoundingSphere and a small radius, instead. * * @exception CapabilityNotSetException if the Geometry.ALLOW_INTERSECT * capability bit is not set in all of the Geometry objects * referred to by this shape node. */ public boolean intersect(SceneGraphPath path, PickShape pickShape) { return intersect(path, pickShape, null); } /** * Checks whether the geometry in this shape node intersects with * the specified pickRay. * * @param path the SceneGraphPath to this shape node * @param pickRay the PickRay to be intersected * @param dist the closest distance of the intersection * * @return true if the pick shape intersects this node; false * otherwise. If true, dist contains the closest distance of * intersection. * * @exception CapabilityNotSetException if the Geometry.ALLOW_INTERSECT * capability bit is not set in all of the Geometry objects * referred to by this shape node. */ public boolean intersect(SceneGraphPath path, PickRay pickRay, double[] dist) { if (isLiveOrCompiled()) { if (!((Shape3DRetained)retained).allowIntersect()) throw new CapabilityNotSetException(J3dI18N.getString("Shape3D6")); } return ((Shape3DRetained)this.retained).intersect(path, pickRay, dist); } /** * Checks whether the geometry in this shape node intersects with * the specified pickShape. * * @param path the SceneGraphPath to this shape node * @param pickShape the PickShape to be intersected * @param dist the closest distance of the intersection * * @return true if the pick shape intersects this node; false * otherwise. If true, dist contains the closest distance of * intersection. * * @exception IllegalArgumentException if pickShape is a PickPoint. * Java 3D doesn't have spatial information of the surface. * Use PickBounds with BoundingSphere and a small radius, instead. * * @exception CapabilityNotSetException if the Geometry.ALLOW_INTERSECT * capability bit is not set in all of the Geometry objects * referred to by this shape node. * * @since Java 3D 1.3 */ public boolean intersect(SceneGraphPath path, PickShape pickShape, double[] dist) { if (isLiveOrCompiled()) { if (!((Shape3DRetained)retained).allowIntersect()) throw new CapabilityNotSetException(J3dI18N.getString("Shape3D6")); } if (pickShape instanceof PickPoint) { throw new IllegalArgumentException(J3dI18N.getString("Shape3D7")); } return ((Shape3DRetained)this.retained).intersect(path, pickShape, dist); } /** * Sets a flag that indicates whether this node's appearance can * be overridden. If the flag is true, then this node's * appearance may be overridden by an AlternateAppearance leaf * node, regardless of the value of the ALLOW_APPEARANCE_WRITE * capability bit. * The default value is false. * * @param flag the apperance override enable flag. * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * * @see AlternateAppearance * * @since Java 3D 1.2 */ public void setAppearanceOverrideEnable(boolean flag) { if (isLiveOrCompiled()) if (!this.getCapability(ALLOW_APPEARANCE_OVERRIDE_WRITE)) throw new CapabilityNotSetException(J3dI18N.getString("Shape3D8")); ((Shape3DRetained)this.retained).setAppearanceOverrideEnable(flag); } /** * Retrieves the appearanceOverrideEnable flag for this node. * @return true if the appearance can be overridden; false * otherwise. * @exception CapabilityNotSetException if appropriate capability is * not set and this object is part of live or compiled scene graph * * @since Java 3D 1.2 */ public boolean getAppearanceOverrideEnable() { if (isLiveOrCompiled()) if (!this.getCapability(ALLOW_APPEARANCE_OVERRIDE_READ)) throw new CapabilityNotSetException(J3dI18N.getString("Shape3D9")); return ((Shape3DRetained)this.retained).getAppearanceOverrideEnable(); } /** * Used to create a new instance of the node. This routine is called * by <code>cloneTree</code> to duplicate the current node. * <code>cloneNode</code> should be overridden by any user subclassed * objects. All subclasses must have their <code>cloneNode</code> * method consist of the following lines: * <P><blockquote><pre> * public Node cloneNode(boolean forceDuplicate) { * UserSubClass usc = new UserSubClass(); * usc.duplicateNode(this, forceDuplicate); * return usc; * } * </pre></blockquote> * @param forceDuplicate when set to <code>true</code>, causes the * <code>duplicateOnCloneTree</code> flag to be ignored. When * <code>false</code>, the value of each node's * <code>duplicateOnCloneTree</code> variable determines whether * NodeComponent data is duplicated or copied. * * @see Node#cloneTree * @see Node#duplicateNode * @see NodeComponent#setDuplicateOnCloneTree */ public Node cloneNode(boolean forceDuplicate) { Shape3D s = new Shape3D(); s.duplicateNode(this, forceDuplicate); return s; } /** * Copies all node information from <code>originalNode</code> into * the current node. This method is called from the * <code>cloneNode</code> method which is, in turn, called by the * <code>cloneTree</code> method. * <P> * For any <code>NodeComponent</code> objects * contained by the object being duplicated, each <code>NodeComponent</code> * object's <code>duplicateOnCloneTree</code> value is used to determine * whether the <code>NodeComponent</code> should be duplicated in the new node * or if just a reference to the current node should be placed in the * new node. This flag can be overridden by setting the * <code>forceDuplicate</code> parameter in the <code>cloneTree</code> * method to <code>true</code>. * <br> * NOTE: Applications should <i>not</i> call this method directly. * It should only be called by the cloneNode method. * * @param originalNode the original node to duplicate. * @param forceDuplicate when set to <code>true</code>, causes the * <code>duplicateOnCloneTree</code> flag to be ignored. When * <code>false</code>, the value of each node's * <code>duplicateOnCloneTree</code> variable determines whether * NodeComponent data is duplicated or copied. * @exception ClassCastException if originalNode is not an instance of * <code>Shape3D</code> * * @see Node#cloneTree * @see Node#cloneNode * @see NodeComponent#setDuplicateOnCloneTree */ public void duplicateNode(Node originalNode, boolean forceDuplicate) { checkDuplicateNode(originalNode, forceDuplicate); } /** * Copies all Shape3D information from * <code>originalNode</code> into * the current node. This method is called from the * <code>cloneNode</code> method which is, in turn, called by the * <code>cloneTree</code> method.<P> * * @param originalNode the original node to duplicate. * @param forceDuplicate when set to <code>true</code>, causes the * <code>duplicateOnCloneTree</code> flag to be ignored. When * <code>false</code>, the value of each node's * <code>duplicateOnCloneTree</code> variable determines whether * NodeComponent data is duplicated or copied. * * @exception RestrictedAccessException if this object is part of a live * or compiled scenegraph. * * @see Node#duplicateNode * @see Node#cloneTree * @see NodeComponent#setDuplicateOnCloneTree */ void duplicateAttributes(Node originalNode, boolean forceDuplicate) { super.duplicateAttributes(originalNode, forceDuplicate); Shape3DRetained attr = (Shape3DRetained) originalNode.retained; Shape3DRetained rt = (Shape3DRetained) retained; rt.setAppearance((Appearance) getNodeComponent( attr.getAppearance(), forceDuplicate, originalNode.nodeHashtable)); int num = attr.numGeometries(id); if (num > 0) { rt.setGeometry((Geometry) getNodeComponent( attr.getGeometry(0, id), forceDuplicate, originalNode.nodeHashtable), 0); for(int i=1; i< num; i++) { rt.addGeometry((Geometry) getNodeComponent( attr.getGeometry(i, id), forceDuplicate, originalNode.nodeHashtable)); } } rt.setCollisionBounds(attr.getCollisionBounds(id)); } /** * See parent class for the documentation on getBounds(). */ public Bounds getBounds() { if (isLiveOrCompiled()) { if(!this.getCapability(ALLOW_BOUNDS_READ)) { throw new CapabilityNotSetException(J3dI18N.getString("Node2")); } } else { // this will throw a SceneGraphCycleException if there is // a cycle checkForCycle(); } return ((Shape3DRetained)this.retained).getBounds(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -