예제 #1
0
//-----------------------------------------------------------------------------
// Name: allocateQuadListGeometry
// Desc: Locks the vertex buffer, and fills indices into the index buffer for the given number of
//     quads.  If this method fails, it makes no allocations, outputs the number of quads
//     that can be successfully allocated and returns false.  If it succeeds, the vertices pointer
//     is set to a valid location for the vertices and it returns true.
//     This method assumes that vertices for the quads are specified in the shape of the letter Z
//     (top left, top right, bottom left, bottom right).
//-----------------------------------------------------------------------------
bool GUILayer::allocateQuadListGeometry(size_t* quads, GUIVertex** vertexBuffer)
{
  // Check the parameters
  if (!quads || !vertexBuffer) return false;

  GUIIndex offset;
  GUIIndex* indices;

  // Allocate the geometry for this quad list
  size_t numQuadsRequested = *quads;
  size_t numVertices = numQuadsRequested * 4;
  size_t numTriangles = numQuadsRequested * 2;
  if (!allocateGeometry(&numVertices, &numTriangles, vertexBuffer, &indices, &offset))
  {
    // Calculate the maximum number of quads allowed by the number of vertices/triangles available
    size_t vertexLimitedQuads = numVertices / 4;
    size_t triangleLimitedQuads = numTriangles / 2;

    // Return the minimum of the number of quads that can be created
    *quads = vertexLimitedQuads < triangleLimitedQuads ? vertexLimitedQuads : triangleLimitedQuads;

    // Fail
    return false;
  }
  else
  {
    // Fill in the allocated indices with geometry data for quads
    for (size_t i = 0; i < numQuadsRequested; ++i)
    {
      indices[0] = offset + 0;
      indices[1] = offset + 1;
      indices[2] = offset + 2;
      indices[3] = offset + 2;
      indices[4] = offset + 1;
      indices[5] = offset + 3;

      indices += 6;
      offset += 4;
    }

    // Success
    return true;
  }
}
/* ******************************************************************************
*  Function Name : instanceCurve()
*
*  Description : Instance a curve
*
*  Input Arguments : GU_Detail *inst_gdp, GU_Detail *mb_gdp
*
*  Return Value : int
*
***************************************************************************** */
int VRAY_clusterThis::instanceCurve(GU_Detail * inst_gdp, GU_Detail * mb_gdp, fpreal theta, long int point_num)
{
#ifdef DEBUG
   std::cout << "VRAY_clusterThis::instanceCurve()" << std::endl;
#endif

   GEO_Point * ppt;
   GU_PrimNURBCurve * myCurve, * myMBCurve;
   uint32 num_vtx;
   int myCurvePointNum = 0;
   UT_Vector4 pt_pos;
   GU_Detail * curve_gdp, * curve_mb_gdp;

   curve_gdp = allocateGeometry();

   GA_RWAttributeRef prim_Cd = curve_gdp->addDiffuseAttribute(GEO_PRIMITIVE_DICT);
   GA_RWAttributeRef prim_Alpha = curve_gdp->addAlphaAttribute(GEO_PRIMITIVE_DICT);
   GA_RWAttributeRef prim_v = curve_gdp->addVelocityAttribute(GEO_PRIMITIVE_DICT);
   GA_RWAttributeRef prim_N = curve_gdp->addNormalAttribute(GEO_PRIMITIVE_DICT);
   GA_RWAttributeRef prim_material = curve_gdp->addStringTuple(GEO_PRIMITIVE_DICT, "shop_materialpath", 1);

   GA_RWAttributeRef pt_Cd = curve_gdp->addDiffuseAttribute(GEO_POINT_DICT);
   GA_RWAttributeRef pt_Alpha = curve_gdp->addAlphaAttribute(GEO_POINT_DICT);
   GA_RWAttributeRef pt_v = curve_gdp->addVelocityAttribute(GEO_POINT_DICT);
   GA_RWAttributeRef pt_N = curve_gdp->addNormalAttribute(GEO_POINT_DICT);
   GA_RWAttributeRef pt_pscale = curve_gdp->addFloatTuple(GA_ATTRIB_POINT, "pscale", 1);
   GA_RWAttributeRef pt_width = curve_gdp->addFloatTuple(GA_ATTRIB_POINT, "width", 1);
   GA_RWAttributeRef pt_id = curve_gdp->addIntTuple(GA_ATTRIB_POINT, "id", 1);
   GA_RWAttributeRef pt_instId = curve_gdp->addIntTuple(GA_ATTRIB_POINT, "inst_id", 1);
   GA_RWAttributeRef pt_material = curve_gdp->addStringTuple(GA_ATTRIB_POINT, "shop_materialpath", 1);

   GA_RWAttributeRef pt_mb_Cd;
   GA_RWAttributeRef pt_mb_Alpha;
   GA_RWAttributeRef pt_mb_v;
   GA_RWAttributeRef pt_mb_N;
   GA_RWAttributeRef pt_mb_pscale;
   GA_RWAttributeRef pt_mb_width;
   GA_RWAttributeRef pt_mb_id;
   GA_RWAttributeRef pt_mb_instId;
   GA_RWAttributeRef pt_mb_material;

   num_vtx = ((myNumCopies * myRecursion) > 4) ? (myNumCopies * myRecursion) : 4;
   myCurve = (GU_PrimNURBCurve *)GU_PrimNURBCurve::build((GU_Detail *)curve_gdp, num_vtx, 4, 0, 1, 1);

   myCurve->setValue<UT_Vector3>(prim_Cd, (const UT_Vector3)myPointAttributes.Cd);
   myCurve->setValue<fpreal>(prim_Alpha, (const fpreal)myPointAttributes.Alpha);
   myCurve->setString(prim_material, myPointAttributes.material);

//   cout << "VRAY_clusterThis::instanceCurve() - num vertices: " << myCurve->getVertexCount() << endl;;
//   cout << "id: "  << myCurve->getPrimitiveId() << endl;
//   cout << "breakCount: "  << myCurve->breakCount() << endl;

   if(myDoMotionBlur == CLUSTER_MB_DEFORMATION) {
         curve_mb_gdp = allocateGeometry();
         myMBCurve = (GU_PrimNURBCurve *)GU_PrimNURBCurve::build((GU_Detail *)curve_mb_gdp, num_vtx, 4, 0, 1, 1);
         pt_mb_Cd = curve_gdp->addDiffuseAttribute(GEO_POINT_DICT);
         pt_mb_Alpha = curve_gdp->addAlphaAttribute(GEO_POINT_DICT);
         pt_mb_v = curve_gdp->addVelocityAttribute(GEO_POINT_DICT);
         pt_mb_N = curve_gdp->addNormalAttribute(GEO_POINT_DICT);
         pt_mb_pscale = curve_gdp->addFloatTuple(GA_ATTRIB_POINT, "pscale", 1);
         pt_mb_width = curve_gdp->addFloatTuple(GA_ATTRIB_POINT, "width", 1);
         pt_mb_id = curve_gdp->addIntTuple(GA_ATTRIB_POINT, "id", 1);
         pt_mb_instId = curve_gdp->addIntTuple(GA_ATTRIB_POINT, "inst_id", 1);
         pt_mb_material = curve_gdp->addStringTuple(GA_ATTRIB_POINT, "shop_materialpath", 1);
      }


   for(int copyNum = 0; copyNum < myNumCopies; copyNum++)
      for(int recursionNum = 0; recursionNum < myRecursion; recursionNum++) {

            VRAY_clusterThis::calculateNewPosition(theta, copyNum, recursionNum);
            ppt = myCurve->getVertexElement(myCurvePointNum).getPt();
            ppt->setPos((float)myPointAttributes.myNewPos[0],
                        (float)myPointAttributes.myNewPos[1],
                        (float)myPointAttributes.myNewPos[2], 1.0);

            // Assign attributes to each point
            ppt->setValue<UT_Vector3>(pt_Cd, (const UT_Vector3)myPointAttributes.Cd);
            ppt->setValue<fpreal>(pt_Alpha, (const fpreal)myPointAttributes.Alpha);
            ppt->setValue<UT_Vector3>(pt_v, (const UT_Vector3)myPointAttributes.v);
            ppt->setValue<UT_Vector3>(pt_N, (const UT_Vector3)myPointAttributes.N);
            ppt->setValue<fpreal>(pt_pscale, (const fpreal)myPointAttributes.pscale);
            ppt->setValue<fpreal>(pt_width, (const fpreal)myPointAttributes.width);
            ppt->setValue<int>(pt_id, (const int)myPointAttributes.id);
            ppt->setValue<int>(pt_instId, (const int)myCurvePointNum);
            ppt->setString(pt_material, myPointAttributes.material);

            if(myDoMotionBlur == CLUSTER_MB_DEFORMATION) {
                  ppt = myMBCurve->getVertexElement(myCurvePointNum).getPt();
                  ppt->setPos((float)myPointAttributes.myNewPos[0],
                              (float)myPointAttributes.myMBPos[1],
                              (float)myPointAttributes.myMBPos[2], 1.0);

                  // Assign attributes to each point
                  ppt->setValue<UT_Vector3>(pt_mb_Cd, (const UT_Vector3)myPointAttributes.Cd);
                  ppt->setValue<fpreal>(pt_mb_Alpha, (const fpreal)myPointAttributes.Alpha);
                  ppt->setValue<UT_Vector3>(pt_mb_v, (const UT_Vector3)myPointAttributes.v);
                  ppt->setValue<UT_Vector3>(pt_mb_N, (const UT_Vector3)myPointAttributes.N);
                  ppt->setValue<fpreal>(pt_mb_pscale, (const fpreal)myPointAttributes.pscale);
                  ppt->setValue<fpreal>(pt_mb_width, (const fpreal)myPointAttributes.width);
                  ppt->setValue<int>(pt_mb_id, (const int)myPointAttributes.id);
                  ppt->setValue<int>(pt_mb_instId, (const int)myInstanceNum);
                  ppt->setString(pt_mb_material, myPointAttributes.material);
               }
//            std::cout << "VRAY_clusterThis::instanceCurve() myCurvePointNum: " << myCurvePointNum << std::endl;
            myCurvePointNum++;
         }

//   myCurve->close();
//   myMBCurve->close ();

   if(myCVEX_Exec)
      VRAY_clusterThis::runCVEX(curve_gdp, curve_mb_gdp, myCVEXFname, CLUSTER_CVEX_POINT);

   if(myCVEX_Exec_prim)
      VRAY_clusterThis::runCVEX(curve_gdp, curve_mb_gdp, myCVEXFname_prim, CLUSTER_CVEX_PRIM);

   inst_gdp->merge(*curve_gdp);
   VRAY_Procedural::freeGeometry(curve_gdp);
   if(myDoMotionBlur == CLUSTER_MB_DEFORMATION) {
         mb_gdp->merge(*curve_mb_gdp);
         VRAY_Procedural::freeGeometry(curve_mb_gdp);
      }

   return 0;
}