|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
| AddNurbsSurfaceMesh2 and JScript
|
|
|
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 a = 2/3 ;
// Create array of control points in the format X,Y,Z,W,V,U with U rows and V colums
var aCv = new Array (
-2, 2, 2, 1, 0, 0,
-a, 2, 2, 1, 0, 1,
a, 2, 2, 1, 0, 2,
2, 2, 2, 1, 0, 3,
-2, 0, a, 1, 1, 0,
-a, 0, a, 1, 1, 1,
a, 0, a, 1, 1, 2,
2, 0, a, 1, 1, 3,
-2, 0, -a, 1, 2, 0,
-a, 0, -a, 1, 2, 1,
a, 0, -a, 1, 2, 2,
2, 0, -a, 1, 2, 3,
-2, 1, -2, 1, 3, 0,
-a, 1, -2, 1, 3, 1,
a, 1, -2, 1, 3, 2,
2, 1, -2, 1, 3, 3 ) ;
var ukv = new Array( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ) ;
var vkv = new Array( 1.0, 2.0, 3.0, 4.0, 5.0, 6.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") ;
|
|
|
|
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( null, null, null, somevalue )
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()
|
|
|
|
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
|
|
|
|
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 a = 0.66666667 ;
// Create an array of control points in the form U,V,X,Y,Z,W
var aCv = [
0,0,-2, 2, 2, 1, 0,1,-2, 0, a, 1, 0,2,-2, 0,-a, 1, 0,3,-2, 1,-2, 1, 1,0,-a, 2, 2, 1, 1,1,-a, 0, a, 1, 1,2,-a, 0,-a, 1, 1,3,-a, 1,-2, 1, 2,0, a, 2, 2, 1, 2,1, a, 0, a, 1, 2,2, a, 0,-a, 1, 2,3, a, 1,-2, 1, 3,0, 2, 2, 2, 1, 3,1, 2, 0, a, 1, 3,2, 2, 0,-a, 1, 3,3, 2, 1,-2, 1
] ;
var uKv = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ;
var vkv = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ;
// Create 2D array for count parameter (number of CV, number of uKnots, number of vKnots) per surface
var aCount = [1, 4, 6, 6 ] ;
// 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.
|
|
|
|
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 a = 0.66666667 ;
// Create an array of control points in the form U,V,X,Y,Z,W
var aCv = [
0,0,-2, 2, 2, 1, 0,1,-2, 0, a, 1, 0,2,-2, 0,-a, 1, 0,3,-2, 1,-2, 1, 1,0,-a, 2, 2, 1, 1,1,-a, 0, a, 1, 1,2,-a, 0,-a, 1, 1,3,-a, 1,-2, 1, 2,0, a, 2, 2, 1, 2,1, a, 0, a, 1, 2,2, a, 0,-a, 1, 2,3, a, 1,-2, 1, 3,0, 2, 2, 2, 1, 3,1, 2, 0, a, 1, 3,2, 2, 0,-a, 1, 3,3, 2, 1,-2, 1
] ;
var uKv = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ;
var vkv = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.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 = 1 ; // one row per nurbs surface oGridData.ColumnCount = 3 ; // 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") ;
|
|
|
|
|
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
|
|
|
|
|
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,
-2, 2, 2, 1,
-a, 2, 2, 1,
a, 2, 2, 1,
2, 2, 2, 1,
-2, 0, a, 1,
-a, 0, a, 1,
a, 0, a, 1,
2, 0, a, 1,
-2, 0, -a, 1,
-a, 0, -a, 1,
a, 0, -a, 1,
2, 0, -a, 1,
-2, 1, -2, 1,
-a, 1, -2, 1,
a, 1, -2, 1,
2, 1, -2, 1 ] ;
Still no result, no display on the viewport.....hum! What to do!
|
|
|
|
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 a = 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,
-2, 2, 2, 1,
-a, 2, 2, 1,
a, 2, 2, 1,
2, 2, 2, 1,
-2, 0, a, 1,
-a, 0, a, 1,
a, 0, a, 1,
2, 0, a, 1,
-2, 0, -a, 1,
-a, 0, -a, 1,
a, 0, -a, 1,
2, 0, -a, 1,
-2, 1, -2, 1,
-a, 1, -2, 1,
a, 1, -2, 1,
2, 1, -2, 1 ] ;
LogMessage (aCv) ;
var ukv = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ;
var vkv = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ;
// Create GridData for 2D array
var oGridData = XSIFactory.CreateGridData() ;
oGridData.RowCount = 1 ; // one row per nurbs surface
oGridData.ColumnCount = 3 ; // 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
|
|
|
|
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 a = 0.6666667 ;
// Create array of control points in the format U,V followed by X,Y,Z,W control points
var aCv = [ 4,4,
-2, 2, 2, 1,
-a, 2, 2, 1,
a, 2, 2, 1,
2, 2, 2, 1,
-2, 0, a, 1,
-a, 0, a, 1,
a, 0, a, 1,
2, 0, a, 1,
-2, 0, -a, 1,
-a, 0, -a, 1,
a, 0, -a, 1,
2, 0, -a, 1,
-2, 1, -2, 1,
-a, 1, -2, 1,
a, 1, -2, 1,
2, 1, -2, 1 ] ;
// Create two array vector of Knot values in the U and V directions
var ukv = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ;
var vkv = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.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" ;
|
|
|
|
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 a = .666667 ;
// Create an array of control points in the format U,V followed by X,Y,Z,W control points
var aCP = [4,4,
-2, 2, 2, 1,
-a, 2, 2, 1,
a, 2, 2, 1,
2, 2, 2, 1,
-2, 0, a, 1,
-a, 0, a, 1,
a, 0, a, 1,
2, 0, a, 1,
-2, 0, -a, 1,
-a, 0, -a, 1,
a, 0, -a, 1,
2, 0, -a, 1,
-2, 1, -2, 1,
-a, 1, -2, 1,
a, 1, -2, 1,
2, 1, -2, 1 ] ;
var UKn = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ;
var VKn = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.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!
|
|
|
|
| Settings
| Choose Theme color:
|
|
|
|
|
|
|