int
main(int argc, char *argv[])
{
    // Make sure to install the GU plug-ins
    GU_Detail::loadIODSOs();

    // Process command line arguments
    UT_Args	args;
    args.initialize(argc, argv);
    args.stripOptions("l:o:v:h");

    if (args.found('h'))
    {
	usage(argv[0]);
	return 1;
    }

    const char	*output = args.found('o') ? args.argp('o') : "stdout.geo";
    int		 lod = args.found('l') ? args.iargp('l') : 3;
    const char	*viewportLOD = args.found('v') ? args.argp('v') : "full";
    GU_Detail	 gdp;

    // Create a packed sphere primitive
    GU_PrimPacked	*pack = GU_PrimPacked::build(gdp, "PackedSphere");
    if (!pack)
	fprintf(stderr, "Can't create a packed sphere\n");
    else
    {
	// Set the location of the packed primitive's point.
	UT_Vector3 pivot(0, 0, 0);
	pack->setPivot(pivot);
	gdp.setPos3(pack->getPointOffset(0), pivot);

	// Set the options on the sphere primitive
	UT_Options	options;
	options.setOptionI("lod", lod);
	pack->implementation()->update(options);
	pack->setViewportLOD(GEOviewportLOD(viewportLOD));

	// Save the geometry.  With the .so file installed, this should load
	// into Houdini and should be rendered by mantra.
	if (!gdp.save(output, NULL).success())
	    fprintf(stderr, "Error saving to: %s\n", output);
    }
    return 0;
}
Beispiel #2
0
// *****************************************************************************
int inputFromGto( const char *filename, bool ascii, bool verbose )
{
    using namespace Gto;

    GU_Detail gdp;
    
    RawDataBaseReader reader;
    
    if( verbose ) std::cerr << "Loading " << filename << "..." << std::flush;

    if( ! reader.open( filename ) )
    {
        std::cerr << "Unable to load input geometry" << std::endl;
        exit(1);
    }

    if( verbose ) std::cerr << "Done" << std::endl;
    if( verbose ) std::cerr << "Building objects..." << std::flush;

    const RawDataBase *db = reader.dataBase();
    for( int oi = 0; oi < db->objects.size(); ++oi )
    {
        const Object *o = db->objects[oi];

        if( o->protocol == GTO_PROTOCOL_PARTICLE ||
            o->protocol == "warped particle")
        {
            HGto::Particle particle( o->name );

            for( int ci = 0; ci < o->components.size(); ++ci )
            {
                const Component *c = o->components[ci];

                for( int pi = 0; pi < c->properties.size(); ++pi )
                {
                    Property *p = c->properties[pi];

                    if( c->name == GTO_COMPONENT_OBJECT )
                    {
                        if( p->name == GTO_PROPERTY_GLOBAL_MATRIX )
                        {
                            memcpy( &particle.globalMatrix(),
                                    p->floatData, 
                                    p->size * p->width * sizeof(float) );
                        }
                    }

                    if( c->name == GTO_COMPONENT_POINTS )
                    {
                        if( p->name == GTO_PROPERTY_POSITION )
                        {
                            particle.positions().resize( p->size );
                            memcpy( &particle.positions().front(), 
                                    p->floatData, 
                                    p->size * p->width * sizeof(float) );
                        }
                        else
                        {
                            // For all other properties
                            HGto::GtoAttribute *attr = NULL;

                            if( p->type == Gto::Float && p->width == 1)
                            {
                                attr = new HGto::FloatAttribute(p->name, p->size);
                                HGto::FloatAttribute *fattr = (HGto::FloatAttribute*)attr;

                                memcpy(&fattr->data().front(), 
                                       p->floatData, 
                                       sizeof( float ) * p->size);

                                particle.attributes().push_back(attr);
                            }
                            else if( p->type == Gto::Float && p->width == 3)
                            {
                                attr = new HGto::VectorAttribute(p->name, p->size);
                                HGto::VectorAttribute *vattr = (HGto::VectorAttribute*)attr;

                                memcpy(&vattr->data().front(), 
                                       p->floatData, 
                                       sizeof( float ) * p->size * 3);

                                particle.attributes().push_back(attr);
                            }
                            else if( p->type == Gto::Int && p->width == 1)
                            {
                                attr = new HGto::IntAttribute(p->name, p->size);
                                HGto::IntAttribute *iattr = (HGto::IntAttribute*)attr;

                                memcpy(&iattr->data().front(), 
                                       p->int32Data, 
                                       sizeof( int ) * p->size * 1);

                                particle.attributes().push_back(attr);
                            }
                        }
                    }
                }

            }

            particle.declareHoudini( gdp );
        }
        else if( o->protocol == GTO_PROTOCOL_POLYGON )
        {
            HGto::Poly polyObject( o->name );

            for( int ci = 0; ci < o->components.size(); ++ci )
            {
                const Component *c = o->components[ci];

                for( int pi = 0; pi < c->properties.size(); ++pi )
                {
                    const Property *p = c->properties[pi];

                    if( c->name == GTO_COMPONENT_OBJECT )
                    {
                        if( p->name == GTO_PROPERTY_GLOBAL_MATRIX )
                        {
                            memcpy( &polyObject.globalMatrix(),
                                    p->floatData, 
                                    p->size * p->width * sizeof(float) );
                        }
                    }

                    if( c->name == GTO_COMPONENT_POINTS )
                    {
                        if( p->name == GTO_PROPERTY_POSITION )
                        {
                            polyObject.positions().resize( p->size );
                            memcpy( &polyObject.positions().front(), 
                                    p->floatData, 
                                    p->size * p->width * sizeof(float) );
                        }
                    }

                    if( c->name == GTO_COMPONENT_ELEMENTS )
                    {
                        if( p->name == GTO_PROPERTY_TYPE )
                        {
                            polyObject.elementsType().resize( p->size );
                            memcpy( &polyObject.elementsType().front(),
                                    p->uint8Data, 
                                    p->size * p->width * sizeof(char) );
                        }
                        if( p->name == GTO_PROPERTY_SIZE )
                        {
                            polyObject.elementsSize().resize( p->size );
                            memcpy( &polyObject.elementsSize().front(),
                                    p->uint16Data, 
                                    p->size * p->width * sizeof(short) );
                        }
                    }
                    if( c->name == GTO_COMPONENT_INDICES )
                    {
                        if( p->name == GTO_PROPERTY_VERTEX )
                        {
                            polyObject.indicesVertex().resize( p->size );
                            memcpy( &polyObject.indicesVertex().front(),
                                    p->int32Data, 
                                    p->size * p->width * sizeof(int) );
                        }
                    }
                    if( c->name == GTO_COMPONENT_SMOOTHING )
                    {
                        if( p->name == GTO_PROPERTY_METHOD )
                        {
                            polyObject.smoothingMethod() = *(p->int32Data);
                        }
                    }
                }

            }

            polyObject.declareHoudini( gdp );
        }
    }
    if( verbose ) std::cerr << "Done" << std::endl;

    if( verbose ) std::cerr << "Writing to stdout..." << std::flush;
    gdp.save( std::cout, ! ascii );
    if( verbose ) std::cerr << "Done" << std::endl;

    return 0;
}
ROP_RENDER_CODE
ROP_DopField::renderFrame(fpreal time, UT_Interrupt *)
{
    OP_Node		*op;
    DOP_Parent		*dopparent;
    UT_String		 doppath, savepath;
    UT_String		 dopobject, dopdata;

    if( !executePreFrameScript(time) )
	return ROP_ABORT_RENDER;

    DOPPATH(doppath, time);

    if( !doppath.isstring() )
    {
	addError(ROP_MESSAGE, "Invalid DOP path");
	return ROP_ABORT_RENDER;
    }

    op = findNode(doppath);
    if (!op)
    {
	addError(ROP_COOK_ERROR, (const char *)doppath);
	return ROP_ABORT_RENDER;
    }

    dopparent = op ? op->castToDOPParent() : 0;
    if( !dopparent )
    {
	addError(ROP_COOK_ERROR, (const char *)doppath);
	return ROP_ABORT_RENDER;
    }

    DOPOBJECT(dopobject, time);
    DOPDATA(dopdata, time);
    OUTPUT(savepath, time);


    time = DOPsetBestTime(dopparent, time);

    OP_Context		context(time);

    const SIM_Object		*object;
    object = dopparent->findObjectFromString(dopobject, 0, 0, time);

    if (!object)
    {
	addError(ROP_COOK_ERROR, (const char *)dopobject);
	return ROP_ABORT_RENDER;
    }

    const SIM_Data		*data;

    data = object->getConstNamedSubData(dopdata);

    if (!data)
    {
	addError(ROP_COOK_ERROR, (const char *) dopdata);
	return ROP_ABORT_RENDER;
    }

    // Create our GDP.
    GU_Detail			*gdp = new GU_Detail();

    const SIM_ScalarField	*scalarfield = SIM_DATA_CASTCONST(data, SIM_ScalarField);
    if (scalarfield)
    {
	addField(gdp, scalarfield->getField());
    }
    const SIM_VectorField	*vectorfield = SIM_DATA_CASTCONST(data, SIM_VectorField);
    if (vectorfield)
    {
	for (int i = 0; i < 3; i++)
	{
	    addField(gdp, vectorfield->getField(i));
	}
    }
    const SIM_MatrixField	*matrixfield = SIM_DATA_CASTCONST(data, SIM_MatrixField);
    if (matrixfield)
    {
	for (int i = 0; i < 3; i++)
	    for (int j = 0; j < 3; j++)
	    {
		addField(gdp, matrixfield->getField(i, j));
	    }
    }

    if (!gdp->save((const char *)savepath, 0, 0).success())
    {
	addError(ROP_SAVE_ERROR, (const char *)savepath);
	return ROP_ABORT_RENDER;
    }

    // DO NOT delete gdp if we are stealing the voxels!
    // delete gdp;

    if (ALFPROGRESS() && (myEndTime != myStartTime))
    {
	fpreal		fpercent = (time - myStartTime) / (myEndTime - myStartTime);
	int		percent = (int)SYSrint(fpercent * 100);
	percent = SYSclamp(percent, 0, 100);
	fprintf(stdout, "ALF_PROGRESS %d%%\n", percent);
	fflush(stdout);
    }
    
    if (error() < UT_ERROR_ABORT)
    {
	if( !executePostFrameScript(time) )
	    return ROP_ABORT_RENDER;
    }

    return ROP_CONTINUE_RENDER;
}
Beispiel #4
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);
        }
};