Пример #1
0
 private void addFloor() {
   final Box floor = new Box("floor", Vector3.ZERO, 100, 5, 100);
   floor.setTranslation(0, -5, 0);
   final TextureState ts = new TextureState();
   ts.setTexture(
       TextureManager.load("models/obj/pitcher.jpg", Texture.MinificationFilter.Trilinear, true));
   floor.setRenderState(ts);
   floor.getSceneHints().setPickingHint(PickingHint.Pickable, false);
   floor.setModelBound(new BoundingBox());
   _root.attachChild(floor);
 }
  private Node createModel() {
    final Node node = new Node("Node");

    final Box box = new Box("Box", new Vector3(), 5, 5, 5);
    box.setModelBound(new BoundingBox());
    box.setTranslation(new Vector3(-3, 0, 0));
    box.setRandomColors();
    node.attachChild(box);

    final Teapot teapot = new Teapot("Teapot");
    teapot.setScale(2.0);
    teapot.setTranslation(new Vector3(3, 0, 0));
    node.attachChild(teapot);

    final Torus torus = new Torus("Torus", 128, 128, 2, 4);
    torus.setTranslation(new Vector3(-8, 3, 0));
    node.attachChild(torus);

    return node;
  }
Пример #3
0
  private void addObjects() {
    final Box box1 = new Box("box", Vector3.ZERO, 5, 15, 5);
    box1.setTranslation(0, box1.getYExtent(), 0);
    TextureState ts = new TextureState();
    ts.setTexture(
        TextureManager.load("images/skybox/1.jpg", Texture.MinificationFilter.Trilinear, true));
    box1.setRenderState(ts);
    box1.getSceneHints().setPickingHint(PickingHint.Pickable, true);
    box1.setModelBound(new BoundingBox());

    final Node base = new Node();
    base.setTranslation(0, 0, 0);
    base.attachChild(box1);
    _root.attachChild(base);

    final Sphere sphere = new Sphere("sphere", Vector3.ZERO, 16, 16, 8);
    ts = new TextureState();
    ts.setTexture(
        TextureManager.load(
            "images/water/dudvmap.png", Texture.MinificationFilter.Trilinear, true));
    sphere.setRenderState(ts);
    sphere.getSceneHints().setPickingHint(PickingHint.Pickable, true);
    sphere.setModelBound(new BoundingSphere());

    final Node joint = new Node();
    joint.setTranslation(0, sphere.getRadius() + 2 * box1.getYExtent(), 0);
    joint.attachChild(sphere);
    base.attachChild(joint);

    final Box box2 = new Box("box", Vector3.ZERO, 5, 15, 5);
    box2.setTranslation(0, box2.getYExtent(), 0);
    ts = new TextureState();
    ts.setTexture(
        TextureManager.load("images/skybox/3.jpg", Texture.MinificationFilter.Trilinear, true));
    box2.setRenderState(ts);
    box2.getSceneHints().setPickingHint(PickingHint.Pickable, true);
    box2.setModelBound(new BoundingBox());

    final Node arm = new Node();
    arm.setTranslation(0, sphere.getRadius(), 0);
    arm.attachChild(box2);
    joint.attachChild(arm);

    // auto select the joint
    _root.updateGeometricState(0);
    manager.setSpatialTarget(joint);
  }
  @Override
  protected void initExample() {
    _canvas.setTitle("Various size imposters - Example");

    _canvas.getCanvasRenderer().getCamera().setLocation(new Vector3(0, 60, 80));
    _canvas.getCanvasRenderer().getCamera().lookAt(new Vector3(), Vector3.UNIT_Y);

    final BasicText keyText =
        BasicText.createDefaultTextLabel("Text", "[SPACE] Switch imposters off");
    keyText.getSceneHints().setRenderBucketType(RenderBucketType.Ortho);
    keyText.getSceneHints().setLightCombineMode(LightCombineMode.Off);
    keyText.setTranslation(new Vector3(0, 20, 0));
    _root.attachChild(keyText);

    final Box box = new Box("Box", new Vector3(), 150, 1, 150);
    box.setModelBound(new BoundingBox());
    box.setTranslation(new Vector3(0, -10, 0));
    _root.attachChild(box);

    final QuadImposterNode imposter0 =
        new QuadImposterNode(
            "Imposter1", 256, 256, _settings.getDepthBits(), _settings.getSamples(), _timer);
    imposter0.setRedrawRate(0.0); // No timed update
    imposter0.setCameraAngleThreshold(1.0 * MathUtils.DEG_TO_RAD);
    imposter0.setCameraDistanceThreshold(0.1);
    _root.attachChild(imposter0);

    final Node scene1 = createModel();
    scene1.setTranslation(0, 0, 0);
    imposter0.attachChild(scene1);

    final QuadImposterNode imposter1 =
        new QuadImposterNode(
            "Imposter1", 128, 128, _settings.getDepthBits(), _settings.getSamples(), _timer);
    imposter1.setRedrawRate(0.0); // No timed update
    imposter1.setCameraAngleThreshold(1.0 * MathUtils.DEG_TO_RAD);
    imposter1.setCameraDistanceThreshold(0.1);
    _root.attachChild(imposter1);

    final Node scene2 = createModel();
    scene2.setTranslation(-15, 0, -25);
    imposter1.attachChild(scene2);

    final QuadImposterNode imposter2 =
        new QuadImposterNode(
            "Imposter2", 64, 64, _settings.getDepthBits(), _settings.getSamples(), _timer);
    imposter2.setRedrawRate(0.0); // No timed update
    imposter2.setCameraAngleThreshold(1.0 * MathUtils.DEG_TO_RAD);
    imposter2.setCameraDistanceThreshold(0.1);
    _root.attachChild(imposter2);

    final Node scene3 = createModel();
    scene3.setTranslation(15, 0, -25);
    imposter2.attachChild(scene3);

    _logicalLayer.registerTrigger(
        new InputTrigger(
            new KeyPressedCondition(Key.SPACE),
            new TriggerAction() {
              public void perform(
                  final Canvas source, final TwoInputStates inputStates, final double tpf) {
                showImposter = !showImposter;
                if (showImposter) {
                  _root.detachChild(scene1);
                  _root.detachChild(scene2);
                  _root.detachChild(scene3);
                  imposter0.attachChild(scene1);
                  imposter1.attachChild(scene2);
                  imposter2.attachChild(scene3);
                  _root.attachChild(imposter0);
                  _root.attachChild(imposter1);
                  _root.attachChild(imposter2);

                  keyText.setText("[SPACE] Switch imposters off");
                } else {
                  _root.detachChild(imposter0);
                  _root.detachChild(imposter1);
                  _root.detachChild(imposter2);
                  _root.attachChild(scene1);
                  _root.attachChild(scene2);
                  _root.attachChild(scene3);

                  keyText.setText("[SPACE] Switch imposters on");
                }
              }
            }));

    final TextureState ts = new TextureState();
    ts.setEnabled(true);
    ts.setTexture(
        TextureManager.load(
            "images/ardor3d_white_256.jpg", Texture.MinificationFilter.Trilinear, true));

    final MaterialState ms = new MaterialState();
    ms.setColorMaterial(ColorMaterial.Diffuse);
    _root.setRenderState(ms);

    _root.setRenderState(ts);

    _root.acceptVisitor(new UpdateModelBoundVisitor(), false);
  }