示例#1
0
    def reload_vbos(self, meshes=None):
        mesh_vbos = []

        # Each mesh gets its own VBO.
        # Each leaf gets its own unique color within the mesh VBO

        all_leafs = []
        if meshes is None:  meshes = self.meshes

        for m in meshes:
            leafs = m.leafs()
            all_leafs += leafs
            merged = Mesh.merge(leafs)

            tcounts = [L.tcount for L in leafs]

            mesh_vbos.append(
                (vbo.VBO(merged.vdata, size=merged.vcount*4*6),
                 vbo.VBO(merged.tdata, target=GL_ELEMENT_ARRAY_BUFFER,
                     size=merged.tcount*4*3),
                 tcounts,
                 m, merged)
            )


        wx.CallAfter(self._reload_vbos, mesh_vbos, all_leafs)
示例#2
0
文件: asdf.py 项目: zsf1975/kokopelli
    def _triangulate(self, halt, queue=None):
        ''' Triangulates a mesh, storing data in the vdata and idata
            arrays.  Pushes results to the queue.'''

        mesh = Mesh(libfab.triangulate(self.ptr, halt))
        if queue: queue.put(mesh)
        else: return mesh
示例#3
0
    def load(self):
        """ @brief Loads the current design file
            @details The file is defined by self.directory and self.filename
        """
        self.clear()

        path = os.path.join(self.directory, self.filename)

        if path[-4:] == '.cad':
            with open(path, 'r') as f:
                text = f.read()
                if text.split('\n')[0] == '##    Geometry header    ##':
                    koko.PRIMS.reconstruct(eval(text.split('\n')[1]))
                    koko.PRIMS.undo_stack = [koko.PRIMS.reconstructor()]
                    text = '\n'.join(text.split('\n')[3:])
            koko.EDITOR.text = text
            koko.FRAME.status = 'Loaded .cad file'

            self.mode = 'cad/cam'
            self.first_render = True
            self.savepoint(True)

        elif path[-4:] == '.png':
            self.mode = 'cam'
            img = Image.load(path)
            koko.CANVAS.load_image(img)
            koko.GLCANVAS.load_image(img)
            koko.FAB.set_input(img)
            wx.CallAfter(self.snap_bounds)

        elif path[-4:] == '.stl':
            self.mode = 'cam'
            mesh = Mesh.load(path)
            koko.GLCANVAS.load_mesh(mesh)
            wx.CallAfter(self.snap_bounds)

        elif path[-5:] == '.asdf':
            self.render_mode('3D')
            self.mode = 'cam'

            msg = dialogs.display_message('Loading...', 'Loading ASDF.')
            msg.Raise()
            wx.Yield()

            asdf = ASDF.load(path)
            msg.txt.SetLabel('Triangulating')
            wx.Yield()

            mesh = asdf.triangulate()
            mesh.source = Struct(type=ASDF, file=path, depth=0)
            msg.Destroy()

            koko.GLCANVAS.load_mesh(mesh)
            koko.FAB.set_input(asdf)
示例#4
0
    def export_stl(self):
        ''' Exports an stl, using an asdf as intermediary.
        '''
        i = 0
        meshes = []
        for expr in self.cad.shapes:

            if self.event.is_set(): return
            asdf = self.make_asdf(expr)
            i += 1
            self.window.progress = i*33/len(self.cad.shapes)

            if self.event.is_set(): return
            mesh = self.make_mesh(asdf)
            i += 2
            self.window.progress = i*33/len(self.cad.shapes)

            if mesh is not None:    meshes.append(mesh)

        if self.event.is_set(): return
        total = Mesh.merge(meshes)
        total.save_stl(self.filename)
示例#5
0
    def export_stl(self):
        ''' Exports an stl, using an asdf as intermediary.
        '''
        i = 0
        meshes = []
        for expr in self.cad.shapes:

            if self.event.is_set(): return
            asdf = self.make_asdf(expr)
            i += 1
            self.window.progress = i * 33 / len(self.cad.shapes)

            if self.event.is_set(): return
            mesh = self.make_mesh(asdf)
            i += 2
            self.window.progress = i * 33 / len(self.cad.shapes)

            if mesh is not None: meshes.append(mesh)

        if self.event.is_set(): return
        total = Mesh.merge(meshes)
        total.save_stl(self.filename)
示例#6
0
    def reload_vbos(self, meshes=None):
        mesh_vbos = []

        # Each mesh gets its own VBO.
        # Each leaf gets its own unique color within the mesh VBO

        all_leafs = []
        if meshes is None: meshes = self.meshes

        for m in meshes:
            leafs = m.leafs()
            all_leafs += leafs
            merged = Mesh.merge(leafs)

            tcounts = [L.tcount for L in leafs]

            mesh_vbos.append(
                (vbo.VBO(merged.vdata, size=merged.vcount * 4 * 6),
                 vbo.VBO(merged.tdata,
                         target=GL_ELEMENT_ARRAY_BUFFER,
                         size=merged.tcount * 4 * 3), tcounts, m, merged))

        wx.CallAfter(self._reload_vbos, mesh_vbos, all_leafs)
示例#7
0
文件: app.py 项目: F3R70/kokopelli
    def load(self):
        """ @brief Loads the current design file
            @details The file is defined by self.directory and self.filename
        """
        self.clear()

        path = os.path.join(self.directory, self.filename)

        if path[-4:] == '.cad':
            with open(path, 'r') as f:
                text = f.read()
                if text.split('\n')[0] == '##    Geometry header    ##':
                    koko.PRIMS.reconstruct(eval(text.split('\n')[1]))
                    koko.PRIMS.undo_stack = [koko.PRIMS.reconstructor()]
                    text = '\n'.join(text.split('\n')[3:])
            koko.EDITOR.text = text
            koko.FRAME.status = 'Loaded .cad file'

            self.mode = 'cad'
            self.first_render = True
            self.savepoint(True)

        elif path[-4:] == '.png':
            self.mode = 'png'
            img = Image.load(path)
            koko.CANVAS.load_image(img)
            koko.GLCANVAS.load_image(img)
            koko.FAB.set_input(img)
            wx.CallAfter(self.snap_bounds)

        elif path[-4:] == '.stl':
            self.mode = 'stl'
            mesh = Mesh.load(path)

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            wx.CallAfter(self.snap_bounds)

        elif path[-5:] == '.asdf':
            self.mode = 'asdf'

            koko.FRAME.status = 'Loading ASDF'
            wx.Yield()

            asdf = ASDF.load(path)
            koko.FRAME.status = 'Triangulating'
            wx.Yield()

            mesh = asdf.triangulate()
            mesh.source = Struct(type=ASDF, file=path, depth=0)
            koko.FRAME.status = ''

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            koko.FAB.set_input(asdf)

        elif path[-4:] == '.vol':
            self.mode = 'vol'
            koko.IMPORT.set_target(self.directory, self.filename)
示例#8
0
文件: asdf.py 项目: zsf1975/kokopelli
 def triangulate_cms(self):
     return Mesh(libfab.triangulate_cms(self.ptr))
示例#9
0
    def load(self):
        """ @brief Loads the current design file
            @details The file is defined by self.directory and self.filename
        """
        self.clear()

        path = os.path.join(self.directory, self.filename)

        if path[-3:] == '.ko' or path[-4:] == '.cad':
            with open(path, 'r') as f:
                text = f.read()
                if text.split('\n')[0] == '##    Geometry header    ##':
                    koko.PRIMS.reconstruct(eval(text.split('\n')[1]))
                    koko.PRIMS.undo_stack = [koko.PRIMS.reconstructor()]
                    text = '\n'.join(text.split('\n')[3:])
            koko.EDITOR.text = text
            koko.FRAME.status = 'Loaded design file'

            if path[-4:] == '.cad':
                dialogs.warning("""
This file has a '.cad' extension, which was superceded by '.ko'.  It may use deprecated features or syntax.

If it is an example file, the 'kokopelli/examples' folder may include an updated version with a '.ko' extension"""
                                )

            self.mode = 'cad'
            self.first_render = True
            self.savepoint(True)

        elif path[-4:] == '.png':
            self.mode = 'png'
            img = Image.load(path)
            koko.CANVAS.load_image(img)
            koko.GLCANVAS.load_image(img)
            koko.FAB.set_input(img)
            wx.CallAfter(self.snap_bounds)

        elif path[-4:] == '.stl':
            self.mode = 'stl'
            mesh = Mesh.load(path)

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            wx.CallAfter(self.snap_bounds)

        elif path[-5:] == '.asdf':
            self.mode = 'asdf'

            koko.FRAME.status = 'Loading ASDF'
            wx.Yield()

            asdf = ASDF.load(path)
            koko.FRAME.status = 'Triangulating'
            wx.Yield()

            mesh = asdf.triangulate()
            mesh.source = Struct(type=ASDF, file=path, depth=0)
            koko.FRAME.status = ''

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            koko.FAB.set_input(asdf)

        elif path[-4:] == '.vol':
            self.mode = 'vol'
            koko.IMPORT.set_target(self.directory, self.filename)
示例#10
0
    def load(self):
        """ @brief Loads the current design file
            @details The file is defined by self.directory and self.filename
        """
        self.clear()

        path = os.path.join(self.directory, self.filename)

        if path[-4:] == '.cad':
            with open(path, 'r') as f:
                text = f.read()
                if text.split('\n')[0] == '##    Geometry header    ##':
                    koko.PRIMS.reconstruct(eval(text.split('\n')[1]))
                    koko.PRIMS.undo_stack = [koko.PRIMS.reconstructor()]
                    text = '\n'.join(text.split('\n')[3:])
            koko.EDITOR.text = text
            koko.FRAME.status = 'Loaded .cad file'

            self.mode = 'cad'
            self.first_render = True
            self.savepoint(True)

        elif path[-4:] == '.png':
            self.mode = 'png'
            img = Image.load(path)
            koko.CANVAS.load_image(img)
            koko.GLCANVAS.load_image(img)
            koko.FAB.set_input(img)
            wx.CallAfter(self.snap_bounds)

        elif path[-4:] == '.stl':
            self.mode = 'stl'
            mesh = Mesh.load(path)

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            wx.CallAfter(self.snap_bounds)

        elif path[-5:] == '.asdf':
            self.mode = 'asdf'

            koko.FRAME.status = 'Loading ASDF'
            wx.Yield()

            asdf = ASDF.load(path)
            koko.FRAME.status = 'Triangulating'
            wx.Yield()

            mesh = asdf.triangulate()
            mesh.source = Struct(type=ASDF, file=path, depth=0)
            koko.FRAME.status = ''

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            koko.FAB.set_input(asdf)

        elif path[-4:] == '.vol':
            self.mode = 'vol'
            koko.IMPORT.set_target(self.directory, self.filename)
示例#11
0
    def load(self):
        """ @brief Loads the current design file
            @details The file is defined by self.directory and self.filename
        """
        self.clear()

        path = os.path.join(self.directory, self.filename)

        if path[-3:] == '.ko' or path[-4:] == '.cad':
            with open(path, 'r') as f:
                text = f.read()
                if text.split('\n')[0] == '##    Geometry header    ##':
                    koko.PRIMS.reconstruct(eval(text.split('\n')[1]))
                    koko.PRIMS.undo_stack = [koko.PRIMS.reconstructor()]
                    text = '\n'.join(text.split('\n')[3:])
            koko.EDITOR.text = text
            koko.FRAME.status = 'Loaded design file'

            if path[-4:] == '.cad':
                dialogs.warning("""
This file has a '.cad' extension, which was superceded by '.ko'.  It may use deprecated features or syntax.

If it is an example file, the 'kokopelli/examples' folder may include an updated version with a '.ko' extension""")

            self.mode = 'cad'
            self.first_render = True
            self.savepoint(True)

        elif path[-4:] == '.png':
            self.mode = 'png'
            img = Image.load(path)
            koko.CANVAS.load_image(img)
            koko.GLCANVAS.load_image(img)
            koko.FAB.set_input(img)
            wx.CallAfter(self.snap_bounds)

        elif path[-4:] == '.stl':
            self.mode = 'stl'
            mesh = Mesh.load(path)

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            wx.CallAfter(self.snap_bounds)

        elif path[-5:] == '.asdf':
            self.mode = 'asdf'

            koko.FRAME.status = 'Loading ASDF'
            wx.Yield()

            asdf = ASDF.load(path)
            koko.FRAME.status = 'Triangulating'
            wx.Yield()

            mesh = asdf.triangulate()
            mesh.source = Struct(type=ASDF, file=path, depth=0)
            koko.FRAME.status = ''

            koko.FRAME.get_menu('View', '3D').Check(True)
            self.render_mode('3D')

            koko.GLCANVAS.load_mesh(mesh)
            koko.FAB.set_input(asdf)

        elif path[-4:] == '.vol':
            self.mode = 'vol'
            koko.IMPORT.set_target(self.directory, self.filename)