Iray environment properties

how we can do this using c++?

 

var viewport_manager = MainWindow.getViewportMgr();
var draw_style = viewport_manager.findUserDrawStyle("NVIDIA Iray");
var viewport = viewport_manager.getActiveViewport();
var viewport_3d = viewport.get3DViewport();
viewport_3d.setDrawStyle(draw_style);
var render_manager = App.getRenderMgr();
Scene.addNode(new DzEnvironmentNode());
Scene.addNode(new DzTonemapperNode());
render_manager.getRenderElementObjects().forEach(function (element)
{
    if (element.className() === "DzEnvironmentNode")
    {
        element.findPropertyByLabel("Draw Dome").setDoubleValue(1);
    }
});

Post edited by MehdiZangenehBar on

Comments

  • surrealsurreal Posts: 175
    edited February 25

    A problem is that the SDK 4.5+ does not know about zEnvironmentNode and DzTonemapperNode. They were created after this version of the SDK was released. 

    One option to work around that problem is to create those nodes using a script called by your plugin. If you are so inclined, you could just get your plugin to call your whole script.

    However, since this is an SDK forum let’s do what we can using the SDK.

    Sorry I do not have a great deal of free time so not the best code it is verbose and has redundant checking. Use at your own risk, hopefully it will be of use to you and others.
    CREDIT: apart from any spelling mistakes this code is simply an adaption from DAZ's examples(included with the SDK) and in the SDk documentation and from many previous forum contributors.

    /**********************************************************************	Copyright (c) 2002-2020 Daz 3D, Inc. All Rights Reserved.	This file is part of the Daz Studio SDK.	This file may be used only in accordance with the Daz Studio SDK	license provided with the Daz Studio SDK.	The contents of this file may not be disclosed to third parties,	copied or duplicated in any form, in whole or in part, without the	prior written permission of Daz 3D, Inc, except as explicitly	allowed in the Daz Studio SDK license.	See http://www.daz3d.com to contact Daz 3D, Inc or for more	information about the Daz Studio SDK.**********************************************************************//// <summary>/// Call a script to create class/// SDK does not know about some new node types i.e. DzEnvironmentNode and DzTonemapperNode/// So we have to use scripting to create those types of nodes/// </summary>/// <param name="nodeClassName">The class name of the node type to create and add to scene</param>void createByClassNodeScript(const QString& nodeClassName) {	DzScript script;	script.addLine("Scene.addNode(new " + nodeClassName + "());");	if (script.execute() == true) {		dzApp->statusLine("Script OK", FALSE);	}	else {		dzApp->debug("createByClassNodeScript error message - " + script.errorMessage());		dzApp->statusLine(script.errorMessage(), FALSE);	}}/// <summary>/// Check if there is a node of a particular class in the scene /// by stepping through all the nodes in the scene/// and checking if they inherit that class./// </summary>/// <param name="nodeClassName">The node class name to find</param>/// <returns>Returns first node of requested class type found in scene, returns nullptr(0) if no node of requested class type found in scene</returns>DzNode* findSceneNodeByClass(const QString& nodeClassName) {	DzNodeListIterator nodeIt(dzScene->nodeListIterator());		// Get iterator for scene node list	while (nodeIt.hasNext()) {									// While not at end of node list		DzNode* node = nodeIt.next();							// Get next node in scene node list		if (node->inherits(nodeClassName)) {					// If environmentalNode not yet found(still null) and node is type DzEnvironmentNode then			return node;		}	}	return nullptr;}/// <summary>/// Execute action/// </summary>void NpKeyMoverTestAction::executeAction(){	const DzMainWindow* mainWindow = dzApp->getInterface();	if (mainWindow) {																	// If main window exists then. Should always be true.		DzViewportMgr* viewport_manager = mainWindow->getViewportMgr();					// Get viewport manager		if (viewport_manager) {															// If successful in getting view port manager then			for (int i = 0; i < viewport_manager->getNumUserDrawStyles(); ++i) {		// Step through each of the user draw styles				DzUserDrawStyle* draw_style = viewport_manager->getUserDrawStyle(i);	// Get user draw style				try {	// getUserDrawStyle is static so we can not test to make sure that it returned 	// getUserDrawStyle is static so can not test if successful					QString uStyleName = draw_style->getName();							// Try to get name from user draw style					if (uStyleName.compare("NVIDIA Iray", Qt::CaseInsensitive)) {		// If style name is "NVIDIA Iray" then						DzViewport* viewport = viewport_manager->getActiveViewport();	// Get the active viewport						if (viewport) {													// If there is an active viewport then							Dz3DViewport* viewport_3d = viewport->get3DViewport();		// Get 3D viewport							if (viewport_3d) {											// If successful then								viewport_3d->setDrawStyle(draw_style);					// Set the 3D viewport style to NVIDIA Iray							}						}					}				}				catch (...) {					dzApp->warning("UserDrawStyle " + QString::number(i) + " is not valid.");	// getUserDrawStyle(i) failed, write warning to log file				}			}		}	}	// Check if there is already a DzEnvironmentNode in the scene	DzNode* environmentalNode = findSceneNodeByClass("DzEnvironmentNode");				// Try to get pointer to existing DzEnvironmentNode	if (!environmentalNode) {															// If environmentalNode not found then		createByClassNodeScript("DzEnvironmentNode");									// Create and add a new DzTonemapperNode to the scene		environmentalNode = findSceneNodeByClass("DzEnvironmentNode");					// Try to get pointer to new DzTonemapperNode	}	if (environmentalNode) {															// If DzTonemapperNode in scene then		DzProperty* drawDomeProperty = environmentalNode->findPropertyByLabel("Draw Dome");	// Try to get pointer to Draw Dome property		if (drawDomeProperty) {															// If successful then			DzBoolProperty* drawDomePropertyOnOff = dynamic_cast<DzBoolProperty*>(drawDomeProperty);	// findPropertyByLabel returned pointer to set value we need a DzBoolProperty			if (drawDomePropertyOnOff && !drawDomePropertyOnOff->getBoolValue()) {		// If drawDomeProperty is of type DzBoolProperty and is false then				drawDomePropertyOnOff->setBoolValue(true);								// Set value to true			}		}	}	if (!findSceneNodeByClass("DzTonemapperNode")) {									// If DzTonemapperNode not found in scene then		createByClassNodeScript("DzTonemapperNode");									// Create and add a new DzTonemapperNode to the scene	}}

     

    Post edited by surreal on
  • MehdiZangenehBarMehdiZangenehBar Posts: 64
    edited February 25

    ok, thanks, code you please wrap your code using <pre> code </pre> tag? it is very hard to read in single line (that is forum problem)

    Post edited by MehdiZangenehBar on
  • OK, I just saw your code, so there no way to instansiate a class by name or any other trick?
    for the first part, checking classname is not better way?

     

        DzViewportMgr *viewport_manager = dzApp->getInterface()->getViewportMgr();
        DzViewport *viewport = viewport_manager->getActiveViewport();
        Dz3DViewport *viewport_3d = viewport->get3DViewport();
        
        for (int i = 0; i < viewport_manager->getNumUserDrawStyles(); ++i)
        {
            DzUserDrawStyle *style = viewport_manager->getUserDrawStyle(i);
            if (style && QString(style->metaObject()->className()) == "DzIrayDrawStyle")
            {
                viewport_3d->setDrawStyle(style);
                break;
            }
        }
    
  • MehdiZangenehBarMehdiZangenehBar Posts: 64
    edited February 25

    I don't undrstand why DzEnvironmentNode is not exposed in SDK!, but don't undrstand more why a scene node used to store environment data!

    Post edited by MehdiZangenehBar on
  • I also don't undrstand why auto creation of the environment and tonemap nodes will be executed synchronously?! the code should not be executed line by line?!

Sign In or Register to comment.