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

📄 mytext3d.java

📁 java 3d 系列源码
💻 JAVA
字号:
//MyText3D.java
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import java.awt.geom.Line2D;
import java.awt.geom.QuadCurve2D;
import java.awt.Font;
import java.awt.GraphicsConfiguration;
public class MyText3D extends Applet {
  public BranchGroup createSceneGraph() {
    BranchGroup objRoot=new BranchGroup();
    Transform3D t=new Transform3D();
    t.setScale(0.2);
    //t.setRotation(new Quat4f(0.78f,0.78f,0.78f,0.0f));
    TransformGroup objTrans=new TransformGroup(t);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRoot.addChild(objTrans);
    
    BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
    
    Color3f bgColor=new Color3f(0.0f,0.0f,0.0f);
    Background bg=new Background(bgColor);
      bg.setApplicationBounds(bounds);
    objRoot.addChild(bg);
    
    Color3f directionalColor=new Color3f(1.0f,1.0f,1.0f);
    Vector3f vec=new Vector3f(1.f,1.f,-1.0f);
    DirectionalLight directionalLight=new DirectionalLight(directionalColor,vec);
    directionalLight.setInfluencingBounds(bounds);
    objRoot.addChild(directionalLight);
    
    String text="清华大学";
    
    FontExtrusion fe0=new FontExtrusion();
    
    QuadCurve2D.Double curve=new QuadCurve2D.Double();
    curve.setCurve(0,0,0.2,0.05,0.4,0);
    FontExtrusion fe1=new FontExtrusion();
    fe1.setExtrusionShape(curve);
    
    Font3D f3d=new Font3D(new Font("宋体",Font.PLAIN,1),fe0);
    Text3D txt=new Text3D(f3d,text,new Point3f(0.0f,0.0f,6.0f),Text3D.ALIGN_CENTER,Text3D.PATH_RIGHT);
    Shape3D sh=new Shape3D();
    Appearance app=new Appearance();
    Material m=new Material();
    m.setDiffuseColor(new Color3f(1.0f,1.0f,0.0f));
    app.setMaterial(m);
    sh.setGeometry(txt);
    sh.setAppearance(app);
    objTrans.addChild(sh);
    
    MouseRotate behavior = new MouseRotate();
    behavior.setTransformGroup(objTrans);
    objRoot.addChild(behavior);
    behavior.setSchedulingBounds(bounds);

    MouseZoom behavior2 = new MouseZoom();
    behavior2.setTransformGroup(objTrans);
    objRoot.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    MouseTranslate behavior3 = new MouseTranslate();
    behavior3.setTransformGroup(objTrans);
    objRoot.addChild(behavior3);
    behavior3.setSchedulingBounds(bounds);
    return objRoot;
  }
  
  public MyText3D() {
    setLayout(new BorderLayout());
    //GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D c=new Canvas3D(config);
    add("Center",c);
    BranchGroup scene=createSceneGraph();
    SimpleUniverse u=new SimpleUniverse(c);
	u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(scene);
  }
  
  public static void main(String[] args) {
    new MainFrame(new MyText3D(),400,300);
  }
}//end of MyText3D.java

⌨️ 快捷键说明

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