Jun
17

Two Surface Space Frame (MEL)

This could be done with many different softwares/methods. Some time last year, I was looking at MEL to write this script that uses two different surfaces to simulate a space frame according to U/V divisions. This can now be easily performed with just a few steps using Grasshopper (Explicit History Plug-in) in Rhino.

//
// Script written by Howard Jiho Kim | kimjiho@gmail.com | crtl-i.com | 2007
//
// ex.
// spFrSurface(srfName1, srfName2, U, V)
// spFrSurface(“nurbsPlane1″, “nurbsPlane2″, 10, 10)
//

// HORIZONTAL MEMBERS!!

global proc spFrSurface(string $nurb, string $nurb2, int $u, int $v)
{
gridSurface($nurb, $u,$v);
gridSurface($nurb2, $u,$v);

float $u_inc = 1.0/$u;
float $v_inc = 1.0/$v;
float $cv[], $cv2[], $cv3[];

float $i2, $k2;

// get U information

$u = $u + 1;
$v = $v + 1;

for($i=0;$i<$u;$i++)
{
for($k=0;$k<$v;$k++)
{

$i2 = $u_inc * $i;
print (“u:” + $i2 + ” | “);
$k2 = $v_inc * $k;
print (“v:” + $k2 + ” | “);
$cv = `pointOnSurface -u $i2 -v $k2 -position $nurb`;
print( $cv[0] +” “+ $cv[1] +” “+ $cv[2]  + ” | “);

$cv2 = `pointOnSurface -u $i2 -v $k2 -position $nurb2`;
print( $cv2[0] +” “+ $cv2[1] +” “+ $cv2[2] +”\n”);

curve -d 1 -p $cv[0] $cv[1] $cv[2] -p $cv2[0] $cv2[1] $cv2[2] -k 0 -k 1;

// print CV

//$x[$k] = $cv[0];
//$y[$k] = $cv[1];
//$z[$k] = $cv[2];

}

//$curveName[$i] = `curve -p $x[0] $y[0] $z[0] -p $x[1] $y[1] $z[1] -p $x[2] $y[2] $z[2] -p $x[3] $y[3] $z[3] -p $x[4] $y[4] $z[4] -p $x[5] $y[5] $z[5] -p $x[6] $y[6] $z[6] -p $x[7] $y[7] $z[7]`;
}
}

// LONGITUDINAL MEMBERS
global proc gridSurface(string $nurb, int $u, int $v)
{
float $u_inc = 1.0/$u;
float $v_inc = 1.0/$v;
float $cv[], $cv2[], $cv3[];

float $i2, $k2;

// get U information

$u = $u + 1;

for($i=0;$i<$u;$i++)
{
for($k=0;$k<$v;$k++)
{

$i2 = $u_inc * $i;
print (“u:” + $i2 + ” | “);
$k2 = $v_inc * $k;
print (“v:” + $k2 + ” | “);
$cv = `pointOnSurface -u $i2 -v $k2 -position $nurb`;
print( $cv[0] +” “+ $cv[1] +” “+ $cv[2]  + ” | “);

$k3 = $v_inc * ($k+1);

$cv2 = `pointOnSurface -u $i2 -v $k3 -position $nurb`;
print( $cv2[0] +” “+ $cv2[1] +” “+ $cv2[2] +”\n”);

curve -d 1 -p $cv[0] $cv[1] $cv[2] -p $cv2[0] $cv2[1] $cv2[2] -k 0 -k 1;

// print CV

//$x[$k] = $cv[0];
//$y[$k] = $cv[1];
//$z[$k] = $cv[2];

}

//$curveName[$i] = `curve -p $x[0] $y[0] $z[0] -p $x[1] $y[1] $z[1] -p $x[2] $y[2] $z[2] -p $x[3] $y[3] $z[3] -p $x[4] $y[4] $z[4] -p $x[5] $y[5] $z[5] -p $x[6] $y[6] $z[6] -p $x[7] $y[7] $z[7]`;
}

// get U information

$v = $v + 1;
$u = $u – 1;

for($i=0;$i<$v;$i++)
{
for($k=0;$k<$u;$k++)
{

$i2 = $u_inc * $k;
print (“u:” + $i2 + ” | “);
$k2 = $v_inc * $i;
print (“v:” + $k2 + ” | “);
$cv = `pointOnSurface -u $i2 -v $k2 -position $nurb`;
print( $cv[0] +” “+ $cv[1] +” “+ $cv[2]  + ” | “);

$i3 = $u_inc * ($k+1);

$cv2 = `pointOnSurface -u $i3 -v $k2 -position $nurb`;
print( $cv2[0] +” “+ $cv2[1] +” “+ $cv2[2] +”\n”);

curve -d 1 -p $cv[0] $cv[1] $cv[2] -p $cv2[0] $cv2[1] $cv2[2] -k 0 -k 1;

// print CV

//$x[$k] = $cv[0];
//$y[$k] = $cv[1];
//$z[$k] = $cv[2];

}

//$curveName[$i] = `curve -p $x[0] $y[0] $z[0] -p $x[1] $y[1] $z[1] -p $x[2] $y[2] $z[2] -p $x[3] $y[3] $z[3] -p $x[4] $y[4] $z[4] -p $x[5] $y[5] $z[5] -p $x[6] $y[6] $z[6] -p $x[7] $y[7] $z[7]`;
}
}

Add your comment

6 responses for this post

  1. alex Says:

    can you run this script in 3dsmax?

  2. crtl-i Says:

    alex.

    i don’t think so. some commands used in this script are probably only for maya.

  3. curious Says:

    cool script but i get a syntax error…

  4. crtl-i Says:

    curious.

    make sure when you copy the script from the web that the ” and ‘ get inserted correctly.

  5. mikoaj Says:

    i can’t make this script working :(

    i’m scating two nurbs planes, select them and run the script and then error

    help

  6. crtl-i Says:

    mikoaj.

    the script does not operate by selecting surfaces. you need to use the actual name of the surfaces and then run the script as a function. refer to the notes on the first part of the script that says:

    spFrSurface(srfName1, srfName2, U, V)
    spFrSurface(”nurbsPlane1″, “nurbsPlane2″, 10, 10)

    hope this helps.

Leave a Reply