def test_struct_clone(self): material_input = ColorMaterialInput(Mask=1, MaskR=0, MaskG=1, MaskB=0, MaskA=1) material_input2 = material_input.clone() self.assertEqual(material_input2.Mask, 1) self.assertEqual(material_input2.MaskR, 0) self.assertEqual(material_input2.MaskG, 1) self.assertEqual(material_input2.MaskB, 0) self.assertEqual(material_input2.MaskA, 1)
def test_new_struct_with_kwargs(self): material_input = ColorMaterialInput(Mask=1, MaskR=1, MaskG=1, MaskB=0, MaskA=1) self.assertEqual(material_input.Mask, 1) self.assertEqual(material_input.MaskR, 1) self.assertEqual(material_input.MaskG, 1) self.assertEqual(material_input.MaskB, 0) self.assertEqual(material_input.MaskA, 1)
def stereo_setup_media_assets(project_name, shot_name, video_dir, stereo=1): # 创建资产 # ---------------------------------------------- file_name = os.path.splitext(os.listdir(video_dir)[0])[0] ext = os.path.splitext(os.listdir(video_dir)[0])[1] file_name_pattern = file_name[:-2] # L # ---------------------------------------------- factory = MediaPlayerFactoryNew() media_player_L = factory.factory_create_new(config_path + project_name + "/" + shot_name + "/" + "MP_" + file_name_pattern + "_L") factory = FileMediaSourceFactoryNew() file_source_L = factory.factory_create_new(config_path + project_name + "/" + shot_name + "/" + "MF_" + file_name_pattern + "_L") file_source_L.set_property("FilePath", video_dir + "\\" + file_name_pattern + "_L" + ext) factory = MediaTextureFactoryNew() media_texture_L = factory.factory_create_new(config_path + project_name + "/" + shot_name + "/" + "MT_" + file_name_pattern + "_L") media_texture_L.set_property("MediaPlayer", media_player_L) # R # ---------------------------------------------- factory = MediaPlayerFactoryNew() media_player_R = factory.factory_create_new(config_path + project_name + "/" + shot_name + "/" + "MP_" + file_name_pattern + "_R") factory = FileMediaSourceFactoryNew() file_source_R = factory.factory_create_new(config_path + project_name + "/" + shot_name + "/" + "MF_" + file_name_pattern + "_R") file_source_R.set_property("FilePath", video_dir + "\\" + file_name_pattern + "_R" + ext) factory = MediaTextureFactoryNew() media_texture_R = factory.factory_create_new(config_path + project_name + "/" + shot_name + "/" + "MT_" + file_name_pattern + "_R") media_texture_R.set_property("MediaPlayer", media_player_R) # 创建并开始编辑sheder # ---------------------------------------------- factory = MaterialFactoryNew() material = factory.factory_create_new(config_path + project_name + "/" + shot_name + "/" + "MM_" + file_name_pattern) material.modify() # 创建材质节点 # ---------------------------------------------- from unreal_engine.classes import MaterialExpressionCustom, MaterialExpressionCustom, MaterialExpressionTextureSample, MaterialExpressionLinearInterpolate texture_sample_node_L = MaterialExpressionTextureSample('', material) texture_sample_node_R = MaterialExpressionTextureSample('', material) texture_sample_node_L.Texture = ue.get_asset(media_texture_L.get_path_name()) texture_sample_node_R.Texture = ue.get_asset(media_texture_R.get_path_name()) custom_node = MaterialExpressionCustom("", material) custom_node.Code = "return ResolvedView.StereoPassIndex;" custom_node.Desc = "0:right, 1:left" custom_node.OutputType = 0 lerp_node = MaterialExpressionLinearInterpolate("", material) # 连接材质节点 # ---------------------------------------------- from unreal_engine.structs import ExpressionInput, ColorMaterialInput lerp_node.A = ExpressionInput(Expression = texture_sample_node_L) lerp_node.B = ExpressionInput(Expression = texture_sample_node_R) lerp_node.Alpha = ExpressionInput(Expression = custom_node) material.Expressions = [ texture_sample_node_R, texture_sample_node_L, custom_node, lerp_node ] # 判断是否需要做立体视频 if stereo: material.EmissiveColor = ColorMaterialInput(Expression = lerp_node) else: material.EmissiveColor = ColorMaterialInput(Expression = texture_sample_node_L) # 结束材质编辑 # ---------------------------------------------- material.post_edit_change() material.save_package() return [media_player_L, media_player_R, file_source_L, file_source_R]
def test_new_struct(self): material_input = ColorMaterialInput() self.assertTrue('MaskR' in material_input.fields())
def test_struct_set(self): material_input = ColorMaterialInput() material_input.MaskG = 1 self.assertEqual(material_input.MaskG, 1)
material_blades_emissive.MaterialExpressionEditorX = -400 material_blades_emissive.MaterialExpressionEditorY = 400 # create the OcclusionRoughnessMetallic node material_blades_orm = MaterialExpressionTextureSample('', material_blades) material_blades_orm.Texture = slicer_blade_texture_orm # force the sampler to 'LinearColor' (remember you turned off sRGB) material_blades_orm.SamplerType = EMaterialSamplerType.SAMPLERTYPE_LinearColor material_blades_orm.MaterialExpressionEditorX = -400 material_blades_orm.MaterialExpressionEditorY = 600 # assign nodes to the material material_blades.Expressions = [material_blades_base_color, material_blades_normal, material_blades_emissive, material_blades_orm] # link nodes material_blades.BaseColor = ColorMaterialInput(Expression=material_blades_base_color) # normals are vectors material_blades.Normal = VectorMaterialInput(Expression=material_blades_normal) material_blades.EmissiveColor = ColorMaterialInput(Expression=material_blades_emissive) # use masking for orm nodes, it turns on/off specific channels, all of the items are scalars material_blades.Roughness = ScalarMaterialInput(Expression=material_blades_orm, Mask=1, MaskG=1) material_blades.Metallic = ScalarMaterialInput(Expression=material_blades_orm, Mask=1, MaskB=1) material_blades.AmbientOcclusion = ScalarMaterialInput(Expression=material_blades_orm, Mask=1, MaskR=1) # run material compilation material_blades.post_edit_change() from unreal_engine.classes import MaterialExpressionSine, MaterialExpressionMultiply, MaterialExpressionTime from unreal_engine.structs import ExpressionInput # turn sRGB off for orm textures
time = MaterialExpressionTime('', mat) time.MaterialExpressionEditorX = -1200 time.MaterialExpressionEditorY = 0 multiply = MaterialExpressionMultiply('', mat) multiply.MaterialExpressionEditorX = -800 multiply.MaterialExpressionEditorY = 0 mat.Expressions = [sample_base_color, sample_emissive, sample_normal, sample_orm, time, sine, multiply] sine.Input = ExpressionInput(Expression=time) multiply.A = ExpressionInput(Expression=sample_emissive) multiply.B = ExpressionInput(Expression=sine) mat.BaseColor = ColorMaterialInput(Expression=sample_base_color) mat.EmissiveColor = ColorMaterialInput(Expression=multiply) mat.Normal = VectorMaterialInput(Expression=sample_normal) mat.Roughness = ScalarMaterialInput(Expression=sample_orm, Mask=1, MaskG=1) mat.Metallic = ScalarMaterialInput(Expression=sample_orm, Mask=1, MaskB=1) mat.AmbientOcclusion = ScalarMaterialInput(Expression=sample_orm, Mask=1, MaskR=1) # run material compilatiom mat.post_edit_change() # re-save it mat.save_package() # import the animation anim_factory = PyFbxFactory()