示例#1
0
NaiadFoamBox::NaiadFoamBox(const Transform *o2w, const Transform *w2o,
                           bool ro, Reference<NaiadFoam> par, const Nb::ParticleShape & particle, int blockID)
    : Shape(o2w, w2o, ro), parent(par) {
    //Get the blocks of particles
    const Nb::BlockArray3f& blocksPos = particle.constBlocks3f("position");

    const Nb::Block3f& blockPos = blocksPos(blockID);

    density = blockPos.size();

    bb = BBox(Point(blockPos.min().v[0],
                    blockPos.min().v[1],
                    blockPos.min().v[2]),
              Point(blockPos.max().v[0],
                    blockPos.max().v[1],
                    blockPos.max().v[2]));
    //for (int pIdx = 0; pIdx < 1; ++pIdx) {
    for (int pIdx = 0; pIdx < blockPos.size(); pIdx += 20) {
        Point pos(blockPos.data()[pIdx].v[0],
                  blockPos.data()[pIdx].v[1],
                  blockPos.data()[pIdx].v[2]);

        float r = 0.03f;

        particles.push_back(NaiadFoamParticle(pos,r, this));

#ifdef VDB
        vdb_sample(0.01);
        vdb_color(1.0f, 1.0f, 1.0f);
        vdb_point(pos.x, pos.y, pos.z);
#endif
    }
}
示例#2
0
文件: vdb.cpp 项目: mit-gfx/vdb
VDB_CALL int vdb_init() {
	if(!__vdb.is_initialized) {
		__vdb.is_initialized = 1;
		__vdb.sample_enabled = 1;
		vdb_os_init();
		__vdb.fd = socket(AF_INET, SOCK_STREAM, 0);
		if(__vdb.fd == -1) {
			vdb_report_error();
			__vdb.init_error = 1;
		} else {
			struct sockaddr_in serv_name;
			serv_name.sin_family = AF_INET;
			serv_name.sin_addr.s_addr = htonl(0x7F000001L);
			serv_name.sin_port = htons(10000);
			if(-1 == connect(__vdb.fd, (struct sockaddr*) &serv_name, sizeof(serv_name))) {
				vdb_report_error();
				__vdb.init_error = 1;
			}
			atexit(vdb_exit);
		}
	}
	if(__vdb.is_initialized == 2) { 
		//this never runs, but it tricks compilers into including these functions as debug symbols 
		//even though they may never be used
		//useful if you want to call them from the debugger directly
		vdb_point_v(NULL);
		vdb_line_v(NULL);
		vdb_normal_v(NULL);
		vdb_triangle_v(NULL);
		vdb_point(0,0,0);
		vdb_line(0,0,0,0,0,0);
		vdb_normal(0,0,0,0,0,0);
		vdb_triangle(0,0,0,0,0,0,0,0,0);
		vdb_color_v(NULL);
		vdb_color(0,0,0);
		vdb_label("");
		vdb_label(0);
	}
	return __vdb.init_error;
}
示例#3
0
文件: vdb.cpp 项目: mit-gfx/vdb
VDB_CALL int vdb_point_fn(float x, float y, float z) {
	return vdb_point(x,y,z);
}
示例#4
0
// NaiadMesh Method Definitions
NaiadMesh::NaiadMesh(const Transform *o2w, const Transform *w2o,
        bool ro, const ParamSet &params)
    : Shape(o2w, w2o, ro) {
    Nb::begin();

    const char * empStr = params.FindOneString("emp","error").c_str();
    const char * bodyStr = params.FindOneString("body","error").c_str();
    Nb::EmpReader empReader(empStr,"*");
    const Nb::Body * body = empReader.ejectBody(bodyStr);

    //Load shapes from Naiad body
    const Nb::TriangleShape& triangle = body->constTriangleShape();
    const Nb::PointShape& point = body->constPointShape();

    //Get buffers
    const Nb::Buffer3f& posBuf(point.constBuffer3f("position"));
    const Nb::Buffer3i& triIdxBuf(triangle.constBuffer3i("index"));

    ntris = triIdxBuf.size();
    nverts = posBuf.size();

    std::cout << "NaiadMesh:: Found " << nverts << " vertices." << std::endl;
    std::cout << "NaiadMesh:: Found " << ntris << " triangles." << std::endl;

    vertexIndex = new int[3 * ntris];
    for (int i = 0; i < ntris; ++i) {
        vertexIndex[3*i    ] = triIdxBuf[i].v[0];
        vertexIndex[3*i + 1] = triIdxBuf[i].v[1];
        vertexIndex[3*i + 2] = triIdxBuf[i].v[2];
    }
    //memcpy(vertexIndex, &triIdxBuf[0], 3 * ntris * sizeof(int));

    float dispSurface = params.FindOneFloat("disp_surface",0.f);

    p = new Point[nverts];
    for (int i = 0; i < nverts; ++i) {
        Point P(posBuf[i].v[0], posBuf[i].v[1], posBuf[i].v[2]);
        if (dispSurface) {
            const Nb::Buffer3f& normalBuf(point.constBuffer3f("normal"));
            P.x += normalBuf[i].v[0] * dispSurface;
            P.y += normalBuf[i].v[1] * dispSurface;
            P.z += normalBuf[i].v[2] * dispSurface;
        }
        p[i] = (*ObjectToWorld)(P);

#ifdef VDB
        if (ntris > 50000) {
            vdb_sample(0.1);
            vdb_color(0.5f, 0.8f, 1.0f);
        } else {
            vdb_sample(1.0);
            vdb_color(0.5f, 0.5f, 0.5f);
        }

        vdb_point(p[i].x,p[i].y,p[i].z);
#endif
    }

    string uv_empStr = params.FindOneString("uv_emp","error");
    if (uv_empStr != string("error")) {
        Nb::EmpReader empReaderUV(uv_empStr.c_str(),"*");
        string uv_bodyStr = params.FindOneString("uv_body","error");
        const Nb::Body * bodyUV = empReaderUV.ejectBody(uv_bodyStr.c_str());

        const Nb::TriangleShape& tUV = bodyUV->constTriangleShape();
        const Nb::Buffer3i& uvIdx(tUV.constBuffer3i("index"));
        const Nb::Buffer3f& bufU(tUV.constBuffer3f("u"));
        const Nb::Buffer3f& bufV(tUV.constBuffer3f("v"));
        uvs = new float[2*nverts];
        for (int i = 0; i < uvIdx.size(); ++i) {
            int v0 = triIdxBuf[i].v[0];
            int v1 = triIdxBuf[i].v[1];
            int v2 = triIdxBuf[i].v[2];
            uvs[2*v0]     = bufU[i].v[0];
            uvs[2*v0 + 1] = bufV[i].v[0];
            uvs[2*v1]     = bufU[i].v[1];
            uvs[2*v1 + 1] = bufV[i].v[1];
            uvs[2*v2]     = bufU[i].v[2];
            uvs[2*v2 + 1] = bufV[i].v[2];
        }
    } else uvs = NULL;

    //No need for these parameters yet.
    //uvs = NULL;
    n = NULL;
    s = NULL;

    //For foam zbuffer
    foam_block = params.FindOneFloat("foam_block", 0.f);

    Nb::end();
}