Пример #1
0
class MyWindow(Window):
    def __init__(self):
        super().__init__(500, 800, 'mywindow', None, None)
        self.framerate = 120
        camera = self.devices.cameras[0]
        camera.tripod.lookat(eye=(-100, -100, 100), at=(0, 0, 0), up=(0, 0, 1))
        # self.devices.cameras.attach_fps_dolly(0, 0)

        self.modeler = AModeler()
        self.model = self.modeler.add_model(parent=None)
        self.modeler.add_ground(self.model, [.5] * 4)
        self.modeler.add_pln(self.model, (0, 0, 0.001), (1, 0, 0), (0, 1, 0),
                             (0, 0, 1))
        self.picker = VicinityPicker()

    def draw(self):
        with self.devices.frames[0] as df:
            df.clear(0, 0, 0, 1)
            df.clear_depth()

            with self.devices.cameras[0] as c:
                self.modeler.render()

                selection = self.picker.pick(gt.Pln(), c,
                                             self.devices.cursors[0])
                if selection:
                    key, point = selection
                    if key == 'xy':
                        clr = 0, 0, 1, 0.5
                    elif key == 'yz':
                        clr = 1, 0, 0, 0.5
                    else:
                        clr = 0, 1, 0, 0.5
                    self.modeler.add_raw(self.model, point).clr = clr
class MyWindow(Window):
    def __init__(self):
        super().__init__(1000, 500, 'my window 1', monitor=None, shared=None)
        self.framerate = 60

        self.fcount = 0
        # enable camera move
        self.devices.cameras[0].tripod.lookat((0, 0, 2000), (0, 0, 0), (0, 1, 0))
        d = self.devices.cameras.attach_fps_dolly(0, 0)
        d.move_boost = 10
        d.move_spd = 5
        # create model
        self.modeler = AModeler()
        self.model = self.modeler.add_model(parent=None)

        self.num_scratch = 0
        self.ori = None
        self.lin_vec = None
        self.offset_vec = None
        self.thk = None

    def draw(self):
        if not self.num_scratch:
            self.ori = gt.Pnt(*(random.randint(-1500, 1500) for _ in range(2)), random.randint(-200, 200))
            self.lin_vec = gt.Vec(*(random.uniform(-1, 1) for _ in range(2))).amplify(random.randint(200, 500))
            self.offset_vec = gt.Vec.cross(gt.ZVec(), self.lin_vec).amplify(random.randint(10, 100))
            self.num_scratch = random.randint(0, 25)
            self.thk = random.randint(2, 15)

        if self.fcount % 3 == 0:
            geo = gt.Lin.from_pnt_vec(self.ori + self.offset_vec * self.num_scratch, self.lin_vec)
            lin = self.modeler.add_raw(self.model, geo)
            lin.thk = self.thk
            self.num_scratch -= 1
        self.fcount += 1

        with self.devices.panes[0] as p:
            with self.devices.cameras[0] as c:
                p.clear(.5, .5, .5, 1)
                self.modeler.render()
Пример #3
0
class MyWindow(Window):
    def __init__(self):
        super().__init__(1000, 1000, 'my window 1', monitor=None, shared=None)
        self.framerate = 60
        # enable camera move
        o = 200
        # self.devices.cameras[0].tripod.lookat(eye=(0, 0, o), at=(0, 0, 0), up=(0, 1, 0))
        self.devices.cameras[0].focus_pane(pane=self.devices.panes[0],
                                           focus=(0, 0, 0),
                                           clip_off=100)

        # create model
        self.modeler = AModeler()
        model = self.modeler.add_model(None)
        plns = []
        self.model1 = model
        pw, ph = self.devices.panes[0].size.xy
        n = 7
        nw, nh = pw // n, ph // n
        for x in range(-pw // 2 + nw, pw // 2 - nw + 1, nw):
            for y in range(-ph // 2 + nh, ph // 2 - nh + 1, nh):
                plns.append(gt.Pln(o=(x, y, 0)))
                self.modeler.add_pnt(model, x, y, 1).clr = ClrRGBA(1, 1, 0, 1)

        e = 100
        q = e / 4
        h = e / 2
        o = e / 10
        t = e / 3
        pgons = []

        # A
        pgons.append(
            gt.Pgon((0, 0, 0), (q, 0, 0), (t, q, 0), (2 * t, q, 0),
                    (3 * q, 0, 0), (e, 0, 0), (h, e, 0), (0, 0, 0)))
        # B
        k = e - 3 * o
        pgons.append(
            gt.Pgon((0, 0, 0), (k, 0, 0), (e, o, 0), (e, h - o, 0), (k, h, 0),
                    (e, h + o, 0), (e, e - o, 0), (k, e, 0), (0, e, 0),
                    (0, 0, 0)))
        # C
        pgons.append(
            gt.Pgon((q, 0, 0), (h, 0, 0), (e, 0, 0), (e, q, 0), (h, q, 0),
                    (t, t, 0), (t, 2 * t, 0), (h, e - q, 0), (e, e - q, 0),
                    (e, e, 0), (q, e, 0), (0, e - q, 0), (0, q, 0), (q, 0, 0)))
        # D
        pgons.append(
            gt.Pgon((0, 0, 0), (3 * q, 0, 0), (e, q, 0), (e, e - q, 0),
                    (e - q, e, 0), (0, e, 0), (0, 0, 0)))
        # E
        k = e / 5
        pgons.append(
            gt.Pgon((0, 0, 0), (e, 0, 0), (e, k, 0), (h, k, 0), (h, 2 * k, 0),
                    (e, 2 * k, 0), (e, 3 * k, 0), (h, 3 * k, 0), (h, 4 * k, 0),
                    (e, 4 * k, 0), (e, e, 0), (0, e, 0), (0, 0, 0)))
        # F
        k = e / 5
        pgons.append(
            gt.Pgon((0, 0, 0), (t, 0, 0), (t, q, 0), (2 * t, q, 0),
                    (2 * t, h, 0), (t, h, 0), (t, 3 * q, 0), (e, 3 * q, 0),
                    (e, e, 0), (0, e, 0), (0, 0, 0)))
        # G
        pgons.append(
            gt.Pgon((0, 0, 0), (e, 0, 0), (e, 2 * t - o, 0),
                    (e - q - o, 2 * t - o, 0), (e - q, t, 0), (q, t, 0),
                    (q, 2 * t, 0), (e, 2 * t, 0), (e, e, 0), (0, e, 0),
                    (0, 0, 0)))
        # H
        pgons.append(
            gt.Pgon((0, 0, 0), (t, 0, 0), (t, t, 0), (2 * t, t, 0),
                    (2 * t, 0, 0), (e, 0, 0), (e, e, 0), (2 * t, e, 0),
                    (2 * t, 2 * t, 0), (t, 2 * t, 0), (t, e, 0), (0, e, 0),
                    (0, 0, 0)))
        # I
        pgons.append(
            gt.Pgon((0, 0, 0), (e, 0, 0), (e, t, 0), (2 * t, t, 0),
                    (2 * t, 2 * t, 0), (e, 2 * t, 0), (e, e, 0), (0, e, 0),
                    (0, 2 * t, 0), (t, 2 * t, 0), (t, t, 0), (0, t, 0),
                    (0, 0, 0)))
        # J
        pgons.append(
            gt.Pgon((q, 0, 0), (2 * t, 0, 0), (e - o, t, 0), (e - o, e - q, 0),
                    (e, e - q, 0), (e, e, 0), (h, e, 0), (h, e - q, 0),
                    (2 * t, e - q, 0), (2 * t, h, 0), (h, q, 0), (t, q, 0),
                    (t, h, 0), (0, h, 0), (0, q, 0), (q, 0, 0)))
        # K
        pgons.append(
            gt.Pgon((0, 0, 0), (t, 0, 0), (t, q, 0), (h, 0, 0), (e, 0, 0),
                    (h, h, 0), (e, e - q, 0), (e, e, 0), (t, e - t, 0),
                    (t, e, 0), (0, e, 0), (0, 0, 0)))
        # L
        pgons.append(
            gt.Pgon((0, 0, 0), (e, 0, 0), (e, t, 0), (t, t, 0), (t, e, 0),
                    (0, e, 0), (0, 0, 0)))
        # M
        pgons.append(
            gt.Pgon((0, 0, 0), (q, 0, 0), (q, h, 0), (1.5 * q, q, 0),
                    (2.5 * q, q, 0), (3 * q, h, 0), (3 * q, 0, 0), (e, 0, 0),
                    (e, e, 0), (3 * q, e, 0), (2.2 * q, h, 0), (1.8 * q, h, 0),
                    (q, e, 0), (0, e, 0), (0, 0, 0)))
        # N
        pgons.append(
            gt.Pgon((0, 0, 0), (q, 0, 0), (q, h, 0), (3 * q, 0, 0), (e, 0, 0),
                    (e, e, 0), (3 * q, e, 0), (3 * q, h, 0), (q, e, 0),
                    (0, e, 0), (0, 0, 0)))
        # O
        pgons.append(
            gt.Pgon((q, 0, 0), (e - q, 0, 0), (e, q, 0), (e, e - q, 0),
                    (e - q, e, 0), (q, e, 0), (0, e - q, 0), (0, q, 0),
                    (q, 0, 0)))
        # P
        pgons.append(
            gt.Pgon((0, 0, 0), (q, 0, 0), (q, h, 0), (e, h, 0), (e, e, 0),
                    (0, e, 0), (0, 0, 0)))
        # Q
        pgons.append(
            gt.Pgon((q, 0, 0), (h + o, 0, 0), (t * 2 + o, o, 0), (e - o, 0, 0),
                    (e, o, 0), (e - o, t - o, 0), (e, h - o, 0), (e, e - q, 0),
                    (e - q, e, 0), (q, e, 0), (0, e - q, 0), (0, q, 0),
                    (q, 0, 0)))
        # R
        pgons.append(
            gt.Pgon((0, 0, 0), (h, 0, 0), (h, q, 0), (e - q, 0, 0), (e, q, 0),
                    (e - q, h, 0), (e, h, 0), (e, e, 0), (0, e, 0), (0, 0, 0)))
        # S
        pgons.append(
            gt.Pgon((0, 0, 0), (e, 0, 0), (e, e - t, 0), (t, e - t, 0),
                    (t, e - t + o, 0), (e, e - t + o, 0), (e, e, 0), (0, e, 0),
                    (0, t, 0), (e - t, t, 0), (e - t, t - o, 0), (0, t - o, 0),
                    (0, 0, 0)))
        # T
        pgons.append(
            gt.Pgon((q, 0, 0), (e - q, 0, 0), (e - q, e - q, 0), (e, e - q, 0),
                    (e, e, 0), (0, e, 0), (0, e - q, 0), (q, e - q, 0),
                    (q, 0, 0)))
        # U
        pgons.append(
            gt.Pgon((q, 0, 0), (e - q, 0, 0), (e, q, 0), (e, e, 0),
                    (e - t, e, 0), (e - t, h, 0), (t, h, 0), (t, e, 0),
                    (0, e, 0), (0, q, 0), (q, 0, 0)))
        # V
        pgons.append(
            gt.Pgon((q, 0, 0), (e - q, 0, 0), (e, e, 0), (e - t, e, 0),
                    (h, h, 0), (t, e, 0), (0, e, 0), (q, 0, 0)))
        # W
        f = e / 5
        pgons.append(
            gt.Pgon((f, 0, 0), (f * 2, 0, 0), (h, h, 0), (f * 3, 0, 0),
                    (f * 4, 0, 0), (e, e, 0), (e - f, e, 0),
                    (e - f * 1.5, h, 0), (f * 3, e, 0), (f * 2, e, 0),
                    (f * 1.5, h, 0), (f, e, 0), (0, e, 0), (f, 0, 0)))
        # X
        pgons.append(
            gt.Pgon((0, 0, 0), (q, 0, 0), (h, t, 0), (e, 0, 0), (e, q, 0),
                    (e - t, h, 0), (e, e, 0), (e - q, e, 0), (h, e - t, 0),
                    (0, e, 0), (0, e - q, 0), (t, h, 0), (0, 0, 0)))
        # Y
        pgons.append(
            gt.Pgon((t, 0, 0), (t * 2, 0, 0), (t * 2, h, 0), (e, e - t, 0),
                    (e, e, 0), (h, e - q, 0), (0, e, 0), (0, e - t, 0),
                    (t, h, 0), (t, 0, 0)))
        # Z
        pgons.append(
            gt.Pgon((0, 0, 0), (e, 0, 0), (e, q, 0), (h, q, 0), (e, e, 0),
                    (0, e, 0), (0, e - q, 0), (h, e - q, 0), (0, 0, 0)))

        for pgon, pln in zip(pgons, plns):
            self.modeler.add_raw(model, pln.orient(pgon,
                                                   gt.Pln())).edge_thk = 5
        self.model = model

    def draw(self, frame_count=None):
        with self.devices.panes[0] as p:
            with self.devices.cameras[0] as c:
                p.clear(.5, .5, .5, 1)
                # e = 100
                self.modeler.render()
Пример #4
0
class MyWindow(Window):
    def __init__(self):
        super().__init__(1000, 1000, 'my window 1', monitor=None, shared=None)
        self.framerate = 60
        # enable camera move
        o = 200
        # self.devices.cameras[0].tripod.lookat(eye=(0, 0, o), at=(0, 0, 0), up=(0, 1, 0))
        self.devices.cameras[0].focus_pane(pane=self.devices.panes[0],
                                           focus=(0, 0, 0),
                                           clip_off=100)

        # create model
        self.modeler = AModeler()
        self.model = self.modeler.add_model(parent=None)
        plns = []
        pw, ph = self.devices.panes[0].size.xy
        n = 6
        nw, nh = pw // n, ph // n
        for x in range(-pw // 2 + nw, pw // 2 - nw + 1, nw):
            for y in range(-ph // 2 + nh, ph // 2 - nh + 1, nh):
                plns.append(gt.Pln(o=(x, y, 0)))
                self.modeler.add_pnt(self.model, x, y,
                                     1).clr = ClrRGBA(1, 1, 0, 1)

        e = 100
        q = e / 4
        h = e / 2
        o = e / 10
        t = e / 3
        pgons = []

        # triangle
        pgons.append(gt.Pgon((0, 0, 0), (e, 0, 0), (0, e, 0), (0, 0, 0)))
        # rectangle
        pgons.append(
            gt.Pgon((0, 0, 0), (e, 0, 0), (e, e, 0), (0, e, 0), (0, 0, 0)))
        # block
        pgons.append(
            gt.Pgon((0, 0, 0), (h, 0, 0), (h, h, 0), (e, h, 0), (e, e, 0),
                    (0, e, 0), (0, 0, 0)))
        # hills
        pgons.append(
            gt.Pgon((0, 0, 0), (e, 0, 0), (e, h, 0), (q * 3, e, 0),
                    (q * 2, h, 0), (q, e, 0), (0, h, 0), (0, 0, 0)))
        # beanie
        pgons.append(
            gt.Pgon((0, 0, 0), (e, 0, 0), (e, h, 0), (q * 3, e, 0), (q, e, 0),
                    (0, h, 0), (0, 0, 0)))
        # cat
        pgons.append(
            gt.Pgon((0, 0, 0), (e, 0, 0), (e, h, 0), (q * 3, e, 0),
                    (q * 3, h, 0), (q, h, 0), (q, e, 0), (0, h, 0), (0, 0, 0)))
        # reverse house
        pgons.append(
            gt.Pgon((h, 0, 0), (e, h, 0), (e, e, 0), (0, e, 0), (0, h, 0),
                    (h, 0, 0)))
        # left dialog
        pgons.append(
            gt.Pgon((q, 0, 0), (h, h, 0), (e, h, 0), (e, e, 0), (0, e, 0),
                    (0, h, 0), (q, 0, 0)))
        # diamond
        pgons.append(
            gt.Pgon((h, 0, 0), (e, h, 0), (h, e, 0), (0, h, 0), (h, 0, 0)))
        # quad triangle
        pgons.append(
            gt.Pgon((h, 0, 0), (e, 0, 0), (h, e, 0), (0, 0, 0), (h, 0, 0)))
        # right dialog
        pgons.append(
            gt.Pgon((3 * q, 0, 0), (e, h, 0), (e, e, 0), (0, e, 0), (0, h, 0),
                    (h, h, 0), (3 * q, 0, 0)))
        # torn paper
        pgons.append(
            gt.Pgon((0, 0, 0), (-q, -q, 0), (0, -q, 0), (e, -q, 0),
                    (e - q, h, 0), (e, e, 0), (-q, e, 0), (0, h + q, 0),
                    (-q, q, 0), (0, 0, 0)))
        # flag right
        pgons.append(
            gt.Pgon((0, 0, 0), (e, 0, 0), (3 * q, h, 0), (e, e, 0), (0, e, 0),
                    (0, 0, 0)))

        # cravas
        pgons.append(
            gt.Pgon((0, 0, 0), (q, h, 0), (h, q, 0), (e, e, 0), (-h, e, 0),
                    (0, 0, 0)))
        # mountain
        pgons.append(
            gt.Pgon((0, 0, 0), (e, 0, 0), (e - q, 2 * q, 0), (e - q, q, 0),
                    (h, 3 * q, 0), (h, 2 * q, 0), (q, e, 0), (0, 0, 0)))
        # bow tie
        pgons.append(
            gt.Pgon((0, 0, 0), (h, q, 0), (e, 0, 0), (e, e, 0), (h, 3 * q, 0),
                    (0, e, 0), (0, 0, 0)))
        # pants
        pgons.append(
            gt.Pgon((0, 0, 0), (q, 0, 0), (h, h, 0), (3 * q, 0, 0), (e, 0, 0),
                    (e, e, 0), (0, e, 0), (0, 0, 0)))
        # bad m
        pgons.append(
            gt.Pgon((0, 0, 0), (q, 0, 0), (q, h, 0), (h, q, 0), (3 * q, h, 0),
                    (3 * q, 0, 0), (e, 0, 0), (e, e, 0), (0, e, 0), (0, 0, 0)))
        # M
        pgons.append(
            gt.Pgon((0, 0, 0), (q, 0, 0), (q, h, 0), (1.5 * q, q, 0),
                    (2.5 * q, q, 0), (3 * q, h, 0), (3 * q, 0, 0), (e, 0, 0),
                    (e, e, 0), (3 * q, e, 0), (2.2 * q, h, 0), (1.8 * q, h, 0),
                    (q, e, 0), (0, e, 0), (0, 0, 0)))
        # N
        pgons.append(
            gt.Pgon((0, 0, 0), (q, 0, 0), (q, h, 0), (3 * q, 0, 0), (e, 0, 0),
                    (e, e, 0), (3 * q, e, 0), (3 * q, h, 0), (q, e, 0),
                    (0, e, 0), (0, 0, 0)))
        # drill
        pgons.append(
            gt.Pgon((h - o, 0, 0), (h + o, 0, 0), (2 * t, h, 0),
                    (2.5 * t, h, 0), (e, h + q, 0), (e, e, 0), (0, e, 0),
                    (0, h + q, 0), (0.5 * t, h, 0), (t, h, 0), (h - o, 0, 0)))
        # gate
        pgons.append(
            gt.Pgon((0, 0, 0), (t, 0, 0), (t, h, 0), (2 * t, h, 0),
                    (2 * t, 0, 0), (e, 0, 0), (e, e, 0), (0, e, 0), (0, 0, 0)))
        # # thin leg
        pgons.append(
            gt.Pgon((0, 0, 0), (t, 0, 0), (t, h, 0), (2 * t, h, 0),
                    (2 * t, 0, 0), (e, e, 0), (0, e, 0), (0, 0, 0)))

        # nepal
        pgons.append(
            gt.Pgon((0, 0, 0), (e, q, 0), (q, h, 0), (3 * q, 3 * q, 0),
                    (0, e, 0), (0, 0, 0)))
        # tick
        pgons.append(
            gt.Pgon((0, 0, 0), (h, h, 0), (0, -h, 0), (-h, 0, 0), (0, 0, 0)))

        for pgon, pln in zip(pgons, plns):
            self.modeler.add_raw(self.model, pln.orient(pgon,
                                                        gt.Pln())).edge_thk = 5

    def draw(self, frame_count=None):
        with self.devices.panes[0] as p:
            with self.devices.cameras[0] as c:
                p.clear(.5, .5, .5, 1)
                self.modeler.render()