## Parametric modeling (Closed linear curves for start)

### Re: Parametric modeling (Closed linear curves for start)

JScript is good enough, I’ve been writing Js for years, but it gets messy with large codes. Not as bad as VBS but not as flexible as Python.

Now about renaming. In my example I’m creating a curve with CreateCurve, but it should work with SICreateCurve too.

crv = CreateCurve( 1, 0, positions, false)('Value')

Most SI commands return a collection object and the first object of that collection is usually the created object, so you can call it with (0).

This first value is also called “value” so you can call it by its name too like I’m doing it in that code (“value”).

I’m using a single line but probably in 2 lines is easier to understand :

crvResultCollection = CreateCurve( 1, 0, positions, false)

crv = crvResultCollection(0)

So since we are getting the new curve as an object with this crv variable, then you can rename it like this:

crv.Name = “NewCurveName”

And of course, verify it with:

LogMessage ( crv )

This crv is the curve object, just like if you were getting it with Selection(0)

Or you can just reuse this variable as the name of your object in the next commands like ray was saying. I kinda misunderstood your question and wrote a long explanation.

In SI if you use an object variable in a command, th command will automatically use this object’s FullName, just be aware that this object isn’t really a string. Well, in Jscript you won’t notice the difference but in python you can’t concatenate an object with a string so you’ll have to use .FullName or str() to “convert” this object to string.

About the ruler, Cesar’s CSruler works pretty well, have you tried it ?

Now about renaming. In my example I’m creating a curve with CreateCurve, but it should work with SICreateCurve too.

crv = CreateCurve( 1, 0, positions, false)('Value')

Most SI commands return a collection object and the first object of that collection is usually the created object, so you can call it with (0).

This first value is also called “value” so you can call it by its name too like I’m doing it in that code (“value”).

I’m using a single line but probably in 2 lines is easier to understand :

crvResultCollection = CreateCurve( 1, 0, positions, false)

crv = crvResultCollection(0)

So since we are getting the new curve as an object with this crv variable, then you can rename it like this:

crv.Name = “NewCurveName”

And of course, verify it with:

LogMessage ( crv )

This crv is the curve object, just like if you were getting it with Selection(0)

Or you can just reuse this variable as the name of your object in the next commands like ray was saying. I kinda misunderstood your question and wrote a long explanation.

In SI if you use an object variable in a command, th command will automatically use this object’s FullName, just be aware that this object isn’t really a string. Well, in Jscript you won’t notice the difference but in python you can’t concatenate an object with a string so you’ll have to use .FullName or str() to “convert” this object to string.

About the ruler, Cesar’s CSruler works pretty well, have you tried it ?

M.Yara

Character Modeler | Softimage Generalist (sort of)

Character Modeler | Softimage Generalist (sort of)

### Re: Parametric modeling (Closed linear curves for start)

Thanks both rray and myara for solving the nameconflict prob! fixed previus posts

The CS Ruler is definatelly great measuurning tool i might used in the past not sure xd.

But i think im suggesting something beyond a measuring tool.

Example:

Lets say that i want to set that distance to 7 so the cube is automatically scaled accordingly.

Iv tried to unlock the parameter but it wont allow me. My suggestion is a ruler that is also a parametric tool that lets you rescale 2 in 1.

The CS Ruler is definatelly great measuurning tool i might used in the past not sure xd.

But i think im suggesting something beyond a measuring tool.

Example:

Lets say that i want to set that distance to 7 so the cube is automatically scaled accordingly.

Iv tried to unlock the parameter but it wont allow me. My suggestion is a ruler that is also a parametric tool that lets you rescale 2 in 1.

Last edited by mc_axe on 07 Jan 2018, 19:53, edited 1 time in total.

### Re: Parametric modeling (Closed linear curves for start)

Well it came to my mind now that i could simply divide 7/curent lenght of the ruler, to get the new scaling for the cube that will result to a new mesurment of 7 it worked actually.

- Daniel Brassard
**Posts:**817**Joined:**18 Mar 2010, 23:38**Location:**St. Thomas, Ontario-
**Contact:**

### Re: Parametric modeling (Closed linear curves for start)

Here is how I do these parametric curve and surfaces in JS. Extracted from the parametric formula plugin available in the softimage resources.

Note: a line is of degree 0, KN = knot, CP = Control Points

In the code, I create an empty array and then push the points parameters in the array. I then use the array as input to the curve or nubs surface.

http://softimage.wiki.softimage.com/xsi ... inuity.htm

Code: Select all

```
// Initialize the u and v Knot arrays
var uKN = [];
var vKN = [];
// Calculate number of knots needed for parameterization
var nbUKN = nbUCP + u_Degree - 1 ;
var nbVKN = nbVCP + v_Degree - 1 ;
var uKN_Start = u_Degree - 1 ;
var vKN_Start = v_Degree - 1 ;
var uKN_End = nbUCP - 1 ;
var vKN_End = nbVCP - 1 ;
// Populate the knot arrays in u and v
for ( i=1; i<= u_Degree; i++) {uKN.push(uKN_Start);} // Start knot with multiplicity equal to the order
for ( i=uKN_Start+1; i<= uKN_End - 1; i++) { uKN.push(i);}
for ( i=1; i<= u_Degree; i++) {uKN.push(uKN_End);} // End knot with multiplicity equal to the order
for ( i=1; i<= v_Degree; i++) {vKN.push(vKN_Start);}
for ( i=vKN_Start+1; i<= vKN_End - 1; i++) { vKN.push(i);}
for ( i=1; i<= v_Degree; i++) {vKN.push(vKN_End);}
// curve parameterization option
if (PPG.u_Parameter.Value == 0) {u_Param = "siUniformParameterization";}
else if (PPG.u_Parameter.Value == 2) {u_Param = "siChordLengthParameterization";}
else if (PPG.u_Parameter.Value == 3) {u_Param = "siCentripedalParameterization";}
else {u_Param = "siNonUniformParameterization";}
if (PPG.v_Parameter.Value == 0) {v_Param = "siUniformParameterization";}
else if (PPG.v_Parameter.Value == 2) {v_Param = "siChordLengthParameterization";}
else if (PPG.v_Parameter.Value == 3) {v_Param = "siCentripedalParameterization";}
else {v_Param = "siNonUniformParameterization";}
// Create nurbs surface
var ns = oRoot.AddNurbsSurfaceMesh2(
Count, aControlPoints, [nbUCP], [nbVCP],
uKN, [nbUKN], vKN, [nbVKN],
[u_Degree],[v_Degree],
[u_Closed],[v_Closed],
[u_Param],[v_Param],
siSINurbs, Name
) ;
```

In the code, I create an empty array and then push the points parameters in the array. I then use the array as input to the curve or nubs surface.

http://softimage.wiki.softimage.com/xsi ... inuity.htm

$ifndef "Softimage"

set "Softimage" "true"

$endif

set "Softimage" "true"

$endif

### Re: Parametric modeling (Closed linear curves for start)

It seems like you only pasted one half of the code.

M.Yara

Character Modeler | Softimage Generalist (sort of)

Character Modeler | Softimage Generalist (sort of)

- Daniel Brassard
**Posts:**817**Joined:**18 Mar 2010, 23:38**Location:**St. Thomas, Ontario-
**Contact:**

### Re: Parametric modeling (Closed linear curves for start)

@Myara

I only pasted a portion of the code is correct as the entire plugin is over 600 lines of codes. For that just download the plugin from the Softimage Resources area (search for "parametric formula") and unzip the plugin to a file. The entire code is JScript and include over 100 preset shapes.

I only pasted a portion of the code is correct as the entire plugin is over 600 lines of codes. For that just download the plugin from the Softimage Resources area (search for "parametric formula") and unzip the plugin to a file. The entire code is JScript and include over 100 preset shapes.

$ifndef "Softimage"

set "Softimage" "true"

$endif

set "Softimage" "true"

$endif

### Re: Parametric modeling (Closed linear curves for start)

Thanx Daniel gr8 contribution to the thread! For a momment i was thinking that i might be the only one not understanding why that code is not working right away

100 shapes sound alot! Is there any shapes that we dont have access through UI?

100 shapes sound alot! Is there any shapes that we dont have access through UI?

### Re: Parametric modeling (Closed linear curves for start)

Onwards with simple shapes in JScript

Shapes like regular triangle, square, pentagon, hexagon etc fall in that category of Regullar Convex Polygons, we can simply call them nGon (n= any value):

In the link you can see a little information about the shape components

Now for a simple script that produces a n-Gon (Linear curve) will need a given 'radius' and 'n'

Then we can solve the possitions of the points within a for loop, with help from sin and cos

We also want a function that will help so we dont have trouble with radians and angles.

A better version of that script could be one that logs more info:
For a real parametric challenge we should have the ability to define the shape with more than 1 cases of given parameters. We need at least one type indicator that will result to spcific 'n' and one size indicator that will result to a certain 'radius', if we have 5x5 parameters, we should normaly solve the problem 25 times! To overcome this problem with my nub scripting skillz as iI said earlir I came up with a loop that calls find_parameter() functions till problem is solved. The find functions would return same value i

Next script generates an n-Gon with more than 25 combos of given values. If the n gon is REGGULAR you get a notification in LOG

Certain values (on type parameters) will result to a 'n' that corespond to no case of regular polygon then youll get an IRREGULAR notification and the result will have at least one irregular component.

For the following script i will credit my friend Spasi for converting my horible non optimized code to something that i barelly understand xD.

Shapes like regular triangle, square, pentagon, hexagon etc fall in that category of Regullar Convex Polygons, we can simply call them nGon (n= any value):

**The Parametric n Gon challenge!**In the link you can see a little information about the shape components

Now for a simple script that produces a n-Gon (Linear curve) will need a given 'radius' and 'n'

Then we can solve the possitions of the points within a for loop, with help from sin and cos

We also want a function that will help so we dont have trouble with radians and angles.

Code: Select all

```
var n = 500;
var radius = 6;
var angle = 360 / n;
function toRadians (angle) {
return angle * (Math.PI / 180);
}
var pointslist="";
for(i = 0; i <= n-1; i++) {
pointslist+="("+radius*Math.cos(toRadians(angle * i))+","+radius * Math.sin(toRadians(angle * i))+",0),";
}
pointslist=pointslist.slice(0,-1);
crv=SICreateCurve("nGon", 1, 1);
SISetCurvePoints( crv, pointslist, false );
ApplyTopoOp("CrvOpenClose", crv, i, siPersistentOperation, null);
```

Code: Select all

```
//LINEAR CURVES -REGULAR CONVEX POLYGON or N-GON (Definition with 'n' and 'radius')
var n = 7; //'N' of the NGon
var radius = 6; //RADIUS or Circumradius
//calcs
function toRadians (angle) { //receives angles returns radians
return angle * (Math.PI / 180);
}
var angle = 360 / n; //MAIN ANGLE or vertex (or apex for each isosceles Triangle )
var innerAngle=180-(360/n); //INTERNAL angle
var extAngle=180-innerAngle; //SUPPLEMENTARY angle or exterior
var hIA=innerAngle/2; //BASE ANGLE there are 2 equals in each isosceles triangle
var dCount=(n*(n-3))/2; //Possible diagonals counter
var tanDist =Math.sin(toRadians(hIA))*radius; //INRADIUS the tangent Distance from a side to the center
var sideL=2*Math.sqrt(Math.pow(radius,2)-Math.pow(tanDist,2));//SIDE LENGTH
var areaIso=tanDist*sideL/2; //AREA of each isosceles TRIANGLE
var area=areaIso*n; //TOTAL AREA OF NGON
var pointslist="";
for(i = 0; i <= n-1; i++) {
pointslist+="("+radius*Math.cos(toRadians(angle * i))+","+radius * Math.sin(toRadians(angle * i))+",0),";
}
pointslist=pointslist.slice(0,-1);
crv=SICreateCurve("nGon", 1, 1);
SISetCurvePoints( crv, pointslist, false );
ApplyTopoOp("CrvOpenClose", crv, i, siPersistentOperation, null);
SelectObj(crv, null, true);
LogMessage(
"Succesfully generated nGon with n = "+n+
"\nCircum-Radius :"+radius+
"\n\nInradius: "+tanDist+
"\nMain Angle (360°/n): "+angle+
"°\nInterior Angle: "+innerAngle+
"°\nSupplementary Angle: "+extAngle+
"°\nPossible diagonals: "+dCount+
"\nSide Lenght: "+sideL+
"\nArea of each isosceles triangle: "+areaIso+
"\nArea of nGon: "+area
);
```

*f already defined*or would try to solve the*undefined*variables with help from something else that is potentially defined. So i had to write a bounch of relationships for each parameter. And it worked with maximum 5 loops it solved all other variables.But i will present a better case of what i did:Next script generates an n-Gon with more than 25 combos of given values. If the n gon is REGGULAR you get a notification in LOG

Certain values (on type parameters) will result to a 'n' that corespond to no case of regular polygon then youll get an IRREGULAR notification and the result will have at least one irregular component.

For the following script i will credit my friend Spasi for converting my horible non optimized code to something that i barelly understand xD.

Code: Select all

```
//LINEAR CURVES -REGULAR CONVEX POLYGON or N-GON (Parametric)
//Regullar Convex Polygon or N-Gon
//Define it by at list 2 parameters that indicate type and size .
//Type indicators
var n;
var angle=10;
var innerAngle;
var extAngle;
var hIA;
//Size indicators
var radius;
var area;
var tanDist;
var sideL;
var areaIso=45;
//DEBUG
var dCount;//todo add relationship that results to a 'n'
function toRadians(angle) {
return angle * (Math.PI / 180);
}
function property(initValue, calc) {
var value = initValue;
var inCalc = false;
return function() {
if (value !== undefined) {
return value;
}
if (!inCalc) {
inCalc = true;
try {
value = calc.call(this);
} finally {
inCalc = false;
}
}
return value;
}
}
polygon = (function() {
function isRegular() {
var n = this.n();
return (n | 0) === n;
}
return {
isValid: function() {
// TODO: validate input
return this.n() !== undefined && this.angle() !== undefined && this.radius() !== undefined;
},
n: property(n, function() {
var angle = this.angle();
if (angle !== undefined) {
return 360.0 / angle;
}
return undefined;
}),
angle: property(angle, function() {
var n = this.n();
if (n !== undefined) {
return 360 / n;
}
var hIA = this.hIA();
if (hIA !== undefined) {
return 180 - 2 * hIA;
}
return undefined;
}),
hIA: property(hIA, function() {
var innerAngle = this.innerAngle();
if (innerAngle !== undefined) {
return innerAngle * 0.5;
}
return undefined;
}),
innerAngle: property(innerAngle, function() {
var n = this.n();
if (n !== undefined) {
return 180 - (360 / n);
}
var extAngle = this.extAngle();
if (extAngle !== undefined) {
return 180 - extAngle;
}
return undefined;
}),
extAngle: property(extAngle, function() {
var innerAngle = this.innerAngle();
if (innerAngle !== undefined) {
return 180 - innerAngle;
}
return undefined;
}),
radius: property(radius, function() {
var sideL = this.sideL();
var angle = this.angle();
if (sideL !== undefined && angle !== undefined) {
return (sideL * 0.5) / Math.sin(toRadians(angle * 0.5));
}
return undefined;
}),
sideL: property(sideL, function() {
var radius = this.radius();
var angle = this.angle();
if (radius !== undefined && angle !== undefined) {
return 2 * Math.sin(toRadians(angle * 0.5)) * radius
}
var tanDist = this.tanDist();
if (tanDist !== undefined && angle !== undefined) {
return 2 * tanDist * Math.tan(toRadians(angle * 0.5));
}
if (radius !== undefined && tanDist !== undefined) {
return 2 * Math.sqrt(Math.pow(radius, 2) - Math.pow(tanDist, 2));
}
return undefined;
}),
tanDist: property(tanDist, function() {
var sideL = this.sideL();
var angle = this.angle();
if (sideL !== undefined) {
return sideL / (2 * Math.tan(toRadians(angle * 0.5)));
}
var areaIso = this.areaIso();
if (areaIso !== undefined && angle !== undefined) {
return Math.sqrt(areaIso / Math.tan(toRadians(angle * 0.5)));
}
return undefined;
}),
areaIso: property(areaIso, function() {
var area = this.area();
var n = this.n();
if (area !== undefined && n !== undefined) {
return area / n;
}
var tanDist = this.tanDist();
var sideL = this.sideL();
if (tanDist !== undefined && sideL !== undefined) {
return (tanDist * sideL) * 0.5;
}
return undefined;
}),
area: property(area, function() {
var n = this.n();
var areaIso = this.areaIso();
if (n !== undefined && areaIso !== undefined) {
return n * areaIso;
}
return undefined;
}),
dCount: property(dCount, function() {
var n = this.n();
if (n !== undefined) {
return (n * (n - 3)) * 0.5;
}
return undefined;
}),
render: function() {
LogMessage(
"\nn: " + this.n() + (isRegular.call(this) ? " REGULAR" : " IRREGULAR ") +
"\nCircum-Radius: " + this.radius() +
"\nIn-Radius: " + this.tanDist() +
"\nSide Length: " + this.sideL() +
"\n\nMain Angle (360°/n): " + this.angle() + "°" +
"\nInterior Angle: " + this.innerAngle() +
"\nIntAngle/2 " + this.hIA() + "°" +
"\nExt_Angle: " + this.extAngle() +
"\n\nArea of each isosceles triangle: " + this.areaIso() +
"\nArea of nGon: " + this.area() +
"\nPossible diagonals: " + this.dCount()
);
var n = this.n();
var angle = this.angle();
var radius = this.radius();
var pointsList = "";
for (i = 0; i <= n - 1; i++) {
pointsList += "(" + radius * Math.cos(toRadians(angle * i)) + "," + radius * Math.sin(toRadians(angle * i)) + ",0),";
}
pointsList = pointsList.slice(0, -1);
return pointsList;
}
};
})();
if (polygon.isValid()) {
var pointsList = polygon.render();
//*
crv=SICreateCurve("nGon", 1, 1);
SISetCurvePoints(crv, pointsList, false);
ApplyTopoOp("CrvOpenClose", crv, i, siPersistentOperation, null);
SelectObj(crv, null, true);
//*/
}
```

### Re: Parametric modeling (Closed linear curves for start)

Oh, now I see what you were trying to do.

There is an addon called keyvis Curve Tools, it's been written in JScript and it's nGon plugin does exactly that:

http://www.keyvis.at/cg-tools/tools-for ... rve-tools/

And although converting degrees to radians is something very simple, you have a couple of XSI tools:

XSIMath.DegreesToRadians()

XSIMath.RadiansToDegrees()

There is an addon called keyvis Curve Tools, it's been written in JScript and it's nGon plugin does exactly that:

http://www.keyvis.at/cg-tools/tools-for ... rve-tools/

And although converting degrees to radians is something very simple, you have a couple of XSI tools:

XSIMath.DegreesToRadians()

XSIMath.RadiansToDegrees()

M.Yara

Character Modeler | Softimage Generalist (sort of)

Character Modeler | Softimage Generalist (sort of)

- Daniel Brassard
**Posts:**817**Joined:**18 Mar 2010, 23:38**Location:**St. Thomas, Ontario-
**Contact:**

### Re: Parametric modeling (Closed linear curves for start)

@MC_Axe

Is there any shapes that we don't have access through UI?

Not really. Providing you don't exceed the number of variables provided in the UI. Their is a way to go around it by entering values directly in the formula.

There is a limitation to the code as it is not a formula parser so it will not handle strange formulas. The code has very limited error detection so it will crash Softimage if the formula solver goes to infinity/division by zero or looping funny. The code is open so anybody can modify it to their needs. I left it open so that anybody with better coding skill can modify it and make it more robust. In the spirit of sharing, I would appreciated any improvement to the code be shared as well with the community.

The code create nurbs surface (i.e. it fold a nurbs plane into all kind of shape). You can convert the nurbs shape to polygons after if you need it.

Is there any shapes that we don't have access through UI?

Not really. Providing you don't exceed the number of variables provided in the UI. Their is a way to go around it by entering values directly in the formula.

There is a limitation to the code as it is not a formula parser so it will not handle strange formulas. The code has very limited error detection so it will crash Softimage if the formula solver goes to infinity/division by zero or looping funny. The code is open so anybody can modify it to their needs. I left it open so that anybody with better coding skill can modify it and make it more robust. In the spirit of sharing, I would appreciated any improvement to the code be shared as well with the community.

The code create nurbs surface (i.e. it fold a nurbs plane into all kind of shape). You can convert the nurbs shape to polygons after if you need it.

$ifndef "Softimage"

set "Softimage" "true"

$endif

set "Softimage" "true"

$endif

- Daniel Brassard
**Posts:**817**Joined:**18 Mar 2010, 23:38**Location:**St. Thomas, Ontario-
**Contact:**

### Re: Parametric modeling (Closed linear curves for start)

The NGon challenge is a good start to understand all kind of formula variation. The points are simply a location on a circle. You basically translate the x,y coordinates to polar coordinates on the circle.

x = r cos(tetha)

y = r sin(tetha)

where r is the radius of the circle and tetha is the angle in radians measured from the X axis

https://en.wikipedia.org/wiki/Polar_coordinate_system

In 3D, x,y,z would translate to polar coordinates on a sphere.

There is even a parametric formula for gears

http://mathworld.wolfram.com/GearCurve.html

x = r cos(tetha)

y = r sin(tetha)

where r is the radius of the circle and tetha is the angle in radians measured from the X axis

https://en.wikipedia.org/wiki/Polar_coordinate_system

In 3D, x,y,z would translate to polar coordinates on a sphere.

There is even a parametric formula for gears

http://mathworld.wolfram.com/GearCurve.html

$ifndef "Softimage"

set "Softimage" "true"

$endif

set "Softimage" "true"

$endif

### Who is online

Users browsing this forum: No registered users and 1 guest