Isotropix Forums

Importing primitives and replacing them with lights

General Discussion about Isotropix and CG related topics

Importing primitives and replacing them with lights

Unread postby adamkuczek » Wed May 02, 2018 4:08 pm

Hello,

Is there a way to replace imported primitives (like numerous spheres) with e.g. point lights?

I find it easier to place my lights (or indicate where they should go) in Maya. I would like to use simple spheres for their position across the complex scene, then import them into Clarisse and replace the spheres with actual lights. I know replacement like this can be done with geometry (replacing primitives with final geo by using 'scene item cloud') but how to deal with lights? Is there a way to do it?


Cheers,
Adam
www.ak-art.net
adamkuczek
 
Posts: 31
Joined: Sat Mar 28, 2015 4:10 am
Location: Cracow, Poland

Re: Importing primitives and replacing them with lights

Unread postby dboude » Wed May 02, 2018 4:51 pm

Hi,

Yes, create a scene item cloud and list your spheres inside it. Then you can use this script : https://forum.isotropix.com/viewtopic.php?f=21&t=2529#p11122

Select the scene item cloud and execute the script. Let first frame and last frame set to zero, select your type of light and hit run in the popup windows. Et voila ;)

Cheers !
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 1506
Joined: Mon Jul 03, 2017 10:51 am

Re: Importing primitives and replacing them with lights

Unread postby adamkuczek » Wed May 02, 2018 9:11 pm

Hello, thank you for the answer but unfortunately the script doesn't seem to be working for me. It says it creates the lights and they do show up in 3D view but they don't react to any changes (intensity, radius, etc.) like other lights. Does it work with the latest version of Clarisse? (3.6 SP1)
www.ak-art.net
adamkuczek
 
Posts: 31
Joined: Sat Mar 28, 2015 4:10 am
Location: Cracow, Poland

Re: Importing primitives and replacing them with lights

Unread postby dboude » Thu May 03, 2018 8:35 am

You have the choice between legacy and physical lights on the list. Make sure you choose the right one!

Cheers
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 1506
Joined: Mon Jul 03, 2017 10:51 am

Re: Importing primitives and replacing them with lights

Unread postby adamkuczek » Thu May 03, 2018 9:03 am

On which list? The script window offers: First Frame, Last Frame and lights:

LightPoint
LightDistant
LightSpot
LightArea
LightLinear

There is nothing about legacy or physical lights there. Or do you choose it somewhere else?

It seems the script creates legacy lights. How do I make it to create physical lights instead?
www.ak-art.net
adamkuczek
 
Posts: 31
Joined: Sat Mar 28, 2015 4:10 am
Location: Cracow, Poland

Re: Importing primitives and replacing them with lights

Unread postby dboude » Thu May 03, 2018 9:11 am

Hi,

Here is the script with legacy and physical lights.

Code: Select all
'''
------------------------------------------------------------------------------------------------------------------------------------------------------------
INIT
------------------------------------------------------------------------------------------------------------------------------------------------------------
'''
sel = ix.application.get_selection()
if sel.get_count() == 0:
    ix.log_error("You have to select a Point Cloud !\n")
if not sel.get_item(0).is_kindof("Geometry"):
    ix.log_error("You have to select a Point Cloud !\n")


sel = ix.selection[0]
ptc = sel.get_module().get_geometry().get_point_cloud()
ptc_count = ptc.get_point_count()
lgtList = []

#Define the default values
result = {'firstFrame' : 0, 'lastFrame' : 0, 'type' : [' - ','LightPoint','LightDistant','LightSpot','LightArea','LightLinear','LightPhysicalSphere','LightPhysicalCylinder','LightPhysicalPlane','LightPhysicalSpot','LightPhysicalDistant']}

'''
------------------------------------------------------------------------------------------------------------------------------------------------------------
UI CLASS
------------------------------------------------------------------------------------------------------------------------------------------------------------
'''
class EventRewire(ix.api.EventObject):
    #These are the called functions by the connect. It is more flexible to make a function for each button
    def firstFrameRefresh(self, sender, evtid):
        result['firstFrame'] = sender.get_value() #refresh result

    def lastFrameRefresh(self, sender, evtid):
        result['lastFrame'] = sender.get_value() #refresh result

    def listRefresh(self, sender, evtid):
        result['type'] = sender.get_selected_item_name() #refresh result

    def cancel(self, sender, evtid):
        sender.get_window().hide() #Hide the window, if it is done, the window is destroy

    def run(self, sender, evtid):
        #Put here the core of your script (or a function to separate UI and Script)
        if result['type'] == ' - ':
            ix.log_error("You have to select a light type")

        sender.get_window().hide() #Hide the window, if it is done, the window is destroy

        firstFrame = result['firstFrame']
        lastFrame = result['lastFrame']
        light = result['type']
        lightName = result['type'][5:] + "_1"

        ix.cmds.SetCurrentFrame(firstFrame)

        for i in range(ptc_count):
            lgt = ix.cmds.CreateObject(lightName, light)
            lgtList.append(lgt.get_full_name())

        while firstFrame <= lastFrame:
            T = ix.application.get_factory().get_vars().get("T").get_double()
            ptc = ix.get_item(str(sel)).get_module().get_geometry().get_point_cloud() # force to evaluate the ptc at actual frame
            global_matrix = sel.get_module().get_global_matrix()
            pos = ix.api.GMathVec3fArray()
            pos_new = ix.api.GMathVec3d()
            for i in range(ptc_count):
                ptc.get_positions(pos)
                ix.api.GMathMatrix4x4d.multiply(pos_new,pos[i],global_matrix)
                lgto = ix.get_item(lgtList[i])
                lgtStr = str(lgto)
                ix.cmds.SetKey([lgtStr + ".translate[0]", lgtStr + ".translate[1]", lgtStr + ".translate[2]"], T, [pos_new[0], pos_new[1], pos_new[2]], 0)
            firstFrame = firstFrame + 1
            ix.cmds.SetCurrentFrame(firstFrame)
        else:
            ix.application.message_box("Baking Lights complete !", "Information", ix.api.AppDialog.yes(), ix.api.AppDialog.STYLE_OK)

'''
------------------------------------------------------------------------------------------------------------------------------------------------------------
UI GENERATION
------------------------------------------------------------------------------------------------------------------------------------------------------------
'''
#Window creation
clarisse_win = ix.application.get_event_window()
window = ix.api.GuiWindow(clarisse_win, 900, 450, 240, 160) #Parent, X position, Y position, Width, Height
window.set_title('Set values...') #Window name

#Main widget creation <= this is the correct way to make a GUI, make a default widget and add inside what you want
panel = ix.api.GuiPanel(window, 0, 0, window.get_width(), window.get_height())
panel.set_constraints(ix.api.GuiWidget.CONSTRAINT_LEFT, ix.api.GuiWidget.CONSTRAINT_TOP, ix.api.GuiWidget.CONSTRAINT_RIGHT, ix.api.GuiWidget.CONSTRAINT_BOTTOM)

#Form generation
firstFrame = ix.api.GuiNumberField(panel, 79, 10, 151, "Fist Frame :  ")#Clarrisse_function(parent, X_position, Y_position, Width, Height, "label", 'this is a custom param to get the value without duplicate the CLASS')
firstFrame.set_increment(1) # this param force the increment ofNumberField to 1

lastFrame = ix.api.GuiNumberField(panel, 79, 40, 151, "Last Frame : ")#Clarrisse_function(parent, X_position, Y_position, Width, Height, "label", 'this is a custom param to get the value without duplicate the CLASS')
lastFrame.set_increment(1) # this param force the increment ofNumberField to 1

listLabel  = ix.api.GuiLabel(panel, 10, 70, 50, 22, "Type : ") #Clarrisse_function(parent, X_position, Y_position, Width, Height, "label")
list = ix.api.GuiListButton(panel, 70, 70, 160, 22) #Make an object of your class with the param inside __init__(parent, X, Y, Width, Height)
for i in result['type']:
    list.add_item(i) #add_item('the_name_of_your_item')

cancelBtn = ix.api.GuiPushButton(panel, 10, 130, 100, 22, "Cancel") #The cancel button (destroy the script window)
runBtn = ix.api.GuiPushButton(panel, 130, 130, 100, 22, "Run") # The run button to run your script

#init values
firstFrame.set_value(result['firstFrame']) #set the default value to the firstFrame input
lastFrame.set_value(result['lastFrame']) #set the default value to the lastFrame input

#Connect to function
event_rewire = EventRewire() #init the class

event_rewire.connect(firstFrame, 'EVT_ID_NUMBER_FIELD_VALUE_CHANGING', event_rewire.firstFrameRefresh) #connect(item_to_listen, what_we_are_listening, function_called)
event_rewire.connect(firstFrame, 'EVT_ID_NUMBER_FIELD_VALUE_CHANGED', event_rewire.firstFrameRefresh) #connect(item_to_listen, what_we_are_listening, function_called)
event_rewire.connect(lastFrame, 'EVT_ID_NUMBER_FIELD_VALUE_CHANGING', event_rewire.lastFrameRefresh) #connect(item_to_listen, what_we_are_listening, function_called)
event_rewire.connect(lastFrame, 'EVT_ID_NUMBER_FIELD_VALUE_CHANGED', event_rewire.lastFrameRefresh) #connect(item_to_listen, what_we_are_listening, function_called)
event_rewire.connect(list, 'EVT_ID_LIST_BUTTON_SELECT', event_rewire.listRefresh) #connect(item_to_listen, what_we_are_listening, function_called)
event_rewire.connect(list, 'EVT_ID_LIST_BUTTON_SELECT_UNCHANGED', event_rewire.listRefresh) #connect(item_to_listen, what_we_are_listening, function_called)
event_rewire.connect(cancelBtn, 'EVT_ID_PUSH_BUTTON_CLICK', event_rewire.cancel) #connect(item_to_listen, what_we_are_listening, function_called)
event_rewire.connect(runBtn, 'EVT_ID_PUSH_BUTTON_CLICK', event_rewire.run) #connect(item_to_listen, what_we_are_listening, function_called)

#Send all info to clarisse to generate window
window.show()
while window.is_shown():    ix.application.check_for_events()
window.destroy()


Sorry for the inconvenience !

Cheers ;)
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 1506
Joined: Mon Jul 03, 2017 10:51 am

Re: Importing primitives and replacing them with lights

Unread postby adamkuczek » Thu May 03, 2018 9:16 am

Thank you! :) Works perfectly now.

Cheers,
Adam
www.ak-art.net
adamkuczek
 
Posts: 31
Joined: Sat Mar 28, 2015 4:10 am
Location: Cracow, Poland

Re: Importing primitives and replacing them with lights

Unread postby adamkuczek » Thu May 03, 2018 3:19 pm

Too early happy about it :(

Half the time all new lights show up in the center of the grid (0,0,0) instead of in the centre of the spheres. Any idea how to fix it?
www.ak-art.net
adamkuczek
 
Posts: 31
Joined: Sat Mar 28, 2015 4:10 am
Location: Cracow, Poland

Re: Importing primitives and replacing them with lights

Unread postby dboude » Thu May 03, 2018 3:33 pm

No ideas. It works 100% time here. Can you send us the Alembic file with the sphere placement please ?

Thanks
Démian
Isotropix
Technical Artist - Clarisse Specialist
User avatar
dboude
 
Posts: 1506
Joined: Mon Jul 03, 2017 10:51 am

Re: Importing primitives and replacing them with lights

Unread postby adamkuczek » Thu May 03, 2018 4:20 pm

Here is the .abc of the example scene:

https://www.dropbox.com/s/pu1fjiydbv053 ... s.abc?dl=0

When I exported all into Alembic instead of obj, it became even stranger - now all the lights were created in a point high above the surface. No idea why.

Image
www.ak-art.net
adamkuczek
 
Posts: 31
Joined: Sat Mar 28, 2015 4:10 am
Location: Cracow, Poland

Next

Return to General Discussion
cron