Hi Carsten,

I've tried both patches. These are the results:

   1. osg::calcFaceNormals(geo) is still buggy. Indices size is still
   increasing and result normals are still wrong. Calling it twice now
   destroys the geometry :)
   2. osg::calcVertexTangents(geo) seems to work fine now
   3. calling calcVertexNormals(geo, angle) first, then
   calcVertexNormal(geo), then calcVertexNormals(geo, angle) again and
   so on also increases the indices size

   to make debugging easier ,please find attached our test
application./(See attached file: main.cpp)/
Thanks,
Michael


Am 14.11.2011 22:21, schrieb Carsten Neumann:
    Hello Michael,

On 11/14/2011 08:59 AM, Michael Raab wrote:
2.) osg::calcVertexTangents() creates not enough tangents and binormals, e.g. for a simple plane only 3 tangents are created...

this one seems to be a off-by-one in accounting for the property size. Can you try the attached patch, please?

    Cheers,
        Carsten

PS: the equivalent bug is also in the 2.0 code, will commit there as well once it's confirmed this fixes the problem.


------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1


_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

// OpenSG Tutorial Example: Hello World
//
// Minimalistic OpenSG program
// 
// This is the shortest useful OpenSG program 
// (if you remove all the comments ;)
//
// It shows how to use OpenSG together with GLUT to create a little
// interactive scene viewer.
//

// GLUT is used for window handling
#include <OpenSG/OSGGLUT.h>

// General OpenSG configuration, needed everywhere
#include <OpenSG/OSGConfig.h>

// Methods to create simple geometry: boxes, spheres, tori etc.
#include <OpenSG/OSGSimpleGeometry.h>

// The GLUT-OpenSG connection class
#include <OpenSG/OSGGLUTWindow.h>

// A little helper to simplify scene management and interaction
#include <OpenSG/OSGSimpleSceneManager.h>

#include <OpenSG/OSGGeoFunctions.h>

#include <OpenSG/OSGSHLChunk.h>

// Activate the OpenSG namespace
// This is not strictly necessary, you can also prefix all OpenSG symbols
// with OSG::, but that would be a bit tedious for this example
OSG_USING_NAMESPACE

// The SimpleSceneManager to manage simple applications
SimpleSceneManager *mgr;

// forward declaration so we can have the interesting stuff upfront
int setupGLUT( int *argc, char *argv[] );

osg::RefPtr<osg::GeometryPtr> testGeo;
osg::RefPtr<NodePtr> scene;
osg::RefPtr<SHLChunkPtr> shl;

void printGeoInfo()
{
        if (testGeo->getTypes() != osg::NullFC) std::cout << "#types: " << 
testGeo->getTypes()->size() << std::endl;
        if (testGeo->getLengths() != osg::NullFC) std::cout << "#lengths: " << 
testGeo->getLengths()->size() << std::endl;
        if (testGeo->getIndices() != osg::NullFC) std::cout << "#indices: " << 
testGeo->getIndices()->size() << std::endl;
        if (testGeo->getPositions() != osg::NullFC) std::cout << "#positions: " 
<< testGeo->getPositions()->size() << std::endl;
        if (testGeo->getNormals() != osg::NullFC) std::cout << "#normals: " << 
testGeo->getNormals()->size() << std::endl;
        if (testGeo->getColors() != osg::NullFC) std::cout << "#colors: " << 
testGeo->getColors()->size() << std::endl;
        if (testGeo->getSecondaryColors() != osg::NullFC) std::cout << 
"#secondary colors: " << testGeo->getSecondaryColors()->size() << std::endl;
        if (testGeo->getTexCoords() != osg::NullFC) std::cout << "#texcoords0: 
" << testGeo->getTexCoords()->size() << std::endl;
        if (testGeo->getTexCoords1() != osg::NullFC) std::cout << "#texcoords1: 
" << testGeo->getTexCoords1()->size() << std::endl;
        if (testGeo->getTexCoords2() != osg::NullFC) std::cout << "#texcoords2: 
" << testGeo->getTexCoords2()->size() << std::endl;
        if (testGeo->getTexCoords3() != osg::NullFC) std::cout << "#texcoords3: 
" << testGeo->getTexCoords3()->size() << std::endl;
        if (testGeo->getTexCoords4() != osg::NullFC) std::cout << "#texcoords4: 
" << testGeo->getTexCoords4()->size() << std::endl;
        if (testGeo->getTexCoords5() != osg::NullFC) std::cout << "#texcoords5: 
" << testGeo->getTexCoords5()->size() << std::endl;
        if (testGeo->getTexCoords6() != osg::NullFC) std::cout << "#texcoords6: 
" << testGeo->getTexCoords6()->size() << std::endl;
        if (testGeo->getTexCoords7() != osg::NullFC) std::cout << "#texcoords7: 
" << testGeo->getTexCoords7()->size() << std::endl;
        if (testGeo->getMaterial() != osg::NullFC) std::cout << "Has Geometry 
Material\n";

        std::cout << "IndexMappingSize: " << 
testGeo->getMFIndexMapping()->size() << std::endl;
        std::cout << "->PositionsIndex: " << 
testGeo->calcMappingIndex(Geometry::MapPosition) << std::endl;
        std::cout << "->NormalsIndex: " << 
testGeo->calcMappingIndex(Geometry::MapNormal) << std::endl;
        std::cout << "->ColorsIndex: " << 
testGeo->calcMappingIndex(Geometry::MapColor) << std::endl;
        std::cout << "->SecondaryColorsIndex: " << 
testGeo->calcMappingIndex(Geometry::MapSecondaryColor) << std::endl;
        std::cout << "->TexCoords0Index: " << 
testGeo->calcMappingIndex(Geometry::MapTexCoords) << std::endl;
        std::cout << "->TexCoords1Index: " << 
testGeo->calcMappingIndex(Geometry::MapTexCoords1) << std::endl;
        std::cout << "->TexCoords2Index: " << 
testGeo->calcMappingIndex(Geometry::MapTexCoords2) << std::endl;
        std::cout << "->TexCoords3Index: " << 
testGeo->calcMappingIndex(Geometry::MapTexCoords3) << std::endl;
        std::cout << "->TexCoords4Index: " << 
testGeo->calcMappingIndex(Geometry::MapTexCoords4) << std::endl;
        std::cout << "->TexCoords5Index: " << 
testGeo->calcMappingIndex(Geometry::MapTexCoords5) << std::endl;
        std::cout << "->TexCoords6Index: " << 
testGeo->calcMappingIndex(Geometry::MapTexCoords6) << std::endl;
        std::cout << "->TexCoords7Index: " << 
testGeo->calcMappingIndex(Geometry::MapTexCoords7) << std::endl;
}

// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
        // OSG init
        osgInit(argc,argv);

        // GLUT init
        int winid = setupGLUT(&argc, argv);

        // the connection between GLUT and OpenSG
        GLUTWindowPtr gwin= GLUTWindow::create();
        gwin->setId(winid);
        gwin->init();

        // create the scene
        testGeo = makeBoxGeo(1.0f, 1.0f, 1.0f, 1, 1, 1);
        scene = Node::create();
        beginEditCP(scene);
                scene->setCore(testGeo);
        endEditCP(scene);

        ChunkMaterialPtr mat = ChunkMaterialPtr::dcast(testGeo->getMaterial());
        if( mat != NullFC )
        {
                shl = SHLChunk::create();

                std::string vertexProgram = "void main(void)\n{\n       
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n       gl_TexCoord[0] 
= vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);\n        gl_TexCoord[3] = 
vec4(gl_Normal.xyz, 1.0);\n    gl_TexCoord[1] = vec4(gl_MultiTexCoord1.xyz * 
gl_MultiTexCoord1.w, 1.0);\n      gl_TexCoord[2] = vec4(gl_MultiTexCoord2.xyz * 
gl_MultiTexCoord2.w, 1.0);\n}";
                std::string fragmentProgram = "uniform int texCoordID;\nvoid 
main(void)\n{\n    gl_FragColor = gl_TexCoord[texCoordID]/2.0 +0.5;\n}";

                beginEditCP(shl);
                        shl->setVertexProgram(vertexProgram);
                        shl->setFragmentProgram(fragmentProgram);
                        shl->setUniformParameter("texCoordID", 3);
                endEditCP(shl);

                beginEditCP(mat);
                        mat->addChunk(shl);
                endEditCP(mat);
        }

        // create the SimpleSceneManager helper
        mgr = new SimpleSceneManager;

        // tell the manager what to manage
        mgr->setWindow(gwin );
        mgr->setRoot  (scene);

        // show the whole scene
        mgr->showAll();

        // GLUT main loop
        glutMainLoop();

        return 0;
}

//
// GLUT callback functions
//

// redraw the window
void display(void)
{
        mgr->redraw();
}

// react to size changes
void reshape(int w, int h)
{
        mgr->resize(w, h);
        glutPostRedisplay();
}

// react to mouse button presses
void mouse(int button, int state, int x, int y)
{
        if (state)
                mgr->mouseButtonRelease(button, x, y);
        else
                mgr->mouseButtonPress(button, x, y);
        glutPostRedisplay();
}

// react to mouse motions with pressed buttons
void motion(int x, int y)
{
        mgr->mouseMove(x, y);
        glutPostRedisplay();
}

// react to keys
void keyboard(unsigned char k, int x, int y)
{
        switch(k)
        {
                case 'a':
                {
                        std::cout << "make/reset box" <<std::endl;
                        testGeo = makeBoxGeo(1.0f, 1.0f, 1.0f, 1, 1, 1);
                        beginEditCP(scene);
                                scene->setCore(testGeo);
                        endEditCP(scene);
                        beginEditCP(shl);
                                shl->setUniformParameter("texCoordID", 3);
                        endEditCP(shl);
                        printGeoInfo();
                        glutPostRedisplay();
                }
                break;
                case 'b':
                {
                        std::cout << "make/reset plane" <<std::endl;
                        testGeo = makePlaneGeo(1.0f, 1.0f, 1, 1);
                        beginEditCP(scene);
                                scene->setCore(testGeo);
                        endEditCP(scene);
                        beginEditCP(shl);
                                shl->setUniformParameter("texCoordID", 3);
                        endEditCP(shl);
                        printGeoInfo();
                        glutPostRedisplay();
                }
                break;
                case '1':
                {
                        std::cout << "calcVertexNormals(g)" <<std::endl;
                        osg::calcVertexNormals(testGeo);
                        beginEditCP(shl);
                                shl->setUniformParameter("texCoordID", 3);
                        endEditCP(shl);
                        printGeoInfo();
                        glutPostRedisplay();
                }
                break;
                case '2':
                {
                        std::cout << "calcVertexNormals(g, deg2rad(60))" 
<<std::endl;
                        osg::calcVertexNormals(testGeo, osg::deg2rad(60.0f));
                        beginEditCP(shl);
                                shl->setUniformParameter("texCoordID", 3);
                        endEditCP(shl);
                        printGeoInfo();
                        glutPostRedisplay();
                }
                break;
                case '3':
                {
                        std::cout << "calcFaceNormals(g)" <<std::endl;
                        osg::calcFaceNormals(testGeo);
                        beginEditCP(shl);
                                shl->setUniformParameter("texCoordID", 3);
                        endEditCP(shl);
                        printGeoInfo();
                        glutPostRedisplay();
                }
                break;
                case '4':
                {
                        std::cout << "calcVertexTangents(g)" <<std::endl;
                        osg::calcVertexTangents(testGeo);
                        beginEditCP(shl);
                                shl->setUniformParameter("texCoordID", 1);
                        endEditCP(shl);
                        printGeoInfo();
                        glutPostRedisplay();
                }
                break;
                case '5':
                {
                        std::cout << "createSharedIndex(g)" <<std::endl;
                        osg::createSharedIndex(testGeo);
                        printGeoInfo();
                        glutPostRedisplay();
                }
                break;
                case '6':
                {
                        std::cout << "createSingleIndex(g)" <<std::endl;
                        osg::createSingleIndex(testGeo);
                        printGeoInfo();
                        glutPostRedisplay();
                }
                break;
                case '7':
                {
                        beginEditCP(shl);
                                shl->setUniformParameter("texCoordID", 3);
                        endEditCP(shl);
                        glutPostRedisplay();
                }
                break;
                case '8':
                {
                        beginEditCP(shl);
                                shl->setUniformParameter("texCoordID", 1);
                        endEditCP(shl);
                        glutPostRedisplay();
                }
                break;
                case '9':
                {
                        beginEditCP(shl);
                                shl->setUniformParameter("texCoordID", 2);
                        endEditCP(shl);
                        glutPostRedisplay();
                }
                break;
                case '0':
                {
                        beginEditCP(shl);
                                shl->setUniformParameter("texCoordID", 0);
                        endEditCP(shl);
                        glutPostRedisplay();
                }
                break;
                case '?':
                {
                        std::cout << "?=help" <<std::endl;
                        std::cout << "1=calcVertexNormals(g)" <<std::endl;
                        std::cout << "2=calcVertexNormals(g, 60)" <<std::endl;
                        std::cout << "3=calcFaceNormals(g)" <<std::endl;
                        std::cout << "4=calcVertexTangents(g)" <<std::endl;
                        std::cout << "5=createSharedIndex(g)" <<std::endl;
                        std::cout << "6=createSingleIndex(g)" <<std::endl;
                        std::cout << "7=show normals" <<std::endl;
                        std::cout << "8=show tangents" <<std::endl;
                        std::cout << "9=show binormals" <<std::endl;
                        std::cout << "0=show texcoords" <<std::endl;
                        std::cout << "a=make/reset box" <<std::endl;
                        std::cout << "b=make/reset plane" <<std::endl;
                }
                break;
                case 27:
                {
                        testGeo = osg::NullFC;
                        scene = osg::NullFC;
                        shl = osg::NullFC;

                        OSG::osgExit();
                        exit(0);
                }
                break;
        }
}

// setup the GLUT library which handles the windows for us
int setupGLUT(int *argc, char *argv[])
{
        glutInit(argc, argv);
        glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);

        int winid = glutCreateWindow("OpenSG");

        glutReshapeFunc(reshape);
        glutDisplayFunc(display);
        glutMouseFunc(mouse);
        glutMotionFunc(motion);
        glutKeyboardFunc(keyboard);

        return winid;
}
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to