Call for Submission
NAB 2012 Best of the Best Show Reel
Submit your work today!
  • 1/3
You are here: Forum Home / Autodesk® Softimage® / XSI SDK / AddNurbsSurfaceMesh2 and JScript
  RSS 2.0 ATOM  

AddNurbsSurfaceMesh2 and JScript
Rate this thread
 
35845
 
Permlink of this thread   Subscribe to this thread
avatar
  • Location: St. Thomas, Ontario
  • Total Posts: 181
  • Joined: 24 February 2008 03:45 PM

Is it possible to create a mesh surface using AddNurbsSurfaceMesh2 in JScript.

I tried this code and the only thing I get is a “syntax error” at the last line.

// ------------------------------------------------------------------
// Test AddNurbsSurfaceMesh2
// ------------------------------------------------------------------ 

var oRoot Application.ActiveProject.ActiveScene.Root ;
var 
2/;

// Create array of control points in the format X,Y,Z,W,V,U with U rows and V colums

var aCv = new Array (

-22,  2100,
-
a2,  2101,
 
a2,  2102,
 
22,  2103,
-
20,  a110,
-
a0,  a111,
 
a0,  a112,
 
20,  a113,
-
20, -a120,
-
a0, -a121,
 
a0, -a122,
 
20, -a123,
-
21, -2130,
-
a1, -2131,
 
a1, -2132,
 
21, -21,  33 ) ;  


var 
ukv = new Array( 1.02.03.04.05.06.0 ) ;
var 
vkv = new Array( 1.02.03.04.05.06.0 ) ;


// Create nurbs surface from default values
// Count,ControlPoint,NbUControlPoints,NbVControlPoints,UKnots,NbUKnots,VKnots,NbVKnots,
// UDegree,VDegree,UClosed,VClosed,UParam,VParam,NurbsFormat,Name

var ns oRoot.AddNurbsSurfaceMesh2(1,aCv,,,ukv,,vkv,,,,,,,,siSINurbs,"MyDefaultNurbsSurface";


Replies: 0
avatar
  • mantom
  • Posted: 22 October 2009 07:33 AM

You need to make some changes to make this work:

First, you can’t pass an empty argument to a command in Jscript, you have to use an equivalent value depending on the parameter type.  Usually it’s the null keyword (null), but sometimes it may be an empty string ("") or the number zero (0).

example:

VBscript:
   
SomeFunction( , , , somevalue )

JScript
:
   
SomeFunction( nullnullnullsomevalue )

If the argument expects an array, then you must pass an array.  null won’t work in those cases.

Second, this command takes arrays as input for most of it’s arguments.  You’ll need to create a separate array for each argument and populate it with a value for each curve in U and V.  Think of this command as a ‘for’ loop which calls it’s cousin AddNurbsSurfaceMesh() iteratively.  Each time through the loop it pulls the n’th value in each array argument and uses those as the argument values.

Third, saw your post on XSIBase.com.  JScript arrays are always flattened to 1-dimensional arrays by XSI.  VBSafeArrays are read-only from JScript, but can be converted to JScript arrays using the .toArray() method

// XSI command returns an array as a VB Safe Array
var aVBSafeArray SomeXSIFunctionWhichReturnsAnArray()

// Convert the safe array to a JScript array.
// result is a 1-dimension JScript array
var aItems ( aVBSafeArray ).toArray()


Replies: 0
avatar

Thank you mantom for your quick reply. I was under the weather for the past week and was only able to reply to your comments today.

Thank you for the reminder about converting VBScript ,,,, to JScript ,null,null,null ...I knew about it as I did change some scripts before but I feel red in the face. I guess I’ll remember it this time! I guess every novice programmers goes through that more than once.

As for your comment about the AddNurbsSurfaceMesh2 accepting arrays, I did try to load the null and “” to confirm your statement and yes, the commands only accept arrays. So I modified the program in the explicit form to pass arrays to AddNurbsSurfaceMesh2.

The only result I got was crashing Softimage.

So, I guess their is more digging to do on that problem.

Thanks for your help and tips! Cheers!

Dan



Replies: 0
avatar

Well I was able to return to this issue lately but I hit an other wall. Maybe someone can help me.

As suggested by mantom, the AddNurbsSurfaceMesh2 call it’s cousin AddNurbsSurfaceMesh. So I tried to load the data direct to AddNurbsSurfaceMesh to see what happen.

here is the code I tried:

// --------------------------------------------------------------
//  Test # 1 to create a 4 x 4 nurbs mesh - AddNurbsSurfaceMesh
// --------------------------------------------------------------

var oRoot Application.ActiveProject.ActiveScene.Root ;
var 
0.66666667 ;

// Create an array of control points in the form U,V,X,Y,Z,W

var aCv [
0
,0,-2221,
0,1,-20a1,
0,2,-20,-a1,
0,3,-21,-21,
1,0,-a221,
1,1,-a0a1,
1,2,-a0,-a1,
1,3,-a1,-21,
2,0a221,
2,1a0a1,
2,2a0,-a1,
2,3a1,-21,
3,02221,
3,120a1,
3,220,-a1,
3,321,-21
;

var 
uKv [ 1.02.03.04.05.06.0 ] ;
var 
vkv [ 1.02.03.04.05.06.0 ] ;

// Create 2D array for count parameter (number of CV, number of uKnots, number of vKnots) per surface

var aCount [1466 ] ;

// Create nurbs surface from default values
// count, ControlPoints, UKnots, VKnots, UClosed, VClosed, UDegree, VDegree, UParam, VParam, NurbsFormat, Name

var ns oRoot.AddNurbsSurfaceMesh(
aCount
,
aCV,
ukv,
vkv,
[false],
[false],
[3],
[3],
[siNonUniformParameterization],
[siNonUniformParameterization],
siSINurbs,
"MyDefaultNurbsSurface";

The result of the code are:

a.  no error message;
b.  a nurbs surface object is created;

Unfortunately, the nurbs surface is not visible in the viewport which led me to believe that an argument was not passed properly to the constructor AddNurbsSurfaceMesh.

Your help in this matter is appreciated.



Replies: 0
avatar

I also tried the grid data object as follow, same result thought.

// --------------------------------------------------------------
//  Test # 2 to create a 4 x 4 nurbs mesh - AddNurbsSurfaceMesh
// --------------------------------------------------------------

var oRoot Application.ActiveProject.ActiveScene.Root ;
var 
0.66666667 ;

// Create an array of control points in the form U,V,X,Y,Z,W

var aCv [
0
,0,-2221,
0,1,-20a1,
0,2,-20,-a1,
0,3,-21,-21,
1,0,-a221,
1,1,-a0a1,
1,2,-a0,-a1,
1,3,-a1,-21,
2,0a221,
2,1a0a1,
2,2a0,-a1,
2,3a1,-21,
3,02221,
3,120a1,
3,220,-a1,
3,321,-21
;

var 
uKv [ 1.02.03.04.05.06.0 ] ;
var 
vkv [ 1.02.03.04.05.06.0 ] ;

// Create 2D array for count parameter (number of CV, number of uKnots, number of vKnots) per surface

var oGridData XSIFactory.CreateGridData()  // create the grid data object
oGridData.RowCount ;    // one row per nurbs surface
oGridData.ColumnCount // threes columns for control points, nb uKnots, nb vKnots
oGridData.SetCell(0,0,4) ;  // number of control points (x,y,z,w)
oGridData.SetCell(1,0,6) ;  // number of UKnots
oGridData.SetCell(2,0,6) ;  // number of VKnots


// Create nurbs surface from default values
// count, ControlPoints, UKnots, VKnots, UClosed, VClosed, UDegree, VDegree, UParam, VParam, NurbsFormat, Name

var ns oRoot.AddNurbsSurfaceMesh(
oGridData
,
aCV,
ukv,
vkv,
[false],
[false],
[3],
[3],
[siNonUniformParameterization],
[siNonUniformParameterization],
siSINurbs,
"MyDefaultNurbsSurface";


Replies: 1
/img/forum/dark/default_avatar.png

If you’re gonna pass a GridData object, you should pass “oGridData.Data” as the “.Data” is the array contained inside.

Author: mantom

Replied: 23 November 2009 12:46 PM  
avatar

Well found one mistake, I did not pass the control points argument correctly. It should be this way:

// Create array of control points in the format U,V,X0,Y0,Z0,W0 .... X(uv-1),Y(uv-1),Z(uv-1),W(uv-1)

var aCv [
4
,4,
-
22,  21,
-
a2,  21,
 
a2,  21,
 
22,  21,
-
20,  a1,
-
a0,  a1,
 
a0,  a1,
 
20,  a1,
-
20, -a1,
-
a0, -a1,
 
a0, -a1,
 
20, -a1,
-
21, -21,
-
a1, -21,
 
a1, -21,
 
21, -21 ] ;

Still no result, no display on the viewport.....hum! What to do!



Replies: 0
avatar

Hi mantom, thank you for the hint on the grid data.

so I modified the code as follows:

// ------------------------------------------------------------------
// Test 5 to creates 4x4 nurbs meshs - AddNurbsSurfaceMesh
// ------------------------------------------------------------------ 

var oRoot Application.ActiveProject.ActiveScene.Root ;
var 
0.6666667 ;

// Create array of control points in the format U,V,X0,Y0,Z0,W0 .... X(uv-1),Y(uv-1),Z(uv-1),W(uv-1)

var aCv [
4
,4,
-
22,  21,
-
a2,  21,
 
a2,  21,
 
22,  21,
-
20,  a1,
-
a0,  a1,
 
a0,  a1,
 
20,  a1,
-
20, -a1,
-
a0, -a1,
 
a0, -a1,
 
20, -a1,
-
21, -21,
-
a1, -21,
 
a1, -21,
 
21, -21 ] 

LogMessage (aCv) 

var 
ukv [ 1.02.03.04.05.06.0 ] ;
var 
vkv [ 1.02.03.04.05.06.0 ] ;

// Create GridData for 2D array

 
var oGridData XSIFactory.CreateGridData() ;
 
oGridData.RowCount // one row per nurbs surface
 
oGridData.ColumnCount // three columns for control vertex, nb uKnots, nb vKnots
 
oGridData.SetCell(0,0,4) // number of control vertex (x,y,z,w)
 
oGridData.SetCell(1,0,6) // number of uKnots in this case 6
 
oGridData.SetCell(2,0,6) // number of vKnots in this case 6

// Create nurbs surface from default values
// Count,ControlPoints,UKnots,VKnots,UClosed,VClosed,UDegree,VDegree,UParm,VParam,NurbsFormat,Name

var ns oRoot.AddNurbsSurfaceMesh(
oGridData
.Data,
aCv,
ukv,
vkv,
[false],
[false],
[3],
[3],
[siNonUniformParameterization],
[siNonUniformParameterization],
siSINurbs,
"MyDefaultNurbsSurface";

I feel I am getting closer but still no display of the nurbs surface. Quite a sticky this one.

Dan



Replies: 0
avatar

EUREKA!!!!

I suspected that AddNurbsSurfaceMesh created only empty object that I needed to feed data to it. So I modified the code to use AddNurbsSurface and voila! Nurbs surface as intended and visible in the viewport.

That was a learning experience. Thank You mantom for your help.

Here is the JScript code for future reference.

Cheers!

// ------------------------------------------------------------------------------
// Test 6 creates 4x4 nurbs meshs using AddNurbsSurfaceMesh and AddNurbsSurface
// ------------------------------------------------------------------------------ 

var oRoot Application.ActiveProject.ActiveScene.Root ;
var 
0.6666667 ;

// Create array of control points in the format U,V followed by X,Y,Z,W control points

var aCv [ 4,4,
-
22,  21,
-
a2,  21,
 
a2,  21,
 
22,  21,
-
20,  a1,
-
a0,  a1,
 
a0,  a1,
 
20,  a1,
-
20, -a1,
-
a0, -a1,
 
a0, -a1,
 
20, -a1,
-
21, -21,
-
a1, -21,
 
a1, -21,
 
21, -21 ] 

// Create two array vector of Knot values in the U and V directions

var ukv [ 1.02.03.04.05.06.0 ] ;
var 
vkv [ 1.02.03.04.05.06.0 ] ;

// Create an empty nurbs surface object

var ns oRoot.AddNurbsSurfaceMesh() ;

// Add nurbs surface to the empty nurb object and provide default values as follow
// ControlPoints,UKnots,VKnots,UClosed,VClosed,UDegree,VDegree,UParm,VParam,NurbsFormat

var oNurbsSurface ns.ActivePrimitive.Geometry.AddSurface(
aCv
,
ukv,
vkv ) ;

ns.name "myDefaultNurbsSurface" ;

// Create nurbs surface using explicit values

var ns2 oRoot.AddNurbsSurfaceMesh() ;

var 
oNurbsSurface2 ns2.ActivePrimitive.Geometry.AddSurface(
aCv
,
ukv,
vkv,
[false],
[false],
[2],
[2],
[siUniformParameterization],
[siUniformParameterization],
siSINurbs) ;

ns2.name "myExplicitNurbsSurface" ;


Replies: 0
avatar

And, yes it is possible to create nurbs surface object using AddNurbsSurfaceMesh2.

Here is the code:

// ------------------------------------------------------------------
// This JScript example creates 4x4 nurbs meshs AddNurbsSurfaceMesh2
// ------------------------------------------------------------------ 

var oRoot Application.ActiveProject.ActiveScene.Root ;
var 
.666667 ;

// Create an array of control points in the format U,V followed by X,Y,Z,W control points

var aCP [4,4,
-
22,  21,
-
a2,  21,
 
a2,  21,
 
22,  21,
-
20,  a1,
-
a0,  a1,
 
a0,  a1,
 
20,  a1,
-
20, -a1,
-
a0, -a1,
 
a0, -a1,
 
20, -a1,
-
21, -21,
-
a1, -21,
 
a1, -21,
 
21, -21   ] ;

var 
UKn [ 1.02.03.04.05.06.0 ] ;
var 
VKn [ 1.02.03.04.05.06.0 ] ;

// Create nurbs surface from default values
// Count,ControlPoint,NbUControlPoints,NbVControlPoints,UKnots,NbUKnots,VKnots,NbVKnots,
// UDegree,VDegree,UClosed,VClosed,UParam,VParam,NurbsFormat,Name

var ns oRoot.AddNurbsSurfaceMesh2(
1
,
aCP,
[4],
[4],
UKn,
[6],
VKn,
[6],
[3],
[3],
[false],
[false],
[siNonUniformParameterization],
[siNonUniformParameterization],
siSINurbs,
"MyDefaultNurbsSurface";

// Create a nurbs surface using explicit values

var ns oRoot.AddNurbsSurfaceMesh2(
1
,
aCP,
[4],
[4],
UKn,
[6],
VKn,
[6],
[2],
[2],
[false],
[false],
[siUniformParameterization],
[siUniformParameterization],
siSINurbs,
"MyExplicitNurbsSurface";

Cheers!



Replies: 0




   
  Settings Choose Theme color: