예제 #1
0
void read(double iFrame, Alembic::AbcGeom::ICamera & iCamera,
    std::vector<double> & oArray)
{
    oArray.resize(18);

    // set some optional scale values
    oArray[13] = 1.0;
    oArray[16] = 1.0;
    oArray[17] = 1.0;

    Alembic::AbcGeom::ICameraSchema schema = iCamera.getSchema();

    Alembic::AbcCoreAbstract::index_t index, ceilIndex;
    double alpha = getWeightAndIndex(iFrame,
        schema.getTimeSampling(), schema.getNumSamples(), index, ceilIndex);

    if (alpha != 0.0)
    {
        Alembic::AbcGeom::CameraSample samp, ceilSamp;
        schema.get(samp, index);
        schema.get(ceilSamp, ceilIndex);

        oArray[0] = simpleLerp<double>(alpha, samp.getFocalLength(),
            ceilSamp.getFocalLength());
        oArray[1] = simpleLerp<double>(alpha, samp.getLensSqueezeRatio(),
            ceilSamp.getLensSqueezeRatio());
        oArray[2] = simpleLerp<double>(alpha, samp.getHorizontalAperture(),
            ceilSamp.getHorizontalAperture()) / 2.54;
        oArray[3] = simpleLerp<double>(alpha, samp.getVerticalAperture(),
            ceilSamp.getVerticalAperture()) / 2.54;
        oArray[4] = simpleLerp<double>(alpha,
            samp.getHorizontalFilmOffset(),
            ceilSamp.getHorizontalFilmOffset()) / 2.54;
        oArray[5] = simpleLerp<double>(alpha,
            samp.getVerticalFilmOffset(),
            ceilSamp.getVerticalFilmOffset()) / 2.54;

        if (samp.getOverScanLeft() == samp.getOverScanRight() &&
            samp.getOverScanTop() == samp.getOverScanBottom() &&
            samp.getOverScanLeft() == samp.getOverScanTop() &&
            ceilSamp.getOverScanLeft() == ceilSamp.getOverScanRight() &&
            ceilSamp.getOverScanTop() == ceilSamp.getOverScanBottom() &&
            ceilSamp.getOverScanLeft() == ceilSamp.getOverScanTop())
        {
            oArray[6] = simpleLerp<double>(alpha,
                samp.getOverScanLeft() + 1.0,
                ceilSamp.getOverScanLeft() + 1.0);
        }
        else
        {
            oArray[6] = 1.0;
        }

        oArray[7] = simpleLerp<double>(alpha, samp.getNearClippingPlane(),
            ceilSamp.getNearClippingPlane());

        oArray[8] = simpleLerp<double>(alpha, samp.getFarClippingPlane(),
            ceilSamp.getFarClippingPlane());

        oArray[9] = simpleLerp<double>(alpha, samp.getFStop(),
            ceilSamp.getFStop());

        oArray[10] = simpleLerp<double>(alpha, samp.getFocusDistance(),
            ceilSamp.getFocusDistance());

        double shutterClose = simpleLerp<double>(alpha, samp.getShutterClose(),
            ceilSamp.getShutterClose());
        double shutterOpen = simpleLerp<double>(alpha, samp.getShutterOpen(),
            ceilSamp.getShutterOpen());
        MTime sec(1.0, MTime::kSeconds);
        oArray[11] =
            360.0 * (shutterClose - shutterOpen) * sec.as(MTime::uiUnit());

        std::size_t numOps = samp.getNumOps();
        for (std::size_t i = 0; i < numOps; ++i)
        {
            Alembic::AbcGeom::FilmBackXformOp & op = samp[i];
            Alembic::AbcGeom::FilmBackXformOp & ceilOp = ceilSamp[i];
            if (op.getHint() == "filmFitOffs")
            {
                double val = op.getChannelValue(0) *
                    samp.getHorizontalAperture();

                double ceilVal = ceilOp.getChannelValue(0) *
                    ceilSamp.getHorizontalAperture();

                if (val != 0.0)
                {
                    // chanValue(0) * 0.5 * horiz aper / 2.54
                    oArray[12] = simpleLerp<double>(alpha, val, ceilVal) / 5.08;
                }
                else
                {
                    val = op.getChannelValue(1) * samp.getHorizontalAperture();

                    ceilVal = ceilOp.getChannelValue(1) *
                        ceilSamp.getHorizontalAperture();

                    // chanValue(1)* 0.5 * horiz aper / 2.54
                    oArray[12] = simpleLerp<double>(alpha, val, ceilVal) / 5.08;
                }
            }
            else if (op.getHint() == "preScale")
            {
                oArray[13] = 1.0 / simpleLerp<double>(alpha,
                    op.getChannelValue(0), ceilOp.getChannelValue(0));
            }
            else if (op.getHint() == "filmTranslate")
            {
                oArray[14] = simpleLerp<double>(alpha,
                    op.getChannelValue(0), ceilOp.getChannelValue(0));

                oArray[15] = simpleLerp<double>(alpha,
                    op.getChannelValue(1), ceilOp.getChannelValue(1));
            }
            else if (op.getHint() == "postScale")
            {
                oArray[16] = 1.0 / simpleLerp<double>(alpha,
                    op.getChannelValue(0), ceilOp.getChannelValue(0));
            }
            else if (op.getHint() == "cameraScale")
            {
                oArray[17] = simpleLerp<double>(alpha,
                    op.getChannelValue(0), ceilOp.getChannelValue(0));
            }
        }
    }
    else
    {
        Alembic::AbcGeom::CameraSample samp;
        schema.get(samp, index);
        oArray[0] = samp.getFocalLength();
        oArray[1] = samp.getLensSqueezeRatio();
        oArray[2] = samp.getHorizontalAperture()/2.54;
        oArray[3] = samp.getVerticalAperture()/2.54;
        oArray[4] = samp.getHorizontalFilmOffset()/2.54;
        oArray[5] = samp.getVerticalFilmOffset()/2.54;

        if (samp.getOverScanLeft() == samp.getOverScanRight() &&
            samp.getOverScanTop() == samp.getOverScanBottom() &&
            samp.getOverScanLeft() == samp.getOverScanTop())
        {
            oArray[6] = samp.getOverScanLeft() + 1.0;
        }
        else
        {
            oArray[6] = 1.0;
        }

        oArray[7] = samp.getNearClippingPlane();
        oArray[8] = samp.getFarClippingPlane();

        oArray[9] = samp.getFStop();
        oArray[10] = samp.getFocusDistance();

        MTime sec(1.0, MTime::kSeconds);
        oArray[11] = 360.0 * (samp.getShutterClose()-samp.getShutterOpen()) *
            sec.as(MTime::uiUnit());

        // prescale, film translate H, V, roll pivot H,V, film roll value
        // post scale might be in the 3x3
        std::size_t numOps = samp.getNumOps();
        for (std::size_t i = 0; i < numOps; ++i)
        {
            Alembic::AbcGeom::FilmBackXformOp & op = samp[i];
            if (op.getHint() == "filmFitOffs")
            {
                if (op.getChannelValue(0) != 0.0)
                {
                    oArray[12] = op.getChannelValue(0) *
                        samp.getHorizontalAperture() / 5.08;
                }
                else
                {
                    oArray[12] = op.getChannelValue(1) *
                        samp.getHorizontalAperture() / 5.08;
                }
            }
            else if (op.getHint() == "preScale")
            {
                oArray[13] = 1.0 / op.getChannelValue(0);
            }
            else if (op.getHint() == "filmTranslate")
            {
                oArray[14] = op.getChannelValue(0);

                oArray[15] = op.getChannelValue(1);
            }
            else if (op.getHint() == "postScale")
            {
                oArray[16] = 1.0 / op.getChannelValue(0);
            }
            else if (op.getHint() == "cameraScale")
            {
                oArray[17] = op.getChannelValue(0);
            }
        }
    }
}
void AlembicFloatController::GetValueLocalTime(TimeValue t, void* ptr,
                                               Interval& valid,
                                               GetSetMethod method)
{
  ESS_CPP_EXCEPTION_REPORTING_START

  Interval interval = FOREVER;

  MCHAR const* strPath = NULL;
  this->pblock->GetValue(AlembicFloatController::ID_PATH, t, strPath, interval);

  MCHAR const* strIdentifier = NULL;
  this->pblock->GetValue(AlembicFloatController::ID_IDENTIFIER, t,
                         strIdentifier, interval);

  MCHAR const* strCategory = NULL;
  this->pblock->GetValue(AlembicFloatController::ID_CATEGORY, t, strCategory,
                         interval);

  MCHAR const* strProperty = NULL;
  this->pblock->GetValue(AlembicFloatController::ID_PROPERTY, t, strProperty,
                         interval);

  float fTime;
  this->pblock->GetValue(AlembicFloatController::ID_TIME, t, fTime, interval);

  BOOL bMuted;
  this->pblock->GetValue(AlembicFloatController::ID_MUTED, t, bMuted, interval);

  extern bool g_bVerboseLogging;

  if (g_bVerboseLogging) {
    ESS_LOG_WARNING("Param block at tick " << t << "-----------------------");
    ESS_LOG_WARNING("PATH: " << strPath);
    ESS_LOG_WARNING("IDENTIFIER: " << strIdentifier);
    ESS_LOG_WARNING("PROPERTY: " << strProperty);
    ESS_LOG_WARNING("TIME: " << fTime);
    ESS_LOG_WARNING("MUTED: " << bMuted);
    ESS_LOG_WARNING("Param block end -------------");
  }

  const float fDefaultVal = -1.0;

  std::string szPath = EC_MCHAR_to_UTF8(strPath);
  std::string szIdentifier = EC_MCHAR_to_UTF8(strIdentifier);
  std::string szProperty = EC_MCHAR_to_UTF8(strProperty);
  std::string szCategory = EC_MCHAR_to_UTF8(strCategory);

  if (szCategory.empty()) {  // default to standard properties for backwards
    // compatibility
    szCategory = std::string("standardProperties");
  }

  if (!strProperty || !strPath || !strIdentifier /*|| !strCategory*/) {
    return setController("1", szProperty, valid, interval, method, ptr,
                         fDefaultVal);
  }

  if (bMuted) {
    return setController("2", szProperty, valid, interval, method, ptr,
                         fDefaultVal);
  }

  // if( szCategory.size() == 0 ) {
  //   ESS_LOG_ERROR( "No category specified." );
  //   return setController("3a", szProperty, valid, interval,   method,   ptr,
  //   fDefaultVal);
  //}

  if (szProperty.size() == 0) {
    ESS_LOG_ERROR("No property specified.");
    return setController("3b", szProperty, valid, interval, method, ptr,
                         fDefaultVal);
  }

  AbcG::IObject iObj = getObjectFromArchive(szPath, szIdentifier);

  if (!iObj.valid()) {
    return setController("4", szProperty, valid, interval, method, ptr,
                         fDefaultVal);
  }

  TimeValue dTicks = GetTimeValueFromSeconds(fTime);
  double sampleTime = GetSecondsFromTimeValue(dTicks);

  float fSampleVal = fDefaultVal;

  if (boost::iequals(szCategory, "standardProperties")) {
    if (Alembic::AbcGeom::ICamera::matches(
            iObj.getMetaData())) {  // standard camera properties

      Alembic::AbcGeom::ICamera objCamera =
          Alembic::AbcGeom::ICamera(iObj, Alembic::Abc::kWrapExisting);

      SampleInfo sampleInfo =
          getSampleInfo(sampleTime, objCamera.getSchema().getTimeSampling(),
                        objCamera.getSchema().getNumSamples());
      Alembic::AbcGeom::CameraSample sample;
      objCamera.getSchema().get(sample, sampleInfo.floorIndex);

      double sampleVal;
      if (!getCameraSampleVal(objCamera, sampleInfo, sample, szProperty,
                              sampleVal)) {
        return setController("5", szProperty, valid, interval, method, ptr,
                             fDefaultVal);
      }

      // Blend the camera values, if necessary
      if (sampleInfo.alpha != 0.0) {
        objCamera.getSchema().get(sample, sampleInfo.ceilIndex);
        double sampleVal2 = 0.0;
        if (getCameraSampleVal(objCamera, sampleInfo, sample, szProperty,
                               sampleVal2)) {
          sampleVal = (1.0 - sampleInfo.alpha) * sampleVal +
                      sampleInfo.alpha * sampleVal2;
        }
      }

      fSampleVal = (float)sampleVal;
    }
    else if (Alembic::AbcGeom::ILight::matches(
                 iObj.getMetaData())) {  // ILight material properties

      ESS_PROFILE_SCOPE(
          "AlembicFloatController::GetValueLocalTime - read ILight shader "
          "parameter");

      Alembic::AbcGeom::ILight objLight =
          Alembic::AbcGeom::ILight(iObj, Alembic::Abc::kWrapExisting);

      SampleInfo sampleInfo =
          getSampleInfo(sampleTime, objLight.getSchema().getTimeSampling(),
                        objLight.getSchema().getNumSamples());

      AbcM::IMaterialSchema matSchema = getMatSchema(objLight);

      std::string strProp = szProperty;

      std::vector<std::string> parts;
      boost::split(parts, strProp, boost::is_any_of("."));

      if (parts.size() == 3) {
        const std::string& target = parts[0];
        const std::string& type = parts[1];
        const std::string& prop = parts[2];

        Abc::IFloatProperty fProp = readShaderScalerProp<Abc::IFloatProperty>(
            matSchema, target, type, prop);
        if (fProp.valid()) {
          fProp.get(fSampleVal, sampleInfo.floorIndex);
        }
        else {
          ESS_LOG_WARNING("Float Controller Error: could find shader parameter "
                          << strProp);
        }
      }
      else if (parts.size() == 5) {
        const std::string& target = parts[0];
        const std::string& type = parts[1];
        const std::string& prop = parts[2];
        const std::string& propInterp = parts[3];
        const std::string& propComp = parts[4];

        // ESS_LOG_WARNING("propInterp: "<<propInterp);

        if (propInterp == "rgb") {
          Abc::IC3fProperty fProp = readShaderScalerProp<Abc::IC3fProperty>(
              matSchema, target, type, prop);
          if (fProp.valid()) {
            Abc::C3f v3f;
            fProp.get(v3f, sampleInfo.floorIndex);
            if (propComp == "x") {
              fSampleVal = v3f.x;
            }
            else if (propComp == "y") {
              fSampleVal = v3f.y;
            }
            else if (propComp == "z") {
              fSampleVal = v3f.z;
            }
            else {
              ESS_LOG_WARNING(
                  "Float Controller Error: invalid component: " << propComp);
            }
          }
          else {
            ESS_LOG_WARNING(
                "Float Controller Error: could find shader parameter "
                << strProp);
          }
        }
        else {
          ESS_LOG_WARNING(
              "Float Controller Error: unrecognized parameter interpretation: "
              << propInterp);
        }
      }
      else {
        ESS_LOG_WARNING(
            "Float Controller Error: could not parse property field: "
            << strProperty);
      }
    }
  }
  else if (boost::iequals(szCategory, "userProperties")) {
    // AbcA::TimeSamplingPtr timeSampling = obj.getSchema().getTimeSampling();
    // int nSamples = (int)obj.getSchema().getNumSamples();

    AbcA::TimeSamplingPtr timeSampling;
    int nSamples = 0;
    Abc::ICompoundProperty propk =
        AbcNodeUtils::getUserProperties(iObj, timeSampling, nSamples);

    if (propk.valid()) {
      SampleInfo sampleInfo = getSampleInfo(sampleTime, timeSampling, nSamples);

      std::vector<std::string> parts;
      boost::split(parts, szProperty, boost::is_any_of("."));

      if (parts.size() == 1) {
        Abc::IFloatProperty fProp =
            readScalarProperty<Abc::IFloatProperty>(propk, szProperty);
        if (fProp.valid()) {
          fProp.get(fSampleVal, sampleInfo.floorIndex);
        }
        else {
          Abc::IInt32Property intProp =
              readScalarProperty<Abc::IInt32Property>(propk, szProperty);
          if (intProp.valid()) {
            int intVal;
            intProp.get(intVal, sampleInfo.floorIndex);
            fSampleVal = (float)intVal;
          }
          else {
            ESS_LOG_WARNING(
                "Float Controller Error: could not read user property "
                << szProperty);
          }
        }
      }
      else if (parts.size() == 3) {
        const std::string& prop = parts[0];
        const std::string& propInterp = parts[1];
        const std::string& propComp = parts[2];

        // ESS_LOG_WARNING("interpretation: "<<propInterp);

        if (propInterp == "rgb") {
          fSampleVal = readScalarPropertyExt3<Abc::IC3fProperty, Abc::C3f>(
              propk, sampleInfo, prop, propComp);
        }
        else if (propInterp == "vector") {
          fSampleVal = readScalarPropertyExt3<Abc::IV3fProperty, Abc::V3f>(
              propk, sampleInfo, prop, propComp);
        }
        else {
          ESS_LOG_WARNING(
              "Float Controller Error: unrecognized parameter interpretation: "
              << propInterp);
        }
      }
    }
  }
  // else if( boost::iequals(szCategory, "arbGeomParams") ){

  //}

  return setController("6", szProperty, valid, interval, method, ptr,
                       fSampleVal);

  ESS_CPP_EXCEPTION_REPORTING_END
}
예제 #3
0
MObject create(Alembic::AbcGeom::ICamera & iNode, MObject & iParent)
{
    Alembic::AbcGeom::ICameraSchema schema = iNode.getSchema();
    MString name(iNode.getName().c_str());

    MFnCamera fnCamera;
    MObject obj = fnCamera.create(iParent);
    fnCamera.setName(name);

    // we need to read this to determine the film fit
    Alembic::AbcGeom::CameraSample samp;
    iNode.getSchema().get(samp);

    std::size_t numOps = samp.getNumOps();
    if (numOps > 0)
    {
        std::string hint = samp[0].getHint();
        if (hint == "filmFitFill")
        {
            fnCamera.setFilmFit(MFnCamera::kFillFilmFit);
        }
        else if (hint == "filmFitHorz")
        {
            fnCamera.setFilmFit(MFnCamera::kHorizontalFilmFit);
        }
        else if (hint == "filmFitVert")
        {
            fnCamera.setFilmFit(MFnCamera::kVerticalFilmFit);
        }
        else if (hint == "filmFitOver")
        {
            fnCamera.setFilmFit(MFnCamera::kOverscanFilmFit);
        }
    }

    if (schema.isConstant())
    {

        // no center of interest
        fnCamera.setFocalLength(samp.getFocalLength());
        fnCamera.setLensSqueezeRatio(samp.getLensSqueezeRatio());
        // camera scale might be in the 3x3

        // weirdo attrs that are in inches
        fnCamera.setHorizontalFilmAperture(samp.getHorizontalAperture()/2.54);
        fnCamera.setVerticalFilmAperture(samp.getVerticalAperture()/2.54);
        fnCamera.setHorizontalFilmOffset(samp.getHorizontalFilmOffset()/2.54);
        fnCamera.setVerticalFilmOffset(samp.getVerticalFilmOffset()/2.54);

        // film fit offset might be in the 3x3

        if (samp.getOverScanLeft() == samp.getOverScanRight() &&
            samp.getOverScanTop() == samp.getOverScanBottom() &&
            samp.getOverScanLeft() == samp.getOverScanTop())
        {
            fnCamera.setOverscan(samp.getOverScanLeft() + 1.0);
        }
        else
        {
            MString warn = iNode.getName().c_str();
            warn += " has unsupported overscan values.";
            MGlobal::displayWarning(warn);
        }

        fnCamera.setNearClippingPlane(samp.getNearClippingPlane());
        fnCamera.setFarClippingPlane(samp.getFarClippingPlane());

        // prescale, film translate H, V, roll pivot H,V, film roll value
        // post scale might be in the 3x3

        fnCamera.setFStop(samp.getFStop());
        fnCamera.setFocusDistance(samp.getFocusDistance());

        MTime sec(1.0, MTime::kSeconds);
        fnCamera.setShutterAngle(Alembic::AbcGeom::DegreesToRadians(
            360.0 * (samp.getShutterClose()-samp.getShutterOpen()) *
            sec.as(MTime::uiUnit()) ));

        for (std::size_t i = 0; i < numOps; ++i)
        {
            Alembic::AbcGeom::FilmBackXformOp & op = samp[i];
            if (op.getHint() == "filmFitOffs")
            {
                double val = op.getChannelValue(0) *
                    samp.getHorizontalAperture() / 5.08;

                if (val != 0.0)
                {
                    fnCamera.setFilmFitOffset(val);
                }
                else
                {
                    fnCamera.setFilmFitOffset(op.getChannelValue(1) *
                        samp.getHorizontalAperture() / 5.08);
                }
            }
            else if (op.getHint() == "preScale")
            {
                fnCamera.setPreScale(1.0/op.getChannelValue(0));
            }
            else if (op.getHint() == "filmTranslate")
            {
                fnCamera.setFilmTranslateH(op.getChannelValue(0));
                fnCamera.setFilmTranslateV(op.getChannelValue(1));
            }
            else if (op.getHint() == "postScale")
            {
                fnCamera.setPostScale(1.0/op.getChannelValue(0));
            }
            else if (op.getHint() == "cameraScale")
            {
                fnCamera.setCameraScale(op.getChannelValue(0));
            }
        }
    }

    // extra transform node is unfortuneatly automatically created above the
    // camera, let's do some reparenting and delete that extra transform
    MDagPath path;
    fnCamera.getPath(path);
    MObject camObj = path.node();

    MDagModifier dagMod;
    dagMod.reparentNode(camObj, iParent);
    dagMod.doIt();
    dagMod.deleteNode(obj);
    dagMod.doIt();

    return camObj;
}