# SpatialED.TarquinSpiralStairBuilder

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 00345 00346 00347 00348 00349 00350 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396 00397 00398 00399 00400 00401 00402 00403 00404 00405 00406 00407 00408 00409 00410 00411 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426 00427 00428 00429 00430 00431 00432 00433 00434 00435 00436 00437 00438 00439 00440 00441 00442 00443 00444 00445 00446 00447 00448 00449 00450 00451 00452 00453 00454 00455 00456 00457 00458 00459 00460 00461 00462 00463 00464 00465 00466 00467 00468 00469 00470 00471 00472 00473 00474 00475 00476 00477 00478 00479 00480 00481 00482 00483 00484 00485 00486 00487 00488 00489 00490 00491 00492 00493 00494 00495 00496 00497 00498 00499 00500 00501 00502 00503 00504 00505 00506 00507 00508 00509 00510 00511 00512 00513 00514 00515 00516 00517 00518 00519 00520 00521 00522 00523 00524 00525 00526 00527 00528 00529 00530 00531 00532 00533 00534 00535 00536 00537 00538 00539 00540 00541 00542 00543 00544 00545 00546 00547 00548 00549 00550 00551 00552 00553 00554 00555 00556 00557 00558 00559 00560 00561 00562 00563 00564 00565 00566 00567 00568 00569 00570 00571 00572 00573 00574 00575 00576 00577 00578 00579 00580 00581 00582 00583 00584 00585 00586 00587 00588 00589 00590 00591 00592 00593 00594 00595 00596 00597 00598 00599 00600 00601 00602 00603 00604 00605 00606 00607 00608 00609 00610 00611 00612 00613 00614 00615 00616 00617 00618 00619 00620 00621 00622 00623 00624 00625 00626 00627 00628 00629 00630 00631 00632 00633 00634 00635 00636 00637 00638 00639 00640 00641 00642 00643 00644 00645 00646 00647 00648 00649 00650 00651 00652 00653 00654 00655 00656 00657 00658 00659 00660 00661 00662 00663 00664 00665 00666 00667 00668 00669 00670 00671 00672 00673 00674 00675 00676 00677 00678 00679 00680 00681 00682 00683 00684 00685 00686 00687 00688 00689 00690 00691 00692 00693 00694 00695 00696 00697 00698 00699 00700 00701 00702 00703 00704 00705 00706 00707 00708 00709 00710 00711 00712 00713 00714 00715 00716 00717 00718 00719 00720 00721 00722 00723 00724 00725 00726 00727 00728 00729 00730 00731 00732 00733 00734 00735 00736 00737 00738 00739 00740 00741 00742 00743 00744 |
    //=============================================================================
    // Spatial Fear
    // Class: TarquinSpiralStairBuilder
    // Description: Builds a spiral staircase.  This builder replaces both the
    //				default SpiralStair builder and the default CurvedStair builder.
    //
    // Author: Tarquin
    // + Used with permission for packaging with SpatialED v2.1
    //=============================================================================
    class TarquinSpiralStairBuilder
    	expands BrushBuilder;

    var() float StepHeight, StepThickness, StepWidth, InnerRadius;
    var() int StepsPerCircle, NumSteps;
    var() name GroupName;
    var() bool AntiClockwise;
    // change state of top and base to enum:

    enum EGoingStyle
    {
    	STYLE_Steps,
    	STYLE_Slope,
    	STYLE_Flat,
    };
    var() EGoingStyle TopStyle, BaseStyle;

    function bool Build()
    {
    // ######################################################### internal variables
    local int	sgn, i, j, iOffset, iTerminal,
    		TrackJumpLower, TrackJumpUpper,
    		TrackOffsetB, TrackOffsetC, TrackOffsetD;
    local bool 		Edge, Disjoint;
    local vector 	InnerVector, FlingVector,
    			StepHeightVector, heightOffset,
    			StepThicknessVector, thicknessOffset;
    local rotator 	SpinTransformation;

    // ######################################################### check input & set booleans
    	if( TopStyle == STYLE_Flat && BaseStyle == STYLE_Flat )
    		return BadParameters("Base and Top may not BOTH be flat. Build a cylinder!");
    	if( StepThickness < StepHeight )
    	{
    		// disjoint.
    		// we MAY have disjoint step, either flat (but flag not set), but NO SLOPES. FlatFlat already excluded.
    		if( TopStyle == STYLE_Slope || BaseStyle == STYLE_Slope )
    			return BadParameters("For stairs with a slope, StepThickness may not be less than StepHeight");
    		if( TopStyle == STYLE_Steps && BaseStyle == STYLE_Steps )
    			Disjoint = True;
    	}
    	if( StepThickness == StepHeight )
    	{
    		// both steps: standard edge
    		// both slopes: forbidden
    		// if there's a flat, don't flag.
    		// either slope or no slope: set flag. BEWARE the order of these last two statements! flat overrides.
    		// NO! CHANGE THE RULES
    		// flat+ slope  FLAGS
    		if( TopStyle == STYLE_Slope && BaseStyle == STYLE_Slope )
    			return BadParameters("For stairs with twin slopes, StepThickness must be strictly greater than StepHeight");
    		if( TopStyle == STYLE_Steps && BaseStyle == STYLE_Steps )
    			Edge = True; // both steps.
    		else if( TopStyle == STYLE_Slope || BaseStyle == STYLE_Slope )
    			Edge = True ; // either slope. So step+flat remains unflagged.
    	}
    	if( InnerRadius <= 0 )
    		return BadParameters("InnerRadius must be positive.");
    	if( StepWidth <= 0 )
    		return BadParameters("StepWidth must be positive.");
    	if( StepsPerCircle < 3 )
    		return BadParameters("At least 3 steps per circle.");
    	if( NumSteps < 1 )
    		return BadParameters("A staircase with 0 or negative steps is silly!");
    	if( NumSteps >= StepsPerCircle && (NumSteps-1)* StepHeight <= StepThickness )
    		BadParameters("The stairs may intersect themselves. Not recommended, but press OK to build anyway.");
    	if ( TopStyle == STYLE_Flat || BaseStyle == STYLE_Flat )
    	{
    		if( NumSteps == StepsPerCircle )
    			BadParameters("A full circle with a 'flat' option will have co-inciding vertices. "$
    						"Press OK to build anyway, but subtracting this brush will leave a spare sheet poly. "$
    						"If this is vitally important, support may added in a future version.");
    		if( NumSteps > StepsPerCircle )
    			return BadParameters("Can't have more than a full circle with the flat option.");
    	}

    // ######################################################### set locals
    // Edge, Disjoint have been set at the parameter checking stage.

    InnerVector.x = InnerRadius ;
    FlingVector.x = StepWidth ;

    StepHeightVector.z = StepHeight ;
    StepThicknessVector.z = StepThickness;

    SpinTransformation.Yaw = 65536.0f / StepsPerCircle ;
    sgn = 1;

    log( "edge= " $ String(Edge) $ "; disjoint= " $ String(Disjoint) );

    if( AntiClockwise )
    {
    	SpinTransformation.Yaw = -SpinTransformation.Yaw ;
    	sgn = -sgn ;
    }

    // !!!!!!! make alterations for anticlockwise! here, before we set the temps.
    // flip Yaw, flip sgn ?? check prev ver.

    // ############# set temps
    heightOffset.z = StepHeightVector.z ;
    thicknessOffset.z = StepThicknessVector.z ;

    /*
    if Flat, user's input StepThickness gives height of first step, like StepStep case.
    	 In effect, StepThickness - StepHeight will work like AddToFirstStep.

    be careful to set these correctly. they apply to = and < case, but if flat, disjoint does not apply, it just means first step will be shallower.
    What does Edge + step + flat mean??? Means NOT edge, since the edge factor won't come into play at all!

    ========================================================== notes on edge and disjoint
    In this list, edge and disjoint refer to the = and < cases, rather than the boolean values.
    a ** means don't set the boolean.
    forbidden cases are intercepted earlier, so no need to consider them here.
    edge + step + step: 		classical edge
    edge + step + slope:		side polys are triangles
    edge + step + flat:		** just means first step same thickness as other steps, should fall out of calculations.
    edge + slope + slope:	forbidden -- side polys have no ares.
    edge + slope + flat:		side elevation is big triangle. Slope handled conventionally, flat side needs an axial offset.
    					watch the side polys! first is a triangle, next are as regular slope+flat.
    					NOTE: as of 0.4.6, flagging has been enabled for this option. residual bugs may occur!
    edge + flat + flat:		forbidden.!

    disjoint + step + step: 	seperate steps
    disjoint + step + slope:	forbidden: first slope would dip below baseline.
    disjoint + step + flat:		** just means first step shallower. handled by flat code.
    disjoint + slope + slope:	forbidden
    disjoint + slope + flat:	forbidden: first slope would dip below baseline.
    disjoint + flat + flat:		forbidden

    we ARE allowed flat with edgeslope or edge.
    */

    // ****************************************************************** vertex build

    BeginBrush( false, GroupName );
    log( "Start Vertex count:" $ GetVertexCount() );

    /*
    We build vertices on 4 tracks: a,b,c,d.
    Each track is either circular or helicoid.
    Track a has vertices 0 to TrackB - 1, etc.
    As far as vertices are concerned, the choice of steps / slope / flat for Upper is independant of the
    choice for Lower. Likewise, Disjoint is treated the same as StepStep.
    We do however have special cases: edge, edgeSlopeUpper, edgeSlopeLower, and the last two with flat opposite.
    In the first case, Lower is treated as if it were regular Step, and Upper has a special form, unique to this case.
    In the two EdgeSlope cases, we choose which tracks takes the 'common' vertex in such a way as the sloped side behaves like the standard sloped case.
    EdgeSlopeUpper: tracks a,b take the standard slope option, tracks c,d  have a special form.
    EdgeSlopeLower: tracks c,d take standard slope. tracks a,b have a special form, in fact identical to Edge.

    Summary:
    ( * indicates a terminal vertex is required )
    LOWER: 	Step (inc. Edge, Disjoint)
    		Slope* (inc. EdgeSlopeLower*), Flat*, (height=0 for flat)
    		EdgeSlopeUpper (axially offset, no terminal)
    UPPER: 	Step (inc. Disjoint)
    		Edge (inc EdgeSlopeLower) (NB no terminal)
    		Slope* (inc. EdgeSlopeUpper), Flat*
    */

    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  tracks a,b LOWER
    if( BaseStyle == STYLE_Steps &&
    	!( Edge && TopStyle ==  STYLE_Slope ) )
    {
    	// all types of Step, EXCEPT EdgeSlopeUpper
    	// set the jump to 2 for these two tracks for polys later. No terminal vertex.
    	for( j = 0 ; j < 2 ; j++ )
    		for( i = 0 ; i < NumSteps ; i++ )
    		{
    			Vertexv(
    				( ( InnerVector + j*FlingVector ) >> ( SpinTransformation * i ) )
    				+ StepHeightVector * i );
    			Vertexv(
    				( ( InnerVector + j*FlingVector ) >> ( SpinTransformation * ( i + 1 ) ) )
    				+ StepHeightVector * i );
    		}
    	TrackJumpLower = 2;
    	TrackOffsetB = ( NumSteps * 2 );
    	TrackOffsetC = TrackOffsetB + ( NumSteps * 2 );
    }
    else
    {
    	/*
    	CASE Flat, ( Slope, EdgeSlopeLower, EdgeSlopeLowerFlatUpper),
    			EdgeSlopeUpper, EdgeSlopeUpperFlatLower
    	one point per step.
    	set the jump to 1 for these two tracks for polys later.
    	set the height increment vector to:
    	step height if slope
    	0 if flat
    	NOTE: EdgeSlopeUpperFlatLower: can be treated as an i offset,
    		but if we treat as an axial offset, the case reverts to
    	EdgeSlopeUpper, but with no height increments. The zero H will be factored in by the flat condition.
    	*/
    	// ################# prepare vars for subcases
    	if( BaseStyle ==  STYLE_Flat )
    		heightOffset.z = 0 ;
    	// Terminal vertex, Axial offset: cases are two disjoint sets
    	if( Edge && TopStyle == STYLE_Slope )
    		iOffset = 1 ; // Axial offset: EdgeSlopeUpper, EdgeSlopeUpperFlatLower, no terminal
    	else
    		iTerminal = 1 ; // all bar EdgeSlopeUpper and EdgeSlopeUpperFlatLower

    	for( j = 0 ; j < 2 ; j ++ )
    		for( i = 0 ; i < NumSteps + iTerminal ; i++ )
    			Vertexv(
    				( ( InnerVector + j*FlingVector ) >> ( SpinTransformation * ( i + iOffset ) ) )
    				+ heightOffset * i
    				);
    	TrackJumpLower = 1;
    	TrackOffsetB =  NumSteps + iTerminal;
    	TrackOffsetC =  TrackOffsetB + NumSteps + iTerminal;
    }
    // END of lower tracks.
    // RESET temp variables.
    heightOffset.z = StepHeightVector.z ;
    thicknessOffset.z = StepThicknessVector.z ;
    iOffset = 0 ;
    iTerminal = 0 ;

    // ============================================== TRACKS C,D UPPER.
    /*
    UPPER: 	Step (inc. Disjoint)
    		Edge (inc EdgeSlopeLower) (NB no terminal)
    		Slope* (inc. EdgeSlopeUpper, EdgeSlopeUpperFlatLower), Flat*,
    			EdgeSlopeLowerFlatUpper [same as flat, but no * since it co-incides]
    how do we branch?
    we want branch 1: Step EXCEPT Edge, EdgeSlopeLower, EdgeSlopeLowerFlatUpper
    if( top = step AND  ( edge=False but NOT EdgeSlopeUpper )
    	but EdgeSlopeUpper means top= slope, so we've already caught it. SO:
    	if( top == step AND Edge = False )
    */
    if( ( TopStyle == STYLE_Steps ) && ( !Edge ) )
    {
    	/*
    	CASE step, disjoint, BUT NOT edge.
    	set the jump to 2 for these two tracks for polys later.
    	set the height increment to	step height.
    	Special requirements: none.
    	*/
    	for( j = 0 ; j < 2 ; j++ )
    		for( i = 0 ; i < NumSteps ; i++ )
    		{
    			Vertexv(
    				( ( InnerVector + j*FlingVector ) >> ( SpinTransformation * i ) )
    				+ StepThicknessVector
    				+ StepHeightVector * i );
    			Vertexv(
    				( ( InnerVector + j*FlingVector ) >> ( SpinTransformation * ( i + 1 ) ) )
    				+ StepThicknessVector
    				+ StepHeightVector * i );
    		}
    	TrackJumpUpper = 2;
    	TrackOffsetD = TrackOffsetC +  ( NumSteps * 2 );
    }
    else
    {
    	/*
    	CASE Slope, EdgeSlopeUpper, Flat, Edge, EdgeSlopeLower
    	set the jump to 1 for these two tracks for polys later.
    	set the height increment vector to: step height if slope, 0 if flat
    	for Slope, EdgeSlopeUpper, we need height * ( i -1) to drop the front of each step
    		(incidentally, to zero in the EdgeSlopeUpper case)
    	terminal vertices:	for Slope, EdgeSlopeUpper, Flat, EDGE!! ONLY.

    	if( TOP = Slope ) ( one extra vertex at the end )
    	vertexv =	 ( InnerVector >> SpinTransformation * i )
    		+ StepHeightVector * ( i - 1 )	// because we need to DIP the front of each step
    		+ StepThicknessVector
    	if( TOP = FLAT )
    	vertexv =	 ( InnerVector >> SpinTransformation * i )
    		+ StepThicknessVector
    		+ StepHeightVector * ( NumSteps - 1) // to make total height of the block throughout.
    	if ( EDGE, EDGESLOPELOWER )
    	vertexv =	 ( InnerVector >> SpinTransformation * i )
    		+ StepHeightVector * i
    		+ StepThicknessVector
    	*/
    	// ################# prepare vars for subcases
    	if( TopStyle == STYLE_Slope )
    	{
    		iOffset = - 1 ; // this handles Slope and EdgeSlopeUpper: height dip
    		iTerminal = 1 ; // we need a terminal vertex
    		// this will also handle EdgeSlopeUpperFlatLower.
    	}
    	if( TopStyle == STYLE_Flat )
    	{
    		thicknessOffset.z = StepThickness + StepHeight * (NumSteps - 1 );
    		heightOffset.z = 0 ; // so no further height is added
    		if( !( Edge && BaseStyle == STYLE_Slope ) )
    			iTerminal = 1 ; // we need a terminal vertex BUT NOT IF EDGE + SlopeLower
    	}
    	// the other two cases are edge (ie top steps) or edgeslopelower (ie top steps)
    	// AND edgeslopelowerFlatUpper, handle like top Flat here (but no terminal)
    	// AND edgeSlopeUpperFlatLower, handle like Slope Upper.
    	log( "iTerminal=" $ String( iTerminal ) );
    	for( j = 0 ; j < 2 ; j++ )
    	{
    		for( i = 0 ; i < NumSteps + iTerminal ; i++ )
    		{
    			// log( "i:" $ String(i) $ ", V" $ String(GetVertexCount()) );
    			Vertexv(
    				( ( InnerVector + j*FlingVector ) >> ( SpinTransformation * i ) )
    				+ heightOffset * ( i + iOffset )
    				+ thicknessOffset
    				);
    		}
    		// special case: Edge needs a terminal vector, but not raised, so build it here.
    		// this is a little messy since we assign twice, but to preserve track order...
    		// for i = last = NumSteps -1, we want an axial offset, but standanrd height.
    		if( Edge && ( TopStyle == STYLE_Steps && BaseStyle == STYLE_Steps ) )
    		{
    			log( "j:" $ String(j) $ ", iX, V" $ String(GetVertexCount()) );
    			Vertexv(
    				( ( InnerVector + j*FlingVector ) >> ( SpinTransformation * NumSteps ) )
    				+ heightOffset * ( NumSteps - 1)
    				+ thicknessOffset
    				);
    			log("Edge StepStep. Terminal vertex:" $ String(
    				( ( InnerVector + j*FlingVector ) >> ( SpinTransformation * NumSteps ) )
    				+ heightOffset * ( NumSteps - 1)
    				+ thicknessOffset ) );
    			// since TOP= steps, this has not been set yet. We never have more than 1 terminal.
    		}
    	}
    	if( Edge && ( TopStyle == STYLE_Steps && BaseStyle == STYLE_Steps ) )
    		iTerminal = 1;
    	TrackJumpUpper = 1;
    	TrackOffsetD = TrackOffsetC + NumSteps + iTerminal;
    }

    log( "B: " $ String(TrackOffsetB) $ " C: " $ String(TrackOffsetC) $ " D: " $ String(TrackOffsetD) );

    // ****************************************************************** poly build
    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  base going
    /*
    ######################### CASE Base = Step:
    	exception: EdgeSlopeUpper (we jump to upper track)
    	includes:
    		Edge, because of way vertices built.
    		Disjoint.
    for( i = 0 ; i < TrackJumpLower * NumSteps ; i+= TrackJumpLower )
    	Poly4i( sgn , i , i + 1 , TrackOffsetB + 1 , TrackOffsetB , 'basegoing' );
    exception:
    for( i = 0 ; i < TrackJumpLower * NumSteps ; i+= TrackJumpLower ) // TrackJumpLower = 1
    	Poly4i( sgn , i , TrackOffsetB , TrackOffsetD, TrackOffsetC, 'basegoing' );
    */
    if( BaseStyle == STYLE_Steps )
    {
    	// GOING
    	if( Edge && ( TopStyle == STYLE_Slope ) )
    		for( i = 0 ; i < NumSteps ; i++ ) //  EdgeSlopeUpper: the only exception. TrackJumpLower = 1
    			Poly4i( sgn , i , TrackOffsetB + i , TrackOffsetD + i , TrackOffsetC + i , 'basegoing' );
    	else
    	{
    		for( i = 0 ; i < TrackJumpLower * NumSteps ; i+= TrackJumpLower )
    			{
    			Poly4i( sgn , i , i + 1 , TrackOffsetB + i + 1 , TrackOffsetB +  i , 'basegoing' );
    			log( "going: " $ String(i)$","$String(i+1)$","$String(TrackOffsetB+i+1)$","$String(TrackOffsetB+i) );
    			}
    	}
    	// RISER
    	// BUG!!!!! beware final riser -- uses upper tracks. to take care of this, stop short of last.
    		// this applies only to regular case, since the exceptions take from upper tracks all the way
    	// exceptions: disjoint, need to take from upper track; edgeSlopeUpper, likewise.
    	if( Disjoint )
    	{
    		log("disjoint riser");
    		// oops forgot TrackJump
    		for( i = 0 ; i < NumSteps ; i++ )
    		{
    			Poly4i( sgn ,
    				TrackJumpLower * i + 1 ,
    				TrackOffsetC + ( TrackJumpUpper * i ) + 1 ,
    				TrackOffsetD + ( TrackJumpUpper * i ) + 1 ,
    				TrackOffsetB + ( TrackJumpLower * i ) + 1 ,
    				'baseriser' ); // note inc. closing cap
    			log("riser:" $ String(i+1) $","$ String(TrackOffsetC+i+1)
    				$","$ String(TrackOffsetD+i+1) $","$ String(TrackOffsetB + i + 1) );
    		}
    	}
    	else if ( Edge &&  TopStyle == STYLE_Slope )
    		for( i = 0 ; i < NumSteps ; i++ )
    			Poly4i( sgn , i , TrackOffsetC + i + 1 , TrackOffsetD + i + 1 , TrackOffsetB + i , 'baseriser' ); // note inc. closing ca
    	else
    	{
    		for( i = 0 ; i < ( TrackJumpLower * ( NumSteps - 1 ) ) - 1 ; i+= TrackJumpLower )
    		{
    			Poly4i( sgn , i + 1 , i + 2 , TrackOffsetB + i + 2 , TrackOffsetB + i + 1 , 'baseriser' );
    			log( "riser: " $ String(i+1)$","$String(i+2)$","$String(TrackOffsetB+i+2)$","$String(TrackOffsetB+i+1) );
    		}
    		Poly4i( sgn ,
    				TrackJumpLower * ( NumSteps - 1 ) + 1,
    				TrackOffsetC + ( TrackJumpUpper * ( NumSteps - 1 ) ) + 1 ,
    				TrackOffsetD + ( TrackJumpUpper * ( NumSteps - 1 ) ) + 1 ,
    				TrackOffsetB + TrackJumpLower * ( NumSteps - 1 ) + 1,
    				'baseriser' ); // CLOSING CAP for generic step case.
    			// use the UpperJUMP to  cover all cases
    		log( "cap: "
    			$ String(TrackJumpLower * ( NumSteps - 1 ) + 1 ) $","
    			$ String(TrackOffsetC + ( TrackJumpUpper * ( NumSteps - 1 ) ) + 1) $ ","
    			$ String(TrackOffsetD + ( TrackJumpUpper * ( NumSteps - 1 ) ) + 1 ) $ ","
    			$ String(TrackOffsetB + TrackJumpLower * ( NumSteps - 1 ) + 1 )
    			);
    	}
    }
    else if( BaseStyle == STYLE_Flat )
    {
    	if( Edge && TopStyle == STYLE_Slope )
    	{
    		// special case: Edge && Upper = Slope ( first vertex is from upper track)
    		Poly4i( sgn , 0 , TrackOffsetB , TrackOffsetD, TrackOffsetC, 'basegoing' );
    		// now we build steps 1 to N-1, remember we're a vertex ahead now.
    		for( i = 1 ; i < NumSteps ; i++ )
    			Poly4i( sgn , i - 1 , i , TrackOffsetB + i , TrackOffsetB + i - 1 , 'basegoing' );
    		Poly4i( sgn ,
    			TrackJumpLower * ( NumSteps - 1 ) ,
    			TrackOffsetC + ( TrackJumpUpper * ( NumSteps - 1 ) ) + 1 ,
    			TrackOffsetD + ( TrackJumpUpper * ( NumSteps - 1 ) ) + 1 ,
    			TrackOffsetB + TrackJumpLower * ( NumSteps - 1 ) ,
    			'baseriser' ); // CLOSING CAP
    		// closing cap fitted into special case because of lower track vertex offset
    	}
    	else
    	{
    		for( i = 0 ; i < NumSteps ; i++ )
    			Poly4i( sgn , i , i + 1 , TrackOffsetB + i + 1 , TrackOffsetB + i , 'basegoing' );
    		Poly4i( sgn ,
    			TrackJumpLower * ( NumSteps - 1 ) + 1,
    			TrackOffsetC + ( TrackJumpUpper * ( NumSteps - 1 ) ) + 1 ,
    			TrackOffsetD + ( TrackJumpUpper * ( NumSteps - 1 ) ) + 1 ,
    			TrackOffsetB + TrackJumpLower * ( NumSteps - 1 ) + 1,
    			'baseriser' ); // CLOSING CAP.
    	}
    	log( TrackJumpLower * ( NumSteps - 1 ) + 1 );
    	log( TrackOffsetC + ( TrackJumpUpper * ( NumSteps - 1 ) ) + 1 );
    	log( TrackOffsetD + ( TrackJumpUpper * ( NumSteps - 1 ) ) + 1 );
    	log( TrackOffsetB + TrackJumpLower * ( NumSteps - 1 ) + 1 );
    	// NO RISER
    }
    else if( BaseStyle == STYLE_Slope )
    {
    	log( "slope" );
    	// there are NO special cases, since all these have been built with the slope topology in mind
    	// oops there is: closing cap
    	if( ! Edge )
    		Poly4i( sgn ,
    			TrackJumpLower * ( NumSteps - 1 ) + 1,
    			TrackOffsetC + ( TrackJumpUpper * ( NumSteps - 1 ) ) + 1 ,
    			TrackOffsetD + ( TrackJumpUpper * ( NumSteps - 1 ) ) + 1 ,
    			TrackOffsetB + TrackJumpLower * ( NumSteps - 1 ) + 1,
    			'baseriser' ); // CLOSING CAP OK! copied from above. test for glitches.
    	for( i = 0 ; i < NumSteps ; i++ )
    	{
    		Poly3i( sgn, i , i + 1, TrackOffsetB + i + 1 , 'baseslope' );
    		Poly3i( sgn, i , TrackOffsetB + i + 1 , TrackOffsetB + i , 'baseslope' );
    	}
    }
    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  outer side
    /*
    special cases:
    	an Edge+Slope+Flat combination -- one is a triangle.
    	an edge + Slope combi: all tri.
    	Edge: take upper track, WATCH FINAL

    branching: possible edge setups, list copied from above -- ** means boolean not set
    edge + step + step: 		classical edge: SPECIAL 1
    edge + step + slope:		side polys are triangles: SPECIAL 2B, 3B
    edge + step + flat:		** MAIN
    edge + slope + slope:	forbidden
    edge + slope + flat:		** SPECIAL 2A, 3A
    edge + flat + flat:		forbidden.
    */

    if( Edge && ( TopStyle == STYLE_Steps && BaseStyle == STYLE_Steps ))
    {
    	log("SIDE: EDGE");
    	for( i = 0 ; i < NumSteps - 1 ; i++ )
    		Poly4i( sgn,
    			TrackOffsetB + ( i * TrackJumpLower ),
    			TrackOffsetB + ( i * TrackJumpLower ) + 1,
    			TrackOffsetB + ( i * TrackJumpLower ) + 2,
    			TrackOffsetD + ( i * TrackJumpUpper ),
    			'outerwall' ); // all bar last take 3 from lower track
    	Poly4i( sgn,
    		TrackOffsetB + ( (NumSteps - 1) * TrackJumpLower ),
    		TrackOffsetB + ( (NumSteps - 1) * TrackJumpLower ) + 1,
    		TrackOffsetD + ( (NumSteps - 1) * TrackJumpUpper ) + 1,
    		TrackOffsetD + ( (NumSteps - 1) * TrackJumpUpper ),
    		'outerwall' ); // last take two and two.
    }
    else if( Edge && TopStyle == STYLE_Slope )
    {
    	log("edge, top = slope");
    	// we have two poss. base flat, base step. first poly same, then differ.
    	Poly3i( sgn, TrackOffsetB, TrackOffsetD + 1, TrackOffsetD, 'outerwall' );
    	log("OuterWall 1:" $ String(TrackOffsetB) $","$ String(TrackOffsetD+1) $","$ String(TrackOffsetD) );
    	if( BaseStyle == STYLE_Flat )
    		for( i = 1 ; i < NumSteps ; i++ )
    			Poly4i( sgn,
    				TrackOffsetB + i - 1,
    				TrackOffsetB + i ,
    				TrackOffsetD + i + 1,
    				TrackOffsetD + i ,
    				'outerwall' );//OK!
    	else
    		for( i = 1 ; i < NumSteps ; i++ )
    			Poly3i( sgn, TrackOffsetB + i, TrackOffsetD + i + 1, TrackOffsetD + i, 'outerwall' ); //OK!
    }
    else if( Edge && BaseStyle == STYLE_Slope )
    {
    	// we have two poss. base flat, base step. different up to last poly. NOTE changed condition back to edge rather than == check
    	if( TopStyle == STYLE_Flat )
    		for( i = 0 ; i < NumSteps - 1 ; i++ )
    			Poly4i( sgn,
    				TrackOffsetB + i ,
    				TrackOffsetB + i + 1,
    				TrackOffsetD + i + 1,
    				TrackOffsetD + i ,
    				'outerwall' ); // OK!
    	else
    		for( i = 0 ; i < NumSteps - 1 ; i++ )
    			Poly3i( sgn, TrackOffsetB + i, TrackOffsetB + i + 1, TrackOffsetD + i, 'outerwall' );//OK!
    	Poly3i( sgn,
    		TrackOffsetB + NumSteps - 1,
    		TrackOffsetB + NumSteps - 1 + 1,
    		TrackOffsetD + NumSteps - 1, 'outerwall' );
    	// log("OuterWall 1:" $ String(TrackOffsetB) $","$ String(TrackOffsetB+1) $","$ String(TrackOffsetD) );
    }
    else
    	for( i = 0 ; i < NumSteps ; i++ )
    		Poly4i( sgn,
    			TrackOffsetB + ( i * TrackJumpLower ),
    			TrackOffsetB + ( i * TrackJumpLower ) + 1,
    			TrackOffsetD + ( i * TrackJumpUpper ) + 1,
    			TrackOffsetD + ( i * TrackJumpUpper ),
    			'outerwall' );

    // END OF OUTER WALL
    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  top going & riser
    /*
    step:going:
    special cases: 	edge ( some from lower track)
    			edgeslopelower (some from lower track -- is this similar. should be. use TrackJumpt to combine.
    step:riser:		edge (lower track used), edgeslopelower
    			disjoint (lower)
    			FIRST riser special.
    */
    if( TopStyle == STYLE_Steps )
    {
    	if( Edge )
    	{
    		// top is already known to be Step. So with edge, 3 cases for base. But flat base not flagged as edge, so
    		// we catch only the 2 cases we want.
    		for( i = 0 ; i < NumSteps - 1 ; i++ )
    			Poly4i( sgn,
    				( i + 1 ) * TrackJumpLower,
    				TrackOffsetC + i,
    				TrackOffsetD + i,
    				TrackOffsetB + (i + 1) * TrackJumpLower,
    				'topgoing' );
    		// now the risers. we start with START CAP.
    		for( i = 0 ; i < NumSteps ; i++ )
    			Poly4i( sgn,
    				TrackOffsetB + ( i * TrackJumpLower ),
    				TrackOffsetD + i,
    				TrackOffsetC + i,
    				i * TrackJumpLower, 'topriser' );
    		// now do final going: two cases.
    		if( BaseStyle == STYLE_Steps )
    		{
    			Poly4i( sgn,
    				TrackOffsetC + NumSteps - 1 + 1 ,
    				TrackOffsetC + NumSteps - 1,
    				TrackOffsetD + NumSteps - 1, TrackOffsetD + NumSteps - 1 + 1, 'topgoing' );
    		}
    		else
    		{
    			// otherwise: base is slope.
    			Poly4i( sgn,
    				NumSteps - 1 + 1,
    				TrackOffsetC + NumSteps - 1,
    				TrackOffsetD + NumSteps - 1,
    				TrackOffsetB + NumSteps - 1 + 1, 'topgoing' );
    		}
    	}
    	else
    	{
    		// main case going
    		for( i = 0 ; i < NumSteps ; i++ )
    			Poly4i( sgn, TrackOffsetC  +2*i + 1,
    				TrackOffsetC + 2*i,
    				TrackOffsetD + 2*i,
    				TrackOffsetD + 2*i + 1,  'topgoing' );// main step case
    		// now the riser:
    		if( Disjoint )
    			for( i = 0 ; i < NumSteps ; i++ )
    				Poly4i( sgn, TrackOffsetB + 2*i , TrackOffsetD+ 2*i , TrackOffsetC+ 2*i , 2*i , 'topriser' );
    		else
    		{
    			// main case riser. first special, then loop
    			Poly4i( sgn, TrackOffsetB, TrackOffsetD, TrackOffsetC, 0, 'topriser' ); // START CAP
    			for( i = 1 ; i < NumSteps ; i++ )
    				Poly4i( sgn, TrackOffsetD +2*i - 1, TrackOffsetD + 2*i,
    					TrackOffsetC + 2*i,TrackOffsetC +2*i - 1, 'topriser' );
    		}
    	}
    }
    else if( TopStyle == STYLE_Flat )
    {
    	// start cap:
    	Poly4i( sgn, TrackOffsetB, TrackOffsetD, TrackOffsetC, 0, 'topriser' ); // START CAP
    	// do all goings bar final:
    	for( i = 0 ; i < NumSteps - 1 ; i++ )
    		Poly4i( sgn, TrackOffsetC + i, TrackOffsetD + i, TrackOffsetD+i+1, TrackOffsetC+i+1, 'topgoing' );
    	if( Edge && BaseStyle == STYLE_Slope )
    		Poly4i( sgn,  TrackOffsetC + NumSteps - 1, TrackOffsetD + NumSteps - 1,
    			TrackOffsetB + NumSteps, NumSteps, 'topgoing' ); // special case final going
    	else
    		Poly4i( sgn, TrackOffsetC + NumSteps - 1, TrackOffsetD + NumSteps - 1,
    			TrackOffsetD + NumSteps, TrackOffsetC + NumSteps, 'topgoing' ); //main case final going
    }
    else
    {
    	// remaining case: slope
    	if( ! Edge )
    		Poly4i( sgn, TrackOffsetB, TrackOffsetD, TrackOffsetC, 0, 'topriser' ); // START CAP if not edge.
    	for( i = 0 ; i < NumSteps ; i++ )
    	for( i = 0 ; i < NumSteps ; i++ )
    	{
    	Poly3i( sgn, TrackOffsetC + i, TrackOffsetD + i, TrackOffsetC + i + 1, 'topgoing' );
    	Poly3i( sgn, TrackOffsetD + i, TrackOffsetD + i + 1, TrackOffsetC + i + 1, 'topgoing' );
    	}
    }
    // end of TOP GOING & RISER
    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  inner wall
    // copy of outer wall code with offset changed for tacks a,c. -sgn is flipped.
    /*
    special cases:
    	an Edge+Slope+Flat combination -- one is a triangle.
    	an edge + Slope combi: all tri.
    	Edge: take upper track, WATCH FINAL

    branching: possible edge setups, list copied from above -- ** means boolean not set
    edge + step + step: 		classical edge: SPECIAL 1
    edge + step + slope:		side polys are triangles: SPECIAL 2B, 3B
    edge + step + flat:		** MAIN
    edge + slope + slope:	forbidden
    edge + slope + flat:		** SPECIAL 2A, 3A
    edge + flat + flat:		forbidden.
    */

    if( Edge && ( TopStyle == STYLE_Steps && BaseStyle == STYLE_Steps ))
    {
    	log("SIDE: EDGE");
    	for( i = 0 ; i < NumSteps - 1 ; i++ )
    		Poly4i( -sgn,
    			0 + ( i * TrackJumpLower ),
    			0 + ( i * TrackJumpLower ) + 1,
    			0 + ( i * TrackJumpLower ) + 2,
    			TrackOffsetC + ( i * TrackJumpUpper ),
    			'innerwall' ); // all bar last take 3 from lower track
    	Poly4i( -sgn,
    		0 + ( (NumSteps - 1) * TrackJumpLower ),
    		0 + ( (NumSteps - 1) * TrackJumpLower ) + 1,
    		TrackOffsetC + ( (NumSteps - 1) * TrackJumpUpper ) + 1,
    		TrackOffsetC + ( (NumSteps - 1) * TrackJumpUpper ),
    		'innerwall' ); // last take two and two.
    }
    else if( Edge && TopStyle == STYLE_Slope )
    {
    	log("edge, top = slope");
    	// we have two poss. base flat, base step. first poly same, then differ.
    	Poly3i( -sgn, 0, TrackOffsetC + 1, TrackOffsetC, 'innerwall' );
    	log("OuterWall 1:" $ String(0) $","$ String(TrackOffsetC+1) $","$ String(TrackOffsetC) );
    	if( BaseStyle == STYLE_Flat )
    		for( i = 1 ; i < NumSteps ; i++ )
    			Poly4i( -sgn,
    				0 + i - 1,
    				0 + i ,
    				TrackOffsetC + i + 1,
    				TrackOffsetC + i ,
    				'innerwall' );//OK!
    	else
    		for( i = 1 ; i < NumSteps ; i++ )
    			Poly3i( -sgn, 0 + i, TrackOffsetC + i + 1, TrackOffsetC + i, 'innerwall' ); //OK!
    }
    else if( Edge && BaseStyle == STYLE_Slope )
    {
    	// we have two poss. base flat, base step. different up to last poly. NOTE changed condition back to edge rather than == check
    	if( TopStyle == STYLE_Flat )
    		for( i = 0 ; i < NumSteps - 1 ; i++ )
    			Poly4i( -sgn,
    				0 + i ,
    				0 + i + 1,
    				TrackOffsetC + i + 1,
    				TrackOffsetC + i ,
    				'innerwall'); // OK!
    	else
    		for( i = 0 ; i < NumSteps - 1 ; i++ )
    			Poly3i( -sgn, 0 + i, 0 + i + 1, TrackOffsetC + i, 'innerwall' );//OK!
    	Poly3i( -sgn,
    		0 + NumSteps - 1,
    		0 + NumSteps - 1 + 1,
    		TrackOffsetC + NumSteps - 1, 'innerwall');
    	// log("OuterWall 1:" $ String(0) $","$ String(0+1) $","$ String(TrackOffsetC) );
    }
    else
    	for( i = 0 ; i < NumSteps ; i++ )
    		Poly4i( -sgn,
    			0 + ( i * TrackJumpLower ),
    			0 + ( i * TrackJumpLower ) + 1,
    			TrackOffsetC + ( i * TrackJumpUpper ) + 1,
    			TrackOffsetC + ( i * TrackJumpUpper ),
    			'innerwall' );
    // END OF INNER WALL

    return EndBrush();
    }

    defaultproperties
    {
         StepHeight=16.000000
         StepThickness=32.000000
         StepWidth=128.000000
         InnerRadius=64.000000
         StepsPerCircle=8
         NumSteps=8
         GroupName=SpiralStsirs
         BitmapFilename="SFEDBBTarquinSpiral"
         ToolTip="Enhanced Spiral Stair Builder"
    }

class file time: 12/7/2003 3:58:26 PM - creation time: 12/7/2003 4:03:46 PM
Created with UnCodeX