예제 #1
0
파일: primvar.cpp 프로젝트: JT-a/USD
bool
UsdGeomPrimvar::Get(
        VtValue* value,
        UsdTimeCode time) const
{
    if (!_idTargetRelName.IsEmpty()) {
        const SdfValueTypeName& typeName = _attr.GetTypeName();
        if (typeName == SdfValueTypeNames->String) {
            std::string s;
            bool ret = Get(&s, time);
            if (ret) {
                *value = VtValue(s);
            }
            return ret;
        }
        else if (typeName == SdfValueTypeNames->StringArray) {
            VtStringArray s;
            bool ret = Get(&s, time);
            if (ret) {
                *value = VtValue(s);
            }
            return ret;
        }
    }

    return _attr.Get(value, time);
}
예제 #2
0
파일: triangulate.cpp 프로젝트: JT-a/USD
bool
HdSt_TriangleIndexBuilderComputation::Resolve()
{
    if (!_TryLock()) return false;

    HD_TRACE_FUNCTION();

    VtVec3iArray trianglesFaceVertexIndices;
    VtIntArray primitiveParam;
    HdMeshUtil meshUtil(_topology, _id);
    meshUtil.ComputeTriangleIndices(
            &trianglesFaceVertexIndices,
            &primitiveParam);

    _SetResult(HdBufferSourceSharedPtr(
                   new HdVtBufferSource(
                       HdTokens->indices,
                       VtValue(trianglesFaceVertexIndices))));

    _primitiveParam.reset(new HdVtBufferSource(
                              HdTokens->primitiveParam,
                              VtValue(primitiveParam)));

    _SetResolved();
    return true;
}
예제 #3
0
파일: parserHelpers.cpp 프로젝트: JT-a/USD
inline VtValue
MakeShapedValueTemplate(vector<unsigned int> const &shape,
                        vector<Value> const &vars, size_t &index,
                        string *errStrPtr) {
    if (shape.empty())
        return VtValue(VtArray<T>());
//    TF_AXIOM(shape.size() == 1);
    unsigned int size = 1;
    TF_FOR_ALL(i, shape)
        size *= *i;

    VtArray<T> array(size);
    size_t shapeIndex = 0;
    size_t origIndex = index;
    try {
        TF_FOR_ALL(i, array) {
            MakeScalarValueImpl(&(*i), vars, index);
            shapeIndex++;
        }
    } catch (const boost::bad_get &) {
        *errStrPtr = TfStringPrintf("Failed to parse at element %zd "
                                    "(at sub-part %zd if there are "
                                    "multiple parts)", shapeIndex,
                                    (index - origIndex) - 1);
        return VtValue();
    }
    return VtValue(array);
}
예제 #4
0
/* static */
const VtDictionary& UsdMayaJobImportArgs::GetDefaultDictionary()
{
    static VtDictionary d;
    static std::once_flag once;
    std::call_once(once, []() {
        // Base defaults.
        d[UsdMayaJobImportArgsTokens->assemblyRep] =
                UsdMayaJobImportArgsTokens->Collapsed.GetString();
        d[UsdMayaJobImportArgsTokens->apiSchema] = std::vector<VtValue>();
        d[UsdMayaJobImportArgsTokens->excludePrimvar] = std::vector<VtValue>();
        d[UsdMayaJobImportArgsTokens->metadata] =
                std::vector<VtValue>({
                    VtValue(SdfFieldKeys->Hidden.GetString()),
                    VtValue(SdfFieldKeys->Instanceable.GetString()),
                    VtValue(SdfFieldKeys->Kind.GetString())
                });
        d[UsdMayaJobImportArgsTokens->shadingMode] =
                UsdMayaShadingModeTokens->displayColor.GetString();
        d[UsdMayaJobImportArgsTokens->useAsAnimationCache] = false;

        // plugInfo.json site defaults.
        // The defaults dict should be correctly-typed, so enable
        // coerceToWeakerOpinionType.
        const VtDictionary site =
                UsdMaya_RegistryHelper::GetComposedInfoDictionary(
                _usdImportInfoScope->allTokens);
        VtDictionaryOver(site, &d, /*coerceToWeakerOpinionType*/ true);
    });

    return d;
}
void
My_TestGLDrawing::InitTest()
{
    _renderIndex = HdRenderIndex::New(&_renderDelegate);
    TF_VERIFY(_renderIndex != nullptr);
    _delegate.reset(new Hdx_UnitTestDelegate(_renderIndex));

    // prepare render task
    SdfPath renderSetupTask("/renderSetupTask");
    SdfPath renderTask("/renderTask");
    SdfPath selectionTask("/selectionTask");
    _delegate->AddRenderSetupTask(renderSetupTask);
    _delegate->AddRenderTask(renderTask);
    _delegate->AddSelectionTask(selectionTask);

    // render task parameters.
    VtValue vParam = _delegate->GetTaskParam(renderSetupTask, HdTokens->params);
    HdxRenderTaskParams param = vParam.Get<HdxRenderTaskParams>();
    param.enableLighting = true; // use default lighting
    _delegate->SetTaskParam(renderSetupTask, HdTokens->params,
                            VtValue(param));
    _delegate->SetTaskParam(renderTask, HdTokens->collection,
                            VtValue(HdRprimCollection(HdTokens->geometry, 
                                HdReprSelector(HdReprTokens->hull))));
    HdxSelectionTaskParams selParam;
    selParam.enableSelection = true;
    selParam.selectionColor = GfVec4f(1, 1, 0, 1);
    selParam.locateColor = GfVec4f(1, 0, 1, 1);
    _delegate->SetTaskParam(selectionTask, HdTokens->params,
                            VtValue(selParam));

    // prepare scene
    _InitScene();
    SetCameraTranslate(GfVec3f(0, 0, -20));

    // picking related init
    _pickablesCol = HdRprimCollection(_tokens->pickables, 
        HdReprSelector(HdReprTokens->hull));
    _marquee.InitGLResources();
    _picker.InitIntersector(_renderIndex);
    _SetPickParams();
    // We have to unfortunately explictly add collections besides 'geometry'
    // See HdRenderIndex constructor.
    _delegate->GetRenderIndex().GetChangeTracker().AddCollection(_tokens->pickables);

// XXX: Setup a VAO, the current drawing engine will not yet do this.
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);
    glBindVertexArray(0);
}
예제 #6
0
파일: batchRenderer.cpp 프로젝트: JT-a/USD
void
UsdMayaGLBatchRenderer::TaskDelegate::_InsertRenderTask(SdfPath const &id)
{
    GetRenderIndex().InsertTask<HdxRenderTask>(this, id);
    _ValueCache &cache = _valueCacheMap[id];
    HdxRenderTaskParams taskParams;
    taskParams.camera = _cameraId;
    // Initialize viewport to the latest value since render tasks can be lazily
    // instantiated, potentially even after SetCameraState.  All other
    // parameters will be updated by _UpdateRenderParams.
    taskParams.viewport = _viewport;
    cache[HdTokens->params] = VtValue(taskParams);
    cache[HdTokens->children] = VtValue(SdfPathVector());
    cache[HdTokens->collection] = VtValue();
}
예제 #7
0
void
HdStreamTaskController::_CreateCamera()
{
    // Create a default camera, driven by SetCameraMatrices.
    _cameraId = GetControllerId().AppendChild(_tokens->camera);
    GetRenderIndex()->InsertSprim(HdPrimTypeTokens->camera,
        &_delegate, _cameraId);

    _delegate.SetParameter(_cameraId, HdStCameraTokens->windowPolicy,
        VtValue());
    _delegate.SetParameter(_cameraId, HdStCameraTokens->matrices,
        HdStCameraMatrices());
    _delegate.SetParameter(_cameraId, HdStCameraTokens->clipPlanes,
        VtValue(std::vector<GfVec4d>()));
}
예제 #8
0
bool
Hd_SmoothNormalsComputation::Resolve()
{
    // dependency check first
    if (_adjacencyBuilder) {
        if (not _adjacencyBuilder->IsResolved()) return false;
    }
    if (_points) {
        if (not _points->IsResolved()) return false;
    }
    if (not _TryLock()) return false;

    HD_TRACE_FUNCTION();
    HD_MALLOC_TAG_FUNCTION();

    if (not TF_VERIFY(_adjacency)) return true;

    int numPoints = _points->GetNumElements();

    HdBufferSourceSharedPtr normals;
    switch (_points->GetGLElementDataType()) {
    case GL_FLOAT_VEC3:
        normals = HdBufferSourceSharedPtr(
            new HdVtBufferSource(
                _dstName, VtValue(
                    _adjacency->ComputeSmoothNormals(
                        numPoints,
                        static_cast<const GfVec3f*>(_points->GetData())))));
        break;
    case GL_DOUBLE_VEC3:
        normals = HdBufferSourceSharedPtr(
            new HdVtBufferSource(
                _dstName, VtValue(
                    _adjacency->ComputeSmoothNormals(
                        numPoints,
                        static_cast<const GfVec3d*>(_points->GetData())))));
        break;
    default:
        TF_CODING_ERROR("Unsupported points type for computing smooth normals");
        break;
    }

    _SetResult(normals);

    // call base class to mark as resolved.
    _SetResolved();
    return true;
}
예제 #9
0
파일: parserHelpers.cpp 프로젝트: JT-a/USD
inline VtValue
MakeScalarValueTemplate(vector<unsigned int> const &,
                        vector<Value> const &vars, size_t &index,
                        string *errStrPtr) {
    T t;
    size_t origIndex = index;
    try {
        MakeScalarValueImpl(&t, vars, index);
    } catch (const boost::bad_get &) {
        *errStrPtr = TfStringPrintf("Failed to parse value (at sub-part %zd "
                                    "if there are multiple parts)",
                                    (index - origIndex) - 1);
        return VtValue();
    }
    return VtValue(t);
}
예제 #10
0
static VtValue
_GetListOpForTokenVector(const TfTokenVector& vector)
{
    SdfTokenListOp op;
    op.SetPrependedItems(vector);
    return VtValue(op);
}
예제 #11
0
bool
MayaPrimWriter::writePrimAttrs(const MDagPath &dagT, const UsdTimeCode &usdTime, UsdGeomImageable &primSchema) 
{
    MStatus status;
    MFnDependencyNode depFn(getDagPath().node());
    MFnDependencyNode depFn2(dagT.node()); // optionally also scan a shape's transform if merging transforms

    if (getArgs().exportVisibility) {
        bool isVisible  = true;   // if BOTH shape or xform is animated, then visible
        bool isAnimated = false;  // if either shape or xform is animated, then animated

        PxrUsdMayaUtil::getPlugValue(depFn, "visibility", &isVisible, &isAnimated);

        if ( dagT.isValid() ) {
            bool isVis, isAnim;
            if (PxrUsdMayaUtil::getPlugValue(depFn2, "visibility", &isVis, &isAnim)){
                isVisible = isVisible and isVis;
                isAnimated = isAnimated or isAnim;
            }
        }

        TfToken const &visibilityTok = (isVisible ? UsdGeomTokens->inherited : 
                                        UsdGeomTokens->invisible);
        if (usdTime.IsDefault() != isAnimated ) {
            if (usdTime.IsDefault())
                primSchema.CreateVisibilityAttr(VtValue(visibilityTok), true);
            else
                primSchema.CreateVisibilityAttr().Set(visibilityTok, usdTime);
        }
    }

    UsdPrim usdPrim = primSchema.GetPrim();

    // There is no Gprim abstraction in this module, so process the few
    // gprim attrs here.
    UsdGeomGprim gprim = UsdGeomGprim(usdPrim);
    if (gprim and usdTime.IsDefault()){

        PxrUsdMayaPrimWriterContext* unused = NULL;
        PxrUsdMayaTranslatorGprim::Write(
                getDagPath().node(),
                gprim,
                unused);

    }

    _writeUsdInfo(dagT, usdTime, usdPrim);
    
    // Write user-tagged export attributes. Write attributes on the transform
    // first, and then attributes on the shape node. This means that attribute
    // name collisions will always be handled by taking the shape node's value
    // if we're merging transforms and shapes.
    if (dagT.isValid() and !(dagT == getDagPath())) {
        PxrUsdMayaWriteUtil::WriteUserExportedAttributes(dagT, usdPrim, usdTime);
    }
    PxrUsdMayaWriteUtil::WriteUserExportedAttributes(getDagPath(), usdPrim, usdTime);

    return true;
}
예제 #12
0
파일: coneAdapter.cpp 프로젝트: 400dama/USD
/*static*/
VtValue
UsdImagingConeAdapter::GetMeshTopology()
{
    // topology is identical for all cones
    static HdMeshTopology coneTopo = _GenerateConeMeshTopology();

    return VtValue(coneTopo);
}
예제 #13
0
/*static*/
VtValue
UsdImagingCapsuleAdapter::GetMeshTopology()
{
    // topology is identical for all capsules
    static HdMeshTopology capsuleTopo = _GenerateCapsuleMeshTopology();

    return VtValue(capsuleTopo);
}
예제 #14
0
static 
void _SetMayaDictValue(const UsdAttribute& attr, const TfToken& flagName, const T& val)
{
    VtValue data = attr.GetCustomDataByKey(_tokens->Maya);

    VtDictionary newDict;
    if (!data.IsEmpty()) {
        if (data.IsHolding<VtDictionary>()) {
            newDict = data.UncheckedGet<VtDictionary>();
        }
        else {
            TF_WARN("Expected to get %s on <%s> to be a dictionary.",
                    _tokens->Maya.GetText(),
                    attr.GetPath().GetText());
            return;
        }
    }
    newDict[flagName] = VtValue(val);
    attr.SetCustomDataByKey(_tokens->Maya, VtValue(newDict));
}
예제 #15
0
HdBufferSourceSharedPtr
HdSt_MeshTopology::GetPointsIndexBuilderComputation()
{
    // this is simple enough to return the result right away.
    int numPoints = GetNumPoints();
    VtIntArray indices(numPoints);
    for (int i = 0; i < numPoints; ++i) indices[i] = i;

    return HdBufferSourceSharedPtr(
        new HdVtBufferSource(HdTokens->indices, VtValue(indices)));
}
예제 #16
0
파일: pointsAdapter.cpp 프로젝트: MWDD/USD
void 
UsdImagingPointsAdapter::UpdateForTime(UsdPrim const& prim,
                                       SdfPath const& cachePath, 
                                       UsdTimeCode time,
                                       HdDirtyBits requestedBits,
                                       HdDirtyBits* resultBits,
                                       UsdImagingInstancerContext const* 
                                           instancerContext)
{
    BaseAdapter::UpdateForTime(
        prim, cachePath, time, requestedBits, resultBits, instancerContext);
    UsdImagingValueCache* valueCache = _GetValueCache();

    PrimvarInfoVector& primvars = valueCache->GetPrimvars(cachePath);

    VtValue& pointsValues = valueCache->GetPoints(cachePath);

    if (requestedBits & HdChangeTracker::DirtyPoints) {
        _GetPoints(prim, &pointsValues, time);
        UsdImagingValueCache::PrimvarInfo primvar;
        primvar.name = HdTokens->points;
        primvar.interpolation = UsdGeomTokens->vertex;
        _MergePrimvar(primvar, &primvars);
    }

    if (requestedBits & HdChangeTracker::DirtyWidths) {
        UsdImagingValueCache::PrimvarInfo primvar;
        UsdGeomPoints points(prim);
        VtFloatArray widths;
        primvar.name = UsdGeomTokens->widths;

        // XXX Add support for real constant interpolation
        primvar.interpolation = UsdGeomTokens->vertex;

        // Read the widths, if there is no widths create a buffer
        // and fill it with default widths of 1.0f
        if (!points.GetWidthsAttr().Get(&widths, time)) {

            // Check if we have just updated the points because in that
            // case we don't need to read the points again
            if (!(requestedBits & HdChangeTracker::DirtyPoints)) {
                _GetPoints(prim, &pointsValues, time);
            }

            for(size_t i = 0; i < pointsValues.Get<VtVec3fArray>().size() ; i ++) {
                widths.push_back(1.0f);
            }
        }
        _MergePrimvar(primvar, &primvars);
        valueCache->GetWidths(cachePath) = VtValue(widths);
    }
}
예제 #17
0
파일: batchRenderer.cpp 프로젝트: JT-a/USD
void
UsdMayaGLBatchRenderer::TaskDelegate::SetCameraState(
    const GfMatrix4d& viewMatrix,
    const GfMatrix4d& projectionMatrix,
    const GfVec4d& viewport)
{
    // cache the camera matrices
    _ValueCache &cache = _valueCacheMap[_cameraId];
    cache[HdStCameraTokens->worldToViewMatrix] = VtValue(viewMatrix);
    cache[HdStCameraTokens->projectionMatrix] = VtValue(projectionMatrix);
    cache[HdStCameraTokens->windowPolicy] = VtValue(); // no window policy.

    // invalidate the camera to be synced
    GetRenderIndex().GetChangeTracker().MarkSprimDirty(_cameraId,
                                                       HdStCamera::AllDirty);

    if( _viewport != viewport )
    {
        // viewport is also read by HdxRenderTaskParam. invalidate it.
        _viewport = viewport;

        // update all render tasks
        for( const auto &it : _renderTaskIdMap )
        {
            SdfPath const &taskId = it.second;
            HdxRenderTaskParams taskParams
                = _GetValue<HdxRenderTaskParams>(taskId, HdTokens->params);

            // update viewport in HdxRenderTaskParams
            taskParams.viewport = viewport;
            _SetValue(taskId, HdTokens->params, taskParams);

            // invalidate
            GetRenderIndex().GetChangeTracker().MarkTaskDirty(
                taskId, HdChangeTracker::DirtyParams);
        }
    }
}
예제 #18
0
파일: batchRenderer.cpp 프로젝트: JT-a/USD
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());
    }
}
예제 #19
0
파일: batchRenderer.cpp 프로젝트: JT-a/USD
/*virtual*/
VtValue
UsdMayaGLBatchRenderer::TaskDelegate::Get(
    SdfPath const& id,
    TfToken const &key)
{
    _ValueCache *vcache = TfMapLookupPtr(_valueCacheMap, id);
    VtValue ret;
    if( vcache && TfMapLookup(*vcache, key, &ret) )
        return ret;

    TF_CODING_ERROR("%s:%s doesn't exist in the value cache\n",
                    id.GetText(), key.GetText());
    return VtValue();
}
예제 #20
0
파일: linkingAPI.cpp 프로젝트: lvxejay/USD
UsdAttribute
UsdLuxLinkingAPI::_GetIncludeByDefaultAttr(bool create /* = false */) const
{
    const TfToken &attrName =
        _GetCollectionPropertyName(_tokens->includeByDefault);
    if (create) {
        return UsdSchemaBase::_CreateAttr(attrName,
                                          SdfValueTypeNames->Bool,
                                          /* custom = */ false,
                                          SdfVariabilityUniform,
                                          /* default = */ VtValue(),
                                          /* writeSparsely */ false);
    } else {
        return GetPrim().GetAttribute(attrName);
    }
}
예제 #21
0
/* static */
UsdUISceneGraphPrimAPI
UsdUISceneGraphPrimAPI::Apply(const UsdStagePtr &stage, const SdfPath &path)
{
    // Ensure we have a valid stage, path and prim
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdUISceneGraphPrimAPI();
    }

    if (path == SdfPath::AbsoluteRootPath()) {
        TF_CODING_ERROR("Cannot apply an api schema on the pseudoroot");
        return UsdUISceneGraphPrimAPI();
    }

    auto prim = stage->GetPrimAtPath(path);
    if (!prim) {
        TF_CODING_ERROR("Prim at <%s> does not exist.", path.GetText());
        return UsdUISceneGraphPrimAPI();
    }

    TfToken apiName("SceneGraphPrimAPI");  

    // Get the current listop at the edit target
    UsdEditTarget editTarget = stage->GetEditTarget();
    SdfPrimSpecHandle primSpec = editTarget.GetPrimSpecForScenePath(path);
    SdfTokenListOp listOp = primSpec->GetInfo(UsdTokens->apiSchemas)
                                    .UncheckedGet<SdfTokenListOp>();

    // Append our name to the prepend list, if it doesnt exist locally
    TfTokenVector prepends = listOp.GetPrependedItems();
    if (std::find(prepends.begin(), prepends.end(), apiName) != prepends.end()) { 
        return UsdUISceneGraphPrimAPI();
    }

    SdfTokenListOp prependListOp;
    prepends.push_back(apiName);
    prependListOp.SetPrependedItems(prepends);
    auto result = listOp.ApplyOperations(prependListOp);
    if (!result) {
        TF_CODING_ERROR("Failed to prepend api name to current listop.");
        return UsdUISceneGraphPrimAPI();
    }

    // Set the listop at the current edit target and return the API prim
    primSpec->SetInfo(UsdTokens->apiSchemas, VtValue(*result));
    return UsdUISceneGraphPrimAPI(prim);
}
예제 #22
0
void
My_TestGLDrawing::
DrawScene(PickParam const * pickParam)
{
    int width = GetWidth(), height = GetHeight();

    GfMatrix4d viewMatrix = GetViewMatrix();

    GfFrustum frustum = GetFrustum();
    GfVec4d viewport(0, 0, width, height);

    if (pickParam) {
        frustum = frustum.ComputeNarrowedFrustum(
            GfVec2d((2.0 * pickParam->location[0]) / width - 1.0,
                    (2.0 * (height-pickParam->location[1])) / height - 1.0),
            GfVec2d(1.0 / width, 1.0 / height));
        viewport = pickParam->viewport;
    }

    GfMatrix4d projMatrix = frustum.ComputeProjectionMatrix();
    _delegate->SetCamera(viewMatrix, projMatrix);

    glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);

    HdTaskSharedPtrVector tasks;
    SdfPath renderSetupTask("/renderSetupTask");
    SdfPath renderTask("/renderTask");
    tasks.push_back(_delegate->GetRenderIndex().GetTask(renderSetupTask));
    tasks.push_back(_delegate->GetRenderIndex().GetTask(renderTask));

    HdxRenderTaskParams param
        = _delegate->GetTaskParam(
            renderSetupTask, HdTokens->params).Get<HdxRenderTaskParams>();
    param.enableIdRender = (pickParam != NULL);
    param.viewport = viewport;
    _delegate->SetTaskParam(renderSetupTask, HdTokens->params, VtValue(param));


    glEnable(GL_DEPTH_TEST);

    glBindVertexArray(vao);

    _engine.Execute(_delegate->GetRenderIndex(), tasks);

    glBindVertexArray(0);
}
예제 #23
0
/*static*/
VtValue
UsdImagingCapsuleAdapter::GetMeshPoints(UsdPrim const& prim, 
                                        UsdTimeCode time)
{
    UsdGeomCapsule capsule(prim);
    double radius = 0.5;
    double height = 1.0;
    TfToken axis = UsdGeomTokens->z;
    TF_VERIFY(capsule.GetRadiusAttr().Get(&radius, time));
    TF_VERIFY(capsule.GetHeightAttr().Get(&height, time));
    TF_VERIFY(capsule.GetAxisAttr().Get(&axis, time));

    // We can't express varying radius and height via a non-uniform
    // scaling transformation and maintain spherical end caps.
    return VtValue(_GenerateCapsuleMeshPoints(float(radius),
                                              float(height),
                                              axis));
}
예제 #24
0
PXR_NAMESPACE_OPEN_SCOPE

// ---------------------------------------------------------------------------
// Delegate implementation.

/* virtual */
VtValue
HdStreamTaskController::_Delegate::Get(SdfPath const& id, TfToken const& key)
{
    _ValueCache *vcache = TfMapLookupPtr(_valueCacheMap, id);
    VtValue ret;
    if (vcache && TfMapLookup(*vcache, key, &ret)) {
        return ret;
    }
    TF_CODING_ERROR("%s:%s doesn't exist in the value cache\n",
            id.GetText(), key.GetText());
    return VtValue();
}
예제 #25
0
/*static*/
VtValue
UsdImagingCubeAdapter::GetMeshTopology()
{
    static int numVerts[] = { 4, 4, 4, 4, 4, 4 };
    static int verts[] = {
        0, 1, 2, 3,
        4, 5, 6, 7,
        0, 6, 5, 1,
        4, 7, 3, 2,
        0, 3, 7, 6,
        4, 2, 1, 5,
    };
    static HdMeshTopology cubeTopo(PxOsdOpenSubdivTokens->bilinear,
               HdTokens->rightHanded,
               _BuildVtArray(numVerts, sizeof(numVerts) / sizeof(numVerts[0])),
               _BuildVtArray(verts, sizeof(verts) / sizeof(verts[0])));
    return VtValue(cubeTopo);
}
예제 #26
0
파일: coneAdapter.cpp 프로젝트: 400dama/USD
/*static*/
VtValue
UsdImagingConeAdapter::GetMeshPoints(UsdPrim const& prim, 
                                     UsdTimeCode time)
{
    UsdGeomCone cone(prim);
    double radius = 1.0;
    double height = 2.0;
    TfToken axis = UsdGeomTokens->z;
    TF_VERIFY(cone.GetRadiusAttr().Get(&radius, time));
    TF_VERIFY(cone.GetHeightAttr().Get(&height, time));
    TF_VERIFY(cone.GetAxisAttr().Get(&axis, time));

    // We could express radius and height via a
    // (potentially non-uniform) scaling transformation.
    return VtValue(_GenerateConeMeshPoints(float(radius),
                                           float(height),
                                           axis));
}
예제 #27
0
/*static*/
VtValue
UsdImagingSphereAdapter::GetMeshPoints(UsdPrim const& prim, 
                                       UsdTimeCode time)
{
    static GfVec3f points[] = {
        GfVec3f( 0.2384,  0.1483, -0.9511) ,GfVec3f( 0.0839,  0.2606, -0.9511) ,GfVec3f(-0.1071,  0.2606, -0.9511),
        GfVec3f(-0.2616,  0.1483, -0.9511) ,GfVec3f(-0.3206, -0.0333, -0.9511) ,GfVec3f(-0.2616, -0.2149, -0.9511),
        GfVec3f(-0.1071, -0.3272, -0.9511) ,GfVec3f( 0.0839, -0.3272, -0.9511) ,GfVec3f( 0.2384, -0.2149, -0.9511),
        GfVec3f( 0.2975, -0.0333, -0.9511) ,GfVec3f( 0.4640,  0.3122, -0.8090) ,GfVec3f( 0.1701,  0.5257, -0.8090),
        GfVec3f(-0.1932,  0.5257, -0.8090) ,GfVec3f(-0.4871,  0.3122, -0.8090) ,GfVec3f(-0.5993, -0.0333, -0.8090),
        GfVec3f(-0.4871, -0.3788, -0.8090) ,GfVec3f(-0.1932, -0.5923, -0.8090) ,GfVec3f( 0.1701, -0.5923, -0.8090),
        GfVec3f( 0.4640, -0.3788, -0.8090) ,GfVec3f( 0.5762, -0.0333, -0.8090) ,GfVec3f( 0.6429,  0.4422, -0.5878),
        GfVec3f( 0.2384,  0.7361, -0.5878) ,GfVec3f(-0.2616,  0.7361, -0.5878) ,GfVec3f(-0.6661,  0.4422, -0.5878),
        GfVec3f(-0.8206, -0.0333, -0.5878) ,GfVec3f(-0.6661, -0.5088, -0.5878) ,GfVec3f(-0.2616, -0.8027, -0.5878),
        GfVec3f( 0.2384, -0.8027, -0.5878) ,GfVec3f( 0.6429, -0.5088, -0.5878) ,GfVec3f( 0.7975, -0.0333, -0.5878),
        GfVec3f( 0.7579,  0.5257, -0.3090) ,GfVec3f( 0.2823,  0.8712, -0.3090) ,GfVec3f(-0.3055,  0.8712, -0.3090),
        GfVec3f(-0.7810,  0.5257, -0.3090) ,GfVec3f(-0.9626, -0.0333, -0.3090) ,GfVec3f(-0.7810, -0.5923, -0.3090),
        GfVec3f(-0.3055, -0.9378, -0.3090) ,GfVec3f( 0.2823, -0.9378, -0.3090) ,GfVec3f( 0.7579, -0.5923, -0.3090),
        GfVec3f( 0.9395, -0.0333, -0.3090) ,GfVec3f( 0.7975,  0.5545, -0.0000) ,GfVec3f( 0.2975,  0.9178, -0.0000),
        GfVec3f(-0.3206,  0.9178, -0.0000) ,GfVec3f(-0.8206,  0.5545, -0.0000) ,GfVec3f(-1.0116, -0.0333,  0.0000),
        GfVec3f(-0.8206, -0.6211,  0.0000) ,GfVec3f(-0.3206, -0.9844,  0.0000) ,GfVec3f( 0.2975, -0.9844,  0.0000),
        GfVec3f( 0.7975, -0.6211,  0.0000) ,GfVec3f( 0.9884, -0.0333,  0.0000) ,GfVec3f( 0.7579,  0.5257,  0.3090),
        GfVec3f( 0.2823,  0.8712,  0.3090) ,GfVec3f(-0.3055,  0.8712,  0.3090) ,GfVec3f(-0.7810,  0.5257,  0.3090),
        GfVec3f(-0.9626, -0.0333,  0.3090) ,GfVec3f(-0.7810, -0.5923,  0.3090) ,GfVec3f(-0.3055, -0.9378,  0.3090),
        GfVec3f( 0.2823, -0.9378,  0.3090) ,GfVec3f( 0.7579, -0.5923,  0.3090) ,GfVec3f( 0.9395, -0.0333,  0.3090),
        GfVec3f( 0.6429,  0.4422,  0.5878) ,GfVec3f( 0.2384,  0.7361,  0.5878) ,GfVec3f(-0.2616,  0.7361,  0.5878),
        GfVec3f(-0.6661,  0.4422,  0.5878) ,GfVec3f(-0.8206, -0.0333,  0.5878) ,GfVec3f(-0.6661, -0.5088,  0.5878),
        GfVec3f(-0.2616, -0.8027,  0.5878) ,GfVec3f( 0.2384, -0.8027,  0.5878) ,GfVec3f( 0.6429, -0.5088,  0.5878),
        GfVec3f( 0.7975, -0.0333,  0.5878) ,GfVec3f( 0.4640,  0.3122,  0.8090) ,GfVec3f( 0.1701,  0.5257,  0.8090),
        GfVec3f(-0.1932,  0.5257,  0.8090) ,GfVec3f(-0.4871,  0.3122,  0.8090) ,GfVec3f(-0.5993, -0.0333,  0.8090),
        GfVec3f(-0.4871, -0.3788,  0.8090) ,GfVec3f(-0.1932, -0.5923,  0.8090) ,GfVec3f( 0.1701, -0.5923,  0.8090),
        GfVec3f( 0.4640, -0.3788,  0.8090) ,GfVec3f( 0.5762, -0.0333,  0.8090) ,GfVec3f( 0.2384,  0.1483,  0.9511),
        GfVec3f( 0.0839,  0.2606,  0.9511) ,GfVec3f(-0.1071,  0.2606,  0.9511) ,GfVec3f(-0.2616,  0.1483,  0.9511),
        GfVec3f(-0.3206, -0.0333,  0.9511) ,GfVec3f(-0.2616, -0.2149,  0.9511) ,GfVec3f(-0.1071, -0.3272,  0.9511),
        GfVec3f( 0.0839, -0.3272,  0.9511) ,GfVec3f( 0.2384, -0.2149,  0.9511) ,GfVec3f( 0.2975, -0.0333,  0.9511),
        GfVec3f(-0.0116, -0.0333, -1.0000) ,GfVec3f(-0.0116, -0.0333,  1.0000),
    };

    size_t numPoints = sizeof(points) / sizeof(points[0]);
    VtArray<GfVec3f> output(numPoints);
    std::copy(points, points + numPoints, output.begin());
    return VtValue(output);
}
void
My_TestGLDrawing::DrawScene()
{
    _Clear();

    int width = GetWidth(), height = GetHeight();

    GfMatrix4d viewMatrix = GetViewMatrix();
    GfFrustum frustum = GetFrustum();

    GfVec4d viewport(0, 0, width, height);

    GfMatrix4d projMatrix = frustum.ComputeProjectionMatrix();
    _delegate->SetCamera(viewMatrix, projMatrix);

    glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);

    SdfPath renderSetupTask("/renderSetupTask");
    SdfPath renderTask("/renderTask");
    SdfPath selectionTask("/selectionTask");

    // viewport
    HdxRenderTaskParams param
        = _delegate->GetTaskParam(
            renderSetupTask, HdTokens->params).Get<HdxRenderTaskParams>();
    param.viewport = viewport;
    _delegate->SetTaskParam(renderSetupTask, HdTokens->params, VtValue(param));

    HdTaskSharedPtrVector tasks;
    tasks.push_back(_delegate->GetRenderIndex().GetTask(renderSetupTask));
    tasks.push_back(_delegate->GetRenderIndex().GetTask(renderTask));
    tasks.push_back(_delegate->GetRenderIndex().GetTask(selectionTask));

    glEnable(GL_DEPTH_TEST);
    glBindVertexArray(vao);

    VtValue v(_picker.GetSelectionTracker());
    _engine.SetTaskContextData(HdxTokens->selectionState, v);

    _engine.Execute(_delegate->GetRenderIndex(), tasks);

    glBindVertexArray(0);
}
예제 #29
0
/*static*/
VtValue
UsdImagingCubeAdapter::GetMeshPoints(UsdPrim const& prim, 
                                     UsdTimeCode time)
{
    static GfVec3f points[] = {
        GfVec3f( 0.5f, 0.5f, 0.5f ),
        GfVec3f(-0.5f, 0.5f, 0.5f ),
        GfVec3f(-0.5f,-0.5f, 0.5f ),
        GfVec3f( 0.5f,-0.5f, 0.5f ),
        GfVec3f(-0.5f,-0.5f,-0.5f ),
        GfVec3f(-0.5f, 0.5f,-0.5f ),
        GfVec3f( 0.5f, 0.5f,-0.5f ),
        GfVec3f( 0.5f,-0.5f,-0.5f ),
    };

    size_t numPoints = sizeof(points) / sizeof(points[0]);
    VtArray<GfVec3f> output(numPoints);
    std::copy(points, points + numPoints, output.begin());
    return VtValue(output);
}
예제 #30
0
/*static*/
VtValue
UsdImagingSphereAdapter::GetMeshTopology()
{
    static int numVerts[] = {
        4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4,
        4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4,
        4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4,
        4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4 ,4,
        3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3 ,3,
    };
    static int verts[] = {
        0 ,1 ,11 ,10 ,1 ,2 ,12 ,11 ,2 ,3 ,13 ,12 ,3 ,4 ,14 ,13 ,4 ,5 ,15 ,14, 5
            ,6 ,16 ,15 ,6 ,7 ,17 ,16 ,7 ,8 ,18 ,17 ,8 ,9 ,19 ,18 ,9 ,0 ,10 ,19,
        10 ,11 ,21 ,20 ,11 ,12 ,22 ,21 ,12 ,13 ,23 ,22 ,13 ,14 ,24 ,23 ,14 ,15
            ,25 ,24, 15 ,16 ,26 ,25 ,16 ,17 ,27 ,26 ,17 ,18 ,28 ,27 ,18 ,19 ,29
            ,28 ,19 ,10 ,20 ,29, 20 ,21 ,31 ,30 ,21 ,22 ,32 ,31 ,22 ,23 ,33 ,32
            ,23 ,24 ,34 ,33 ,24 ,25 ,35 ,34, 25 ,26 ,36 ,35 ,26 ,27 ,37 ,36 ,27
            ,28 ,38 ,37 ,28 ,29 ,39 ,38 ,29 ,20 ,30 ,39, 30 ,31 ,41 ,40 ,31 ,32
            ,42 ,41 ,32 ,33 ,43 ,42 ,33 ,34 ,44 ,43 ,34 ,35 ,45 ,44, 35 ,36 ,46
            ,45 ,36 ,37 ,47 ,46 ,37 ,38 ,48 ,47 ,38 ,39 ,49 ,48 ,39 ,30 ,40 ,49,
        40 ,41 ,51 ,50 ,41 ,42 ,52 ,51 ,42 ,43 ,53 ,52 ,43 ,44 ,54 ,53 ,44 ,45
            ,55 ,54, 45 ,46 ,56 ,55 ,46 ,47 ,57 ,56 ,47 ,48 ,58 ,57 ,48 ,49 ,59
            ,58 ,49 ,40 ,50 ,59, 50 ,51 ,61 ,60 ,51 ,52 ,62 ,61 ,52 ,53 ,63 ,62
            ,53 ,54 ,64 ,63 ,54 ,55 ,65 ,64, 55 ,56 ,66 ,65 ,56 ,57 ,67 ,66 ,57
            ,58 ,68 ,67 ,58 ,59 ,69 ,68 ,59 ,50 ,60 ,69, 60 ,61 ,71 ,70 ,61 ,62
            ,72 ,71 ,62 ,63 ,73 ,72 ,63 ,64 ,74 ,73 ,64 ,65 ,75 ,74, 65 ,66 ,76
            ,75 ,66 ,67 ,77 ,76 ,67 ,68 ,78 ,77 ,68 ,69 ,79 ,78 ,69 ,60 ,70 ,79,
        70 ,71 ,81 ,80 ,71 ,72 ,82 ,81 ,72 ,73 ,83 ,82 ,73 ,74 ,84 ,83 ,74 ,75
            ,85 ,84, 75 ,76 ,86 ,85 ,76 ,77 ,87 ,86 ,77 ,78 ,88 ,87 ,78 ,79 ,89
            ,88 ,79 ,70 ,80 ,89, 1 ,0 ,90 ,2 ,1 ,90 ,3 ,2 ,90 ,4 ,3 ,90 ,5 ,4
            ,90 ,6 ,5 ,90 ,7 ,6, 90 ,8 ,7 ,90 ,9 ,8 ,90 ,0 ,9 ,90 ,80 ,81 ,91
            ,81 ,82 ,91 ,82 ,83 ,91 ,83, 84 ,91 ,84 ,85 ,91 ,85 ,86 ,91 ,86 ,87
            ,91 ,87 ,88 ,91 ,88 ,89 ,91 ,89 ,80 ,91,
    };
    static HdMeshTopology sphereTopo(PxOsdOpenSubdivTokens->catmark,
                                   HdTokens->rightHanded,
               _BuildVtArray(numVerts, sizeof(numVerts) / sizeof(numVerts[0])),
               _BuildVtArray(verts, sizeof(verts) / sizeof(verts[0])));
    return VtValue(sphereTopo);
}