Isotropix Forums

Light scatterer - kind of ;)

Clarisse Scripting related topics

Light scatterer - kind of ;)

Unread postby atnreg » Sat Aug 17, 2019 2:05 pm

Hi!

Here is simple code which creates instances of light to exact positions AND orientations of scattered geometry.
Select a light and then select a scatterer that has some geometry and run this script.

The lights' exposures and other attributes except translation and rotation remain normal instance attributes.

Of course this is not actual light scattering but as far as I know, light instances are closest we can get today :)
And this code does not 'clean' previous instances so this cannot be used to update lights if you change scatterer settings but still this makes 'scattering' lights a lot easier :)

Code: Select all
# Create light instances in place of scattered geometry
# Antti Nuoreva 2019-08-17
#
# Usage:  Set up scatterer using any geometry so that the geometries are positioned and oriented
#         like you want the lights to be. Then select a light and the scatterer and run this script
# Result: Instances of the selected light are positioned and oriented to exact places of the
#         scattered geometry.
#         To reset (e.g. after changing scatterer attributes) delete all ctrl* and light1+ and
#         run script again
#
# Note: Locator is used to handle axis difference between scatterer and Spot light
# Note2: This code has no checking for any errors to keep it compact

light=ix.selection[0]
scat=ix.selection[1]

def lightscatter(light,scat):
    scatm=scat.get_module()

    instance_count = scatm.get_instance_count()

    loc0=ix.cmds.CreateObject("ctrl0","Locator","")

    lm=light.get_module()
    lrot = ix.api.GMathVec3d()
    ltra = ix.api.GMathVec3d()
    lm.get_rotation(lrot,lm.SPACE_GLOBAL)
    lm.get_translation(ltra,lm.SPACE_GLOBAL)
    for i in range(instance_count):
        matr = scatm.get_instance_matrix(i)
        mat3t = ix.api.GMathVec3d()
        mat3r = ix.api.GMathVec3d()

        loc = loc0.get_context().add_instance(loc0)
        ix.cmds.LocalizeAttributes([str(loc)+".translate"], True)
        ix.cmds.LocalizeAttributes([str(loc)+".rotate"], True)
        locm=loc.get_module()
        loc.attrs.display_visible=False

        matr.extract_translation(mat3t)
        locm.set_translation(mat3t,locm.SPACE_GLOBAL)
        matr.compute_euler_angles(mat3r)
        locm.set_rotation(mat3r,locm.SPACE_GLOBAL)

        lighto = light.get_context().add_instance(light)
        lightm=lighto.get_module()

        ix.cmds.LocalizeAttributes([str(lighto)+".parent"], True)
        ix.cmds.LocalizeAttributes([str(lighto)+".translate"], True)
        ix.cmds.LocalizeAttributes([str(lighto)+".rotate"], True)

        lightm.set_parent(locm,locm.PARENT_IN_PLACE_FORCED_OFF)
        lightm.set_rotation(lrot,lightm.SPACE_LOCAL)
        lightm.set_translation(ltra,lightm.SPACE_LOCAL)

        ix.cmds.SetValues([str(scat)+".display_visible"], ["0"])
        ix.cmds.SetValues([str(scat)+".unseen_by_renderer"], ["1"])

lightscatter(light,scat)

Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0(always latest SP),Houdini,Blender,ZBrush,Fusion360,Onyx...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 595
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland

Re: Light scatterer - kind of ;)

Unread postby bvz » Tue Aug 20, 2019 8:38 pm

Cool! Thanks for posting!
bvz
 
Posts: 93
Joined: Tue Dec 03, 2013 9:55 am

Re: Light scatterer - kind of ;)

Unread postby david_grp » Thu Apr 30, 2020 3:34 am

Man, thank you so much, it's going to be super useful for what I'm working on! :D

Cheers!
david_grp
 
Posts: 7
Joined: Wed Jul 25, 2018 5:35 pm
Location: Montreal, Canada

Re: Light scatterer - kind of ;)

Unread postby atnreg » Thu Apr 30, 2020 4:54 pm

david_grp wrote:Man, thank you so much, it's going to be super useful for what I'm working on! :D

Cheers!


Nice to hear :)
Are you doing some production stuff i.e. do you have deadline?

I'm asking because I have developed that further A LOT (as it seems we will not get the new light system in Clarisse any time soon so this is closest we can get ;)) and unless you are in a hurry we could try to get it to you :)

It is now a button on toolbar and is based on scripted class and can do adjustments even in realtime and has automated setup. If you are interested, I can tell more :mrgreen:

I just need to verify it works with the latest Clarisse SP, I have been doing other things lately and haven't worked on it for a while but it should be ok.
Antti
AMD Ryzen Threadripper 2990wx (32c/64t),64GB RAM,NVIDIA GTX 1080ti,Win10
Clarisse 4.0(always latest SP),Houdini,Blender,ZBrush,Fusion360,Onyx...
Started: Clarisse 2016/10 (Py 2017/01), Python 2016/11
No business, just fun :)
atnreg
 
Posts: 595
Joined: Mon Sep 19, 2016 4:20 pm
Location: Helsinki, Finland


Return to Scripting