maxscript challenge 'Screw"

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 03 March 2013   #1
maxscript challenge 'Screw"

I figured this would be a fun and challenging one to wrap your head around. Creating a screw plugin. Speaking for myself, I dislike modeling screws of any kind. They are a pain to model for the sake of the double helix affect they require for proper threading.

I was thinking this would be a great place to start a thread and see who'd be interested in the challenge of figuring out how to create a screw. I've attached a max file 2012 which has a quick breakdown on the modeling process of how I go about make a screw.

The first step would be creating just the shank part of the screw.


In my mind this would be a custom geo plugin, but I'm always open to whatever.
Controls that would be nice to have would be:
1. Number of helix threads
2. Control the height spacing between each loop/ or overall height
3. Number of loops
4. Radius of the core cylinder
5. Radius of the outer rim of the thread

If anyone needs, I can post the basic setup I use to create a custom cylinder geo plugin.

Download Screw Max File Here
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 03 March 2013   #2
Genome
__________________
Maxscript Made Easy...
http://davewortley.wordpress.com/
 
Old 03 March 2013   #3
Id love to see one using Genome. I was on the beta for that but never got to in-depth with it.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 03 March 2013   #4
pretty awesome
http://www.youtube.com/watch?v=NKIsvBXTmaw
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 03 March 2013   #5
Hi,
my basic setup of my screw script:
-create cone
-three helix's
-have to Attach the splines by hand
-applies crosssection and surface modifier

greets

myCone = cone radius1: 10 radius2: 10 height: 30 heightsegs:1 capsegs:1 sides:18

myHelix1 = helix pos:[0,0,0] radius1: 10 radius2: 10 height: 30 turns: 10 direction:0 
myHelix2 = helix pos:[0,0,2] radius1: 10 radius2: 10 height: 30 turns: 10 direction:0 
myHelix3 = helix pos:[0,0,1] radius1: 12 radius2: 12 height: 30 turns: 10 direction:0 

rollout unnamedRollout "Untitled" width:162 height:300
(
	slider sld_Radius1 "Radius1" pos:[16,2] width:125 height:44 range:[1,15,0]
	slider sld_Radius2 "Radius2" pos:[16,51] width:112 height:44 range:[1,15,0]
	slider sld_Turns "Turns" pos:[21,100] width:112 height:44 range:[1,10,0]	
	
	button btn1 "Attach Splines" pos:[14,157] width:85 height:33
	button btn2 "Screw 'm" pos:[12,200] width:86 height:31
	

	
	on sld_Radius1 changed Val1 do
	(
		mycone.radius1 = Val1
		myhelix1.radius1 = Val1
		myhelix2.radius1 = Val1		
		myhelix3.radius1 = Val1	 + 2
	)
	on sld_Radius2 changed Val2 do
	(
		mycone.radius2 = Val2
		myhelix1.radius2 = Val2
		myhelix2.radius2 = Val2		
		myhelix3.radius2 = Val2 + 2
	)
	
	on sld_Turns changed Val3 do
	(
		myhelix1.turns = Val3
		myhelix2.turns = Val3		
		myhelix3.turns = Val3
	)
	
	on btn1 pressed do
	(
		convertToSplineShape myhelix1
		convertToSplineShape myhelix2
		convertToSplineShape myhelix3
		updateShape myhelix1
		updateShape myhelix2
		updateShape myhelix3
		select myhelix1
		splineOps.startAttach myhelix1
	)
	
	on btn2 pressed do
	(
	addmodifier myhelix1 (Crosssection())
	addmodifier myhelix1 (Surface())
	)

)
createdialog unnamedRollout
 
Old 03 March 2013   #6
my pipeline probably would be:
# extended cone (see a sample on the forum)
# helix modifier (see a sample on the forum)
# sweep modifier (extended)
 
Old 03 March 2013   #7
Think of a cylinder with a twist modifier. Then a control to adjust x number of vertical segements to push the verts out on there normals. That could work as well.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 03 March 2013   #8
I made threading in stainless in a small factory as a holiday job, while in High School.

If I wasn't so busy I'd love to recreate this in 3D.
__________________
http://blog.senorfreebie.com
My own self-interested promotion of technical ramblings and portfolio updates.
 
Old 03 March 2013   #9
So points #4 and #5 are pretty straightforward -- but I"m having a hard time figuring out how to get that helix cleanly integrated into the mesh. Once you have the helix how do you attach/cut the splines to the geo to generate the "selectedEdges" object?
 
Old 03 March 2013   #10
well... genome is really smart. but it's not match the real 'screw' standards. so everyone has a chance to kick genome's b...
 
Old 03 March 2013   #11
that and it doesn't help that genome's objects have to be dense as heck to make that screw work correct.
It's cool......but not practical.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 03 March 2013   #12
heres my contribution, should get you started, not tested on odd number of segments


     fn mxssetedgevisflags m face flags =
     (	
     	setEdgeVis m  face 1 flags[1];
     	setEdgeVis m  face 2 flags[2];
     	setEdgeVis m  face 3 flags[3];
     )
     
     fn create_thread_mesh segs num_turns maj_radius min_radius pitch poffset =
     (
     	rd = 360.0 / segs;	-- angular delta
     	pd = pitch / segs;	-- pitch delta
     	mmd = (maj_radius - min_radius) / segs; -- major to minor delta
     	
     -- compute numverts & faces we need	
     	
     	num_verts = segs * num_turns * 2 + ((segs - 1) * 2) + 1;
     	num_faces = segs * num_turns * 4 + 3 * segs - 4;
     	
     -- empty mesh	
     	
     	msh = mesh numverts:num_verts  numfaces:num_faces
     
     	segs_over_two = segs/2;
     	vert_count = (num_verts - 1)/ 2.0;	-- vert counts
     	final_loop = num_turns * segs;	-- start of final loop
     	r = rd;
     	p = 0.0;
     	rp = maj_radius;
     	verti = 1;	-- vert index
     	
     -- create outer helix verts   
     	
     	for i = 1 to vert_count do
     	(	
 -- outer helix blends to the inner helix over the final loop
     		if i > final_loop then 
     			rp -= mmd;
     		
     		setVert msh verti  (rp * cos r) (rp * sin r) p;
     		verti += 1;
     		
 -- the helix is flat for the first turn and last half turn
 
     		if r >= 360 and i <= vert_count - segs_over_two then
     			p += pd;
     		r += rd;	
     	)
     	top = p;
     
     -- create inner helix verts
     	
     	r = rd;
     	p = 0.0;
     	rp = maj_radius;
     	for i = 1 to vert_count do
     	(	
 
 -- inner helix starts at major rad blending to the minor rad over the first turn
 
     		if i <= segs then
     			rp -= mmd;
     		
     		setVert msh verti  (rp * cos r) (rp * sin r) p;
     		verti += 1;
     		
 -- this is flat for the first and last half turns
 
     		if p < top and i >= segs_over_two then
     			p += pd;
     		r += rd;	
     	)
     	
     -- set the point	
     	
     	setVert msh verti  0 0 (top + poffset);
     	verti += 1;
     	
     -- create the faces	
     	
     	facei = 1 -- face index
     	
     -- first 2 fillet tris	
     	
     	setface msh facei [segs, 1, vert_count + 1];
     	mxssetedgevisflags msh facei #{1,3};
     	setFaceSmoothGroup msh facei 1;
     	facei += 1;
     	
     	setface msh facei [segs, vert_count + 1, segs + 1];
     	setFaceSmoothGroup msh facei 2;
     	facei += 1;
     	
     -- main thread	
     	
     	for i = 1 to vert_count - 1 do
     	(
     		ip1 = i + 1;
     		opi = vert_count + i;
     		opip1 = opi + 1;
     		spi = segs + i;
     
     		setface msh facei [i, ip1, opi];
     		mxssetedgevisflags msh facei #{1,3};
     		setFaceSmoothGroup msh facei 1;
     		facei += 1;
     		setface msh facei [opi, ip1, opip1];
     		mxssetedgevisflags msh facei #{3};
     		setFaceSmoothGroup msh facei 1;
     		facei += 1;
     		
     		if i < vert_count - segs then
     		(	
     			setface msh facei [opi, opip1,spi];
     			mxssetedgevisflags msh facei #{1,3};
     			setFaceSmoothGroup msh facei 2;
     			facei += 1;
     			setface msh facei [spi, opip1, spi + 1];
     			mxssetedgevisflags msh facei #{3};
     			setFaceSmoothGroup msh facei 2;
     			facei += 1;
     		)	
     	)	
     
     -- last fillet 2 tris
     
     	setface msh facei [num_verts - segs - 1, num_verts - segs, vert_count];
     	mxssetedgevisflags msh facei #{2,3};
     	setFaceSmoothGroup msh facei 2;
     	facei += 1;	
     	setface msh facei [vert_count, num_verts - segs, num_verts - 1];
     	mxssetedgevisflags msh facei #{2,3};
     	setFaceSmoothGroup msh facei 1;
     	facei += 1;	
     
     -- point cap	
     	
     	svert = num_verts - segs;
  	for i = 0 to segs - 1 do
  	(
  		b = svert + i;
  		c = b + 1
  		if i == segs - 1 then
  		(
  			b = num_verts - 1;
  			c = svert;
  		)		
  		setface msh facei [num_verts, b , c];	
  		setFaceSmoothGroup msh facei 1;
  		mxssetedgevisflags msh facei #{1};
  		facei += 1;	
  	)	  
     	
     	update msh;
     	msh;
     	
     )	
     
     create_thread_mesh 16 7 0.5 0.375 0.25 0.25


edit: small bug fixed, too many faces created on the top cap also added some more comments

Last edited by Klunk : 03 March 2013 at 08:19 AM.
 
Old 03 March 2013   #13
Klunk!
Super impressive stuff.
I'll have to check this out and mess around with it.
Nice work.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 03 March 2013   #14
Finally got around to playing with the script more. Very cool. Now just adding an option to add spacing between each loop.

A simple way to do this right now is to just select the loop and chamfer it but its rather hackish to do that.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 03 March 2013   #15
Better explain
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 01:19 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.