Пример #1
0
def test_closestPointsOnMesh():
    mesh = pgf.scale(loadSmallBunny(), pgf.var_float(10.))

    inpts = pgf.var_vec3([
        (0.359824538230896, -0.012389957904815674, 0.3581507205963135),
        (-0.3318827152252197, 0.1699751615524292, 0.7063822150230408),
        (0.27124643325805664, -0.14796850085258484, 0.5440048575401306),
        (0.2950490713119507, 0.0309564471244812, 1.5690069198608398),
        (0.470700740814209, 0.559279203414917, 0.5738930106163025),
        (-0.6372849941253662, 0.5158957242965698, 0.9492948055267334),
        (-0.42367517948150635, 0.17821109294891357, 0.5325688719749451),
        (0.24817490577697754, 0.27643465995788574, 0.5003229975700378),
        (-0.5128110647201538, -0.4166657030582428, 1.868307113647461),
        (-0.08426868915557861, 0.14360648393630981, 0.6685295104980469)
    ])

    outpts = pgf.closestPoints(mesh, inpts)

    expected = [
        (0.35241958498954773, -0.022721359506249428, 0.3823484480381012),
        (-0.3473210334777832, 0.18098655343055725, 0.6997533440589905),
        (0.22252899408340454, -0.13979701697826385, 0.36583301424980164),
        (0.1671879142522812, -0.029879290610551834, 1.274683952331543),
        (0.22475071251392365, 0.2590671181678772, 0.5857457518577576),
        (-0.5479510426521301, 0.21973726153373718, 0.9220386743545532),
        (-0.423895001411438, 0.11360426992177963, 0.5336558818817139),
        (0.21963083744049072, 0.23689928650856018, 0.5136839151382446),
        (-0.6122115254402161, -0.3117043375968933, 1.5369797945022583),
        (-0.03959565982222557, 0.34772586822509766, 0.666935384273529)
    ]

    assert tu.equalf(expected, pgf.read(outpts))
Пример #2
0
def test_meshSphereQuery():
    mesh = pgf.scale(loadSmallBunny(), pgf.var_float(10.0))
    zero = pgf.var_float(0.)
    center = pgf.vec3(zero, zero, zero)
    radius = pgf.var_float(.5)
    sphere = pgf.sphere(center, radius)

    rmesh, rindices, rcount = pgf.meshSphereQuery(mesh, sphere)

    nfaces = pgf.read(rcount)
    area = pgf.read(pgf.area(rmesh))
    assert tu.equalf(area, 0.4436888098716736)
    assert nfaces == 292
Пример #3
0
def test_scaleMesh():
    mesh = loadLargeBunny()
    factor = 10.0
    scaled = pgf.scale(mesh, pgf.var_float(factor))
    meshes = [mesh, scaled]

    areas = [pgf.read(pgf.area(m)) for m in meshes]
    volumes = [pgf.read(pgf.volume(m)) for m in meshes]
    vcounts = [pgf.read(pgf.numVertices(m)) for m in meshes]
    fcounts = [pgf.read(pgf.numFaces(m)) for m in meshes]

    assert (abs(areas[1] - pow(factor, 2) * areas[0]) / areas[1]) < 1e-5
    assert (abs(volumes[1] - pow(factor, 3) * volumes[0]) / volumes[1]) < 1e-5
    assert vcounts[0] == vcounts[1]
    assert fcounts[0] == fcounts[1]
Пример #4
0
import pygalfunc as pgf
import pygalview as pgv

relpath = pgf.var_string("../assets/bunny.obj")
path = pgf.absPath(relpath)
mesh = pgf.loadObjFile(path)
scale = pgf.var_float(10.0)
scaled = pgf.scale(mesh, scale)

center = pgv.sliderVec3("center", 0., 1., 0.)
radius = pgv.sliderf32("radius", 0., 1., .5)
sphere = pgf.sphere(center, radius)
resultMesh, resultIndices, numResults = pgf.meshSphereQuery(scaled, sphere)

pgv.print("Number of results", numResults)
pgv.show("Queried faces", resultMesh)
pgv.show("Sphere", sphere)