Announcement

Collapse
No announcement yet.

Creating a simple triangle with GeomStaticMesh

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

  • Creating a simple triangle with GeomStaticMesh

    Hi,
    I try to create a simple triangle to render in maya using the following code:

    Code:
    void setFace(VR::DefIntListParam &p, int faceIndex, int a, int b, int c) {
        p[faceIndex*3+0]=a;
        p[faceIndex*3+1]=b;
        p[faceIndex*3+2]=c;
    }
    void VRayPlane::createVRayPlugin(VR::VRayGeomInfo *geomInfo)
    {
    	if (!geomInfo) return;
    
    	PluginManager *plugman=geomInfo->getPluginManager();
            if (!plugman) return;
    
            bool existing=false;
    
            geomPlugin=geomInfo->newPlugin("GeomStaticMesh",existing);
    
            VR:: DefVectorListParam param_vertices("vertices",0);
            param_vertices.setCount(3);
            param_vertices[0]=VR::Vector(0,0,0);
            param_vertices[1]=VR::Vector(0,0,10);
            param_vertices[2]=VR::Vector(10,0,0);
    
            VR:: DefIntListParam param_faces("faces",0);
            param_faces.setCount(3);
            setFace(param_faces, 0, 0, 1, 2);
    
            VR:: DefVectorListParam param_normals("normals",0);
            param_normals.setCount(1);
            param_normals[0]=VR::Vector(0,1,0);
    
            VR:: DefIntListParam param_faceNormals("faceNormals",0);
            param_faceNormals.setCount(3);
            setFace(param_faceNormals,0,0,0,0);
    
            geomPlugin->setParameter(&param_vertices);
            geomPlugin->setParameter(&param_faces);
            geomPlugin->setParameter(&param_normals);
            geomPlugin->setParameter(&param_faceNormals);
    }
    All the lines are executed, but the render crashes Maya. Anything I did wrongly ?
    Thanks !
    Last edited by lcrivell; 06-12-2015, 11:00 PM.

  • #2
    You must also instance the geometry. Check out the vray_geommeshloader/vray_geommeshloader1 samples.
    V-Ray/PhoenixFD for Maya developer

    Comment


    • #3
      Thanks. I had a look at these samples, but it is not obvious to me how to include them in maya code. Would you have any documentation on "Instancing a Geometry", or at least a quick explanation of what this is ?
      Is it this function from vray_geommeshloader1 which is instancing geometries ?
      Code:
      VRayStaticGeometry* GeomMeshLoader::newInstance(MaterialInterface *_mtl, BSDFInterface *_bsdf, int renderID, VolumetricInterface *volume, LightList *lightList, const TraceTransform &baseTM, int objectID, const tchar *userAttr, int primaryVisibility)
      If yes, when does this function get called ?
      Sorry for my basic question, as I am just in the learning phase.

      Thanks !

      Comment


      • #4
        Yes. "GeomStaticMesh" derives from StaticGeomSourceInterface, which has this newInstance() method. It returns a "VRayStaticGeometry" object, which has compileGeometry(). This compileGeometry() must be called by the compileGeometry() method of an object that has GeomGenInterface (the node that instance geometry) in his own compileGeometry(), like this:

        Code:
        void Node::compileGeometry(VR::VRayRenderer *vray) {
           VRayStaticGeometry* instance = geomSource->newInstance(mtl, bsdf, renderID, volume, lightList, base_tm, objectID, userAttributes, primaryVisibility);
           instance->compileGeometry(vray, tm, times, nsamples);
        }
        In Maya the "Node" and the "Instancer" plugins instance the actual geometry into the scene. The examples I gave you do the same thing.
        V-Ray/PhoenixFD for Maya developer

        Comment


        • #5
          Thanks, I could make it work !
          Now a quick complementary question: the geometry is always related to the (0,0,0) center of Maya. How can I have the geometry following the position, rotation and scale of the MPx node ?

          Comment


          • #6
            You do this with the base_tm/tm parameters from the last example. base_tm is the transformation of your object at the "base" time. This is generally the transformation at the animation start. For example if your transform parameter is called param_tm:

            Code:
            base_tm = param_tm->getTransform(0, vray->getSequenceData().animStart)
            tm that you pass to compileGeometry(), is a pointer to one or more transformations for the motion blur interval, and times is an array with the times at which they were taken. The number of transformation samples is whatever you want to sample from Maya.
            V-Ray/PhoenixFD for Maya developer

            Comment


            • #7
              Thanks. My issue now is that param_tm is set by paramList->getParam("transform"), and paramList is only available in the main class.
              But vray is only available in the Instance.
              How can I match both ? Should I do the base_tm calculation in the instance or in the main class which is creating the instance ?
              Thanks for your patience and support.

              Comment


              • #8
                Not sure I understand the problem. You calculate base_tm in Node::compileGeometry(VR::VRayRenderer *vray) which should pass it to newInstance(). "Node" is your main class that should have parameters about what and where to instance. Like you can see, compileGeometry() has a "vray" parameter.
                V-Ray/PhoenixFD for Maya developer

                Comment


                • #9
                  Mmmmh. In my code I don't have a compileGeometry that is passing to a new instance. Instead I have a compileGeometry which is calling another compileGeometry and a newInstance which is calling another newInstance, so not sure where to best issue this tmParam or of my code is not correct:
                  Code:
                  struct GeomMeshLoaderInstance: VRayStaticGeometry
                  {
                      void compileGeometry(VR::VRayRenderer *vray, VR::TraceTransform *tm, double *times, int tmCount)
                      {
                           <...>             
                           VRayPluginParameter *tmParam=paramList->getParam("transform"); [COLOR="#FF0000"]--> paramList not known[/COLOR]
                           tms[k] = tmParam->getTransform(0, vray->getSequenceData().animStart);
                   
                           meshes[i]->compileGeometry(vray, tms, times, tmCount);
                      }
                  }
                  But the one which is calling newInstance is:
                  Code:
                  VRayStaticGeometry* GeomMeshLoader::newInstance(MaterialInterface *_mtl, BSDFInterface *_bsdf, int renderID, VolumetricInterface *volume, LightList *lightList, const TraceTransform &baseTM, int objectID, const tchar *userAttr, int primaryVisibility)
                  {
                      if (_geomPlugin)
                      {
                          // Get the geometry interface from it
                          StaticGeomSourceInterface *geomSource=static_cast<StaticGeomSourceInterface*>(GET_INTERFACE(_geomPlugin, EXT_STATIC_GEOM_SOURCE));
                  
                      if (geomSource)
                      {
                          GeomMeshLoaderInstance *myInstance=new GeomMeshLoaderInstance;
                          VRayPluginParameter *tmParam=paramList->getParam("transform");
                  <...>
                          // Base transformation
                          TraceTransform bTM=tmParam->getTransform(0, vray->getSequenceData().animStart);  [COLOR="#FF0000"]--> vray not known[/COLOR]
                          myInstance->addMesh(geomSource->newInstance(mtl, bsdf, renderID, volume, lightList, bTM, objectID, infoUserAttr.ptr(), primaryVisibility));
                   <...>
                   }

                  Comment


                  • #10
                    Read my #4 comment, you need also to implement GeomGenInterface with the compileGeometry() from the example.
                    V-Ray/PhoenixFD for Maya developer

                    Comment


                    • #11
                      Thank you. I need to understand how to apply your recommendation in my code (as the code you gave in comment #4 does include this GeomGenInterface). But will try to find out. Thanks for your support.

                      Comment

                      Working...
                      X