refunct-tas icon indicating copy to clipboard operation
refunct-tas copied to clipboard

MapEditor: Allow you to modify opacity of materials

Open LukeSaward opened this issue 2 years ago • 0 comments

  1. Get material from static mesh
UPrimitiveComponent::GetMaterial(int ElementIndex)
  1. Create dynamic material instance
UMaterialInstanceDynamic::Create(UMaterialInterface* ParentMaterial, UObject* InOuter)
  1. Set scalar parameter value of the material
let fun2: extern_fn!(fn( this: *const c_void, name: FName, value: f32 ))
    = unsafe { mem::transmute(UMATERIALINSTANCEDYNAMIC_SETSCALARPARAMETERVALUE.load(Ordering::SeqCst)) };
fun2(obj.as_ptr() as *const c_void, FName::from("opacity"), 0.3);
  1. Set mesh's material to the dynamic material
unsafe {
    let fun2376 = mesh.class().find_function("SetMaterial").unwrap();
    let params = fun2376.create_argument_struct();
    let thingy23 = ObjectWrapper::new(thing as *mut UObject);
    params.get_field("Material").set_object(&thingy23);
    fun2376.call(mesh.as_ptr(), &params);
}

Ties into #301

LukeSaward avatar Jun 09 '23 21:06 LukeSaward