示例#1
0
    def make(self):
        self.body = CubeModel(*self.size)
        self.body.geom_node.setIntoCollideMask(BitMask32.bit(2))
        self.body.reparentTo(self)
        self.body.setTag('Tree', '{0}'.format(self.name))
        self.set_body_tex(self.body_tex)
        start_leaf = random.randint(2, 4)
        if start_leaf > self.size[2] - 1:
            start_leaf = self.size[2] - 1

        self.leafs = []
        i = 0
        for z in xrange(start_leaf, self.size[2] - 1):
            for ix in xrange(-1, 1):
                for iy in xrange(-1, 1):

                    size_x = random.randint(int((self.size[2] - z + 4) * 0.2),
                                            int((self.size[2] - z + 4) * 0.4))
                    size_y = random.randint(int((self.size[2] - z + 4) * 0.2),
                                            int((self.size[2] - z + 4) * 0.4))
                    if size_x == 0 or size_y == 0:
                        continue
                    self.leafs.append(CubeModel(size_x, size_y, 1))
                    x = size_x * ix
                    y = size_y * iy

                    self.leafs[i].setPos(x, y, z)
                    self.leafs[i].reparentTo(self)
                    i += 1

        self.set_leaf_tex(self.leaf_tex)
示例#2
0
class LowTreeModel(NodePath):
    """Cube-like tree
    """
    def __init__(self, name, size, body_tex=None, leaf_tex=None):
        NodePath.__init__(self, name)
        self.name = name
        self.size = size
        self.body_tex = body_tex
        self.leaf_tex = leaf_tex
        self.make()
        self.flattenStrong()

    def make(self):
        self.body = CubeModel(*self.size)
        self.body.geom_node.setIntoCollideMask(BitMask32.bit(2))
        self.body.reparentTo(self)
        self.body.setTag('Tree', '{0}'.format(self.name))
        self.set_body_tex(self.body_tex)
        start_leaf = random.randint(2, 4)
        if start_leaf > self.size[2] - 1:
            start_leaf = self.size[2] - 1

        self.leafs = []
        i = 0
        for z in xrange(start_leaf, self.size[2] - 1):
            for ix in xrange(-1, 1):
                for iy in xrange(-1, 1):

                    size_x = random.randint(int((self.size[2] - z + 4) * 0.2),
                                            int((self.size[2] - z + 4) * 0.4))
                    size_y = random.randint(int((self.size[2] - z + 4) * 0.2),
                                            int((self.size[2] - z + 4) * 0.4))
                    if size_x == 0 or size_y == 0:
                        continue
                    self.leafs.append(CubeModel(size_x, size_y, 1))
                    x = size_x * ix
                    y = size_y * iy

                    self.leafs[i].setPos(x, y, z)
                    self.leafs[i].reparentTo(self)
                    i += 1

        self.set_leaf_tex(self.leaf_tex)

    def set_body_tex(self, body_tex):
        if body_tex != None:
            self.body.setTexture(body_tex)

    def set_leaf_tex(self, leaf_tex):
        if leaf_tex != None:
            ts = TextureStage('ts')
            for leaf in self.leafs:
                leaf.setTexture(ts, leaf_tex)
                leaf.setTexScale(ts, 10, 10)
                leaf.setTransparency(TransparencyAttrib.MAlpha)