示例#1
0
void SavePRC::WriteNodeModelsToPRCFile(PRCFile &outPRCFile, PRCModelTreeNode modelTreeNode)
{
  if (modelTreeNode.ID != 0)   // Do not create a group for root node
  {
    outPRCFile.begingroup(modelTreeNode.Name.c_str());
  }

  WritePointSetDataToPRCFile(outPRCFile, modelTreeNode.ID);
  WriteLineSetDataToPRCFile(outPRCFile, modelTreeNode.ID);
  WriteMeshDataToPRCFile(outPRCFile, modelTreeNode.ID);
  // Write annotations

  for (MLintVector::iterator it = modelTreeNode.ChildrenIDs.begin(); it != modelTreeNode.ChildrenIDs.end(); ++it) 
  {
    MLint thisChildNodeIndex = *it;
    PRCModelTreeNode nextNode = getNodeFromPRCModelTree(_modelTree, thisChildNodeIndex);

    if (nextNode.ID != -1)  
    {
      WriteNodeModelsToPRCFile(outPRCFile, nextNode);
    }
    else  
    {
      // This can happen only if ThisChildNodeIndex was not found in model tree... and therefore should never happen!
    }
  }

  if (modelTreeNode.ID != 0)   // Do not close group for root node
  {
    outPRCFile.endgroup();
  }

}
void SavePRC::WriteLineSetDataToPRCFile(PRCFile &outPRCFile, MLint modelTreeNode)
{
  const bool perSegmentColor = false;
  const MLuint32 numberOfSegmentColors = 0;
  const MLuint32 numberOfSegmentColorIndices = 0;

  for (PRCObjectInfoVector::iterator it = _prcObjectInfoVector.begin(); it != _prcObjectInfoVector.end(); ++it)
  {
    PRCObjectInfoStruct thisObjectInfo = *it;

    if ( (thisObjectInfo.Type == PRCOBJECTTYPE_LINESET) && (thisObjectInfo.ParentTreeNodeID == modelTreeNode) )
    {
      outPRCFile.begingroup(thisObjectInfo.DisplayName.c_str());

      size_t numLineSets = _lineSetsGeometryVector.size();

      for (size_t s = 0; s < numLineSets; s++)
      {
        LineSetSpecificationStruct thisLineSetGeometry = _lineSetsGeometryVector[s];

        if (thisLineSetGeometry.internalName == thisObjectInfo.InternalName)
        {
          Vector3 startPositionColor = thisLineSetGeometry.positions[0].color;
          double  startPositionAlpha = thisLineSetGeometry.positions[0].alpha;

          size_t numberOfPositions = thisLineSetGeometry.positions.size();
          double (*positionsArray)[3] = new double[numberOfPositions][3];

          for (MLuint32 p = 0; p < numberOfPositions; p++) {
            positionsArray[p][0] = thisLineSetGeometry.positions[p].position.x;
            positionsArray[p][1] = thisLineSetGeometry.positions[p].position.y;
            positionsArray[p][2] = thisLineSetGeometry.positions[p].position.z;
          }

          const size_t numberOfIndices = thisLineSetGeometry.lines.size();            
          const size_t lineIndexArraySize = numberOfIndices*3;
          MLuint32 *lineIndexArray = new MLuint32[lineIndexArraySize];

          for (MLuint32 i = 0; i < numberOfIndices; i++) {
            lineIndexArray[i*3] = 2;     // Number of points in this segment
            lineIndexArray[i*3+1] = thisLineSetGeometry.lines[i].startIndex;
            lineIndexArray[i*3+2] = thisLineSetGeometry.lines[i].endIndex;
          }

          PRC_RGBAColor c(startPositionColor[0],startPositionColor[1],startPositionColor[2],startPositionAlpha);

          if (thisObjectInfo.RGBAColor[3] > 0)  // If alpha value is not = "invisible" -> Use color from UI
          {
            c.Set(thisObjectInfo.RGBAColor[0],thisObjectInfo.RGBAColor[1],thisObjectInfo.RGBAColor[2],thisObjectInfo.RGBAColor[3]);
          }

          outPRCFile.addLines((MLuint32)numberOfPositions, positionsArray, (MLuint32)lineIndexArraySize, lineIndexArray, c, thisLineSetGeometry.lines[0].width, perSegmentColor, numberOfSegmentColors, NULL, numberOfSegmentColorIndices, NULL);

          delete[] positionsArray;
          delete[] lineIndexArray;

        }
      }

      outPRCFile.endgroup();
    }

  }

}