Esempio n. 1
0
void wendy_GIO_ROP::save_mata_ass(string arDsoPath,string dpCachePath,GU_Detail *gdp )
{
    //get arnold dso path


    g_particle_mataAss assROP;
    ofstream fout;
    string getCacheDP=dpCachePath;

    stringstream ss(getCacheDP);
    string sub_str;
    vector <string> sp_strPath;
    sp_strPath.clear();
    while(getline(ss,sub_str,'.'))
    {
        sp_strPath.push_back(sub_str);
    }

    string newAssPathName = sp_strPath[0]+"."+sp_strPath[1]+string(".ass");
    fout.open(newAssPathName);
    assROP.setGioCachePath(getCacheDP);  // set Link GIO CACHE
    for (GA_AttributeDict::iterator it = gdp->getAttributeDict(GA_ATTRIB_POINT).begin(GA_SCOPE_PUBLIC); !it.atEnd(); ++it)
    {
        GA_Attribute *attrib = it.attrib();
        string attName( attrib->getName() );
        assROP.inserExtraMataInfo(attName);
    }
    //set ass bbox
    UT_BoundingBox BBOX;
    gdp->getBBox(&BBOX);
    BBOX.expandBounds(2,2,2);
    float min_x=BBOX.xmin();
    float min_y=BBOX.xmin();
    float min_z=BBOX.xmin();
    float max_x=BBOX.xmax();
    float max_y=BBOX.ymax();
    float max_z=BBOX.zmax();
    assROP.setBBOX(min_x,min_y,min_z,max_x,max_y,max_z);
    assROP.setDsoPath(arDsoPath);
    assROP.save(fout);
    fout.close();
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	
	logger.setLogLevel(Logging::Debug);
	struct args a;
	setArgs(a, argc, argv);

    GU_Detail		 gdp;
	bool binary = false;
	bool bbox = false;		

	if( a.b )
		binary = true;

	// convert all files in directory from hsff to geo or bgeo
	if (a.cd || a.c)
	{
		logger.debug("Found argument -cd or -c, trying to convert files in a directory.");
		std::vector<std::string> filesToConvert;
		if( a.cd )
		{
			logger.debug("Found argument -cd trying to convert files in a directory.");
			std::string info("Directory: ");
			info += a.cdDir;
			logger.debug(info);

			if( binary )
				logger.debug("Exporting binary bgeo files");
			else
				logger.debug("Exporting ascii geo files");

			//dirname.harden(argv[1]); // what does this mean, harden???

			fs::path p(a.cdDir);
			getHsffFiles(p, filesToConvert, binary);
		}else{
			logger.debug("Found argument -c trying to convert exactly one file.");
			//filename = UT_String(args.argp('c'));
			std::string info("Filename.");
			info += a.cFile;
			logger.debug(info);
			filesToConvert.push_back(a.cFile);
		}

		// export geo loop
		for( uint fId = 0; fId < filesToConvert.size(); fId++)
		{
			Hsff inFile(filesToConvert[fId]);
			if(!inFile.good)
			{
				logger.error(std::string("Error: problems reading file ") + filesToConvert[fId]);
				//cerr << "Error: problems reading file " << filesToConvert[fId] << "\n";
				inFile.close();
				continue;		
			}
			logger.debug(std::string("Converting file ") + filesToConvert[fId]);
			//cout << "Converting " << filesToConvert[fId] << "\n";
			inFile.doBinary = binary;

			unsigned int geoType = inFile.readGeoType();
			switch(geoType)
			{
			case PARTICLE:
				//cout << "Detected particle file.\n";
				createParticleGeo(inFile);
				break;
			case FLUID:
				//cout << "Detected fluid file.\n";
				createFluidGeo(inFile);
				break;
			case MESH:
				//cout << "Detected mesh file.\n";
				createMeshGeo(inFile);
				break;
			case CURVE:
				//cout << "Detected curve file.\n";
				createCurveGeo(inFile);
				break;
			case NURBS:
				//cout << "Detected nurbs file.\n";
				createNurbsGeo(inFile);
				break;
			}

			inFile.close();
		}
		return 0;
	}


	// get bbox from 1st argument
	if (a.bbox)
	{	
		std::string info("Getting BBox of ");
		info += a.bboxfile;
		logger.debug(info);
		if( !isValid(fs::path(a.bboxfile)))
		{
			logger.error("Could not read file.");
			return 1;
		}
		UT_BoundingBox bbox;
		getBBox(a.bboxfile, bbox);
		cout << "BBox: " << bbox.xmin() << " " << bbox.ymin() << " " << bbox.zmin() << " " << bbox.xmax() << " " << bbox.ymax() << " " << bbox.zmax() << "\n";
	}

	if (a.ptc)
	{
		std::string info("Getting pointcloud of ");
		info += a.ptcfile;
		logger.debug(info);
		std::string outFile = pystring::replace(a.ptcfile, ".geo", ".hsffp"); // add a 'p' to show that it is a point cloud file from this tool
		if( pystring::endswith(a.ptcfile, "bgeo"))
			outFile = pystring::replace(a.ptcfile, ".bgeo", ".hsffp"); // add a 'p' to show that it is a point cloud file from this tool
		UT_BoundingBox bbox;
		readPtc(a.ptcfile, outFile, a.ptcdv, bbox);
		cout << "BBox: " << bbox.xmin() << " " << bbox.ymin() << " " << bbox.zmin() << " " << bbox.xmax() << " " << bbox.ymax() << " " << bbox.zmax() << "\n";
	}

	//cout << "numargs: " << args.argc() << "\n"; 

	
	
 //   if (args.argc() == 3)
	//{
	//	UT_String dobin;
	//	
	//	dobin.harden(argv[2]);
	//	if(dobin.isInteger())
	//	{
	//		if( dobin.toInt() == 0)
	//			binary = true;
	//		else
	//			binary = false;
	//	}
	//}

	//if(binary)
	//	cout << "Writing from source dir " << dirname << " as binary\n";
	//else
	//	cout << "Writing from source dir " << dirname << " as ascii\n";
	


    return 0;

}
Esempio n. 3
0
void SOP_Scallop::SaveDivMap(float time)
{
        OP_Context context(time);

        bool clip = (lockInputs(context) < UT_ERROR_ABORT);

        UT_BoundingBox bbox;

        if(clip)
        {
                const GU_Detail* input = inputGeo(0,context);
                if(input != NULL)
                {
                        //UT_Matrix4 bm;
                        int res = input->getBBox(&bbox);
                        if(res == 0) clip = false;
                }
                else clip = false;
                unlockInputs();
        };

        if(!clip) return;

        UT_String file;
        STR_PARM(file,"mappath", 11, 0, time);

        float& now=time;
        //////////////////////////////////////////////////////////////////////////

        Daemon::now=now;
        Daemon::bias = evalFloat("bias",0,now);

        int cnt = evalInt("daemons", 0, now);

        Daemon* daemons=new Daemon[cnt];

        float weights = 0;

        int totd=0;

        float maxR = 0;
        for(int i=1;i<=cnt;i++)
        {
                bool skip = (evalIntInst("enabled#",&i,0,now)==0);
                if(skip) continue;

                Daemon& d = daemons[totd];

                UT_String path = "";
                evalStringInst("obj#", &i, path, 0, now);

                if(path == "") continue;

                SOP_Node* node = getSOPNode(path);

                OBJ_Node* obj = dynamic_cast<OBJ_Node*>(node->getParent());

                if(obj == NULL) continue;

                obj->getWorldTransform(d.xform,context);

                d.weight = evalFloatInst("weight#",&i,0,now);

                d.c[0] = evalFloatInst("color#",&i,0,now);
                d.c[1] = evalFloatInst("color#",&i,1,now);
                d.c[2] = evalFloatInst("color#",&i,2,now);

                int mth = evalIntInst("model#",&i,0,now);

                switch(mth)
                {
                case 1:
                        d.method = Methods::Spherical;
                        break;
                case 2:
                        d.method = Methods::Polar;
                        break;
                case 3:
                        d.method = Methods::Swirl;
                        break;
                case 4:
                        d.method = Methods::Trigonometric;
                        break;
                case 5:
                        {
                                UT_String script;
                                evalStringInst("vexcode#", &i, script, 0, now);
                                d.SetupCVEX(script);

                                break;
                        };
                case 0:
                default:
                        d.method = Methods::Linear;
                };

                d.power = evalFloatInst("power#",&i,0,now);
                d.radius = evalFloatInst("radius#",&i,0,now);
                d.parameter = evalFloatInst("parameter#",&i,0,now);

                if(d.radius > maxR) maxR = d.radius;

                weights+=d.weight;
                totd++;
        };

        if(totd == 0)
        {
                delete [] daemons;
                return;
        };

        float base = 0.0;
        for(int i=0;i<totd;i++)
        {
                Daemon& d = daemons[i];
                d.range[0]=base;
                d.range[1] = base+d.weight/weights;
                base=d.range[1];
        };

        //////////////////////////////////////////////////////////////////////////
        int total = evalInt("count",0,now);
        int degr = evalInt("degr",0,now);

        total >>= degr;

        GU_Detail det;

        UT_Vector3 current(0,0,0);
        float C[3] = { 0,0,0 };

        float R=1.0f;

        float param=0.0f;

        srand(0);

        bool medial = (evalInt("mapmedial",0,now)!=0);
        int mapdiv = evalInt("mapdiv",0,now);

        //BoundBox Box;
        OctreeBox O(mapdiv);

        //if(medial)
        //{
                O.bbox=bbox;
        //}
        //else
        //{
        //      BoundBox::limit = evalInt("nodecount", 0, now);

        //      BoundBox::medial = (evalInt("mapmedial",0,now)!=0);

        //      float boxb[6];
        //      memcpy(boxb,bbox.minvec().vec,12);
        //      memcpy(boxb+3,bbox.maxvec().vec,12);
        //      Box.Organize(boxb);
        //};

        for(int i=-50;i<total;i++)
        {
                bool ok = false;

                float w = double(rand())/double(RAND_MAX);

                for(int j=0;j<totd;j++)
                {
                        ok = daemons[j].Transform(w,current,C,R,param);
                        if(ok) break;
                };

                if(i<0) continue;

                //if(medial)
                //{
                        float P[4] = { current.x(), current.y(), current.z(), R };
                        O.Insert(P);
                //}
                //else
                //{
                //      Box.CheckPoint(current.vec);
                //}
        };

        delete [] daemons;

        //////////////////////////////////////////////////////////////////////////

        int ita[3] = {-1,-1,-1};

        //if(medial)
        //{
                int count = 0;
                OctreeBox::at = det.addPrimAttrib("count",4,GB_ATTRIB_INT,&count);
                det.addVariableName("count","COUNT");

                float radius = 0.0f;
                OctreeBox::rt = det.addAttrib("radius",4,GB_ATTRIB_FLOAT,&radius);
                det.addVariableName("radius","RADIUS");

                OctreeBox::it = det.addPrimAttrib("mask",12,GB_ATTRIB_INT,ita);
                det.addVariableName("mask","MASK");

                float box[6] = {bbox.xmin(),bbox.xmax(),bbox.ymin(),bbox.ymax(),bbox.zmin(),bbox.zmax()};
                det.addAttrib("bbox",24,GB_ATTRIB_FLOAT,box);

                O.maxlevel = 0x01<<mapdiv;
                O.parentbbox = bbox;

                O.Build(det);
        //}
        //else  Box.Build(det);

        det.save(file.buffer(),1,NULL);

        // ...SAVE ATLAS

        {
                UT_String atlas =file;
                atlas+=".atlas";
                FILE* fa = fopen(atlas.buffer(),"wb");

                GEO_PrimList& pl = det.primitives();

                int cnt = pl.entries();

                fwrite(&cnt,sizeof(int),1,fa);

                float bb[6] = { bbox.xmin(), bbox.xmax(), bbox.ymin(), bbox.ymax(), bbox.zmin(), bbox.zmax() };
                fwrite(bb,sizeof(float),6,fa);

                fwrite(&(O.maxlevel),sizeof(int),1,fa);
                fwrite(&(O.maxlevel),sizeof(int),1,fa);
                fwrite(&(O.maxlevel),sizeof(int),1,fa);

                for(int i=0;i<cnt;i++)
                {
                        const GEO_PrimVolume* v = dynamic_cast<const GEO_PrimVolume*>(pl[i]);
                        UT_BoundingBox b;
                        v->getBBox(&b);
                        float _bb[6] = { b.xmin(), b.xmax(), b.ymin(), b.ymax(), b.zmin(), b.zmax() };
                        fwrite(_bb,sizeof(float),6,fa);

                        // MASK
                        fwrite(v->castAttribData<int>(OctreeBox::it),sizeof(int),3,fa);
                }

                fclose(fa);
        }
};