📄 pickinfo.java
字号:
// PickInfo.SCENEGRAPHPATH - request for computed SceneGraphPath. if ((flags & SCENEGRAPHPATH) != 0) { mpath = createPath(srcNode, bgRetained, geomAtoms[i], initpath); if(mpath != null) { SceneGraphPath sgpath = new SceneGraphPath(locale, mpath, (Node) srcNode.source); sgpath.setTransform(shape.getCurrentLocalToVworld(0)); if(pickInfo == null) pickInfo = new PickInfo(); pickInfo.setSceneGraphPath(sgpath); } } // PickInfo.NODE - request for computed intersected Node. if ((flags & NODE) != 0) { if(pickInfo == null) pickInfo = new PickInfo(); pickInfo.setNode((Node) srcNode.source); } // PickInfo.LOCAL_TO_VWORLD // - request for computed local to virtual world transform. if ((flags & LOCAL_TO_VWORLD) != 0) { Transform3D l2vw = geomAtoms[i].source.getCurrentLocalToVworld(); if(pickInfo == null) pickInfo = new PickInfo(); pickInfo.setLocalToVWorld( new Transform3D(l2vw)); } // NOTE : Piggy bag for geometry computation by caller. if (((flags & CLOSEST_DISTANCE) != 0) || ((flags & CLOSEST_GEOM_INFO) != 0) || ((flags & CLOSEST_INTERSECTION_POINT) != 0) || ((flags & ALL_GEOM_INFO) != 0)) { if(pickInfo == null) pickInfo = new PickInfo(); pickInfo.setNodeRef((Node) srcNode.source); Transform3D l2vw = geomAtoms[i].source.getCurrentLocalToVworld(); pickInfo.setLocalToVWorldRef(l2vw); } if(pickInfo != null) pickInfoList.add(pickInfo); if(pickType == PICK_ANY) { return pickInfoList; } } } return pickInfoList; } static PickInfo[] pick(Object node, GeometryAtom[] geomAtoms, int mode, int flags, PickShape pickShape, int pickType) { int pickInfoListSize; PickInfo[] pickInfoArr = null; Locale locale = null; BranchGroupRetained bgRetained = null; ArrayList initPath = null; ArrayList pickInfoList = null; if (node instanceof Locale) { locale = (Locale) node; } else if ( node instanceof BranchGroupRetained) { bgRetained = (BranchGroupRetained) node; locale = bgRetained.locale; } synchronized (locale.universe.sceneGraphLock) { if ( bgRetained != null) { initPath = initSceneGraphPath(bgRetained); } pickInfoList = getPickInfos(initPath, bgRetained, geomAtoms, locale, flags, pickType); } // We're done with PICK_BOUNDS case, but there is still more work for PICK_GEOMETRY case. if((mode == PICK_GEOMETRY) && (pickInfoList != null) && ((pickInfoListSize = pickInfoList.size()) > 0)) { //System.err.println("PickInfo.pick() - In geometry case : pickInfoList.size() is " + pickInfoListSize); PickInfo pickInfo = null; Node pickNode = null; // Order is impt. Need to do in reverse order. for(int i = pickInfoListSize - 1; i >= 0; i--) { pickInfo = (PickInfo) pickInfoList.get(i); pickNode = pickInfo.getNode(); if( pickNode == null) { // Use the piggy reference from getPickInfos() pickNode = pickInfo.getNodeRef(); } if (pickNode instanceof Shape3D) { /* * @exception CapabilityNotSetException if the mode is * PICK_GEOMETRY and the Geometry.ALLOW_INTERSECT capability bit * is not set in any Geometry objects referred to by any shape * node whose bounds intersects the PickShape. * * @exception CapabilityNotSetException if flags contains any of * CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE, CLOSEST_GEOM_INFO * or ALL_GEOM_INFO, and the capability bits that control reading of * coordinate data are not set in any GeometryArray object referred * to by any shape node that intersects the PickShape. * The capability bits that must be set to avoid this exception are * as follows : * * By-copy geometry : GeometryArray.ALLOW_COORDINATE_READ * By-reference geometry : GeometryArray.ALLOW_REF_DATA_READ * Indexed geometry : IndexedGeometryArray.ALLOW_COORDINATE_INDEX_READ * (in addition to one of the above) * */ if (!pickNode.getCapability(Shape3D.ALLOW_GEOMETRY_READ)) { throw new CapabilityNotSetException(J3dI18N.getString("PickInfo0")); } for (int j = 0; j < ((Shape3D)pickNode).numGeometries(); j++) { Geometry geo = ((Shape3D)pickNode).getGeometry(j); if(geo == null) { continue; } if(!geo.getCapability(Geometry.ALLOW_INTERSECT)) { throw new CapabilityNotSetException(J3dI18N.getString("PickInfo1")); } if (geo instanceof GeometryArray) { if(!geo.getCapability(GeometryArray.ALLOW_COORDINATE_READ)) throw new CapabilityNotSetException(J3dI18N.getString("PickInfo2")); if(!geo.getCapability(GeometryArray.ALLOW_COUNT_READ)) throw new CapabilityNotSetException(J3dI18N.getString("PickInfo3")); if(!geo.getCapability(GeometryArray.ALLOW_FORMAT_READ)) throw new CapabilityNotSetException(J3dI18N.getString("PickInfo4")); if (geo instanceof IndexedGeometryArray) { if(!geo.getCapability(IndexedGeometryArray.ALLOW_COORDINATE_INDEX_READ)) throw new CapabilityNotSetException(J3dI18N.getString("PickInfo5")); } } else if (geo instanceof CompressedGeometry) { if(!geo.getCapability(CompressedGeometry.ALLOW_GEOMETRY_READ)) throw new CapabilityNotSetException(J3dI18N.getString("PickInfo0")); } } if (((Shape3DRetained)(pickNode.retained)).intersect(pickInfo, pickShape, flags) == false) { // System.err.println(" ---- geom " + i + " not intersected"); pickInfoList.remove(i); } else if(pickType == PICK_ANY) { pickInfoArr = new PickInfo[1]; pickInfoArr[0] = pickInfo; return pickInfoArr; } } else if (pickNode instanceof Morph) { /* * @exception CapabilityNotSetException if the mode is * PICK_GEOMETRY and the Geometry.ALLOW_INTERSECT capability bit * is not set in any Geometry objects referred to by any shape * node whose bounds intersects the PickShape. * * @exception CapabilityNotSetException if flags contains any of * CLOSEST_INTERSECTION_POINT, CLOSEST_DISTANCE, CLOSEST_GEOM_INFO * or ALL_GEOM_INFO, and the capability bits that control reading of * coordinate data are not set in any GeometryArray object referred * to by any shape node that intersects the PickShape. * The capability bits that must be set to avoid this exception are * as follows : * * By-copy geometry : GeometryArray.ALLOW_COORDINATE_READ * By-reference geometry : GeometryArray.ALLOW_REF_DATA_READ * Indexed geometry : IndexedGeometryArray.ALLOW_COORDINATE_INDEX_READ * (in addition to one of the above) * */ if (!pickNode.getCapability(Morph.ALLOW_GEOMETRY_ARRAY_READ)) { throw new CapabilityNotSetException(J3dI18N.getString("PickInfo6")); } int numGeo = ((MorphRetained)(pickNode.retained)).getNumGeometryArrays(); for (int j = 0; j < numGeo; j++) { GeometryArray geo = ((Morph)pickNode).getGeometryArray(j); if(geo == null) { continue; } if(!geo.getCapability(Geometry.ALLOW_INTERSECT)) { throw new CapabilityNotSetException(J3dI18N.getString("PickInfo1")); } if(!geo.getCapability(GeometryArray.ALLOW_COORDINATE_READ)) throw new CapabilityNotSetException(J3dI18N.getString("PickInfo2")); if(!geo.getCapability(GeometryArray.ALLOW_COUNT_READ)) throw new CapabilityNotSetException(J3dI18N.getString("PickInfo3")); if(!geo.getCapability(GeometryArray.ALLOW_FORMAT_READ)) throw new CapabilityNotSetException(J3dI18N.getString("PickInfo4")); if (geo instanceof IndexedGeometryArray) { if(!geo.getCapability(IndexedGeometryArray.ALLOW_COORDINATE_INDEX_READ)) throw new CapabilityNotSetException(J3dI18N.getString("PickInfo5")); } } if (((MorphRetained)(pickNode.retained)).intersect(pickInfo, pickShape, flags) == false) { pickInfoList.remove(i); } else if(pickType == PICK_ANY) { pickInfoArr = new PickInfo[1]; pickInfoArr[0] = pickInfo; return pickInfoArr; } } } } // System.err.println("PickInfo : pickInfoList " + pickInfoList); if ((pickInfoList != null) && (pickInfoList.size() > 0)) { // System.err.println(" --- : pickInfoList.size() " + pickInfoList.size()); // System.err.println(" --- : pickInfoList's sgp " + // ((PickInfo)(pickInfoList.get(0))).getSceneGraphPath()); pickInfoArr = new PickInfo[pickInfoList.size()]; return (PickInfo []) pickInfoList.toArray(pickInfoArr); } return null; } /** * The IntersectionInfo object holds extra information about an intersection * of a PickShape with a Node as part of a PickInfo. Information such as * the intersected geometry, the intersected point, and the vertex indices * can be inquired. * The local coordinates, normal, color and texture coordiantes of at the * intersection can be computed, if they are present and readable, using the * interpolation weights and vertex indices. * <p> * If the Shape3D being picked has multiple geometry arrays, the possible arrays * of IntersectionInfo are stored in the PickInfo and referred to by a geometry * index. If the picked geometry is of type, Text3D or CompressGeometry, * getVertexIndices is invalid. If the picked Node is an Morph * object, the geometry used in pick computation is alway at index 0. * <p> * * @since Java 3D 1.4 */ public class IntersectionInfo extends Object { /* The index to the intersected geometry in the pickable node */ private int geomIndex; /* The reference to the intersected geometry in the pickable object */ private Geometry geom; /* The intersection point */ private Point3d intersectionPoint; /* Distance between start point of pickShape and intersection point */ private double distance; /* The vertex indices of the intersected primitive in the geometry */ private int[] vertexIndices; /* The interpolation weights for each of the verticies of the primitive */ // private float[] weights; Not supported. Should be done in util. package /** IntersectionInfo Constructor */ IntersectionInfo() { } void setGeometryIndex(int geomIndex) { this.geomIndex = geomIndex; } void setGeometry(Geometry geom) { this.geom = geom; } void setIntersectionPoint(Point3d intersectionPoint) { assert(intersectionPoint != null); this.intersectionPoint = new Point3d(intersectionPoint); } void setDistance(double distance) { this.distance = distance; } void setVertexIndices(int[] vertexIndices) { assert(vertexIndices != null); this.vertexIndices = new int[vertexIndices.length]; for(int i=0; i<vertexIndices.length; i++) { this.vertexIndices[i] = vertexIndices[i]; } } /** * Retrieves the index to the intersected geometry in the picked node, either a Shape3D or Morph. * @return the index of the intersected geometry in the pickable node. */ public int getGeometryIndex() { return geomIndex; } /** * Retrieves the reference to the intersected geometry in the picked object, either a Shape3D or Morph. * @return the intersected geometry in the pickable node. */ public Geometry getGeometry() { return geom; } /** * Retrieves the reference to the intersection point in the pickable node. * @return the intersected point in the pickable node. */ public Point3d getIntersectionPoint() { return intersectionPoint; } /** * Retrieves the distance between the start point of the pickShape and the * intersection point. * @return distance between the start point of the pickShape and the * intersection point. */ public double getDistance() { return distance; } /** * Retrieves the vertex indices of the intersected primitive in the geometry. * @return the vertex indices of the intersected primitive. */ public int[] getVertexIndices() { return vertexIndices; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -