def add_arrows(self,
                raily,
                frompos,
                topos,
                maxn=10,
                d=5,
                spacing=60,
                bothsides=True):
     y = self.track.rails[0, raily].middlepos.y
     r, t = primitivemeshes.p_arrow(5, 20, 2, (255, 0, 0))
     r.move(V3(-d, y, 0))
     t.move(V3(-d, y, 0))
     r.rotate_around_center_z(90)
     t.rotate_around_center_z(90)
     r.rotate_around_center_y(90)
     t.rotate_around_center_y(90)
     #
     cpies = []
     cpies += self.track.add_thing(r, frompos, topos, 50, maxn)
     cpies += self.track.add_thing(t, frompos, topos, 50, maxn)
     if bothsides:
         r2, t2 = r.get_copy(), t.get_copy()
         r2.move(V3(2 * d + parameters.RAILW * self.track.nx, 0, 0))
         t2.move(V3(2 * d + parameters.RAILW * self.track.nx, 0, 0))
         cpies += self.track.add_thing(r2, frompos, topos, spacing, maxn)
         cpies += self.track.add_thing(t2, frompos, topos, spacing, maxn)
     return cpies
Beispiel #2
0
 def __init__(self, filename):
     self.filename = filename
     self.lines = get_stl_lines(filename)
     self.triangles = get_triangles(self.lines)
     self.from_center = V3()
     vset = self.get_vertices_set()
     self.vertices = {val: V3(val) for val in vset}
     self.compactize()
 def __init__(self, track, x, y):
     self.track = track
     self.x = x
     self.y = y
     self.obstacles = []
     self.pos = V3(x * track.railw, y * track.railh, 0)
     self.middlepos = self.pos + V3(self.track.railw // 2,
                                    self.track.railh // 2, 0)
Beispiel #4
0
def p_arrow(a, b, c, color=(0, 0, 0)):
    rect = p_rectangle(a, b, color)
    triangle = Path3D([V3(2 * c, b, 0),
                       V3(0, b + 3 * c, 0),
                       V3(-2 * c, b, 0)], True, Material(color))
    triangle.move(V3(0, -b / 2, 0))
    triangle.from_init = V3()
    triangle.filled = True
    return rect, triangle
Beispiel #5
0
def triangle(a, color=(0, 0, 0)):
    t1 = ManualObject3D([
        Triangle(a * V3(-1, 0, 0),
                 a * V3(1, 0, 0),
                 a * V3(0, 1, 0),
                 color=Material(color))
    ])
    t1.refresh_normals()
    return t1
Beispiel #6
0
def get_vertex(line):
    if "vertex" in line:
        line = line.split(" ")
        x, y, z = line[-3], line[-2], line[-1]
        return V3(float(x), float(y), float(z)), "v"
    elif "normal" in line:
        line = line.split(" ")
        x, y, z = line[-3], line[-2], line[-1]
        return V3(float(x), float(y), float(z)), "n"
    return False
Beispiel #7
0
def p_triangle(a, filled=True, color=(0, 0, 0)):
    ##    a = V3(a,0,0)
    ##    p1 = a.rotate_z(60)
    ##    p2 = p1.rotate_z(60)
    ##    p3 = p1.rotate_z(60)
    ##    p = Path3D([p1,p2,p3], True, color)
    ##    p.filled = filled
    ##    return p
    p = Path3D([V3(-a, 0, 0), V3(a, 0), V3(0, a, 0)], True, Material(color))
    p.filled = filled
    return p
 def other_vessel():
     self.vessels[0] = create_vessel(parameters.HERO_COLOR)
     self.vessels[0].set_pos(V3(0, -1 * 4.5, 20))
     self.vessels[0].move(V3(0, 4, 0))
     self.displayed_vessel = self.vessels[0]
     #replace self.ve
     new_ve = get_vessel_element(self.vessels[0])
     self.e_bckgr.replace_element(self.ve, new_ve)
     thorpy.functions.refresh_current_menu()
     self.ve = new_ve
     self.e_bckgr.unblit_and_reblit()
 def add_visual_rails(self, color=(0, 0, 0)):
     for x in range(self.nx + 1):
         xrail = x * self.railw
         for y in range(self.ny + 1):
             yrail = y * self.railh
             p1 = parameters.scene.relative_to_cam(V3(xrail, yrail, 0))
             p2 = parameters.scene.relative_to_cam(
                 V3(xrail, yrail, parameters.VISURAIL_LENGTH))
             path = Path3D([p1, p2], False, Material(color))
             ##                path = Path3D([V3(xrail,yrail,0),V3(xrail,yrail,30)],False,color)
             self.add_thing(path, 0, self.zfinish,
                            parameters.VISURAIL_SPACE,
                            parameters.VISURAIL_NMAX)
def wings_rect(a,b,color,x=0.,y=0.,angle=0.):
    w = primitivemeshes.rectangle(a,b,color)
    w.rotate_around_center_x(-90)
    w.from_init_rot = V3()
    w2 = w.get_copy()
##    w.move(V3(0,-a,0)) #biplan
##    w2.move(V3(0,a,0))
    w.move(V3(x,y,-b/2-1)) #monoplan
    w.rotate_around_center_x(angle)
    w2.move(V3(x,y,b/2+1))
    w2.rotate_around_center_x(-angle)
    w.from_init = V3()
    w2.from_init = V3()
##    w = w.get_splitted_copy()
    return w,w2
Beispiel #11
0
    def rail_centers(self):
        for rail in self.rails.itercells():
            yield V3(rail.middlepos)


##    def monitor(self):
##        monitor.show("abc")
##
##
##import time
##class Monitor:
##
##    def append(self, name):
##        if not hasattr(self, name):
##            setattr(self, name, [time.clock()])
##        else:
##            getattr(self,name).append(time.clock())
##
##    def show(self, letters):
##        tot = [0.]*len(letters)
##        L = len(getattr(self,letters[0]))
##        for i in range(1,len(letters)):
##            for k in range(L):
##                diff = getattr(self,letters[i])[k] - getattr(self,letters[i-1])[k]
##                tot[i] += diff
##        for i in range(1,len(tot)):
##            print(letters[i-1]+"->"+letters[i]+": "+str(tot[i]))
##
##monitor = Monitor()
Beispiel #12
0
def rectangle(a, b, color=(0, 0, 0)):
    t1 = ManualObject3D([
        Triangle(V3(0, 0, 0), V3(a, 0, 0), V3(a, b, 0), color=Material(color)),
        Triangle(V3(0, 0, 0), V3(a, b, 0), V3(0, b, 0), color=Material(color))
    ])
    t1.move(V3(-a / 2, -b / 2, 0))
    t1.from_init = V3()
    t1.refresh_normals()
    return t1
def wings_free(a,b,c,d,fleche,color,angle=0.,y=0,sym=True):
    assert d < 0
    assert a > 0
    p1 = V3()
    p2 = p1 + V3(0,0,a)
    p3 = p2 + V3(b,0,-fleche)
    p4 = p3 + V3(c,0,d)
##    if p4.z > p2.z:
##        print("correction")
##        p4.z = p2.z-0.2
##    mesh = core3d.Area3D([p1,p2,p3,p4],color)
    if sym:
        t1 = core3d.Triangle(p1,p2,p3)
        t2 = core3d.Triangle(p1,p3,p4)
    else:
        t1 = core3d.Triangle(p3,p2,p1)
        t2 = core3d.Triangle(p4,p3,p1)
    mesh = core3d.ManualObject3D([t1,t2])
    mesh.refresh_normals()
    mesh.refresh()
    mesh.rotate_around_center_y(90)
    delta = -1
    if not sym: delta*=-1
    mesh.move(V3(-1,y,delta))
    mesh.from_init = V3()
    mesh.rotate_around_center_x(angle)
    mesh.from_init_rot = V3()
    mesh.set_color(color)
    #
    if sym:
        return mesh, wings_free(a,-b,-c,d,fleche,color,-angle,y,False)
    else:
        return mesh
 def vessel_collision(self, vessel):
     if random.random() < 0.5:
         vessel.change_rail(2 * random.randint(0, 1) - 1,
                            2 * random.randint(0, 1) - 1)
     if self.dyn.velocity.x != 0:
         self.dyn.velocity.x *= -10
     elif self.dyn.velocity.y != 0:
         self.dyn.velocity.y *= -1
     elif self.dyn.velocity.z > vessel.dyn.velocity.z:
         if vessel.is_hero:
             self.move(V3(0, 0, -20))
         else:
             vessel.move(V3(0, 0, 20))
     else:
         if vessel.is_hero:
             self.move(V3(0, 0, -20))
         else:
             vessel.move(V3(0, 0, 20))
 def add_globs_square(self, frompos, topos, spacing=60, maxn=10):
     glob = primitivemeshes.p_rectangle(self.track.nx * parameters.RAILW,
                                        self.track.ny * parameters.RAILH,
                                        filled=False)
     glob.move(
         V3(self.track.nx * parameters.RAILW // 2,
            self.track.ny * parameters.RAILH // 2, 0))
     glob.closed = False
     globs = self.track.add_thing(glob, frompos, topos, spacing, maxn)
     return globs
Beispiel #16
0
def p_rectangle(a, b, color=(0, 0, 0), edges=None, filled=True):
    points = [V3(0, 0, 0), V3(a, 0, 0), V3(a, b, 0), V3(0, b, 0)]
    area = Path3D(points, True, color=Material(color))
    if edges:
        area.edges = V3(edges)
    area.move(V3(-a / 2, -b / 2, 0))
    area.from_init = V3()
    area.filled = filled
    return area
Beispiel #17
0
def a_rectangle(a, b, color=(0, 0, 0), edges=None):
    points = [V3(0, 0, 0), V3(a, 0, 0), V3(a, b, 0), V3(0, b, 0)]
    area = Area3D(points, color=Material(color))
    if edges:
        area.edges = V3(edges)
    area.move(V3(-a / 2, -b / 2, 0))
    area.from_init = V3()
    area.refresh_triangle()
    return area
Beispiel #18
0
 def refresh(self): #get_rail_from_pos
     if self.rotation_x:
         self.obj.rotate_around_center_x(self.rotation_x)
     elif self.rotation_y:
         self.obj.rotate_around_center_y(self.rotation_y)
     #
     if self.movement_x:
         shift = parameters.scene.cam.from_init
         if self.box.x[0] + shift.x < 0:
             self.movement_x = get_positive(self.movement_x)
         elif self.box.x[1] + shift.x> self.W:
             self.movement_x = get_negative(self.movement_x)
         self.obj.move(V3(self.movement_x,0,0))
     if self.movement_y:
         shift = parameters.scene.cam.from_init
         if self.box.y[0] + shift.y < 0:
             self.movement_y = get_positive(self.movement_y)
         elif self.box.y[1] + shift.y> self.W:
             self.movement_y = get_negative(self.movement_y)
         self.obj.move(V3(0,self.movement_y,0))
Beispiel #19
0
 def __init__(self, obj, vel, n):
     debris = get_debris(obj)
     size = (obj.box.x[1]-obj.box.x[0])//2
     self.debris = [debris.get_copy() for i in range(n)]
     self.rotations = [random.randint(0,2) for i in range(n)]
     for t in self.debris:
         t.physics = Physics(vel)
         t.move(V3([random.randint(-size,size) for i in range(3)]))
     self.cam = parameters.scene.cam
     self.light = parameters.scene.light
     self.i = 0
Beispiel #20
0
def p_arrow_line(a, b, c, color=(0, 0, 0)):
    path = PathBuilder([V3(-a, 0, 0)])
    path.go(2 * a, 0, 0)
    path.go(0, 0, b)
    path.go(c, 0, 0)
    path.go(-c - a, 0, c)  #middle
    path.go(-c - a, 0, -c)
    path.go(c, 0, 0)
    path.go(0, 0, -b)
    p = Path3D(path.path, True, Material(color))
    p.filled = False
    return p
Beispiel #21
0
 def __init__(self, color, m=None, M=None):
     if isinstance(color, Material):
         m = color.m
         M = color.M
         color = color.col
     self.col = V3(color)
     self.m = m
     if self.m is None:
         self.m = self.col * 0.2
     self.M = M
     if self.M is None:
         self.M = control_color(self.col * 1.1 + hundred)
Beispiel #22
0
 def __init__(self, v1, v2, v3, color=None):
     self.v1 = v1
     self.v2 = v2
     self.v3 = v3
     self.n = None
     self.c = None
     self.color = color
     if color is None:
         self.color = V3(random.randint(0, 255), random.randint(0, 255),
                         random.randint(0, 255))
     self.ecolor = self.color
     self.neighs = []
     self.pd = None
Beispiel #23
0
def func(event):
    global light_pos
    objs.sort(key=lambda x:x.from_center.length(), reverse=True)
    screen.fill((255,255,255))
    DS = 0.2
    DA = 10
    print(pygame.event.event_name(event.type))
    if event.key == pygame.K_LEFT:
        active_obj.move(V3(-DS,0,0))
    elif event.key == pygame.K_RIGHT:
        active_obj.move(V3(DS,0,0))
    elif event.key == pygame.K_DOWN:
        active_obj.move(V3(0,-DS,0))
    elif event.key == pygame.K_UP:
        active_obj.move(V3(0,DS,0))
    elif event.key == pygame.K_m:
        active_obj.move(V3(0,0,DS))
    elif event.key == pygame.K_l:
        active_obj.move(V3(0,0,-DS))
    elif event.key == pygame.K_z:
        active_obj.rotate_around_center_z(DA)
    elif event.key == pygame.K_u:
        active_obj.rotate_around_center_z(-DA)
    elif event.key == pygame.K_x:
        active_obj.rotate_around_center_x(DA)
    elif event.key == pygame.K_c:
        active_obj.rotate_around_center_x(-DA)
    elif event.key == pygame.K_y:
        active_obj.rotate_around_center_y(DA)
    elif event.key == pygame.K_a:
        active_obj.rotate_around_center_y(-DA)
    elif event.key == pygame.K_SPACE:
##        cam.move(V3(1,0,1), objs)
        cam.rotate("y",1,objs)
    for obj in objs: #pas boucler sur objs mais sur tous les triangles de la scen!!! ==> objet scene, le concept de obj est la que pour user transfos ?
        obj.refresh()
        i = 0
        for t in obj.triangles:
            if t.c.z > 0: #c denotes the center coordinate
                p = []
                for v in t.vertices():
                    x,y = cam.project(v)
                    p.append((int(x),int(y)))
                if USE_LIGHT:
                    color = light.get_color(t)
                else:
                    color = t.color
##                print(color)
##                color = t.color
##                print(p)
                gfx.filled_trigon(screen, p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1], color)
                gfx.aatrigon(screen, p[0][0], p[0][1], p[1][0], p[1][1], p[2][0], p[2][1], color)
            i+=1
    pygame.display.flip()
 def add_globs_circle(self,
                      frompos,
                      topos,
                      n=10,
                      spacing=60,
                      maxn=10,
                      dr=0):
     radius = max(self.track.nx * parameters.RAILW,
                  self.track.ny * parameters.RAILH) + dr
     radius *= 1.5
     glob = primitivemeshes.p_disk(radius / 2, False, n=n)
     glob.move(
         V3(self.track.nx * parameters.RAILW // 2,
            self.track.ny * parameters.RAILH // 2, 0))
     glob.closed = False
     globs = self.track.add_thing(glob, frompos, topos, spacing, maxn)
     return globs
Beispiel #25
0
 def __init__(self, screen, fov, d, objs):
     self.screen = screen
     self.w = screen.get_width() / 2.
     self.h = screen.get_height() / 2.
     self.fov = fov
     self.d = d
     self.objs = objs
     #
     self.aa = parameters.AA
     self.set_aa(True)
     self.draw_object = None
     self.draw_filled_polygon = None
     self.draw_polygon = None
     self.draw_path = None
     #
     self.from_init = V3()
     self.set_aa(True)
Beispiel #26
0
 def add_thing(self, thing, frompos, topos, spacing, maxn=None):
     n = (topos - frompos) // spacing
     if maxn is None:
         maxn = n
     manager = ThingManager(n, maxn, spacing)
     type_ = get_type(thing)
     actual_number_drawn = min(n, maxn)
     copies = []
     for i in range(actual_number_drawn):
         cpy = thing.get_copy()
         cpy.move(V3(0, 0, frompos + i * spacing))
         cpy.manager = manager
         if type_ == "p":
             self.things_paths.append(cpy)
         else:
             self.things_objects.append(cpy)
         copies.append(cpy)
     return copies
def cut_object(filename, color, glass_color):
   model = core3d.Object3D(filename)
   model.set_color(color)
   model.rotate_around_center_x(-90)
   model.from_init_rot = V3()
   tail, nose, c**k = [], [], []
   for t in model.triangles:
       x = [p.x for p in t.vertices()]
       if max(x) <= -2.:
           tail.append(t)
       elif min(x) >= 2.:
           nose.append(t)
       else:
           c**k.append(t)
   tail = core3d.ManualObject3D(tail)
   nose = core3d.ManualObject3D(nose)
   c**k = core3d.ManualObject3D(c**k)
   for t in c**k.triangles:
       if sum([abs(value)>1e-6 for value in t.compute_normal()]) > 1:
           t.color = glass_color
   return [tail, nose, c**k]
Beispiel #28
0
def create_vessel(color):
    quality = parameters.CURRENT_QUALITY
    glass = Material((0, 0, 0), M=(120, 120, 120))
    rest = Material(color)
    t, n, c = garage.generate_vessel(rest, glass)
    w = garage.random_wing(rest)
    v = vessel.Vessel(None, more_triangles=[])
    #quality = power*friction
    #quality = turn+max_fuel
    power_rand = random.random() + 0.000001
    power = parameters.MIN_POWER + power_rand * (parameters.MAX_POWER -
                                                 parameters.MIN_POWER)
    friction = power_rand
    power *= parameters.ENGINE_POWER
    mass = parameters.MIN_MASS + random.random() * (parameters.MAX_MASS -
                                                    parameters.MIN_MASS)
    turn = parameters.MIN_TURN + random.random() * (parameters.MAX_TURN -
                                                    parameters.MIN_TURN)
    max_fuel = quality - turn
    max_fuel = parameters.MIN_FUEL + int(
        max_fuel * (parameters.MAX_FUEL - parameters.MIN_FUEL))
    #
    v.tail = vessel.Part(t.triangles, turn, friction, mass)
    v.nose = vessel.Part(n.triangles, turn, friction, mass)
    v.cockpit = vessel.Part(c.triangles, turn, friction, mass)
    v.lwing = vessel.Part(w[0].triangles, turn / 2., friction / 2., mass / 2.)
    v.rwing = vessel.Part(w[1].triangles, turn / 2., friction / 2., mass / 2.)
    v.engine = vessel.Engine(max_fuel, power)
    v.engine.mass = mass
    v.engine.turn = turn
    v.engine.friction = friction
    #
    v.refresh_mesh()
    v.rotate_around_center_y(-90)
    v.compute_box3D()
    v.compute_dynamics()
    v.from_init_rot = V3()
    v.color = rest
    #
    return v
 def f():
     self.color += self.color_sign
     if self.color >= 255:
         self.color = 255
         self.color_sign *= -1
     elif self.color <= 0:
         self.color = 0
         self.color_sign *= -1
     #refresh color
     for c in acol:
         self.material.col[1] = self.color
         self.material.m[1] = self.color / 0.2
         self.material.M[1] = min(self.color * 1.1 + 100, 255)
     for c in arot:
         c.rotate_around_center_z(1)
     for c in amov:
         c.move(V3(0, 0, -1))
     for g in rotating:
         g.rotate_around_center_z(3)
     for g in coloring:
         self.material2.col[1] = self.color
         self.material2.m[1] = self.color / 0.2
         self.material2.M[1] = min(self.color * 1.1 + 100, 255)
MODELS = [
    "Aerocrush", "BangDynamics", "CabalysticsAndCo", "Dropplet", "Elbus",
    "F12", "GorschType", "Herschel", "Illuminus"
]
HERO_COLOR = (0, 0, 255)
HERO_MODEL = None
HERO_NAME = "Hero"

PRICE = 5000.

MOVE_DELTA_I = 5
VISIBILITY = 800
SPEED = 0  #to be deleted

##HERO_POS = V3(0,-4,15)
HERO_POS = V3(0, -4, 10)
ORIGINAL_HERO_POS = V3(HERO_POS)

MIN_BOX_THICKNESS = 10

RAILW = 12
RAILH = 12

TURN = 2. / 10.
FRICTION = 1. / 500.
MASS = 1. / 10.

CURRENT_QUALITY = 1.

BACKGROUNDS = {
    1.: "background1.jpg",