Beispiel #1
0
MStatus setPlayback(double min, double max)
{
    MStatus status = MS::kSuccess;
    MAnimControl anim;
    MTime minTime, maxTime, curTime;
    minTime.setValue(min);
    maxTime.setValue(max);

    status = anim.setMinTime(minTime);
    status = anim.setAnimationStartTime(minTime);

    if (max > 0)
    {
        status = anim.setMaxTime(maxTime);
        status = anim.setAnimationEndTime(maxTime);
    }

    return status;
}
Beispiel #2
0
MStatus PTCMapCmd::doIt( const MArgList& args)
{
    MStatus status = parseArgs( args );

    if( status != MS::kSuccess ) return status;

    MArgDatabase argData(syntax(), args);

    MAnimControl timeControl;
    MTime time = timeControl.currentTime();
    int frame =int(time.value());
    MString proj;
    MGlobal::executeCommand( MString ("string $p = `workspace -q -fn`"), proj );

    MString cache_path = proj + "/data";
    MString cache_name = "foo";
    MString cache_attrib;
    double cache_mindist = 0.1;
    int max_level = 3;
    double root_size = 32;
    MString dem_trans = "nil";
    double cloud_os = 0.05;
    MString key_trans = "nil";
    MString eye_trans = "nil";

    if (argData.isFlagSet("-p")) argData.getFlagArgument("-p", 0, cache_path);
    if (argData.isFlagSet("-n")) argData.getFlagArgument("-n", 0, cache_name);
    if (argData.isFlagSet("-a")) argData.getFlagArgument("-a", 0, cache_attrib);
    if (argData.isFlagSet("-mnd")) argData.getFlagArgument("-mnd", 0, cache_mindist);
    if (argData.isFlagSet("-ml")) argData.getFlagArgument("-ml", 0, max_level);
    if (argData.isFlagSet("-rs")) argData.getFlagArgument("-rs", 0, root_size);
    if (argData.isFlagSet("-t")) argData.getFlagArgument("-t", 0, dem_trans);
    if(argData.isFlagSet("-o")) argData.getFlagArgument("-o", 0, cloud_os);
    if(argData.isFlagSet("-tk")) argData.getFlagArgument("-tk", 0, key_trans);
    if(argData.isFlagSet("-te")) argData.getFlagArgument("-te", 0, eye_trans);

    float def_area = root_size;
    int last = 0;
    while(last < max_level-2) {
        def_area /= 2;
        last++;
    }

    def_area = 1.0f;

    //def_area *= def_area;

// get bounding box center
    MDagPath p_bbox;

    zWorks::getTypedPathByName(MFn::kTransform, dem_trans, p_bbox);
    MObject o_bbox = p_bbox.transform();

    float m_space[4][4];
    m_space[0][0]=1;
    m_space[0][1]=0;
    m_space[0][2]=0;
    m_space[1][0]=0;
    m_space[1][1]=1;
    m_space[1][2]=0;
    m_space[2][0]=0;
    m_space[2][1]=0;
    m_space[2][2]=1;
    m_space[3][0]=0;
    m_space[3][1]=0;
    m_space[3][2]=0;

    if(o_bbox.isNull()) MGlobal::displayWarning("Cannot find pmap dimension, use default space.");
    else zWorks::getTransformWorldNoScale(p_bbox.partialPathName(), m_space);

    XYZ root_center(m_space[3][0], m_space[3][1], m_space[3][2]);

// get key light dir
    MDagPath p_key;

    zWorks::getTypedPathByName(MFn::kTransform, key_trans, p_key);
    MObject o_key = p_key.transform();

    m_space[0][0]=1;
    m_space[0][1]=0;
    m_space[0][2]=0;
    m_space[1][0]=0;
    m_space[1][1]=1;
    m_space[1][2]=0;
    m_space[2][0]=0;
    m_space[2][1]=0;
    m_space[2][2]=1;
    m_space[3][0]=0;
    m_space[3][1]=0;
    m_space[3][2]=0;

    if(o_key.isNull()) MGlobal::displayWarning("Cannot find key camera, use default space.");
    else zWorks::getTransformWorldNoScale(p_key.partialPathName(), m_space);

    XYZ key_dir(m_space[2][0], m_space[2][1], m_space[2][2]);
    key_dir.normalize();

// get view dir
    MDagPath p_eye;

    zWorks::getTypedPathByName(MFn::kTransform, eye_trans, p_eye);
    MObject o_eye = p_eye.transform();

    m_space[0][0]=1;
    m_space[0][1]=0;
    m_space[0][2]=0;
    m_space[1][0]=0;
    m_space[1][1]=1;
    m_space[1][2]=0;
    m_space[2][0]=0;
    m_space[2][1]=0;
    m_space[2][2]=1;
    m_space[3][0]=0;
    m_space[3][1]=0;
    m_space[3][2]=0;

    if(o_eye.isNull()) MGlobal::displayWarning("Cannot find render camera, use default space.");
    else zWorks::getTransformWorldNoScale(p_eye.partialPathName(), m_space);

    XYZ view_dir(-m_space[2][0], -m_space[2][1], -m_space[2][2]);
    view_dir.normalize();

// additional attribs
    MStringArray attribArray;
    cache_attrib.split('.', attribArray);

    MSelectionList slist;
    MGlobal::getActiveSelectionList( slist );
    MItSelectionList list( slist, MFn::kParticle, &status );
    if (MS::kSuccess != status) {
        displayError( "Could not create selection list iterator");
        return status;
    }

    if (list.isDone()) {
        displayError( "No particles selected" );
        return MS::kSuccess;
    }

    MDagPath fDagPath;
    MObject component;
    unsigned npt = 0,acc = 0;
    for(; !list.isDone(); list.next()) {
        list.getDagPath (fDagPath, component);
        MFnParticleSystem ps( fDagPath );
        npt += ps.count();
    }

    if(npt < 1) {
        MGlobal::displayInfo(" zero particle: do nothing ");
        return MS::kSuccess;
    }

    std::list<AParticle *> particles;

    RGRID *buf = new RGRID[npt];
    unsigned *idxb = new unsigned[npt];
    float *opab = new float[npt];
    float *ageb = new float[npt];

    list.reset();
    for(; !list.isDone(); list.next()) {
        list.getDagPath (fDagPath, component);
        MFnParticleSystem ps( fDagPath );

        MVectorArray positions;
        ps.position( positions );

        MVectorArray velarr;
        ps.velocity( velarr );

        MIntArray ids;
        ps.particleIds(ids);

        MVectorArray cols;
        ps.rgb(cols);

        MDoubleArray opas;
        ps.opacity(opas);

        MDoubleArray ages;
        ps.opacity(ages);

        for(unsigned i=0; i<positions.length(); i++,acc++ ) {
            buf[acc].pos.x = positions[i].x;
            buf[acc].pos.y = positions[i].y;
            buf[acc].pos.z = positions[i].z;
            buf[acc].nor.x = velarr[i].x;
            buf[acc].nor.y = velarr[i].y;
            buf[acc].nor.z = velarr[i].z;
            buf[acc].area = def_area;

            if(ps.hasRgb()) {
                buf[acc].col.x = cols[i].x;
                buf[acc].col.y = cols[i].y;
                buf[acc].col.z = cols[i].z;
            }
            else buf[acc].col = XYZ(1,1,1);

            idxb[acc] = ids[i];

            if(ps.hasOpacity ()) opab[acc] = opas[i];
            else opab[acc] = 1.f;

            ageb[acc] = ages[i];

            AParticle *pt = new AParticle();
            pt->pos.x = positions[i].x;
            pt->pos.y = positions[i].y;
            pt->pos.z = positions[i].z;
            pt->r = def_area;

            particles.push_back(pt);
        }
    }
    /*
    	Z3DTexture* tree = new Z3DTexture();
    	tree->setGrid(buf, npt);
    	tree->constructTree(root_center, root_size, max_level);
    	tree->setGridIdData(idxb, npt);
    	tree->setGridOpacityData(opab, npt);
    	tree->setGridAgeData(ageb, npt);
    	MGlobal::displayInfo(MString(" num grid ")+ tree->getNumGrid());
    	MGlobal::displayInfo(MString(" num voxel ")+ tree->getNumVoxel());
    	MGlobal::displayInfo(MString(" num leaf ")+ tree->getNumLeaf());
    	MGlobal::displayInfo(MString(" max level ")+ tree->getMaxLevel());
    	MGlobal::displayInfo(" calculating voxel volume occlusion...");
    	tree->occlusionVolume(cloud_os, key_dir, view_dir);
    	MGlobal::displayInfo(" done");
    	MGlobal::displayInfo(" updating grid distance to neighbour...");
    	tree->distanceToNeighbour(cache_mindist);
    	MGlobal::displayInfo(" done");

    	char filename[512];
    	sprintf( filename, "%s/%s.%d.pmap", cache_path.asChar(), cache_name.asChar(), frame );
    	MGlobal::displayInfo(MString("PTCMap saved ") + filename);
    	tree->save(filename);

    	delete tree;
    	*/
    if(!particles.empty()) {
        GPUOctree *data = new GPUOctree();
        data->create(root_center, root_size, 8, particles);
        MGlobal::displayInfo(MString(" num voxel ")+ data->getNumVoxel()+ MString(" minvar ")+ data->getMinVariation()+ MString(" max level ")+ data->getMaxLevel()+ MString(" filter size ")+ def_area);

        char filename[512];
        sprintf( filename, "%s/%s.%d", cache_path.asChar(), cache_name.asChar(), frame );

        data->dumpIndirection(filename);

        delete data;
        particles.clear();
    }

    return MS::kSuccess;
}
//----------------------------------------------------------------------------------------------------------------------
// This method should be overridden in user defined nodes.
// Recompute the given output based on the nodes inputs.
// The plug represents the data value that needs to be recomputed, and the data block holds the storage
// for all of the node'_scale attributes.
//----------------------------------------------------------------------------------------------------------------------
MStatus OceanNode::compute( const MPlug &_plug , MDataBlock &_data ){
    MStatus status;
    // see if we get the output plug
    if( _plug == m_output){    

        MDataHandle dataHandle;

        dataHandle = _data.inputValue(m_resolution, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for resolution plug");

        if (m_res != dataHandle.asInt()){
            switch(dataHandle.asInt()){
                case 0:
                    m_ocean->setResolution(128);
                    MGlobal::displayInfo("Resolution: 128");
                    break;
                case 1:
                    m_ocean->setResolution(256);
                    MGlobal::displayInfo("Resolution: 256");
                    break;
                case 2:
                    m_ocean->setResolution(512);
                    MGlobal::displayInfo("Resolution: 512");
                    break;
                case 3:
                    m_ocean->setResolution(1024);
                    MGlobal::displayInfo("Resolution: 1024");
                    break;
                default:
                    break;
            }
            m_res = dataHandle.asInt();
        }

        dataHandle = _data.inputValue( m_amplitude , &status );
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL( status , "Unable to get data handle for amplitude plug" );
        // now get the value for the data handle as a double
        double amp = dataHandle.asDouble();
        m_ocean->setAmplitude(amp);

        dataHandle = _data.inputValue(m_frequency, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get handle for \"frequency\" plug");
        double freq = dataHandle.asDouble();
        m_ocean->setFrequency(freq);

        dataHandle = _data.inputValue(m_windDirectionX, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for windDirectionX plug");
        // now get value for data handle
        double wdx = dataHandle.asDouble();
        dataHandle = _data.inputValue(m_windDirectionZ, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for windDirectionY plug");
        // now get value for data handle
        double wdz = dataHandle.asDouble();
        m_ocean->setWindVector(make_float2(wdx, wdz));

        dataHandle = _data.inputValue(m_windSpeed, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for windSpeed plug");
        // now get value for data handle
        double ws = dataHandle.asDouble();
        m_ocean->setWindSpeed(ws);

        // Only create a new frequency domain if either amplitude or the wind vecotr has changed
        if (m_amp != amp || m_wdx != wdx || m_wdz != wdz || m_ws != ws ){
            MGlobal::displayInfo("here");
            m_ocean->createH0();
            m_amp = amp;
            m_wdx = wdx;
            m_wdz = wdz;
            m_ws = ws;
        }

        dataHandle = _data.inputValue(m_choppiness, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for the choppiness plug");
        double choppiness = dataHandle.asDouble();

        dataHandle = _data.inputValue(m_time, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to get data handle for time plug");
        MTime time = dataHandle.asTime();

        MDataHandle outputData = _data.outputValue(m_output, &status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL( status , "Unable to get data handle for output plug" );

        MFnMeshData mesh;
        MObject outputObject = mesh.create(&status);
        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to create output mesh");

        // Find the current frame number we're on and create the grid based on this
        MAnimControl anim;
        anim.setMinTime(time);

        createGrid((int)pow(2.0, m_res+7), anim.currentTime().value()/24, choppiness, outputObject, status);

        CHECK_STATUS_AND_RETURN_MSTATUS_IF_FAIL(status, "Unable to to create grid");

        outputData.set(outputObject);

        // clean the output plug, ie unset it from dirty so that maya does not re-evaluate it
        _data.setClean( _plug );

        return MStatus::kSuccess;
    }

    return MStatus::kUnknownParameter;
}
Beispiel #4
0
MStatus vxCache::doIt( const MArgList& args ) 
{

	MStatus status = parseArgs( args );
	
	if( status != MS::kSuccess ) return status;
	
	MArgDatabase argData(syntax(), args);
	
	MAnimControl timeControl;
	MTime time = timeControl.currentTime();
	int frame =int(time.value());

	MString proj;
	MGlobal::executeCommand( MString ("string $p = `workspace -q -fn`"), proj );
	
	MSelectionList selList;
	MGlobal::getActiveSelectionList ( selList );
	MItSelectionList iter( selList );

	MString cache_path = proj + "/data/";
	MString cache_name;
	MString scene_name = "untitled";
	worldSpace = false;
	
	if (argData.isFlagSet("-p")) argData.getFlagArgument("-p", 0, cache_path);
	if (argData.isFlagSet("-n")) argData.getFlagArgument("-n", 0, cache_name);
	if (argData.isFlagSet("-w")) argData.getFlagArgument("-w", 0, worldSpace);

	for ( ; !iter.isDone(); iter.next() )
	{								
		MDagPath meshPath;		
		iter.getDagPath( meshPath );
		
		meshPath.extendToShape();
		
		MObject meshObj = meshPath.node();
	
		MString surface = meshPath.partialPathName();
	
		zWorks::validateFilePath(surface);

		char filename[512];

		cache_name = surface;
		
		if(argData.isFlagSet("-sg")) sprintf( filename, "%s/%s.mcf", cache_path.asChar(), cache_name.asChar() );
		else sprintf( filename, "%s/%s.%d.mcf", cache_path.asChar(), cache_name.asChar(), frame );

		MDagPath surfDag;

		if ( meshPath.hasFn(MFn::kMesh)) 
		{
			writeMesh(filename, meshPath, meshObj);
			MGlobal::displayInfo ( MString("vxCache writes ") + filename);
		}
		else
			MGlobal::displayError ( surface + "- Cannot find mesh to write!" );
	}

	if ( selList.length() == 0 )
	{
		MGlobal:: displayError ( "Nothing is selected!" );
		return MS::kSuccess;
	}
	

	
 return MS::kSuccess;
 }
MStatus depthMap::doIt( const MArgList& args ) 
{

	MStatus status = parseArgs( args );
	
	if( status != MS::kSuccess ) return status;
	
	MArgDatabase argData(syntax(), args);
	
	MAnimControl timeControl;
	MTime time = timeControl.currentTime();
	int frame =int(time.value());
	
	MString scene_name, camera_name, title;
	if (argData.isFlagSet("-n")) argData.getFlagArgument("-n", 0, title);
	else return MS::kFailure;
	if (argData.isFlagSet("-sc")) argData.getFlagArgument("-sc", 0, scene_name);
	else return MS::kFailure;
	if (argData.isFlagSet("-ca")) argData.getFlagArgument("-ca", 0, camera_name);
	else return MS::kFailure;
	
	m_eye[0][0]=1; m_eye[0][1]=0; m_eye[0][2]=0; m_eye[0][3]=0;
	m_eye[1][0]=0; m_eye[1][1]=1; m_eye[1][2]=0; m_eye[1][3]=0;
	m_eye[2][0]=0; m_eye[2][1]=0; m_eye[2][2]=1; m_eye[2][3]=0;
	m_eye[3][0]=0; m_eye[3][1]=0; m_eye[3][2]=0; m_eye[3][3]=1;
	
// get eye space
	zWorks::getTypedPathByName(MFn::kTransform, camera_name, p_eye);
	MObject o_eye = p_eye.transform();
	if(o_eye.isNull()) MGlobal::displayWarning("Cannot find eye camera, use default space.");
	else zWorks::getTransformWorldNoScale(p_eye.partialPathName(), m_eye);
	
	m_eye[0][0] *=-1; m_eye[0][1] *=-1; m_eye[0][2] *=-1;
	m_eye[2][0] *=-1; m_eye[2][1] *=-1; m_eye[2][2] *=-1;
	
	p_eye.extendToShape();
	MFnCamera feye(p_eye);
	double fov = feye.horizontalFieldOfView();
	int map_w = 1024, map_h = 1024;
	float* data = new float[map_w * map_h];
	
	for(int i=0; i<map_w * map_h; i++) data[i] = 10e6;

	string sscene = scene_name.asChar();
	zGlobal::changeFrameNumber(sscene, frame);
	MGlobal::displayInfo ( MString(" calculating ") + sscene.c_str());
	
	FXMLScene* fscene = new FXMLScene();
	if(fscene->load(sscene.c_str()) != 1) {
		MGlobal::displayWarning(" cannot open scene, do nothing.");
		return MS::kFailure;
	}
	
	fscene->depthMap(data, map_w, map_h, fov, m_eye);
	
	zGlobal::cutByLastSlash(sscene);
	sscene = sscene + "/" + title.asChar() + ".1.exr";
	zGlobal::changeFrameNumber(sscene, frame);
	//zGlobal::changeFilenameExtension(sscene, "exr");
	MGlobal::displayInfo ( MString(" saving ") + sscene.c_str());
	
	M44f amat(m_eye[0][0], m_eye[0][1], m_eye[0][2], m_eye[0][3],
			m_eye[1][0], m_eye[1][1], m_eye[1][2], m_eye[1][3],
			m_eye[2][0], m_eye[2][1], m_eye[2][2], m_eye[2][3],
			m_eye[3][0], m_eye[3][1], m_eye[3][2], m_eye[3][3] );
	ZFnEXR::saveCameraNZ(data, amat, fov, sscene.c_str(), map_w, map_h);
	delete[] data;
	delete fscene;

 return MS::kSuccess;
 }
Beispiel #6
0
MStatus ExportACache::doIt( const MArgList& args ) 
{

	MStatus status = parseArgs( args );
	
	if( status != MS::kSuccess ) return status;
	
	MArgDatabase argData(syntax(), args);
	
	MAnimControl timeControl;
	MTime time = timeControl.currentTime();
	int frame =int(time.value());

	MString proj;
	MGlobal::executeCommand( MString ("string $p = `workspace -q -fn`"), proj );
	
	MSelectionList selList;
	MGlobal::getActiveSelectionList ( selList );

	if ( selList.length() == 0 ) {
		MGlobal:: displayError ( "Nothing is selected!" );
		return MS::kSuccess;
	}
	
	MItSelectionList iter( selList );

	MString cache_path = proj + "/data/";
	MString cache_name;
	MString scene_name = "untitled";
	MString sscat("spaceBS");
	MString seye("spaceBS");
	
	if (argData.isFlagSet("-p")) argData.getFlagArgument("-p", 0, cache_path);
	if (argData.isFlagSet("-t")) argData.getFlagArgument("-t", 0, scene_name);
	
	m_space[0][0]=1; m_space[0][1]=0; m_space[0][2]=0;
	m_space[1][0]=0; m_space[1][1]=1; m_space[1][2]=0;
	m_space[2][0]=0; m_space[2][1]=0; m_space[2][2]=1;
	m_space[3][0]=0; m_space[3][1]=0; m_space[3][2]=0;
	
	m_eye[0][0]=1; m_eye[0][1]=0; m_eye[0][2]=0;
	m_eye[1][0]=0; m_eye[1][1]=1; m_eye[1][2]=0;
	m_eye[2][0]=0; m_eye[2][1]=0; m_eye[2][2]=1;
	m_eye[3][0]=0; m_eye[3][1]=0; m_eye[3][2]=0;
	
	if (argData.isFlagSet("-bc")) {
		argData.getFlagArgument("-bc", 0, sscat);
	
// get back light space
		MDagPath p_backscat;
		
		AHelper::getTypedPathByName(MFn::kTransform, sscat, p_backscat);
		MObject o_backscat = p_backscat.transform();
		if(o_backscat.isNull()) MGlobal::displayWarning("Cannot find backscat camera, use default space.");
		else AHelper::getTransformWorldNoScale(p_backscat.partialPathName(), m_space);
	}
	
	if (argData.isFlagSet("-ec")) {
		argData.getFlagArgument("-ec", 0, seye);
	
// get eye space
		
		AHelper::getTypedPathByName(MFn::kTransform, seye, p_eye);
		MObject o_eye = p_eye.transform();
		if(o_eye.isNull()) MGlobal::displayWarning("Cannot find eye camera, use default space.");
		else AHelper::getTransformWorldNoScale(p_eye.partialPathName(), m_eye);
	}
	
	m_mesh_list.clear();
	m_nurbs_list.clear();

	for ( ; !iter.isDone(); iter.next() ) {								
		MDagPath meshPath;		
		iter.getDagPath( meshPath );
		
		if( meshPath.hasFn(MFn::kMesh))  m_mesh_list.append(meshPath);
		if( meshPath.hasFn(MFn::kNurbsSurface)) m_nurbs_list.append(meshPath);
		
	}	
	
	int istart = 1, iend = 1;
	if(argData.isFlagSet("-fs")) argData.getFlagArgument("-fs", 0, istart);
	if(argData.isFlagSet("-fe")) argData.getFlagArgument("-fe", 0, iend);
		
// log on start		
	if(frame == istart) MGlobal::displayInfo( MString("acache ") + scene_name + " to " + cache_path);

	char file_name[512];
	    
	sprintf( file_name, "%s/%s.%d.scene", cache_path.asChar(), scene_name.asChar(), frame );

	if(frame == istart) save(file_name, frame, 1);
	else save(file_name, frame, 0);
	
	MGlobal::displayInfo( MString("writes frame ") + frame);
	
	if(argData.isFlagSet("-ej")) {
		MString jobparam;
		argData.getFlagArgument("-ej", 0, jobparam);
			
		std::string sjob = file_name;
		SHelper::cutByFirstDot(sjob);
		std::string stitle = sjob;
		sjob = sjob + ".txt";
		
		std::ofstream ffjob;
		ffjob.open(sjob.c_str(), ios::out);
		char job_line[1024];
		for(int i=istart; i<= iend; i++) {
			sprintf(job_line, "%s %s.%i.scene\n", jobparam.asChar(), stitle.c_str(), i);
			ffjob.write((char*)job_line, strlen(job_line));
		}
		ffjob.close();
		
		MGlobal::displayInfo(MString("writes external job script: ") + sjob.c_str());
	}

 return MS::kSuccess;
 }