Node* ConeModule::evaluate(Context* ctx) { NumberValue* heightValue = dynamic_cast<NumberValue*>(getParameterArgument(ctx,0)); NumberValue* r1Value = dynamic_cast<NumberValue*>(getParameterArgument(ctx,1)); NumberValue* r2Value = dynamic_cast<NumberValue*>(getParameterArgument(ctx,2)); Value* centerValue = getParameterArgument(ctx,3); decimal h=1.0; if(heightValue) h=heightValue->getNumber(); decimal r1=0,r2=0; if(r1Value) r1=r1Value->getNumber(); if(r2Value) r2=r2Value->getNumber(); bool center = false; if(centerValue) center=centerValue->isTrue(); decimal z1,z2; z1 = 0.0; z2 = h; Fragment fg=getSpecialVariables(ctx); decimal r=fmax(r1,r2); int f = fg.getFragments(r); Polygon* p1 = getCircle(r1,f,z1); Polygon* p2 = getCircle(r2,f,z2); QList<Point> c1=p1->getPoints(); QList<Point> c2=p2->getPoints(); PrimitiveNode* p = new PrimitiveNode(); if(r1 > 0) { p->createPolygon(); foreach(Point pt, c1) p->appendVertex(pt); } if(h==0.0) return p; for(int i=0; i<f; i++) { int j=(i+1)%f; if(r1 > 0) { p->createPolygon(); p->appendVertex(c1.at(i)); p->appendVertex(c2.at(i)); p->appendVertex(c1.at(j)); } if(r2 > 0) { p->createPolygon(); p->appendVertex(c2.at(i)); p->appendVertex(c2.at(j)); p->appendVertex(c1.at(j)); } } if(r2 > 0) { p->createPolygon(); foreach(Point pt,c2) p->prependVertex(pt); } if(center) { AlignNode* n=new AlignNode(); n->setCenter(true); n->addChild(p); return n; } return p; }
Node* SphereModule::evaluate(Context* ctx) { NumberValue* rValue=dynamic_cast<NumberValue*>(getParameterArgument(ctx,0)); Value* centerValue=getParameterArgument(ctx,1); bool center=true; if(centerValue) center=centerValue->isTrue(); double r=1.0; if(rValue) { r=rValue->getNumber(); } else { NumberValue* dValue = dynamic_cast<NumberValue*>(ctx->getArgument(0,"diameter")); if(dValue) r=(dValue->getNumber()/2.0); } int f = getFragments(r,ctx); int ringCount=f/2; QList<Polygon> rings; for(int i=0; i<ringCount; i++) { double phi = (M_PI*(i+0.5)) / ringCount; double r2 = r*sin(phi); double z = r*cos(phi)+!center*r; Polygon c = getCircle(r2,f,z); rings.append(c); } PrimitiveNode* p = new PrimitiveNode(); p->createPolygon(); for(int i=0; i<f; i++) p->appendVertex(rings.at(0).at(i)); for(int i = 0; i < ringCount-1; i++) { Polygon r1 = rings.at(i); Polygon r2 = rings.at(i+1); int r1i = 0, r2i = 0; while(r1i < f || r2i < f) { if(r1i >= f) goto next_r2; if(r2i >= f) goto next_r1; if((double)r1i / f < (double)r2i / f) { next_r1: p->createPolygon(); int r1j = (r1i+1) % f; p->prependVertex(r1.at(r1i)); p->prependVertex(r1.at(r1j)); p->prependVertex(r2.at(r2i % f)); r1i++; } else { next_r2: p->createPolygon(); int r2j = (r2i+1) % f; p->appendVertex(r2.at(r2i)); p->appendVertex(r2.at(r2j)); p->appendVertex(r1.at(r1i % f)); r2i++; } } } p->createPolygon(); for(int i=0; i<f; i++) p->prependVertex(rings.at(ringCount-1).at(i)); return p; }
Node* SphereModule::evaluate(Context* ctx) { NumberValue* rValue=dynamic_cast<NumberValue*>(getParameterArgument(ctx,0)); Value* centerValue=getParameterArgument(ctx,1); bool center=true; if(centerValue) center=centerValue->isTrue(); decimal r=0.0; if(rValue) { r=rValue->getNumber(); } else { NumberValue* dValue = dynamic_cast<NumberValue*>(ctx->getArgument(0,"diameter")); if(dValue) r=(dValue->getNumber()/2.0); } if(r==0.0) return new PointNode(); Fragment fg=getSpecialVariables(ctx); int f = fg.getFragments(r); int ringCount=f/2; decimal h=center?0.0:r; QList<Polygon> rings; for(int i=0; i<ringCount; i++) { decimal phi = (M_PI*(i+0.5)) / ringCount; decimal r2 = r*sin(phi); decimal z = r*cos(phi)+h; Polygon* c = getCircle(r2,f,z); rings.append(*c); } PrimitiveNode* p = new PrimitiveNode(); p->createPolygon(); Polygon top=rings.at(0); foreach(Point pt, top.getPoints()) p->appendVertex(pt); for(int i = 0; i < ringCount-1; i++) { QList<Point> r1 = rings.at(i).getPoints(); QList<Point> r2 = rings.at(i+1).getPoints(); int r1i = 0, r2i = 0; while(r1i < f || r2i < f) { if(r2i >= f||(decimal)r1i/f<(decimal)r2i/f) { p->createPolygon(); int r1j = (r1i+1) % f; p->prependVertex(r1.at(r1i)); p->prependVertex(r1.at(r1j)); p->prependVertex(r2.at(r2i % f)); r1i++; } else { p->createPolygon(); int r2j = (r2i+1) % f; p->appendVertex(r2.at(r2i)); p->appendVertex(r2.at(r2j)); p->appendVertex(r1.at(r1i % f)); r2i++; } } } p->createPolygon(); Polygon bottom=rings.at(ringCount-1); foreach(Point pt, bottom.getPoints()) p->prependVertex(pt); if(center) { AlignNode* n=new AlignNode(); n->setCenter(true); n->addChild(p); return n; } return p; }