Ejemplo n.º 1
0
SgMesh* MeshGenerator::generateArrow(double length, double width, double coneLengthRatio, double coneWidthRatio)
{
    double r = width / 2.0;
    double h = length * coneLengthRatio;
    SgShapePtr cone = new SgShape;
    //setDivisionNumber(20);
    cone->setMesh(generateCone(r * coneWidthRatio, h));
    SgPosTransform* conePos = new SgPosTransform;
    conePos->setTranslation(Vector3(0.0, length / 2.0 + h / 2.0, 0.0));
    conePos->addChild(cone);

    SgShapePtr cylinder = new SgShape;
    //setDivisionNumber(12);
    cylinder->setMesh(generateCylinder(r, length, true, false));
    //cylinder->setMesh(generateCylinder(r, length - h, true, false));
    //SgPosTransform* cylinderPos = new SgPosTransform;
    //cylinderPos->setTranslation(Vector3(0.0, -h, 0.0));
    //cylinderPos->addChild(cylinder);
        
    MeshExtractor meshExtractor;
    SgGroupPtr group = new SgGroup;
    group->addChild(conePos);
    //group->addChild(cylinderPos);
    group->addChild(cylinder);
    return meshExtractor.integrate(group);
}
Ejemplo n.º 2
0
SgNode* VRMLSceneLoaderImpl::load(const std::string& filename)
{
    converter.clearConvertedNodeMap();

    SgGroupPtr top = new SgGroup;

    try {
        parser.load(filename);
        
        while(VRMLNodePtr vrml = parser.readNode()){
            SgNodePtr node = converter.convert(vrml);
            if(node){
                top->addChild(node);
            }
        }
        parser.checkEOF();

    } catch(EasyScanner::Exception& ex){
        os() << ex.getFullMessage() << endl;
        return 0;
    }

    if(top->empty()){
        os() << format(_("VRML file \"{}\" does not have any valid entity."), filename) << endl;
        return 0;
    }

    if(top->numChildren() == 1){
        return top->child(0);
    }

    return top.retn();
}