Beispiel #1
0
void retargetLocator::getRadPoints( MPointArray& radPoints )
{
	int    div = discDivision;
	double angle = 360.0/div*0.01745327778;

	radPoints.setLength( div );

	double axisList[3];
	for( int i=0; i<div; i++ )
	{
		axisList[0] = 0.0;
		axisList[1] = sin( angle*i + discAngle );
		axisList[2] = cos( angle*i + discAngle );
		radPoints.set( i, axisList[(discAxis+3)%3]*discSize.x, 
			              axisList[(discAxis+2)%3]*discSize.y, 
						  axisList[(discAxis+1)%3]*discSize.z );
	}
}
MObject readNurbs(double iFrame, Alembic::AbcGeom::INuPatch & iNode,
    MObject & iObject)
{
    MStatus status;
    MObject obj;

    Alembic::AbcGeom::INuPatchSchema schema = iNode.getSchema();

    // no interpolation for now
    Alembic::AbcCoreAbstract::index_t index, ceilIndex;
    getWeightAndIndex(iFrame, schema.getTimeSampling(),
        schema.getNumSamples(), index, ceilIndex);

    Alembic::AbcGeom::INuPatchSchema::Sample samp;
    schema.get(samp, Alembic::Abc::ISampleSelector(index));

    Alembic::Abc::P3fArraySamplePtr pos = samp.getPositions();
    Alembic::Abc::FloatArraySamplePtr weights = samp.getPositionWeights();

    MString surfaceName(iNode.getName().c_str());

    unsigned int degreeU  = samp.getUOrder() - 1;
    unsigned int degreeV  = samp.getVOrder() - 1;
    unsigned int numCVInU = samp.getNumU();
    unsigned int numCVInV = samp.getNumV();

    // cv points
    unsigned int numCV = numCVInU*numCVInV;
    unsigned int curPos = 0;

    MPointArray controlVertices;
    controlVertices.setLength(numCV);

    for (unsigned int v = 0; v < numCVInV; ++v)
    {
        for (unsigned int u = 0; u < numCVInU; ++u, ++curPos)
        {
            unsigned int mayaIndex = u * numCVInV + (numCVInV - v - 1);
            MPoint pt((*pos)[curPos].x, (*pos)[curPos].y, (*pos)[curPos].z);

            if (weights)
            {
                pt.w = (*weights)[curPos];
            }

            // go from u,v order to reversed v, u order
            controlVertices.set(pt, mayaIndex);
        }
    }

    // Nurbs form
    // Alemblic file does not record the form of nurb surface, we get the form
    // by checking the CV data. If the first degree number CV overlap the last
    // degree number CV, then the form is kPeriodic. If only the first CV overlaps
    // the last CV, then the form is kClosed.
    MFnNurbsSurface::Form formU = MFnNurbsSurface::kPeriodic;
    MFnNurbsSurface::Form formV = MFnNurbsSurface::kPeriodic;
    // Check all curves
    bool notOpen = true;
    for (unsigned int v = 0; notOpen && v < numCVInV; v++) {
        for (unsigned int u = 0; u < degreeU; u++) {
            unsigned int firstIndex = u * numCVInV + (numCVInV - v - 1);
            unsigned int lastPeriodicIndex = (numCVInU - degreeU + u) * numCVInV + (numCVInV - v - 1);
            if (!controlVertices[firstIndex].isEquivalent(controlVertices[lastPeriodicIndex])) {
                formU = MFnNurbsSurface::kOpen;
                notOpen = false;
                break;
            }
        }
    }

    if (formU == MFnNurbsSurface::kOpen) {
        formU = MFnNurbsSurface::kClosed;
        for (unsigned int v = 0; v < numCVInV; v++) {
            unsigned int lastUIndex = (numCVInU - 1) * numCVInV + (numCVInV - v - 1);
            if (! controlVertices[numCVInV-v-1].isEquivalent(controlVertices[lastUIndex])) {
                formU = MFnNurbsSurface::kOpen;
                break;
            }
        }
    }

    notOpen = true;
    for (unsigned int u = 0; notOpen && u < numCVInU; u++) {
        for (unsigned int v = 0; v < degreeV; v++) {
            unsigned int firstIndex = u * numCVInV + (numCVInV - v - 1);
            unsigned int lastPeriodicIndex = u * numCVInV + (degreeV - v - 1); //numV - (numV - vDegree + v) - 1;
            if (!controlVertices[firstIndex].isEquivalent(controlVertices[lastPeriodicIndex])) {
                formV = MFnNurbsSurface::kOpen;
                notOpen = false;
                break;
            }
        }
    }
    if (formV == MFnNurbsSurface::kOpen) {
        formV = MFnNurbsSurface::kClosed;
        for (unsigned int u = 0; u < numCVInU; u++) {
            if (! controlVertices[u * numCVInV + (numCVInV-1)].isEquivalent(controlVertices[u * numCVInV])) {
                formV = MFnNurbsSurface::kOpen;
                break;
            }
        }
    }


    Alembic::Abc::FloatArraySamplePtr uKnot = samp.getUKnot();
    Alembic::Abc::FloatArraySamplePtr vKnot = samp.getVKnot();

    unsigned int numKnotsInU = static_cast<unsigned int>(uKnot->size() - 2);
    MDoubleArray uKnotSequences;
    uKnotSequences.setLength(numKnotsInU);
    for (unsigned int i = 0; i < numKnotsInU; ++i)
    {
        uKnotSequences.set((*uKnot)[i+1], i);
    }

    unsigned int numKnotsInV = static_cast<unsigned int>(vKnot->size() - 2);
    MDoubleArray vKnotSequences;
    vKnotSequences.setLength(numKnotsInV);
    for (unsigned int i = 0; i < numKnotsInV; i++)
    {
        vKnotSequences.set((*vKnot)[i+1], i);
    }

    // Node creation try the API first
    MFnNurbsSurface mFn;
    obj = mFn.create(controlVertices, uKnotSequences, vKnotSequences,
        degreeU, degreeV, formU, formV,
        true, iObject, &status);

    // something went wrong, try open/open create
    if (status != MS::kSuccess && (formU != MFnNurbsSurface::kOpen ||
        formV != MFnNurbsSurface::kOpen))
    {
        obj = mFn.create(controlVertices, uKnotSequences, vKnotSequences,
            degreeU, degreeV,  MFnNurbsSurface::kOpen,  MFnNurbsSurface::kOpen,
            true, iObject, &status);
    }

    if (status == MS::kSuccess)
    {
        mFn.setName(surfaceName);
    }
    else
    {
        MString errorMsg = "Could not create Nurbs Surface: ";
        errorMsg += surfaceName;
        MGlobal::displayError(errorMsg);
    }

    trimSurface(samp, mFn);

    return obj;
}
//setEdgeVertexIndexListShear
//-----------------------------------------------
void TesselationVisualization::setEdgeVertexPositionListShear(MDataBlock &data)
{
	//clear edgeVertexPositionList
	drawData.edgeVertexPositionList.clear();

	//inputGeo
	MObject oInputGeo = data.inputValue(aInputGeo).asMesh();

	//fnMeshInputGeo
	MFnMesh fnMeshInputGeo(oInputGeo);

	//vertexPositionList
	MPointArray vertexPositionList;
	fnMeshInputGeo.getPoints(vertexPositionList);

	//itMeshPolyInputGeo
	MItMeshPolygon itMeshPolyInputGeo(oInputGeo);

	//for each poly
	while(!itMeshPolyInputGeo.isDone())
	{
		//get edges
		MIntArray edgeIndexList;
		itMeshPolyInputGeo.getEdges(edgeIndexList);
		
		//edgeVertexIndices
		int2* edgeVertexIndices = new int2[4];

		for(int index = 0; index < edgeIndexList.length(); index++)
		{
			fnMeshInputGeo.getEdgeVertices(edgeIndexList[index], edgeVertexIndices[index]);
		};

		//edgeVertexIndicesNoDuplicates
		std::set<int> setEdgeVertexIndicesNoDuplicates;

		for(int index = 0; index < edgeIndexList.length(); index++)
		{
			setEdgeVertexIndicesNoDuplicates.insert(edgeVertexIndices[index][0]);
			setEdgeVertexIndicesNoDuplicates.insert(edgeVertexIndices[index][1]);
		};

		//vecEdgeVertexIndicesNoDuplicates
		std::vector<int> vecEdgeVertexIndicesNoDuplicates(setEdgeVertexIndicesNoDuplicates.begin(), setEdgeVertexIndicesNoDuplicates.end());


		//get faceVertexList
		MPointArray faceVertexPointList = MPointArray(4);

		for(int index = 0; index < edgeIndexList.length(); index++)
		{
			MPoint faceVertexPoint = vertexPositionList[vecEdgeVertexIndicesNoDuplicates[index]];
			faceVertexPointList.set(faceVertexPoint, index);
		};

		
		
		//edge01
		std::vector<float> edge01;
		edge01.push_back(faceVertexPointList[0].x);edge01.push_back(faceVertexPointList[0].y);edge01.push_back(faceVertexPointList[0].z);
		edge01.push_back(faceVertexPointList[1].x);edge01.push_back(faceVertexPointList[1].y);edge01.push_back(faceVertexPointList[1].z);

		//edge13
		std::vector<float> edge13;
		edge13.push_back(faceVertexPointList[1].x);edge13.push_back(faceVertexPointList[1].y);edge13.push_back(faceVertexPointList[1].z);
		edge13.push_back(faceVertexPointList[3].x);edge13.push_back(faceVertexPointList[3].y);edge13.push_back(faceVertexPointList[3].z);

		//edge32
		std::vector<float> edge32;
		edge32.push_back(faceVertexPointList[3].x);edge32.push_back(faceVertexPointList[3].y);edge32.push_back(faceVertexPointList[3].z);
		edge32.push_back(faceVertexPointList[2].x);edge32.push_back(faceVertexPointList[2].y);edge32.push_back(faceVertexPointList[2].z);

		//edge20
		std::vector<float> edge20;
		edge20.push_back(faceVertexPointList[2].x);edge20.push_back(faceVertexPointList[2].y);edge20.push_back(faceVertexPointList[2].z);
		edge20.push_back(faceVertexPointList[0].x);edge20.push_back(faceVertexPointList[0].y);edge20.push_back(faceVertexPointList[0].z);

		//edge03
		std::vector<float> edge03;
		edge03.push_back(faceVertexPointList[0].x);edge03.push_back(faceVertexPointList[0].y);edge03.push_back(faceVertexPointList[0].z);
		edge03.push_back(faceVertexPointList[3].x);edge03.push_back(faceVertexPointList[3].y);edge03.push_back(faceVertexPointList[3].z);

		//edge12
		std::vector<float> edge12;
		edge12.push_back(faceVertexPointList[1].x);edge12.push_back(faceVertexPointList[1].y);edge12.push_back(faceVertexPointList[1].z);
		edge12.push_back(faceVertexPointList[2].x);edge12.push_back(faceVertexPointList[2].y);edge12.push_back(faceVertexPointList[2].z);

		
		//add to drawData.edgeVertexPositionList
		drawData.edgeVertexPositionList.push_back(edge01);
		drawData.edgeVertexPositionList.push_back(edge13);
		drawData.edgeVertexPositionList.push_back(edge32);
		drawData.edgeVertexPositionList.push_back(edge20);
		drawData.edgeVertexPositionList.push_back(edge03);
		drawData.edgeVertexPositionList.push_back(edge12);
		
		//del edgeVertexIndices
		delete [] edgeVertexIndices;
		
		//Advance
		itMeshPolyInputGeo.next();
	};
};