コード例 #1
0
ファイル: ScenegraphTree.java プロジェクト: mallanmba/Ardor3D
 public Object getChild(final Object parent, final int index) {
   if (parent instanceof Node) {
     final Node parentNode = (Node) parent;
     return parentNode.getChild(index);
   }
   return null;
 }
コード例 #2
0
ファイル: Grid.java プロジェクト: nasa/DERT
  /**
   * Constructor
   *
   * @param state
   */
  public Grid(GridState state) {
    super(state.name);
    this.state = state;
    this.cellSize = state.size;
    this.color = state.color;
    this.lineWidth = state.lineWidth;
    offset = new Vector3();
    setLocation(state.location, false);

    lattice = new HiddenLine("_lattice", IndexMode.Lines);
    SpatialUtil.setPickHost(lattice, this);
    lattice.setColor(color);
    lattice.setModelBound(new BoundingBox());

    MaterialState ms = new MaterialState();
    ms.setColorMaterial(ColorMaterial.Emissive);
    ms.setColorMaterialFace(MaterialState.MaterialFace.FrontAndBack);
    ms.setEnabled(true);
    text = new Node("_text");
    text.getSceneHints().setLightCombineMode(LightCombineMode.Off);
    text.getSceneHints().setPickingHint(PickingHint.Pickable, false);
    text.setRenderState(ms);
    setLabelVisible(state.labelVisible);

    attachChild(lattice);
    attachChild(text);

    setVisible(state.visible);
    setPinned(state.pinned);

    state.setMapElement(this);
  }
コード例 #3
0
ファイル: ScenegraphTree.java プロジェクト: mallanmba/Ardor3D
 public int getIndexOfChild(final Object parent, final Object child) {
   if (parent instanceof Node && child instanceof Spatial) {
     final Node parentNode = (Node) parent;
     return parentNode.getChildIndex((Spatial) child);
   }
   return 0;
 }
コード例 #4
0
ファイル: ScenegraphTree.java プロジェクト: mallanmba/Ardor3D
 public int getChildCount(final Object parent) {
   if (parent instanceof Node) {
     final Node parentNode = (Node) parent;
     return parentNode.getNumberOfChildren();
   }
   return 0;
 }
コード例 #5
0
ファイル: Grid.java プロジェクト: nasa/DERT
 /** Show the label */
 @Override
 public void setLabelVisible(boolean visible) {
   labelVisible = visible;
   if (text != null) {
     text.getSceneHints().setCullHint(visible ? CullHint.Inherit : CullHint.Always);
     text.markDirty(DirtyType.RenderState);
   }
 }
コード例 #6
0
ファイル: PickingUtil.java プロジェクト: thecookie/Ardor3D
  public static void findCollisions(
      final Spatial spatial, final Spatial scene, final CollisionResults results) {
    if (spatial == scene
        || spatial.getWorldBound() == null
        || !spatial.getSceneHints().isPickingHintEnabled(PickingHint.Collidable)
        || !scene.getSceneHints().isPickingHintEnabled(PickingHint.Collidable)) {
      return;
    }

    if (spatial instanceof Node) {
      final Node node = (Node) spatial;

      if (node.getWorldBound().intersects(scene.getWorldBound())) {
        // further checking needed.
        for (int i = 0; i < node.getNumberOfChildren(); i++) {
          PickingUtil.findCollisions(node.getChild(i), scene, results);
        }
      }
    } else if (spatial instanceof Mesh) {
      final Mesh mesh = (Mesh) spatial;

      if (mesh.getWorldBound().intersects(scene.getWorldBound())) {
        if (scene instanceof Node) {
          final Node parent = (Node) scene;
          for (int i = 0; i < parent.getNumberOfChildren(); i++) {
            PickingUtil.findCollisions(mesh, parent.getChild(i), results);
          }
        } else {
          results.addCollision(mesh, (Mesh) scene);
        }
      }
    }
  }
コード例 #7
0
ファイル: Analyzer.java プロジェクト: NkD/m-theory
 public void dispose() {
   if (selectedMesh != null) selectedMesh.removeController(updater);
   selectedMesh = null;
   bbvn = null;
   root.detachChild(this);
   for (InputTrigger it : inputTriggers) {
     logicalLayer.deregisterTrigger(it);
   }
 }
コード例 #8
0
ファイル: WaterNode.java プロジェクト: gouessej/Ardor3D
  /**
   * Sets up a node to be transformed and clipped for skybox usage
   *
   * @param skyBox Handle to a node to use as skybox
   */
  public void setSkybox(final Node skyBox) {
    if (skyBox != null) {
      final ClipState skyboxClipState = new ClipState();
      skyboxClipState.setEnabled(false);
      skyBox.setRenderState(skyboxClipState);
    }

    this.skyBox = skyBox;
  }
コード例 #9
0
ファイル: WaterNode.java プロジェクト: gouessej/Ardor3D
  @Override
  public void draw(final Renderer r) {
    initialize(r);

    updateTranslations();

    final double camWaterDist = waterPlane.pseudoDistance(cam.getLocation());
    aboveWater = camWaterDist >= 0;

    if (isSupported()) {
      waterShader.setUniform("tangent", tangent);
      waterShader.setUniform("binormal", binormal);
      waterShader.setUniform("useFadeToFogColor", useFadeToFogColor);
      waterShader.setUniform("waterColor", waterColorStart);
      waterShader.setUniform("waterColorEnd", waterColorEnd);
      waterShader.setUniform("normalTranslation", (float) normalTranslation);
      waterShader.setUniform("refractionTranslation", (float) refractionTranslation);
      waterShader.setUniform("abovewater", aboveWater);
      if (useProjectedShader) {
        waterShader.setUniform("cameraPos", cam.getLocation());
        waterShader.setUniform("waterHeight", (float) waterPlane.getConstant());
        waterShader.setUniform("amplitude", (float) waterMaxAmplitude);
        waterShader.setUniform("heightFalloffStart", (float) heightFalloffStart);
        waterShader.setUniform("heightFalloffSpeed", (float) heightFalloffSpeed);
      }

      final double heightTotal = clipBias + waterMaxAmplitude - waterPlane.getConstant();
      final Vector4 clipPlane = Vector4.fetchTempInstance();

      if (useReflection) {
        clipPlane.set(
            waterPlane.getNormal().getX(),
            waterPlane.getNormal().getY(),
            waterPlane.getNormal().getZ(),
            heightTotal);
        renderReflection(clipPlane);
      }

      if (useRefraction && aboveWater) {
        clipPlane.set(
            -waterPlane.getNormal().getX(),
            -waterPlane.getNormal().getY(),
            -waterPlane.getNormal().getZ(),
            -waterPlane.getConstant());
        renderRefraction(clipPlane);
      }
    }

    if (fallbackTextureState != null) {
      fallbackTextureStateMatrix.setM31(normalTranslation);
      fallbackTexture.setTextureMatrix(fallbackTextureStateMatrix);
    }

    super.draw(r);
  }
コード例 #10
0
  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;
  }
コード例 #11
0
ファイル: CollisionTree.java プロジェクト: bandj/Ardor3D
 /**
  * Recreate this Collision Tree for the given Node and child index.
  *
  * @param childIndex the index of the child to generate the tree for.
  * @param parent The Node that this tree should represent.
  * @param doSort true to sort primitives during creation, false otherwise
  */
 public void construct(
     final int childIndex, final int section, final Node parent, final boolean doSort) {
   final Spatial spat = parent.getChild(childIndex);
   if (spat instanceof Mesh) {
     _mesh = makeRef((Mesh) spat);
     _primitiveIndices = new int[((Mesh) spat).getMeshData().getPrimitiveCount(section)];
     for (int i = 0; i < _primitiveIndices.length; i++) {
       _primitiveIndices[i] = i;
     }
     createTree(section, 0, _primitiveIndices.length, doSort);
   }
 }
コード例 #12
0
ファイル: PickingUtil.java プロジェクト: thecookie/Ardor3D
  public static void findPick(final Spatial spatial, final Ray3 ray, final PickResults results) {
    if (!spatial.getSceneHints().isPickingHintEnabled(PickingHint.Pickable)) {
      return;
    }

    if (spatial instanceof Node) {
      final Node node = (Node) spatial;

      if (node.getNumberOfChildren() == 0 || node.getWorldBound() == null) {
        return;
      }
      if (node.getWorldBound().intersects(ray)) {
        // further checking needed.
        for (int i = 0; i < node.getNumberOfChildren(); i++) {
          PickingUtil.findPick(node.getChild(i), ray, results);
        }
      }
    } else if (spatial instanceof Mesh) {
      final Mesh mesh = (Mesh) spatial;

      if (mesh.getWorldBound() == null) {
        return;
      }
      if (mesh.getWorldBound().intersects(ray)) {
        // find the primitive that is being hit.
        // add this node and the primitive to the PickResults list.
        results.addPick(ray, mesh);
      }
    }
  }
コード例 #13
0
ファイル: PickingUtil.java プロジェクト: thecookie/Ardor3D
  public static boolean hasCollision(
      final Spatial spatial, final Spatial scene, final boolean checkPrimitives) {
    if (spatial == scene
        || spatial.getWorldBound() == null
        || !spatial.getSceneHints().isPickingHintEnabled(PickingHint.Collidable)
        || !scene.getSceneHints().isPickingHintEnabled(PickingHint.Collidable)) {
      return false;
    }

    if (spatial instanceof Node) {
      final Node node = (Node) spatial;

      if (node.getWorldBound().intersects(scene.getWorldBound())) {
        if (node.getNumberOfChildren() == 0 && !checkPrimitives) {
          return true;
        }
        // further checking needed.
        for (int i = 0; i < node.getNumberOfChildren(); i++) {
          if (PickingUtil.hasCollision(node.getChild(i), scene, checkPrimitives)) {
            return true;
          }
        }
      }
    } else if (spatial instanceof Mesh) {
      final Mesh mesh = (Mesh) spatial;

      if (mesh.getWorldBound().intersects(scene.getWorldBound())) {
        if (scene instanceof Node) {
          final Node parent = (Node) scene;
          for (int i = 0; i < parent.getNumberOfChildren(); i++) {
            if (PickingUtil.hasCollision(mesh, parent.getChild(i), checkPrimitives)) {
              return true;
            }
          }

          return false;
        }

        if (!checkPrimitives) {
          return true;
        }

        return PickingUtil.hasTriangleCollision(mesh, (Mesh) scene);
      }

      return false;
    }

    return false;
  }
コード例 #14
0
ファイル: WaterNode.java プロジェクト: gouessej/Ardor3D
  /** Render water refraction RTT */
  private void renderRefraction(final Vector4 clipPlane) {
    if (renderList.isEmpty()) {
      return;
    }

    refractionTime += tpf;
    if (refractionTime < refractionThrottle) {
      return;
    }
    refractionTime = 0;

    // tRenderer.getCamera().set(cam);
    tRenderer.getCamera().setLocation(cam.getLocation());
    tRenderer.getCamera().setDirection(cam.getDirection());
    tRenderer.getCamera().setUp(cam.getUp());
    tRenderer.getCamera().setLeft(cam.getLeft());

    CullHint cullMode = CullHint.Dynamic;
    if (skyBox != null) {
      cullMode = skyBox.getSceneHints().getCullHint();
      skyBox.getSceneHints().setCullHint(CullHint.Always);
    }

    tRenderer.getCamera().setProjectionMatrix(cam.getProjectionMatrix());

    texArray.clear();
    texArray.add(textureRefract);
    texArray.add(textureDepth);

    tRenderer.getCamera().update();
    tRenderer.getCamera().getModelViewMatrix();
    tRenderer.getCamera().getProjectionMatrix();

    tRenderer.render(renderList, texArray, Renderer.BUFFER_COLOR_AND_DEPTH);

    if (skyBox != null) {
      skyBox.getSceneHints().setCullHint(cullMode);
    }
  }
コード例 #15
0
/**
コード例 #16
0
ファイル: Arrow.java プロジェクト: krka/Ardor3D
 @Override
 public void read(final InputCapsule capsule) throws IOException {
   super.read(capsule);
   _length = capsule.readDouble("length", 1);
   _width = capsule.readDouble("width", .25);
 }
コード例 #17
0
ファイル: Arrow.java プロジェクト: krka/Ardor3D
 @Override
 public void write(final OutputCapsule capsule) throws IOException {
   super.write(capsule);
   capsule.write(_length, "length", 1);
   capsule.write(_width, "width", .25);
 }
コード例 #18
0
ファイル: WaterNode.java プロジェクト: gouessej/Ardor3D
  /** Render water reflection RTT */
  private void renderReflection(final Vector4 clipPlane) {
    if (renderList.isEmpty()) {
      return;
    }

    reflectionTime += tpf;
    if (reflectionTime < reflectionThrottle) {
      return;
    }
    reflectionTime = 0;

    if (aboveWater) {
      camLocation.set(cam.getLocation());

      double planeDistance = waterPlane.pseudoDistance(camLocation);
      calcVect.set(waterPlane.getNormal()).multiplyLocal(planeDistance * 2.0f);
      camReflectPos.set(camLocation.subtractLocal(calcVect));

      camLocation.set(cam.getLocation()).addLocal(cam.getDirection());
      planeDistance = waterPlane.pseudoDistance(camLocation);
      calcVect.set(waterPlane.getNormal()).multiplyLocal(planeDistance * 2.0f);
      camReflectDir
          .set(camLocation.subtractLocal(calcVect))
          .subtractLocal(camReflectPos)
          .normalizeLocal();

      camLocation.set(cam.getLocation()).addLocal(cam.getUp());
      planeDistance = waterPlane.pseudoDistance(camLocation);
      calcVect.set(waterPlane.getNormal()).multiplyLocal(planeDistance * 2.0f);
      camReflectUp
          .set(camLocation.subtractLocal(calcVect))
          .subtractLocal(camReflectPos)
          .normalizeLocal();

      camReflectLeft.set(camReflectUp).crossLocal(camReflectDir).normalizeLocal();

      tRenderer.getCamera().setLocation(camReflectPos);
      tRenderer.getCamera().setDirection(camReflectDir);
      tRenderer.getCamera().setUp(camReflectUp);
      tRenderer.getCamera().setLeft(camReflectLeft);
    } else {
      tRenderer.getCamera().setLocation(cam.getLocation());
      tRenderer.getCamera().setDirection(cam.getDirection());
      tRenderer.getCamera().setUp(cam.getUp());
      tRenderer.getCamera().setLeft(cam.getLeft());
    }

    if (skyBox != null) {
      tmpLocation.set(skyBox.getTranslation());
      skyBox.setTranslation(tRenderer.getCamera().getLocation());
      skyBox.updateGeometricState(0.0f);
      skyBox.getSceneHints().setCullHint(CullHint.Never);
    }

    texArray.clear();
    if (doBlurReflection) {
      texArray.add(textureReflect);
    } else {
      texArray.add(textureReflectBlur);
    }

    tRenderer.getCamera().setProjectionMode(ProjectionMode.Custom);
    tRenderer.getCamera().setProjectionMatrix(cam.getProjectionMatrix());
    tRenderer.render(skyBox, texArray, Renderer.BUFFER_COLOR_AND_DEPTH);

    if (skyBox != null) {
      skyBox.getSceneHints().setCullHint(CullHint.Always);
    }

    modifyProjectionMatrix(clipPlane);

    tRenderer.render(renderList, texArray, Renderer.BUFFER_NONE);

    if (doBlurReflection) {
      blurReflectionTexture();
    }

    if (skyBox != null) {
      skyBox.setTranslation(tmpLocation);
      skyBox.updateGeometricState(0.0f);
      skyBox.getSceneHints().setCullHint(CullHint.Never);
    }
  }
コード例 #19
0
ファイル: Analyzer.java プロジェクト: NkD/m-theory
 public static void attachToScene(Node root, LogicalLayer logicalLayer) {
   detachFromScene();
   REF = new Analyzer(root, logicalLayer);
   root.attachChild(REF);
 }
コード例 #20
0
ファイル: InteractExample.java プロジェクト: gouessej/Ardor3D
  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);
  }
コード例 #21
0
  @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);
  }