コード例 #1
0
def test_meshStatistics():
    mesh = loadLargeBunny()
    area = pgf.read(pgf.area(mesh))
    volume = pgf.read(pgf.volume(mesh))
    nfaces = pgf.read(pgf.numFaces(mesh))
    nverts = pgf.read(pgf.numVertices(mesh))
    assert tu.equalf(area, 23.27821922302246)
    assert tu.equalf(volume, 6.039211750030518)
    assert nfaces == 69630
    assert nverts == 34817
コード例 #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_meshPlaneClipping():
    mesh = loadLargeBunny()
    half = pgf.var_float(0.5)
    plane = pgf.plane(pgf.vec3(half, half, half), pgf.vec3(half, half, half))
    clipped = pgf.clipMesh(mesh, plane)

    area = pgf.read(pgf.area(clipped))
    nfaces = pgf.read(pgf.numFaces(clipped))
    nverts = pgf.read(pgf.numVertices(clipped))

    assert tu.equalf(area, 19.79486274)
    assert nfaces == 59387
    assert nverts == 30013
コード例 #4
0
def test_rectangleMesh():
    plane = pgf.plane(pgf.var_vec3((0., 0., 0.)), pgf.var_vec3((1., 1., 0.)))
    box = pgf.box2(pgf.var_vec2((0., 0.)), pgf.var_vec2((15., 12.)))
    edgeLn = pgf.var_float(1.)

    rect = pgf.rectangleMesh(plane, box, edgeLn)
    area = pgf.area(rect)
    nfaces = pgf.numFaces(rect)
    nverts = pgf.numVertices(rect)

    assert 360 == pgf.read(nfaces)
    assert 208 == pgf.read(nverts)
    assert tu.equalf(180., pgf.read(area))
コード例 #5
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]
コード例 #6
0
import pygalfunc as pgf
import pygalview as pgv

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

pt = pgv.sliderVec3("point", 0., 1., .5)
norm = pgv.sliderVec3("normal", 0., 1., .5)
plane = pgf.plane(pt, norm)
clipped = pgf.clipMesh(scaled, plane)

area = pgf.area(clipped)
centroid = pgf.centroid(clipped)

pgv.show("Plane", plane)
pgv.show("Clipped Mesh", clipped)
pgv.print("Original triangle count", pgf.numFaces(scaled))
pgv.print("Final triangle count", pgf.numFaces(clipped))
pgv.print("Mesh Area", area)
pgv.print("Mesh Centroid", centroid)