void EllipseObject::BuildShape(TimeValue t, BezierShape& ashape) { // Start the validity interval at forever and whittle it down. ivalid = FOREVER; float length; float width; float thickness; BOOL build_outine = FALSE; myParamBlock->GetValue(PB_LENGTH, t, length, ivalid); myParamBlock->GetValue(PB_WIDTH, t, width, ivalid); myParamBlock->GetValue(PB_THICKNESS, t, thickness, ivalid); myParamBlock->GetValue(PB_OUTLINE, t, build_outine, ivalid); LimitValue( length, MIN_LENGTH, MAX_LENGTH ); LimitValue( width, MIN_WIDTH, MAX_WIDTH ); LimitValue(thickness, MIN_THICK, MAX_THICK ); // Delete the existing shape and create a new spline in it ashape.NewShape(); // Get parameters from SimpleSpline and place them in the BezierShape int steps; BOOL optimize,adaptive; ipblock->GetValue(IPB_STEPS, t, steps, ivalid); ipblock->GetValue(IPB_OPTIMIZE, t, optimize, ivalid); ipblock->GetValue(IPB_ADAPTIVE, t, adaptive, ivalid); ashape.steps = adaptive ? -1 : steps; ashape.optimize = optimize; float radius, xmult, ymult; if(length < width) { radius = width; xmult = 1.0f; ymult = length / width; } else if(width < length) { radius = length; xmult = width / length; ymult = 1.0f; } else { radius = length; xmult = ymult = 1.0f; } MakeCircle(ashape, radius / 2.0f, xmult, ymult); if(build_outine) { length += 2*thickness; width += 2*thickness; LimitValue( length, MIN_LENGTH, MAX_LENGTH ); LimitValue( width, MIN_WIDTH, MAX_WIDTH ); if(length < width) { radius = width; xmult = 1.0f; ymult = length / width; } else if(width < length) { radius = length; xmult = width / length; ymult = 1.0f; } else { radius = length; xmult = ymult = 1.0f; } MakeCircle(ashape, radius / 2.0f, xmult, ymult); } ashape.UpdateSels(); // Make sure it readies the selection set info ashape.InvalidateGeomCache(); }
void RectangleObject::BuildShape(TimeValue t, BezierShape& ashape) { // Start the validity interval at forever and whittle it down. ivalid = FOREVER; float length,fillet; float width; pblock->GetValue(PB_LENGTH, t, length, ivalid); pblock->GetValue(PB_WIDTH, t, width, ivalid); pblock->GetValue(PB_FILLET, t, fillet, ivalid); LimitValue( length, MIN_LENGTH, MAX_LENGTH ); LimitValue( width, MIN_WIDTH, MAX_WIDTH ); LimitValue( fillet, MIN_WIDTH, MAX_WIDTH ); // Delete the existing shape and create a new spline in it ashape.NewShape(); // Get parameters from SimpleSpline and place them in the BezierShape int steps; BOOL optimize,adaptive; ipblock->GetValue(IPB_STEPS, t, steps, ivalid); ipblock->GetValue(IPB_OPTIMIZE, t, optimize, ivalid); ipblock->GetValue(IPB_ADAPTIVE, t, adaptive, ivalid); ashape.steps = adaptive ? -1 : steps; ashape.optimize = optimize; Spline3D *spline = ashape.NewSpline(); // Now add all the necessary points // We'll add 'em as auto corners initially, have the spline package compute some vectors (because // I'm basically lazy and it does a great job, besides) then turn 'em into bezier corners! float l2 = length / 2.0f; float w2 = width / 2.0f; Point3 p = Point3(w2, l2, 0.0f); int pts=4; if (fillet>0) { pts=8; float cf=fillet*CIRCLE_VECTOR_LENGTH; Point3 wvec=Point3(fillet,0.0f,0.0f),lvec=Point3(0.0f,fillet,0.0f); Point3 cwvec=Point3(cf,0.0f,0.0f),clvec=Point3(0.0f,cf,0.0f); Point3 p3=p-lvec,p2; spline->AddKnot(SplineKnot(KTYPE_BEZIER,LTYPE_CURVE,p3,p3-clvec,p3+clvec)); p=p-wvec; spline->AddKnot(SplineKnot(KTYPE_BEZIER,LTYPE_CURVE,p,p+cwvec,p-cwvec)); p=Point3(-w2,l2,0.0f);p2=p+wvec; spline->AddKnot(SplineKnot(KTYPE_BEZIER,LTYPE_CURVE,p2,p2+cwvec,p2-cwvec)); p=p-lvec; spline->AddKnot(SplineKnot(KTYPE_BEZIER,LTYPE_CURVE,p,p+clvec,p-clvec)); p=Point3(-w2,-l2,0.0f);p3=p+lvec; spline->AddKnot(SplineKnot(KTYPE_BEZIER,LTYPE_CURVE,p3,p3+clvec,p3-clvec)); p=p+wvec; spline->AddKnot(SplineKnot(KTYPE_BEZIER,LTYPE_CURVE,p,p-cwvec,p+cwvec)); p = Point3(w2, -l2, 0.0f);p3=p-wvec; spline->AddKnot(SplineKnot(KTYPE_BEZIER,LTYPE_CURVE,p3,p3-cwvec,p3+cwvec)); p=p+lvec; spline->AddKnot(SplineKnot(KTYPE_BEZIER,LTYPE_CURVE,p,p-clvec,p+clvec)); spline->SetClosed(); spline->ComputeBezPoints(); } else {spline->AddKnot(SplineKnot(KTYPE_CORNER,LTYPE_CURVE,p,p,p)); p = Point3(-w2, l2, 0.0f); spline->AddKnot(SplineKnot(KTYPE_CORNER,LTYPE_CURVE,p,p,p)); p = Point3(-w2, -l2, 0.0f); spline->AddKnot(SplineKnot(KTYPE_CORNER,LTYPE_CURVE,p,p,p)); p = Point3(w2, -l2, 0.0f); spline->AddKnot(SplineKnot(KTYPE_CORNER,LTYPE_CURVE,p,p,p)); spline->SetClosed(); spline->ComputeBezPoints(); for(int i = 0; i < 4; ++i) spline->SetKnotType(i, KTYPE_BEZIER_CORNER); } spline->SetClosed(); spline->ComputeBezPoints(); for(int i = 0; i < pts; ++i) spline->SetKnotType(i, KTYPE_BEZIER_CORNER); ashape.UpdateSels(); // Make sure it readies the selection set info ashape.InvalidateGeomCache(); }