Пример #1
0
  protected void updateSubBatch(Geometry bg) {
    Batch batch = batchesByGeom.get(bg);
    if (batch != null) {
      Mesh mesh = batch.geometry.getMesh();
      Mesh origMesh = bg.getMesh();

      VertexBuffer pvb = mesh.getBuffer(VertexBuffer.Type.Position);
      FloatBuffer posBuf = (FloatBuffer) pvb.getData();
      VertexBuffer nvb = mesh.getBuffer(VertexBuffer.Type.Normal);
      FloatBuffer normBuf = (FloatBuffer) nvb.getData();

      VertexBuffer opvb = origMesh.getBuffer(VertexBuffer.Type.Position);
      FloatBuffer oposBuf = (FloatBuffer) opvb.getData();
      VertexBuffer onvb = origMesh.getBuffer(VertexBuffer.Type.Normal);
      FloatBuffer onormBuf = (FloatBuffer) onvb.getData();
      Matrix4f transformMat = getTransformMatrix(bg);

      if (mesh.getBuffer(VertexBuffer.Type.Tangent) != null) {

        VertexBuffer tvb = mesh.getBuffer(VertexBuffer.Type.Tangent);
        FloatBuffer tanBuf = (FloatBuffer) tvb.getData();
        VertexBuffer otvb = origMesh.getBuffer(VertexBuffer.Type.Tangent);
        FloatBuffer otanBuf = (FloatBuffer) otvb.getData();
        doTransformsTangents(
            oposBuf,
            onormBuf,
            otanBuf,
            posBuf,
            normBuf,
            tanBuf,
            bg.startIndex,
            bg.startIndex + bg.getVertexCount(),
            transformMat);
        tvb.updateData(tanBuf);
      } else {
        doTransforms(
            oposBuf,
            onormBuf,
            posBuf,
            normBuf,
            bg.startIndex,
            bg.startIndex + bg.getVertexCount(),
            transformMat);
      }
      pvb.updateData(posBuf);
      nvb.updateData(normBuf);

      batch.needMeshUpdate = true;
    }
  }
Пример #2
0
  @Override
  public void updateGeometricState() {
    if ((refreshFlags & RF_LIGHTLIST) != 0) {
      updateWorldLightList();
    }

    if ((refreshFlags & RF_TRANSFORM) != 0) {
      // combine with parent transforms- same for all spatial
      // subclasses.
      updateWorldTransforms();
    }

    if (!children.isEmpty()) {
      // the important part- make sure child geometric state is refreshed
      // first before updating own world bound. This saves
      // a round-trip later on.
      // NOTE 9/19/09
      // Although it does save a round trip,

      for (Spatial child : children.getArray()) {
        child.updateGeometricState();
      }

      for (Batch batch : batches.getArray()) {
        if (batch.needMeshUpdate) {
          batch.geometry.updateModelBound();
          batch.geometry.updateWorldBound();
          batch.needMeshUpdate = false;
        }
      }
    }

    if ((refreshFlags & RF_BOUND) != 0) {
      updateWorldBound();
    }

    assert refreshFlags == 0;
  }