[UE5.3.2][Cloth][Python]UE5.3でClothがPythonでどこまでさわれるかの調査

https://docs.unrealengine.com/5.3/en-US/PythonAPI/search.html?q=Cloth

より抜粋して調査。


★★★unreal.SkeletalMesh★★★

  • cloth_lod_bias_mode(クロスLODBiasMode): [読み取り/書き込み]
  • mesh_clothing_assets(配列[ Cloth ingAssetBase]): [読み取り/書き込み]

is_section_using_cloth ( Section_index , check_corresponding_sections = True ) → bool_

提供されたセクションが APEXクロスを使用しているかどうかを確認します。 bCheckCorrespondingSections が true の場合、無効なセクションは、クロスが使用されているかどうかを確認するために対応するセクションを延期します (クロス以外のセクションは無効になり、クロスが有効な場合は別のセクションが追加されます。このフラグを使用すると、元のセクションのチェックが成功します)。

プロパティ Mesh_clothing_assets :なし _

[読み書き]タイプ:(配列ClothingAssetBase ])

★★★unreal.SkeletalMeshComponent★★★


allow_cloth_actors(bool): [読み取り/書き込み] クロス シミュレーションの作成を切り替えます。オフの場合、シミュレーション ステップをスキップするだけでなく、アクターの割り当てを完全に回避する点で、以下のシミュレーション トグルとは異なります。


cloth_blend_weight(浮動小数点): [読み取り/書き込み] シミュレーション結果とキーフレーム位置の間でブレンドするウェイト。ウェイトが 1.0 の場合、クロス シミュレーション結果のみが表示され、0.0 の場合はスキンされた結果のみが表示されます。

cloth_max_distance_scale(浮動小数点): [読み取り/書き込み]

clothing_simulation_factory(type(Class)): [読み取り-書き込み] を担当するオブジェクトのクラス


disable_cloth_simulation(bool): [読み取り/書き込み] クロス シミュレーションを無効にし、シミュレーションなしでオリジナルのアニメーションを再生します。


update_cloth_in_editor(bool): [読み取り/書き込み] true の場合、エディターでクロスを再生します


wait_for_parallel_cloth_task(bool): [読み取り/書き込み] クロス シミュレーションが完了するまで、クロス ティック タスクを停止するかどうか。これは、ゲーム スレッド上で最新のクロス データが必要な場合、たとえばクロスの頂点でパーティクルを生成したい場合に必要です。


▶プロパティ allow_cloth_actors : bool
[読み取り/書き込み] クロスシミュレーションの作成を切り替えます。オフの場合、シミュレーション ステップをスキップするだけでなく、アクターの割り当てを完全に回避する点で、以下のシミュレーション トグルとは異なります。


binding_cloth_to_leader_pose_component ( ) → なし
このコンポーネントに有効な LeaderPoseComponent がある場合、この関数は、個別にシミュレーションするのではなく、フォロワー コンポーネントのクロス アイテムにリーダー コンポーネントのクロス アイテムの変換を適用させます。注: これにより、リーダー コンポーネント上のすべてのクロス アクタがローカル スペースでシミュレートされます。また、クロスを正しくバインドするには、コンポーネントで使用されるメッシュが同一である必要があります。


binding_cloth_to_master_pose_component ( ) → なし
非推奨: 「bind_cloth_to_master_pose_component」は「bind_cloth_to_leader_pose_component」に名前変更されました。


▶プロパティ cloth_blend_weight : float
[読み取り/書き込み] シミュレーション結果とキーフレーム位置をブレンドするウェイト。ウェイトが 1.0 の場合、クロス シミュレーション結果のみが表示され、0.0 の場合はスキンされた結果のみが表示されます。


▶プロパティ cloth_max_distance_scale : float


▶プロパティ disable_cloth_simulation : bool
[読み取り/書き込み] クロスシミュレーションを無効にし、シミュレーションなしでオリジナルのアニメーションを再生します


Force_cloth_next_update_teleport ( ) → なし


UpdateClothState への次の呼び出し中に強制的に「テレポート」する必要があることを示すために使用されます。これにより位置と速度が変換され、シミュレーション状態が維持され、新しいポーズに変換されるだけです。


force_cloth_next_update_teleport_and_reset ( ) → なし


UpdateClothState への次回の呼び出し中に「テレポートとリセット」を強制する必要があることを示すために使用されます。これは、悪い状態からリセットしたり、古い状態が重要でなくなった場合にテレポートによってリセットしたりするために使用できます。


get_allow_cloth_actors ( ) → bool
許可されたクロス アクターを取得する

get_cloth_max_distance_scale ( ) → float
衣服メッシュの頂点の最大距離スケールを取得/設定します


get_clothing_simulation_interactor ( ) → ClothingSimulationInteractor
現在のシミュレーションがランタイム インタラクションをサポートしている場合は、衣服シミュレーションの現在のインタラクターを取得します。


is_clothing_simulation_suspended ( ) → bool
服装シミュレーションが現在一時停止されているかどうかを取得します。


unbind_cloth_from_master_pose_component ( restore_simulation_space : bool = True ) → なし
非推奨: 「unbind_cloth_from_master_pose_component」は「unbind_cloth_from_leader_pose_component」に名前変更されました。

▶プロパティ wait_for_Parallel_cloth_task : bool

[読み取り/書き込み] クロス シミュレーションが完了するまで、クロス ティック タスクを停止するかどうか。これは、ゲーム スレッド上で最新のクロス データが必要な場合、たとえばクロスの頂点でパーティクルを生成したい場合に必要です。

★★★unreal.ChaosClothComponent★★★ 

  
▶プロパティ cloth_asset : ChaosClothAsset


get_cloth_asset ( ) → ChaosClothAsset
このコンポーネントで使用されるクロス アセットを取得します。


set_cloth_asset ( clothes_asset ) → なし

このコンポーネントで使用されるクロス アセットを設定します。

★★★unreal.ClothingSimulationInteractor★★★


clothes_config_updated ( ) → なし

シミュレーションを再起動せずにクロス構成を更新するために呼び出されます。


★★★unreal.ClothingAssetCommon★★★


ソルバー固有の実装では、このクラスをオーバーライドして、c Cloth SimConfig や c CustomData などの子クラスの独自のデフォルト インスタンスを構築したり、c AddNewLod() ファクトリをオーバーライドして c UClothLODDataBase の独自の実装を構築したりすることができます。


▶プロパティ cloth_configs :なし
[読み取り専用] シミュレーション固有の布パラメータ。 GetClothConfig() を使用して、目的の布地シミュレーション システムの正しいパラメータ/構成タイプを取得します。

タイプ:
(マップ[名前,クロスConfigBase ])
エディターのプロパティ: (get_editor_property/set_editor_property を参照)

cloth_configs(Map[Name, Cloth ConfigBase]): [読み取り専用] シミュレーション固有のクロス パラメータ。 GetClothConfig() を使用して、目的の布地シミュレーション システムの正しいパラメータ/構成タイプを取得します。

imported_file_path(str): [読み取り専用] このアセットがファイルからインポートされた場合、これが元のパスになります

physics_asset(PhysicsAsset): [読み取り/書き込み] シミュレーションを構築するときに衝突を抽出する物理アセット。

★★★例えばSampleコードを書いてみる★★★

unreal.SkeletalMesh.disable_cloth_simulation=True#クロス シミュレーション計算を有効に
unreal.SkeletalMesh.allow_cloth_actors=True#クロスシミュレーション作成Createへ切替え
mesh_clothing_list = unreal.SkeletalMesh.mesh_clothing_assets

・「Add Clothing」ボタンでも基本的に別のメッシュのClothingDataをApplayすると、Apply時に、Failed Bind Cloth Assetでエラーがでます。
E:/SandBox/jennie9UE532/jennie9UE532/Content/Developers/notsuka/EUB_ClothTool_AssetAction.uasset
・Mesh Clothing Assetsの配列のコピーというより参照変えはできましたが、そのあとApplyすると

Failed to bind clothing asset
Plane_Clothing_O_myCloth as the provided mesh is not the owner of this asset.
衣類アセットのバインドに失敗しました
Plane_Clothing_O_myCloth は、提供されたメッシュとしてこのアセットの所有者ではありません。


となりました。

・現存の「Add Clothing」ボタンと変わらないかそれ以下な結果となりました。
・また配列を参照変えでなくコピーにできないかも研究しましたが今回の「Mesh Clothing Assets」の型が「Add To Variable(変数化)」できない部分が問題でコピーできませんでした。

[UnrealEngine] PythonでGet All Collision Presets

DefaultEngine.iniに記載されているので無理やり読む

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import codecs


project_config_dir=unreal.Paths.project_config_dir()
#D:\MOSAProduct\MOSAProduct\Config\DefaultEngine.ini
DefaultEngineINI_Path=project_config_dir+"DefaultEngine.ini"
print("DefaultEngineINI_Path="+DefaultEngineINI_Path)
#fout = codecs.open('sjis.txt', 'w', 'shift_jis')

import re
def get_CollisionProfileNameStr(content):
    #m = re.search('"(.*)".*', content)
    result = re.findall('"(.*?)"', content)
    print("result[0]="+str(result[0]))
    #print("result[1]="+str(result[1]))
    return str(result[0])

CollisionProfileStrArr=[]
for line in codecs.open(DefaultEngineINI_Path, 'r', 'utf_8'):
    #fout.write(line)
    #print(line)
    if("-Profiles=(Name=" in line):
        ProfilesName=get_CollisionProfileNameStr(line)
        CollisionProfileStrArr.append(ProfilesName)
    if("+Profiles=(Name=" in line):
        ProfilesName=get_CollisionProfileNameStr(line)
        CollisionProfileStrArr.append(ProfilesName)
        
print("-----------------------Do Unique-----------------------------")
CollisionProfileStrSet = set(CollisionProfileStrArr)
CollisionProfileStrArr = list(CollisionProfileStrSet)
CollisionProfileStrArr.sort()
CollisionProfileStrArrBuildCSV=""
for CollisionProfileStr in CollisionProfileStrArr:
    print("CollisionProfileStr="+CollisionProfileStr)
    CollisionProfileStrArrBuildCSV=CollisionProfileStrArrBuildCSV+","+CollisionProfileStr

print("CollisionProfileStrArrBuildCSV="+CollisionProfileStrArrBuildCSV)

[Unreal Engine]複数のカメラのスクリーンショットを自動的に撮るPython

複数のカメラのスクリーンショットを自動的に撮るPython

Log Python: Automation Library: Failed to convert parameter ‘camera’ when calling function ‘AutomationBlueprintFunctionLibrary.TakeHighResScreenshot’ on ‘Default__AutomationBlueprintFunctionLibrary’ TypeError: NativizeProperty: Cannot nativize ‘SceneCaptureActor’ as ‘Camera’ (ObjectProperty) TypeError: NativizeObject: Cannot nativize ‘SceneCaptureActor’ as ‘Object’ (allowed Class type: ‘CameraActor’)

IS FIX Code

import unreal
import time

class OnTick(object):
  """ Register a function and run it on tick, """
  def __init__(self):
    # make a generator function so we can call next on it,
    
    EditorLevelLibrary = unreal.EditorLevelLibrary()
    all_level_actors=EditorLevelLibrary.get_all_level_actors()
    CameraActors=[]
    for actor in all_level_actors:
        #CameraBool=actor.find_camera_component_when_view_target
        CameraComponent=actor.get_component_by_class(unreal.CameraComponent)
        #print("CameraComponent="+str(CameraComponent))
        #className=CameraComponent.get_class() 
        #print("CameraComponent.get_class() ="+str(className))
        if(str(CameraComponent)=="None"):
            pass
        else:
            #if(str(CameraComponent) in "CineCameraComponent"):
            #    pass
            #else: 
            CameraActors.append(actor)
    
    self.CameraActors=CameraActors
    #self.actors = (actor for actor in unreal.EditorLevelLibrary.get_selected_level_actors())
    self.actors = iter(CameraActors)
    
    self.tickcount=0
    self.CapturedCount=0
    # register a callback on tick
    self.on_tick = unreal.register_slate_post_tick_callback(self.__tick__)
    
    
  def __tick__(self, deltatime):
    """ Function we will call every tick, """
    try:
      print(deltatime) # Print the deltatime just for sanity check so we
      # know a tick was made,
        
      # Get the next actor from our generator function,
      actor = next(self.actors)
      """
      actor_location = actor.get_actor_location()
      actor_rotation = actor.get_actor_rotation() 
      # Solve the camera position, and rotation
      position = actor_location + unreal.Vector(0.0, 0.0, 0.0)

      # roll(z), pitch(tate), yaw(yoko)
      rotation = unreal.Rotator(actor_rotation.roll+0.0, actor_rotation.pitch+5.0,actor_rotation.yaw+0.0)
      
      unreal.EditorLevelLibrary.set_level_viewport_camera_info(
        position,
        rotation
      )
      """
      errorBool=False
      try:
          CameraComponent=actor.get_component_by_class(unreal.CameraComponent)
          print("actor= "+str(actor))
          print("CameraComponent= "+str(CameraComponent))
          unreal.AutomationLibrary.take_high_res_screenshot(
            1920,
            1080,
            str(self.CapturedCount)+"_"+actor.get_name() + ".hdr",
            camera=actor,
            capture_hdr=True,
            comparison_tolerance=unreal.ComparisonTolerance.HIGH
          )
          errorBool=False
          
      except Exception as error:
          errorBool=True
          pass
      
      if(errorBool==False):
          # Count
          self.CapturedCount=self.CapturedCount+1
      """
      unreal.EditorLevelLibrary.pilot_level_actor(actor)
      unreal.EditorLevelLibrary.editor_set_game_view(True)
      # Take the screenshot,
      unreal.AutomationLibrary.take_high_res_screenshot(
        1920,
        1080,
        actor.get_name() + ".hdr",
        camera=actor,
        capture_hdr=True,
        comparison_tolerance=unreal.ComparisonTolerance.HIGH,
        delay=0.25
      )
      
      unreal.EditorLevelLibrary.eject_pilot_level_actor()
      """
      # Count
      self.tickcount=self.tickcount+1
      
      CameraActors=self.CameraActors
      CameraActorsLen=len(CameraActors)
      endActor=CameraActors[CameraActorsLen-1]
      print("self.tickcount="+str(self.tickcount)+"  :CameraActorsLen="+str(CameraActorsLen))
      if(str(self.tickcount)==str(CameraActorsLen)):
          print("finish")
          unreal.unregister_slate_post_tick_callback(self.on_tick)
      
    except Exception as error:
      #pass
      print(error)
      try:
          unreal.unregister_slate_post_tick_callback(self.on_tick)
      except Exception as error:
          pass
#if __name__ == '__main__':
instance = OnTick()

関連URL

https://forums.unrealengine.com/t/python-api-highrescreenshot/132783/10

https://docs.unrealengine.com/5.1/en-US/PythonAPI/class/EditorLevelLibrary.html

https://docs.unrealengine.com/5.0/en-US/PythonAPI/class/AutomationLibrary.html

https://docs.unrealengine.com/5.1/en-US/taking-screenshots-in-unreal-engine/

https://docs.unrealengine.com/4.26/en-US/BlueprintAPI/Utilities/Struct/MakeAutomationScreenshotOptions/