Hi,

I want to make a Geometry to a RigGeometry and give them an InfluenceMap. 


At first I create the InfluenceMap.


Code:
struct AddHelperBone : public osg::NodeVisitor
{
                ::osgAnimation::Skeleton* Skeleton;
    AddHelperBone() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) 
{}
    void apply(osg::Transform& node) {
        ::osgAnimation::Bone* Bone = dynamic_cast<osgAnimation::Bone*>(&node);
                                ::osgAnimation::Skeleton* skel = 
dynamic_cast<osgAnimation::Skeleton*>(&node);
                                if (skel)
                                {
                                        Skeleton = skel;
                                }
        if (Bone)
                                {       
                                        initVertexMap(Bone);
                                }
                traverse(node);
                }
};




Code:
void initVertexMap(osgAnimation::Bone* b0)
{ 
                string str_FileName = "/home/username/TestMesh/File.txt";       
                string str_tmp;
                int i_tmp;
                float f_tmp;
                ifstream FileStream;

    (*vim)[b0->getName()].setName(b0->getName());

                FileStream.open(str_FileName.c_str(), ifstream::in);
                if(FileStream.good())
                {
                        while ( FileStream >> str_tmp >> i_tmp >> f_tmp)
                        {
                                if(b0->getName() == str_tmp)
                                {
                                        
(*vim)[b0->getName()].push_back(osgAnimation::VertexIndexWeight(i_tmp,f_tmp));
                                }
                        }
                }
                else
                {
                        cout << "Error" << endl;
                }
                FileStream.close(); 
}



Data fom File.txt
Bone 0 1.0
Bone 1 1.0
Bone 2 1.0
Bone 3 1.0
Bone 12 0.5
Bone 14 0.5
Bone 16 0.5
Bone 18 0.5
...







Then I read the vertices / faces from an obj-file and create a new geometry.


Code:
osg::Geometry* createGeo()
{
    osg::Geometry* geometry = new osg::Geometry;
    osg::ref_ptr<osg::Vec3Array> vertices (new osg::Vec3Array());
    
        string str_O = " ";
                string isTri ="";
                float x, y, z = 0.0;
                int f_1, f_2, f_3, f_4 = 0;
                ifstream File;
                string str_Data = "/home/username/TestMesh/File.obj";           
                File.open(str_Data.c_str(), ifstream::in);
                if(File.good())
                {
                        while ( File >> str_O)
                        {
                                if(str_O == "v")
                                {
                                        File >> x >> y >> z;
                                        vertices->push_back (osg::Vec3f ( x, 
-z, y));
                                }
                        }
                        geometry->setVertexArray(vertices);
                }       
                else { cout << "Error" << endl; }
                File.close();

                File.open(str_Data.c_str(), ifstream::in);
                if(File.good())
                {
                        cout << "Faces" << endl;
                        
                        while (File >> str_O)
                        {
                                if(str_O == "f")
                                {
                                        File >> f_1 >> f_2 >> f_3;
                                        isTri = File.get();
                                        if(isTri != "\n")
                                        {
                                                File >> f_4;
                                                ::osg::ref_ptr< 
::osg::DrawElementsUInt > Face = new ::osg::DrawElementsUInt( 
::osg::PrimitiveSet::QUADS, 0);

                                                Face->push_back(f_1-1);
                                                Face->push_back(f_2-1);
                                                Face->push_back(f_3-1);
                                                Face->push_back(f_4-1);
                        
                                                geometry->addPrimitiveSet(Face);
                                        }
                                        else 
                                        {
                                                ::osg::ref_ptr< 
::osg::DrawElementsUInt > Face = new ::osg::DrawElementsUInt( 
::osg::PrimitiveSet::TRIANGLES, 0);

                                                Face->push_back(f_1-1);
                                                Face->push_back(f_2-1);
                                                Face->push_back(f_3-1);
                        
                                                
geometry->addPrimitiveSet(Face);        
                                        }
                                }
                        
                        }
                }       
                else { cout << "Error" << endl; }
                File.close();

                geometry->getOrCreateStateSet()->setMode(GL_LIGHTING, false);
                return geometry;
}




After this I set the InfluenceMap to the RigGeometry like this


Code:
::osgAnimation::RigGeometry* Rgeo = new ::osgAnimation::RigGeometry;
        ::osg::Geometry* geo = createGeo();
        Rgeo->setSourceGeometry(geo);
        Rgeo->setInfluenceMap(vim);



The problem is that the cube has not the right height and the animation doesn't 
look like in blender.

Can anybody help me?

Thank you and sorry for my bad english!

Cheers,
Benjamin

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=43667#43667





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to