Author Topic: Need help scripting  (Read 38431 times)

2019-06-24, 11:05:12

Neil Cross

  • Active Users
  • **
  • Posts: 46
    • View Profile
Hi all

To explain this quickly, what I need is a script that isolates an object, at the same time, the HDRI needs to switch to a different HDRI and the VFB tone settings need to reset. These settings need to revert back when turning isolate off.
Let me know if I'm not making myself clear

The general idea is to isolate an object and run interactive using an HDRI that's good for testing materials. What I would usually do is switch my 3ds max settings to single map in corona scene environment settings. The issue with this is you will need to change your VFB tone settings to compensate each HDRI. Therefore you need to save and load Postprocess .conf files when switching your HDRI which is time-consuming!

Any thoughts?

Thanks!

2019-06-24, 19:10:26
Reply #1

Frood

  • Active Users
  • **
  • Posts: 1903
    • View Profile
    • Rakete GmbH
Any thoughts?

The issue may get saving/loading vfb conf files. Afaik the corona interface does not have any option to do this by maxscript so it has to be done manually for specific renderer properties (all "colorMap_" ones). But presuming the scene uses a corona camera (with tone mapping overrides) and tweaking happens in perspective mode (which uses "Render Setup" -> "Camera" in opposition) it may even not be necessary to save/load vfb settings. I like the idea to have a button "let's tweak this". So what kind of help do you actually need to proceed?


Good Luck




Never underestimate the power of a well placed level one spell.

2019-06-25, 10:13:53
Reply #2

Neil Cross

  • Active Users
  • **
  • Posts: 46
    • View Profile
Hi Frood. Your approach to using camera tone map override definitely helps. No point in creating a script. Maybe creating a hotkey to switch corona environment settings could be useful.

2019-06-25, 12:08:13
Reply #3

maru

  • Corona Team
  • Active Users
  • ****
  • Posts: 12711
  • Marcin
    • View Profile
You could also have 3ds Max enviro set to one HDRI and Corona enviro set to another. Then use a script to switch between "use Max" and "use Corona" options in the Scene tab.
Marcin Miodek | chaos-corona.com
3D Support Team Lead - Corona | contact us

2019-06-26, 01:11:07
Reply #4

Neil Cross

  • Active Users
  • **
  • Posts: 46
    • View Profile
Hi Maru. I'm no expert at using scripts. Understanding something as simple as CoronaRenderer.CoronaFp.showvfb true is as far as my knowledge goes. According to https://corona-renderer.com/doc 3ds Max enviro and Corona enviro have the same script name "bg_source". How would it be possible to toggle these settings?

2019-06-26, 01:59:46
Reply #5

Neil Cross

  • Active Users
  • **
  • Posts: 46
    • View Profile
Iv made this script using maxscript listener

environmentMap = sceneMaterials["Personal HDRI"]
actionMan.executeAction 0 "268"  -- Tools: Isolate Selection Toggle
actionMan.executeAction 0 "40182"  -- Views: Perspective User View
actionMan.executeAction 0 "310"  -- Tools: Zoom Extents Selected

It's not the result I'm after
Object isolates, Camera to perspective, HDRI loaded. from this point I need a toggle which unisolates, perspective to camera, Scene HDRI Loaded.


2019-06-26, 09:58:40
Reply #6

Frood

  • Active Users
  • **
  • Posts: 1903
    • View Profile
    • Rakete GmbH
Quick ones to continue testing would be:

-Unisolate: "IsolateSelection.ExitIsolateSelectionMode()"
-Switch to camera view: "viewport.setType(#view_camera)". However if you have multiple cameras you would get a prompt to choose a camera
-Scene HDRI: Depends where and how it is stored

But basically my approach would be to remember every change made without exception for reverting later (when releasing the button) so the button can be used for any scene without leaving traces behind. Meaning:

Button toggle on:
  • Save viewport type, save camera reference if it is a camera viewport. (See "viewport.getType()" and "viewport.getCamera()")
  • (Maybe even save viewport layout and active viewport in case someone changes it during tweaking)
  • Save renderer environment setting ("renderers.current.bg_source", can be 3dsMax (0), Corona single (1) or Corona multiple (2), this also answers your question about switching environment setting by script)
  • If you choose to always use 3dsmax env for tweaking and Corona env for rendering and renderers.current.bg_source is not set to 3ds max env and it's empty, plug tweak map into 3ds max environment while saving the currently assigned one if present.
  • Save states of Corona overrides ("renderers.current.bg_overrideDirect/Refract/Reflect") and switch them off
  • Optionally open SME, create a new tab "Tweaking" and fetch all materials from selected objects automatically (bonus task I would like to have :)
  • Isolate+zoom selection

Tweak

Button toggle off:
  • Delete SME tab "Tweaking" (bonus task)
  • Restore saved 3ds max env map if one was present
  • Restore saved renderer environment setting (see above)
  • Restore saved states of Corona overrides
  • Switch to saved viewport type, switch to saved camera if it has been a camera view (""viewport.setType()" and "viewport.setCamera()")
  • Unisolate

For personal/inhouse use you can of course simplify everything. As mentioned, I pretty much love the idea of having a "Let's tweak this!" button, maybe I'll give it a try someday.


Good Luck





Edit: 3dsMax (1), Corona single (2) or Corona multiple (3) -> 3dsMax (0), Corona single (1) or Corona multiple (2)
« Last Edit: 2019-07-02, 12:53:34 by Frood »
Never underestimate the power of a well placed level one spell.

2019-06-26, 11:07:35
Reply #7

Neil Cross

  • Active Users
  • **
  • Posts: 46
    • View Profile

2019-06-28, 01:19:29
Reply #8

Neil Cross

  • Active Users
  • **
  • Posts: 46
    • View Profile
@Frood im slowly getting there

Iv got to a point where my object is isolated and running interactive in perspective with a different hdri. Iv managed to set this up using a a single hotkey.
Reverting back should be easy as the scripts work visa versa. Only issues im having is making it toggle. Is there some toggle language im not understanding?

Thanks
Neil


2019-06-28, 15:47:39
Reply #9

Frood

  • Active Users
  • **
  • Posts: 1903
    • View Profile
    • Rakete GmbH
Good to read of progress :) As for your toggle issue: you have to remember yourself in which state your script currently is. I would do the whole thing as macroscript to use it as a button, but you can also assign it to a hotkey only. Here is a basic macro script to show how you could do it:

Code: [Select]
macroScript NeilCrossToggleTemplate
category:"NeilCross"
toolTip:"Toolbar Button Template"
icon:#("MaxScript",3)
(
--- remember everything here, also any variables/settings which have to be reverted later
local tweakingActive=false

on isEnabled do ( --- defines if the button/script is active
--- only be active if something is selected:
if selection.count > 0 then return true else return false
)

on isChecked do ( --- defines if the button is pressed
--- this is either true or false, suitable to return this directly:
return tweakingActive
)

on execute do ( --- someone pressed the button or the assigned hotkey
if tweakingActive==false then ( --- not tweaking currently
print "Preparing to tweak"

--- do everything to make it happen here

--- now we are in tweak mode, so:
tweakingActive=true
)
else (  --- tweaking currently
print "Reverting from tweak mode"

--- reverse/cleanup everything here

--- now we are out of tweak mode, so:
tweakingActive=false
)
)
)

Save it in your usermacros directory and you should find it in Customize -> Customize User Interface -> Toolbars (I would drag it to any toolbar unless it is finished for better access) -> Category "NeilCross" - > Action "Toobar Button Template" -> Drag it to some toolbar, right click and choose "Edit macro script" to start modifying.

More about all possible "on <blabla> do" event handlers and what you can do inside them here:

https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/MAXScript-Help/files/GUID-6E21C768-7256-4500-AB1F-B144F492F055-htm.html


Good Luck



Never underestimate the power of a well placed level one spell.

2019-07-03, 13:19:56
Reply #10

Neil Cross

  • Active Users
  • **
  • Posts: 46
    • View Profile
Thanks Frood.

Appreciate all your help. I'm starting to understand the language slowly. If I manage to complete this script ill make sure I share it with you!

Cheers!
Neil

2019-07-03, 15:45:52
Reply #11

Frood

  • Active Users
  • **
  • Posts: 1903
    • View Profile
    • Rakete GmbH
Same here, I have a prototype (5% of work) in my toolbar, but those 95% work catching errors, special situations and some bugs (getRenderType() again...) and further testing is still missing. But since I want this for myself I will try to complete some first version asap and also post here.


Good Luck



Never underestimate the power of a well placed level one spell.

2019-07-09, 15:16:26
Reply #12

Frood

  • Active Users
  • **
  • Posts: 1903
    • View Profile
    • Rakete GmbH
Testversion attached :]

- Create a map called "Tweak Map" anywhere in a material editor
- And/Or change the custom section of the script to hardcode some file

Basically it's what I mentioned above. Additional things that happen:

- script deactivated when autokey is active
- script deactivated when production render is active
- when started in perspective mode, it will restore that exactly view
- automatically switches off corona sun(s) when entering tweak mode
- leaves suns alone when CoronaSky is used as env map


Good Luck



Edit: deleted old version
« Last Edit: 2019-07-18, 09:42:28 by Frood »
Never underestimate the power of a well placed level one spell.

2019-07-15, 11:15:50
Reply #13

Frood

  • Active Users
  • **
  • Posts: 1903
    • View Profile
    • Rakete GmbH
and the VFB tone settings need to reset. These settings need to revert back when turning isolate off.

Afaik the corona interface does not have any option to do this by maxscript so it has to be done manually

Added this. You are now entirely free to use a preset for distinct VFB settings matching the environment or not, to change tone mapping settings during tweaking; all is saved and will revert back. This way the script can also be used to change into a calibrated scene with one click (and back of course).


Good Luck


Edit: removed old version
« Last Edit: 2019-07-31, 08:47:55 by Frood »
Never underestimate the power of a well placed level one spell.

2019-07-31, 01:29:14
Reply #14

Neil Cross

  • Active Users
  • **
  • Posts: 46
    • View Profile
Thanks for sharing Frood. I will test it out later today. #need to sleep lol. I will share what I have created myself. Cheers

2019-07-31, 08:47:15
Reply #15

Frood

  • Active Users
  • **
  • Posts: 1903
    • View Profile
    • Rakete GmbH
Then try the newest one :) Changes are:

  • v0.40 File Save/Reset/Open callbacks for resetting environment added
  • v0.35 Deepcopy of VFB parameters workaround (maxscript glitch), lightmix settings also revert after tweaking now. Catched possibly missing camera. 'useEnvironmentMap' fix/added. Undefined extended viewport types cause no error any more.



Good Luck and happy recreation :)



Edit: Removed old version
« Last Edit: 2019-08-02, 16:13:39 by Frood »
Never underestimate the power of a well placed level one spell.

2019-07-31, 17:39:48
Reply #16

LorenzoS

  • Active Users
  • **
  • Posts: 291
    • View Profile
Hi,
(very useful script),
if in ligthmix I deactivated the enviroment, when I launch the script I see the black vfb, so I think it should automatically switch to the beauty of the vfb and come back to te ligthmix when close it.

2019-07-31, 17:46:12
Reply #17

LorenzoS

  • Active Users
  • **
  • Posts: 291
    • View Profile
...i use three hdri:two enviroment in the lightmix and one loaded from script

2019-07-31, 18:06:11
Reply #18

Frood

  • Active Users
  • **
  • Posts: 1903
    • View Profile
    • Rakete GmbH
it should automatically switch to the beauty of the vfb

Yes, easy to do...

and come back to te ligthmix when close it.

... but this is not possible. There is no way to get the currently displayed channel index from Corona. So something which would not revert :-| But I will add a parameter for autoswitching to beauty.


Good Luck


Never underestimate the power of a well placed level one spell.

2019-07-31, 18:21:01
Reply #19

LorenzoS

  • Active Users
  • **
  • Posts: 291
    • View Profile
thank you Frood

2019-08-02, 16:13:01
Reply #20

Frood

  • Active Users
  • **
  • Posts: 1903
    • View Profile
    • Rakete GmbH
Here you are:

v0.41 Changing to VFB beauty channel automatically when starting tweak (not revertable unfortunately, but configurable to switch it on/off)


Good Luck


Edit: This script does not work with Corona v8 or later.
« Last Edit: 2022-12-02, 16:10:11 by Frood »
Never underestimate the power of a well placed level one spell.

2019-08-02, 16:59:04
Reply #21

LorenzoS

  • Active Users
  • **
  • Posts: 291
    • View Profile
Hi Frood,
the last thing,
when i toogle off the script, the IR stop automatically, where can i modify the script to continue IR?

thanks again

2019-08-02, 17:13:26
Reply #22

Frood

  • Active Users
  • **
  • Posts: 1903
    • View Profile
    • Rakete GmbH
Everything reverts when disabling tweak mode again. So if you have been running IR before pressing the button, IR would continue running after tweaking. If it was not running, IR is stopped after using the button. This is by purpose and kind of principle of the script: You break out of the prison of your scene with overrides, strange tone mapping settings+LUT and incredible exposure with one click to tweak in a defined environment and are exactly there where you have been when switching back. But of course this can be configured by a parameter (which would act like described by default), will consider.


Good Luck



Never underestimate the power of a well placed level one spell.

2019-08-02, 17:39:36
Reply #23

LorenzoS

  • Active Users
  • **
  • Posts: 291
    • View Profile
I understand, what you say is coherent

2020-12-13, 22:33:25
Reply #24

whitepaper

  • Users
  • *
  • Posts: 3
    • View Profile
Up, i need more 8)

2022-12-02, 15:02:41
Reply #25

Crazy Homeless Guy

  • Active Users
  • **
  • Posts: 32
    • View Profile
Here you are:

v0.41 Changing to VFB beauty channel automatically when starting tweak (not revertable unfortunately, but configurable to switch it on/off)


Good Luck

Hi Frood.  Is this the latest version of your "Let's Tweak This/It" Script?  I didn't see it elsewhere on the internet (Scriptspot, etc.)

Thanks in advance!

2022-12-02, 16:07:19
Reply #26

Frood

  • Active Users
  • **
  • Posts: 1903
    • View Profile
    • Rakete GmbH
Hi,

that script has been rather a kind of finger exercise along the way to discuss some concepts with Neil :) And it does not work with the new tone mapping stack anyway (Corona v8 and newer). Since script access to tone mapping in Corona v8 came out quite complicated and prudish, I had no time and mood to update it yet, sorry.


Good Luck


Never underestimate the power of a well placed level one spell.