Exemple #1
0
 /**
  * @return a Text with {@link #DEFAULT_FONT} and correct blend state
  * @param name name of the spatial
  */
 public static BasicText createDefaultTextLabel(final String name, final String initialText) {
   final BasicText text = new BasicText(name, initialText);
   text.setCullHint(Spatial.CullHint.Never);
   text.setRenderState(getDefaultFontTextureState());
   text.setRenderState(getFontBlend());
   return text;
 }
  @Override
  protected void initExample() {
    _canvas.setTitle("Degenerate vs MultiStrip Example");

    t = BasicText.createDefaultTextLabel("Text", "[SPACE] MultiStrip Mesh");
    t.getSceneHints().setRenderBucketType(RenderBucketType.Ortho);
    t.getSceneHints().setLightCombineMode(LightCombineMode.Off);
    t.setTranslation(new Vector3(0, 20, 0));
    _root.attachChild(t);

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

    final double maxSize = Math.max(xSize, ySize);
    final double requiredDistance =
        (maxSize / 2)
            / Math.tan(
                _canvas.getCanvasRenderer().getCamera().getFovY() * MathUtils.DEG_TO_RAD * 0.5);

    final Mesh multiStripMesh = createMultiStripMesh();
    multiStripMesh.setRenderState(ts);
    multiStripMesh.updateModelBound();
    multiStripMesh.setTranslation(-xSize * 0.5, -ySize * 0.5, -requiredDistance);
    _root.attachChild(multiStripMesh);

    final Mesh degenerateStripMesh = createDegenerateStripMesh();
    degenerateStripMesh.setRenderState(ts);
    degenerateStripMesh.updateModelBound();
    degenerateStripMesh.setTranslation(-xSize * 0.5, -ySize * 0.5, -requiredDistance);
    _root.attachChild(degenerateStripMesh);

    degenerateStripMesh.getSceneHints().setCullHint(CullHint.Always);

    _logicalLayer.registerTrigger(
        new InputTrigger(
            new KeyPressedCondition(Key.SPACE),
            new TriggerAction() {
              public void perform(
                  final Canvas source, final TwoInputStates inputStates, final double tpf) {
                showDegenerateMesh = !showDegenerateMesh;
                if (showDegenerateMesh) {
                  t.setText("[SPACE] Degenerate Mesh");
                  multiStripMesh.getSceneHints().setCullHint(CullHint.Always);
                  degenerateStripMesh.getSceneHints().setCullHint(CullHint.Inherit);
                } else {
                  t.setText("[SPACE] MultiStrip Mesh");
                  multiStripMesh.getSceneHints().setCullHint(CullHint.Inherit);
                  degenerateStripMesh.getSceneHints().setCullHint(CullHint.Always);
                }
              }
            }));
  }
  @Override
  protected void initWindow() {
    _canvas.setTitle("Shapes Example");

    wrapCount = 5;
    addMesh(new Arrow("Arrow", 3, 1));
    addMesh(new AxisRods("AxisRods", true, 3, 0.5));
    addMesh(new Box("Box", new Vector3(), 3, 3, 3));
    addMesh(new Capsule("Capsule", 5, 5, 5, 2, 5));
    addMesh(new Cone("Cone", 8, 8, 2, 4));
    addMesh(new Cylinder("Cylinder", 8, 8, 2, 4));
    addMesh(new Disk("Disk", 8, 8, 3));
    addMesh(new Dodecahedron("Dodecahedron", 3));
    addMesh(new Dome("Dome", 8, 8, 3));
    addMesh(new Hexagon("Hexagon", 3));
    addMesh(new Icosahedron("Icosahedron", 3));
    addMesh(new MultiFaceBox("MultiFaceBox", new Vector3(), 3, 3, 3));
    addMesh(new Octahedron("Octahedron", 3));
    addMesh(new PQTorus("PQTorus", 5, 4, 1.5, .5, 128, 8));
    addMesh(new Pyramid("Pyramid", 2, 4));
    addMesh(new Quad("Quad", 3, 3));
    addMesh(new RoundedBox("RoundedBox", new Vector3(3, 3, 3)));
    addMesh(new Sphere("Sphere", 16, 16, 3));
    addMesh(new GeoSphere("GeoSphere", true, 3, 3, TextureMode.Original));
    addMesh(new StripBox("StripBox", new Vector3(), 3, 3, 3));
    addMesh(new Teapot("Teapot"));
    addMesh(new Torus("Torus", 16, 8, 1.0, 2.5));
    addMesh(new Tube("Tube", 2, 3, 4));
    addMesh(createLines());

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

    final BlendState bs = new BlendState();
    bs.setBlendEnabled(true);
    _root.setRenderState(bs);

    // Set up a reusable pick results
    _pickResults = new PrimitivePickResults();
    _pickResults.setCheckDistance(true);

    // Set up our pick label
    _text = BasicText.createDefaultTextLabel("", "pick");
    _text.setTranslation(10, 10, 0);
    _text.getSceneHints().setCullHint(CullHint.Always);
    _root.attachChild(_text);
  }
  @Override
  protected void initExample() {
    _canvas.setTitle("Shapes Example");

    wrapCount = 5;
    addMesh(new Arrow("Arrow", 3, 1));
    addMesh(new AxisRods("AxisRods", true, 3, 0.5));
    addMesh(new Box("Box", new Vector3(), 3, 3, 3));
    addMesh(new Capsule("Capsule", 5, 5, 5, 2, 5));
    addMesh(new Cone("Cone", 8, 8, 2, 4));
    addMesh(new Cylinder("Cylinder", 8, 8, 2, 4));
    addMesh(new Disk("Disk", 8, 8, 3));
    addMesh(new Dodecahedron("Dodecahedron", 3));
    addMesh(new Dome("Dome", 8, 8, 3));
    addMesh(new Hexagon("Hexagon", 3));
    addMesh(new Icosahedron("Icosahedron", 3));
    addMesh(new MultiFaceBox("MultiFaceBox", new Vector3(), 3, 3, 3));
    addMesh(new Octahedron("Octahedron", 3));
    addMesh(new PQTorus("PQTorus", 5, 4, 1.5, .5, 128, 8));
    addMesh(new Pyramid("Pyramid", 2, 4));
    addMesh(new Quad("Quad", 3, 3));
    addMesh(new RoundedBox("RoundedBox", new Vector3(3, 3, 3)));
    addMesh(new Sphere("Sphere", 16, 16, 3));
    addMesh(new GeoSphere("GeoSphere", true, 3, 3, TextureMode.Original));
    addMesh(new StripBox("StripBox", new Vector3(), 3, 3, 3));
    addMesh(new Teapot("Teapot"));
    addMesh(new Torus("Torus", 16, 8, 1.0, 2.5));
    addMesh(new Tube("Tube", 2, 3, 4));
    addMesh(createLines());

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

    final BlendState bs = new BlendState();
    bs.setBlendEnabled(true);
    _root.setRenderState(bs);

    // Set up a reusable pick results
    _pickResults = new BoundingPickResults();
    _pickResults.setCheckDistance(true);

    // Set up our pick label
    _text = BasicText.createDefaultTextLabel("", "pick");
    _text.setTranslation(10, 10, 0);
    _text.getSceneHints().setCullHint(CullHint.Always);
    _root.attachChild(_text);

    // Set up picked pulse
    _pickedControl =
        new SpatialController<Spatial>() {
          ColorRGBA curr = new ColorRGBA();
          float val = 0;
          boolean add = true;

          public void update(final double time, final Spatial caller) {
            val += time * (add ? 1 : -1);
            if (val < 0) {
              val = -val;
              add = true;
            } else if (val > 1) {
              val = 1 - (val - (int) val);
              add = false;
            }

            curr.set(val, val, val, 1.0f);

            final MaterialState ms = (MaterialState) caller.getLocalRenderState(StateType.Material);
            ms.setAmbient(curr);
          }
        };
  }
  @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);
  }