Ejemplo n.º 1
0
  @Override
  public RenderState extract(final Stack<? extends RenderState> stack, final Spatial spat) {
    if (spat == null) {
      return stack.peek();
    }

    final LightCombineMode mode = spat.getLightCombineMode();

    final Mesh mesh = (Mesh) spat;
    LightState lightState = mesh.getLightState();
    if (lightState == null) {
      lightState = new LightState();
      mesh.setLightState(lightState);
    }

    lightState.detachAll();

    if (mode == LightCombineMode.Replace || (mode != LightCombineMode.Off && stack.size() == 1)) {
      // todo: use dummy state if off?

      final LightState copyLightState = (LightState) stack.peek();
      copyLightState(copyLightState, lightState);
    } else {
      // accumulate the lights in the stack into a single LightState object
      final Object states[] = stack.toArray();
      boolean foundEnabled = false;
      switch (mode) {
        case CombineClosest:
        case CombineClosestEnabled:
          for (int iIndex = states.length - 1; iIndex >= 0; iIndex--) {
            final LightState pkLState = (LightState) states[iIndex];
            if (!pkLState.isEnabled()) {
              if (mode == LightCombineMode.CombineClosestEnabled) {
                break;
              }

              continue;
            }

            foundEnabled = true;
            copyLightState(pkLState, lightState);
          }
          break;
        case CombineFirst:
          for (int iIndex = 0, max = states.length; iIndex < max; iIndex++) {
            final LightState pkLState = (LightState) states[iIndex];
            if (!pkLState.isEnabled()) {
              continue;
            }

            foundEnabled = true;
            copyLightState(pkLState, lightState);
          }
          break;
        case Off:
          break;
      }
      lightState.setEnabled(foundEnabled);
    }

    return lightState;
  }