22#include <pxr/base/vt/types.h>
24#include <pxr/usd/usdGeom/curves.h>
26static bool set_knots(
const pxr::VtDoubleArray &knots,
float *&nu_knots)
33 const size_t num_knots = knots.size();
34 nu_knots =
static_cast<float *
>(
MEM_callocN(num_knots *
sizeof(
float), __func__));
36 for (
size_t i = 0; i < num_knots; i++) {
37 nu_knots[i] =
float(knots[i]);
62 if (
curve_prim_.GetPointsAttr().ValueMightBeTimeVarying()) {
73 pxr::UsdAttribute widthsAttr =
curve_prim_.GetWidthsAttr();
74 pxr::UsdAttribute vertexAttr =
curve_prim_.GetCurveVertexCountsAttr();
75 pxr::UsdAttribute pointsAttr =
curve_prim_.GetPointsAttr();
77 pxr::VtIntArray usdCounts;
78 vertexAttr.Get(&usdCounts, motionSampleTime);
80 pxr::VtVec3fArray usdPoints;
81 pointsAttr.Get(&usdPoints, motionSampleTime);
83 pxr::VtFloatArray usdWidths;
84 widthsAttr.Get(&usdWidths, motionSampleTime);
86 pxr::VtIntArray orders;
87 curve_prim_.GetOrderAttr().Get(&orders, motionSampleTime);
89 pxr::VtDoubleArray knots;
90 curve_prim_.GetKnotsAttr().Get(&knots, motionSampleTime);
92 pxr::VtVec3fArray usdNormals;
93 curve_prim_.GetNormalsAttr().Get(&usdNormals, motionSampleTime);
97 if (!usdNormals.empty()) {
103 curve_->bevel_radius = 1.0f;
107 for (
size_t i = 0; i < usdCounts.size(); i++) {
108 const int num_verts = usdCounts[i];
117 nu->
pntsu = num_verts;
120 if (i < orders.size()) {
121 nu->
orderu = short(orders[i]);
130 if (knots.size() > 3) {
131 if ((knots[0] == knots[1]) && (knots[knots.size()] == knots[knots.size() - 1])) {
145 for (
int j = 0; j < nu->
pntsu; j++, bp++, idx++) {
146 bp->
vec[0] =
float(usdPoints[idx][0]);
147 bp->
vec[1] =
float(usdPoints[idx][1]);
148 bp->
vec[2] =
float(usdPoints[idx][2]);
154 if (idx < usdWidths.size()) {
155 radius = usdWidths[idx];
171 const char **r_err_str)
174 Mesh *new_mesh = read_mesh(
nullptr,
params, r_err_str);
178Mesh *USDNurbsReader::read_mesh(
Mesh * ,
182 pxr::UsdGeomCurves curve_prim(
prim_);
184 pxr::UsdAttribute widthsAttr = curve_prim.GetWidthsAttr();
185 pxr::UsdAttribute vertexAttr = curve_prim.GetCurveVertexCountsAttr();
186 pxr::UsdAttribute pointsAttr = curve_prim.GetPointsAttr();
188 pxr::VtIntArray usdCounts;
190 vertexAttr.Get(&usdCounts,
params.motion_sample_time);
191 int num_subcurves = usdCounts.size();
193 pxr::VtVec3fArray usdPoints;
194 pointsAttr.Get(&usdPoints,
params.motion_sample_time);
201 bool same_topology = curve_count == num_subcurves;
205 for (curve_idx = 0; nurbs; nurbs = nurbs->
next, curve_idx++) {
206 const int num_in_usd = usdCounts[curve_idx];
207 const int num_in_blender = nurbs->
pntsu;
209 if (num_in_usd != num_in_blender) {
210 same_topology =
false;
216 if (!same_topology) {
222 for (curve_idx = 0; nurbs; nurbs = nurbs->
next, curve_idx++) {
223 const int totpoint = usdCounts[curve_idx];
228 for (
int i = 0; i < totpoint; i++,
point++, vertex_idx++) {
229 point->vec[0] = usdPoints[vertex_idx][0];
230 point->vec[1] = usdPoints[vertex_idx][1];
231 point->vec[2] = usdPoints[vertex_idx][2];
234 else if (nurbs->
bezt) {
237 for (
int i = 0; i < totpoint; i++, bezier++, vertex_idx++) {
238 bezier->vec[1][0] = usdPoints[vertex_idx][0];
239 bezier->vec[1][1] = usdPoints[vertex_idx][1];
240 bezier->vec[1][2] = usdPoints[vertex_idx][2];
ListBase * BKE_curve_nurbs_get(Curve *cu)
void BKE_nurb_knot_calc_u(Nurb *nu)
void BKE_nurbList_free(ListBase *lb)
Curve * BKE_curve_add(Main *bmain, const char *name, int type)
Mesh * BKE_mesh_new_nomain_from_curve(const Object *ob)
General operations, lookup, etc. for blender objects.
Object * BKE_object_add_only_object(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)
struct BezTriple BezTriple
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 Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture 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()
void read_geometry(bke::GeometrySet &geometry_set, USDMeshReadParams params, const char **r_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
draw_view in_light_buf[] float
void *(* MEM_callocN)(size_t len, const char *str)
void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
static bool set_knots(const pxr::VtDoubleArray &knots, float *&nu_knots)