Esempio n. 1
0
    def get_avatar_objects_from_its_root(self, child_object):
        """
            オブジェクトからルートオブジェクトを取得して、
            mdobjectsに格納する。
        """
        fjw.deselect()
        root = fjw.get_root(child_object)

        mdobj = self.find_mdobj_by_object(root)
        if mdobj is not None:
            return mdobj

        fjw.activate(root)
        rootname = re.sub("\.\d+", "", root.name)
        bpy.ops.fujiwara_toolbox.command_24259()  #親子選択
        selection = fjw.get_selected_list()

        #selectionの中にMESHオブジェクトがなかったら除外する
        mesh_found = False
        for obj in selection:
            if obj.type == "MESH":
                mesh_found = True
        if not mesh_found:
            return None

        mdobj = MDObject(rootname, selection)
        self.mdobjects.append(mdobj)

        return mdobj
    def execute(self,context):
        fjw.reject_notmesh()

        canvases = []
        targets = []
        #カスタムプロパティをチェック
        for obj in fjw.get_selected_list():
            if "canvas" in obj:
                canvases.append(obj)
                continue
            if "asset" in obj:
                targets.append(obj)
                continue

        #カンバス群にパッシブ追加
        fjw.deselect()
        fjw.activate(canvases[0])
        fjw.select(canvases)
        bpy.ops.rigidbody.objects_add(type='PASSIVE')

        #ターゲット群にアクティブ追加
        fjw.deselect()
        fjw.activate(targets[0])
        fjw.select(targets)
        bpy.ops.rigidbody.objects_add(type='ACTIVE')

        #アニメーション再生
        bpy.ops.screen.frame_jump()
        bpy.ops.screen.animation_play()

        #self.report({"INFO"},"")
        pass
        return {"FINISHED"}
    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
 def dup(self, obj):
     fjw.mode("OBJECT")
     fjw.deselect()
     obj.select = True
     bpy.ops.object.duplicate()
     selection = fjw.get_selected_list()
     return selection[0]
Esempio n. 5
0
def gen_bevelcurve_all_strokes(depth):
        fjw.deselect()
        color = (1,1,1)
        while color:
            color, fill_color = extract_stroke_to_new_layer()
            if color:
                bpy.ops.gpencil.convert(type='CURVE', use_timing_data=True)
                bpy.ops.gpencil.layer_remove()
                selection = fjw.get_selected_list()
                for obj in selection:
                    curve_set_bevel(obj, depth, color)
                    fjw.deselect()
        bpy.ops.gpencil.layer_remove()
Esempio n. 6
0
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)
Esempio n. 7
0
    def execute(self, context):
        fjw.reject_notmesh()

        canvases = []
        targets = []
        #カスタムプロパティをチェック
        for obj in fjw.get_selected_list():
            if "canvas" in obj:
                canvases.append(obj)
                continue
            if "asset" in obj:
                targets.append(obj)
                continue

        fjw.select(canvases)
        fjw.select(targets)

        bpy.ops.rigidbody.objects_remove()

        #self.report({"INFO"},"")
        pass
        return {"FINISHED"}
Esempio n. 8
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
Esempio n. 9
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)
Esempio n. 10
0
 def export_selected_mdavatar(self, run_simulate=False):
     selection = fjw.get_selected_list()
     self.export_mdavatar(selection, run_simulate)