Пример #1
0
        def apply(self, mesh, filename):
            if os.path.exists(filename):
                raise FilterException("Specified mesh filename already exists")

            dotloc = filename.rfind('.')
            if dotloc == -1:
                mtlfilename = filename
            else:
                mtlfilename = filename[:dotloc]
            mtlfilename += '.mtl'
            if os.path.exists(mtlfilename):
                raise FilterException("Material filename already exists")

            # Handle materials first, iterating through all materials
            fmtl = open(mtlfilename, 'w')
            save_obj_util.write_mtl(mesh, fmtl, mtlfilename)
            fmtl.close()

            f = open(filename, 'w')
            rel_mtlfilename = os.path.relpath(mtlfilename,
                                              os.path.dirname(filename))
            save_obj_util.write_obj(mesh, rel_mtlfilename, f)
            f.close()

            return mesh
Пример #2
0
        def apply(self, mesh, filename):
            if os.path.exists(filename):
                raise FilterException("specified filename already exists")

            z = zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED)

            basename = os.path.basename(filename)
            dotloc = basename.find('.')
            if dotloc == -1:
                dirname = basename
            else:
                dirname = basename[:dotloc]

            names_used = [dirname + '.obj']

            prev_written = []
            for cimg in mesh.images:
                img_data = cimg.data
                img_name = posixpath.basename(cimg.path)

                dotloc = img_name.find('.')
                if dotloc == -1:
                    base_img_name = img_name
                    img_ext = ''
                else:
                    base_img_name = img_name[:dotloc]
                    img_ext = img_name[dotloc:]

                while base_img_name + img_ext in names_used:
                    base_img_name = base_img_name + 'x'

                img_path = "%s/%s%s" % (dirname, base_img_name, img_ext)
                if img_path not in prev_written:
                    z.writestr(img_path, img_data)
                    prev_written.append(img_path)

                cimg.path = "./%s%s" % (base_img_name, img_ext)

            mtl_data = StringIO()
            save_obj_util.write_mtl(mesh, mtl_data)
            z.writestr("%s/%s.mtl" % (dirname, dirname), mtl_data.getvalue())
            mtl_data.close()

            obj_data = StringIO()
            save_obj_util.write_obj(mesh, "%s.mtl" % (dirname), obj_data)
            z.writestr("%s/%s.obj" % (dirname, dirname), obj_data.getvalue())
            obj_data.close()

            z.close()

            return mesh
Пример #3
0
        def apply(self, mesh, filename):
            if os.path.exists(filename):
                raise FilterException("specified filename already exists")

            z = zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED)

            basename = os.path.basename(filename)
            dotloc = basename.find('.')
            if dotloc == -1:
                dirname = basename
            else:
                dirname = basename[:dotloc]

            names_used = [dirname + '.obj']

            prev_written = []
            for cimg in mesh.images:
                img_data = cimg.data
                img_name = posixpath.basename(cimg.path)

                dotloc = img_name.find('.')
                if dotloc == -1:
                    base_img_name = img_name
                    img_ext = ''
                else:
                    base_img_name = img_name[:dotloc]
                    img_ext = img_name[dotloc:]

                while base_img_name + img_ext in names_used:
                    base_img_name = base_img_name + 'x'

                img_path = "%s/%s%s" % (dirname, base_img_name, img_ext)
                if img_path not in prev_written:
                    z.writestr(img_path, img_data)
                    prev_written.append(img_path)

                cimg.path = "./%s%s" % (base_img_name, img_ext)

            mtl_data = StringIO()
            save_obj_util.write_mtl(mesh, mtl_data)
            z.writestr("%s/%s.mtl" % (dirname, dirname), mtl_data.getvalue())
            mtl_data.close()

            obj_data = StringIO()
            save_obj_util.write_obj(mesh, "%s.mtl" % (dirname), obj_data)
            z.writestr("%s/%s.obj" % (dirname, dirname), obj_data.getvalue())
            obj_data.close()

            z.close()

            return mesh
Пример #4
0
        def apply(self, mesh, filename):
            if os.path.exists(filename):
                raise FilterException("Specified mesh filename already exists")

            dotloc = filename.rfind('.')
            if dotloc == -1:
                mtlfilename = filename
            else:
                mtlfilename = filename[:dotloc]
            mtlfilename += '.mtl'
            if os.path.exists(mtlfilename):
                raise FilterException("Material filename already exists")

            # Handle materials first, iterating through all materials
            fmtl = open(mtlfilename, 'w')
            save_obj_util.write_mtl(mesh, fmtl, mtlfilename)
            fmtl.close()

            f = open(filename, 'w')
            rel_mtlfilename = os.path.relpath(mtlfilename, os.path.dirname(filename))
            save_obj_util.write_obj(mesh, rel_mtlfilename, f)
            f.close()

            return mesh