'<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
'<>                                                                <>
'<>   Seashell v0.34        May 7 2000               <-EDIT ;-)    <>
'<>                                                                <>
'<>   VBscript by Eric Poirier      eric_poirier3d@hotmail.com     <>
'<>                                                                <>
'<>   GUI by Frank (2) Hellmann (hellmann@vcc.de), 12 June 2000    <>
'<>								   <>
'<>								   <>
'<>    Visit the XSI Station at http://pages.infinit.net/ericxsi/  <>
'<>                                                                <>
'<>   For now this is a seashell generator using only one curve,   <>
'<>   as soon as i can figure out how to assemble vertexes to      <>
'<>   created a object this script will be much better !!          <>
'<>                                                                <>
'<>                                                                <>
'<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

createSeashell

sub createSeashell
	Dim r, d, x, y, z, i, j, theta, phi, rotation_angle, Uncoiling_factor
	Dim trochospiral_factor, quality, percentage, details, PI, myName

	PI=3.141592654
	
	'//In case somethings goes wrong, just continue
	On Error Resume Next

	'//In case the user Change the name of the Scene Root
	'//Find the Scene_Root object 
	set mySceneRoot = EnumElements("Project", TRUE)
	set mySceneRoot = SIFilter(mySceneRoot, "Scene", TRUE )(0)
	set mySceneRoot = EnumElements( mySceneRoot , TRUE)
	set mySceneRoot = SIFilter(mySceneRoot, "SceneObject", TRUE)(0)

	'//in case someone as already created put a custom parameter named "Seashell"
	set seashell_name = AddProp ("Custom_parameter_list",mySceneRoot, , "Seashell").Value("Value")

	'//Adding the Parameters in the Custom parameter
	SIAddCustomParameter seashell_name, "ObjectName", siString, 0, 0, 0, 0, 0, 0.000, 0.000
	SIAddCustomParameter seashell_name, "RotationAngle", siDouble, 20, 1, 1000, , 0, 0, 100
	SIAddCustomParameter seashell_name, "UncoilingFactor", siDouble, 0.090, 0.000, 10.000, , 0, 0.000, 0.000
	SIAddCustomParameter seashell_name, "TrochospiralFactor", siDouble, 0.200, 0.000, 10.000, , 0, 0.000, 0.000
	SIAddCustomParameter seashell_name, "Quality", siDouble, 8.000, 0.000, 100.000, , 0, 0.000, 0.000
	SIAddCustomParameter seashell_name, "Percentage", siDouble, 25.000, 0.000, 100.000, , 0, 0.000, 0.000
	SIAddCustomParameter seashell_name, "Details", siDouble, 0.330, 0.000, 10.000, , 0, 0.000, 0.000

	'//Opening the CustomParameter for the user to Interact with it
	InspectObj mySceneRoot & "." & seashell_name,,"Create Seashell",4

	myName 		= GetValue(seashell_name &".ObjectName")
	rotation_angle	= GetValue(seashell_name &".RotationAngle")
	uncoiling_factor	= GetValue(seashell_name &".UncoilingFactor")
	trochospiral_factor	= GetValue(seashell_name &".TrochospiralFactor")
	quality		= GetValue(seashell_name &".Quality")
	percentage	= GetValue(seashell_name &".Percentage")
	details		= GetValue(seashell_name &".Details")

	i=0
	j=0
	x=0
	y=0
	z=0
	theta=0
	phi=0
	r=0
	d=0

	if Err.Number = 0 then
	
	   if myName = "" then
			
		LogMessage "No Name given.", siWarning
	
	   else 		
	
		'// Create Non-Interpolated NURBS Curve
	
		SICreateCurve myName, 3, 0

		'// Generate Curve Points
		i=0
		do while i<(percentage*10)
    		    i=i+1
		    theta=i/rotation_angle           
		    r=exp(theta*uncoiling_factor)    
		    d=details*r 
		    j=0 
	                         
		    do while j<quality
      
		      j=j+1
		      phi=2*PI*j/(quality-1)
		      x=d*cos(phi)*cos(theta)
		      z=d*sin(phi)
		      y=d*cos(phi)*sin(theta)
		      x=r*cos(theta)+x
		      y=r*sin(theta)+y
		      z=r*trochospiral_factor+z         
      
		      SIAddPointOnCurveAtEnd myName, x, y, z, False
            
 	            loop
	         loop
  
		SelectObj myName, , True
		
	   end if	

	end if

	'//At the end we do a simple cleanup of the Custom Parameter
	DeleteObj mySceneRoot & "." & seashell_name

end sub