PDA

View Full Version : Need some help



nodger
04-20-2003, 01:10 PM
Does anyone here know how to write a script that will create a tessalated half-sphere, and then create miniature spheres at all the points of the large sphere, and finally create tubes connecting each of the mini-spheres. (it's for an architectural idea. I know its probably easy but I've never done any scripting before.

Any help would be greatly apprieciated.

Karsten Lueth
04-23-2003, 12:31 AM
Creating the tesselated sphere is simple. Just use the sphere command, no need for scripting. Creating the mini-spheres is also very simple. Use Point-Clone+ command. The tubes are really complicated, because they have to be rotated so that they match the shape of the sphere. It can be done, but -sorry!- I do not have a solution for that.

Karsten Lueth
04-24-2003, 02:39 PM
Hi nodger,

After a while, I found the problem so interessting, that I worked a out a solution. Here it comes:

Create a tesselated sphere. Be sure that it is really tesselated (only triangles) not a globe type. I used a radius of 50m. Delete the lower half polygons so that you have
a nice dome.

In a second layer create another sphere for the joints. I used a radius of 2m for that. Use the layer with the dome as background and use the Point-Clone+ command. Just press OK.

For the tube you need a script. My script is named "DomeTool":

@script modeler
@name "DomeTool"
@version 2.3

domePoints;


z_points_to: p, dir
{
rx = cross3d(<0,1,0>, dir);
ry = cross3d(dir, rx);
rz = dir;
rx = normalize(rx);
ry = normalize(ry);
rz = normalize(rz);
x = p.x*rx.x + p.y*ry.x + p.z*rz.x;
y = p.x*rx.y + p.y*ry.y + p.z*rz.y;
z = p.x*rx.z + p.y*ry.z + p.z*rz.z;
return <x,y,z>;
}


maketube: v1, v2, r, nsides
{
d = v2-v1;
h = vmag(d);

da = 2.0*PI/nsides;
a = 0.0;
editbegin();
// create the points.
for (i=1; i<=nsides; i++) {
p = <r*cos(a), r*-sin(a), 0>;
pr = z_points_to(p, d);
pr += v1;
id[2*i] = addpoint(pr);
p.z = h;
pr = z_points_to(p, d);
pr+= v1;
id[2*i+1] = addpoint(pr);
a += da;
}

// create the faces
for (i=1; i<=nsides; i++) {
v[1] = id[2*i];
v[2] = id[2*i+1];
if (i==nsides) {
v[3] = id[2 + 1];
v[4] = id[2];
} else {
v[3] = id[2*((i+1)) + 1];
v[4] = id[2*((i+1))];
}
addquad(v);

}
editend();
}


main
{
reqbegin("Dome Tool");

c0 = ctlinteger("Sides",12);
c1 = ctldistance("Radius",1.0);

return if !reqpost();

nsides = getvalue(c0);
radius = getvalue(c1);

reqend();

selmode(USER);
polys = polycount();
npolys = polys[1];
editbegin();
for (i=1; i<=npolys; i++) {
id = polygons[i];
info = polyinfo(id);
p1 = info[2];
p2 = info[3];
p3 = info[4];

domePoints[i*3] = pointinfo(p1);
domePoints[i*3+1] = pointinfo(p2);
domePoints[i*3+2] = pointinfo(p3);

}
editend();
lyrs = lyrempty();
bg = lyrs[1];
lyrsetbg(bg);
lyrswap();

for (i=1; i<=npolys; i++) {
p1 = domePoints[i*3];
p2 = domePoints[i*3+1];
p3 = domePoints[i*3+2];
monstep();
avg_y = (p1.y + p2.y + p3.y) / 3;
min_y = min(min(p1.y, p2.y), p3.y);
max_y = max(max(p1.y, p2.y), p3.y);
if (avg_y > ((min_y+max_y) / 2)) continue;
maketube(p1, p2, radius, nsides);
maketube(p2, p3, radius, nsides);
maketube(p3, p1, radius, nsides);

}
monend();
lyrswap();
}


When you use the script, the dome should be in the foreground layer and polygon selection mode should be used. The tubes are created in an unsed layer in the background.

Have fun,

Karsten

nodger
04-30-2003, 03:41 AM
thanks a lot , man