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

📄 canvas3d.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	ctx = null;	// must be after removeCtx() because 	// it will free graphics2D textureID	graphics2D = null;	super.removeNotify();        // Release and clear.        for (Container container : containerParentList) {            container.removeComponentListener(eventCatcher);            container.removeComponentListener(canvasViewEventCatcher);        }        containerParentList.clear();        this.removeComponentListener(eventCatcher);        this.removeComponentListener(canvasViewEventCatcher);	if (eventCatcher != null) {	    this.removeFocusListener(eventCatcher);	    this.removeKeyListener(eventCatcher);	    this.removeMouseListener(eventCatcher);	    this.removeMouseMotionListener(eventCatcher);	    this.removeMouseWheelListener(eventCatcher);	    eventCatcher.reset();	}	if (windowParent != null) {	    windowParent.removeWindowListener(eventCatcher);	    windowParent.requestFocus();	}        added = false;	if (rdr != null) {            // Issue 84: Send a message to MC to restart renderer            VirtualUniverse.mc.postRequest(MasterControl.START_RENDERER, rdr);            while (rdr.userStop) {                MasterControl.threadYield();            }	}        // Fix for issue 102 removing strong reference and avoiding memory leak        // due retention of parent container        this.windowParent = null;    }    void allocateCanvasId() {        if (!canvasIdAlloc) {            canvasId = VirtualUniverse.mc.getCanvasId();            canvasBit = 1 << canvasId;            canvasIdAlloc = true;        }    }     void freeCanvasId() {        if (canvasIdAlloc) {            VirtualUniverse.mc.freeCanvasId(canvasId);            canvasBit = 0;            canvasId = 0;            canvasIdAlloc = false;        }    }     // This decides if the canvas is active    void evaluateActive() {	// Note that no need to check for isRunning, we want	// view register in order to create scheduler in pure immedite mode	// Also we can't use this as lock, otherwise there is a	// deadlock where updateViewCache get a lock of this and        // get a lock of this component. But Container 	// remove will get a lock of this component follows by evaluateActive.	synchronized (evaluateLock) {	    if ((visible || manualRendering) && firstPaintCalled) {		if (!active) {		    active = true;		    if (pendingView != null) {			pendingView.evaluateActive();		    } 		} else {		    if ((pendingView != null) &&			!pendingView.activeStatus) {			pendingView.evaluateActive();		    } 		}	    } else {		if (active) {		    active = false;		    if (view != null) {			view.evaluateActive();		    }		} 	    }	}		if ((view != null) && (!active)) {	    VirtualUniverse u = view.universe;	    if ((u != null) && !u.isSceneGraphLock) {		u.waitForMC();	    }	}    }    void setFrustumPlanes(Vector4d[] planes) {		if(VirtualUniverse.mc.viewFrustumCulling) {	    /* System.err.println("Canvas3D.setFrustumPlanes()"); */	    viewFrustum.set(planes);	}    }    /**     * Retrieve the Screen3D object that this Canvas3D is attached to.     * If this Canvas3D is an off-screen buffer, a new Screen3D object     * is created corresponding to the off-screen buffer.     * @return the 3D screen object that this Canvas3D is attached to     */    public Screen3D getScreen3D() {	return screen;    }    /**     * Get the immediate mode 3D graphics context associated with     * this Canvas3D.  A new graphics context object is created if one does     * not already exist.     * @return a GraphicsContext3D object that can be used for immediate     * mode rendering to this Canvas3D.     */    public GraphicsContext3D getGraphicsContext3D() {	synchronized(gfxCreationLock) {	    if (graphicsContext3D == null)		graphicsContext3D = new GraphicsContext3D(this);	}	return graphicsContext3D;    }    /**     * Get the 2D graphics object associated with     * this Canvas3D.  A new 2D graphics object is created if one does     * not already exist.     *     * @return a Graphics2D object that can be used for Java 2D     * rendering into this Canvas3D.     *     * @since Java 3D 1.2     */    public J3DGraphics2D getGraphics2D() {	synchronized(gfxCreationLock) {	    if (graphics2D == null)		graphics2D = new J3DGraphics2DImpl(this);	}	return graphics2D;    }    /**     * This routine is called by the Java 3D rendering loop after clearing     * the canvas and before any rendering has been done for this frame.     * Applications that wish to perform operations in the rendering loop,     * prior to any actual rendering may override this function.     *     * <p>     * Updates to live Geometry, Texture, and ImageComponent objects     * in the scene graph are not allowed from this method.     *     * <p>     * NOTE: Applications should <i>not</i> call this method.     */    public void preRender() {	// Do nothing; the user overrides this to cause some action    }    /**     * This routine is called by the Java 3D rendering loop after completing     * all rendering to the canvas for this frame and before the buffer swap.     * Applications that wish to perform operations in the rendering loop,     * following any actual rendering may override this function.     *     * <p>     * Updates to live Geometry, Texture, and ImageComponent objects     * in the scene graph are not allowed from this method.     *     * <p>     * NOTE: Applications should <i>not</i> call this method.     */    public void postRender() {	// Do nothing; the user overrides this to cause some action    }    /**     * This routine is called by the Java 3D rendering loop after completing     * all rendering to the canvas, and all other canvases associated with     * this view, for this frame following the buffer swap.     * Applications that wish to perform operations at the very     * end of the rendering loop may override this function.     * In off-screen mode, all rendering is copied to the off-screen     * buffer before this method is called.     *     * <p>     * Updates to live Geometry, Texture, and ImageComponent objects     * in the scene graph are not allowed from this method.     *     * <p>     * NOTE: Applications should <i>not</i> call this method.     */    public void postSwap() {	// Do nothing; the user overrides this to cause some action    }    /**     * This routine is called by the Java 3D rendering loop during the     * execution of the rendering loop.  It is called once for each     * field (i.e., once per frame on     * a mono system or once each for the right eye and left eye on a     * two-pass stereo system.  This is intended for use by applications that     * want to mix retained/compiled-retained mode rendering with some     * immediate mode rendering.  Applications that wish to perform     * operations during the rendering loop, may override this     * function.     *     * <p>     * Updates to live Geometry, Texture, and ImageComponent objects     * in the scene graph are not allowed from this method.     *     * <p>     * NOTE: Applications should <i>not</i> call this method.     * <p>     *     * @param fieldDesc field description, one of: FIELD_LEFT, FIELD_RIGHT or     * FIELD_ALL.  Applications that wish to work correctly in stereo mode     * should render the same image for both FIELD_LEFT and FIELD_RIGHT calls.     * If Java 3D calls the renderer with FIELD_ALL then the immediate mode     * rendering only needs to be done once.     */    public void renderField(int fieldDesc) {	// Do nothing; the user overrides this to cause some action    }    /**     * Stop the Java 3D renderer on this Canvas3D object.  If the     * Java 3D renderer is currently running, the rendering will be     * synchronized before being stopped.  No further rendering will be done     * to this canvas by Java 3D until the renderer is started again.     * In pure immediate mode this method should be called prior to adding     * this canvas to an active View object.     *     * @exception IllegalStateException if this Canvas3D is in     * off-screen mode.     */    public final void stopRenderer() {        // Issue 131: renderer can't be stopped only if it is an offscreen,        // manual canvas. Otherwise, it has to be seen as an onscreen canvas.	if (manualRendering)	    throw new IllegalStateException(J3dI18N.getString("Canvas3D14"));	if (isRunning) {	    VirtualUniverse.mc.postRequest(MasterControl.STOP_RENDERER, this);	    isRunning = false;	}    }    /**     * Start the Java 3D renderer on this Canvas3D object.  If the     * Java 3D renderer is not currently running, any rendering to other     * Canvas3D objects sharing the same View will be synchronized before this     * Canvas3D's renderer is (re)started.  When a Canvas3D is created, it is     * initially marked as being started.  This means that as soon as the     * Canvas3D is added to an active View object, the rendering loop will     * render the scene graph to the canvas.     */    public final void startRenderer() {        // Issue 260 : ignore attempt to start renderer if fatal error        if (fatalError) {            return;        }	if (!isRunning) {	    VirtualUniverse.mc.postRequest(MasterControl.START_RENDERER, this);	    isRunning = true;	    redraw();	}    }    /**     * Retrieves the state of the renderer for this Canvas3D object.     * @return the state of the renderer     *     * @since Java 3D 1.2     */    public final boolean isRendererRunning() {	return isRunning;    }    // Returns the state of the fatal error flag    boolean isFatalError() {        return fatalError;    }    // Sets the fatal error flag to true; stop the renderer for this canvas    void setFatalError() {        fatalError = true;	if (isRunning) {            isRunning = false;            if (!manualRendering) {                VirtualUniverse.mc.postRequest(MasterControl.STOP_RENDERER, this);            }	}    }    /**     * Retrieves a flag indicating whether this Canvas3D is an     * off-screen canvas.     *     * @return <code>true</code> if this Canvas3D is an off-screen canvas;     * <code>false</code> if this is an on-screen canvas.     *     * @since Java 3D 1.2     */    public boolean isOffScreen() {	return offScreen;    }    /**     * Sets the off-screen buffer for this Canvas3D.  The specified     * image is written into by the Java 3D renderer.  The size of the     * specified ImageComponent determines the size, in pixels, of     * this Canvas3D--the size inherited from Component is ignored.     * <p>     * NOTE: the size, physical width, and physical height of the associated     * Screen3D must be set explicitly prior to rendering.     * Failure to do so will result in an exception.     * <p>     *     * @param buffer the image component that will be rendered into by     * subsequent calls to renderOffScreenBuffer. The image component must not     * be part of a live scene graph, nor may it subsequently be made part of a     * live scene graph while being used as an off-screen buffer; an     * IllegalSharingException is thrown in such cases. The buffer may be null,     * indicating that the previous off-screen buffer is released without a new     * buffer being set.     *     * @exception IllegalStateException if this Canvas3D is not in     * off-screen mode.     *     * @exception RestrictedAccessException if an off-screen rendering     * is in process for this Canvas3D.     *     * @exception IllegalSharingException if the specified Ima

⌨️ 快捷键说明

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