Example #1
0
    def place(x, y, z, lcval, crustval, bathyval, doSchematics, r=None, g=None, b=None, ir=None):
        try:
            Terrain.terdict[lcval]
        except KeyError:
            print "lcval value %s not found!" % lcval
        (y, column, tree) = Terrain.terdict.get(lcval, Terrain.terdict[0])(x, y, z, crustval, bathyval, doSchematics)
        merged = [ (depth, (block, 0)) if type(block) is not tuple else (depth, block) for (depth, block) in column ]
        # y=0 is always bedrock
        blocks = [ (0, materialNamed('Bedrock')) ]
        datas = [ (0, 0) ]
        core = [ ((y - height(merged)), ('End Stone', 0)) ] + merged
        base = 0
        while core:
            (depth, (block, data)) = core.pop(0)
            [ blocks.append((y, materialNamed(block) if type(block) is str else block)) for y in xrange(base, base+depth) if y > 0 ]
            [ datas.append((y, data)) for y in xrange(base, base+depth) if y > 0 ]
            base += depth

        water = materialNamed('Water')
        water = water(0) if type(water) is tuple else water 
        iswater = (block == 'Water') if type(block) is str else (block == water)
        if haveOrthoColors and not(iswater):
            [block, data] = mcBlockData.nearest(r, g, b, ir, not(lcval >= 22 and lcval <=25))
            blocks[-1] = (blocks[-1][0], block)
            datas[-1] = (datas[-1][0], data)

        return blocks, datas, tree
Example #2
0
    def geom_mat(self, tri, x, y, z, timg, ttex, majax, smjax, minax):

        if ttex == None or timg == None:
            return [1, 0]

            # Step 1: Grab all the points
        p1 = [x, y, z]
        p1[majax] -= 0.5
        p1[smjax] -= 0.5
        p1 = self.geom_cart2bary(tri, p1[0], p1[1], p1[2], minax)
        if p1[0] == 0 and p1[2] == 0 and p1[2] == 0:
            return [1, 0]

        p2 = [x, y, z]
        p2[majax] += 0.5
        p2[smjax] -= 0.5
        p2 = self.geom_cart2bary(tri, p2[0], p2[1], p2[2], minax)
        if p2[0] == 0 and p2[2] == 0 and p2[2] == 0:
            return [1, 0]

        p3 = [x, y, z]
        p3[majax] -= 0.5
        p3[smjax] += 0.5
        p3 = self.geom_cart2bary(tri, p3[0], p3[1], p3[2], minax)
        if p3[0] == 0 and p3[2] == 0 and p3[2] == 0:
            return [1, 0]

        p4 = [x, y, z]
        p4[majax] += 0.5
        p4[smjax] += 0.5
        p4 = self.geom_cart2bary(tri, p4[0], p4[1], p4[2], minax)
        if p4[0] == 0 and p4[2] == 0 and p4[2] == 0:
            return [1, 0]

            # Step 2: Map modified texture coordinates to pixel coords
        p1 = np.dot(p1[0:3], ttex)
        p2 = np.dot(p2[0:3], ttex)
        p3 = np.dot(p3[0:3], ttex)
        p4 = np.dot(p4[0:3], ttex)

        # Step 3: Scan/rasterize over all pixels
        c = 1 + abs(max(p2[0] - p1[0], p4[0] - p3[0]))
        d = 1 + abs(max(p3[1] - p1[1], p4[1] - p2[1]))

        # Cheap trimming. Appears to be ok.
        c = c if c < 7 else 7
        d = d if d < 7 else 7

        pxcount = 0
        pxsum = [0.0] * len(timg.uintarray[0, 0])

        for a in np.linspace(0, 1, d):
            for b in np.linspace(0, 1, c):
                cx = a * p3[0] + (1 - a) * p1[0] + a * (p4[0] - p3[0]) * b + (1 - a) * (p2[0] - p1[0]) * b
                cy = a * p3[1] + (1 - a) * p1[1] + a * (p4[1] - p3[1]) * b + (1 - a) * (p2[1] - p1[1]) * b
                # Step 3: Grab the pixel there
                pxc = array(
                    [
                        self.modulus(cx, timg.uintarray.shape[1]),
                        self.modulus((timg.uintarray.shape[0] - cy), timg.uintarray.shape[0]),
                    ]
                )
                if np.isnan(pxc[0]) or np.isnan(pxc[1]):
                    continue
                if pxc[1] >= timg.uintarray.shape[0] or pxc[0] >= timg.uintarray.shape[1]:
                    continue
                pixel = timg.uintarray[pxc[1], pxc[0]]
                pxcount += 1
                pxsum = pxsum + pixel

        data, damage = [1, 0]
        if pxcount > 0:
            self.pxscan += pxcount
            pixel = pxsum / float(pxcount)
            if len(pixel) >= 4 and pixel[3] < 127:
                if pixel[3] < 1:
                    data, damage = [0, 0]  # air
                else:
                    data, damage = [20, 0]  # glass
            else:
                data, damage = mcBlockData.nearest(int(pixel[0]), int(pixel[1]), int(pixel[2]))
        return [data, damage]
Example #3
0
    def geom_mat(self, tri, x, y, z, timg, ttex, majax, smjax, minax):

        if ttex == None or timg == None:
            return [1, 0]

        # Step 1: Grab all the points
        p1 = [x, y, z]
        p1[majax] -= 0.5
        p1[smjax] -= 0.5
        p1 = self.geom_cart2bary(tri, p1[0], p1[1], p1[2], minax)
        if p1[0] == 0 and p1[2] == 0 and p1[2] == 0:
            return [1, 0]

        p2 = [x, y, z]
        p2[majax] += 0.5
        p2[smjax] -= 0.5
        p2 = self.geom_cart2bary(tri, p2[0], p2[1], p2[2], minax)
        if p2[0] == 0 and p2[2] == 0 and p2[2] == 0:
            return [1, 0]

        p3 = [x, y, z]
        p3[majax] -= 0.5
        p3[smjax] += 0.5
        p3 = self.geom_cart2bary(tri, p3[0], p3[1], p3[2], minax)
        if p3[0] == 0 and p3[2] == 0 and p3[2] == 0:
            return [1, 0]

        p4 = [x, y, z]
        p4[majax] += 0.5
        p4[smjax] += 0.5
        p4 = self.geom_cart2bary(tri, p4[0], p4[1], p4[2], minax)
        if p4[0] == 0 and p4[2] == 0 and p4[2] == 0:
            return [1, 0]

        # Step 2: Map modified texture coordinates to pixel coords
        p1 = np.dot(p1[0:3], ttex)
        p2 = np.dot(p2[0:3], ttex)
        p3 = np.dot(p3[0:3], ttex)
        p4 = np.dot(p4[0:3], ttex)

        # Step 3: Scan/rasterize over all pixels
        c = 1 + abs(max(p2[0] - p1[0], p4[0] - p3[0]))
        d = 1 + abs(max(p3[1] - p1[1], p4[1] - p2[1]))

        # Cheap trimming. Appears to be ok.
        c = c if c < 7 else 7
        d = d if d < 7 else 7

        pxcount = 0
        pxsum = [0.] * len(timg.uintarray[0, 0])

        for a in np.linspace(0, 1, d):
            for b in np.linspace(0, 1, c):
                cx = a * p3[0] + (1 - a) * p1[0] + a * (p4[0] - p3[0]) * b + (
                    1 - a) * (p2[0] - p1[0]) * b
                cy = a * p3[1] + (1 - a) * p1[1] + a * (p4[1] - p3[1]) * b + (
                    1 - a) * (p2[1] - p1[1]) * b
                # Step 3: Grab the pixel there
                pxc = array([self.modulus(cx,timg.uintarray.shape[1]), \
                           self.modulus((timg.uintarray.shape[0] - cy),timg.uintarray.shape[0])])
                if np.isnan(pxc[0]) or np.isnan(pxc[1]):
                    continue
                if pxc[1] >= timg.uintarray.shape[0] or pxc[
                        0] >= timg.uintarray.shape[1]:
                    continue
                pixel = timg.uintarray[pxc[1], pxc[0]]
                pxcount += 1
                pxsum = pxsum + pixel

        data, damage = [1, 0]
        if pxcount > 0:
            self.pxscan += pxcount
            pixel = pxsum / float(pxcount)
            if len(pixel) >= 4 and pixel[3] < 127:
                if pixel[3] < 1:
                    data, damage = [0, 0]  # air
                else:
                    data, damage = [20, 0]  # glass
            else:
                data, damage = mcBlockData.nearest(int(pixel[0]),
                                                   int(pixel[1]),
                                                   int(pixel[2]))
        return [data, damage]