Profile Picture

Can not change weights on multiple texture channels

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

Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)

Group: Forum Members
Last Active: 5 Years Ago
Posts: 31, Visits: 143
Here is a code to show the issue I'm having. To test it, you want to put some image named "image.jpg" to the same folder as the script, it will be used as texture.

import os, time, math, random, RLPy, PySide2, copy
from winreg import *
from PySide2 import *
from PySide2.QtWidgets import *
from PySide2.QtQuickWidgets import QQuickWidget
from PySide2.QtQuick import QQuickView
from PySide2.QtCore import QUrl
from PySide2.QtCore import QObject
from PySide2.shiboken2 import wrapInstance

cwd = os.path.dirname(os.path.realpath(__file__))

Registry = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
RawKey = OpenKey(Registry, r"SOFTWARE\Reallusion\iClone\7.0")
ic_template_path = os.path.abspath(QueryValueEx(RawKey, "Template Data" )[0])

def findObj(name, type = RLPy.EObjectType_Prop):
    obj = RLPy.RScene.FindObject(type, name)
    if obj == None:
        print("object '{}' is not found on the scene".format(name))
    return obj  
   
def loadObj(path):
  global ic_template_path
  full_path = ic_template_path + path
  status = RLPy.RFileIO.LoadFile(full_path)
  if status != RLPy.RStatus.Success:
     print("object '{}' is not found".format(full_path))
     return 0
  return 1   
 
def getControl(obj, name):
  control = obj.GetControl(name)
  if control == None:
     print("control '{}' for object '{}' is not found".format(name, obj))
  return control  

def setTexture(mat_comp, mesh_name, mat_name, channel, file):
    global cwd
    full_path = cwd + file
    result = mat_comp.LoadImageToTexture(mesh_name, mat_name, channel, full_path)
    if result != RLPy.RStatus.Success:
        print("LoadTexture '{}' failed".format(full_path))   

class Prop():
    def __init__(self, name, path):
        self.name = name
        self.path = path
        self.key = RLPy.RKey()
        self.key.SetTime(RLPy.RTime(0))
        self.obj = None
        self.tsc = None
        self.dbl = None
    def link(self):
        self.obj = findObj(self.name)
        mesh_list = self.obj.GetMeshNames()
        self.mesh_name = mesh_list[0]
        self.mat_comp = self.obj.GetMaterialComponent()
        mat_list = self.mat_comp.GetMaterialNames(self.mesh_name)
        self.mat_name = mat_list[0]
    def setup(self):
        if self.obj != None:
          self.tsc = getControl(self.obj, "Transform")
          if self.tsc != None:
              self.dbl = self.tsc.GetDataBlock()
    def texturise(self):
        if self.obj != None:
            setTexture(self.mat_comp, self.mesh_name, self.mat_name, \
            RLPy.EMaterialTextureChannel_Diffuse, "\\image.jpg")
            setTexture(self.mat_comp, self.mesh_name, self.mat_name, \
            RLPy.EMaterialTextureChannel_DiffuseBlend, "\\image.jpg")
            setTexture(self.mat_comp, self.mesh_name, self.mat_name, \
            RLPy.EMaterialTextureChannel_Glow, "\\image.jpg")
    def load(self):
        if loadObj(self.path):
            self.link()
            self.setup()  
            self.texturise()

prop = None           
           
def create(event):
    global prop
    prop = Prop("Box_001", "\\iClone Template\\Props\\3D Blocks\\Box_001.iProp")
    prop.load()
           
def test(event):
    global prop
    prop.mat_comp.AddTextureWeightKey(prop.key, prop.mesh_name, prop.mat_name, RLPy.EMaterialTextureChannel_Diffuse, 0.92)
    prop.mat_comp.AddTextureWeightKey(prop.key, prop.mesh_name, prop.mat_name, RLPy.EMaterialTextureChannel_Glow, 0.23)
    prop.mat_comp.AddTextureWeightKey(prop.key, prop.mesh_name, prop.mat_name, RLPy.EMaterialTextureChannel_DiffuseBlend, 0.46)
   
def test2(event):
    global prop
    prop.mat_comp.AddTextureWeightKey(prop.key, prop.mesh_name, prop.mat_name, RLPy.EMaterialTextureChannel_Diffuse, 0.92)  
      
rl_dialog = RLPy.RUi.CreateRDialog()
rl_dialog.SetWindowTitle("Dialog")
pyside_dialog = wrapInstance(int(rl_dialog.GetWindow()), QtWidgets.QDialog)

pyside_layout = pyside_dialog.layout()

def addButton(title):
   global pyside_layout
   widget_button = QtWidgets.QPushButton(title)
   pyside_layout.addWidget(widget_button)
   return widget_button

button_start = addButton("CREATE")
button_test = addButton("TEST") 
button_test2 = addButton("TEST2")

button_start.mousePressEvent = create
button_test.mousePressEvent = test
button_test2.mousePressEvent = test2

rl_dialog.Show()


First, you press "CREATE" to make a textured cube with Diffuse, Blend and Glow channels.
The problem is with the function test (assigned to button "TEST").

def test(event):
    global prop
    prop.mat_comp.AddTextureWeightKey(prop.key, prop.mesh_name, prop.mat_name, RLPy.EMaterialTextureChannel_Diffuse, 0.92)
    prop.mat_comp.AddTextureWeightKey(prop.key, prop.mesh_name, prop.mat_name, RLPy.EMaterialTextureChannel_Glow, 0.23)
    prop.mat_comp.AddTextureWeightKey(prop.key, prop.mesh_name, prop.mat_name, RLPy.EMaterialTextureChannel_DiffuseBlend, 0.46)


For some reason, only the last channel will change its weight, in this case Blend. If you shuffle the order, whichever is the last one will change weight and others won't.

On the other hand, if you only have one call to AddTextureWeightKey as in the function test2 (assigned to button "TEST2"), it will always work.
So, if you press CREATE and then TEST, Diffuse channel will not change weight, if you then press TEST2 - it will.



https://forum.reallusion.com/uploads/images/89636428-fa5f-497a-a394-ebf0.pngaCuteMissFortune
Edited
5 Years Ago by alikims
The-any-Key
The-any-Key
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (2.8K reputation)Distinguished Member (2.8K reputation)Distinguished Member (2.8K reputation)Distinguished Member (2.8K reputation)Distinguished Member (2.8K reputation)Distinguished Member (2.8K reputation)Distinguished Member (2.8K reputation)Distinguished Member (2.8K reputation)Distinguished Member (2.8K reputation)

Group: Forum Members
Last Active: 3 Weeks Ago
Posts: 356, Visits: 1.9K
Report it in the feedback tracker. Sounds like a bug.



iClone 7, 3DXchange 7 Pipeline, CC3 Pipeline, CT8 Pipeline, Iray, Live Face, iPhone Xr, Win 10, i9 9900K ~5GHz, Nvidia RTX 2080 8GB, 16GB Ram, M.2 SSD
alikims
alikims
Posted 5 Years Ago
View Quick Profile
Senior Member

Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)Senior Member (410 reputation)

Group: Forum Members
Last Active: 5 Years Ago
Posts: 31, Visits: 143
This is a very experimental api...


https://forum.reallusion.com/uploads/images/89636428-fa5f-497a-a394-ebf0.pngaCuteMissFortune



Reading This Topic