Ejemplo n.º 1
0
void
OsdMeshData::initializeMesh() 
{
    if (!_hbrmesh)
        return;

    OpenSubdiv::OsdMeshBitset bits;
    bits.set(OpenSubdiv::MeshAdaptive, _adaptive!=0);
    bits.set(OpenSubdiv::MeshFVarData, true);

    if (_kernel == kCPU) {
        _mesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdCpuGLVertexBuffer,
                                         OpenSubdiv::OsdCpuComputeController,
                                         OpenSubdiv::OsdGLDrawContext>(
                                                g_cpuComputeController,
                                                _hbrmesh, 3, _level, bits);
#ifdef OPENSUBDIV_HAS_OPENMP
    } else if (_kernel == kOPENMP) {
        _mesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdCpuGLVertexBuffer,
                                         OpenSubdiv::OsdOmpComputeController,
                                         OpenSubdiv::OsdGLDrawContext>(
                                                g_ompComputeController,
                                                _hbrmesh, 3, _level, bits);
#endif
#ifdef OPENSUBDIV_HAS_CUDA
    } else if(_kernel == kCUDA) {
        _mesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdCudaGLVertexBuffer,
                                         OpenSubdiv::OsdCudaComputeController,
                                         OpenSubdiv::OsdGLDrawContext>(
                                                g_cudaComputeController,
                                                _hbrmesh, 3, _level, bits);
#endif
#ifdef OPENSUBDIV_HAS_OPENCL
    } else if(_kernel == kCL) {
        _mesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdCLGLVertexBuffer,
                                         OpenSubdiv::OsdCLComputeController,
                                         OpenSubdiv::OsdGLDrawContext>(
                                                g_clComputeController,
                                                _hbrmesh, 3, _level, bits,
                                                g_clContext, g_clQueue);
#endif
    }

    delete _hbrmesh;
    _hbrmesh = NULL;

    _needsInitializeMesh = false;

    // get geometry from maya mesh
    MFnMesh meshFn(_meshDagPath);
    meshFn.getPoints(_pointArray);

    _needsUpdate = true;
}
void
OsdMeshWrapper::CreateCatmarkMesh(
    int level, int numPoints, int numFloatsPerPoint,
    int nvertsSize, const jint *nverts,
    int vertsSize, const jint *verts)
{
    static OpenSubdiv::HbrCatmarkSubdivision<OpenSubdiv::OsdVertex> catmark;
    OsdHbrMesh *hmesh = new OsdHbrMesh(&catmark);

    // create new empty vertices
    OpenSubdiv::OsdVertex v;
    for (int i=0; i<numPoints; ++i) {
        hmesh->NewVertex(i, v);
    }

    // assign base mesh topology
    const jint *faceIndices = verts;
    for (int i=0; i<nvertsSize; ++i) {
        int numVertsInFace = nverts[ i ];

        bool faceIsValid = true;
        for (int j=0; j<numVertsInFace; ++j) {
            int i0 = faceIndices[ j ];
            int i1 = faceIndices[ (j+1) % numVertsInFace ];

            OsdHbrVertex *v0 = hmesh->GetVertex(i0);
            OsdHbrVertex *v1 = hmesh->GetVertex(i1);

            // XXXdyu-api check for topology errors
        }

        if (faceIsValid) {
            OsdHbrFace * face =
                hmesh->NewFace(numVertsInFace, const_cast<int *>(faceIndices), 0);
        }

        faceIndices += numVertsInFace;
    }

    hmesh->Finish();

    _level = level;
    _numPoints = numPoints;
    _numFloatsPerPoint = numFloatsPerPoint;

    OpenSubdiv::OsdMeshBitset bits;
    bits.set(OpenSubdiv::MeshAdaptive, false);

    _osdMesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdCpuGLVertexBuffer,
                                       OpenSubdiv::OsdCpuComputeController,
                                       OpenSubdiv::OsdGLDrawContext>
                                       (hmesh, _numFloatsPerPoint+3, _level, bits); //XXXdyu

    delete hmesh;

    _nverts.assign(nverts, nverts+nvertsSize);
    _verts.assign(verts, verts+vertsSize);
}