DAZ Script 2: Getting standard surface parameters/using layered images. Almost done now

3dcheapskate3dcheapskate Posts: 2,719

Edit: The original question (how to read standard surface parameters) has been answered, and I'm now trying to work out how to read/modify/write a layered image.

N.B. I'm using both DS3 and DS4, so any answer should apply to both.
Basically I want to read all the current surface parameters before applying a ShaderMixer based material, since the SM mat needs to use most of the current parameters.

DzPresetHelper makes it easy to SET the standard parameters on the Surfaces tab with setColorProperty( ), setNumericPropertyWithAttributes( ), and setNumericProperty(), but how does one GET the current values.

I'm sure the answer's really obvious, but I just can't find it. The old DAZ Script 2 documentation (DAZ Studio/DAZScript/class_dz_preset_helper.html) isn't much help here since although the function prototypes are given none of the functions are documented.

E.g. the script for writing the SM 'Diffuse Colour' will be something like this

     ...
     oMatSettings_sub_sub_sub_sub = oMatSettings_sub_sub_sub.setSettingsValue( "Parameters" );
     oMatSettings_sub_sub_sub_sub_sub = oMatSettings_sub_sub_sub_sub.setSettingsValue( "DiffuseColor" );
     oMatSettings_sub_sub_sub_sub_sub.setStringValue( "Tokens", "elr_cd852154_364e_4eb5_8354_690477174e8c_token_21" );
     oMatSettings_sub_sub_sub_sub_sub.setStringValue( "Label", "Diffuse Color" );
     oMatSettings_sub_sub_sub_sub_sub_sub = oMatSettings_sub_sub_sub_sub_sub.setSettingsValue( "Prop_0" );
     oMatSettings_sub_sub_sub_sub_sub_sub.setStringValue( "Label", "Diffuse Color" );
     oMatSettings_sub_sub_sub_sub_sub_sub.setBoolValue( "Hidden", false );
     oMatSettings_sub_sub_sub_sub_sub_sub.setStringValue( "Path", "/DS Default Material (2)" );
     oMatSettings_sub_sub_sub_sub_sub_sub.setBoolValue( "UserProperty", true );
     oMatSettings_sub_sub_sub_sub_sub_sub.setBoolValue( "CanAnimate", true );
     oMatSettings_sub_sub_sub_sub_sub_sub.setBoolValue( "Locked", false );
     oMatSettings_sub_sub_sub_sub_sub_sub.setBoolValue( "Manipulator", true );
     oMatSettings_sub_sub_sub_sub_sub_sub.setBoolValue( "Favorite", false );
     oMatSettings_sub_sub_sub_sub_sub_sub.setBoolValue( "GlobalFavorite", false );
     oMatSettings_sub_sub_sub_sub_sub_sub.setBoolValue( "Selected", false );
     oMatSettings_sub_sub_sub_sub_sub_sub.setStringValue( "XYZInterest", "None" );
     oMatSettings_sub_sub_sub_sub_sub_sub.setBoolValue( "Clamped", false );
     oMatSettings_sub_sub_sub_sub_sub_sub.setBoolValue( "Mapable", false );
     oMatSettings_sub_sub_sub_sub_sub_sub.setBoolValue( "NeedMap", false );
     oMatSettings_sub_sub_sub_sub_sub_sub.setIntValue( "Min", -2147483648 );
     oMatSettings_sub_sub_sub_sub_sub_sub.setIntValue( "Max", 2147483647 );
     oMatSettings_sub_sub_sub_sub_sub_sub.setIntValue( "Sensitivity", 1 );
     oMatSettings_sub_sub_sub_sub_sub_sub_sub = oMatSettings_sub_sub_sub_sub_sub_sub.setSettingsValue( "Value" );
     // I WANT TO DO THE 'GET' VERSION OF...
     // g_oPresetHelper.setColorProperty( "Diffuse Color",  [ 255, 195, 181 ] );
     // ...HERE, AND APPLY THE RGB VALUES BACK
     oMatSettings_sub_sub_sub_sub_sub_sub_sub.setIntValue( "Red", 255 );
     oMatSettings_sub_sub_sub_sub_sub_sub_sub.setIntValue( "Green", 255 );
     oMatSettings_sub_sub_sub_sub_sub_sub_sub.setIntValue( "Blue", 255 );
     ...
Post edited by 3dcheapskate on

Comments

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited October 2013

    Found part of the answer - DzMaterial: getColorMap(), getDiffuseColor (), getBaseOpacity() and getOpacityMap() .

    But that's just four parameters.

    What about all the others? Diffuse strength, glossiness, etc...

    Post edited by 3dcheapskate on
  • Richard HaseltineRichard Haseltine Posts: 100,886
    edited October 2013

    Try getPropertyList() on the DzMaterial, which is inherited from DzElement, then go through it getting each property's name, type and value as required.

    Post edited by Richard Haseltine on
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited October 2013

    Thanks Richard, I'll give that a try.

    Any idea if it's possible to access Layered Image Editor (MLIE/LIE) parameters from DAZ Script?
    I think the LIE parameters are saved with a scene, but not with a standard shader/material preset...

    Post edited by 3dcheapskate on
  • Richard HaseltineRichard Haseltine Posts: 100,886
    edited December 1969

    It is, since there were .dsa presets that would build a layered material (and products like Marieah's use those) but I'm not sure of the details, it's not an area I've yet poked at.

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited October 2013

    Are you sure the ones your thinking of actually use LIE? Layered materials can be made in ShaderMixer and saved as .dsa material/shader presets (I've done a few).

    The big problem I've found with ShaderMixer layered materials is that they display plain grey in the preview pane (and apparently they don't work with Luxus/LuxRender).

    Proper LIE layered materials display correctly in the preview pane and work with Luxus/LuxRender - and that's why I want to have LIE support in my script. The ShaderMixer version would then just be a fallback for users who don't have LIE/MLIE.

    Edit: Just spotted the 'DzImageLayer' class in the documentation, for 'A single layer in a multi-layer texture image' so I guess that's a good place to start !

    P.S. The getPropertyList() was what I needed for my original query, so many thanks again Richard.

    Post edited by 3dcheapskate on
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited October 2013

    Looks quite straightforward to create a layered image, something along these lines...

    // Initialize stuff
    var li = new DzLayeredImage;
    var l1 = new DzImageFileLayer;
    var l2 = new DzImageFileLayer;
    var m2 = new DzImageMask;
    
    // Set up the individual layers and mask
    l1.getImageData().load( [image-1-file] );
    l2.getImageData().load( [image-2-file] );
    m2.filename = [image-2-mask-file];
    l2.setMask(m2);
    
    // Combine the layers
    li.addLayer(l1);
    li.addLayer(l2);
    
    // Save the layered image
    App.getImageMgr().saveLayeredImage ([file-for-layered-image],li);

    ... and then the layered image file, a .dsi (DS3) or .tif (DS4), needs to be plugged into the appropriate map input.

    Haven't tried it yet...

    Edit: corrected the parameters passed to addlayer() in the code sample, as per Richard's comment in post 8.
    Edit2: Changed DzImageLayer to DzImageFileLayer (DzImageFileLayer and DzImageColorLayer are children/descendants/whatever-the-word-is of DzImageLayer but are missing from the DS3 DAZ Script 2 documentation. Also capitalized the 'l' in 'addlayer()'

    Post edited by 3dcheapskate on
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited October 2013

    Hmmm...

    DS4 gives me "WARNING: ReferenceError: Can't find variable: DzImageLayer"
    DS3 gives me "WARNING: ReferenceError: DzImageLayer is not defined"

    DzLayeredImage and DzImageMask are fine.
    I've checked that I've spelt DzImageLayer as per the documentation.

    So what's up? The DS4 warning seems to indicate that it's not recognized as a class name, so is the documentation wrong?

    Edit: Trying to suss out what the correct class name for the DAZ Image Layer is, since it doesn't seem to be the documented one - DzImageLayer.

    But I'm not having much luck.

    No clues in the code samples with the DAZ Script 2 kit or on the Wiki.

    No clues in the files created by DS3/4 either. The LIE info isn't saved with a DS3 or DS4 shader/material preset, so no way of checking the code in those files. And although the LIE info IS saved with scene files, the DS4 scene file is a .duf (i.e. not DAZ Script 2), and the DS3 scene is a binary (non-zip) .daz file. So no way to check that code

    Help!

    Post edited by 3dcheapskate on
  • Richard HaseltineRichard Haseltine Posts: 100,886
    edited December 1969

    DzImageLayer doesn't have a constructor, so you can't create one with the new operator like that. I'm not sure how you would create an new layer if that's the case - presumably something will return a new one as a function, but there doesn't look to be anything helpful in DzLayeredImage or DzImageMgr.

    Shouldn't you be replacing layerBase and layerOverlay in the addLayer calls, assuming you can create the layers in the first place?

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited October 2013

    I noticed the lack of constructor in the documentation (although the 'List All Members' link indicates that it inherits constructor from Object ). But since I don't really 'get' OOP* (machine code, assembler, and C were the main stuff I played with in my job) I use the 'try it and see if it works' approach. Obviously that bit doesn't!

    I searched for 'DzImageLayer' in all the .html files for the DAZ Script 2 documentation and there doesn't appear to be anything that returns one. So how does one create a DzImageLayer?

    layerBase and layerOverlay should be l1 and l2 respectively - I shortened all my variable names but didn't change them all! I'll go and correct the post now.

    *No problem with the OO concept itself, it's the implementations. Same with Microsoft stuff, Apple stuff, etc - I'm sure they're all perfectly logical and intuitive... once you 'get' the mindset of the creators. Unfortunately none of these mindsets have ever clicked for me. However, the Blender 2.49 UI did click, eventually, in a transcendental moment of enlightenment - but that's irrelevant... ;o)

    Post edited by 3dcheapskate on
  • rbtwhizrbtwhiz Posts: 2,250
    edited December 1969

    Added an example... Create Layered Image Backdrop. Shows how to create a layered image pre and post 4.6.2.23. I should also point out that It uses functions that do not exist prior to 4.1.0.24 and 4.0.4.16.

    -Rob

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited October 2013

    Thanks Rob ! DzImageFileLayer instead of DzImageLayer does the trick (plus capitalizing the 'l' in addLayer() ). With just those changes my code snippet now runs in both DS3A and DS4.5... well, it doesn't crash and it actually creates a layered image of sorts. Plenty to be going on with...

    Post edited by 3dcheapskate on
  • 3dcheapskate3dcheapskate Posts: 2,719
    edited October 2013

    Anybody know what happens if the user has a version of DAZ Studio WITHOUT the LIE/MLIE ? I'm assuming that the layered image is still created and the resulting .dsi or .tif/.tdl file gets connected to the relevant channel (e.g. diffuce color image map), and will still work, but the user will not have the facility to view or change the layers (since it's the (Multi) Layered Image EDITOR that will be missing, not the DzLayeredImage class etc).

    There's also a potential copyright issue about saving the outputs of the layered image editor:
    - Not a problem in DS3 since it uses a proprietary .dsi format, which is just an XML definition of the separate layers and masks, so the combined image is never actually saved to disk.
    - But DS4 saves a .tif version of the combined output image, although it's created in a temporary folder and deleted when you close DAZ Studio. However, I'm saving to the desktop (while I'm testing) and the file isn't deleted when I close DAZ Studio. So how to I make sure that my .tif/tdl file is written to the same temporary folder as LIE uses?

    Post edited by 3dcheapskate on
  • rbtwhizrbtwhiz Posts: 2,250
    edited December 1969

    Thanks Rob ! DzImageFileLayer instead of DzImageLayer does the trick (plus capitalizing the 'l' in addLayer() ). With just those changes my code snippet now runs in both DS3A and DS4.5... well, it doesn't crash and it actually creates a layered image of sorts. Plenty to be going on with...

    DzImageLayer is an abstract base class that provides common functionality to DzImageFileLayer and DzImageColorLayer, via inheritance. DzImageLayer is not instantiated, rather DzImageFileLayer or DzImageColorLayer are. These classes are part of the "old" API for layered images. The new API provides similar functionality through a single DzTextureLayer class.

    Anybody know what happens if the user has a version of DAZ Studio WITHOUT the LIE/MLIE ? I'm assuming that the layered image is still created and the resulting .dsi or .tif/.tdl file gets connected to the relevant channel (e.g. diffuce color image map), and will still work, but the user will not have the facility to view or change the layers (since it's the (Multi) Layered Image EDITOR that will be missing, not the DzLayeredImage class etc).

    There's also a potential copyright issue about saving the outputs of the layered image editor:
    - Not a problem in DS3 since it uses a proprietary .dsi format, which is just an XML definition of the separate layers and masks, so the combined image is never actually saved to disk.
    - But DS4 saves a .tif version of the combined output image, although it's created in a temporary folder and deleted when you close DAZ Studio. However, I'm saving to the desktop (while I'm testing) and the file isn't deleted when I close DAZ Studio. So how to I make sure that my .tif/tdl file is written to the same temporary folder as LIE uses?

    The layered image API is part of the core library. This is what allows layered image presets to be used by end users that do not own the plugin. The plugin provides the editor interface and the save filter that generates a layered image preset. For versions prior to 4.x, the plugin requires purchase. Version 4.x+ includes the plugin as part of the pro product, which is [currently] free.

    The .tif/tdl files are generated in a temporary directory (i.e. App.getTempPath()) due to requirements of the rendering pipeline. This happens for DS3 and DS4. What was saved in a .dsi in DS3 is saved within a .duf in DS4.

    -Rob

  • 3dcheapskate3dcheapskate Posts: 2,719
    edited October 2013

    Thanks for the clarification Rob. Much appreciated. And it all makes sense when you know what's going on behind the scenes.

    Post edited by 3dcheapskate on
  • gabugabu Posts: 303
    edited December 1969

    rbtwhiz said:
    Thanks Rob ! DzImageFileLayer instead of DzImageLayer does the trick (plus capitalizing the 'l' in addLayer() ). With just those changes my code snippet now runs in both DS3A and DS4.5... well, it doesn't crash and it actually creates a layered image of sorts. Plenty to be going on with...

    DzImageLayer is an abstract base class that provides common functionality to DzImageFileLayer and DzImageColorLayer, via inheritance. DzImageLayer is not instantiated, rather DzImageFileLayer or DzImageColorLayer are. These classes are part of the "old" API for layered images. The new API provides similar functionality through a single DzTextureLayer class.

    Anybody know what happens if the user has a version of DAZ Studio WITHOUT the LIE/MLIE ? I'm assuming that the layered image is still created and the resulting .dsi or .tif/.tdl file gets connected to the relevant channel (e.g. diffuce color image map), and will still work, but the user will not have the facility to view or change the layers (since it's the (Multi) Layered Image EDITOR that will be missing, not the DzLayeredImage class etc).

    There's also a potential copyright issue about saving the outputs of the layered image editor:
    - Not a problem in DS3 since it uses a proprietary .dsi format, which is just an XML definition of the separate layers and masks, so the combined image is never actually saved to disk.
    - But DS4 saves a .tif version of the combined output image, although it's created in a temporary folder and deleted when you close DAZ Studio. However, I'm saving to the desktop (while I'm testing) and the file isn't deleted when I close DAZ Studio. So how to I make sure that my .tif/tdl file is written to the same temporary folder as LIE uses?

    The layered image API is part of the core library. This is what allows layered image presets to be used by end users that do not own the plugin. The plugin provides the editor interface and the save filter that generates a layered image preset. For versions prior to 4.x, the plugin requires purchase. Version 4.x+ includes the plugin as part of the pro product, which is [currently] free.

    The .tif/tdl files are generated in a temporary directory (i.e. App.getTempPath()) due to requirements of the rendering pipeline. This happens for DS3 and DS4. What was saved in a .dsi in DS3 is saved within a .duf in DS4.

    -Rob

    "[currently] free"?

    Is that a hint that things might change pricing wise?

  • Richard HaseltineRichard Haseltine Posts: 100,886
    edited December 1969

    I doubt it's a hint, it's a necessary caveat to leave DAZ free to change its status in future. Of course that doesn't mean it isn't about to change (I have no information on that), just that you shouldn't read anything into Rob's comment

  • rbtwhizrbtwhiz Posts: 2,250
    edited December 1969

    luxgabu said:
    "[currently] free"?

    Is that a hint that things might change pricing wise?

    Short answer:

    No more a hint than "FREE for a limited time" suggests.

    Longer answer:

    Unfortunately there are some that read every word that comes from an employee as being absolute and/or a "promise" of some sort; regardless of the position held within the company. Worse yet, there are some that pull otherwise innocuous statements entirely out of context and insist that a promise was made... nevermind imagined statements. It makes posting at all like walking in a minefield at times. As a result, I have to choose my words carefully (which, no doubt, someone will still find issue with) and include caveats that allow a statement to be accurate and factual at the time it was written, while allowing for it to not be read as some sort of eternal promise. As of this moment, the DAZ Studio product page states "FREE for a limited time"... Thus, I used "[currently]" to make the statement as accurate as possible, considering that "a limited time" implies an end and said "limited time" is not a decision I make.

    -Rob

  • gabugabu Posts: 303
    edited December 1969

    I sympathise with your predicament. The forums seem at times rife with speculation about Daz's intentions.

    I for one am grateful that Studio is available free even though I was put out when it became free so soon after I had bought a copy of it.

Sign In or Register to comment.