25 #ifndef HBRSUBDIVISION_H
26 #define HBRSUBDIVISION_H
28 #include "../version.h"
30 namespace OpenSubdiv {
31 namespace OPENSUBDIV_VERSION {
33 template <
class T>
class HbrFace;
34 template <
class T>
class HbrVertex;
35 template <
class T>
class HbrHalfedge;
36 template <
class T>
class HbrMesh;
37 template <
class T>
class HbrSubdivision {
122 SmoothSubdivisionVertexOperator(T* data,
bool meshHasEdits,
float weight)
124 m_meshHasEdits(meshHasEdits),
130 if (m_meshHasEdits) {
133 m_data->AddWithWeight(vertex.
GetData(), m_weight);
137 const bool m_meshHasEdits;
138 const float m_weight;
142 class CreaseSubdivisionHalfedgeOperator :
public HbrHalfedgeOperator<T> {
144 CreaseSubdivisionHalfedgeOperator(HbrVertex<T> *vertex, T* data,
bool meshHasEdits,
bool next,
float weight)
147 m_meshHasEdits(meshHasEdits),
153 virtual void operator() (HbrHalfedge<T> &edge) {
154 if (m_count < 2 && edge.IsSharp(m_next)) {
155 HbrVertex<T>* a = edge.GetDestVertex();
156 if (a == m_vertex) a = edge.GetOrgVertex();
158 if (m_meshHasEdits) {
159 a->GuaranteeNeighbors();
161 m_data->AddWithWeight(a->GetData(), m_weight);
166 HbrVertex<T>* m_vertex;
168 const bool m_meshHasEdits;
170 const float m_weight;
176 class RefineFaceAtVertexOperator :
public HbrFaceOperator<T> {
178 RefineFaceAtVertexOperator(HbrSubdivision<T>* subdivision, HbrMesh<T>* mesh, HbrVertex<T> *vertex)
179 : m_subdivision(subdivision),
184 virtual void operator() (HbrFace<T> &face) {
185 m_subdivision->RefineFaceAtVertex(m_mesh, &face, m_vertex);
188 HbrSubdivision<T>*
const m_subdivision;
189 HbrMesh<T>*
const m_mesh;
190 HbrVertex<T>*
const m_vertex;
198 GuaranteeNeighbors(mesh, vertex);
199 RefineFaceAtVertexOperator op(
this, mesh, vertex);
219 float childsharp = 0.0f;
228 ChaikinEdgeCreaseOperator(
230 m_edge(edge), m_childsharp(childsharp), m_count(count) { }
235 if ((&edge==m_edge) || (&edge==m_edge->
GetOpposite()))
245 float & m_childsharp;
249 ChaikinEdgeCreaseOperator op(edge, childsharp, n);
254 childsharp = childsharp * 0.25f / float(n);
258 childsharp += sharpness * 0.75f;
261 childsharp = (float) HbrHalfedge<T>::k_Smooth;
268 sharpness = (float) HbrHalfedge<T>::k_Smooth;
277 SmoothSubdivisionVertexOperator op(data, mesh->
HasVertexEdits(), weight);
284 CreaseSubdivisionHalfedgeOperator op(vertex, data, mesh->
HasVertexEdits(), next, weight);
289 using namespace OPENSUBDIV_VERSION;
bool HasVertexEdits() const
void GuaranteeNeighbors()
virtual void GuaranteeNeighbor(HbrMesh< T > *mesh, HbrHalfedge< T > *edge)=0
virtual int GetFaceChildrenCount(int nvertices) const =0
void ApplyOperatorSurroundingVertices(HbrVertexOperator< T > &op) const
virtual void Refine(HbrMesh< T > *mesh, HbrFace< T > *face)=0
void SubdivideCreaseWeight(HbrHalfedge< T > *edge, HbrVertex< T > *vertex, HbrHalfedge< T > *subedge)
float GetSharpness() const
virtual void GuaranteeNeighbors(HbrMesh< T > *mesh, HbrVertex< T > *vertex)=0
void SetCreaseSubdivisionMethod(CreaseSubdivision method)
virtual HbrFace< T > * RefineFaceAtVertex(HbrMesh< T > *mesh, HbrFace< T > *face, HbrVertex< T > *vertex)=0
void SetSharpness(float sharp)
virtual bool FaceIsExtraordinary(HbrMesh< T > const *, HbrFace< T > *)
virtual bool HasLimit(HbrMesh< T > *, HbrVertex< T > *)
virtual HbrSubdivision< T > * Clone() const =0
CreaseSubdivision GetCreaseSubdivisionMethod() const
void AddCreaseEdgesWithWeight(HbrMesh< T > *mesh, HbrVertex< T > *vertex, bool next, float weight, T *data)
HbrHalfedge< T > * GetOpposite() const
virtual HbrVertex< T > * Subdivide(HbrMesh< T > *mesh, HbrFace< T > *face)=0
void ApplyOperatorSurroundingFaces(HbrFaceOperator< T > &op) const
void ApplyOperatorSurroundingEdges(HbrHalfedgeOperator< T > &op) const
CreaseSubdivision creaseSubdivision
virtual void RefineAtVertex(HbrMesh< T > *mesh, HbrVertex< T > *vertex)
void AddSurroundingVerticesWithWeight(HbrMesh< T > *mesh, HbrVertex< T > *vertex, float weight, T *data)
virtual bool HasLimit(HbrMesh< T > *, HbrFace< T > *)
virtual bool VertexIsExtraordinary(HbrMesh< T > const *, HbrVertex< T > *)
virtual bool HasLimit(HbrMesh< T > *, HbrHalfedge< T > *)