7 #ifndef __maya_SurfaceAccessorMaya_h__ 8 #define __maya_SurfaceAccessorMaya_h__ 10 #define FE_SAM_BLIND_DEBUG FALSE 52 m_pIntegerCache(NULL),
54 m_pSpatialVectorCache(NULL),
56 { setName(
"SurfaceAccessorMaya"); }
59 if(m_pSpatialVectorCache)
61 if(m_attribute==SurfaceAccessibleI::e_normal)
63 MVectorArray normalArray;
67 const U32 normalCount=
68 m_faceVertTable.size();
69 for(U32 normalIndex=0;
70 normalIndex<normalCount;
80 normal=m_pSpatialVectorCache
85 rotateVector(m_inverse,
87 [normalIndex],normal);
89 const MVector vector(normal[0],
93 m_faceVertTable[normalIndex];
94 const U32 faceVertCount=
95 rFaceVertArray.size();
96 for(U32 faceVertIndex=0;
97 faceVertIndex<faceVertCount;
100 FaceVert& faceVert=rFaceVertArray
102 normalArray.append(vector);
103 faceList.append(faceVert.m_face);
104 vertexList.append(normalIndex);
108 m_pFnMesh->setFaceVertexNormals(
109 normalArray,faceList,vertexList);
112 delete[] m_pSpatialVectorCache;
116 delete[] m_pBooleanCache;
120 delete[] m_pRealCache;
124 delete[] m_pIntegerCache;
128 delete[] m_pStringCache;
136 using SurfaceAccessorBase::set;
137 using SurfaceAccessorBase::append;
138 using SurfaceAccessorBase::spatialVector;
140 BWORD bind(SurfaceAccessibleI::Element a_element,
141 SurfaceAccessibleI::Attribute a_attribute)
145 m_attribute=a_attribute;
146 if(a_attribute==SurfaceAccessibleI::e_vertices ||
148 SurfaceAccessibleI::e_properties)
151 SurfaceAccessibleI::e_primitive);
156 return bindInternal(a_element,
String());
158 BWORD bind(SurfaceAccessibleI::Element a_element,
166 m_attribute=SurfaceAccessibleI::e_generic;
170 m_attribute=SurfaceAccessibleI::e_position;
174 m_attribute=SurfaceAccessibleI::e_normal;
176 else if(a_name==
"uv")
178 m_attribute=SurfaceAccessibleI::e_uv;
180 else if(a_name==
"Cd")
182 m_attribute=SurfaceAccessibleI::e_color;
184 else if(a_element==SurfaceAccessibleI::e_point &&
185 a_name.match(
"[A-z0-9_]+\\.[A-z0-9_]+"))
189 m_attribute=SurfaceAccessibleI::e_uv;
193 if(!bindInternal(a_element,rename))
198 if(!textureName.
empty())
200 cacheTexture(textureName);
208 virtual String type(
void)
const;
209 virtual U32 count(
void)
const 215 case SurfaceAccessibleI::e_point:
216 return vertexCount();
221 case SurfaceAccessibleI::e_primitive:
222 return m_pFnMesh->numPolygons();
224 case SurfaceAccessibleI::e_detail:
227 case SurfaceAccessibleI::e_pointGroup:
228 return (m_attrName==
"")?
232 case SurfaceAccessibleI::e_primitiveGroup:
233 return (m_attrName==
"")?
234 m_pFnMesh->numPolygons():
243 virtual U32 subCount(U32 a_index)
const 247 if(m_element==SurfaceAccessibleI::e_primitiveGroup
250 if(a_index>=m_groupList.size())
254 return polyVertCount(m_groupList[a_index]);
257 SurfaceAccessibleI::e_primitiveGroup ||
258 m_attribute==SurfaceAccessibleI::e_vertices)
261 SurfaceAccessibleI::e_primitive ||
263 SurfaceAccessibleI::e_primitiveGroup);
265 return polyVertCount(a_index);
271 virtual void set(U32 a_index,U32 a_subIndex,
String a_string)
275 if(m_element==SurfaceAccessibleI::e_detail)
277 setDetail(m_attrName,a_string);
281 if(m_spSurfaceAccessibleI.isValid())
283 m_spSurfaceAccessibleI->lock(I64(
this));
286 assureBlindDataID(
"string");
288 const I32 compID=rawVertex(a_index);
289 const MFn::Type component=componentType();
290 MStatus status=m_pFnMesh->setStringBlindData(
297 if(m_spSurfaceAccessibleI.isValid())
299 m_spSurfaceAccessibleI->unlock(I64(
this));
304 feLog(
"SurfaceAccessorMaya::set(... String)" 306 " setStringBlindData failed\n",
312 m_pStringCache[a_index]=a_string;
315 virtual String string(U32 a_index,U32 a_subIndex=0)
319 if(m_element==SurfaceAccessibleI::e_detail)
321 return getDetail(m_attrName);
326 return m_pStringCache[a_index];
329 if(m_attrName==
".shader")
332 return m_pStringCache[a_index];
335 checkBlindDataID(
"string");
337 if(!m_pFnMesh->isBlindDataTypeUsed(m_blindDataID))
339 #if FE_SAM_BLIND_DEBUG 340 feLog(
"SurfaceAccessorMaya::string" 341 " \"%s\" blind data %d not used\n",
342 m_attrName.c_str(),m_blindDataID);
346 const MFn::Type component=componentType();
347 if(!m_pFnMesh->hasBlindData(component))
349 #if FE_SAM_BLIND_DEBUG 350 feLog(
"SurfaceAccessorMaya::string" 351 " no component blind data\n");
355 const I32 compID=rawVertex(a_index);
356 if(!m_pFnMesh->hasBlindDataComponentId(compID,
359 #if FE_SAM_BLIND_DEBUG 360 feLog(
"SurfaceAccessorMaya::string" 362 " index %d compID %d\n",a_index,compID);
367 const I32 size=count();
371 MStatus status=m_pFnMesh->getStringBlindData(
379 feLog(
"SurfaceAccessorMaya::integer" 380 " getStringBlindData failed\n");
386 m_pStringCache=
new String[size];
387 for(I32 m=0;m<size;m++)
389 m_pStringCache[m]=
"";
392 const I32 found=compIDs.
length();
393 for(I32 m=0;m<found;m++)
395 FEASSERT(compIDs[m]<size);
396 m_pStringCache[compIDs[m]]=data[m].asChar();
399 return m_pStringCache[a_index];
402 virtual void set(U32 a_index,U32 a_subIndex,I32 a_integer)
406 if(m_element==SurfaceAccessibleI::e_detail)
410 setDetail(m_attrName,text);
414 if(m_spSurfaceAccessibleI.isValid())
416 m_spSurfaceAccessibleI->lock(I64(
this));
422 SurfaceAccessibleI::e_pointGroup ||
424 SurfaceAccessibleI::e_primitiveGroup);
426 const BWORD useBool=FALSE;
429 assureBlindDataID(useBool?
"boolean":
"integer");
431 const I32 compID=rawVertex(a_index);
432 const MFn::Type component=componentType();
436 const bool data=a_integer;
437 MStatus status=m_pFnMesh->setBoolBlindData(
445 feLog(
"SurfaceAccessorMaya::set(... I32)" 447 " setBoolBlindData failed\n",
453 const I32
data=a_integer;
454 MStatus status=m_pFnMesh->setIntBlindData(
462 feLog(
"SurfaceAccessorMaya::set(... I32)" 464 " setIntBlindData failed\n",
469 if(m_spSurfaceAccessibleI.isValid())
471 m_spSurfaceAccessibleI->unlock(I64(
this));
474 if(m_attrName==
"POLY_FORMAT")
476 m_cachePolyFormat=PolyFormat(a_integer);
481 m_pIntegerCache[a_index]=a_integer;
484 virtual I32 integer(U32 a_index,U32 a_subIndex=0)
488 if(m_element==SurfaceAccessibleI::e_detail)
490 return getDetail(m_attrName).integer();
495 return m_pIntegerCache[a_index];
500 SurfaceAccessibleI::e_pointGroup ||
502 SurfaceAccessibleI::e_primitiveGroup);
504 const BWORD useBool=isGroup;
506 const BWORD useBool=FALSE;
509 checkBlindDataID(useBool?
"boolean":
"integer");
511 if(isGroup && m_groupList.size())
513 FEASSERT(a_index<m_groupList.size());
514 return (a_index>=m_groupList.size())?
515 0: m_groupList[a_index];
519 SurfaceAccessibleI::e_primitiveGroup ||
520 m_attribute==SurfaceAccessibleI::e_vertices)
523 SurfaceAccessibleI::e_primitive ||
525 SurfaceAccessibleI::e_primitiveGroup);
527 I32 primitiveIndex=a_index;
529 SurfaceAccessibleI::e_primitiveGroup &&
532 FEASSERT(a_index<m_groupList.size());
533 if(a_index>=m_groupList.size())
537 primitiveIndex=m_groupList[a_index];
540 U32 subs=m_pFnMesh->polygonVertexCount(
542 FEASSERT(a_subIndex<subs);
548 MIntArray vertexList;
550 m_pFnMesh->getPolygonVertices(
551 primitiveIndex,vertexList);
553 const U32 raw=vertexList[a_subIndex];
555 return logicalVertex(raw);
558 if(m_attribute==SurfaceAccessibleI::e_properties)
561 SurfaceAccessibleI::e_primitive ||
563 SurfaceAccessibleI::e_primitiveGroup);
565 const PolyFormat format=polyFormat(a_index);
566 return format==e_openPoly;
569 if(!m_pFnMesh->isBlindDataTypeUsed(m_blindDataID))
571 #if FE_SAM_BLIND_DEBUG 572 feLog(
"SurfaceAccessorMaya::integer" 573 " \"%s\" blind data %d not used\n",
574 m_attrName.c_str(),m_blindDataID);
578 const MFn::Type component=componentType();
579 if(!m_pFnMesh->hasBlindData(component))
581 #if FE_SAM_BLIND_DEBUG 582 feLog(
"SurfaceAccessorMaya::integer" 583 " no component blind data\n");
587 const I32 compID=rawVertex(a_index);
588 if(!m_pFnMesh->hasBlindDataComponentId(compID,
591 #if FE_SAM_BLIND_DEBUG 592 feLog(
"SurfaceAccessorMaya::integer" 594 " index %d compID %d\n",a_index,compID);
601 MStatus status=m_pFnMesh->getIntBlindData(
609 feLog(
"SurfaceAccessorMaya::integer" 610 " getIntBlindData failed\n");
615 const I32 size=count();
621 MStatus status=m_pFnMesh->getBoolBlindData(
629 feLog(
"SurfaceAccessorMaya::integer" 630 " getBoolBlindData failed\n");
636 MStatus status=m_pFnMesh->getIntBlindData(
644 feLog(
"SurfaceAccessorMaya::integer" 645 " getIntBlindData failed\n");
650 m_pIntegerCache=
new I32[size];
651 for(I32 m=0;m<size;m++)
653 m_pIntegerCache[m]=0;
656 const I32 found=compIDs.length();
657 for(I32 m=0;m<found;m++)
659 const I32 rawIndex=compIDs[m];
660 FEASSERT(rawIndex>=0);
663 logicalVertex(rawIndex);
665 FEASSERT(index<size);
666 m_pIntegerCache[index]=data[m];
669 return m_pIntegerCache[a_index];
672 virtual I32 duplicate(U32 index,U32 subIndex=0)
677 virtual I32 append(SurfaceAccessibleI::Form a_form)
679 if(m_element==SurfaceAccessibleI::e_point)
687 const MPoint origin(0.0,0.0,0.0);
689 MPointArray vertexArray;
690 m_pFnMesh->getPoints(vertexArray);
692 feLog(
"SurfaceAccessorMaya::append was %d\n",
693 vertexArray.length());
696 vertexArray.append(origin);
698 m_pFnMesh->setPoints(vertexArray);
700 const int vertexId=count();
701 m_pFnMesh->setPoint(vertexId,origin);
704 feLog(
"SurfaceAccessorMaya::append now %d\n",
710 if(m_element==SurfaceAccessibleI::e_primitive)
712 const bool mergeVertices=
false;
714 MPointArray vertexArray;
715 m_pFnMesh->addPolygon(
716 (
const MPointArray&)vertexArray,
724 virtual I32 append(I32 a_integer,SurfaceAccessibleI::Form a_form)
726 if(m_element!=SurfaceAccessibleI::e_primitive ||
727 m_attribute!=SurfaceAccessibleI::e_vertices)
729 append(U32(0),a_integer);
735 MPointArray vertexArray;
736 vertexArray.setLength(a_integer);
739 for(I32 vertIndex=0;vertIndex<a_integer;vertIndex++)
741 vertexArray.set(vertIndex,0.01*vertIndex,0.0,
742 0.001*vertIndex*vertIndex);
745 const bool mergeVertices=
false;
746 m_pFnMesh->addPolygon(
747 (
const MPointArray&)vertexArray,
750 return m_pFnMesh->numPolygons()-1;
752 virtual void append(U32 a_index,I32 a_integer)
754 if(m_element==SurfaceAccessibleI::e_pointGroup ||
756 SurfaceAccessibleI::e_primitiveGroup)
760 set(a_integer,U32(0),I32(
true));
762 for(U32 m=0;m<m_groupList.size();m++)
764 if(m_groupList[m]==a_integer)
769 m_groupList.push_back(a_integer);
775 virtual void remove(U32 a_index,I32 a_integer)
777 if(m_element==SurfaceAccessibleI::e_pointGroup ||
779 SurfaceAccessibleI::e_primitiveGroup)
781 set(a_index,U32(0),I32(
false));
782 for(U32 m=0;m<m_groupList.size();m++)
784 if(m_groupList[m]==I32(a_index))
787 m_groupList.begin()+m);
793 virtual void set(U32 a_index,U32 a_subIndex,Real a_real)
797 if(m_element==SurfaceAccessibleI::e_detail)
801 setDetail(m_attrName,text);
805 if(m_element==SurfaceAccessibleI::e_detail)
809 MPlug plug=m_pFnMesh->findPlug(
810 m_attrName.c_str(),status);
812 if(status && !plug.isNull())
814 plug.setDouble(a_real);
819 MFnNumericAttribute numAttr;
820 MObject attrObject=numAttr.create(
821 m_attrName.c_str(),m_attrName.c_str(),
822 MFnNumericData::kDouble,a_real,&status);
825 feLog(
"SurfaceAccessorMaya::set(... Real)" 826 " index %d failed to create" 827 " detail attribute \"%s\"" 829 a_index,m_attrName.c_str(),
830 status.errorString().asChar());
833 status=m_pFnMesh->addAttribute(attrObject,
834 MFnDependencyNode::kLocalDynamicAttr);
837 feLog(
"SurfaceAccessorMaya::set(... Real)" 838 " index %d failed to add" 839 " detail attribute \"%s\"" 841 a_index,m_attrName.c_str(),
842 status.errorString().asChar());
848 if(m_spSurfaceAccessibleI.isValid())
850 m_spSurfaceAccessibleI->lock(I64(
this));
853 assureBlindDataID(
"real");
855 const I32 compID=rawVertex(a_index);
857 const double data=a_real;
858 const MFn::Type component=componentType();
859 MStatus status=m_pFnMesh->setDoubleBlindData(
866 if(m_spSurfaceAccessibleI.isValid())
868 m_spSurfaceAccessibleI->unlock(I64(
this));
873 feLog(
"SurfaceAccessorMaya::set(... Real)" 874 " index %d compID %d" 875 " setDoubleBlindData failed:" 878 status.errorString().asChar());
883 m_pRealCache[a_index]=a_real;
886 virtual Real real(U32 a_index,U32 a_subIndex=0)
890 if(m_element==SurfaceAccessibleI::e_detail)
892 return getDetail(m_attrName).real();
897 return m_pRealCache[a_index];
900 checkBlindDataID(
"real");
902 if(!m_pFnMesh->isBlindDataTypeUsed(m_blindDataID))
904 #if FE_SAM_BLIND_DEBUG 905 feLog(
"SurfaceAccessorMaya::real" 906 " \"%s\" blind data %d not used\n",
907 m_attrName.c_str(),m_blindDataID);
912 const MFn::Type component=componentType();
913 if(!m_pFnMesh->hasBlindData(component))
915 #if FE_SAM_BLIND_DEBUG 916 feLog(
"SurfaceAccessorMaya::real" 917 " no component blind data\n");
922 const I32 compID=rawVertex(a_index);
923 if(!m_pFnMesh->hasBlindDataComponentId(compID,
926 #if FE_SAM_BLIND_DEBUG 927 feLog(
"SurfaceAccessorMaya::real" 929 " index %d compID %d\n",a_index,compID);
934 const I32 size=count();
938 MStatus status=m_pFnMesh->getDoubleBlindData(
946 feLog(
"SurfaceAccessorMaya::real" 947 " getDoubleBlindData failed\n");
951 m_pRealCache=
new Real[size];
952 for(I32 m=0;m<size;m++)
954 m_pRealCache[m]=Real(0);
957 const I32 found=compIDs.length();
958 for(I32 m=0;m<found;m++)
960 const I32 rawIndex=compIDs[m];
961 FEASSERT(rawIndex>=0);
964 logicalVertex(rawIndex);
966 FEASSERT(index<size);
967 m_pRealCache[index]=data[m];
970 return m_pRealCache[a_index];
973 virtual void set(U32 a_index,U32 a_subIndex,
978 if(m_element==SurfaceAccessibleI::e_detail)
982 a_vector[0],a_vector[1],a_vector[2]);
983 setDetail(m_attrName,text);
988 if(m_element==SurfaceAccessibleI::e_detail)
992 MPlug plug=m_pFnMesh->findPlug(
993 m_attrName.c_str(),status);
995 if(status && !plug.isNull())
997 const U32 size=plug.numElements();
999 for(U32 m=0;m<size && m<3;m++)
1001 plug[m].setDouble(a_vector[m]);
1007 MFnNumericAttribute numAttr;
1008 MObject attrObject=numAttr.create(
1009 m_attrName.c_str(),m_attrName.c_str(),
1010 MFnNumericData::k3Double,0,&status);
1013 feLog(
"SurfaceAccessorMaya::" 1014 "set(... SpatialVector)" 1015 " index %d failed to create" 1016 " detail attribute \"%s\"" 1017 " because \"%s\"\n",
1018 a_index,m_attrName.c_str(),
1019 status.errorString().asChar());
1022 numAttr.setDefault((
double)a_vector[0],
1023 (
double)a_vector[1],
1024 (
double)a_vector[2]);
1026 status=m_pFnMesh->addAttribute(attrObject,
1027 MFnDependencyNode::kLocalDynamicAttr);
1030 feLog(
"SurfaceAccessorMaya::" 1031 "set(... SpatialVector)" 1032 " index %d failed to add" 1033 " detail attribute \"%s\"" 1034 " because \"%s\"\n",
1035 a_index,m_attrName.c_str(),
1036 status.errorString().asChar());
1043 if(m_element==SurfaceAccessibleI::e_pointGroup)
1045 if(a_index>=m_groupList.size())
1049 a_index=m_groupList[a_index];
1052 SurfaceAccessibleI::e_primitiveGroup ||
1053 m_attribute==SurfaceAccessibleI::e_vertices)
1056 SurfaceAccessibleI::e_primitiveGroup &&
1059 if(a_index>=m_groupList.size())
1063 a_index=m_groupList[a_index];
1066 FEASSERT(m_element==
1067 SurfaceAccessibleI::e_primitive ||
1069 SurfaceAccessibleI::e_primitiveGroup);
1072 m_pFnMesh->polygonVertexCount(a_index);
1073 FEASSERT(a_subIndex<subs);
1074 if(a_subIndex>=subs)
1079 MIntArray vertexList;
1080 MStatus status=m_pFnMesh->getPolygonVertices(
1081 a_index,vertexList);
1086 transformVector(m_inverse,a_vector,local);
1093 MPoint point(local[0],local[1],local[2]);
1095 const U32 raw=vertexList[a_subIndex];
1096 status=m_pFnMesh->setPoint(raw,point);
1098 const PolyFormat format=polyFormat(a_index);
1099 if(format==e_openPoly)
1102 vertexList[subs-1-a_subIndex];
1103 status=m_pFnMesh->setPoint(raw2,point);
1110 if(m_attribute==SurfaceAccessibleI::e_position ||
1111 m_element==SurfaceAccessibleI::e_pointGroup)
1116 transformVector(m_inverse,a_vector,local);
1123 MPoint point(local[0],local[1],local[2]);
1125 const U32 raw=rawVertex(a_index);
1126 MStatus status=m_pFnMesh->setPoint(raw,point);
1127 const PolyFormat format=polyFormat(0);
1128 if(format==e_openPoly)
1130 const U32 twin=twinVertex(a_index);
1131 status=m_pFnMesh->setPoint(twin,point);
1138 if(m_element==SurfaceAccessibleI::e_point &&
1139 m_attribute==SurfaceAccessibleI::e_uv)
1142 const U32 raw=rawVertex(a_index);
1143 if(!m_faceVertTable.size())
1145 initializeFaceVertArray();
1148 m_faceVertTable[raw];
1149 const U32 faceVertCount=rFaceVertArray.size();
1151 for(U32 faceVertIndex=0;
1152 faceVertIndex<faceVertCount;
1156 rFaceVertArray[faceVertIndex];
1159 m_pFnMesh->getPolygonUVid(faceVert.m_face,
1160 faceVert.m_vert,uvId);
1162 m_pFnMesh->setUV(uvId,
1163 a_vector[0],a_vector[1]);
1168 if(m_element==SurfaceAccessibleI::e_primitive &&
1169 m_attribute==SurfaceAccessibleI::e_uv)
1172 const U32 raw=rawVertex(a_index);
1175 m_pFnMesh->getPolygonUVid(raw,a_subIndex,uvId);
1177 m_pFnMesh->setUV(uvId,a_vector[0],a_vector[1]);
1181 if(m_element==SurfaceAccessibleI::e_point &&
1182 m_attribute==SurfaceAccessibleI::e_normal)
1184 MVector vector(a_vector[0],a_vector[1],
1187 const U32 raw=rawVertex(a_index);
1191 if(!m_faceVertTable.size())
1193 MFloatVectorArray normals;
1194 status=m_pFnMesh->getNormals(normals);
1195 if(!normals.length())
1197 feLog(
"SurfaceAccessorMaya::set" 1199 " no normals (%d points)\n",
1204 initializeFaceVertArray();
1209 const U32 normalCount=
1210 m_faceVertTable.size();
1216 m_pSpatialVectorCache=
1219 new BWORD[normalCount];
1222 for(U32 normalIndex=0;
1223 normalIndex<normalCount;
1226 MFloatVector& normal=
1227 normals[normalIndex];
1228 rotateVector(m_transform,
1230 normal[0],normal[1],
1232 m_pSpatialVectorCache
1235 m_pBooleanCache[normalIndex]=FALSE;
1240 for(U32 normalIndex=0;
1241 normalIndex<normalCount;
1244 MFloatVector& normal=
1245 normals[normalIndex];
1246 m_pSpatialVectorCache[normalIndex]=
1248 normal[1],normal[2]);
1250 m_pBooleanCache[normalIndex]=FALSE;
1255 FEASSERT(raw<m_faceVertTable.size());
1256 m_pSpatialVectorCache[raw]=a_vector;
1257 m_pBooleanCache[raw]=TRUE;
1262 if(m_spSurfaceAccessibleI.isValid())
1264 m_spSurfaceAccessibleI->lock(I64(
this));
1267 assureBlindDataID(
"vector3");
1269 MPoint point(a_vector[0],a_vector[1],a_vector[2]);
1271 I32 compID=rawVertex(a_index);
1272 for(U32 n=0;n<3;n++)
1274 const double data=point[n];
1276 name.
sPrintf(
"%s_%c",m_attrName.c_str(),
'x'+n);
1278 const MFn::Type component=componentType();
1279 MStatus status=m_pFnMesh->setDoubleBlindData(
1287 feLog(
"SurfaceAccessorMaya::set" 1288 "(... SpatialVector)" 1289 " index %d %d compID %d" 1290 " setDoubleBlindData failed:" 1293 status.errorString().asChar());
1297 if(m_spSurfaceAccessibleI.isValid())
1299 m_spSurfaceAccessibleI->unlock(I64(
this));
1302 if(m_pSpatialVectorCache)
1304 m_pSpatialVectorCache[a_index]=a_vector;
1307 virtual SpatialVector spatialVector(U32 a_index,U32 a_subIndex=0)
1309 FEASSERT(m_pFnMesh);
1311 if(m_element==SurfaceAccessibleI::e_detail)
1313 const String text=getDetail(m_attrName);
1316 sscanf(text.
c_str(),
"%f %f %f",&x,&y,&z);
1321 if(m_pSpatialVectorCache)
1323 return m_pSpatialVectorCache[a_index];
1328 if(m_element==SurfaceAccessibleI::e_pointGroup)
1330 if(a_index>=m_groupList.size())
1334 const U32 raw=rawVertex(m_groupList[a_index]);
1337 m_pFnMesh->getPoint(raw,point);
1340 SurfaceAccessibleI::e_primitiveGroup ||
1341 m_attribute==SurfaceAccessibleI::e_vertices)
1344 SurfaceAccessibleI::e_primitiveGroup &&
1347 if(a_index>=m_groupList.size())
1351 a_index=m_groupList[a_index];
1354 FEASSERT(m_element==
1355 SurfaceAccessibleI::e_primitive ||
1357 SurfaceAccessibleI::e_primitiveGroup);
1360 m_pFnMesh->polygonVertexCount(a_index);
1361 FEASSERT(a_subIndex<subs);
1362 if(a_subIndex>=subs)
1367 MIntArray vertexList;
1368 MStatus status=m_pFnMesh->getPolygonVertices(
1369 a_index,vertexList);
1371 const U32 raw=vertexList[a_subIndex];
1372 status=m_pFnMesh->getPoint(raw,point);
1374 else if(m_attribute==SurfaceAccessibleI::e_position)
1376 const U32 raw=rawVertex(a_index);
1378 m_pFnMesh->getPoint(raw,point);
1380 else if(m_element==SurfaceAccessibleI::e_point &&
1381 (m_attribute==SurfaceAccessibleI::e_normal
1382 || m_attribute==SurfaceAccessibleI::e_uv))
1385 const U32 raw=rawVertex(a_index);
1386 if(!m_faceVertTable.size())
1388 initializeFaceVertArray();
1391 m_faceVertTable[raw];
1392 const U32 faceVertCount=rFaceVertArray.size();
1399 FaceVert& faceVert=rFaceVertArray[0];
1401 if(m_attribute==SurfaceAccessibleI::e_uv)
1404 m_pFnMesh->getPolygonUVid(faceVert.m_face,
1405 faceVert.m_vert,uvId);
1409 m_pFnMesh->getUV(uvId,u,v);
1415 m_pFnMesh->getFaceVertexNormal(
1416 faceVert.m_face,raw,vector);
1421 vector[1],vector[2]);
1425 rotateVector(m_transform,
1427 vector[1],vector[2]),world);
1442 else if(m_element==SurfaceAccessibleI::e_primitive
1443 && m_attribute==SurfaceAccessibleI::e_uv)
1446 const U32 raw=rawVertex(a_index);
1449 m_pFnMesh->getPolygonUVid(raw,a_subIndex,uvId);
1453 m_pFnMesh->getUV(uvId,u,v);
1461 checkBlindDataID(
"vector3");
1463 if(!m_pFnMesh->isBlindDataTypeUsed(
1466 #if FE_SAM_BLIND_DEBUG 1467 feLog(
"SurfaceAccessorMaya::spatialVector" 1468 " \"%s\" blind data %d not used\n",
1469 m_attrName.c_str(),m_blindDataID);
1474 const MFn::Type component=componentType();
1475 if(!m_pFnMesh->hasBlindData(component))
1477 #if FE_SAM_BLIND_DEBUG 1478 feLog(
"SurfaceAccessorMaya::spatialVector" 1479 " no component blind data\n");
1484 if(!m_pFnMesh->hasBlindDataComponentId(
1485 rawVertex(a_index),component))
1487 #if FE_SAM_BLIND_DEBUG 1488 feLog(
"SurfaceAccessorMaya::spatialVector" 1491 a_index,rawVertex(a_index));
1496 const I32 size=count();
1498 for(I32 m=0;m<size;m++)
1500 fe::set(m_pSpatialVectorCache[m]);
1503 for(U32 n=0;n<3;n++)
1507 m_attrName.c_str(),
'x'+n);
1512 m_pFnMesh->getDoubleBlindData(
1520 feLog(
"SurfaceAccessorMaya::" 1522 " getDoubleBlindData failed\n");
1524 delete m_pSpatialVectorCache;
1525 m_pSpatialVectorCache=NULL;
1530 const I32 found=compIDs.length();
1531 for(I32 m=0;m<found;m++)
1533 const I32 rawIndex=compIDs[m];
1534 FEASSERT(rawIndex>=0);
1537 logicalVertex(rawIndex);
1539 FEASSERT(index<size);
1540 m_pSpatialVectorCache[index][n]=
1545 return m_pSpatialVectorCache[a_index];
1551 transformVector(m_transform,world,world);
1558 void setMeshNode(
const MObject a_meshNode)
1560 m_meshNode=a_meshNode;
1562 void setMeshData(
const MDataHandle a_meshData)
1564 m_meshData=a_meshData;
1573 m_pFnMesh=
new MFnMesh(m_meshData.asMesh());
1575 m_cachePolyFormat=PolyFormat(e_unknown);
1578 const MDataHandle meshData(
void)
1579 {
return m_meshData; }
1580 void setGroupIt(MItGeometry* a_pGroupIt)
1581 { m_pGroupIt=a_pGroupIt; }
1583 void clearTransform(
void)
1585 m_useTransform=FALSE;
1589 m_useTransform=TRUE;
1590 m_transform=a_transform;
1591 invert(m_inverse,m_transform);
1596 { m_spMaster=a_spMaster; }
1600 static MFn::Type componentTypeOfElement(
1601 SurfaceAccessibleI::Element a_element)
1612 case SurfaceAccessibleI::e_point:
1613 case SurfaceAccessibleI::e_pointGroup:
1614 return MFn::kMeshVertComponent;
1616 case SurfaceAccessibleI::e_vertex:
1618 return MFn::kMeshFaceVertComponent;
1620 case SurfaceAccessibleI::e_primitive:
1621 case SurfaceAccessibleI::e_primitiveGroup:
1622 return MFn::kMeshPolygonComponent;
1624 case SurfaceAccessibleI::e_detail:
1631 return MFn::kInvalid;
1634 static String readDetailAt(MDataHandle a_meshData,I32 a_id);
1635 static void writeDetailAt(MDataHandle a_meshData,I32 a_id,
1636 const String& a_rString);
1637 static void removeDetailAt(MDataHandle a_meshData,I32 a_id);
1638 static BWORD removeDetailFor(MDataHandle a_meshData,
1640 static I32 findDetailKey(MDataHandle a_meshData,
1641 const String& a_rKey,BWORD a_createMissing);
1642 static void dumpDetail(MDataHandle a_meshData);
1645 virtual BWORD bindInternal(SurfaceAccessibleI::Element a_element,
1648 m_element=SurfaceAccessibleI::e_point;
1649 if(a_element>=0 && a_element<=5)
1651 m_element=a_element;
1660 void cacheShaders(
void);
1661 void cacheTexture(
String a_textureName);
1662 void updateGroupList(
void);
1664 void checkBlindDataID(
const String& a_attrType)
1666 #if FE_SAM_BLIND_DEBUG 1667 feLog(
"SurfaceAccessorMaya::checkBlindDataID" 1668 " attr %d type \"%s\"\n",
1669 m_attribute,a_attrType.
c_str());
1672 if(m_attribute==SurfaceAccessibleI::e_generic &&
1675 m_attrType=a_attrType;
1676 if(!m_attrName.empty())
1679 m_attrName+
":"+m_attrType;
1681 m_spMaster->catalog()
1682 ->catalogOrDefault<I32>(
1683 "MayaBlindID",attrKey,-1);
1684 #if FE_SAM_BLIND_DEBUG 1685 feLog(
"SurfaceAccessorMaya::" 1687 " found id %d for \"%s\"\n",
1688 m_blindDataID,attrKey.c_str());
1693 void assureBlindDataID(
const String& a_attrType)
1695 #if FE_SAM_BLIND_DEBUG 1696 feLog(
"SurfaceAccessorMaya::assureBlindDataID" 1697 " attr %d type \"%s\"\n",
1698 m_attribute,a_attrType.
c_str());
1701 checkBlindDataID(a_attrType);
1702 if(m_attribute==SurfaceAccessibleI::e_generic &&
1705 m_blindDataID=createBlindDataID(
1706 m_attrName,m_attrType);
1707 #if FE_SAM_BLIND_DEBUG 1708 feLog(
"SurfaceAccessorMaya::assureBlindDataID" 1709 " created new id %d for \"%s\"\n",
1710 m_blindDataID,m_attrName.c_str());
1715 I32 getBlindDataID(
String a_attrName,
String a_attrType,
1717 I32 createBlindDataID(
String a_attrName,
String a_attrType);
1719 void checkPolyFormatID(
void)
1721 if(m_polyFormatID<0)
1723 const String attrKey=
"POLY_FORMAT:I32";
1725 m_spMaster->catalog()->catalog<I32>(
1726 "MayaBlindID",attrKey,-1);
1729 void assurePolyFormatID(
void)
1731 checkPolyFormatID();
1732 if(m_polyFormatID<0)
1734 m_polyFormatID=createBlindDataID(
1735 "POLY_FORMAT",
"integer");
1741 FEASSERT(m_pFnMesh);
1743 m_pFnMesh->getIntBlindData(0,
1744 MFn::kMeshPolygonComponent,
1745 m_polyFormatID,
"POLY_FORMAT",
1748 PolyFormat polyFormat(U32 a_index)
const 1752 if(m_cachePolyFormat!=e_unknown)
1754 return m_cachePolyFormat;
1758 ->assurePolyFormatID();
1760 PolyFormat format=e_unknown;
1763 MStatus status=m_pFnMesh->getIntBlindData(
1765 MFn::kMeshPolygonComponent,
1771 format=PolyFormat(data);
1775 feLog(
"SurfaceAccessorMaya::polyFormat" 1776 " getIntegerBlindData failed\n");
1779 if(format==e_unknown)
1781 format=guessPolyFormat();
1783 if(format==e_unknown)
1785 format=e_closedPoly;
1789 m_cachePolyFormat=format;
1790 return m_cachePolyFormat;
1793 PolyFormat guessPolyFormat(
void)
const;
1795 U32 polyVertCount(U32 a_index)
const 1797 FEASSERT(m_pFnMesh);
1800 m_pFnMesh->polygonVertexCount(a_index);
1801 const PolyFormat format=polyFormat(a_index);
1810 return rawCount? 1: 0;
1817 U32 vertexCount(
void)
const 1822 if(!m_pFnMesh->hasBlindData(
1823 MFn::kMeshPolygonComponent,m_polyFormatID))
1826 if(m_pFnMesh->numVertices()!=countVertices())
1828 feLog(
"SurfaceAccessorMaya::vertexCount" 1830 " bogus numVertices %d" 1833 m_pFnMesh->numVertices(),
1836 const U32 primitiveCount=
1837 m_pFnMesh->numPolygons();
1838 for(U32 primitiveIndex=0;
1839 primitiveIndex<primitiveCount;
1842 feLog(
" prim %d/%d\n",
1843 primitiveIndex,primitiveCount);
1845 MIntArray vertexList;
1846 m_pFnMesh->getPolygonVertices(
1847 primitiveIndex,vertexList);
1850 m_pFnMesh->polygonVertexCount(
1853 subIndex<subCount;subIndex++)
1856 vertexList[subIndex];
1858 feLog(
" sub %d/%d index %d\n",
1859 subIndex,subCount,raw);
1863 return countVertices();
1867 return m_pFnMesh->numVertices();
1870 return countVertices();
1872 U32 countVertices(
void)
const 1876 U32 primitiveCount=m_pFnMesh->numPolygons();
1877 for(U32 index=0;index<primitiveCount;index++)
1879 sum+=polyVertCount(index);
1883 void resetMark(
void)
1889 U32 logicalVertex(U32 a_rawVertex)
1894 if(!m_pFnMesh->hasBlindData(
1895 MFn::kMeshPolygonComponent,m_polyFormatID))
1900 if(m_cachePolyFormat!=e_openPoly)
1907 if(a_rawVertex<m_markRawVertex)
1911 feX(
"SurfaceAccessorMaya::rawVertex",
1912 "mark data corrupt");
1917 m_markVertex-=polyVertCount(m_markPoly);
1919 m_pFnMesh->polygonVertexCount(
1923 const U32 subIndex=a_rawVertex-m_markRawVertex;
1924 const U32 subs=polyVertCount(m_markPoly);
1927 return m_markVertex+subIndex;
1929 else if(subIndex<subs*2)
1931 return m_markVertex+(subs*2-1-subIndex);
1933 const U32 primitiveCount=
1934 m_pFnMesh->numPolygons();
1938 if(m_markPoly>=primitiveCount-1)
1940 feX(
"SurfaceAccessorMaya::logicalVertex",
1941 "excessive point index");
1943 m_markVertex+=polyVertCount(m_markPoly);
1945 m_pFnMesh->polygonVertexCount(
1950 U32 rawVertex(U32 a_logicalVertex)
1952 const PolyFormat format=polyFormat(a_logicalVertex);
1954 if(format!=e_openPoly)
1956 return a_logicalVertex;
1961 if(a_logicalVertex<m_markVertex)
1965 feX(
"SurfaceAccessorMaya::rawVertex",
1966 "mark data corrupt");
1971 m_markVertex-=polyVertCount(m_markPoly);
1973 m_pFnMesh->polygonVertexCount(
1977 const U32 subIndex=a_logicalVertex-m_markVertex;
1978 const U32 subs=polyVertCount(m_markPoly);
1981 return m_markRawVertex+subIndex;
1983 const U32 primitiveCount=
1984 m_pFnMesh->numPolygons();
1988 if(m_markPoly>=primitiveCount-1)
1990 feX(
"SurfaceAccessorMaya::rawVertex",
1991 "excessive point index");
1993 m_markVertex+=polyVertCount(m_markPoly);
1995 m_pFnMesh->polygonVertexCount(
2000 U32 twinVertex(U32 a_logicalVertex)
2002 rawVertex(a_logicalVertex);
2003 const U32 subIndex=a_logicalVertex-m_markVertex;
2004 const U32 subs=m_pFnMesh->polygonVertexCount(
2007 MIntArray vertexList;
2009 m_pFnMesh->getPolygonVertices(
2010 m_markPoly,vertexList);
2012 return vertexList[subs-1-subIndex];
2015 MFn::Type componentType(
void)
2017 return componentTypeOfElement(m_element);
2020 void setDetail(
const String& a_rKey,
const String& a_rValue);
2023 void initializeFaceVertArray(
void);
2032 FaceVert(I32 a_face,I32 a_vert):
2045 U32 m_markRawVertex;
2047 PolyFormat m_cachePolyFormat;
2051 MDataHandle m_meshData;
2056 MItGeometry* m_pGroupIt;
2059 BWORD m_useTransform;
2064 I32* m_pIntegerCache;
2067 BWORD* m_pBooleanCache;
const FESTRING_I8 * c_str(void) const
Return the contents of the 8-bit buffer cast as signed bytes.
Definition: String.h:352
kernel
Definition: namespace.dox:3
Matrix< 4, 4, T > & invert(Matrix< 4, 4, T > &a_inverted, const Matrix< 4, 4, T > &a_matrix)
4x4 full matrix inversion
Definition: Matrix.h:1033
Common Functionality for Accessor Surface.
Definition: SurfaceAccessorBase.h:20
BWORD empty(void) const
Returns true if the contents have zero length.
Definition: String.h:667
Maya Surface Editing Implementation.
Definition: SurfaceAccessorMaya.h:30
String & sPrintf(const char *fmt,...)
Populate the string in the manner of sprintf().
Definition: String.cc:529
Automatically reference-counted string container.
Definition: String.h:128
Wrapper for std::vector.
Definition: Array.h:21
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
U32 length(void) const
Return the number of represented characters, but not necessarily the size of any buffer.
Definition: String.h:662
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192