 Timestamp:
 12/19/14 16:43:31 (33 hours ago)
 Files:

 1 modified
Legend:
 Unmodified
 Added
 Removed

OpenSceneGraph/trunk/src/osgPlugins/Inventor/ConvertToInventor.cpp
r13497 r13557 25 25 // but you are not forced to do so. 26 26 // 27 28 #include <osg/Config>29 #ifndef OSG_USE_DEPRECATED_GEOMETRY_METHODS30 #define OSG_USE_DEPRECATED_GEOMETRY_METHODS 131 #endif32 27 33 28 #include <osg/BlendFunc> … … 471 466 472 467 template<typename variableType, typename fieldType> 473 bool ivProcessArray(const osg::Array * indices, const osg::Array *drawElemIndices,468 bool ivProcessArray(const osg::Array *drawElemIndices, 474 469 fieldType *destField, const fieldType *srcField, 475 470 int startIndex, int numToProcess) … … 477 472 bool ok = true; 478 473 479 if ( indices drawElemIndices) {474 if (drawElemIndices) { 480 475 481 476 // "deindex" original data 482 if (indices && !drawElemIndices) 483 ok = ivDeindex<variableType>(destField>startEditing(), 484 srcField>getValues(startIndex), 485 srcField>getNum(), indices, numToProcess); else 486 if (!indices && drawElemIndices) 487 ok = ivDeindex<variableType>(destField>startEditing(), 488 srcField>getValues(startIndex), 489 srcField>getNum(), drawElemIndices, numToProcess); 490 else { 491 OSG_WARN << "IvWriter: NOT IMPLEMENTED" << std::endl; 492 assert(0); // FIXME: 493 } 477 ok = ivDeindex<variableType>(destField>startEditing(), 478 srcField>getValues(startIndex), 479 srcField>getNum(), drawElemIndices, numToProcess); 494 480 495 481 destField>finishEditing(); … … 512 498 513 499 514 static void processIndices(const osg::Array * indices, const osg::Array *drawElemIndices,500 static void processIndices(const osg::Array *drawElemIndices, 515 501 SoMFInt32 &ivIndices, 516 502 int startIndex, int stopIndex, int numItemsUntilMinusOne) 517 503 { 518 if (indices  drawElemIndices) { 519 if (indices && !drawElemIndices) 520 osgArray2ivMField(indices, ivIndices, startIndex, stopIndex, numItemsUntilMinusOne); else 521 if (!indices && drawElemIndices) 504 if (drawElemIndices) { 505 522 506 osgArray2ivMField(drawElemIndices, ivIndices, startIndex, stopIndex, numItemsUntilMinusOne); 523 else {524 OSG_WARN << "IvWriter: NOT IMPLEMENTED" << std::endl;525 assert(0); // FIXME:526 }527 507 528 508 } else { 509 529 510 int num = stopIndexstartIndex; 530 511 if (numItemsUntilMinusOne != 0 && num >= 1) … … 573 554 574 555 static void postProcessField(const SbIntList &runLengths, osg::PrimitiveSet::Mode primType, 575 SoMFInt32 *field, osg::Geometry::AttributeBinding binding)576 { 577 if (binding== osg::Geometry::BIND_OFF  binding==osg::Geometry::BIND_OVERALL 578 binding== osg::Geometry::BIND_PER_PRIMITIVE_SET)556 SoMFInt32 *field, deprecated_osg::Geometry::AttributeBinding binding) 557 { 558 if (binding==deprecated_osg::Geometry::BIND_OFF  binding==deprecated_osg::Geometry::BIND_OVERALL  559 binding==deprecated_osg::Geometry::BIND_PER_PRIMITIVE_SET) 579 560 return; 580 561 … … 589 570 const int l = runLengths.getLength(); 590 571 switch (binding) { 591 case osg::Geometry::BIND_PER_VERTEX:572 case deprecated_osg::Geometry::BIND_PER_VERTEX: 592 573 for (int i=0; i<l; i++) 593 574 newNum += (runLengths[i]3)*3; 594 575 break; 595 case osg::Geometry::BIND_PER_PRIMITIVE:576 case deprecated_osg::Geometry::BIND_PER_PRIMITIVE: 596 577 for (int i=0; i<l; i++) 597 578 newNum += runLengths[i]3; … … 607 588 // int32_t *dst2 = dst; 608 589 switch (binding) { 609 case osg::Geometry::BIND_PER_VERTEX:590 case deprecated_osg::Geometry::BIND_PER_VERTEX: 610 591 for (int i=0; i<l; i++) { 611 592 int c = runLengths[i]; … … 643 624 break; 644 625 645 case osg::Geometry::BIND_PER_PRIMITIVE:626 case deprecated_osg::Geometry::BIND_PER_PRIMITIVE: 646 627 for (int i=0; i<l; i++,src++) { 647 628 int c = runLengths[i]; … … 663 644 664 645 static void postProcessTriangleSeparation(SoIndexedShape *shape, osg::PrimitiveSet::Mode primType, 665 osg::Geometry::AttributeBinding normalBinding,666 osg::Geometry::AttributeBinding colorBinding)646 deprecated_osg::Geometry::AttributeBinding normalBinding, 647 deprecated_osg::Geometry::AttributeBinding colorBinding) 667 648 { 668 649 // compute runLengths … … 681 662 runLengths.append(l); 682 663 683 postProcessField(runLengths, primType, &shape>coordIndex, osg::Geometry::BIND_PER_VERTEX);664 postProcessField(runLengths, primType, &shape>coordIndex, deprecated_osg::Geometry::BIND_PER_VERTEX); 684 665 postProcessField(runLengths, primType, &shape>normalIndex, normalBinding); 685 666 postProcessField(runLengths, primType, &shape>materialIndex, colorBinding); … … 687 668 (shape>textureCoordIndex.getNum()==1 && shape>textureCoordIndex[0] == 1); 688 669 if (!notUseTexCoords) 689 postProcessField(runLengths, primType, &shape>textureCoordIndex, osg::Geometry::BIND_PER_VERTEX);690 691 } 692 693 694 static SoMaterialBinding* createMaterialBinding(const osg::Geometry *g, bool isMaterialIndexed)670 postProcessField(runLengths, primType, &shape>textureCoordIndex, deprecated_osg::Geometry::BIND_PER_VERTEX); 671 672 } 673 674 675 static SoMaterialBinding* createMaterialBinding(const deprecated_osg::Geometry *g, bool isMaterialIndexed) 695 676 { 696 677 SoMaterialBinding *materialBinding = new SoMaterialBinding; 697 678 switch (g>getColorBinding()) { 698 case osg::Geometry::BIND_OFF: // OFF means use material from state set (if any) for whole geometry699 case osg::Geometry::BIND_OVERALL:700 case osg::Geometry::BIND_PER_PRIMITIVE_SET: materialBinding>value = SoMaterialBinding::OVERALL; break;701 case osg::Geometry::BIND_PER_PRIMITIVE: materialBinding>value = (isMaterialIndexed) ? SoMaterialBinding::PER_PART_INDEXED : SoMaterialBinding::PER_PART; break;702 case osg::Geometry::BIND_PER_VERTEX: materialBinding>value = (isMaterialIndexed) ? SoMaterialBinding::PER_VERTEX_INDEXED : SoMaterialBinding::PER_VERTEX; break;679 case deprecated_osg::Geometry::BIND_OFF: // OFF means use material from state set (if any) for whole geometry 680 case deprecated_osg::Geometry::BIND_OVERALL: 681 case deprecated_osg::Geometry::BIND_PER_PRIMITIVE_SET: materialBinding>value = SoMaterialBinding::OVERALL; break; 682 case deprecated_osg::Geometry::BIND_PER_PRIMITIVE: materialBinding>value = (isMaterialIndexed) ? SoMaterialBinding::PER_PART_INDEXED : SoMaterialBinding::PER_PART; break; 683 case deprecated_osg::Geometry::BIND_PER_VERTEX: materialBinding>value = (isMaterialIndexed) ? SoMaterialBinding::PER_VERTEX_INDEXED : SoMaterialBinding::PER_VERTEX; break; 703 684 default: assert(0); 704 685 } … … 707 688 708 689 709 static SoNormalBinding* createNormalBinding(const osg::Geometry *g, bool areNormalsIndexed)690 static SoNormalBinding* createNormalBinding(const deprecated_osg::Geometry *g, bool areNormalsIndexed) 710 691 { 711 692 // Convert normal binding 712 693 SoNormalBinding *normalBinding = new SoNormalBinding; 713 694 switch (g>getNormalBinding()) { 714 case osg::Geometry::BIND_OFF: // FIXME: what to do with BIND_OFF value?715 case osg::Geometry::BIND_OVERALL:716 case osg::Geometry::BIND_PER_PRIMITIVE_SET: normalBinding>value = SoNormalBinding::OVERALL; break;717 case osg::Geometry::BIND_PER_PRIMITIVE: normalBinding>value = (areNormalsIndexed) ? SoNormalBinding::PER_PART_INDEXED : SoNormalBinding::PER_PART; break;718 case osg::Geometry::BIND_PER_VERTEX: normalBinding>value = (areNormalsIndexed) ? SoNormalBinding::PER_VERTEX_INDEXED : SoNormalBinding::PER_VERTEX; break;695 case deprecated_osg::Geometry::BIND_OFF: // FIXME: what to do with BIND_OFF value? 696 case deprecated_osg::Geometry::BIND_OVERALL: 697 case deprecated_osg::Geometry::BIND_PER_PRIMITIVE_SET: normalBinding>value = SoNormalBinding::OVERALL; break; 698 case deprecated_osg::Geometry::BIND_PER_PRIMITIVE: normalBinding>value = (areNormalsIndexed) ? SoNormalBinding::PER_PART_INDEXED : SoNormalBinding::PER_PART; break; 699 case deprecated_osg::Geometry::BIND_PER_VERTEX: normalBinding>value = (areNormalsIndexed) ? SoNormalBinding::PER_VERTEX_INDEXED : SoNormalBinding::PER_VERTEX; break; 719 700 default: assert(0); 720 701 } … … 1102 1083 1103 1084 1104 static bool processPrimitiveSet(const osg::Geometry *g, const osg::PrimitiveSet *pset,1085 static bool processPrimitiveSet(const deprecated_osg::Geometry *g, const osg::PrimitiveSet *pset, 1105 1086 osg::UIntArray *drawElemIndices, bool needSeparateTriangles, 1106 1087 int elementsCount, int primSize, const int startIndex, int stopIndex, … … 1137 1118 1138 1119 // Normal indexing 1139 int normalStart = g>getNormalBinding() == osg::Geometry::BIND_PER_VERTEX? startIndex : normalIndex;1120 int normalStart = (g>getNormalBinding() == deprecated_osg::Geometry::BIND_PER_VERTEX) ? startIndex : normalIndex; 1140 1121 int numNormalsUsed = 0; 1141 1122 switch (g>getNormalBinding()) { 1142 case osg::Geometry::BIND_OFF: // FIXME: what is meaning of OFF value?1143 case osg::Geometry::BIND_OVERALL: numNormalsUsed = 0; break;1144 case osg::Geometry::BIND_PER_PRIMITIVE_SET: numNormalsUsed = 1; break;1145 case osg::Geometry::BIND_PER_PRIMITIVE: numNormalsUsed = primSize!=0 ? (stopIndexstartIndex)/primSize :1123 case deprecated_osg::Geometry::BIND_OFF: // FIXME: what is meaning of OFF value? 1124 case deprecated_osg::Geometry::BIND_OVERALL: numNormalsUsed = 0; break; 1125 case deprecated_osg::Geometry::BIND_PER_PRIMITIVE_SET: numNormalsUsed = 1; break; 1126 case deprecated_osg::Geometry::BIND_PER_PRIMITIVE: numNormalsUsed = primSize!=0 ? (stopIndexstartIndex)/primSize : 1146 1127 (drawArrayLengths ? drawArrayLengths>size() : 1); break; 1147 case osg::Geometry::BIND_PER_VERTEX: numNormalsUsed = stopIndexstartIndex; break;1128 case deprecated_osg::Geometry::BIND_PER_VERTEX: numNormalsUsed = stopIndexstartIndex; break; 1148 1129 } 1149 1130 normalIndex += numNormalsUsed; 1150 1131 1151 1132 // Color indexing 1152 int colorStart = g>getColorBinding() == osg::Geometry::BIND_PER_VERTEX ? startIndex : colorIndex;1133 int colorStart = g>getColorBinding() == deprecated_osg::Geometry::BIND_PER_VERTEX ? startIndex : colorIndex; 1153 1134 int numColorsUsed = 0; 1154 1135 switch (g>getColorBinding()) { 1155 case osg::Geometry::BIND_OFF:1156 case osg::Geometry::BIND_OVERALL: numColorsUsed = 0; break;1157 case osg::Geometry::BIND_PER_PRIMITIVE_SET: numColorsUsed = 1; break;1158 case osg::Geometry::BIND_PER_PRIMITIVE: numColorsUsed = primSize!=0 ? (stopIndexstartIndex)/primSize :1136 case deprecated_osg::Geometry::BIND_OFF: 1137 case deprecated_osg::Geometry::BIND_OVERALL: numColorsUsed = 0; break; 1138 case deprecated_osg::Geometry::BIND_PER_PRIMITIVE_SET: numColorsUsed = 1; break; 1139 case deprecated_osg::Geometry::BIND_PER_PRIMITIVE: numColorsUsed = primSize!=0 ? (stopIndexstartIndex)/primSize : 1159 1140 (drawArrayLengths ? drawArrayLengths>size() : 1); break; 1160 case osg::Geometry::BIND_PER_VERTEX: numColorsUsed = stopIndexstartIndex; break;1141 case deprecated_osg::Geometry::BIND_PER_VERTEX: numColorsUsed = stopIndexstartIndex; break; 1161 1142 } 1162 1143 colorIndex += numColorsUsed; … … 1165 1146 1166 1147 // Convert to SoIndexedShape 1167 processIndices( g>getVertexIndices(),drawElemIndices, ((SoIndexedShape*)shape)>coordIndex,1148 processIndices(drawElemIndices, ((SoIndexedShape*)shape)>coordIndex, 1168 1149 startIndex, stopIndex, primSize); 1169 1150 1170 1151 if (ivNormals) 1171 processIndices( g>getNormalIndices(),drawElemIndices, ((SoIndexedShape*)shape)>normalIndex,1152 processIndices(drawElemIndices, ((SoIndexedShape*)shape)>normalIndex, 1172 1153 normalStart, normalStart+(numNormalsUsed==0 ? 1 : numNormalsUsed), 1173 g>getNormalBinding()== osg::Geometry::BIND_PER_VERTEX ? primSize : 0);1154 g>getNormalBinding()==deprecated_osg::Geometry::BIND_PER_VERTEX ? primSize : 0); 1174 1155 1175 1156 if (ivMaterial) 1176 processIndices( g>getColorIndices(),drawElemIndices, ((SoIndexedShape*)shape)>materialIndex,1157 processIndices(drawElemIndices, ((SoIndexedShape*)shape)>materialIndex, 1177 1158 colorStart, colorStart+(numColorsUsed==0 ? 1 : numColorsUsed), 1178 g>getColorBinding()== osg::Geometry::BIND_PER_VERTEX ? primSize : 0);1159 g>getColorBinding()==deprecated_osg::Geometry::BIND_PER_VERTEX ? primSize : 0); 1179 1160 1180 1161 if (ivTexCoords && !ivTexCoords>isOfType(SoTextureCoordinateFunction::getClassTypeId())) 1181 processIndices( g>getTexCoordIndices(0),drawElemIndices, ((SoIndexedShape*)shape)>textureCoordIndex,1162 processIndices(drawElemIndices, ((SoIndexedShape*)shape)>textureCoordIndex, 1182 1163 startIndex, stopIndex, primSize); 1183 1164 … … 1187 1168 postProcessDrawArrayLengths(drawArrayLengths, &((SoIndexedShape*)shape)>coordIndex); 1188 1169 1189 if (ivNormals && g>getNormalBinding()== osg::Geometry::BIND_PER_VERTEX)1170 if (ivNormals && g>getNormalBinding()==deprecated_osg::Geometry::BIND_PER_VERTEX) 1190 1171 postProcessDrawArrayLengths(drawArrayLengths, &((SoIndexedShape*)shape)>normalIndex); 1191 1172 1192 if (ivMaterial && g>getColorBinding()== osg::Geometry::BIND_PER_VERTEX)1173 if (ivMaterial && g>getColorBinding()==deprecated_osg::Geometry::BIND_PER_VERTEX) 1193 1174 postProcessDrawArrayLengths(drawArrayLengths, &((SoIndexedShape*)shape)>materialIndex); 1194 1175 … … 1215 1196 if (ok) { 1216 1197 ((SoCoordinate4*)nonIndexedCoords)>point.setNum(n); 1217 ok = ivProcessArray<SbVec4f,SoMFVec4f>(g>getVertexIndices(), 1218 drawElemIndices, 1198 ok = ivProcessArray<SbVec4f,SoMFVec4f>(drawElemIndices, 1219 1199 &((SoCoordinate4*)nonIndexedCoords)>point, 1220 1200 &((SoCoordinate4*)ivCoords)>point, … … 1225 1205 if (ok) { 1226 1206 ((SoCoordinate3*)nonIndexedCoords)>point.setNum(n); 1227 ok = ivProcessArray<SbVec3f,SoMFVec3f>(g>getVertexIndices(), 1228 drawElemIndices, 1207 ok = ivProcessArray<SbVec3f,SoMFVec3f>(drawElemIndices, 1229 1208 &((SoCoordinate3*)nonIndexedCoords)>point, 1230 1209 &((SoCoordinate3*)ivCoords)>point, … … 1242 1221 { 1243 1222 ((SoTextureCoordinate2*)nonIndexedTexCoords)>point.setNum(n); 1244 ok = ivProcessArray<SbVec2f,SoMFVec2f>(g>getTexCoordIndices(0), 1245 drawElemIndices, 1223 ok = ivProcessArray<SbVec2f,SoMFVec2f>(drawElemIndices, 1246 1224 &((SoTextureCoordinate2*)nonIndexedTexCoords)>point, 1247 1225 &((SoTextureCoordinate2*)ivTexCoords)>point, … … 1256 1234 { 1257 1235 ((SoTextureCoordinate3*)nonIndexedTexCoords)>point.setNum(n); 1258 ok = ivProcessArray<SbVec3f,SoMFVec3f>(g>getTexCoordIndices(0), 1259 drawElemIndices, 1236 ok = ivProcessArray<SbVec3f,SoMFVec3f>(drawElemIndices, 1260 1237 &((SoTextureCoordinate3*)nonIndexedTexCoords)>point, 1261 1238 &((SoTextureCoordinate3*)ivCoords)>point, … … 1273 1250 if (ok) { 1274 1251 nonIndexedNormals>vector.setNum(numNormalsUsed==0 ? 1 : numNormalsUsed); 1275 ok = ivProcessArray<SbVec3f,SoMFVec3f>(g>getNormalIndices(), 1276 g>getNormalBinding()==osg::Geometry::BIND_PER_VERTEX ? drawElemIndices : NULL, 1252 ok = ivProcessArray<SbVec3f,SoMFVec3f>(g>getNormalBinding()==deprecated_osg::Geometry::BIND_PER_VERTEX ? drawElemIndices : NULL, 1277 1253 &nonIndexedNormals>vector, &ivNormals>vector, 1278 1254 normalStart, numNormalsUsed==0 ? 1 : numNormalsUsed); … … 1296 1272 &((SoBaseColor*)ivMaterial)>rgb; 1297 1273 dstColorField>setNum(numColorsUsed==0 ? 1 : numColorsUsed); 1298 ok = ivProcessArray<SbColor,SoMFColor>(g>getColorIndices(), 1299 g>getColorBinding()==osg::Geometry::BIND_PER_VERTEX ? drawElemIndices : NULL, 1274 ok = ivProcessArray<SbColor,SoMFColor>(g>getColorBinding()==deprecated_osg::Geometry::BIND_PER_VERTEX ? drawElemIndices : NULL, 1300 1275 dstColorField, srcColorField, 1301 1276 colorStart, numColorsUsed==0 ? 1 : numColorsUsed); … … 1472 1447 1473 1448 1474 void ConvertToInventor::processGeometry(const osg::Geometry *g, InventorState *ivState)1449 void ConvertToInventor::processGeometry(const deprecated_osg::Geometry *g, InventorState *ivState) 1475 1450 { 1476 1451 int normalIndex = 0; … … 1599 1574 1600 1575 // Create appropriate SoShape 1601 bool useIndices = g>getVertexIndices() != NULL vrml1Conversion;1576 bool useIndices = vrml1Conversion; 1602 1577 bool needSeparateTriangles = false; 1603 1578 SoVertexShape *shape = NULL; … … 1835 1810 void ConvertToInventor::processDrawable(osg::Drawable *d) 1836 1811 { 1837 osg::Geometry *g = d>asGeometry(); // FIXME: other drawables have to be handled also1838 osg::ShapeDrawable *sd ;1812 deprecated_osg::Geometry *g = dynamic_cast<deprecated_osg::Geometry*>(d); // FIXME: other drawables have to be handled also 1813 osg::ShapeDrawable *sd = 0; 1839 1814 1840 1815 // Create SoSeparator and convert StateSet for Drawable