⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shape3dretained.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            /**     * Returns an enumeration of this Shape3D node's list of geometry     * components.     * @return an Enumeration object containing all geometry components in     * this Shape3D node's list of geometry components.     *     * @since Java 3D 1.2     */    Enumeration getAllGeometries(int id) {	GeometryRetained ga = null;	Vector geomList = new Vector(geometryList.size());		for(int i=0; i<geometryList.size(); i++) {	    ga = (GeometryRetained) geometryList.get(i);	    if(ga != null) 		geomList.add((Geometry)ga.source);	    else		geomList.add(null);	}		return geomList.elements();    }    /**     * 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.     *     * @since Java 3D 1.2     */    int numGeometries(int id) {	return geometryList.size();    }	    /**     * Sets the appearance component of this Shape3D node.     * @param appearance the new apearance component for this shape node     */    void setAppearance(Appearance newAppearance) {	Shape3DRetained s;	boolean visibleIsDirty = false;		if (((Shape3D)this.source).isLive()) {	    	    if (appearance != null) {	        appearance.clearLive(refCount);		for (int i=0; i<mirrorShape3D.size(); i++) {		    s = (Shape3DRetained)mirrorShape3D.get(i);		    appearance.removeAMirrorUser(s);		}	   	    }	    	    if (newAppearance != null) {	       ((AppearanceRetained)newAppearance.retained).setLive(inBackgroundGroup, refCount);		appearance = ((AppearanceRetained)newAppearance.retained);		for (int i=0; i<mirrorShape3D.size(); i++) {		    s = (Shape3DRetained)mirrorShape3D.get(i);		    appearance.addAMirrorUser(s);		}		if((appearance.renderingAttributes != null) &&		   (visible !=  appearance.renderingAttributes.visible)) {		    visible = appearance.renderingAttributes.visible;		    visibleIsDirty = true;		}	    }	    else {		if(visible == false) {		    visible = true;		    visibleIsDirty = true;	       }	    }	    int size = 0;	    if (visibleIsDirty)		size = 2;	    else		size = 1;	    J3dMessage[] createMessage = new J3dMessage[size];	    // Send a message	    createMessage[0] = new J3dMessage();	    createMessage[0].threads = targetThreads;	    createMessage[0].type = J3dMessage.SHAPE3D_CHANGED;	    createMessage[0].universe = universe;	    createMessage[0].args[0] = this;	    createMessage[0].args[1]= new Integer(APPEARANCE_CHANGED);	    Shape3DRetained[] s3dArr = new Shape3DRetained[mirrorShape3D.size()];	    mirrorShape3D.toArray(s3dArr);	    createMessage[0].args[2] = s3dArr;	    Object[] obj = new Object[2];	    if (newAppearance == null) {		obj[0] = null;	    }	    else {		obj[0]  = appearance.mirror;	    }	    obj[1] = new Integer(changedFrequent);	    createMessage[0].args[3] = obj;	    createMessage[0].args[4] = getGeomAtomsArray(mirrorShape3D);	    if(visibleIsDirty) {		createMessage[1] = new J3dMessage();		createMessage[1].threads = J3dThread.UPDATE_GEOMETRY;	    		createMessage[1].type = J3dMessage.SHAPE3D_CHANGED;		createMessage[1].universe = universe;		createMessage[1].args[0] = this;		createMessage[1].args[1]= new Integer(APPEARANCE_CHANGED);		createMessage[1].args[2]= visible?Boolean.TRUE:Boolean.FALSE;		createMessage[1].args[3]= createMessage[0].args[4];	    }	    VirtualUniverse.mc.processMessage(createMessage);	        }	else { // not live.	    if (newAppearance == null) {		appearance = null;	    } else {		appearance = (AppearanceRetained) newAppearance.retained;    	    }	}    }        /**     * Retrieves the shape node's appearance component.     * @return the shape node's appearance     */    Appearance getAppearance() {        return (appearance == null ? null: (Appearance) appearance.source);    }    void setAppearanceOverrideEnable(boolean flag) {	if (((Shape3D)this.source).isLive()) {	    	    // Send a message	    J3dMessage createMessage = new J3dMessage();	    createMessage.threads = targetThreads;	    createMessage.type = J3dMessage.SHAPE3D_CHANGED;	    createMessage.universe = universe;	    createMessage.args[0] = this;	    createMessage.args[1]= new Integer(APPEARANCEOVERRIDE_CHANGED);	    Shape3DRetained[] s3dArr = new Shape3DRetained[mirrorShape3D.size()];	    mirrorShape3D.toArray(s3dArr);	    createMessage.args[2] = s3dArr;	    Object[] obj = new Object[2];	    if (flag) {		obj[0] = Boolean.TRUE;	    }	    else {		obj[0]  = Boolean.FALSE;	    }	    obj[1] = new Integer(changedFrequent);	    createMessage.args[3] = obj;	    createMessage.args[4] = getGeomAtomsArray(mirrorShape3D);	    VirtualUniverse.mc.processMessage(createMessage);	}	appearanceOverrideEnable = flag;    }    boolean getAppearanceOverrideEnable() {	return appearanceOverrideEnable;    }        boolean intersect(PickInfo pickInfo, PickShape pickShape, int flags ) {                  Transform3D localToVworld = pickInfo.getLocalToVWorldRef();                // Support OrientedShape3D here.	// Note - BugId : 4363899 - APIs issue : OrientedShape3D's intersect needs view	//                          info. temp. fix use the primary view.	if (this instanceof OrientedShape3DRetained) {	    Transform3D orientedTransform = ((OrientedShape3DRetained)this).		getOrientedTransform(getPrimaryViewIdx());	    localToVworld.mul(orientedTransform);	}         	Transform3D t3d = new Transform3D();	t3d.invert(localToVworld);	PickShape newPS = pickShape.transform(t3d);	// Note: For optimization - Should do a geobounds check of	// each geometry first. But this doesn't work for	// OrientedShape3D case...	int geomListSize = geometryList.size();	GeometryRetained geometry;        if (((flags & PickInfo.CLOSEST_INTERSECTION_POINT) == 0) &&                ((flags & PickInfo.CLOSEST_DISTANCE) == 0) &&                ((flags & PickInfo.CLOSEST_GEOM_INFO) == 0) &&                ((flags & PickInfo.ALL_GEOM_INFO) == 0)) {                        for (int i=0; i < geomListSize; i++) {                geometry =  (GeometryRetained) geometryList.get(i);                if (geometry != null) {                    if (geometry.mirrorGeometry != null) {                        geometry = geometry.mirrorGeometry;                    }                    if (geometry.intersect(newPS, null, 0, null, null, 0)) {                        return true;                    }                }            }        } else {            double distance;            double minDist = Double.POSITIVE_INFINITY;            Point3d closestIPnt = new Point3d();            Point3d iPnt = new Point3d();            Point3d iPntVW = new Point3d();                        for (int i=0; i < geomListSize; i++) {                geometry =  (GeometryRetained) geometryList.get(i);                if (geometry != null) {                    if (geometry.mirrorGeometry != null) {                        geometry = geometry.mirrorGeometry;                    }                    //if (geometry.intersect(newPS, intersectionInfo, flags, iPnt)) {                    if(geometry.intersect(newPS, pickInfo, flags, iPnt, geometry, i)) {                                                iPntVW.set(iPnt);                        localToVworld.transform(iPntVW);                        distance = pickShape.distance(iPntVW);                                                if (minDist > distance) {                            minDist = distance;                            closestIPnt.set(iPnt);                        }                    }                }            }                        if (minDist < Double.POSITIVE_INFINITY) {                if ((flags & PickInfo.CLOSEST_DISTANCE) != 0) {                    pickInfo.setClosestDistance(minDist);                }                if((flags & PickInfo.CLOSEST_INTERSECTION_POINT) != 0) {                    pickInfo.setClosestIntersectionPoint(closestIPnt);                }                return true;            }        }        	return false;           }                /**     * Check if the geometry component of this shape node under path     * intersects with the pickShape.     * This is an expensive method. It should only be called if and only     * if the path's bound intersects pickShape.       * @exception IllegalArgumentException if <code>path</code> is     * invalid.     */     boolean intersect(SceneGraphPath path,            PickShape pickShape, double[] dist) {                int flags;        PickInfo pickInfo = new PickInfo();                Transform3D localToVworld = path.getTransform();        if (localToVworld == null) {	    throw new IllegalArgumentException(J3dI18N.getString("Shape3DRetained3"));   	}        pickInfo.setLocalToVWorldRef( localToVworld);        //System.err.println("Shape3DRetained.intersect() : ");        if (dist == null) {            //System.err.println("      no dist request ....");            return intersect(pickInfo, pickShape, 0);        }                flags = PickInfo.CLOSEST_DISTANCE;        if (intersect(pickInfo, pickShape, flags)) {            dist[0] = pickInfo.getClosestDistance();            return true;        }                return false;                }    /**     * This sets the immedate mode context flag     */      void setInImmCtx(boolean inCtx) {        inImmCtx = inCtx;    }    /**     * This gets the immedate mode context flag     */      boolean getInImmCtx() {        return (inImmCtx);    }    /**     * This updates the mirror shape to reflect the state of the     * real shape3d.     */    private void initMirrorShape3D(SetLiveState s, Shape3DRetained ms, int index) {	// New 1.2.1 code	        ms.inBackgroundGroup = inBackgroundGroup;        ms.geometryBackground = geometryBackground;	ms.source = source;	ms.universe = universe;	// Has to be false. We have a instance of mirror for every link to the shape3d.	ms.inSharedGroup = false;	ms.locale = locale;	ms.parent = parent;	// New 1.3.2	// Used when user supplied their own bounds for transparency sorting	// GeometryAtom uses this to change how it computes the centroid	ms.boundsAutoCompute = boundsAutoCompute;	ms.localBounds = localBounds;	// End new 1.3.2        OrderedPath op = (OrderedPath)s.orderedPaths.get(index);        if (op.pathElements.size() == 0) {            ms.orderedPath = null;        } else {            ms.orderedPath = op;/*            System.err.println("initMirrorShape3D ms.orderedPath ");            ms.orderedPath.printPath();*/        }	// all mirror shapes point to the same transformGroupRetained	// for the static transform	ms.staticTransform = staticTransform;	ms.appearanceOverrideEnable = appearanceOverrideEnable;		ms.geometryList = geometryList;		// Assign the parent of this mirror shape node	ms.sourceNode = this;        if (this instanceof OrientedShape3DRetained) {            OrientedShape3DRetained os = (OrientedShape3DRetained)this;            OrientedShape3DRetained oms = (OrientedShape3DRetained)ms;            oms.initAlignmentMode(os.mode);            oms.initAlignmentAxis(os.axis);            oms.initRotationPoint(os.rotationPoint);	    oms.initConstantScaleEnable(os.constantScale);	    oms.initScale(os.scaleFactor);        }	    }    void updateImmediateMirrorObject(Object[] objs) {	int component = ((Integer)objs[1]).intValue();	GeometryArrayRetained ga;		Shape3DRetained[] msArr = (Shape3DRetained[]) objs[2];	int i, j;	if ((component & APPEARANCE_CHANGED) != 0) {	    Object[] arg = (Object[])objs[3];	    int val = ((Integer)arg[1]).intValue();	    for ( i = msArr.length-1; i >=0; i--) {		msArr[i].appearance = (AppearanceRetained)arg[0];		msArr[i].changedFrequent = val;	    }	}	if ((component & APPEARANCEOVERRIDE_CHANGED) != 0) {	    Object[] arg = (Object[])objs[3];	    int val = ((Integer)arg[1]).intValue();	    for ( i = msArr.length-1; i >=0; i--) {		msArr[i].appearanceOverrideEnable = ((Boolean)arg[0]).booleanValue();		msArr[i].changedFrequent = val;	    }	}    }    /**     * Gets the bounding object of a node.     * @return the node's bounding object     */        Bounds getBounds() {        if(boundsAutoCompute) {	    // System.err.println("getBounds ---- localBounds is " + localBounds);	    if (cachedBounds!=null) {                return (Bounds) cachedBounds.clone();            }	    if(geometryList != null) {		BoundingBox bbox = new BoundingBox((Bounds) null);		GeometryRetained geometry;    		for(int i=0; i<geometryList.size(); i++) {		    geometry = (GeometryRetained) geometryList.get(i);		    if ((geometry != null) && 			(geometry.geoType != GeometryRetained.GEO_TYPE_NONE)) {			geometry.computeBoundingBox();			synchronized(geometry.geoBounds) {			    bbox.combine(geometry.geoBounds);			}		    }		}		return (Bounds) bbox;			    } else {		return null;            }	            } else {            return super.getBounds();        }    }         Bounds getEffectiveBounds() {        if(boundsAutoCompute) {	    return getBounds();	}	else {	    return super.getEffectiveBounds();	}    }            /**     * ONLY needed for SHAPE, MORPH, and LINK node type.     * Compute the combine bounds of bounds and its localBounds.     */    void computeCombineBounds(Bounds bounds) {	        if(boundsAutoCompute) {            if(geometryList != null) {                GeometryRetained geometry;                BoundingBox bbox = null;                                if (staticTransform != null) {                    bbox = new BoundingBox((BoundingBox) null);                }                                    if (!VirtualUniverse.mc.cacheAutoComputedBounds) {                                        for(int i=0; i<geometryList.size(); i++) {                        geometry = (GeometryRetained) geometryList.get(i);                        if ((geometry != null) &&                                (geometry.geoType != GeometryRetained.GEO_TYPE_NONE)) {                            geometry.computeBoundingBox();                            // Should this be lock too ? ( MT safe  ? )                            synchronized(geometry.geoBounds) {                                if (staticTransform != null) {                                    bbox.set(geometry.geoBounds);                                    bbox.transform(staticTransform.transform);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -