diff --git a/inc/hgl/graph/InlineGeometry.h b/inc/hgl/graph/InlineGeometry.h
index 87cf4b54..935d1a56 100644
--- a/inc/hgl/graph/InlineGeometry.h
+++ b/inc/hgl/graph/InlineGeometry.h
@@ -48,9 +48,9 @@ namespace hgl
{
Vector2f center; ///<圆心坐标
Vector2f radius; ///<半径
- uint field_count=8; ///<分段次数
+ uint field_count=8; ///<分段数量
- bool has_color =false;
+ bool has_center; ///<是否有圆心点
Vector4f center_color; ///<圆心颜色
Vector4f border_color; ///<边缘颜色
@@ -59,7 +59,17 @@ namespace hgl
/**
* 创建一个2D圆形(扇形/线圈)
*/
- Primitive *CreateCircle(PrimitiveCreater *pc,const CircleCreateInfo *cci);
+ Primitive *CreateCircle2D(PrimitiveCreater *pc,const CircleCreateInfo *cci);
+
+ /**
+ * 创建一个3D圆形(扇形/圆形,XY,Z永远为0)
+ */
+ Primitive *CreateCircle3D(PrimitiveCreater *pc,const CircleCreateInfo *cci);
+
+ /**
+ * 创建一个使用三角形绘制的3D圆形(扇形/圆形,XY,Z永远为0)
+ */
+ Primitive *CreateCircle3DByIndexTriangles(PrimitiveCreater *pc,const CircleCreateInfo *cci);
/**
* 平面网格创建信息
diff --git a/src/SceneGraph/InlineGeometry.cpp b/src/SceneGraph/InlineGeometry.cpp
index c9b4ac0c..0085b7af 100644
--- a/src/SceneGraph/InlineGeometry.cpp
+++ b/src/SceneGraph/InlineGeometry.cpp
@@ -113,14 +113,14 @@ namespace hgl
return pc->Create();
}
- Primitive *CreateCircle(PrimitiveCreater *pc,const CircleCreateInfo *cci)
+ Primitive *CreateCircle2D(PrimitiveCreater *pc,const CircleCreateInfo *cci)
{
if(!pc)return(nullptr);
uint edge;
uint vertex_count;
- if(cci->has_color)
+ if(cci->has_center)
{
edge=cci->field_count+1;
vertex_count=cci->field_count+2;
@@ -139,13 +139,12 @@ namespace hgl
if(!vertex.IsValid())
return(nullptr);
- if(cci->has_color)
+ if(cci->has_center)
{
- if(!color.IsValid())
- return(nullptr);
-
vertex->Write(cci->center);
- color->Write(cci->center_color);
+
+ if(color.IsValid())
+ color->Write(cci->center_color);
}
for(uint i=0;iWrite(x,y);
- if(cci->has_color)
+ if(color.IsValid())
color->Write(cci->border_color);
}
return pc->Create();
}
+
+ template
+ void WriteIBO(T *p,const T start,const T count)
+ {
+ for(T i=start;ihas_center)
+ {
+ edge=cci->field_count+1;
+ vertex_count=cci->field_count+2;
+ }
+ else
+ {
+ edge=cci->field_count;
+ vertex_count=cci->field_count;
+ }
+
+ bool has_index=pc->hasIndex();
+
+ if(!pc->Init("Circle",vertex_count,has_index?vertex_count:0))return(nullptr);
+
+ VABMap3f vertex(pc->GetVABMap(VAN::Position));
+ VABMap4f color(pc->GetVABMap(VAN::Color));
+ VABMap3f normal(pc->GetVABMap(VAN::Normal));
+
+ if(!vertex.IsValid())
+ return(nullptr);
+
+ if(cci->has_center)
+ {
+ vertex->Write(cci->center.x,cci->center.y,0);
+
+ if(color.IsValid())
+ color->Write(cci->center_color);
+
+ if(normal.IsValid())
+ normal->Write(AxisVector::Z);
+ }
+
+ for(uint i=0;ifield_count)*360.0f;
+
+ float x=cci->center.x+sin(deg2rad(ang))*cci->radius.x;
+ float y=cci->center.y+cos(deg2rad(ang))*cci->radius.y;
+
+ vertex->Write(x,y,0);
+
+ if(color.IsValid())
+ color->Write(cci->border_color);
+
+ if(normal.IsValid())
+ normal->Write(AxisVector::Z);
+ }
+
+ if(has_index)
+ {
+ IBMap *ib_map=pc->GetIBMap();
+
+ if(pc->GetIndexType()==IndexType::U16)WriteIBO((uint16 *)(ib_map->Map()),0,vertex_count);else
+ if(pc->GetIndexType()==IndexType::U32)WriteIBO((uint32 *)(ib_map->Map()),0,vertex_count);else
+ if(pc->GetIndexType()==IndexType::U8 )WriteIBO((uint8 *)(ib_map->Map()),0,vertex_count);
+
+ ib_map->Unmap();
+ }
+
+ return pc->Create();
+ }
+
+ template
+ void WriteCircleIBO(T *ibo,const uint edge_count)
+ {
+ T *p=ibo;
+
+ for(T i=1;ifield_count;
+ index_count=(vertex_count-2)*3;
+
+ if(!pc->Init("Circle",vertex_count,index_count))return(nullptr);
+
+ VABMap3f vertex(pc->GetVABMap(VAN::Position));
+ VABMap4f color(pc->GetVABMap(VAN::Color));
+ VABMap3f normal(pc->GetVABMap(VAN::Normal));
+
+ if(!vertex.IsValid())
+ return(nullptr);
+
+ for(uint i=0;ifield_count+1;i++)
+ {
+ float ang=float(i)/float(cci->field_count)*360.0f;
+
+ float x=cci->center.x+sin(deg2rad(ang))*cci->radius.x;
+ float y=cci->center.y+cos(deg2rad(ang))*cci->radius.y;
+
+ vertex->Write(x,y,0);
+
+ if(color.IsValid())
+ color->Write(cci->border_color);
+
+ if(normal.IsValid())
+ normal->Write(AxisVector::Z);
+ }
+
+ {
+ IBMap *ib_map=pc->GetIBMap();
+
+ if(pc->GetIndexType()==IndexType::U16)WriteCircleIBO((uint16 *)(ib_map->Map()),cci->field_count);else
+ if(pc->GetIndexType()==IndexType::U32)WriteCircleIBO((uint32 *)(ib_map->Map()),cci->field_count);else
+ if(pc->GetIndexType()==IndexType::U8 )WriteCircleIBO((uint8 *)(ib_map->Map()),cci->field_count);
+
+ ib_map->Unmap();
+ }
+
+ return pc->Create();
+ }
Primitive *CreatePlaneGrid2D(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci)
{