<div dir="ltr"><div><div>Hi Florian,<br><br></div>Is there a reason your copy and pasted code doesn't assign the texture coordinate arrays to the geometry?<br><br></div>Robert.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 2 May 2016 at 21:08, Florian GOLESTIN <span dir="ltr"><<a href="mailto:florian.golestin@gmail.com" target="_blank">florian.golestin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Robert,<br>
<br>
Thanks for your response!<br>
<br>
I might have the two vectors for the textures coordinate.<br>
Basically my idea is to have cubes to draw Labyrinth.<br>
I read a file such as:<br>
<br>
Code:<br>
<br>
xxxxx<br>
x.....x<br>
xxxxx<br>
<br>
<br>
<br>
Where 'x' represents a wall.<br>
<br>
I've a class named Level that hold two Vec2Array for the two textures, it also hold vertices and normals.<br>
What I do is<br>
- Even: the first vector is filled with texture coordinates while the second is filled with 0<br>
- Odd: then the second time the first vector is filled with 0 and the second with texture coordinates.<br>
<br>
Here is the code:<br>
<br>
Code:<br>
<br>
float x = 0;<br>
float y = 0;<br>
int wallCount = 0;<br>
<br>
while(std::getline(stream, line))<br>
{<br>
std::stringstream linestream(line);<br>
<br>
while (linestream >> block)<br>
{<br>
float posx = 1.0 * x;<br>
float posy = 1.0 * y;<br>
float endx = posx + 1.0;<br>
float endy = posy + 1.0;<br>
switch (block)<br>
{<br>
case 'x':<br>
if (wallCount % 2) // Odd or Even?<br>
createCube(level.get(), *level->texcoords, *level->texcoords2, posx, posy, endx, endy);<br>
else<br>
createCube(level.get(), *level->texcoords2, *level->texcoords, posx, posy, endx, endy);<br>
wallCount++;<br>
break;<br>
x += 1.0;<br>
}<br>
x = 0;<br>
y -= 1.0; /* We decrements y To keep the labyrinth as on the file */<br>
}<br>
<br>
<br>
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;<br>
geom->setVertexArray(level->vertices);<br>
geom->setNormalArray(level->normals, osg::Array::Binding::BIND_PER_VERTEX);<br>
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 24*wallCount));<br>
osgUtil::SmoothingVisitor::smooth(*geom);<br>
<br>
<br>
<br>
/*<br>
* @param Level the container of the vertices, normals and textures for the walls of our labyrinth<br>
* @param tex the Vector that should receive the coordinate for the textures<br>
* @param skip the second vector for texture filled with '0' to 'skip' this wall<br>
*/<br>
void LevelReader::createCube(Soleil::Level *level, osg::Vec2Array &tex, osg::Vec2Array &skip,<br>
float posx, float posy, float endx, float endy) const<br>
{<br>
// ------ Front<br>
level->vertices->push_back(osg::Vec3(posx, posy, 0.0f));<br>
level->vertices->push_back(osg::Vec3(endx, posy, 0.0f));<br>
level->vertices->push_back(osg::Vec3(endx, posy, 1.0f));<br>
level->vertices->push_back(osg::Vec3(posx, posy, 1.0f));<br>
<br>
level->normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));<br>
level->normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));<br>
level->normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));<br>
level->normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));<br>
<br>
tex.push_back( osg::Vec2(0.0f, 0.0f));<br>
tex.push_back( osg::Vec2(0.0f, 1.0f));<br>
tex.push_back( osg::Vec2(1.0f, 1.0f));<br>
tex.push_back( osg::Vec2(1.0f, 0.0f));<br>
//<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
<br>
<br>
// ------ top<br>
level->vertices->push_back(osg::Vec3(posx, posy, 1.0f));<br>
level->vertices->push_back(osg::Vec3(endx, posy, 1.0f));<br>
level->vertices->push_back(osg::Vec3(endx, endy, 1.0f));<br>
level->vertices->push_back(osg::Vec3(posx, endy, 1.0f));<br>
<br>
level->normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));<br>
level->normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));<br>
level->normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));<br>
level->normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));<br>
<br>
tex.push_back( osg::Vec2(0.0f, 0.0f));<br>
tex.push_back( osg::Vec2(0.0f, 1.0f));<br>
tex.push_back( osg::Vec2(1.0f, 1.0f));<br>
tex.push_back( osg::Vec2(1.0f, 0.0f));<br>
//<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
<br>
<br>
// ------ back<br>
level->vertices->push_back(osg::Vec3(posx, endy, 0.0f));<br>
level->vertices->push_back(osg::Vec3(endx, endy, 0.0f));<br>
level->vertices->push_back(osg::Vec3(endx, endy, 1.0f));<br>
level->vertices->push_back(osg::Vec3(posx, endy, 1.0f));<br>
<br>
level->normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));<br>
level->normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));<br>
level->normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));<br>
level->normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));<br>
<br>
tex.push_back( osg::Vec2(0.0f, 0.0f));<br>
tex.push_back( osg::Vec2(0.0f, 1.0f));<br>
tex.push_back( osg::Vec2(1.0f, 1.0f));<br>
tex.push_back( osg::Vec2(1.0f, 0.0f));<br>
//<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
<br>
<br>
// ------ Bottom<br>
level->vertices->push_back(osg::Vec3(posx, posy, 0.0f));<br>
level->vertices->push_back(osg::Vec3(endx, posy, 0.0f));<br>
level->vertices->push_back(osg::Vec3(endx, endy, 0.0f));<br>
level->vertices->push_back(osg::Vec3(posx, endy, 0.0f));<br>
<br>
level->normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));<br>
level->normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));<br>
level->normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));<br>
level->normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));<br>
<br>
tex.push_back( osg::Vec2(0.0f, 0.0f));<br>
tex.push_back( osg::Vec2(0.0f, 1.0f));<br>
tex.push_back( osg::Vec2(1.0f, 1.0f));<br>
tex.push_back( osg::Vec2(1.0f, 0.0f));<br>
//<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
<br>
<br>
// ------ Left<br>
level->vertices->push_back(osg::Vec3(posx, posy, 0.0f));<br>
level->vertices->push_back(osg::Vec3(posx, endy, 0.0f));<br>
level->vertices->push_back(osg::Vec3(posx, endy, 1.0f));<br>
level->vertices->push_back(osg::Vec3(posx, posy, 1.0f));<br>
<br>
level->normals->push_back(osg::Vec3(-1.0f, 0.0f, 0.0f));<br>
level->normals->push_back(osg::Vec3(-1.0f, 0.0f, 0.0f));<br>
level->normals->push_back(osg::Vec3(-1.0f, 0.0f, 0.0f));<br>
level->normals->push_back(osg::Vec3(-1.0f, 0.0f, 0.0f));<br>
<br>
tex.push_back( osg::Vec2(0.0f, 0.0f));<br>
tex.push_back( osg::Vec2(0.0f, 1.0f));<br>
tex.push_back( osg::Vec2(1.0f, 1.0f));<br>
tex.push_back( osg::Vec2(1.0f, 0.0f));<br>
//<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
<br>
<br>
// ------ Right<br>
level->vertices->push_back(osg::Vec3(endx, posy, 0.0f));<br>
level->vertices->push_back(osg::Vec3(endx, endy, 0.0f));<br>
level->vertices->push_back(osg::Vec3(endx, endy, 1.0f));<br>
level->vertices->push_back(osg::Vec3(endx, posy, 1.0f));<br>
<br>
level->normals->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));<br>
level->normals->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));<br>
level->normals->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));<br>
level->normals->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));<br>
<br>
tex.push_back( osg::Vec2(0.0f, 0.0f));<br>
tex.push_back( osg::Vec2(0.0f, 1.0f));<br>
tex.push_back( osg::Vec2(1.0f, 1.0f));<br>
tex.push_back( osg::Vec2(1.0f, 0.0f));<br>
//<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
skip.push_back( osg::Vec2(0.0f, 0.0f));<br>
<br>
}<br>
<br>
<br>
<br>
<br>
Thanks,<br>
<span class="">Florian<br>
<br>
------------------<br>
Read this topic online here:<br>
</span><a href="http://forum.openscenegraph.org/viewtopic.php?p=67041#67041" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=67041#67041</a><br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</div></div></blockquote></div><br></div>