Blender V5.0
osd.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2024 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#ifdef WITH_OPENSUBDIV
8
9# include "subd/patch.h"
10
11# include "util/unique_ptr.h"
12# include "util/vector.h"
13
14# include <opensubdiv/far/patchMap.h>
15# include <opensubdiv/far/patchTableFactory.h>
16# include <opensubdiv/far/primvarRefiner.h>
17# include <opensubdiv/far/topologyRefinerFactory.h>
18
20
21/* Directly use some OpenSubdiv namespaces for brevity. */
22namespace Far = OpenSubdiv::Far;
23namespace Sdc = OpenSubdiv::Sdc;
24
25class Attribute;
26class Mesh;
27
28/* OpenSubdiv interface for vertex and attribute values. */
29
30template<typename T> struct OsdValue {
31 T value;
32
33 OsdValue() = default;
34
35 void Clear(void *unused = nullptr)
36 {
37 (void)unused;
38 memset((void *)&value, 0, sizeof(T));
39 }
40
41 void AddWithWeight(OsdValue<T> const &src, float weight)
42 {
43 value += src.value * weight;
44 }
45};
46
47/* Wrapper around Mesh for TopologyRefinerFactory. */
48
49class OsdMesh {
50 public:
51 /* Face-varying attribute that requires merging of corners with the same value, typically a UV
52 * map. The resulting topology after merging is stored in a topology refiner fvar channel. The
53 * merged attribute values are stored here, in a generic buffer used for different data types. */
54 struct MergedFVar {
55 const Attribute &attr;
56 int channel = -1;
57 vector<char> values;
58 };
59
60 Mesh &mesh;
61 vector<MergedFVar> merged_fvars;
62
63 explicit OsdMesh(Mesh &mesh) : mesh(mesh) {}
64
65 Sdc::Options sdc_options();
66 bool use_smooth_fvar(const Attribute &attr) const;
67 bool use_smooth_fvar() const;
68};
69
70/* OpenSubdiv refiner and patch data structures. */
71
72struct OsdData {
73 unique_ptr<Far::TopologyRefiner> refiner;
74 unique_ptr<Far::PatchTable> patch_table;
75 unique_ptr<Far::PatchMap> patch_map;
76 vector<OsdValue<float3>> refined_verts;
77
78 void build(OsdMesh &osd_mesh);
79};
80
81/* Patch with OpenSubdiv evaluation. */
82
83struct OsdPatch final : Patch {
84 OsdData &osd_data;
85
86 explicit OsdPatch(OsdData &data) : osd_data(data) {}
87 void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, const float u, const float v)
88 const override;
89};
90
92
93#endif
#define final(a, b, c)
Definition BLI_hash.h:19
struct Mesh Mesh
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert * v
void build(btStridingMeshInterface *triangles, bool useQuantizedAabbCompression, const btVector3 &bvhAabbMin, const btVector3 &bvhAabbMax)
Definition patch.h:12
virtual void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, const float u, float v) const =0
#define CCL_NAMESPACE_END
VecBase< float, 3 > float3
#define N
#define T