Profile Picture

Avatar Opacity Setting not working

Posted By videodv 5 Years Ago
You don't have permission to rate!
Author
Message
videodv
videodv
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 342, Visits: 12.0K
Hi

I am trying out a script to set all an avatars materials opacity settings to zero but I have come up against this error <class 'TypeError'>, File: C:\Program Files\Reallusion\iClone 7\Bin64\RLPy.py, Line: 8452
When I have seen this in the past it is pointing to not being implemented yet in the API but RL has some test code that sets the opacity so whats going on anyone have an idea?
Here is the code I am trying with Jade as a test avatar.

import RLPy

# Get Avatar mesh and Material
avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
material_component = avatar.GetMaterialComponent()
mesh_list = avatar.GetMeshNames()
mesh_name = mesh_list[0]
material_list = material_component.GetMaterialNames(mesh_name)

for mesh in mesh_list:
    print("****************")
    print("Mesh List: {} ".format(mesh))
    material_list = material_component.GetMaterialNames(mesh)    
    for mat in material_list:
        print("Mat: {} ".format(mat))
        # Set Materials Invisable here NOT WORKING ??????
        material_component.AddOpacityKey(0, mesh, mat, 0)       
        print("Opacity Value: {} ".format(material_component.GetOpacity(mesh, mat))) # This works
    
print("Finished...")

This will print out the opacity setting for the correct material if you change it manually.

Chris
Kelleytoons
Kelleytoons
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 9.1K, Visits: 21.8K
Chris,

I change opacity on materials all the time, so it's most likely something wrong in your code somewhere.  I'm about ready to eat, but if Any Key doesn't beat me to it I'll post something that does work after that.



Alienware Aurora R12, Win 10, i9-119000KF, 3.5GHz CPU, 128GB RAM, RTX 3090 (24GB), Samsung 960 Pro 4TB M-2 SSD, TB+ Disk space
Mike "ex-genius" Kelley
videodv
videodv
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 342, Visits: 12.0K
Kelleytoons (3/31/2019)
Chris,

I change opacity on materials all the time, so it's most likely something wrong in your code somewhere.  I'm about ready to eat, but if Any Key doesn't beat me to it I'll post something that does work after that.


Hi Mike

Yup just found it forgot to add a key here is the revised code that now works.

import RLPy

# Get Avatar mesh and Material
avatar_list = RLPy.RScene.GetAvatars()
avatar = avatar_list[0]
material_component = avatar.GetMaterialComponent()
mesh_list = avatar.GetMeshNames()
mesh_name = mesh_list[0]
material_list = material_component.GetMaterialNames(mesh_name)

time_line = RLPy.RGlobal_GetTime()
R_Key = RLPy.RKey()
R_Key.SetTime(RLPy.RTime(time_line))
   
for mesh in mesh_list:
    print("****************")
    print("Mesh List: {} ".format(mesh))
    material_list = material_component.GetMaterialNames(mesh)    
    for mat in material_list:
        print("Mat: {} ".format(mat))
        # Set Materials Invisable here
        material_component.AddOpacityKey(R_Key, mesh, mat, 0)       

       
print("Finished...")

Chris

Kelleytoons
Kelleytoons
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)Distinguished Member (35.6K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 9.1K, Visits: 21.8K
Ah, ya beat me to it (but for others, here's code that works for any selected object, including avatars):

import RLPy
key = RLPy.RKey()
key.SetTime(RLPy.RTime(1200))
key.SetTransitionType(RLPy.ETransitionType_Linear)
key.SetTransitionStrength(50)
opacity = 0
selected_list = RLPy.RScene.GetSelectedObjects()
for object in selected_list:
    material_component = object.GetMaterialComponent()
    mesh_list = object.GetMeshNames()
    for mesh in mesh_list:
        material_list = material_component.GetMaterialNames(mesh)
        if not material_list:
            print ("No materials in mesh")
        else:
            for matty in material_list:
                material_component.AddOpacityKey(key, mesh, matty, opacity)
                
                
print ("Finished")




Alienware Aurora R12, Win 10, i9-119000KF, 3.5GHz CPU, 128GB RAM, RTX 3090 (24GB), Samsung 960 Pro 4TB M-2 SSD, TB+ Disk space
Mike "ex-genius" Kelley
videodv
videodv
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)Distinguished Member (2.7K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 342, Visits: 12.0K
Thanks Mike

Ya went to make a cup of tea and it just poped into my head Blink

Thanks for the update code and enjoy your meal.

Chris.

Edited
5 Years Ago by videodv



Reading This Topic