Announcement

Collapse
No announcement yet.

First generated node contain unknown information in it's attribute ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • First generated node contain unknown information in it's attribute ?

    hi,

    I try to implement a simple node that expects an input connection with maya's file texture node. Since the input attribute has no connection at the time of node generation i think the input attribute(i.e. "plugin_Texture" in the code snippet) should be NULL. What confusing me is even i set "plugin_Texture" as NULL in constructor, it seems filled in with something before frameBegin call such that I can pass all the condition check even there's not any connection to the "bitmap" attribute of my node. Why settings in constructor not take effect ? And what's filled in "plugin_Texture" parameter ?

    What i want to achieve in frameBegin is before retrieving any related interface (or something else) i can make sure that there exist an effective connection to that attriubte\parameter, how to i fix my code to fit this requirement ?

    Code:
    #include "vrayplugins.h"
    #include "vrayinterface.h"
    #include "vrayrenderer.h"
    #include "vraytexutils.h"
    #include "defparams.h"
    
    // Prevent from "to tchar*" conversion warning ...
    #if (defined __GNUC__) && !(defined __clang__)
    	#pragma GCC diagnostic ignored "-Wwrite-strings"
    #endif //(defined __GNUC__) && !(defined __clang__)
    
    #include "globalnewdelete.cpp"
    
    using namespace VR;
    
    // Parameters
    struct TexSteepParallaxMap_Params: VRayParameterListDesc {
        TexSteepParallaxMap_Params(void) {
            // Add the parameters
    	addParamTexture("bitmap", AColor(1.0f, 0.0f, 0.0f, 1.0f), -1, "The input of bitmap texture");
        }
    };
    
    struct TexSteepParallaxMap: VRayTexture {
        TexSteepParallaxMap(VRayPluginDesc *pluginDesc) : VRayTexture(pluginDesc) {
    	// Set parameter caches
    	paramList->setParamCache("bitmap", &plugin_Texture);
    	plugin_Texture = NULL;
        }
    
        void frameBegin(VR::VRayRenderer* vray);
        void frameEnd(VR::VRayRenderer* vray);
    
        // VRayTexture member function
        AColor getTexColor(const VRayContext &rc);
        void getTexColorBounds(AColor &cmin, AColor &cmax);
        Vector getColorBumpGradient(const VRayContext &rc);
    
        private:
            PluginBase* plugin_Texture;
    };
    
    #define TexSteepParallaxMap_PluginID PluginID(LARGE_CONST(2004110919))
    SIMPLE_PLUGIN_LIBRARY(TexSteepParallaxMap_PluginID, EXT_TEXTURE, "TexSteepParallaxMap", "SteepParallaxMap texture plugin for VRay", TexSteepParallaxMap, TexSteepParallaxMap_Params);
    
    void TexSteepParallaxMap::frameBegin(VR::VRayRenderer *vray) {
        // Call the base class to update the parameter caches
        VRayTexture::frameBegin(vray);
    
        printf("Frame begin called ...\n");
    
        if(plugin_Texture)
        {
            printf("Get valid texture plugin ...\n");
            
            TextureInterface* texture_interface = (TextureInterface*)GET_INTERFACE(plugin_Texture, EXT_TEXTURE); 
            
            if(texture_interface)
            {
                printf("Get valid texture interface ...\n");
            
                const tchar* n = texture_interface->getInterfaceName();    // <----- Maya crash if i uncomment this line !!!!!!!!!!!!
                //printf("IF name = %s\n", n);
            }
        }
    }
    
    void TexSteepParallaxMap::frameEnd(VRayRenderer *vray) {
    	VRayTexture::frameEnd(vray);
    }
    
    
    AColor TexSteepParallaxMap::getTexColor(const VRayContext &rc) {
    
        return AColor(0.0f, 0.0f, 0.0f, 1.0f);
    }
    
    void TexSteepParallaxMap::getTexColorBounds(AColor &cmin, AColor &cmax) {
        cmin = AColor(0.0f, 0.0f, 0.0f, 1.0f);
        cmax = AColor(1.0f, 1.0f, 1.0f, 1.0f);
    }
    
    Vector TexSteepParallaxMap::getColorBumpGradient(const VRayContext &rc) {
        return Vector(0.0f, 0.0f, 0.0f);
    }

  • #2
    You are using a variant of addParamTexture which has a default value, so it gets assigned to "plugin_Texture" if no parameter is set. If you don't wan't this behaviour, don't pass a default value.
    V-Ray/PhoenixFD for Maya developer

    Comment


    • #3
      I use the another addParamTexture function with no default value provided but the "plugin_Texture" variable is still not NULL (I've assigned it as NULL in constructor), is this a bug ?

      Comment


      • #4
        It seems to work fine on my side.
        V-Ray/PhoenixFD for Maya developer

        Comment


        • #5
          Could you help me to check what's wrong with my code ? The parameter is still not NULL at first (i.e. i always get red output no matter there is any texture connect to it). Thanks.

          Code:
          #include "vrayplugins.h"
          #include "vrayinterface.h"
          #include "vrayrenderer.h"
          #include "vraytexutils.h"
          
          #include "meshinfobase.h"
          #include "meshinfointerface.h"
          
          #include "globalnewdelete.cpp"
          
          #if (defined __GNUC__) && !(defined __clang__)
          	#pragma GCC diagnostic ignored "-Wwrite-strings"
          #endif //(defined __GNUC__) && !(defined __clang__)
          
          using namespace VR;
          
          // Parameters
          struct TexInputTypeTest_Params: VRayParameterListDesc {
              TexInputTypeTest_Params(void) {
                  addParamTexture("texture_color");
              }
          };
          
          struct TexInputTypeTest: VRayTexture {
              TexInputTypeTest(VRayPluginDesc *pluginDesc):VRayTexture(pluginDesc) {
                  // Set parameter caches
          		paramList->setParamCache("texture_color", &texture_color);
          		
                  texture_color = NULL;
              }
          
          	void frameBegin(VR::VRayRenderer *vray) {
          	    VRayTexture::frameBegin(vray);
          
                  if(texture_color == NULL)
                      testNull = AColor(0.0f, 1.0f, 0.0f, 1.0f);
                  else
                      testNull = AColor(1.0f, 0.0f, 0.0f, 1.0f);
          	}
          
              AColor getTexColor(const VRayContext &rc);
          	void getTexColorBounds(AColor &cmin, AColor &cmax);
          	Vector getColorBumpGradient(const VRayContext &rc);
              
              virtual PluginInterface* newInterface(InterfaceID id) { return VRayTexture::newInterface(id); }
              
              // VRayTexture Member function
              PluginBase* getPlugin(void) { return static_cast<PluginBase*>(this); }
              
              // These pure virtual functions have to be implemented if support RTTexInterface
              //int getDataSize(void) { return 0; }
              //void getData(float *fdata) { }
              //int getSource(const char *part,const char *outParam,const char *lang,VUtils::ShaderSource &, OCLData &mtlData);
                  
              private:
          		TextureInterface* texture_color;
                  AColor testNull;
          };
          
          #define TexInputTypeTest_PluginID PluginID(LARGE_CONST(2004711829))
          SIMPLE_PLUGIN_LIBRARY(TexInputTypeTest_PluginID, EXT_TEXTURE, "TexInputTypeTest", "Test curious input type of VRay plugin", TexInputTypeTest, TexInputTypeTest_Params);
          
          
          AColor TexInputTypeTest::getTexColor(const VRayContext &rc) {
              return testNull;
          }
          
          void TexInputTypeTest::getTexColorBounds(AColor &cmin, AColor &cmax) {
              cmin = AColor(0.0f, 0.0f, 0.0f, 1.0f);
              cmax = AColor(1.0f, 1.0f, 1.0f, 1.0f);
          }
          
          Vector TexInputTypeTest::getColorBumpGradient(const VRayContext &rc) {
              return Vector(0.0f, 0.0f, 0.0f);
          }

          Comment


          • #6
            I don't think there is something wrong with the code. If you have exported the parameter, even if it's holding just a color, it will support the TextureInterface and act like a texture. TextureInterface doesn't provide a method to detect if it holds a simple color, or a real texture. The only way is to have 2 parameters - one for simple color and one for a texture. And if there is no texture, don't export it. I don't think you can do this with desc.txt though, since it's uncommon to need such information. You will need again post translate Python script.
            V-Ray/PhoenixFD for Maya developer

            Comment


            • #7
              Another way to detect if you have a texture or a flat color is to use the getTexColorBounds() method of the texture. If both the min and max are the same, the input is likely a solid color.

              Something like this:
              Code:
              int isTexure=false;
              if (texture_color!=NULL) {
                  // Figure out if we actually have a texture or just a solid color
                  AColor cmin(0.0f, 0.0f, 0.0f, 0.0f);
                  AColor cmax(1.0f, 1.0f, 1.0f, 1.0f);
                  texture_color->getTexColorBounds(cmin, cmax);
                  if (cmin!=cmax) isTexture=true;
              }

              Best regards,
              Vlado
              Last edited by vlado; 26-10-2015, 11:40 PM.
              I only act like I know everything, Rogers.

              Comment


              • #8
                hi vlado,

                I encounter similar problem when trying to retrieve PluginBase pointer instead of TextureInterface pointer from parameters. I do something as following but this time the "plugin" pointer is always NULL no matter whether there's Maya's 2d Texture connect to this parameter or not. After checking the .vrscene file i found the connection is totally unrecognized. Since the corresponding Vray plugins for Maya 2d texture nodes are all classified with EXT_TEXTURE I think the following code should work. What's wrong with it ?

                I also try to use " GET_INTERFACE(plugin, EXT_TEXTURE)" to get the related interface of the plugin. What really curious is if i use the pointer of TextureInterface as condition the result shows the pointer is also always NULL. This really make me very confusing. Could you provide more detail about this issue ? Thanks.

                Code:
                // Parameters
                struct TexInputTypeTest_Params: VRayParameterListDesc {
                    TexInputTypeTest_Params(void) {
                        addParamPlugin("Plug_Test", EXT_TEXTURE);
                    }
                };
                
                struct TexInputTypeTest: VRayTexture {
                    TexInputTypeTest(VRayPluginDesc *pluginDesc):VRayTexture(pluginDesc) {
                        // Set parameter caches
                	paramList->setParamCache("Plug_Test", &plugin);
                    }
                
                    void frameBegin(VR::VRayRenderer *vray) {
                        VRayTexture::frameBegin(vray);
                
                        if(plugin == NULL)
                            testNull = AColor(1.0f, 0.0f, 0.0f, 1.0f);
                        else
                            testNull = AColor(0.0f, 1.0f, 0.0f, 1.0f);
                	}
                    }
                
                    ...
                
                    private:
                        PluginBase* plugin;
                    
                    ....
                }

                Comment


                • #9
                  You need to add the parameter with addParamTexture() and not with addParamPlugin().

                  Best regards,
                  Vlado
                  I only act like I know everything, Rogers.

                  Comment

                  Working...
                  X