访问模型索引

starhuhu 2016-07-13 12:50:13
上代码:
osg::ref_ptr<osg::Node> mModel = osgDB::readNodeFile(“Tile_+037_+004_+000.osgb”);

osg::PagedLOD* pagedLOD = dynamic_cast<osg::PagedLOD*>((osg::Node*)mModel);

osg::ref_ptr<osg::Geode> geode = dynamic_cast<osg::Geode*>(pagedLOD->getChild(0));

deprecated_osg::Geometry *geom = (deprecated_osg::Geometry *)(geode->getDrawable(0));

osg::UIntArray* coordIndices = (osg::UIntArray*)(geom->getVertexIndices());

问题: coordIndices 一直为 NULL ,为什么?怎么样才能访问到模型顶点的索引数据呢?

我知道范围顶点是很容易,用

osg::Vec3 v(0,0,0);
osg::Vec3Array *vx = dynamic_cast<osg::Vec3Array*>(geom->getVertexArray());
osg::Vec3Array::iterator coord_index = vx->begin();

while( coord_index != vx->end() )
{
v = *(coord_index++) ;
// v._v[0] ;v._v[1] ;v._v[2] ; // 顶点坐标
}


模型数据如下:
PagedLOD {
UniqueID PagedLOD_0
nodeMask 0xffffffff
cullingActive TRUE
Center -2328.59 -2698.65 8.49903
Radius 93.1091
RangeMode PIXEL_SIZE_ON_SCREEN
RangeList 2 {
0 93.1091
93.1091 1e+030
}
DatabasePath D:\00_OSG\Data2015\4/
NumChildrenThatCannotBeExpired 0
DisableExternalChildrenPaging 0
FileNameList 2 {
""
Tile_+037_+004_+000_L16_0.osgb
}
num_children 1
Geode {
nodeMask 0xffffffff
cullingActive TRUE
num_drawables 2
Geometry {
DataVariance STATIC
StateSet {
DataVariance STATIC
rendering_hint DEFAULT_BIN
renderBinMode INHERIT
Material {
ColorMode OFF
ambientColor 1 1 1 1
diffuseColor 1 1 1 1
specularColor 0 0 0 1
emissionColor 0 0 0 1
shininess 0
}
textureUnit 0 {
GL_TEXTURE_2D ON
Texture2D {
DataVariance STATIC
file "Tile_+037_+004_+000_0.jpg"
wrap_s CLAMP
wrap_t CLAMP
wrap_r CLAMP
min_filter LINEAR_MIPMAP_LINEAR
mag_filter LINEAR
maxAnisotropy 1
borderColor 0 0 0 0
borderWidth 0
useHardwareMipMapGeneration TRUE
unRefImageDataAfterApply TRUE
internalFormatMode USE_IMAGE_DATA_FORMAT
resizeNonPowerOfTwo TRUE
shadowComparison FALSE
shadowCompareFunc GL_LEQUAL
shadowTextureMode GL_LUMINANCE
}
}
}
useDisplayList TRUE
useVertexBufferObjects FALSE
PrimitiveSets 1
{
DrawElementsUInt TRIANGLES 243
{
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 11 21 22 23 24 25 26 27 28
29 30 22 3 29 14 1 0 31 32
33 34 17 35 36 37 38 4 39 40
41 34 42 21 37 14 38 29 22 21
34 33 43 44 45 46 29 21 42 1
47 22 30 6 22 48 44 26 40 39
49 50 22 6 51 26 46 50 1 22
12 52 13 26 40 48 53 20 54 17
16 55 49 18 20 26 44 46 31 48
56 32 49 53 49 10 57 54 20 58
59 60 43 40 49 57 51 27 26 47
1 31 48 31 61 53 33 32 20 19
58 29 3 5 28 40 26 9 48 57
40 57 48 6 1 50 48 9 56 28
41 40 25 62 23 49 39 18 45 44
63 32 34 10 60 34 43 21 11 34
30 29 5 9 47 56 63 44 48 53
54 33 34 60 42 34 11 10 59 12
60 3 37 4 49 20 53 47 9 22
6 30 7 1 6 2 42 60 14 10
49 32 22 9 11 47 31 56 48 61
63 6 8 2 12 14 60 42 14 29
57 10 9
}
}
VertexArray Vec3Array 64
{
-2274.95 -2696.02 5.14414
-2284.25 -2713.14 6.00906
-2268.65 -2720.93 6.03399
-2339.85 -2754.05 8.52102
-2337.78 -2758.39 12.4992
-2335.33 -2759.38 9.20016
-2287.48 -2738.61 7.33001
-2288.48 -2742.99 10.3985
-2276.13 -2746.22 7.50024
-2301.22 -2677.29 6.35114
-2331.36 -2673.4 6.93997
-2331.44 -2696.21 7.41576
-2373 -2756 9.66438
-2369.61 -2764.26 15.0098
-2358.84 -2755.53 9.37347
-2369.61 -2764.26 15.0098
-2365.72 -2768.54 12.7139
-2358.84 -2755.53 9.37347
-2339.01 -2637.44 14.6991
-2355.03 -2632.97 13.0889
-2363.8 -2647.41 14.8428
-2333.37 -2717.74 7.16813
-2302.07 -2712.82 6.14249
-2286.83 -2666.25 -1.50324
-2282.17 -2666.2 4.83722
-2279.07 -2678.86 6.8695
-2295.35 -2648.47 8.67525
-2300.4 -2636.08 9.73091
-2309.14 -2635.59 12.2434
-2324.4 -2742.59 7.64503
-2303.24 -2749.84 8.27619
-2279.07 -2678.86 6.8695
-2356.82 -2666.65 7.69725
-2380.2 -2668.61 8.87479
-2358.87 -2697.79 7.24886
-2340.92 -2753.53 16.9236
-2339.85 -2754.05 8.52102
-2340.92 -2753.53 16.9236
-2342.1 -2756.54 18.5023
-2330.33 -2636.93 7.88878
-2313.2 -2652.82 9.05498
-2318.52 -2631.06 8.29108
-2348.78 -2732.25 7.43589
-2380.37 -2699.4 7.73474
-2281.77 -2649.12 8.4949
-2270.6 -2638.08 9.07715
-2284.58 -2628.32 6.96736
-2289.77 -2693.56 10.4479
-2284.11 -2666.6 10.8603
-2331.22 -2652.86 8.19912
-2287.35 -2723.52 11.0509
-2297.36 -2630.88 8.24831
-2375.93 -2768.96 16.5073
-2363.22 -2655.88 7.54339
-2376.83 -2648.83 15.0525
-2342.1 -2756.54 18.5023
-2283.74 -2677.81 11.4199
-2315.55 -2669.45 11.7067
-2376.82 -2633.16 15.1186
-2380.19 -2736.26 7.47725
-2367.43 -2729.74 7.98294
-2282.17 -2666.2 4.83722
-2274.95 -2696.02 5.14414
-2268.6 -2650.08 7.61186
}
TexCoordArray 0 Vec2Array 64
{
0.384372 0.94007
0.467246 0.879598
0.526579 0.980059
0.617202 0.550379
0.646899 0.528323
0.650184 0.57028
0.600365 0.8558
0.626845 0.823966
0.655968 0.927195
0.264052 0.763828
0.222727 0.587508
0.336849 0.589317
0.590057 0.371382
0.640609 0.344651
0.603435 0.444502
0.785024 0.68882
0.805498 0.725704
0.751412 0.776097
0.0453539 0.469553
0.0152021 0.39957
0.0822676 0.344315
0.442125 0.586878
0.447091 0.770994
0.751946 0.448878
0.763081 0.416182
0.823725 0.41582
0.120184 0.769774
0.0536213 0.727151
0.0485689 0.654374
0.576876 0.638872
0.640703 0.756302
0.290692 0.893816
0.173654 0.445541
0.16984 0.320705
0.321986 0.44719
0.780371 0.788844
0.769481 0.864214
0.62502 0.471684
0.640853 0.452423
0.0422966 0.574882
0.132386 0.664168
0.0183937 0.634723
0.49862 0.50665
0.313349 0.337304
0.13168 0.853804
0.0794467 0.915159
0.0186379 0.843738
0.363321 0.800971
0.225309 0.823728
0.121495 0.571798
0.525597 0.819274
0.0269959 0.756477
0.657695 0.302121
0.118076 0.411803
0.0827794 0.279358
0.795296 0.771746
0.285948 0.824352
0.218155 0.632442
0.00845727 0.27482
0.486479 0.349703
0.468566 0.406314
0.218879 0.888557
0.901154 0.45191
0.144375 0.944569
}
}
Geometry {
DataVariance STATIC
StateSet {
DataVariance STATIC
rendering_hint DEFAULT_BIN
renderBinMode INHERIT
Material {
ColorMode OFF
ambientColor 0.501961 0.501961 0.501961 1
diffuseColor 0.501961 0.501961 0.501961 1
specularColor 0 0 0 1
emissionColor 0 0 0 1
shininess 0
}
}
useDisplayList TRUE
useVertexBufferObjects FALSE
PrimitiveSets 1
{
DrawElementsUInt TRIANGLES 12
{
0 1 2 3 4 5 1 6 2 3
7 4
}
}
VertexArray Vec3Array 8
{
-2268.6 -2650.08 7.61186
-2282.17 -2666.2 4.83722
-2271.17 -2659.22 -0.517275
-2373 -2756 9.66438
-2388.85 -2768.16 18.5201
-2375.93 -2768.96 16.5073
-2286.83 -2666.25 -1.50324
-2380.19 -2736.26 7.47725
}
}
}
}
...全文
1384 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
starhuhu 2016-07-13
  • 打赏
  • 举报
回复
补充: 只有给coordIndices赋值后,用 geom->setVertexIndices(coordIndices); 的索引才能用 geom->getVertexIndices()访问到。感觉 osgDB::readNodeFile后模型没有存储 索引。但是渲染没有问题啊

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧