Forum

FORUMS > EON Authoring Tools Forum > Mapping a Path Using KeyFrame Node and Scripting
RE: Mapping a Path Using KeyFrame Node and Scriptingtop^
Sunil Naidu
Username: sunil.naidu
Posted: Fri 1 Jul, 2011 6:58 AM
2691 days ago
Location: United States
Maintenance

I need an object to follow a set of control points from a database.  I was able to trace the control points coming from the database successfully into the log file, but my keyframe node does not record those points correctly.  The last control point is the only set that is recorded successfully.  Any suggestions on what I may be doing incorrectly?

 

 

 db.txt

RE: Mapping a Path Using KeyFrame Node and Scriptingtop^
Sunil Naidu
Username: sunil.naidu
Posted: Fri 1 Jul, 2011 7:01 AM
2691 days ago
Location: United States
Maintenance

Figured out what happened:

 

When adding control points via script to the KeyFrame node, the for loop needs to decrement from total number of records that are in your database file.

 Example:

 

     // select data and send to Sphere node
    rset.Source = "Select x, y, z, time from trajectory";
    rset.Open();

    var pos = new Array();
    var t;
    var newpos = new Array();
    var k = rset.RecordCount;
    
    for (var i = k-1; i>=0; i--)
    {
        eon.findnode("SphereTraj").GetFieldByName("SortPoints").value = false;
        pos[0] = rset.Fields("x").value;
        pos[1] = rset.Fields("y").value;
        pos[2] = rset.Fields("z").value;
        t = rset.Fields("time").value;

        // page 517 Multiple Value Fields - field needs to be a VBArray data type
        newpos = eon.MakeSFVec3f(pos[0], pos[1], pos[2]);    // create an SFVec3f type value
        
        eon.findnode("SphereTraj").GetFieldByName("Times").SetMFElement(i, t);    //KeyFrame node    
        eon.findnode("SphereTraj").GetFieldByName("Positions").SetMFElement(i, newpos);
        eon.findnode("SphereTraj").GetFieldByName("SortPoints").value = true;
        
        eon.Trace(pos[0] + " " + pos[1] + " " + pos[2] + " " + t);
        rset.MoveNext();
    }
    rset.Close();
    FollowPath();
}

function FollowPath()
{
    eon.findnode("SphereTraj").GetFieldByName("SetRun").value = true;
}