Пример #1
0
  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);
        }
      }
    }
  }
Пример #2
0
  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;
  }
Пример #3
0
  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);
      }
    }
  }
Пример #4
0
 /**
  * Sets a spatial up for being rendered with the watereffect
  *
  * @param spatial Spatial to use as base for the watereffect
  */
 public void setWaterEffectOnSpatial(final Spatial spatial) {
   spatial.setRenderState(cullBackFace);
   if (isSupported()) {
     // spatial.setRenderBucketType(RenderBucketType.Skip);
     spatial.setRenderState(waterShader);
     spatial.setRenderState(textureState);
   } else {
     spatial.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
     spatial.getSceneHints().setLightCombineMode(LightCombineMode.Off);
     spatial.setRenderState(fallbackTextureState);
     spatial.setRenderState(as1);
   }
 }
Пример #5
0
    public void valueChanged(final TreeSelectionEvent e) {
      if (e.getNewLeadSelectionPath() == null
          || e.getNewLeadSelectionPath().getLastPathComponent() == null) {
        return;
      }

      final Spatial spatial = (Spatial) e.getNewLeadSelectionPath().getLastPathComponent();

      final StringBuilder str = new StringBuilder();

      str.append(spatial.getName());
      str.append(" - ");
      str.append(spatial.getClass().getName()).append('\n');

      if (spatial instanceof Mesh) {
        final Mesh mesh = (Mesh) spatial;
        str.append("Primitives: ");
        str.append(mesh.getMeshData().getTotalPrimitiveCount()).append('\n');
        str.append("Index mode: ");
        str.append(mesh.getMeshData().getIndexMode(0)).append('\n');
      }

      str.append(spatial.getTransform()).append('\n');
      if (spatial.getWorldBound() != null) {
        str.append(spatial.getWorldBound()).append('\n');
      }

      str.append('\n');
      final SceneHints sceneHints = spatial.getSceneHints();
      str.append("Cull hint: ");
      str.append(sceneHints.getCullHint()).append('\n');
      str.append("Bucket: ");
      str.append(sceneHints.getRenderBucketType()).append('\n');

      textArea.setText(str.toString());
    }
Пример #6
0
  @Override
  public void render(final Renderer renderer) {
    // Grab our render context - used to enforce renderstates
    final RenderContext context = ContextManager.getCurrentContext();

    // go through our bucket contents
    Spatial spatial;
    for (int i = 0; i < _currentListSize; i++) {
      spatial = _currentList[i];

      // make sure we have a real spatial
      if (spatial == null) {
        continue;
      }

      // we only care about altering the Mesh... perhaps could be altered later to some interface
      // shared by Mesh
      // and other leaf nodes.
      if (spatial instanceof Mesh) {

        // get our transparency rendering type.
        final TransparencyType renderType = spatial.getSceneHints().getTransparencyType();

        // check for one of the two pass types...
        if (renderType != TransparencyType.OnePass) {

          // get handle to Mesh
          final Mesh mesh = (Mesh) spatial;

          // check if we have a Cull state set or enforced. If one is explicitly set and is not
          // Face.None,
          // we'll not do two-pass transparency.
          RenderState setState =
              context.hasEnforcedStates() ? context.getEnforcedState(StateType.Cull) : null;
          if (setState == null) {
            setState = mesh.getWorldRenderState(RenderState.StateType.Cull);
          }

          // Do the described check.
          if (setState == null || ((CullState) setState).getCullFace() == Face.None) {

            // pull any currently enforced cull or zstate. We'll put them back afterwards
            final RenderState oldCullState = context.getEnforcedState(StateType.Cull);
            final RenderState oldZState = context.getEnforcedState(StateType.ZBuffer);

            // enforce our cull and zstate. The zstate is setup to respect depth, but not write to
            // it.
            context.enforceState(_tranparentCull);
            context.enforceState(_transparentZBuff);

            // first render back-facing tris only
            _tranparentCull.setCullFace(CullState.Face.Front);
            mesh.draw(renderer);

            // revert z state
            context.clearEnforcedState(StateType.ZBuffer);
            if (oldZState != null) {
              context.enforceState(oldZState);
            }

            // render front-facing tris
            _tranparentCull.setCullFace(CullState.Face.Back);
            mesh.draw(renderer);

            // revert cull state
            if (oldCullState != null) {
              context.enforceState(oldCullState);
            } else {
              context.clearEnforcedState(StateType.Cull);
            }
            continue;
          }
        }
      }

      // go ahead and draw as usual
      spatial.draw(renderer);
    }
  }