Hi Dave,

    Here is an exmaple of how start/stopRenderer() works.
(works fine with v1.2.1 release)
It is a bug if startRendering() fail to start once stop.
In this case please send us a test case.

Thanks.

- Kelvin
---------------
Java 3D Team
Sun Microsystems Inc.

>MIME-Version: 1.0
>Content-Transfer-Encoding: 7bit
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
>Date: Wed, 14 Mar 2001 19:52:17 -0500
>From: David <[EMAIL PROTECTED]>
>Subject: [JAVA3D] Stopping rendering and restarting
>To: [EMAIL PROTECTED]
>
>I am trying to figure out the best way to stop rendering, do some
>loading/etc and then restart rendering.  I want to do this at startup and
>for certain situations.  Specifically I want to free up the CPU cycles and
>not show partially built scenegraphs while loading.  I also want to replace
>the canvas with some other components during this time (a swing 2d animation
>for example, or splash image).
>
>I tried using canvas.stopRenderer() and canvas.startRenderer() but I can't
>seem to get it started once I stop it.  I looked at view.stopView() and the
>docs say this should not be used for flow control.  Detaching the main
>branchgroup is not what I want to do, since that leaves the renderer running
>flat out.
>
>Suggestions?
>
>Dave Yazel
>
>===========================================================================
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff JAVA3D-INTEREST".  For general help, send email to
>[EMAIL PROTECTED] and include in the body of the message "help".
/*
 *      @(#)StartStopRenderer.java 1.3 99/09/15 13:38:26
 *
 * Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import java.awt.*;
import java.awt.event.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;

class StartStopRendererPanel extends Panel implements ActionListener {
    private StartStopRenderer startStop;
    private Button stopButton;
    private Button startButton;
    private Button quitButton;

    public void actionPerformed (ActionEvent event) {
        Object target = event.getSource();

        if (target == stopButton) {
            startStop.stopInterpolators();
        }
        else if (target == startButton) {
            startStop.startInterpolators();
        }
        else if (target == quitButton) {
            System.exit(0);
        }
    }

    public void paint(Graphics g) {
        Dimension d = getSize();
        g.drawRect(0, 0, d.width - 1, d.height - 1);
    }

    public StartStopRendererPanel(StartStopRenderer startStop) {
        this.startStop = startStop;

        stopButton = new Button("Stop");
        startButton = new Button("Start");
        quitButton = new Button("Quit");

        stopButton.addActionListener(this);
        startButton.addActionListener(this);
        quitButton.addActionListener(this);

        setLayout(new FlowLayout());
        add(stopButton);
        add(startButton);
        add(quitButton);
    }
}

public class StartStopRenderer extends Frame {

    Canvas3D canvas = null;


    public BranchGroup createSceneGraph() {
        // Create the root of the branch graph
        BranchGroup objRoot = new BranchGroup();

        // Create a Transformgroup to scale all objects so they
        // appear in the scene.
        TransformGroup objScale = new TransformGroup();
        Transform3D t3d = new Transform3D();
        t3d.setScale(0.4);
        objScale.setTransform(t3d);
        objRoot.addChild(objScale);

        // Create the transform group node and initialize it to the
        // identity.  Enable the TRANSFORM_WRITE capability so that
        // our behavior code can modify it at runtime.  Add it to the
        // root of the subgraph.
        TransformGroup objTrans = new TransformGroup();
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        objScale.addChild(objTrans);

        // Create a simple shape leaf node, add it to the scene graph.
        objTrans.addChild(new ColorCube());

        // Create a new Behavior object that will perform the desired
        // operation on the specified transform object and add it into
        // the scene graph.
        Transform3D yAxis = new Transform3D();
        Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE,
                                        0, 0,
                                        4000, 0, 0,
                                        0, 0, 0);

        RotationInterpolator rotator =
            new RotationInterpolator(rotationAlpha, objTrans, yAxis,
                                     0.0f, (float) Math.PI*2.0f);
        BoundingSphere bounds =
            new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
        rotator.setSchedulingBounds(bounds);
        objTrans.addChild(rotator);

        return objRoot;
    }

    public void stopInterpolators() {
        canvas.stopRenderer();
    }

    public void startInterpolators() {
        canvas.startRenderer();
    }

    public StartStopRenderer() {
        canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());

        // Handle the close event
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent winEvent) {
                System.exit(0);
            }
        });

        StartStopRendererPanel startStopPanel
            = new StartStopRendererPanel(this);
        startStopPanel.setSize(0, 100);
        add("North", startStopPanel);
        add("Center", canvas);
        setTitle("Java3D: Canvas Start Stop Renderer Test");
        setSize(256, 256);
        setVisible(true);

        // Create a simple scene and attach it to the virtual universe
        BranchGroup scene = createSceneGraph();
        SimpleUniverse u = new SimpleUniverse(canvas);
        // This will move the ViewPlatform back a bit so the
        // objects in the scene can be viewed.
        u.getViewingPlatform().setNominalViewingTransform();

        u.addBranchGraph(scene);
    }

    public static void main(String[] args) {
        new StartStopRenderer();
    }
}

Reply via email to