Esempio n. 1
0
  public void draw(DrawModel d) {
    view.detach();
    rotation.removeAllChildren();
    drawModel = d;
    if (drawModel.getPicture() == null) return;
    Integer i = 0;
    for (VisualShape v : drawModel.getPicture()) {
      TransformGroup shapeGroup = new TransformGroup();
      rotation.addChild(shapeGroup);
      BranchGroup faces = v.getFaces2(BranchGroup.class);
      BranchGroup edges = v.getEdges2(BranchGroup.class);
      BranchGroup text = v.getText2(BranchGroup.class);
      if (faces == null && edges == null) continue;
      i++;
      if (faces != null) {
        faces.detach();
        rotation.addChild(faces);
        faces.setPickable(true);
        faces.setUserData(v);
        faces.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
        faces.setName(i.toString());
      }
      if (edges != null) {
        edges.detach();
        rotation.addChild(edges);
        edges.setPickable(true);
        edges.setUserData(v);
        edges.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
        edges.setName(i.toString());
      }

      if (text != null) {
        text.detach();
        rotation.addChild(text);
        text.setPickable(false);
        if (text instanceof BranchGroup) {
          BranchGroup bg = (BranchGroup) text;
          for (int j = 0; j < bg.numChildren(); j++) {
            Node child = bg.getChild(j);
            if (child instanceof TransformGroup) {
              TransformGroup tg = (TransformGroup) child;
              tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
              tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
              textLabels.add(tg);
            }
          }
        }

        //        		edges.setUserData(v);
        //        		edges.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
        //         		edges.setName(i.toString());
      }
    }
    root.addChild(view);
  }
Esempio n. 2
0
  public DefaultUniverse() {
    super(
        createVWorldPlatform(),
        new Viewer(new Canvas3D(SimpleUniverse.getPreferredConfiguration())));

    // some useful parts of this universe
    // Viewer viewer = getViewer();
    // ViewingPlatform viewingPlatform = getViewingPlatform();
    // View view = viewer.getView();
    // ViewPlatform viewPlatform = viewingPlatform.getViewPlatform();
    // TransformGroup viewTransGroup = getViewingPlatform().getViewPlatformTransform();

    // set up the view
    getViewer().getView().setFrontClipPolicy(View.VIRTUAL_EYE);
    getViewer().getView().setBackClipDistance(BACK_CLIP);
    getViewer().getView().setFrontClipDistance(FRONT_CLIP);
    // set max frame rate to 50 so server can get in
    getViewer().getView().setMinimumFrameCycleTime(2);

    // TODO: I believe I can remove these calls
    PlatformGeometry pg = new PlatformGeometry();
    pg.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    getViewingPlatform().setPlatformGeometry(pg);

    getViewer().createAudioDevice();

    // set capabilities for the various branch groups
    mainSceneGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    mainSceneGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
    environmentGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    environmentGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
    behaviorGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    behaviorGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
    terrainGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    terrainGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);
    terrainGroup.setCapability(BranchGroup.ALLOW_DETACH);
    terrainGroup.setUserData("Terrain Group");

    // initialise the sound system
    // SoundEngine mt = new SoundEngine();
    // behaviorGroup.addChild(mt);

    // put a sky in place
    sky.setApplicationBounds(Utils3D.defaultBounds);
    environmentGroup.addChild(sky);

    // Create ambient light	and add it
    Color3f alColor = new Color3f(0.6f, 0.6f, 0.6f);
    ambLight = new AmbientLight(true, alColor);
    ambLight.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
    ambLight.setInfluencingBounds(Utils3D.defaultBounds);
    environmentGroup.addChild(ambLight);

    // Create sun light and add it
    Color3f slColor = new Color3f(1.0f, 1.0f, 1.0f);
    sunLight = new DirectionalLight(slColor, new Vector3f(0.2f, -1.0f, -0.2f));
    sunLight.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_WRITE);
    sunLight.setInfluencingBounds(Utils3D.defaultBounds);
    environmentGroup.addChild(sunLight);

    // Add the fog
    fog.setCapability(Fog.ALLOW_INFLUENCING_BOUNDS_WRITE);
    environmentGroup.addChild(fog);

    nightClip.setApplicationBounds(Utils3D.defaultBounds);
    fogClip.setApplicationBounds(Utils3D.defaultBounds);
    nightClipGroup.addChild(nightClip);
    nightClipGroup.setCapability(BranchGroup.ALLOW_DETACH);
    fogClipGroup.addChild(fogClip);
    fogClipGroup.setCapability(BranchGroup.ALLOW_DETACH);

    // initialise the rain model
    // Color3f rainColor = new Color3f(0.6f, 0.6f, 0.65f);
    // Vector3f windVector = new Vector3f(0.2f, 0f, 0f);
    // rainyModel = new RainyArea(14, 0, 25000, rainColor, 4.5f, 0.8f, 50, windVector, 80f, 80f,
    // 20f, 20000);
    // rainyModel.hoverOver(getViewingPlatform().getViewPlatformTransform());
    // environmentGroup.addChild(rainyModel);

    mainSceneGroup.setCapability(BranchGroup.ALLOW_DETACH);
    environmentGroup.setCapability(BranchGroup.ALLOW_DETACH);
    behaviorGroup.setCapability(BranchGroup.ALLOW_DETACH);

    addBranchGraph(mainSceneGroup);
    addBranchGraph(environmentGroup);
    addBranchGraph(behaviorGroup);
    addBranchGraph(terrainGroup);
  }