Example #1
0
bool VART::Human::LoadFromFile(const string& fileName)
{
    XmlScene scene;
    bool result = scene.LoadFromFile(fileName);
    if (result) // if no read errors
    {
        // Detach human's root joint from local scene and add it to self
        hipJointPtr = dynamic_cast<Joint*>(scene.GetObjects().front());
        orientation.AddChild(*hipJointPtr);
        scene.Unreference(hipJointPtr);

        // Find smaller vertex on front right foot
        MeshObject* rightFootFingersMeshPtr =
                       dynamic_cast<MeshObject*>(hipJointPtr->FindChildByName("R_footfingersMesh"));
        assert(rightFootFingersMeshPtr != NULL);
        hipJointPtr->FindPathTo(rightFootFingersMeshPtr, &pathToRFoot);
        Point4D::xWeight = 0.1;
        Point4D::yWeight = 3;
        Point4D::zWeight = 2;
        Point4D::operatorLess = &Point4D::WeightedLess;
        rightFootFingersMeshPtr->SmallerVertex(&rfFront); // Compute right foot front
        ResetPosition();

        // Find smaller vertex on front left foot
        MeshObject* leftFootFingersMeshPtr =
                       dynamic_cast<MeshObject*>(hipJointPtr->FindChildByName("L_footfingersMesh"));
        assert(leftFootFingersMeshPtr != NULL);
        hipJointPtr->FindPathTo(leftFootFingersMeshPtr, &pathToLFoot);
        Point4D::xWeight = -0.1;
        Point4D::yWeight = 3;
        Point4D::zWeight = 2;
        leftFootFingersMeshPtr->SmallerVertex(&lfFront); // Compute left foot front
        Point4D::operatorLess = &Point4D::LexicographicalLess;
        Dot* leftFootFrontDotPtr = new Dot(lfFront); // debug only
        leftFootFrontDotPtr->color = Color::RED();
        leftFootFingersMeshPtr->AddChild(*leftFootFrontDotPtr);
        stickPositionPtr = &lfFront;
        pathToStickPosPtr = &pathToLFoot;

        // Load Rest Action
        std::string restFile("");
        restFile = VART::File::GetPathFromString(fileName) + "rest.xml";
        restPtr = LoadAction(restFile);
        if (restPtr)
        {
            restPtr->SetPriority(1);
            restPtr->Activate();
            //~ restPtr->SetSpeed(3);
        }
        // Load Breeth Action
        std::string breethFile("");
        breethFile = VART::File::GetPathFromString(fileName) + "breathe.xml";
        breathePtr = LoadAction(breethFile);
        if (breathePtr)
        {
            breathePtr->SetPriority(2);
            breathePtr->Activate();
        }
    }
    return result;
}