コード例 #1
0
ファイル: ObjectViewer.java プロジェクト: ppurka/sage
  public ObjectViewer(URL url) {
    setLayout(new BorderLayout());
    Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
    add("Center", canvas3D);

    BoundingSphere bounds = new BoundingSphere(new Point3d(), 1000);
    BranchGroup root = new BranchGroup();
    BranchGroup scene = createSceneGraph(url);
    scene.setBoundsAutoCompute(true);
    System.out.println(scene.getBounds());
    BoundingSphere sceneBounds = new BoundingSphere(scene.getBounds());

    SimpleUniverse univ = new SimpleUniverse(canvas3D);
    ViewingPlatform view = univ.getViewingPlatform();
    view.setNominalViewingTransform();

    Transform3D t = new Transform3D();
    TransformGroup viewTransform = view.getViewPlatformTransform();

    t.set(new Vector3d(0, 0, 3 * sceneBounds.getRadius()));
    viewTransform.setTransform(t);

    BranchGroup lights = new BranchGroup();
    Light light = new AmbientLight();
    light.setInfluencingBounds(bounds);
    lights.addChild(light);
    light = new DirectionalLight();
    light.setInfluencingBounds(bounds);
    lights.addChild(light);
    root.addChild(lights);

    TransformGroup tg = new TransformGroup();
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tg.addChild(scene);

    root.addChild(tg);

    MouseRotate mouse = new MouseRotate();
    mouse.setTransformGroup(tg);
    mouse.setSchedulingBounds(bounds);
    root.addChild(mouse);

    MouseZoom mousezoom = new MouseZoom();
    mousezoom.setTransformGroup(tg);
    mousezoom.setSchedulingBounds(bounds);
    root.addChild(mousezoom);

    Background background = new Background(1, 1, 1);
    background.setApplicationBounds(bounds);
    root.addChild(background);

    root.compile();

    univ.addBranchGraph(root);
  }
コード例 #2
0
ファイル: KainCorak.java プロジェクト: danurwenda/JB4
  public void init() {
    // initialize our SimpleUniverse -> u
    u = new SimpleUniverse(this);

    // set viewing platform (the camera)
    vp = u.getViewingPlatform();
    view = u.getViewer().getView();
    view.setScreenScalePolicy(View.SCALE_EXPLICIT);
    view.setBackClipPolicy(View.VIRTUAL_EYE);
    view.setFrontClipPolicy(View.VIRTUAL_EYE);
    view.setBackClipDistance(FARTHEST);
    view.setFrontClipDistance(CLOSEST);
    fieldOfView = view.getFieldOfView();
    view.setDepthBufferFreezeTransparent(false);
    cameraTG = vp.getViewPlatformTransform();
    cameraT3D = new Transform3D();
    cameraTG.getTransform(cameraT3D);

    // initialize root of our scene -> BranchGroup kainBG and TransformGroup kainTG
    kainBG = new BranchGroup();
    kainBG.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
    kainBG.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    kainBG.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);

    background = new Background(new Color3f(0, 0, 0));
    background.setCapability(Background.ALLOW_COLOR_READ);
    background.setCapability(Background.ALLOW_COLOR_WRITE);
    background.setCapability(Background.ALLOW_IMAGE_READ);
    background.setCapability(Background.ALLOW_IMAGE_WRITE);
    background.setApplicationBounds(new BoundingSphere(new Point3d(0, 0, 0), FARTHEST));
    background.setImageScaleMode(Background.SCALE_FIT_ALL);
    kainBG.addChild(background);

    kainTG = new TransformGroup();
    kainTG.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
    kainTG.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
    kainBG.addChild(kainTG);

    // branch for axis lines
    axisBG = new BranchGroup();
    axisBG.setCapability(BranchGroup.ALLOW_DETACH);
    axisLines = createAxisLines();
    axisBG.addChild(axisLines);

    // branch for ground
    groundBG = new BranchGroup();
    groundBG.setCapability(BranchGroup.ALLOW_DETACH);
    ground = createGround();
    groundBG.addChild(ground);

    kainBG.compile();
    u.addBranchGraph(kainBG);
    currentAppearance = Appearance3DChangerCookie.Appearance.WIREFRAME;
  }
コード例 #3
0
ファイル: DefaultUniverse.java プロジェクト: philjord/3DTools
 public static ViewingPlatform createVWorldPlatform() {
   ViewingPlatform viewingPlatform = new ViewingPlatform();
   TransformGroup viewTransGroup = viewingPlatform.getViewPlatformTransform();
   viewTransGroup.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
   return viewingPlatform;
 }