static UsdPrim
_GetMaterialParent(const UsdStageRefPtr& stage,
               const PxrUsdMayaShadingModeExportContext::AssignmentVector& assignments)
{
    SdfPath commonAncestor;
    TF_FOR_ALL(iter, assignments) {
        const SdfPath& assn = iter->first;
        if (stage->GetPrimAtPath(assn)) {
            if (commonAncestor.IsEmpty()) {
                commonAncestor = assn;
            }
            else {
                commonAncestor = commonAncestor.GetCommonPrefix(assn);
            }
        }
    }

    if (commonAncestor.IsEmpty()) {
        return UsdPrim();
    }

    if (commonAncestor == SdfPath::AbsoluteRootPath()) {
        return stage->GetPseudoRoot();
    }

    SdfPath shaderExportLocation = commonAncestor;
    while (!shaderExportLocation.IsRootPrimPath()) {
        shaderExportLocation = shaderExportLocation.GetParentPath();
    }
    shaderExportLocation = shaderExportLocation.AppendChild(TfToken("Looks"));

    return UsdGeomScope::Define(stage, shaderExportLocation).GetPrim();
}
Example #2
0
File: path.cpp Project: lvxejay/USD
static SdfPath
_AppendNode(const SdfPath &path, const Sdf_PathNodeConstRefPtr &node) {

    switch (node->GetNodeType()) {
        case Sdf_PathNode::PrimNode:
            return path.AppendChild(node->GetName());
        case Sdf_PathNode::PrimPropertyNode:
            return path.AppendProperty(node->GetName());
        case Sdf_PathNode::PrimVariantSelectionNode:
        {
            const Sdf_PathNode::VariantSelectionType& selection =
                node->GetVariantSelection();
            return path.AppendVariantSelection(selection.first.GetString(),
                                               selection.second.GetString());
        }
        case Sdf_PathNode::TargetNode:
            return path.AppendTarget( node->GetTargetPath());
        case Sdf_PathNode::RelationalAttributeNode:
            return path.AppendRelationalAttribute(node->GetName());
        case Sdf_PathNode::MapperNode:
            return path.AppendMapper(node->GetTargetPath());
        case Sdf_PathNode::MapperArgNode:
            return path.AppendMapperArg(node->GetName());
        case Sdf_PathNode::ExpressionNode:
            return path.AppendExpression();
        default:
            // CODE_COVERAGE_OFF
            // Should never get here.  All reasonable cases are
            // handled above.
            TF_CODING_ERROR("Unexpected node type %i", node->GetNodeType());
            return SdfPath::EmptyPath();
            // CODE_COVERAGE_ON
    }
}
/* static */
bool
UsdMayaTranslatorCamera::Read(
        const UsdGeomCamera& usdCamera,
        MObject parentNode,
        const UsdMayaPrimReaderArgs& args,
        UsdMayaPrimReaderContext* context)
{
    if (!usdCamera) {
        return false;
    }

    const UsdPrim& prim = usdCamera.GetPrim();
    const SdfPath primPath = prim.GetPath();

    MStatus status;

    // Create the transform node for the camera.
    MObject transformObj;
    if (!UsdMayaTranslatorUtil::CreateTransformNode(prim,
                                                       parentNode,
                                                       args,
                                                       context,
                                                       &status,
                                                       &transformObj)) {
        return false;
    }

    // Create the camera shape node.
    MDagModifier dagMod;
    MObject cameraObj = dagMod.createNode(_tokens->MayaCameraTypeName.GetText(),
                                          transformObj,
                                          &status);
    CHECK_MSTATUS_AND_RETURN(status, false);
    status = dagMod.doIt();
    CHECK_MSTATUS_AND_RETURN(status, false);
    TF_VERIFY(!cameraObj.isNull());

    MFnCamera cameraFn(cameraObj, &status);
    CHECK_MSTATUS_AND_RETURN(status, false);
    const std::string cameraShapeName = prim.GetName().GetString() +
        _tokens->MayaCameraShapeNameSuffix.GetString();
    cameraFn.setName(cameraShapeName.c_str(), &status);
    CHECK_MSTATUS_AND_RETURN(status, false);
    if (context) {
        const SdfPath shapePrimPath = primPath.AppendChild(TfToken(cameraShapeName));
        context->RegisterNewMayaNode(shapePrimPath.GetString(), cameraObj);
    }

    return _ReadToCamera(usdCamera, cameraFn, args, context);
}
Example #4
0
UsdMayaGLBatchRenderer::TaskDelegate::TaskDelegate(
    HdRenderIndex *renderIndex, SdfPath const& delegateID)
    : HdSceneDelegate(renderIndex, delegateID)
{
    _lightingContext = GlfSimpleLightingContext::New();

    // populate tasks in renderindex

    // create an unique namespace
    _rootId = delegateID.AppendChild(
        TfToken(TfStringPrintf("_UsdImaging_%p", this)));

    _simpleLightTaskId          = _rootId.AppendChild(_tokens->simpleLightTask);
    _cameraId                   = _rootId.AppendChild(_tokens->camera);

    // camera
    {
        // Since we're hardcoded to use HdStRenderDelegate, we expect to
        // have camera Sprims.
        TF_VERIFY(renderIndex->IsSprimTypeSupported(HdPrimTypeTokens->camera));

        renderIndex->InsertSprim(HdPrimTypeTokens->camera, this, _cameraId);
        _ValueCache &cache = _valueCacheMap[_cameraId];
        cache[HdStCameraTokens->worldToViewMatrix] = VtValue(GfMatrix4d(1.0));
        cache[HdStCameraTokens->projectionMatrix] = VtValue(GfMatrix4d(1.0));
        cache[HdStCameraTokens->windowPolicy] = VtValue();  // no window policy.
    }

    // simple lighting task (for Hydra native)
    {
        renderIndex->InsertTask<HdxSimpleLightTask>(this, _simpleLightTaskId);
        _ValueCache &cache = _valueCacheMap[_simpleLightTaskId];
        HdxSimpleLightTaskParams taskParams;
        taskParams.cameraPath = _cameraId;
        cache[HdTokens->params] = VtValue(taskParams);
        cache[HdTokens->children] = VtValue(SdfPathVector());
    }
}
Example #5
0
UsdImaging_DefaultTaskDelegate::UsdImaging_DefaultTaskDelegate(
    HdRenderIndexSharedPtr const& parentIndex,
    SdfPath const& delegateID)
    : UsdImagingTaskDelegate(parentIndex, delegateID)
    , _viewport(0,0,1,1)
    , _selectionColor(1,1,0,1)
{
    // create an unique namespace
    _rootId = delegateID.AppendChild(
        TfToken(TfStringPrintf("_UsdImaging_%p", this)));

    _renderTaskId               = _rootId.AppendChild(_tokens->renderTask);
    _idRenderTaskId             = _rootId.AppendChild(_tokens->idRenderTask);
    _selectionTaskId            = _rootId.AppendChild(_tokens->selectionTask);
    _simpleLightTaskId          = _rootId.AppendChild(_tokens->simpleLightTask);
    _simpleLightBypassTaskId    = _rootId.AppendChild(_tokens->simpleLightBypassTask);
    _cameraId                   = _rootId.AppendChild(_tokens->camera);
    _activeSimpleLightTaskId    = SdfPath();

    // TODO: tasks of shadow map generation, accumulation etc will be
    // prepared here.
    HdRenderIndex &renderIndex = GetRenderIndex();

    // camera
    {
        renderIndex.InsertCamera<HdCamera>(this, _cameraId);
        _ValueCache &cache = _valueCacheMap[_cameraId];
        cache[HdShaderTokens->worldToViewMatrix] = VtValue(GfMatrix4d(1));
        cache[HdShaderTokens->projectionMatrix]  = VtValue(GfMatrix4d(1));
        cache[HdTokens->cameraFrustum] = VtValue(); // we don't use GfFrustum.
        cache[HdTokens->windowPolicy] = VtValue();  // we don't use window policy.
    }

    // selection task
    {
        renderIndex.InsertTask<HdxSelectionTask>(this, _selectionTaskId);
        _ValueCache &cache = _valueCacheMap[_selectionTaskId];
        HdxSelectionTaskParams params;
        params.enableSelection = true;
        params.selectionColor = _selectionColor;
        params.locateColor = GfVec4f(0,0,1,1);
        cache[HdTokens->params] = VtValue(params);
        cache[HdTokens->children] = VtValue(SdfPathVector());
    }

    // simple lighting task (for Hydra native)
    {
        renderIndex.InsertTask<HdxSimpleLightTask>(this, _simpleLightTaskId);
        _ValueCache &cache = _valueCacheMap[_simpleLightTaskId];
        HdxSimpleLightTaskParams params;
        params.cameraPath = _cameraId;
        cache[HdTokens->params] = VtValue(params);
        cache[HdTokens->children] = VtValue(SdfPathVector());
    }

    // simple lighting task (for Presto UsdBaseIc compatible)
    {
        renderIndex.InsertTask<HdxSimpleLightBypassTask>(this,
                                                         _simpleLightBypassTaskId);
        _ValueCache &cache = _valueCacheMap[_simpleLightBypassTaskId];
        HdxSimpleLightBypassTaskParams params;
        params.cameraPath = _cameraId;
        cache[HdTokens->params] = VtValue(params);
        cache[HdTokens->children] = VtValue(SdfPathVector());
    }

    // render task
    _InsertRenderTask(_renderTaskId);
    _InsertRenderTask(_idRenderTaskId);

    // initialize HdxRenderTaskParams for render tasks
    _UpdateCollection(&_rprims, HdTokens->geometry, HdTokens->smoothHull,
                      SdfPathVector(1, SdfPath::AbsoluteRootPath()),
                      _renderTaskId,
                      _idRenderTaskId);
    _UpdateRenderParams(_renderParams,
                        _renderParams,
                        _renderTaskId);
    _UpdateRenderParams(_idRenderParams,
                        _idRenderParams,
                        _idRenderTaskId);
}