📄 shape3dretained.java
字号:
/* * $RCSfile: Shape3DRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.10 $ * $Date: 2007/04/20 00:54:41 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.*;import java.util.ArrayList;import java.util.Enumeration;import java.util.Vector;/** * A shape leaf node consisting of geometry and appearance properties. */class Shape3DRetained extends LeafRetained { static final int GEOMETRY_CHANGED = 0x00001; static final int APPEARANCE_CHANGED = 0x00002; static final int COLLISION_CHANGED = 0x00004; static final int BOUNDS_CHANGED = 0x00008; static final int APPEARANCEOVERRIDE_CHANGED = 0x00010; static final int LAST_DEFINED_BIT = 0x00010; // Target threads to be notified when light changes static final int targetThreads = J3dThread.UPDATE_RENDERING_ENVIRONMENT | J3dThread.UPDATE_RENDER; /** * The appearance component of the shape node. */ AppearanceRetained appearance = null; /** * The arraylist of geometry component of the shape node. */ ArrayList geometryList = null; /** * A 2D storage of all geometry atoms associated with this shape node. * There may be more than one geometry for a Shape3D node. * Do not change the following private variables to public, its access need to synchronize * via mirrorShape3DLock. */ // geomAtomArr should always be a 1 element array, unless S3D contains multiple Text3Ds. private GeometryAtom geomAtom = null; /** * To sychronize access of the mirrorShape3D's geomAtomArray*. * A multiple read single write Lock to sychronize access into mirrorShape3D. * To prevent deadlock a call to read/write lock must end with a read/write unlock * respectively. */ private MRSWLock mirrorShape3DLock = null; /** * The mirror Shape3DRetained nodes for this object. There is one * mirror for each instance of this Shape3D node. If it is not in * a SharedGroup, only index 0 is valid. * Do not change the following private variables to public, its access need to synchronize * via mirrorShape3DLock. */ ArrayList mirrorShape3D = new ArrayList(1); /** * This field is used for mirror Shape3D nodes accessing their * original nodes. It is a NodeRetained because the original * node may be a Shape3DRetained or a MorphRetained node. */ NodeRetained sourceNode = null; /** * The hashkey for this Shape3DRetained mirror object */ HashKey key = null; // This is true when this geometry is referenced in an IMM mode context boolean inImmCtx = false; // A bitmask to indicate when something has changed int isDirty = 0xffff; // The list of lights that are scoped to this node LightRetained[] lights =null; // The number of lights in the above array, may be less than lights.length int numlights = 0; // The list of fogs that are scoped to this node FogRetained[] fogs = null; // The number of fogs in the above array, may be less than fogs.length int numfogs = 0; // The list of modelClips that are scoped to this node ModelClipRetained[] modelClips = null; // The number of modelClips in the above array, may be less than modelClips.length int numModelClips = 0; // The list of alt app that are scoped to this node AlternateAppearanceRetained[] altApps = null; //The number of alt app in the above array, may be less than alt app.length int numAltApps = 0; /** * Reference to the BranchGroup path of this mirror shape * This is used for picking and GeometryStructure only. */ BranchGroupRetained branchGroupPath[]; // cache value for picking in mirror shape. // True if all the node of the path from this to root are all pickable boolean isPickable = true; // cache value for collidable in mirror shape. // True if all the node of the path from this to root are all collidable boolean isCollidable = true; // closest switch parent SwitchRetained closestSwitchParent = null; // the child index from the closest switch parent int closestSwitchIndex = -1; // Is this S3D visible ? The default is true. boolean visible = true; // Whether the normal appearance is overrided by the alternate app boolean appearanceOverrideEnable = false; // AlternateAppearance retained that is applicable to this // mirror shape when the override flag is true AppearanceRetained otherAppearance = null; // geometry Bounds in local coordinate Bounds bounds = null; // geometry Bounds in virtual world coordinate BoundingBox vwcBounds = null; // collision Bounds in local coordinate Bounds collisionBound = null; // collision Bounds in virtual world coordinate Bounds collisionVwcBound = null; // a path of OrderedGroup, childrenId pairs which leads to this node OrderedPath orderedPath = null; // List of views that a mirror object is scoped to ArrayList viewList = null; int changedFrequent = 0; Shape3DRetained() { super(); this.nodeType = NodeRetained.SHAPE; numlights = 0; numfogs = 0; numModelClips = 0; numAltApps = 0; localBounds = new BoundingBox((BoundingBox) null); mirrorShape3DLock = new MRSWLock(); geometryList = new ArrayList(1); geometryList.add(null); } /** * Sets the collision bounds of a node. * @param bounds the bounding object for the node */ void setCollisionBounds(Bounds bounds) { if (bounds == null) { this.collisionBound = null; } else { this.collisionBound = (Bounds)bounds.clone(); } if (source.isLive()) { // Notify Geometry Structure to check for collision J3dMessage message = new J3dMessage(); message.type = J3dMessage.COLLISION_BOUND_CHANGED; message.threads = J3dThread.UPDATE_TRANSFORM; message.universe = universe; message.args[0] = getGeomAtomsArray(mirrorShape3D); // no need to clone collisionBound message.args[1] = collisionBound; VirtualUniverse.mc.processMessage(message); } } Bounds getLocalBounds(Bounds bounds) { if(localBounds != null) { localBounds.set(bounds); } else { localBounds = new BoundingBox(bounds); } return localBounds; } /** * Sets the geometric bounds of a node. * @param bounds the bounding object for the node */ void setBounds(Bounds bounds) { super.setBounds(bounds); if (source.isLive() && !boundsAutoCompute) { J3dMessage message = new J3dMessage(); message.type = J3dMessage.REGION_BOUND_CHANGED; message.threads = J3dThread.UPDATE_TRANSFORM | J3dThread.UPDATE_GEOMETRY | J3dThread.UPDATE_RENDER; message.universe = universe; message.args[0] = getGeomAtomsArray(mirrorShape3D); // no need to clone localBounds message.args[1] = localBounds; VirtualUniverse.mc.processMessage(message); } } /** * Gets the collision bounds of a node. * @return the node's bounding object */ Bounds getCollisionBounds(int id) { return (collisionBound == null ? null: (Bounds)collisionBound.clone()); } /** * Appends the specified geometry component to this Shape3D * node's list of geometry components. * If there are existing geometry components in the list, the new * geometry component must be of the same equivalence class * (point, line, polygon, CompressedGeometry, Raster, Text3D) as * the others. * @param geometry the geometry component to be appended. * @exception IllegalArgumentException if the new geometry * component is not of of the same equivalence class as the * existing geometry components. * * @since Java 3D 1.2 */ void addGeometry(Geometry geometry) { int i; Shape3DRetained s; GeometryRetained newGeom = null; checkEquivalenceClass(geometry, -1); if(((Shape3D)this.source).isLive()) { if (geometry != null) { newGeom = ((GeometryRetained)geometry.retained); newGeom.setLive(inBackgroundGroup, refCount); geometryList.add(newGeom); } else { geometryList.add(null); newGeom = null; } sendDataChangedMessage(newGeom); } else { if (geometry != null) { geometryList.add((GeometryRetained) geometry.retained); } else { geometryList.add(null); } } dirtyBoundsCache(); } /** * Replaces the geometry component at the specified index in this * Shape3D node's list of geometry components with the specified * geometry component. * If there are existing geometry components in the list (besides * the one being replaced), the new geometry component must be of * the same equivalence class (point, line, polygon, CompressedGeometry, * Raster, Text3D) as the others. * @param geometry the geometry component to be stored at the * specified index. * @param index the index of the geometry component to be replaced. * @exception IllegalArgumentException if the new geometry * component is not of of the same equivalence class as the * existing geometry components. * * @since Java 3D 1.2 */ void setGeometry(Geometry geometry, int index) { int i; Shape3DRetained mShape; GeometryRetained newGeom = null; GeometryRetained oldGeom = null; checkEquivalenceClass(geometry, index); if (((Shape3D)this.source).isLive()) { oldGeom = (GeometryRetained) (geometryList.get(index)); if (oldGeom != null) { oldGeom.clearLive(refCount); for (i=0; i<mirrorShape3D.size(); i++) { mShape = (Shape3DRetained)mirrorShape3D.get(i); oldGeom.removeUser(mShape); } oldGeom.decRefCnt(); } if (geometry != null) { newGeom = (GeometryRetained) geometry.retained; newGeom.incRefCnt(); newGeom.setLive(inBackgroundGroup, refCount); geometryList.set(index, newGeom); sendDataChangedMessage(newGeom); } else { geometryList.set(index, null); sendDataChangedMessage(null); } } else { oldGeom = (GeometryRetained) (geometryList.get(index)); if (oldGeom != null) { oldGeom.decRefCnt(); } if (geometry != null) { geometryList.set(index,(GeometryRetained) geometry.retained); ((GeometryRetained)geometry.retained).incRefCnt(); } else { geometryList.set(index,null); } } dirtyBoundsCache(); } /** * Inserts the specified geometry component into this Shape3D * node's list of geometry components at the specified index. * If there are existing geometry components in the list, the new * geometry component must be of the same equivalence class * (point, line, polygon, CompressedGeometry, Raster, Text3D) as * the others. * @param geometry the geometry component to be inserted at the * specified index. * @param index the index at which the geometry component is inserted. * * @since Java 3D 1.2 */ void insertGeometry(Geometry geometry, int index) { int i; Shape3DRetained mShape; GeometryRetained newGeom = null; GeometryRetained oldGeom = null; checkEquivalenceClass(geometry, -1); if (((Shape3D)this.source).isLive()) { if (geometry != null) { // Note : The order of the statements in important. Want ArrayList class to do index bounds // check before creating internal object. newGeom = (GeometryRetained) geometry.retained; newGeom.incRefCnt(); geometryList.add(index, newGeom); newGeom.setLive(inBackgroundGroup, refCount); sendDataChangedMessage(newGeom); } else { geometryList.add(index, null); sendDataChangedMessage(null); } } else { if (geometry != null) { geometryList.add(index,(GeometryRetained) geometry.retained); ((GeometryRetained)geometry.retained).incRefCnt(); } else { geometryList.add(index,null); } } dirtyBoundsCache(); } /** * Removes the geometry component at the specified index from * this Shape3D node's list of geometry components. * @param index the index of the geometry component to be removed. * * @since Java 3D 1.2 */ void removeGeometry(int index) { int i; Shape3DRetained mShape; GeometryRetained oldGeom = null; if (((Shape3D)this.source).isLive()) { oldGeom = (GeometryRetained) (geometryList.get(index)); if (oldGeom != null) { oldGeom.clearLive(refCount); oldGeom.decRefCnt(); for (i=0; i<mirrorShape3D.size(); i++) { mShape = (Shape3DRetained)mirrorShape3D.get(i); oldGeom.removeUser(mShape); } } geometryList.remove(index); sendDataChangedMessage(null); } else { oldGeom = (GeometryRetained) (geometryList.get(index)); if (oldGeom != null) { oldGeom.decRefCnt(); } geometryList.remove(index); } dirtyBoundsCache(); } /** * Retrieves the geometry component of this Shape3D node. * @return the geometry component of this shape node * * @since Java 3D 1.2 */ Geometry getGeometry(int index, int id) { GeometryRetained ga = (GeometryRetained) geometryList.get(index); return (ga == null ? null : (Geometry)ga.source); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -