18 #include <pxr/base/vt/array.h>
19 #include <pxr/base/vt/types.h>
20 #include <pxr/base/vt/value.h>
21 #include <pxr/usd/sdf/types.h>
23 #include <pxr/usd/usdGeom/curves.h>
25 static bool set_knots(
const pxr::VtDoubleArray &knots,
float *&nu_knots)
32 const size_t num_knots = knots.size();
33 nu_knots =
static_cast<float *
>(
MEM_callocN(num_knots *
sizeof(
float), __func__));
35 for (
size_t i = 0; i < num_knots; i++) {
36 nu_knots[i] = (
float)knots[i];
61 if (
curve_prim_.GetPointsAttr().ValueMightBeTimeVarying()) {
72 pxr::UsdAttribute widthsAttr =
curve_prim_.GetWidthsAttr();
73 pxr::UsdAttribute vertexAttr =
curve_prim_.GetCurveVertexCountsAttr();
74 pxr::UsdAttribute pointsAttr =
curve_prim_.GetPointsAttr();
76 pxr::VtIntArray usdCounts;
77 vertexAttr.Get(&usdCounts, motionSampleTime);
79 pxr::VtVec3fArray usdPoints;
80 pointsAttr.Get(&usdPoints, motionSampleTime);
82 pxr::VtFloatArray usdWidths;
83 widthsAttr.Get(&usdWidths, motionSampleTime);
85 pxr::VtIntArray orders;
86 curve_prim_.GetOrderAttr().Get(&orders, motionSampleTime);
88 pxr::VtDoubleArray knots;
89 curve_prim_.GetKnotsAttr().Get(&knots, motionSampleTime);
91 pxr::VtVec3fArray usdNormals;
92 curve_prim_.GetNormalsAttr().Get(&usdNormals, motionSampleTime);
96 if (!usdNormals.empty()) {
106 for (
size_t i = 0; i < usdCounts.size(); i++) {
107 const int num_verts = usdCounts[i];
116 nu->
pntsu = num_verts;
119 if (i < orders.size()) {
120 nu->
orderu =
static_cast<short>(orders[i]);
129 if (knots.size() > 3) {
130 if ((knots[0] == knots[1]) && (knots[knots.size()] == knots[knots.size() - 1])) {
143 for (
int j = 0; j < nu->
pntsu; j++, bp++, idx++) {
144 bp->
vec[0] = (
float)usdPoints[idx][0];
145 bp->
vec[1] = (
float)usdPoints[idx][1];
146 bp->
vec[2] = (
float)usdPoints[idx][2];
152 if (idx < usdWidths.size()) {
153 radius = usdWidths[idx];
168 const double motionSampleTime,
174 pxr::UsdAttribute widthsAttr =
curve_prim_.GetWidthsAttr();
175 pxr::UsdAttribute vertexAttr =
curve_prim_.GetCurveVertexCountsAttr();
176 pxr::UsdAttribute pointsAttr =
curve_prim_.GetPointsAttr();
178 pxr::VtIntArray usdCounts;
180 vertexAttr.Get(&usdCounts, motionSampleTime);
181 int num_subcurves = usdCounts.size();
183 pxr::VtVec3fArray usdPoints;
184 pointsAttr.Get(&usdPoints, motionSampleTime);
191 bool same_topology = curve_count == num_subcurves;
195 for (curve_idx = 0; nurbs; nurbs = nurbs->
next, curve_idx++) {
196 const int num_in_usd = usdCounts[curve_idx];
197 const int num_in_blender = nurbs->
pntsu;
199 if (num_in_usd != num_in_blender) {
200 same_topology =
false;
206 if (!same_topology) {
212 for (curve_idx = 0; nurbs; nurbs = nurbs->
next, curve_idx++) {
213 const int totpoint = usdCounts[curve_idx];
218 for (
int i = 0; i < totpoint; i++,
point++, vertex_idx++) {
219 point->vec[0] = usdPoints[vertex_idx][0];
220 point->vec[1] = usdPoints[vertex_idx][1];
221 point->vec[2] = usdPoints[vertex_idx][2];
224 else if (nurbs->
bezt) {
227 for (
int i = 0; i < totpoint; i++, bezier++, vertex_idx++) {
228 bezier->
vec[1][0] = usdPoints[vertex_idx][0];
229 bezier->
vec[1][1] = usdPoints[vertex_idx][1];
230 bezier->
vec[1][2] = usdPoints[vertex_idx][2];
typedef float(TangentPoint)[2]
struct Curve * BKE_curve_add(struct Main *bmain, const char *name, int type)
void BKE_nurb_knot_calc_u(struct Nurb *nu)
void BKE_nurbList_free(struct ListBase *lb)
ListBase * BKE_curve_nurbs_get(struct Curve *cu)
struct Mesh * BKE_mesh_new_nomain_from_curve(const struct Object *ob)
General operations, lookup, etc. for blender objects.
struct Object * BKE_object_add_only_object(struct Main *bmain, int type, const char *name) ATTR_RETURNS_NONNULL
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
void add_cache_modifier()
Mesh * read_mesh(struct Mesh *existing_mesh, double motionSampleTime, int read_flag, const char **err_str) override
void read_object_data(Main *bmain, double motionSampleTime) override
pxr::UsdGeomNurbsCurves curve_prim_
void read_curve_sample(Curve *cu, double motionSampleTime)
void create_object(Main *bmain, double motionSampleTime) override
void *(* MEM_callocN)(size_t len, const char *str)
static bool set_knots(const pxr::VtDoubleArray &knots, float *&nu_knots)