# # Yet another simple 3D mechanical object. This one whas taken from # PC MAGAZINE volume 8 number 2, January 31, 1989, page 34. This was example # that was implemented under AutoCAD ver 10, and it looked nice so I tried # it... It took me about an hour to complete. # # Created by Gershon Elber, Mar 89 # save_mat = view_mat; save_res = resolution; resolution = 16; view_mat = view_mat * trans( vector( 0.4, -0.1, 0.0 ) ); ExtractIDParts = function( Obj, ID, rgb ): i: p: return = nil(): for (i = 0, 1, sizeof( Obj ) - 1, p = coord( Obj, i ): if ( getattr( p, "ID" ) == ID, snoc( p, return ) ) ): return = mergepoly( return ): attrib( return, "rgb", rgb ); # # Create the big cylinder ( no hole yet ) # C1 = cylin( vector( 0.0, 0.0, 0.0 ), vector( 0.0, 0.0, 0.7 ), 0.2, 3 ); attrib( C1, "ID", 1 ); # # And the small one ( including the torus & sphere cut # C2 = cylin( vector( 1.0, 0.0, 0.05 ), vector( 0.0, 0.0, 0.4 ), 0.15, 3 ); attrib( C2, "ID", 2 ); resolution = 8; T1 = circpoly( vector( 0.0, 1.0, 0.0 ), vector( 0.151, 0.0, 0.25 ), 0.03 ); resolution = 16; T2 = surfrev( T1 ) * trans( vector( 1.0, 0.0, 0.0 ) ); free( T1 ); attrib( T2, "ID", 3 ); B1 = C2 - T2; free( C2 ); free( T2 ); resolution = 12; S1 = sphere( vector( 1.0, 0.0, 0.0 ), 0.135 ); attrib( S1, "ID", 4 ); B2 = B1 - S1; free( B1 ); free( S1 ); view( list( view_mat, B2 ), true ); v1 = vector( 0.0, 0.19, 0.35 ); v2 = vector( 0.0,-0.19, 0.35 ); v3 = vector( 1.0,-0.14, 0.35 ); v4 = vector( 1.0, 0.14, 0.35 ); CrossSec = poly( list( v1, v2, v3, v4 ), false ); Ext1 = extrude( CrossSec, vector( 0.0, 0.0, 0.07 ), 3 ); attrib( Ext1, "ID", 5 ); free( CrossSec ); free( v1 ); free( v2 ); free( v3 ); free( v4 ); B3 = C1 + Ext1 + B2; free( C1 ); free( Ext1 ); free( B2 ); view( B3, true ); # # Time to do the final hole in the big cylinder. Note we couldnt do it before # as E1 would have penetrate it... # resolution = 16; C3 = cylin( vector( 0.0, 0.0,-0.1 ), vector( 0.0, 0.0, 0.9 ), 0.165, 3 ); attrib( C3, "ID", 6 ); B4 = B3 - C3; free( B3 ); free( C3 ); final = convex( B4 ); free( B4 ); finalSplit = list( ExtractIDParts( final, 1, "255, 0, 0" ), ExtractIDParts( final, 2, "0, 255, 0" ), ExtractIDParts( final, 3, "0, 255, 255" ), ExtractIDParts( final, 4, "255, 0, 255" ), ExtractIDParts( final, 5, "255, 255, 0" ), ExtractIDParts( final, 6, "255, 255, 255" ) ); interact( finalSplit ); save( "solid7", finalSplit ); free( finalSplit ); smooth_final = SmoothNrml( final, 190 ); free( final ); interact( smooth_final ); save( "solid7s", smooth_final ); free( smooth_final ); resolution = save_res; view_mat = save_mat;