Hi all !
I wonder why nobody answers to this simple(?) question ?? I need to fix
this annoying bug till Thursday, so it would be nice, if anyone could
check this over.
In short:
can GeoPositions be shared by different GeometryPtrs who use different
but overlapping indices to define Quads among them ?
Thanx,
Tobi
Tobias Kilian schrieb:
Hi OpenSG Users !
I recently changed my code and get a "no source information available
error" since then. Very frustrating!
I'm working on a simple Terrain Editor and split the Terrain into
different subnodes, for to get view frustum culling and the like.
First I just duplicated the Vertices that are needed for two adjacent
Nodes. Then I thought it would be nice, if it was possible to share
the vertices between all nodes and just let them have a different index:
_points = GeoPositions3f::create();
beginEditCP(_points);
GeoPositions3f::StoredFieldType * p = _points->getFieldPtr();
// for all vertices:
p->push_back(Pnt3f(x, y, z);
...
endEditCP(_points);
// now all vertices are in _points
// that is: for every subnode
for (int nodesX = 0; nodesX < width/NODE_LENGTH; nodesX++)
{
for (int nodesY = 0; nodesY < width/NODE_LENGTH; nodesY++)
{
GeoIndicesUI32::StoredFieldType * i = index->getFieldPtr();
GeoPLengthsUI32::StoredFieldType * l = lens->getFieldPtr();
GeoPTypesUI8::StoredFieldType * t = types->getFieldPtr();
beginEditCP(index);
beginEditCP(lens);
beginEditCP(types);
t->push_back(GL_QUADS);
// #define NODE_LENGTH 8
int nodeLengthX = NODE_LENGTH;
int nodeLengthY = NODE_LENGTH;
if ( nodesX >= width/NODE_LENGTH-1)
{
nodeLengthX -= 1;
}
if ( nodesY >= width/NODE_LENGTH-1)
{
nodeLengthY -= 1;
}
int length = (nodeLengthX)*(nodeLengthY)*4;
l->push_back( length );
// now indexing into the vertices field _points.
for (int quadX = nodesX*nodeLengthX; quadX <
(nodesX+1)*nodeLengthX; quadX++)
{ for (int quadY = nodesY*nodeLengthY; quadY<
(nodesY+1)*nodeLengthY; quadY++)
{
// points to four vertices that will
// define a single quad
i->push_back(quadX*(width)+quadY);
i->push_back((quadX+1)*(width)+quadY);
i->push_back((quadX+1)*(width)+quadY+1);
i->push_back(quadX*(width)+quadY+1);
}
}
endEditCP(index); endEditCP(lens);
endEditCP(types);
GeometryPtr geo = Geometry::create();
beginEditCP(geo);
geo->setColors(_colors);
geo->setMaterial(_terrainMaterial);
geo->setPositions(_points);
geo->setNormals(_normals);
geo->getIndexMapping().push_back(Geometry::MapPosition |
Geometry::MapNormal |
Geometry::MapTexCoords);
geo->setTexCoords(tex);
geo->setTexCoords1(tex1);
geo->setIndices(index);
geo->setTypes(types);
geo->setLengths(lens);
endEditCP(geo);
NodePtr terrainSubNode = Node::create();
beginEditCP (terrainSubNode);
terrainSubNode->setCore(geo);
endEditCP (terrainSubNode);
// this is a blitz++-Array, to give me later access to the subnodes.
_terrainSubNodes( nodesX, nodesY)= terrainSubNode;
beginEditCP(_terrainNode);
_terrainNode->addChild(_terrainSubNodes( nodesX, nodesY));
endEditCP(_terrainNode);
}
}
Well - it seems to work.
Now I would be grateful if anyone could verify this code and/or tell
me if this is a valid solution.
Many thanks in advance and greetings,
Tobias Kilian
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users