View Full Version : half circle


dejawolf
02 February 2005, 01:46 PM
well, i'm trying to make a primitive plugin. i tried modifying the antistar sun shape primitive into a full poly circle,
but only managed to get backfaces.

Bobo
02 February 2005, 04:58 PM
well, i'm trying to make a primitive plugin. i tried modifying the antistar sun shape primitive into a full poly circle,
but only managed to get backfaces.

Can you explain what you mean with "only backfaces"? Any face has a front and back. If you have got backfaces, you must have front faces on the other side! It just depends on the vertex order - counterclockwise gives you front, clockwise gives you the inverse...

Can you post any code?

dejawolf
02 February 2005, 11:38 PM
radius1 = 100

radius2 = 10

width = 10

vert_array = #()

face_array = #()

vert_count = 0

num_faces = 10

for a = 0 to 360 by 360/num_faces do

(

v1 = [radius1*cos(a+width),radius1*sin(a+width),0]

v2 = [radius1*cos(a-width),radius1*sin(a-width),0]

v3 = [radius2*cos(a),radius2*sin(a),0]

append vert_array v1

append vert_array v2

append vert_array v3

append face_array [vert_count+1,vert_count+3,vert_count+2]

vert_count += 3

) m = mesh vertices:vert_array faces:face_array

well, this is the code i try to modify.

http://img.photobucket.com/albums/v253/dejawolf/primitive.jpg

1. is what i try to create, 2. is what this script creates
3. is how i think i'll make it.
and 4 is how i want the final primitive.

i think making an edge from each of the middle vertices (radius2)
and then extruding that edge to the left and right by radius 1 will get me the result
i want. but i just have no idea how to make radius 2 into a single vertex located in the middle, or how to make faces inbetween those faces in the antistar.
i tried creating another face array, but it only created backfaces.

Bobo
02 February 2005, 12:57 AM
well, this is the code i try to modify.


I know, I wrote it :)

Here is what you need, with comments:


radius1 = radius2 = 100 --both radii of the hemi-circles
theHeight = 100 --the distance between the halves

num_faces = 20 --number of segments per hemi-circle

vert_array = #() --vertex array
face_array = #() --face array

center1 = [0,theHeight/2,0] --center of the first hemi-circle
center2 = [0,-theHeight/2,0] --center of the second hemi-circle

append vert_array center1 --add the center to the vertex array
vert_count = 1 --init. the vertex counter to 1

theStep = 180.0/num_faces --the angle to increment to get N segments

for a = 0 to 180-theStep by theStep do --loop through the segments of the first hemi-circle
(
append vert_array (center1 + [radius1*cos(a),radius1*sin(a),0]) --add first vertex on circle
append vert_array (center1 + [radius1*cos(a+theStep),radius1*sin(a+theStep),0]) --add second circle + the angular offset
append face_array [1 ,vert_count+1,vert_count+2] --define a face from center1 (vertex 1) and the two new vertices on the circle
vert_count += 2 --add two because two new vertices were added
)--end a loop

append vert_array center2 --add the second center as vertex
center2Index = vert_count += 1 --and remember its index

for a = 180 to 360-theStep by theStep do --same as above, but other half from 180 to 360-the step
(
append vert_array (center2 + [radius2*cos(a),radius2*sin(a),0]) --same as before, just using center2 and radius2
append vert_array (center2 + [radius2*cos(a+theStep),radius2*sin(a+theStep),0]) --same as before
append face_array [center2Index ,vert_count+1,vert_count+2] --connect the vertex at center2 with the two new verts
vert_count += 2 --increase by 2 as before
)--end a loop

append face_array [center2Index ,vert_count, 2] --create a face from the center2 to the last vertex to the first vertex of first half-circle (index 2)
append face_array [1, center2Index , 2] --create a face using first center, the second center and the first vertex of hemi circle 1
append face_array [center2Index - 1, center2Index + 1, 1 ] --same with the last vertex of circle 1, the first vertex of circle2 and center 1
append face_array [center2Index + 1, center2Index, 1 ] --and finally face from first vertex of circle2, center 2 and center 1

m = mesh vertices:vert_array faces:face_array --create the mesh...



Now just make it a scripted plugin and you are done :)

Bobo
02 February 2005, 01:09 AM
This update shows how to hide all the internal edges...

radius1 = radius2 = 100 --both radii of the hemi-circles
theHeight = 100 --the distance between the halves

num_faces = 20 --number of segments per hemi-circle

vert_array = #() --vertex array
face_array = #() --face array
edge_vis = #() --edge visibility

center1 = [0,theHeight/2,0] --center of the first hemi-circle
center2 = [0,-theHeight/2,0] --center of the second hemi-circle

append vert_array center1 --add the center to the vertex array
vert_count = 1 --init. the vertex counter to 1

theStep = 180.0/num_faces --the angle to increment to get N segments

for a = 0 to 180-theStep by theStep do --loop through the segments of the first hemi-circle
(
append vert_array (center1 + [radius1*cos(a),radius1*sin(a),0]) --add first vertex on circle
append vert_array (center1 + [radius1*cos(a+theStep),radius1*sin(a+theStep),0]) --add second circle + the angular offset
append face_array [1 ,vert_count+1,vert_count+2] --define a face from center1 (vertex 1) and the two new vertices on the circle
append edge_vis #(false,true,false) --make first and third edge invisible
vert_count += 2 --add two because two new vertices were added
)--end a loop

append vert_array center2 --add the second center as vertex
center2Index = vert_count += 1 --and remember its index

for a = 180 to 360-theStep by theStep do --same as above, but other half from 180 to 360-the step
(
append vert_array (center2 + [radius2*cos(a),radius2*sin(a),0]) --same as before, just using center2 and radius2
append vert_array (center2 + [radius2*cos(a+theStep),radius2*sin(a+theStep),0]) --same as before
append face_array [center2Index ,vert_count+1,vert_count+2] --connect the vertex at center2 with the two new verts
append edge_vis #(false,true,false) --make first and third edge invisible
vert_count += 2 --increase by 2 as before
)--end a loop

append face_array [center2Index ,vert_count, 2] --create a face from the center2 to the last vertex to the first vertex of first half-circle (index 2)
append face_array [1, center2Index , 2] --create a face using first center, the second center and the first vertex of hemi circle 1
append face_array [center2Index - 1, center2Index + 1, 1 ] --same with the last vertex of circle 1, the first vertex of circle2 and center 1
append face_array [center2Index + 1, center2Index, 1 ] --and finally face from first vertex of circle2, center 2 and center 1

append edge_vis #(false,true,false) --make first and third edges invisible
append edge_vis #(false,false,false) --make all edges invisible
append edge_vis #(true,false,false) --make second and third edges invisible
append edge_vis #(false,false,false) --make all edges invisible

m = mesh vertices:vert_array faces:face_array --create the mesh...

for i = 1 to edge_vis.count do --go through all edge visibility arrays
for j = 1 to 3 do --loop from 1 to 3
setEdgeVis m i j edge_vis[i][j] --set the 3 edges of the current face (index same as i)
update m --update the mesh

Bobo
02 February 2005, 01:20 AM
And because I cannot stop, here is the plugin.
If you want to do it yourself, stop reading :)

This will be most probably a new HowTo tutorial in the next MAXScript Reference update, if you don't mind...


plugin simpleObject ExtCircle
name:"ExtCircle"
category:"HowTo"
classID:#(0xe855567d, 0xbcd73b8c)
(

parameters main rollout:params
(
num_faces type:#integer ui:num_faces default:10
radius1 type:#float ui:radius1 default:0
radius2 type:#float ui:radius2 default:0
width type:#float ui:width default:1
)

rollout params "ExtCircle"
(
spinner num_faces "Segments" range:[2,100,10] type:#integer
spinner radius1 "Radius 1" range:[0,10000,0]
spinner radius2 "Radius 2" range:[0,10000,0]
spinner width "Width" range:[0,90,1]
)


on buildMesh do
(


vert_array = #() --vertex array
face_array = #() --face array
edge_vis = #() --edge visibility

center1 = [0,width/2,0]
center2 = [0,-width/2,0]

append vert_array center1
vert_count = 1
theStep = 180.0/num_faces
for a = 0 to 180-theStep by theStep do
(
append vert_array (center1 + [radius1*cos(a),radius1*sin(a),0])
append vert_array (center1 + [radius1*cos(a+theStep),radius1*sin(a+theStep),0])
append face_array [1 ,vert_count+1,vert_count+2]
append edge_vis #(false,true,false)
vert_count += 2
)--end a loop

append vert_array center2
center2Index = vert_count += 1

for a = 180 to 360-theStep by theStep do
(
append vert_array (center2 + [radius2*cos(a),radius2*sin(a),0])
append vert_array (center2 + [radius2*cos(a+theStep),radius2*sin(a+theStep),0])
append face_array [center2Index ,vert_count+1,vert_count+2]
append edge_vis #(false,true,false)
vert_count += 2
)--end a loop

append face_array [center2Index ,vert_count, 2]
append face_array [1, center2Index , 2]
append face_array [center2Index - 1, center2Index + 1, 1 ]
append face_array [center2Index + 1, center2Index, 1 ]
append edge_vis #(false,true,false)
append edge_vis #(false,false,false)
append edge_vis #(true,false,false)
append edge_vis #(false,false,false)

setMesh mesh vertices:vert_array faces:face_array

for i = 1 to edge_vis.count do
for j = 1 to 3 do --loop from 1 to 3
setEdgeVis mesh i j edge_vis[i][j]

)--end buildMesh

tool create
(
on mousePoint click do
(
case click of
(
1: coordsys grid (nodeTM.translation = gridPoint)
)
)

on mouseMove click do
(
case click of
(
2: (radius1 = radius2 = abs(gridDist.y))
3: (width = abs(gridDist.y))
4: (#stop)
)
)

)--end create
)--end plugin




http://www.scriptspot.com/bobo/stuff/forum/extcircle.jpg

dejawolf
02 February 2005, 01:32 AM
wow, that is fantastic! thanks a lot! :D
no i don't mind you making this into a tutorial :)
i've been searching for a tutorial on how to create my own primitives for quite a while!

dejawolf
02 February 2005, 02:36 AM
well, did some minor modifications,
i increased the middle width to 400,
and put it into standard primitives.
now my fingers burns after putting this into some heavy usage :)

later i'll see if i can make one of the half circles disappear,
and make it 3 dimensional.
maybe make the edges chamferable.
and an option to create a standard circle.
or box. hehe.

dejawolf
02 February 2005, 03:19 AM
well, just had to play around a bit with the code :)

here's the result.
i added a little shape modifier code.
now trying to figure how to do it on the other side :)

http://img.photobucket.com/albums/v253/dejawolf/disturbed.jpg

dejawolf
02 February 2005, 03:48 AM
well, now i tried modifying the plugin code. but it refuse to work.

plugin simpleObject ExtCircle

name:"ExtCircle"

category:"Standard Primitives"

classID:#(0xe855567d, 0xbcd73b8c)

(



parameters main rollout:params

(

num_faces type:#integer ui:num_faces default:10

radius1 type:#float ui:radius1 default:0

radius2 type:#float ui:radius2 default:0

width type:#float ui:width default:1

disturber type:#float ui:disturber default:1

)



rollout params "ExtCircle"

(

spinner num_faces "Segments" range:[2,100,10] type:#integer

spinner radius1 "Radius 1" range:[0,10000,0]

spinner radius2 "Radius 2" range:[0,10000,0]

spinner width "Width" range:[0,400,1]

spinner disturber "disturb" range:[0,80,0]

)





on buildMesh do

(





vert_array = #() --vertex array

face_array = #() --face array

edge_vis = #() --edge visibility



center1 = [0,width/2,0]

center2 = [0,-width/2,0]



append vert_array center1

vert_count = 1

theStep = 180.0/num_faces

disturber = 1



for a = 7-disturber to 180-theStep+disturber by theStep do

(

append vert_array (center1 + [radius1*cos(a),radius1*sin(a),0])

append vert_array (center1 + [radius1*cos(a+theStep),radius1*sin(a+theStep),0])

append face_array [1 ,vert_count+1,vert_count+2]

append edge_vis #(false,true,false)

vert_count += 2

)--end a loop



append vert_array center2

center2Index = vert_count += 1



for a = 180.4-disturber to 360-theStep+disturber by theStep do

(

append vert_array (center2 + [radius2*cos(a),radius2*sin(a),0])

append vert_array (center2 + [radius2*cos(a+theStep),radius2*sin(a+theStep),0])

append face_array [center2Index ,vert_count+1,vert_count+2]

append edge_vis #(false,true,false)

vert_count += 2

)--end a loop



append face_array [center2Index ,vert_count, 2]

append face_array [1, center2Index , 2]

append face_array [center2Index - 1, center2Index + 1, 1 ]

append face_array [center2Index + 1, center2Index, 1 ]

append edge_vis #(false,true,false)

append edge_vis #(false,false,false)

append edge_vis #(true,false,false)

append edge_vis #(false,false,false)



setMesh mesh vertices:vert_array faces:face_array



for i = 1 to edge_vis.count do

for j = 1 to 3 do--loop from 1 to 3

setEdgeVis mesh i j edge_vis[i][j]



)--end buildMesh



tool create

(

on mousePoint click do

(

case click of

(

1: coordsys grid (nodeTM.translation = gridPoint)

)

)



on mouseMove click do

(

case click of

(

2: (radius1 = radius2 = abs(gridDist.y))

3: (width = abs(gridDist.y))

4: (disturber = abs(gridDist.y))

5: (#stop)

)

)



)--end create

)--end plugin

dejawolf
02 February 2005, 04:44 AM
hah, ok, i found why it went wrong :P

i should have replaced the number with the parameter.

dejawolf
02 February 2005, 05:12 AM
here's the final "bonecircle" script. :D

plugin simpleObject ExtCircle
name:"ExtCircle"

category:"Standard Primitives"

classID:#(0xe855567d, 0xbcd73b8c)

(



parameters main rollout:params

(

num_faces type:#integer ui:num_faces default:10

radius1 type:#float ui:radius1 default:0

radius2 type:#float ui:radius2 default:0

width type:#float ui:width default:1

disturb type:#float ui:disturb default:0



)



rollout params "ExtCircle"

(

spinner num_faces "Segments" range:[2,100,10] type:#integer

spinner radius1 "Radius 1" range:[0,10000,0]

spinner radius2 "Radius 2" range:[0,10000,0]

spinner width "Width" range:[0,400,1]

spinner disturb "disturber" range:[0,70,1]

)



on buildMesh do

(





vert_array = #() --vertex array

face_array = #() --face array

edge_vis = #() --edge visibility



center1 = [0,width/2,0]

center2 = [0,-width/2,0]



append vert_array center1

vert_count = 1

theStep = 180.0/num_faces

disturber = disturb



for a = 0-disturber to 180-theStep+disturber by theStep do

(

append vert_array (center1 + [radius1*cos(a),radius1*sin(a),0])

append vert_array (center1 + [radius1*cos(a+theStep),radius1*sin(a+theStep),0])

append face_array [1 ,vert_count+1,vert_count+2]

append edge_vis #(false,true,false)

vert_count += 2

)--end a loop



append vert_array center2

center2Index = vert_count += 1



for a = 180-disturber to 360-theStep+disturber by theStep do

(

append vert_array (center2 + [radius2*cos(a),radius2*sin(a),0])

append vert_array (center2 + [radius2*cos(a+theStep),radius2*sin(a+theStep),0])

append face_array [center2Index ,vert_count+1,vert_count+2]

append edge_vis #(false,true,false)

vert_count += 2

)--end a loop



append face_array [center2Index ,vert_count, 2]

append face_array [1, center2Index , 2]

append face_array [center2Index - 1, center2Index + 1, 1 ]

append face_array [center2Index + 1, center2Index, 1 ]

append edge_vis #(false,true,false)

append edge_vis #(false,false,false)

append edge_vis #(true,false,false)

append edge_vis #(false,false,false)



setMesh mesh vertices:vert_array faces:face_array



for i = 1 to edge_vis.count do

for j = 1 to 3 do--loop from 1 to 3

setEdgeVis mesh i j edge_vis[i][j]



)--end buildMesh



tool create

(

on mousePoint click do

(

case click of

(

1: coordsys grid (nodeTM.translation = gridPoint)

)

)



on mouseMove click do

(

case click of

(

2: (radius1 = radius2 = abs(gridDist.y))

3: (width = abs(gridDist.y))

4: (disturb = abs(gridDist.y))

5: (#stop)

)

)



)--end create

)--end plugin

dejawolf
02 February 2005, 05:50 AM
managed to remove second half :)

radius1 = radius2 = 100 --both radii of the hemi-circles

theHeight = 100 --the distance between the halves



num_faces = 10 --number of segments per hemi-circle



vert_array = #() --vertex array

face_array = #() --face array



center1 = [0,theHeight/2,0] --center of the first hemi-circle

center2 = [0,-theHeight/2,0] --center of the second hemi-circle



append vert_array center1 --add the center to the vertex array

vert_count = 1 --init. the vertex counter to 1



theStep = 180.0/num_faces --the angle to increment to get N segments

deathdriver = 180



for a = 0 to 180-theStep by theStep do --loop through the segments of the first hemi-circle

(

append vert_array (center1 + [radius1*cos(a),radius1*sin(a),0]) --add first vertex on circle

append vert_array (center1 + [radius1*cos(a+theStep),radius1*sin(a+theStep),0]) --add second circle + the angular offset

append face_array [1 ,vert_count+1,vert_count+2] --define a face from center1 (vertex 1) and the two new vertices on the circle

vert_count += 2 --add two because two new vertices were added

)--end a loop



append vert_array center2 --add the second center as vertex

center2Index = vert_count += 1 --and remember its index



for a = 180 to 360 by deathdriver do --same as above, but other half from 180 to 360-the step

(

append vert_array (center2 + [radius2*cos(a),radius2*sin(a),0]) --same as before, just using center2 and radius2

append vert_array (center2 + [radius2*cos(a),radius2*sin(a),0]) --same as before

append face_array [center2Index ,vert_count+1,vert_count+2] --connect the vertex at center2 with the two new verts

vert_count += 2 --increase by 2 as before

)--end a loop



append face_array [center2Index ,vert_count, 2] --create a face from the center2 to the last vertex to the first vertex of first half-circle (index 2)

append face_array [1, center2Index , 2] --create a face using first center, the second center and the first vertex of hemi circle 1

append face_array [center2Index - 1, center2Index + 1, 1 ] --same with the last vertex of circle 1, the first vertex of circle2 and center 1

append face_array [center2Index + 1, center2Index, 1 ] --and finally face from first vertex of circle2, center 2 and center 1



m = mesh vertices:vert_array faces:face_array --create the mesh...

dejawolf
02 February 2005, 06:13 AM
btw, do you have anything against me posting these on scriptspot?

i bow in thy honour for helping me, o great bobo, god of maxscript.

Bobo
02 February 2005, 04:35 PM
btw, do you have anything against me posting these on scriptspot?

i bow in thy honour for helping me, o great bobo, god of maxscript.

Not at all. Scriptspot is where it belongs to... :)
I am still going to add a couple of tutorials to the MAXScript Reference based on my version of the code because the AntiStar was obviously not enough to get you started.

CGTalk Moderation
02 February 2006, 05:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.


1