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

📄 texturebyreference.java

📁 java 3d编程的一些例子源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $RCSfile: TextureByReference.java,v $ * * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistribution of source code must retain the above copyright *   notice, this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright *   notice, this list of conditions and the following disclaimer in *   the documentation and/or other materials provided with the *   distribution. * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * 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 MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF * USING, MODIFYING OR DISTRIBUTING THIS 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 THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed, licensed or * intended for use in the design, construction, operation or * maintenance of any nuclear facility. * * $Revision: 1.2 $ * $Date: 2006/02/14 19:26:20 $ * $State: Exp $ */package org.jdesktop.j3d.examples.texture_by_ref;import java.applet.Applet;import java.awt.*;import java.awt.event.*;import com.sun.j3d.utils.applet.MainFrame;import com.sun.j3d.utils.universe.*;import javax.media.j3d.*;import javax.vecmath.*;import java.awt.image.*;import com.sun.j3d.utils.image.TextureLoader;import javax.swing.*;import javax.swing.event.*;import org.jdesktop.j3d.examples.Resources;public class TextureByReference extends Applet implements ItemListener, ActionListener, ChangeListener {  // need reference to animation behavior  private AnimateTexturesBehavior animate;  // need reference to tetrahedron  private Tetrahedron tetra;    // the gui buttons   private JCheckBox flipB;  private JRadioButton texByRef;  private JRadioButton texByCopy;  private JRadioButton geomByRef;  private JRadioButton geomByCopy;  private JRadioButton img4ByteABGR;  private JRadioButton img3ByteBGR;  private JRadioButton imgIntARGB;  private JRadioButton imgCustomRGBA;  private JRadioButton imgCustomRGB;  private JRadioButton yUp;  private JRadioButton yDown;  private JButton animationB;  private JSlider frameDelay;    private SimpleUniverse universe = null;  // image files used for the Texture animation for the applet,  // or if no parameters are passed in for the application  public static final String[] defaultFiles = {    "resources/images/animation1.gif",    "resources/images/animation2.gif",    "resources/images/animation3.gif",    "resources/images/animation4.gif",    "resources/images/animation5.gif",    "resources/images/animation6.gif",    "resources/images/animation7.gif",    "resources/images/animation8.gif",    "resources/images/animation9.gif",    "resources/images/animation10.gif"};  private java.net.URL[] urls = null;    public TextureByReference() {  }   public TextureByReference(java.net.URL[] fnamesP) {     urls = fnamesP;   }  public void init() {    if (urls == null) {      urls = new java.net.URL[defaultFiles.length];      for (int i = 0; i < defaultFiles.length; i++) {            urls[i] = Resources.getResource(defaultFiles[i]);            if (urls[i] == null) {                System.err.println(defaultFiles[i] + " not found");                System.exit(1);            }            /*            try {	  urls[i] = new java.net.URL(getCodeBase().toString() + 				       defaultFiles[i]);	}	catch (java.net.MalformedURLException ex) {	  System.out.println(ex.getMessage());	  System.exit(1);	}             */      }    }    setLayout(new BorderLayout());    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();    Canvas3D canvas = new Canvas3D(config);    add("Center", canvas);    // create a simple scene graph and attach it to a simple universe    BranchGroup scene = createSceneGraph();    universe = new SimpleUniverse(canvas);    universe.getViewingPlatform().setNominalViewingTransform();    universe.addBranchGraph(scene);    // create the gui    JPanel gui = buildGui();        this.add("South", gui);  }    public void destroy() {	universe.cleanup();    }  public JPanel buildGui() {    flipB = new JCheckBox("flip image", true);    flipB.addItemListener(this);    javax.swing.Box flipBox = new javax.swing.Box(BoxLayout.Y_AXIS);    flipBox.add(flipB);    Component strut1 = flipBox.createVerticalStrut(flipB.getPreferredSize().height);    Component strut2 = flipBox.createVerticalStrut(flipB.getPreferredSize().height);    Component strut3 = flipBox.createVerticalStrut(flipB.getPreferredSize().height);    Component strut4 = flipBox.createVerticalStrut(flipB.getPreferredSize().height);    Component strut5 = flipBox.createVerticalStrut(flipB.getPreferredSize().height);    flipBox.add(strut1);    flipBox.add(strut2);    flipBox.add(strut3);    flipBox.add(strut4);    flipBox.add(strut5);    yUp = new JRadioButton("y up");    yUp.addActionListener(this);    yUp.setSelected(true);    yDown = new JRadioButton("y down");    yDown.addActionListener(this);    ButtonGroup yGroup = new ButtonGroup();    yGroup.add(yUp);    yGroup.add(yDown);    JLabel yLabel = new JLabel("Image Orientation:");    javax.swing.Box yBox = new javax.swing.Box(BoxLayout.Y_AXIS);    yBox.add(yLabel);    yBox.add(yUp);    yBox.add(yDown);    strut1 = yBox.createVerticalStrut(yUp.getPreferredSize().height);    strut2 = yBox.createVerticalStrut(yUp.getPreferredSize().height);    strut3 = yBox.createVerticalStrut(yUp.getPreferredSize().height);    yBox.add(strut1);    yBox.add(strut2);    yBox.add(strut3);    texByRef = new JRadioButton("by reference");    texByRef.addActionListener(this);    texByRef.setSelected(true);    texByCopy = new JRadioButton("by copy");    texByCopy.addActionListener(this);    ButtonGroup texGroup = new ButtonGroup();    texGroup.add(texByRef);    texGroup.add(texByCopy);    JLabel texLabel = new JLabel("Texture:*");    javax.swing.Box texBox = new javax.swing.Box(BoxLayout.Y_AXIS);    texBox.add(texLabel);    texBox.add(texByRef);    texBox.add(texByCopy);    strut1 = texBox.createVerticalStrut(texByRef.getPreferredSize().height);    strut2 = texBox.createVerticalStrut(texByRef.getPreferredSize().height);    strut3 = texBox.createVerticalStrut(texByRef.getPreferredSize().height);    texBox.add(strut1);    texBox.add(strut2);    texBox.add(strut3);    geomByRef = new JRadioButton("by reference");    geomByRef.addActionListener(this);    geomByRef.setSelected(true);    geomByCopy = new JRadioButton("by copy");    geomByCopy.addActionListener(this);    ButtonGroup geomGroup = new ButtonGroup();    geomGroup.add(geomByRef);    geomGroup.add(geomByCopy);    JLabel geomLabel = new JLabel("Geometry:");    javax.swing.Box geomBox = new javax.swing.Box(BoxLayout.Y_AXIS);    geomBox.add(geomLabel);    geomBox.add(geomByRef);    geomBox.add(geomByCopy);    strut1 = geomBox.createVerticalStrut(geomByRef.getPreferredSize().height);    strut2 = geomBox.createVerticalStrut(geomByRef.getPreferredSize().height);    strut3 = geomBox.createVerticalStrut(geomByRef.getPreferredSize().height);    geomBox.add(strut1);    geomBox.add(strut2);    geomBox.add(strut3);        img4ByteABGR = new JRadioButton("TYPE_4BYTE_ABGR");    img4ByteABGR.addActionListener(this);    img4ByteABGR.setSelected(true);    img3ByteBGR = new JRadioButton("TYPE_3BYTE_BGR");    img3ByteBGR.addActionListener(this);    imgIntARGB = new JRadioButton("TYPE_INT_ARGB");    imgIntARGB.addActionListener(this);    imgCustomRGBA = new JRadioButton("TYPE_CUSTOM RGBA");    imgCustomRGBA.addActionListener(this);    imgCustomRGB = new JRadioButton("TYPE_CUSTOM RGB");    imgCustomRGB.addActionListener(this);    ButtonGroup imgGroup = new ButtonGroup();    imgGroup.add(img4ByteABGR);    imgGroup.add(img3ByteBGR);    imgGroup.add(imgIntARGB);    imgGroup.add(imgCustomRGBA);    imgGroup.add(imgCustomRGB);    JLabel imgLabel = new JLabel("Image Type:*");    javax.swing.Box imgBox = new javax.swing.Box(BoxLayout.Y_AXIS);    imgBox.add(imgLabel);    imgBox.add(img4ByteABGR);    imgBox.add(img3ByteBGR);    imgBox.add(imgIntARGB);    imgBox.add(imgCustomRGBA);    imgBox.add(imgCustomRGB);    javax.swing.Box topBox = new javax.swing.Box(BoxLayout.X_AXIS);    topBox.add(flipBox);    topBox.add(texBox);    topBox.add(geomBox);    topBox.add(yBox);    Component strut = topBox.createRigidArea(new Dimension(10, 10));    topBox.add(strut);    topBox.add(imgBox);    frameDelay = new JSlider(0, 50, 0);    frameDelay.addChangeListener(this);    frameDelay.setSnapToTicks(true);    frameDelay.setPaintTicks(true);    frameDelay.setPaintLabels(true);    frameDelay.setMajorTickSpacing(10);    frameDelay.setMinorTickSpacing(1);    frameDelay.setValue(20);

⌨️ 快捷键说明

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