Exemple #1
0
def add_drawing_curve(name, color, bvel_depth):
    bpy.context.scene.tool_settings.curve_paint_settings.curve_type = 'POLY'
    bpy.context.scene.tool_settings.curve_paint_settings.use_pressure_radius = True
    bpy.context.scene.tool_settings.curve_paint_settings.radius_min = 0
    bpy.context.scene.tool_settings.curve_paint_settings.radius_max = 1
    bpy.context.scene.tool_settings.curve_paint_settings.depth_mode = 'SURFACE'
    bpy.context.scene.tool_settings.curve_paint_settings.surface_offset = 1
    bpy.context.scene.tool_settings.curve_paint_settings.use_offset_absolute = False
    bpy.context.scene.tool_settings.curve_paint_settings.use_stroke_endpoints = False

    for obj in bpy.context.visible_objects:
        if name in obj.name:
            return obj

    bpy.ops.curve.primitive_bezier_curve_add(radius=1, view_align=False, enter_editmode=False, location=(0, 0, 0), layers=bpy.context.scene.layers)
    curve = fjw.active().data
    fjw.active().name = name
    curve.fill_mode = "FULL"
    curve.bevel_depth = bvel_depth

    curve.show_handles = False
    curve.show_normal_face = False

    mat = bpy.data.materials.new(name)
    mat.use_shadeless = True
    mat.diffuse_color = color
    mat.use_cast_shadows = False
    curve.materials.append(mat)

    fjw.mode("EDIT")
    bpy.ops.curve.select_all(action='SELECT')
    bpy.ops.curve.dissolve_verts()
    fjw.mode("OBJECT")

    return fjw.active()
Exemple #2
0
    def armature_autokey(cls):
        """
        アーマチュアのキーをオートで入れる
        """
        if fjw.active().type != "ARMATURE":
            return

        fjw.mode("POSE")

        #アーマチュアのキーをオートで入れる
        if bpy.context.scene.frame_current == cls.last_frame:
            rootname = fjw.get_root(fjw.active()).name

            fjw.active().location = Vector((0, 0, 0))

            cls.setkey()

            #フレーム10なら微調整じゃないのでオートフレーム。
            armu = fjw.ArmatureUtils(fjw.active())
            geo = armu.GetGeometryBone()
            armu.clearTrans([geo])

            cls.setkey()

            fjw.framejump(1)
            selection = armu.select_all()
            armu.clearTrans(selection)

            cls.setkey()

            #選択にズーム
            bpy.ops.view3d.view_selected(use_all_regions=False)
            fjw.framejump(cls.last_frame)
    def mesh_dup(self, vertex_group=""):
        base = fjw.active()
        mode = base.mode

        fjw.mode("OBJECT")
        fjw.deselect()
        fjw.mode("EDIT")

        if vertex_group != "":
            self.mesh_deselect()
            self.select_by_vertex_group(vertex_group)

        bpy.ops.mesh.duplicate(mode=1)
        bpy.ops.mesh.separate(type='SELECTED')
        fjw.mode("OBJECT")
        for obj in fjw.get_selected_list():
            if obj != base:
                fjw.activate(obj)
                fjw.mode("EDIT")
                break
        dup = fjw.active()
        dup.data.materials.clear()
        self.clear_mods()
        # dup.parent = base
        return dup
Exemple #4
0
    def setkey(cls):
        if fjw.active().type == "ARMATURE":
            fjw.mode("POSE")
        if fjw.active().mode == "OBJECT":
            bpy.ops.anim.keyframe_insert_menu(type='LocRotScale')
        if fjw.active().mode == "POSE":
            #MarvelousDesigner用
            aau = fjw.ArmatureActionUtils(fjw.active())
            aau.set_action("mdwork")
            frame = bpy.context.scene.frame_current
            aau.store_pose(frame, "mdpose_" + str(frame))

            bpy.ops.pose.select_all(action='SELECT')
            bpy.ops.anim.keyframe_insert_menu(type='WholeCharacter')
Exemple #5
0
    def delkey(cls):
        if fjw.active().type == "ARMATURE":
            fjw.mode("POSE")
        if fjw.active().mode == "OBJECT":
            bpy.ops.anim.keyframe_delete_v3d()
        if fjw.active().mode == "POSE":
            #MarvelousDesigner用
            aau = fjw.ArmatureActionUtils(fjw.active())
            aau.set_action("mdwork")
            frame = bpy.context.scene.frame_current
            aau.delete_pose("mdpose_" + str(frame))

            bpy.ops.pose.select_all(action='SELECT')
            bpy.ops.anim.keyframe_delete_v3d()
    def __make_projector(self, name, baseobj):
        """
        プロジェクタ名はテクスチャ名を使うといいかも。
        """
        #オブジェクト作成
        # pos = (baseobj.location[0], baseobj.location[1] - 1, baseobj.location[2])
        pos = baseobj.location
        bpy.ops.mesh.primitive_plane_add(radius=1,
                                         calc_uvs=True,
                                         view_align=False,
                                         enter_editmode=False,
                                         location=pos,
                                         layers=baseobj.layers)
        projector = fjw.active()
        projector.name = "UVProjector_" + name
        projector.data.uv_textures[0].name = projector.name
        projector.hide_render = True

        #コンストレイント
        c = projector.constraints.new("DAMPED_TRACK")
        c.track_axis = "TRACK_NEGATIVE_Z"
        c.target = baseobj

        #マテリアル
        projector.data.materials.append(baseobj.active_material)

        return projector
Exemple #7
0
    def execute(self, context):
        obj = fjw.active()
        if obj is None or obj.type != "CURVE" or obj.mode != "EDIT":
            return {"CANCELLED"}

        curve = obj.data
        spline = curve.splines.active
        if spline is None:
            return {"CANCELLED"}

        for p in spline.points:
            p.select = False

        #交互に選択
        select = False
        for p in spline.points:
            p.select = select
            select = not select

        spline.points[0].select = False
        spline.points[-1].select = False
        bpy.ops.curve.dissolve_verts()

        for p in spline.points:
            p.select = True
        curve.splines.active = spline

        return {"FINISHED"}
    def make_plane(self, parent, filepath):
        dirname = os.path.dirname(filepath)
        basename = os.path.basename(filepath)
        name, ext = os.path.splitext(basename)

        texture_path = self.get_texture_path(filepath)
        if not texture_path:
            return None

        #とりあえずplaneを用意して画像をロード。計算がめんどくなるので半径0.5=直径1に。→プロジェクションでダメだった!!1でやらないと見た目があわない!
        bpy.ops.mesh.primitive_plane_add(
            radius=1,
            calc_uvs=True,
            view_align=False,
            enter_editmode=False,
            location=(0, 0, 0),
            layers=(True, False, False, False, False, False, False, False,
                    False, False, False, False, False, False, False, False,
                    False, False, False, False))
        plane = fjw.active()
        plane.name = "Projector_" + name
        plane.layers = parent.layers
        plane.data.uv_textures[0].name = plane.name

        mat = self.new_projection_mat(plane.name)
        texture = self.load_texture(mat, texture_path, plane.name)
        plane.data.materials.append(mat)
        return plane
    def execute(self, use_active_camera=False, to_active_mat=True):
        filename = os.path.basename(self.filepath)
        name, ext = os.path.splitext(filename)

        obj = fjw.active()
        current_mode = obj.mode

        if current_mode == "OBJECT":
            mat = self.__get_active_mat(obj)
        elif current_mode == "EDIT":
            self.__add_new_mat(obj)
            mat = self.__get_active_mat(obj)
            bpy.ops.object.material_slot_assign()

        fjw.mode("OBJECT")

        active_camera = bpy.context.scene.camera
        if active_camera and use_active_camera:
            projector = active_camera
        else:
            projector = self.__make_projector(name, obj)

        if to_active_mat:
            self.__add_texture_to_mat(mat, self.filepath, projector)
        else:
            for mat in obj.data.materials:
                self.__add_texture_to_mat(mat, self.filepath, projector)
        self.set_uv_projection(obj, projector)

        projector.parent = obj
 def assign_material_to_mesh(self, mat):
     obj = fjw.active()
     mode = obj.mode
     if mat.name not in obj.data.materials:
         obj.data.materials.append(mat)
     index = obj.material_slots.find(mat.name)
     obj.active_material_index = index
     fjw.mode("EDIT")
     bpy.ops.object.material_slot_assign()
     fjw.mode(mode)
def save_pre(context):
    #カメラにキー入らんでどうしようもないからこれでいれる!!!→2017/11/26 Blender2.79で修正されているのを確認
    #カメラにキー入れる
    if bpy.context.scene.tool_settings.use_keyframe_insert_auto:
        if bpy.context.scene.camera != None:
            if not fjw.in_localview():
                current = fjw.active()
                current_mode = "OBJECT"
                if current != None:
                    current_mode = fjw.active().mode
                fjw.mode("OBJECT")
                selection = fjw.get_selected_list()
                fjw.deselect()
                fjw.activate(bpy.context.scene.camera)
                bpy.ops.anim.keyframe_insert_menu(type='LocRotScale')
                if current != None:
                    fjw.deselect()
                    fjw.select(selection)
                    fjw.activate(current)
                    fjw.mode(current_mode)
    def select_by_vertex_group(self, name):
        fjw.mode("EDIT")
        #頂点グループで選択する
        obj = fjw.active()
        if name not in obj.vertex_groups:
            return False

        vg = obj.vertex_groups[name]
        vgi = obj.vertex_groups.find(name)
        obj.vertex_groups.active_index = vgi
        bpy.ops.object.vertex_group_select()
        return True
Exemple #13
0
    def gen_rig_and_reparent(self, metarig, unparent_at_rest=True):
        """
        genrigして再ペアレントする。
        """
        if metarig.type != "ARMATURE":
            return False

        layers_current = fjw.layers_current_state()
        fjw.layers_showall()

        objects_bu = fjw.ObjectsPropBackups(bpy.context.scene.objects)
        objects_bu.store("hide")
        for obj in bpy.context.scene.objects:
            obj.hide = False

        self.set_metarig(metarig)
        self.set_rig(self.find_rig())

        rig_old = None
        if self.rig:
            rig_old = self.rig
            if unparent_at_rest:
                self.rig.obj.data.pose_position = 'REST'
            self.rig.rigged_objects.parent_clear()
            rigdata = self.rig.obj.data
            fjw.delete([self.rig.obj])
            bpy.data.armatures.remove(rigdata)


        fjw.deselect()
        fjw.activate(metarig)
        bpy.ops.pose.rigify_generate()

        new_rig = Rig(fjw.active())
        if self.rig:
            new_rig.edit_bones_data.restore_info_from(self.rig.edit_bones_data)
            self.rig.rigged_objects.reset_rig(new_rig.obj)
        # bpy.ops.view3d.layers(nr=0, extend=False)
        if self.rig:
            self.rig.rigged_objects.reparent()
        # bpy.ops.view3d.layers(nr=0, extend=False)
        fjw.layers_show_list(layers_current)
        metarig.hide = True

        fjw.activate(new_rig.obj)
        fjw.mode("POSE")

        if rig_old:
            new_rig.restore_settings_from(rig_old)
        
        objects_bu.restore()

        return True
 def assign_material_by_vetexgroup(self,
                                   vertex_group,
                                   mat,
                                   deselect_axis=""):
     obj = fjw.active()
     mode = obj.mode
     fjw.mode("EDIT")
     self.mesh_deselect()
     self.select_by_vertex_group(vertex_group)
     if deselect_axis != "":
         self.deselect_by_axis(deselect_axis)
     self.assign_material_to_mesh(mat)
     fjw.mode(mode)
 def set_projection(self, projector_name, mat, find=False):
     """
     projectorを受け取ってmatのプロジェクタにする。
     """
     obj = fjw.active()
     mode = obj.mode
     fjw.mode("OBJECT")
     proj = self.get_projector(projector_name, find)
     if not proj:
         print("!:no proj:%s" % projector_name)
         #プロジェクタがなければキャンセル
         fjw.mode(mode)
         return
     ProjectionUtils.set_uv_projection(obj, proj)
     fjw.mode(mode)
     pass
Exemple #16
0
    def execute(self, context):
        bpy.context.space_data.viewport_shade = 'MATERIAL'
        fjw.mode("TEXTURE_PAINT")

        bpy.context.scene.tool_settings.unified_paint_settings.use_unified_size = False
        bpy.context.scene.tool_settings.unified_paint_settings.use_unified_strength = False
        bpy.context.scene.tool_settings.unified_paint_settings.use_unified_color = False

        brush = get_brush("消去ブラシ")
        brush.size = 15
        brush.use_pressure_size = True
        brush.use_pressure_strength = False
        brush.strength = 1
        brush.blend = 'ERASE_ALPHA'

        bpy.context.scene.tool_settings.image_paint.brush = brush

        fjw.active().show_wire = True
        return {"FINISHED"}
    def deselect_by_axis(self, axis):
        #指定した軸を選択解除する
        d = 0
        if "x" in axis:
            d = 0
        elif "y" in axis:
            d = 1
        elif "z" in axis:
            d = 2
        s = 1
        if "-" in axis:
            s = -1

        obj = fjw.active()
        bm = bmesh.from_edit_mesh(bpy.context.object.data)
        for v in bm.verts:
            if v.co[d] * s > 0:
                v.select = False
        bm.select_flush(False)
Exemple #18
0
def make_buillboard(width, height):
    loc = bpy.context.space_data.cursor_location
    bpy.ops.mesh.primitive_plane_add(radius=1,
                                     view_align=True,
                                     location=loc,
                                     layers=bpy.context.scene.layers)
    billboard = fjw.active()
    billboard.name = "ビルボード描画"

    fjw.mode("EDIT")
    bpy.ops.uv.unwrap(method='ANGLE_BASED', margin=0.001)
    fjw.mode("OBJECT")

    mat = bpy.data.materials.new("ビルボード描画")
    mat.use_shadeless = True
    mat.use_transparency = True
    mat.alpha = 0.0
    mat.use_cast_shadows = False
    mat.use_shadows = False
    tslot = mat.texture_slots.add()
    tslot.use_map_alpha = True
    tex = bpy.data.textures.new("ビルボード描画", "IMAGE")
    img = bpy.data.images.new("ビルボード描画", width, height, alpha=True)
    img.generated_color = (0, 0, 0, 0)
    tex.image = img
    tslot.texture = tex
    billboard.data.materials.append(mat)

    scale = 1024 * 2
    dim_x = width / scale
    dim_y = height / scale

    billboard.scale.x = dim_x / 2
    billboard.scale.y = dim_y / 2
    bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)

    bpy.context.space_data.viewport_shade = 'MATERIAL'

    return billboard
Exemple #19
0
    def remove_not_used_materials(self, obj):
        if obj.type != "MESH":
            return
        current = fjw.active()
        fjw.activate(obj)
        fjw.mode("OBJECT")
        used_indexes = []
        for face in obj.data.polygons:
            i = face.material_index
            if i not in used_indexes:
                used_indexes.append(i)
        print("used_indexes:" + str(used_indexes))

        used_materials = []
        for i in used_indexes:
            if i >= len(obj.material_slots):
                continue
            mat = obj.material_slots[i].material
            if mat not in used_materials:
                used_materials.append(mat)
        print(used_materials)

        delmats = []
        for m in range(len(used_materials)):
            for i in range(len(obj.material_slots)):
                mslot = obj.material_slots[i]
                print("mslot:" + str(mslot.material))
                print("in:" + str(mslot.material in used_materials))
                if mslot.material and mslot.material not in used_materials:
                    print("remove:" + str(i) + " " + str(mslot.material))
                    obj.active_material_index = i
                    bpy.ops.object.material_slot_remove()
                    delmats.append(mslot.material)
                    break
        for mat in delmats:
            if mat.users == 0:
                bpy.data.materials.remove(mat)

        fjw.activate(current)
 def clear_mods(self):
     obj = fjw.active()
     modu = fjw.Modutils(obj)
     for m in modu.mods:
         if m.type != "MIRROR" and m.type != "SUBSURF":
             modu.remove(m)
Exemple #21
0
    def setup_mdwork_main(cls, self, context):
        if "_MDWork" not in bpy.data.filepath:
            fjw.framejump(cls.last_frame)
            dir = os.path.dirname(bpy.data.filepath)
            name = os.path.splitext(os.path.basename(bpy.data.filepath))[0]
            blend_md = dir + os.sep + name + "_MDWork.blend"
            bpy.ops.wm.save_as_mainfile(filepath=blend_md)

            bpy.context.scene.layers[0] = True
            for i in range(19):
                bpy.context.scene.layers[i + 1] = False
            for i in range(5):
                bpy.context.scene.layers[i] = True

            #ポーズだけついてるやつをポーズライブラリに登録する
            for armature_proxy in bpy.context.visible_objects:
                if armature_proxy.type != "ARMATURE":
                    continue
                if "_proxy" not in armature_proxy.name:
                    continue
                fjw.deselect()
                fjw.activate(armature_proxy)
                fjw.mode("POSE")
                bpy.ops.pose.select_all(action='SELECT')
                bpy.ops.fujiwara_toolbox.set_key()
                fjw.mode("OBJECT")

            fjw.mode("OBJECT")
            bpy.ops.object.select_all(action='SELECT')

            bpy.ops.file.make_paths_absolute()
            selection = fjw.get_selected_list()
            for obj in selection:
                md_garment_path_list = cls.__get_prop(obj,
                                                      "md_garment_path_list")
                md_export_id = cls.__get_prop(obj, "md_export_id")
                md_garment_index = cls.__get_prop(obj, "md_garment_index")
                md_export_depth = cls.__get_prop(obj, "md_export_depth")

                # obj.dupli_group.library.filepath
                link_path = ""
                if obj.dupli_group is not None and obj.dupli_group.library is not None:
                    link_path = obj.dupli_group.library.filepath
                if link_path == "" or link_path is None:
                    continue

                fjw.deselect()
                fjw.activate(obj)
                bpy.ops.object.duplicates_make_real(use_base_parent=True,
                                                    use_hierarchy=True)
                realized_objects = fjw.get_selected_list()
                for robj in realized_objects:
                    robj["linked_path"] = link_path

                    root = fjw.get_root(robj)
                    if md_garment_path_list is not None:
                        root["md_garment_path_list"] = md_garment_path_list
                    if md_export_id is not None:
                        root["md_export_id"] = md_export_id
                    if md_garment_index is not None:
                        root["md_garment_index"] = md_garment_index
                    if md_export_depth is not None:
                        root["md_export_depth"] = md_export_depth

                    #garment_pathを絶対パス化する
                    if "md_garment_path_list" in robj:
                        pathlist_base = robj["md_garment_path_list"]

                        print("*" * 15)
                        print("* make garment path to abs")
                        print("*" * 15)
                        lib_dir = os.path.dirname(link_path)
                        pathlist_new = []
                        for garment_path in pathlist_base:
                            new_path = bpy.path.abspath(garment_path,
                                                        start=lib_dir)
                            pathlist_new.append(new_path)
                            print(new_path)
                        robj["md_garment_path_list"] = pathlist_new
                        print("*" * 15)

            #proxyの処理
            #同一のアーマチュアデータを使っているものを探してポーズライブラリを設定する。
            for armature_proxy in bpy.data.objects:
                if armature_proxy.type != "ARMATURE":
                    continue
                if "_proxy" not in armature_proxy.name:
                    continue

                for armature in bpy.data.objects:
                    if armature.type != "ARMATURE":
                        continue
                    if armature == armature_proxy:
                        continue

                    if armature.data == armature_proxy.data:
                        #同一データを使用している
                        #のでポーズライブラリの設定をコピーする
                        armature.pose_library = armature_proxy.pose_library

                        #回収したポーズライブラリを反映する
                        fjw.mode("OBJECT")
                        fjw.activate(armature)

                        if fjw.active() is not None:
                            aau = fjw.ArmatureActionUtils(armature)
                            armu = fjw.ArmatureUtils(armature)

                            fjw.active().hide = False
                            fjw.mode("POSE")
                            poselist = aau.get_poselist()
                            if poselist is not None:
                                for pose in aau.get_poselist():
                                    frame = int(
                                        str(pose.name).replace("mdpose_", ""))
                                    fjw.framejump(frame)

                                    #ジオメトリはゼロ位置にする
                                    geo = armu.GetGeometryBone()
                                    armu.clearTrans([geo])
                                    bpy.ops.pose.select_all(action='SELECT')
                                    armu.databone(geo.name).select = False
                                    aau.apply_pose(pose.name)
                            #1フレームではデフォルトポーズに
                            fjw.mode("POSE")
                            fjw.framejump(1)
                            bpy.ops.pose.select_all(action='SELECT')
                            bpy.ops.pose.transforms_clear()

            #proxyの全削除
            fjw.mode("OBJECT")
            prxs = fjw.find_list("_proxy")
            fjw.delete(prxs)

            # bpy.app.handlers.scene_update_post.append(process_proxy)
            bpy.context.space_data.show_only_render = False
Exemple #22
0
    def import_mdresult(cls, resultpath, attouch_fjwset=False):
        if not os.path.exists(resultpath):
            return

        current = fjw.active()

        loc = Vector((0, 0, 0))
        qrot = Quaternion((0, 0, 0, 0))
        scale = Vector((1, 1, 1))

        bonemode = False
        # ↓微妙なのでやめる
        # #もしボーンが選択されていたらそのボーンにトランスフォームをあわせる
        # if current is not None and current.mode == "POSE":
        #     armu = fjw.ArmatureUtils(current)
        #     pbone = armu.poseactive()
        #     armu.get_pbone_world_co(pbone.head)
        #     loc = armu.get_pbone_world_co(pbone.head)
        #     qrot = pbone.rotation_quaternion
        #     scale = pbone.scale
        #     print("loc:%s"%str(loc))
        #     print("qrot:%s"%str(qrot))
        #     print("scale:%s"%str(scale))

        #     #boneはYupなので入れ替え
        #     # qrot = Quaternion((qrot.w, qrot.x, qrot.z * -1, qrot.y))
        #     bonemode = True
        print("bonemode:%s" % str(bonemode))

        fjw.mode("OBJECT")

        fname, ext = os.path.splitext(resultpath)
        if ext == ".obj":
            bpy.ops.import_scene.obj(filepath=resultpath)
        if ext == ".abc":
            bpy.ops.wm.alembic_import(filepath=resultpath,
                                      as_background_job=False)
            selection = fjw.get_selected_list()
            for obj in selection:
                obj.name = "result"

        #透過を無効にしておく
        selection = fjw.get_selected_list()
        for obj in selection:
            for mat in obj.data.materials:
                mat.use_transparency = False

        #インポート後処理
        #回転を適用
        bpy.ops.object.transform_apply(location=False,
                                       rotation=True,
                                       scale=False)

        selection = fjw.get_selected_list()
        for obj in selection:
            if obj.type == "MESH":
                bpy.context.scene.objects.active = obj
                bpy.ops.object.mode_set(mode='EDIT', toggle=False)
                bpy.ops.mesh.remove_doubles()
                bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

                # #服はエッジ出ない方がいい 裏ポリで十分
                # for slot in obj.material_slots:
                #     mat = slot.material
                #     mat.use_transparency = True
                #     mat.transparency_method = 'RAYTRACE'

                obj.location = loc
                if bonemode:
                    obj.rotation_quaternion = obj.rotation_quaternion * qrot
                    obj.rotation_euler = obj.rotation_quaternion.to_euler()
                    obj.scale = scale

                #読み先にレイヤーをそろえる
                if current is not None:
                    obj.layers = current.layers

        if attouch_fjwset:
            bpy.ops.fujiwara_toolbox.command_318722()  #裏ポリエッジ付加
            # bpy.ops.fujiwara_toolbox.set_thickness_driver_with_empty_auto() #指定Emptyで厚み制御

        cls.delete_imported_files(resultpath)
Exemple #23
0
 def export_active_body_mdavatar(self, run_simulate=False):
     active = fjw.active()
     self.export_mdavatar([active], run_simulate)
    def fjw_texture_export_uvmap(cls, obj):
        """
            アクティブオブジェクトのアクティブUVマップ書き出してテクスチャ作業をする。
            
        arguments:
            オブジェクト
            
        outputs:
            アクティブUV画像を書き出し
            作業ディレクトリ/textures/uv名.png
            jsonにテクスチャパスを保存する?いらないかも
            
        既にblendファイルが存在する場合はそのblendファイルを開いて完了したい。
        
        """

        if obj.type != "MESH":
            return

        export_name = "uv_map"
        path = cls.get_exist_filepath(obj, export_name)
        if path:
            #既に存在するのでそれを開く
            bpy.ops.wm.open_mainfile(filepath=path)
            return

        fjw.activate(obj)

        # UVをチェック
        if len(obj.data.uv_layers) == 0:
            # なければUVを作成
            fjw.mode("EDIT")
            bpy.ops.mesh.select_all(action='SELECT')
            bpy.ops.uv.smart_project()

        uv_layer = obj.data.uv_layers.active

        # テクスチャ作業ファイル作成
        json = cls.make_texture_workingfile(obj, export_name)
        # if not json:
        #     return

        dirname = os.path.dirname(bpy.data.filepath)
        basename = os.path.basename(bpy.data.filepath)
        name, ext = os.path.splitext(basename)
        print("filepath:%s" % bpy.data.filepath)

        # UVテクスチャ出力先
        uv_dir = dirname + os.sep + "textures"
        if not os.path.exists(uv_dir):
            os.makedirs(uv_dir)
        uv_path = uv_dir + os.sep + name + ".png"
        print("uv_path:%s" % uv_path)
        fjw.mode("EDIT")
        bpy.ops.mesh.select_all(action='SELECT')
        bpy.ops.uv.export_layout(filepath=uv_path,
                                 check_existing=False,
                                 export_all=False,
                                 modified=False,
                                 mode='PNG',
                                 size=(1024, 1024),
                                 opacity=0.25,
                                 tessellated=False)
        fjw.mode("OBJECT")

        dellist = []
        for delobj in bpy.context.scene.objects:
            if delobj != obj:
                dellist.append(delobj)

        # 全オブジェクトを削除してUVテクスチャの読み込み
        fjw.delete(dellist)
        bpy.ops.mesh.primitive_plane_add(
            radius=1,
            calc_uvs=True,
            view_align=False,
            enter_editmode=False,
            location=(0, 0, 0),
            layers=(True, False, False, False, False, False, False, False,
                    False, False, False, False, False, False, False, False,
                    False, False, False, False))
        plane = fjw.active()
        plane.name = name

        mat = bpy.data.materials.new("uv_map")
        img = bpy.data.images.load(uv_path)
        # mat.use_shadeless = True
        # tslot = mat.texture_slots.add()
        # tex = bpy.data.textures.new("uv_map", "IMAGE")
        # tex.image = img
        # tslot.texture = tex

        plane.data.materials.append(mat)

        # 背景画像として追加
        # https://blender.stackexchange.com/questions/6101/poll-failed-context-incorrect-example-bpy-ops-view3d-background-image-add/6105#6105
        bpy.context.space_data.show_background_images = True
        for area in bpy.context.screen.areas:
            if area.type == 'VIEW_3D':
                space_data = area.spaces.active
                bg = space_data.background_images.new()
                bg.image = img
                bg.size = 2
                bg.draw_depth = "FRONT"
                bg.view_axis = "TOP"
                break

        #SUN追加
        bpy.ops.object.lamp_add(type='SUN',
                                radius=1,
                                view_align=False,
                                location=(0, 0, 1),
                                layers=(True, False, False, False, False,
                                        False, False, False, False, False,
                                        False, False, False, False, False,
                                        False, False, False, False, False))

        bpy.ops.wm.save_as_mainfile()