JakobTischler / MoreRealisticDLCs

A lua/xml project that adds MoreRealistic to the Farming Simulator DLCs
8 stars 0 forks source link

RES - AnimationParser #72

Closed quadural closed 10 years ago

quadural commented 10 years ago

Hi, I don't know if this can be of any help to another person, but here is a piece of script I used to "read" the "animations" of the Horsch Maestro :

    print("testing animations");
    local a = 0;
    while true do
        local animKey = ('vehicle.animations.animation(%d)'):format(a);
        if not hasXMLProperty(xmlFile, animKey) then break; end;
        local animName = getXMLString(xmlFile, animKey .. '#name');
        print(" anim="..tostring(animName));

        local p = 0;
        while true do
            local partKey = ('%s.part(%d)'):format(animKey, p);
            if not hasXMLProperty(xmlFile, partKey) then break; end;

            local componentJointIndex = getXMLFloat(xmlFile, partKey .. '#componentJointIndex');

            if componentJointIndex then 
                --this is a "componentJointIndex" part

                local startTime = getXMLFloat(xmlFile, partKey .. '#startTime');
                local endTime   = getXMLFloat(xmlFile, partKey .. '#endTime');
                local startRotLimit = getXMLString(xmlFile, partKey .. '#startRotLimit');
                local endRotLimit = getXMLString(xmlFile, partKey .. '#endRotLimit');
                local startTransLimit = getXMLString(xmlFile, partKey .. '#startTransLimit');
                local endTransLimit = getXMLString(xmlFile, partKey .. '#endTransLimit');
                print(string.format('  part componentJointIndex=%s startTime=%s endTime=%s startRotLimit=%s endRotLimit=%s startTransLimit=%s endTransLimit=%s', tostring(componentJointIndex),tostring(startTime),tostring(endTime),tostring(startRotLimit),tostring(endRotLimit),tostring(startTransLimit),tostring(endTransLimit)));
            else
                --this is a "node" part
                local node = getXMLString(xmlFile, partKey .. '#node');
                local startTime = getXMLFloat(xmlFile, partKey .. '#startTime');
                local endTime   = getXMLFloat(xmlFile, partKey .. '#endTime');
                local duration  = getXMLFloat(xmlFile, partKey .. '#duration');

                local startRot = getXMLString(xmlFile, partKey .. '#startRot');
                local endRot = getXMLString(xmlFile, partKey .. '#endRot');
                local startTrans = getXMLString(xmlFile, partKey .. '#startTrans');
                local endTrans = getXMLString(xmlFile, partKey .. '#endTrans');

                print(string.format('  part node=%s startTime=%s endTime=%s duration=%s startRot=%s endRot=%s startTrans=%s endTrans=%s',tostring(node),tostring(startTime),tostring(endTime),tostring(duration),tostring(startRot),tostring(endRot),tostring(startTrans),tostring(endTrans)));

            end;
            p = p + 1;
        end;

        a = a + 1;      
    end;
    print("end testing animations");