Exemplo n.º 1
0
int
GusdOBJ_usdcamera::applyInputIndependentTransform(OP_Context& ctx, UT_DMatrix4& mx)
{
    mx.identity();
    fpreal t = ctx.getTime();

    if(UsdGeomCamera cam = _LoadCamera(t, ctx.getThread()))
    {
        float frame = evalFloat(_frameIdx, 0, t);

        GfMatrix4d ctm(1.);
        bool stat = true;
        bool resetsXformStack = false;

        switch(evalInt("xformmode", 0, t))
        {
        case _POSTMULTCTM_TRANSFORM:
            stat = true;
            ctm = cam.ComputeLocalToWorldTransform(frame);
            break;
        case _CTM_TRANSFORM:
            stat = true;
            ctm = cam.ComputeParentToWorldTransform(frame);
            break;
        case _OBJ_TRANSFORM:
            // XXX: how do we reset xformStack here?
            // Is that (or should that
            // be) handled by the Compute calls above?
            stat = cam.GetLocalTransformation(&ctm, &resetsXformStack, frame);
            break;
        default: // _IGNORE_TRANSFORM:
            stat = true;
            ctm.SetIdentity();
            break;
        }
        if(!stat)
        {
            stealErrors(_errors, /*borrow*/ true);
            return 0;
        }

        mx = GusdUT_Gf::Cast(ctm);
    }
    return OBJ_Camera::applyInputIndependentTransform(ctx, mx);
}
Exemplo n.º 2
0
OP_ERROR SOP_UniPdist::cookMySop(OP_Context &context)
{
    // Before we do anything, we must lock our inputs.  Before returning,
    // we have to make sure that the inputs get unlocked.
    if (lockInputs(context) >= UT_ERROR_ABORT)
	return error();

    // Duplicate input geometry
    duplicateSource(0, context);

	float time = context.getTime();
	float dist = evalFloat(distanceName.getToken(), 0, time);
	
	GA_PointGroup *removeGroup = gdp->newPointGroup(REMOVE_GROUP_NAME);
	GA_PointGroup *keepGroup   = gdp->newPointGroup(KEEP_GROUP_NAME);
	

    // Flag the SOP as being time dependent (i.e. cook on time changes)
    flags().timeDep = 1;

	//Create a removeAttrib
	GA_RWHandleI removeAttrib(gdp->addIntTuple(GA_ATTRIB_POINT, "__remove__", 1));
	
	//Creating PointTree
	GEO_PointTreeGAOffset pttree;
	//Build PointTree with all the points
	pttree.build(gdp,NULL);
	
	
	//Create the Array wich holds the distance for the current point in the for loop
	UT_FloatArray ptdist;
	
	// Index offset
	const GA_IndexMap points = gdp->getPointMap();
	GA_Size ptoffsetindex;
	ptoffsetindex = points.offsetSize()-points.indexSize();
	

	//set all
	for (GA_Iterator ptoff(gdp->getPointRange()); !ptoff.atEnd(); ++ptoff) 
	{
		removeAttrib.set(*ptoff,0);
	}

	
	
	
	
	// loop over all points, find second closest point
	for (GA_Iterator ptoff(gdp->getPointRange()); !ptoff.atEnd(); ++ptoff)

	{
		int removeMe;
		removeMe = int(removeAttrib.get(*ptoff));
		if(removeMe)
		{
			removeGroup->addIndex(*ptoff-ptoffsetindex);
			continue;
		}
			
		// Create the Array which holds a list sorted on distance to current point in the for loop
		GEO_PointTree::IdxArrayType plist; //plist
		UT_Vector3 pos = gdp->getPos3(*ptoff); // create pos
		pttree.findAllCloseIdx(pos,dist,plist); // find all points within the search radius
		
		
		unsigned int tempListP = plist.entries(); //create a int for entries in the array

		for(int i=0;i < tempListP; ++i)
		{
			removeAttrib.set(plist[i],1); //set the tempList points to be removed
		}
		removeAttrib.set(*ptoff,0);
		keepGroup->addIndex(*ptoff-ptoffsetindex);
	}
	pttree.clear(); //clear the pointtree
	
	
    unlockInputs();
    return error();
}