Example #1
0
    def load_layer(self, layer):
        layer_node = NodePath(layer.get("name"))
        static_tiles = NodePath("static")  # Static tiles to flatten
        flat_animated_tiles = NodePath("animated")  # Animated tiles to flatten
        dynamic_tiles = NodePath(
            "dynamic")  # All tiles unless otherwise specified (don't flatten)
        tile_groups = {}
        # should we flatten this layer
        store_data = flatten = False
        properties = layer.find("properties")
        if properties:
            for property in properties:
                if property.get("name") == "flatten":
                    flatten = True
                if property.get("name") == "store_data":
                    store_data = True
        # build all tiles in data as a grid of cards
        data = layer.find("data").text
        data = data.replace('\n', '')
        data = data.split(",")
        collumns = int(layer.get("width"))
        rows = int(layer.get("height"))
        self.size = [collumns, rows]
        for y in range(rows):
            for x in range(collumns):
                id = int(data[(y * collumns) + (x % collumns)])
                data[(y * collumns) + (x % collumns)] = id
                if id > 0:
                    tile = NodePath("tile")
                    self.get_tile(id).copy_to(tile)
                    if flatten:
                        if tile.find("**/+SequenceNode"):
                            tile.reparent_to(flat_animated_tiles)
                        else:
                            tile.reparent_to(static_tiles)
                    else:
                        tile.reparent_to(layer_node)
                    tile.set_pos(x, -y, 0)

        if flatten:
            if static_tiles.get_num_children() > 0:
                clear_all_tags(static_tiles)
                static_tiles.flatten_strong()
            if flat_animated_tiles.get_num_children() > 0:
                clear_all_tags(flat_animated_tiles)
                flat_animated_tiles = self.flatten_animated_tiles(
                    flat_animated_tiles)
            for t in (static_tiles, flat_animated_tiles):
                t.reparent_to(layer_node)

        if store_data:
            layer_node.set_python_tag("data", data)
        self.append_layer(layer_node, properties)
Example #2
0
def make_station(name, size=5):
    if size == 0: size = 0.1
    maker = base.shapes
    root = NodePath(str(name))
    root.set_scale(0.02)
    model = root.attach_new_node("station model")

    torus_color = random_color()
    sphere_color = random_color()
    cap_color = random_color()
    # Make poker
    w = uniform(0.01*size, 0.05*size)
    shape = choice(("Cylinder", "Cone"))
    maker.new(
        shape,random_color(), parent=model,
        pos=(0,0,0), hpr=(0,0,0), scale=(w,w,size)
    )
    # Add kebab
    rings = int(size+1)#int(randint(1,4))
    distance = size/rings  
    for i in range(rings):
        z = (distance*(i+1))+ distance
        w = uniform(min(0.2,0.05*size),0.5*size)
        shape = choice(("Torus", "Torus", "Sphere"))
        h = uniform(0.5,2)
        # Spheres should be flattened and not so wide.
        color = torus_color
        if shape == "Sphere": 
            h/=randint(2,5)
            w/=2
            color = sphere_color
        maker.new(
            shape, color, parent=model,
            pos=(0,0,z), hpr=(0,0,0), scale=(w,w,h)
        )
    # Add top and bottom cap
    def cap(z,p):
        shape = choice(("Cone", "Sphere"))
        w = uniform(0.1*size,0.3*size)
        l = uniform(0.1,1)
        maker.new(
            shape, cap_color, parent=model,
            pos=(0,0,z), hpr=(0,p,0), scale=(w,w,l)
        )
    if not randint(0,2):
        cap(size*2,0)
    if not randint(0,2):
        cap(0,180)
 
    model.set_pos(0,0,-size/2)    
    root.flatten_strong()        
    return root
Example #3
0
class Chunk():  # A chunk of the map to add tiles to.
    def __init__(self):
        self.node = NodePath("chunk")
        self.cells = defaultdict(list)
        self.geometry = None

    def make_tile(self, pos, tile):
        if self.geometry:
            to_make = self.geometry[tile[0]]
            tile_node = NodePath(to_make.name)
            to_make.copy_to(tile_node)
            tile_node.set_pos(Vec3(pos) + tuple(tile[1]))
            tile_node.set_hpr(tuple(tile[2]))
            tile_node.reparent_to(self.node)

    def flatten(self):
        if self.node:
            if self.node.get_num_children() > 0:
                self.node.flatten_strong()

    def add_tile(self, pos, tile):
        cell = self.cells[pos]
        if not tile in cell:
            cell.append(tile)
            self.make_tile(pos, tile)
            self.flatten()

    def remove_tile(self, pos, tile):
        cell = self.cells[pos]
        if tile in cell:
            cell.remove(tile)
            self.rebuild()

    def remove_cell(self, pos):
        for tile in self.cells[pos]:
            self.cells[pos].remove(tile)
        self.rebuild()

    def destroy(self):
        self.node.remove_node()
        self.node = None

    def rebuild(self):
        self.destroy()
        self.node = NodePath("chunk")
        for cell in self.cells:
            for tile in self.cells[cell]:
                self.make_tile(cell, tile)
        self.flatten()
Example #4
0
def make_ship(name):
    maker = base.shapes
    root = NodePath(str(name))
    root.set_scale(0.007)
    model = root.attach_new_node("station model")
    maker.new(
        "Cone", random_color(), parent=model,
        pos=(0,0,0), hpr=(0,0,0), scale=(0.2,0.2,1)
    )
    maker.new(
        "Cone", random_color(), parent=model,
        pos=(0,0,0.3), hpr=(0,0,0), scale=(0.2,1,0.5)
    )
    root.flatten_strong()
    return root
Example #5
0
def test_nodepath_flatten_tags_same_value():
    from panda3d.core import NodePath, PandaNode

    # Don't flatten nodes with different tag values
    node1 = PandaNode("node1")
    node1.set_tag("key", "value1")
    node2 = PandaNode("node2")
    node2.set_tag("key", "value2")

    path = NodePath("parent")
    path.node().add_child(node1)
    path.node().add_child(node2)

    path.flatten_strong()
    assert len(path.children) == 2
Example #6
0
def test_nodepath_flatten_tags_identical():
    from panda3d.core import NodePath, PandaNode

    # Do flatten nodes with same tags
    node1 = PandaNode("node1")
    node1.set_tag("key", "value")
    node2 = PandaNode("node2")
    node2.set_tag("key", "value")

    path = NodePath("parent")
    path.node().add_child(node1)
    path.node().add_child(node2)

    path.flatten_strong()
    assert len(path.children) == 1
def replace_tree(tree_def=BoringTree, seed=None):
    if seed is None:
        seed = random.random()

    global tree_root
    tree_root.remove_node()
    tree_root = NodePath('autotree')
    tree_root.reparent_to(base.render)

    rng = random.Random(seed)

    style = Skeleton
    # style = Bark

    treeify(tree_root, tree_def, rng, style)
    tree_root.flatten_strong()
Example #8
0
def make_character(name):
    maker = base.shapes
    root = NodePath(str(name))
    root.set_scale(0.0005)
    model = root.attach_new_node("station model")

    maker.new(
        "Cone", random_color(), parent=model,
        pos=(0,0,0), hpr=(0,180,0), scale=(0.2,1,1)
    )
    maker.new(
        "Sphere", random_color(), parent=model,
        pos=(0,0,1), hpr=(0,0,0), scale=(1,1,1)
    )
    root.flatten_strong()
    return root
Example #9
0
from Native.RSNative import MeshSplitterWriter
from panda3d.core import Loader, NodePath

# TODO: Make input- and output-file command line parameters, something like:
# convert.py -o output.rpsg input.bam 


INPUT_FILE = "Scene.bam"
OUTPUT_FILE = "model.rpsg"


loader = Loader.get_global_ptr()
model = NodePath(loader.load_sync(INPUT_FILE))

# Flatten the transform of the model, since we don't store the transform
model.flatten_strong()

print("Loaded model ...")
writer = MeshSplitterWriter()

# Collect all geoms of the model and register them to the writer
geom_nodes = model.find_all_matches("**/+GeomNode")
for geom_node in geom_nodes:
    geom_node = geom_node.node()
    for geom_idx in range(geom_node.get_num_geoms()):
        geom = geom_node.get_geom(geom_idx)
        geom_state = geom_node.get_geom_state(geom_idx)
        writer.add_geom(geom)

# Write the result file
print("Processing ....")