示例#1
0
def clipfacevecs(o, numo, cx, cy, size, rvecs):
    cx <<= 3
    cy <<= 3
    size <<= 3

    r = 0
    prev = o[numo - 1]
    for i in range(numo):
        cur = o[i]
        r += clipfacevec(prev, facevec(cur.x - prev.x, cur.y - prev.y), cx, cy,
                         size, rvecs[r])
        prev = cur

    corner = [
        facevec(cx, cy),
        facevec(cx + size, cy),
        facevec(cx + size, cy + size),
        facevec(cx, cy + size)
    ]
    for i in range(4):
        if insideface(corner[i], 1, o, numo):
            rvecs[r] = corner[i]
            r += 1

    assert (r <= 8)
    return r
示例#2
0
def occludesface(c, orient, o, size, vo, vsize, vmat, nmat, matmask, vf, numv):
    dim = dimension(orient)

    if c.children == 0:
        if nmat != empty_material_types.MAT_AIR and (c.material
                                                     & matmask) == nmat:
            nf = [facevec() for _ in range(8)]
            return clipfacevecs(vf, numv, o[C[dim]], o[R[dim]], size, nf) < 3

        if c.isentirelysolid():
            return True

        if vmat != empty_material_types.MAT_AIR and (
            (c.material & matmask) == vmat or
            (isliquid(vmat)
             and isclipped(c.material & material_types.MATF_VOLUME))):
            return True

        if touchingface(c, orient) and faceedges(c, orient) == F_SOLID:
            return True

        cf = [facevec() for _ in range(8)]
        numc = clipfacevecs(vf, numv, o[C[dim]], o[R[dim]], size, cf)

        if numc < 3:
            return True

        if c.isempty() or notouchingface(c, orient):
            return False

        of = [facevec() for _ in range(4)]

        numo = genfacevecs(c, orient, o, size, False, of)

        return numo >= 3 and insideface(cf, numc, of, numo)

    size >>= 1
    coord = dimcoord(orient)

    for i in range(8):
        if octacoord(dim, i) == coord:
            if occludesface(c.children[i], orient,
                            ivec(i, o.x, o.y, o.z, size), size, vo, vsize,
                            vmat, nmat, matmask, vf, numv) == 0:
                return False

    return True
示例#3
0
def occludesface(c, orient, o, size, vo, vsize, vmat, nmat, matmask, vf, numv):
    dim = dimension(orient)
    
    if c.children == 0:
        if nmat != empty_material_types.MAT_AIR and (c.material & matmask) == nmat:
            nf = [facevec() for _ in xrange(8)]
            return clipfacevecs(vf, numv, o[C[dim]], o[R[dim]], size, nf) < 3;
        
        if c.isentirelysolid():
            return True
        
        if vmat != empty_material_types.MAT_AIR and ((c.material & matmask) == vmat or (isliquid(vmat) and isclipped(c.material & material_types.MATF_VOLUME))):
            return True
        
        if touchingface(c, orient) and faceedges(c, orient) == F_SOLID:
            return True
        
        cf = [facevec() for _ in xrange(8)]
        numc = clipfacevecs(vf, numv, o[C[dim]], o[R[dim]], size, cf)
        
        if numc < 3:
            return True
        
        if c.isempty() or notouchingface(c, orient):
            return False
        
        of = [facevec() for _ in xrange(4)]
        
        numo = genfacevecs(c, orient, o, size, False, of)
        
        return numo >= 3 and insideface(cf, numc, of, numo)

    size >>= 1
    coord = dimcoord(orient)
    
    for i in xrange(8):
        if octacoord(dim, i) == coord:
            if occludesface(c.children[i], orient, ivec(i, o.x, o.y, o.z, size), size, vo, vsize, vmat, nmat, matmask, vf, numv) == 0:
                return False;

    return True;
示例#4
0
def insideface(p, nump, o, numo):
    bounds = 0

    prev = o[numo - 1]

    for i in range(numo):

        cur = o[i]
        d = facevec(cur.x - prev.x, cur.y - prev.y)

        offset = d.x * prev.y - d.y * prev.x

        for j in range(nump):
            if d.x * p[j].y - d.y * p[j].x > offset:
                return False

        bounds += 1
        prev = cur

    return bounds >= 3
示例#5
0
def insideface(p, nump, o, numo):
    bounds = 0
    
    prev = o[numo-1]
    
    for i in xrange(numo):
    
        cur = o[i]
        d = facevec(cur.x-prev.x, cur.y-prev.y)
        
        offset = d.x*prev.y - d.y*prev.x
        
        for j in xrange(nump):
            if d.x*p[j].y - d.y*p[j].x > offset:
                return False;
           
        bounds += 1
        prev = cur
    
    return bounds >= 3
示例#6
0
def genfacevecs(cu, orient, pos, size, solid, fvecs, v=None):
    i = 0
    if solid:
        if orient == 0:
            if dimcoord(0):
                f = fvecs[i]
                f.y = ((pos.y + size) << 3)
                f.x = ((pos.z + size) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.y + size) << 3)
                f.x = ((pos.z) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.y) << 3)
                f.x = ((pos.z) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.y) << 3)
                f.x = ((pos.z + size) << 3)
                i += 1
            else:
                f = fvecs[i]
                f.y = ((pos.y) << 3)
                f.x = ((pos.z + size) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.y) << 3)
                f.x = ((pos.z) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.y + size) << 3)
                f.x = ((pos.z) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.y + size) << 3)
                f.x = ((pos.z + size) << 3)
                i += 1
        elif orient == 1:
            if dimcoord(1):
                f = fvecs[i]
                f.y = ((pos.y + size) << 3)
                f.x = ((pos.z + size) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.y) << 3)
                f.x = ((pos.z + size) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.y) << 3)
                f.x = ((pos.z) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.y + size) << 3)
                f.x = ((pos.z) << 3)
                i += 1
            else:
                f = fvecs[i]
                f.y = ((pos.y + size) << 3)
                f.x = ((pos.z) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.y) << 3)
                f.x = ((pos.z) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.y) << 3)
                f.x = ((pos.z + size) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.y + size) << 3)
                f.x = ((pos.z + size) << 3)
                i += 1
        elif orient == 2:
            if dimcoord(2):
                f = fvecs[i]
                f.x = ((pos.x + size) << 3)
                f.y = ((pos.z + size) << 3)
                i += 1

                f = fvecs[i]
                f.x = ((pos.x) << 3)
                f.y = ((pos.z + size) << 3)
                i += 1

                f = fvecs[i]
                f.x = ((pos.x) << 3)
                f.y = ((pos.z) << 3)
                i += 1

                f = fvecs[i]
                f.x = ((pos.x + size) << 3)
                f.y = ((pos.z) << 3)
                i += 1
            else:
                f = fvecs[i]
                f.x = ((pos.x + size) << 3)
                f.y = ((pos.z) << 3)
                i += 1

                f = fvecs[i]
                f.x = ((pos.x) << 3)
                f.y = ((pos.z) << 3)
                i += 1

                f = fvecs[i]
                f.x = ((pos.x) << 3)
                f.y = ((pos.z + size) << 3)
                i += 1

                f = fvecs[i]
                f.x = ((pos.x + size) << 3)
                f.y = ((pos.z + size) << 3)
                i += 1
        elif orient == 3:
            if dimcoord(3):
                f = fvecs[i]
                f.x = ((pos.x) << 3)
                f.y = ((pos.z) << 3)
                i += 1

                f = fvecs[i]
                f.x = ((pos.x) << 3)
                f.y = ((pos.z + size) << 3)
                i += 1

                f = fvecs[i]
                f.x = ((pos.x + size) << 3)
                f.y = ((pos.z + size) << 3)
                i += 1

                f = fvecs[i]
                f.x = ((pos.x + size) << 3)
                f.y = ((pos.z) << 3)
                i += 1
            else:
                f = fvecs[i]
                f.x = ((pos.x + size) << 3)
                f.y = ((pos.z) << 3)
                i += 1

                f = fvecs[i]
                f.x = ((pos.x + size) << 3)
                f.y = ((pos.z + size) << 3)
                i += 1

                f = fvecs[i]
                f.x = ((pos.x) << 3)
                f.y = ((pos.z + size) << 3)
                i += 1

                f = fvecs[i]
                f.x = ((pos.x) << 3)
                f.y = ((pos.z) << 3)
                i += 1
        elif orient == 4:
            if dimcoord(4):
                f = fvecs[i]
                f.y = ((pos.x) << 3)
                f.x = ((pos.y) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.x) << 3)
                f.x = ((pos.y + size) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.x + size) << 3)
                f.x = ((pos.y + size) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.x + size) << 3)
                f.x = ((pos.y) << 3)
                i += 1
            else:
                f = fvecs[i]
                f.y = ((pos.x + size) << 3)
                f.x = ((pos.y) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.x + size) << 3)
                f.x = ((pos.y + size) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.x) << 3)
                f.x = ((pos.y + size) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.x) << 3)
                f.x = ((pos.y) << 3)
                i += 1
        elif orient == 5:
            if dimcoord(5):
                f = fvecs[i]
                f.y = ((pos.x) << 3)
                f.x = ((pos.y) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.x + size) << 3)
                f.x = ((pos.y) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.x + size) << 3)
                f.x = ((pos.y + size) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.x) << 3)
                f.x = ((pos.y + size) << 3)
                i += 1
            else:
                f = fvecs[i]
                f.y = ((pos.x) << 3)
                f.x = ((pos.y + size) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.x + size) << 3)
                f.x = ((pos.y + size) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.x + size) << 3)
                f.x = ((pos.y) << 3)
                i += 1

                f = fvecs[i]
                f.y = ((pos.x) << 3)
                f.x = ((pos.y) << 3)
                i += 1
        return 4
    buf = [ivec() for _ in range(4)]

    if v is None:
        genfaceverts(cu, orient, buf)
        v = buf

    prev = facevec(INT_MAX, INT_MAX)
    if orient == 0:
        if dimcoord(0):
            e = v[0]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(0) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[1]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(0) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[2]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(0) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[3]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(0) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1
        else:
            e = v[3]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(0) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[2]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(0) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[1]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(0) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[0]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(0) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1
    elif orient == 1:
        if dimcoord(1):
            e = v[0]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(1) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[1]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(1) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[2]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(1) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[3]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(1) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1
        else:
            e = v[3]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(1) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[2]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(1) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[1]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(1) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[0]
            ef = ivec()
            ef.z = e.x
            ef.y = e.y
            ef.x = e.z
            if ef.z == dimcoord(1) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.z = pos.x
                pf.y = pos.y
                pf.x = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1
    elif orient == 2:
        if dimcoord(2):
            e = v[0]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(2) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[1]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(2) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[2]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(2) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[3]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(2) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1
        else:
            e = v[3]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(2) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[2]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(2) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[1]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(2) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[0]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(2) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1
    elif orient == 3:
        if dimcoord(3):
            e = v[0]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(3) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[1]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(3) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[2]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(3) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[3]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(3) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1
        else:
            e = v[3]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(3) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[2]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(3) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[1]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(3) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[0]
            ef = ivec()
            ef.x = e.x
            ef.z = e.y
            ef.y = e.z
            if ef.z == dimcoord(3) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.x = pos.x
                pf.z = pos.y
                pf.y = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1
    elif orient == 4:
        if dimcoord(4):
            e = v[0]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(4) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[1]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(4) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[2]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(4) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[3]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(4) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1
        else:
            e = v[3]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(4) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[2]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(4) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[1]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(4) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[0]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(4) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1
    elif orient == 5:
        if dimcoord(5):
            e = v[0]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(5) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[1]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(5) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[2]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(5) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[3]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(5) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1
        else:
            e = v[3]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(5) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[2]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(5) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[1]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(5) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1

            e = v[0]
            ef = ivec()
            ef.y = e.x
            ef.x = e.y
            ef.z = e.z
            if ef.z == dimcoord(5) * 8:
                f = fvecs[i]
                pf = ivec()
                pf.y = pos.x
                pf.x = pos.y
                pf.z = pos.z
                f = facevec(ef.x * size + (pf.x << 3),
                            ef.y * size + (pf.y << 3))
                if f != prev:
                    prev = f
                    i += 1
    if fvecs[0] == prev: i -= 1
    return i
示例#7
0
def visibletris(c, cube_map, orient, x, y, z, size, nmat, matmask):

    vis = 3
    touching = 0xF

    e1, e2, e3, n = [ivec() for _ in range(4)]

    v = [None] * 4
    genfaceverts(c, orient, v)

    e1 = v[1]
    e2 = v[2]
    e3 = v[0]

    n.cross((e1).sub(v[0]), (e2).sub(v[0]))
    convex = (e3).sub(v[3]).dot(n)
    if convex == 0:

        if ivec().cross(e3, e2).iszero():
            if n.iszero():
                return 0
            vis = 1
            touching = 0xF & ~(1 << 3)

        elif n.iszero():
            vis = 2
            touching = 0xF & ~(1 << 1)

    dim = dimension(orient)
    coord = dimcoord(orient)

    if v[0][dim] != coord * 8: touching &= ~(1 << 0)
    if v[1][dim] != coord * 8: touching &= ~(1 << 1)
    if v[2][dim] != coord * 8: touching &= ~(1 << 2)
    if v[3][dim] != coord * 8: touching &= ~(1 << 3)

    # mask of triangles not touching
    notouchmasks = [
        # order 0: flat or convex
        # 0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15
        [3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 1, 3, 0],
        # order 1: concave
        [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 2, 0],
    ]
    order = 1 if convex < 0 else 0
    notouch = notouchmasks[order][touching]

    if (vis & notouch) == vis:
        return vis

    no = ivec()
    nsize = 0

    o = neighbourcube(c, cube_map, orient, x, y, z, size, no, nsize)

    if o is c:
        return 0

    if c.material & matmask == nmat:
        nmat = empty_material_types.MAT_AIR

    vo = ivec(x, y, z)

    vo.mask(0xFFF)
    no.mask(0xFFF)

    cf = [facevec() for _ in range(4)]
    of = [facevec() for _ in range(4)]

    opp = opposite(orient)
    numo = 0
    numc = 0

    if nsize > size or (nsize == size and o.children == 0):

        if o.isempty() or notouchingface(o, opp):
            return vis

        if nmat != empty_material_types.MAT_AIR and (o.material
                                                     & matmask) == nmat:
            return vis

        if o.isentirelysolid() or (touchingface(o, opp)
                                   and faceedges(o, opp) == F_SOLID):
            return vis & notouch

        numc = genfacevecs(c, orient, vo, size, False, cf, v)
        numo = genfacevecs(o, opp, no, nsize, False, of)

        if numo < 3:
            return vis

        if insideface(cf, numc, of, numo):
            return vis & notouch

    else:
        numc = genfacevecs(c, orient, vo, size, False, cf, v)
        if occludesface(o, opp, no, nsize, vo, size,
                        empty_material_types.MAT_AIR, nmat, matmask, cf, numc):
            return vis & notouch

    if vis != 3 or notouch:
        return vis

    triverts = [
        # order
        [  # coord
            [[1, 2, 3], [0, 1, 3]],  # verts
            [[0, 1, 2], [0, 2, 3]]
        ],
        [  # coord
            [[0, 1, 2], [3, 0, 2]],  # verts
            [[1, 2, 3], [1, 3, 0]]
        ]
    ]

    while 1:
        for i in range(2):
            verts = triverts[order][coord][i]

            tf = [cf[verts[0]], cf[verts[1]], cf[verts[2]]]

            if numo > 0:
                if insideface(tf, 3, of, numo) == 0:
                    continue

            elif occludesface(o, opp, no, nsize, vo, size,
                              empty_material_types.MAT_AIR, nmat, matmask, tf,
                              3) == 0:
                continue

            return vis & ~(1 << i)

        vis |= 4

        order += 1
        if order <= 1: break

    return 3
示例#8
0
def visibletris(c, cube_map, orient, x, y, z, size, nmat, matmask):

    vis = 3
    touching = 0xF
    
    e1, e2, e3, n = [ivec() for _ in xrange(4)]
    
    
    v = [None]*4
    genfaceverts(c, orient, v)
    
    e1 = v[1]
    e2 = v[2]
    e3 = v[0]
    
    n.cross((e1).sub(v[0]), (e2).sub(v[0]))
    convex = (e3).sub(v[3]).dot(n)
    if convex == 0:
    
        if ivec().cross(e3, e2).iszero():
            if n.iszero():
                return 0
            vis = 1
            touching = 0xF & ~(1<<3)
            
        elif n.iszero():
            vis = 2
            touching = 0xF&~(1<<1)
    

    dim = dimension(orient)
    coord = dimcoord(orient)
    
    if v[0][dim] != coord*8: touching &= ~(1<<0)
    if v[1][dim] != coord*8: touching &= ~(1<<1)
    if v[2][dim] != coord*8: touching &= ~(1<<2)
    if v[3][dim] != coord*8: touching &= ~(1<<3)
    
    # mask of triangles not touching
    notouchmasks = [
      # order 0: flat or convex
       # 0  1  2  3  4  5  6  7  8  9  10 11 12 13 14 15
        [ 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 1, 3, 0 ],
      # order 1: concave
        [ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 2, 0 ],
    ]
    order = 1 if convex < 0 else 0
    notouch = notouchmasks[order][touching]
    
    if (vis&notouch)==vis:
        return vis

    no = ivec()
    nsize = 0
    
    o = neighbourcube(c, cube_map, orient, x, y, z, size, no, nsize)
    
    if o is c:
        return 0
    
    if c.material & matmask == nmat:
        nmat = empty_material_types.MAT_AIR

    vo = ivec(x, y, z)
    
    vo.mask(0xFFF)
    no.mask(0xFFF)
    
    cf = [facevec() for _ in xrange(4)]
    of = [facevec() for _ in xrange(4)]
    
    opp = opposite(orient)
    numo = 0
    numc = 0
    
    if nsize > size or (nsize == size and o.children == 0):
    
        if o.isempty() or notouchingface(o, opp):
            return vis
        
        if nmat != empty_material_types.MAT_AIR and (o.material & matmask) == nmat:
            return vis
       
        if o.isentirelysolid() or (touchingface(o, opp) and faceedges(o, opp) == F_SOLID):
            return vis & notouch

        numc = genfacevecs(c, orient, vo, size, False, cf, v)
        numo = genfacevecs(o, opp, no, nsize, False, of)
        
        if numo < 3:
            return vis
        
        if insideface(cf, numc, of, numo):
            return vis & notouch
    
    else:
        numc = genfacevecs(c, orient, vo, size, False, cf, v)
        if occludesface(o, opp, no, nsize, vo, size, empty_material_types.MAT_AIR, nmat, matmask, cf, numc):
            return vis & notouch
    
    if vis != 3 or notouch:
        return vis

    triverts = [
      # order
        [ # coord
            [ [ 1, 2, 3 ], [ 0, 1, 3 ] ], # verts
            [ [ 0, 1, 2 ], [ 0, 2, 3 ] ]
        ],
        [ # coord
            [ [ 0, 1, 2 ], [ 3, 0, 2 ] ], # verts
            [ [ 1, 2, 3 ], [ 1, 3, 0 ] ]
        ]
    ]

    while 1:
        for i in xrange(2):
            verts = triverts[order][coord][i]
            
            tf = [cf[verts[0]], cf[verts[1]], cf[verts[2]]]
            
            if numo > 0:
                if insideface(tf, 3, of, numo) == 0:
                    continue
                
            elif occludesface(o, opp, no, nsize, vo, size, empty_material_types.MAT_AIR, nmat, matmask, tf, 3) == 0:
                continue
            
            return vis & ~(1<<i)
        
        vis |= 4;
        
        order += 1
        if order <= 1: break

    return 3;