Re: Curve creation using geometry.set

Date : Wed, 2 Apr 2008 15:38:24 -0600
To : XSI(at)Softimage.COM
From : "Bradley Gabe" <withanar(at)gmail.com>
Subject : Re: Curve creation using geometry.set
Dave-

Here are a couple of functions that may help out. The first function bypasses using the Set() method in favor of AddNurbsCurve(), just because it is easy to build a curve from any point coordinates without having to set knot data.

The second function uses Get and Set to copy data from one curve to another (This only works for single curvelist objects). In the event you are having problems sorting through the data access, you can interrupt the data getting passed to see how it looks. Then hack it into what you need.

/////// jscript
/////// Build Crv using selected scene object positions
function CrvFromSelection(){
    pntArr = new Array();
    for(var e = new Enumerator(Selection); !e.atEnd(); e.moveNext()){

        gTrans = e.item().Kinematics.Global.Transform;
        gPos = XSIMath.CreateVector3();
        gTrans.GetTranslation(gPos);
        pntArr.push(   
            gPos.X,
            gPos.Y,
            gPos.Z,
            1
        );
    }
    crv = ActiveSceneRoot.AddNurbsCurve(pntArr, "", 0, 3, siNonUniformParameterization, siSINurbs, 'MyCurve');
    return(crv);
}


/////// jscript
/////// Get crv info from getCrvObj and copy it onto setCrvObj
function SwapCurve(setCrvObj, getCrvObj)
{ 
    var vbArgs = new VBArray(getCrvObj.ActivePrimitive.Geometry.Get2(siSINurbs));
    var args = vbArgs.toArray();
    FreezeObj(setCrvObj);       
    setCrvObj.ActivePrimitive.Geometry.Set(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], siSINurbs);
}


On Wed, Apr 2, 2008 at 3:06 PM, David Barosin <dbarosin(at)gmail.com> wrote:
I hope someone can shed light on this.  I'm trying to create curves using the geometry.set method.  To help me understand how this method functions I'm looking at what is returned with the geometry.get2 method in jscript. 

most everything looks fine except the array that returns the 'knot' information.

What I get is extra blank values at the end of the array.  I'm not sure what these values are.  If I leave the knot array as is and generate curves the geometry.set method works fine.  If I strip the blank values off the array I get an 'unexpected error' message.  What I'd eventually like to do is feed in my own controlPoint and knot info to geometry.set but I guess I need to understand what the blank values in the array mean.

Here is a script that demonstrates what I'm talking about.  It shows the knot count for both curves in the text object then displays the knot array with it's length.  If you uncomment the * display knot info ** it will list the knot info per curve. 



/////////////////begin

var oRoot = Application.ActiveProject.ActiveScene.Root;
var oText = oRoot.AddGeometry( "Text", "NurbsCurve" );
oText.text = "b";

var vbArgs = new VBArray(oText.ActivePrimitive.Geometry.Get2( siSINurbs ));
var args = vbArgs.toArray();

// Number of knots per curve
var vbArg7 = new VBArray(args[4]);
var nknots = vbArg7.toArray();
for (i = 0; i < nknots.length; i++)
{
LogMessage("number of knots for curve " + i + ": " + nknots[i] );
}

// Knots
var vbArg2 = new VBArray(args[3]);
var knots = vbArg2.toArray();

/*  display knot info *****************
for ( j=0; j<knots.length; j++)
{
    for (i = 0; i < nknots[j]; i++)
    {
        LogMessage("crv" + j + ": " + "knots" + i + ": " + knots[i]);
    }
}
*/

logmessage("knots = " + knots + "  "  + knots.length);


///////////////// end


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.