Home > other >  Baidu's online code, about 3 d modeling, could you tell me the reason for the error?
Baidu's online code, about 3 d modeling, could you tell me the reason for the error?

Time:09-25

The Exception in the thread "main" Java. Lang. NullPointerException
The at javamodel. LoadModelDemo. LoadModel (LoadModelDemo. Java: 90)
The at javamodel. LoadModelDemo. CreateSceneGroup (LoadModelDemo. Java: 50)
The at javamodel. LoadModelDemo. & lt; init> (LoadModelDemo. Java: 39)
The at javamodel. Gamemain. & lt; init> (Gamemain. Java: 22)
The at javamodel. Gamemain. Main (Gamemain. Java: 15)
================================================================================================
Gamemain. Java main program entrance:

Package javamodel;

The import javax.mail. Swing. JFrame;
The import javax.mail. Swing. JPanel;

Public class Gamemain {

Private static int scrWidth=800;
Private static int scrHeight=600;
Private static int scrBitdepth=32;
Private JFrame gameFrame;
Private JPanel gamePanel;

Public static void main (String [] args) {
New Gamemain ();
}

Public Gamemain () {
ScreenManager screen=new ScreenManager (scrWidth scrHeight, scrBitdepth, "Java 3 d model");
Screen. SetWindowMode ();
GameFrame=screen. GetFrame ();
GamePanel=new LoadModelDemo (scrWidth scrHeight);
GameFrame. Add (gamePanel);
}

}
================================================================================================
LoadModelDemo. Java

Package javamodel;

Import the Java. The awt. BorderLayout.
Import the Java. The awt. GraphicsConfiguration;
Import the Java. IO. FileNotFoundException;

The import javax.mail. Media. J3d. Background;
The import javax.mail. Media. J3d. BoundingBox;
The import javax.mail. Media. J3d. BoundingSphere;
The import javax.mail. Media. J3d. BranchGroup;
The import javax.mail. Media. J3d. Canvas3D;
The import javax.mail. Media. J3d. The Transform3D;
The import javax.mail. Media. J3d. TransformGroup;
The import javax.mail. Swing. JPanel;
The import javax.mail. Vecmath. Point3d;
The import javax.mail. Vecmath. Vector3d;

The import com. Sun. J3d. Loaders. IncorrectFormatException;
The import com. Sun. J3d. Loaders. ParsingErrorException;
The import com. Sun. J3d) loaders) Scene;
The import com. Sun. J3d. Loaders. Objectfile. Objectfile;
The import com. Sun. J3d. Utils. Behaviors. Vp. OrbitBehavior;
The import com. Sun. J3d. Utils. Universe. SimpleUniverse;
The import com. Sun. J3d. Utils. Universe. ViewingPlatform;

Public class LoadModelDemo extends JPanel {
Private BranchGroup sceneBG;
Private SimpleUniverse universe;
Private BoundingSphere bounds;
Private double boundRadius=100;

Public LoadModelDemo (int width, int height) {
Enclosing setLayout (new BorderLayout ());
GraphicsConfiguration config=SimpleUniverse. GetPreferredConfiguration ();
Canvas3D canvas=new Canvas3D (config);
Canvas. SetSize (width, height);
This. The add (canvas, BorderLayout. CENTER);
Universe=new SimpleUniverse (canvas);
CreateSceneGroup ();
InitUserPosition ();
OrbitControls (canvas);
Universe. AddBranchGraph (sceneBG);
}

Public void createSceneGroup () {
SceneBG=new BranchGroup ();
Bounds=new BoundingSphere (new Point3d (0, 0), boundRadius);
AddBackground ();
TransformGroup [] objModel=new TransformGroup [4].
SceneBG. AddChild (objModel [0]=loadModel (" when/Liit. Obj ", ObjectFile. RESIZE, new Vector3d (5.4, 0, 0)));
SceneBG. AddChild (objModel [1]=loadModel (" when/Liit. Obj ", ObjectFile. REVERSE, new Vector3d (1.8, 0, 0)));
SceneBG. AddChild (objModel [2]=loadModel (" when/Liit. Obj ", ObjectFile TRIANGULATE, new Vector3d (1.8, 0, 0)));
SceneBG. AddChild (objModel [3]=loadModel (" when/Liit. Obj ", ObjectFile STRIPIFY, new Vector3d (5.4, 0, 0)));
SceneBG. AddChild (new CheckerFloor (.) getBG ());
//to compile and cache sceneBG related objects, if add other branches again after compilation will throw an exception
SceneBG.com from running ();
}

Public void addBackground () {
Background the back=new Background ();
Back. SetApplicationBounds (bounds);
Back. SetColor (0.17 f, f, 0.62 0.92 f);
SceneBG. AddChild (back);
}

Private void initUserPosition () {
//returns the current observation platform of virtual world
ViewingPlatform vp=universe. GetViewingPlatform ();
//get the coordinates of the observation platform branches take
TransformGroup steerTG=vp. GetViewPlatformTransform ();
The Transform3D t3d=new the Transform3D ();
SteerTG. GetTransform (t3d);
//set the observation point coordinates (0,5,20), look at coordinates (0, 0), specify the Y axis to the positive direction of extension direction of
,5,20 t3d. LookAt (new Point3d (0), new Point3d (0, 0), new Vector3d (0, 0));
T3d. Invert ();
SteerTG. SetTransform (t3d);
}

Private void orbitControls (Canvas3D canvas) {
OrbitBehavior orbit=new OrbitBehavior (canvas, OrbitBehavior REVERSE_ALL);
Orbit. SetSchedulingBounds (bounds);
ViewingPlatform vp=universe. GetViewingPlatform ();
The vp. SetViewPlatformBehavior (orbit);
}

Private TransformGroup loadModel (String filename, int flag, Vector3d translation) {
Scene loadScene=this. LoadFromFile (filename, flag);
The Transform3D t3d=new the Transform3D ();
T3d=this. RotateModel ();
T3d. SetScale (enclosing calcScaleFactor (loadScene getSceneGroup ()));
T3d. SetTranslation (translation); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related