Blender V5.3
hydra/mesh.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 NVIDIA Corporation
2 * SPDX-FileCopyrightText: 2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: Apache-2.0 */
5
6#include "hydra/mesh.h"
7#include "hydra/geometry.inl"
8#include "hydra/util.h"
9#include "scene/mesh.h"
10
11#include <pxr/base/gf/vec2f.h>
12#include <pxr/imaging/hd/geomSubsetSchema.h>
13#include <pxr/imaging/hd/legacyDisplayStyleSchema.h>
14#include <pxr/imaging/hd/materialBindingSchema.h>
15#include <pxr/imaging/hd/materialBindingsSchema.h>
16#include <pxr/imaging/hd/meshSchema.h>
17#include <pxr/imaging/hd/meshTopologySchema.h>
18#include <pxr/imaging/hd/sceneIndex.h>
19#include <pxr/imaging/hd/subdivisionTagsSchema.h>
20
22
23namespace {
24
25template<typename T>
26VtValue ComputeTriangulatedUniformPrimvar(VtValue value, const VtIntArray &primitiveParams)
27{
28 T output;
29 output.reserve(primitiveParams.size());
30 const T &input = value.Get<T>();
31
32 for (size_t i = 0; i < primitiveParams.size(); ++i) {
33 const int faceIndex = HdMeshUtil::DecodeFaceIndexFromCoarseFaceParam(primitiveParams[i]);
34
35 output.push_back(input[faceIndex]);
36 }
37
38 return VtValue(output);
39}
40
42 const HdType valueType,
43 const VtIntArray &primitiveParams)
44{
45 switch (valueType) {
46 case HdTypeFloat:
47 return ComputeTriangulatedUniformPrimvar<VtFloatArray>(value, primitiveParams);
48 case HdTypeFloatVec2:
49 return ComputeTriangulatedUniformPrimvar<VtVec2fArray>(value, primitiveParams);
50 case HdTypeFloatVec3:
51 return ComputeTriangulatedUniformPrimvar<VtVec3fArray>(value, primitiveParams);
52 case HdTypeFloatVec4:
53 return ComputeTriangulatedUniformPrimvar<VtVec4fArray>(value, primitiveParams);
54 default:
55 TF_RUNTIME_ERROR("Unsupported attribute type %d", static_cast<int>(valueType));
56 return VtValue();
57 }
58}
59
61 const HdType valueType,
62 HdMeshUtil &meshUtil)
63{
64 if (meshUtil.ComputeTriangulatedFaceVaryingPrimvar(
65 HdGetValueData(value), value.GetArraySize(), valueType, &value)
66#if PXR_VERSION >= 2511
67 != HdMeshComputationResult::Error
68#endif
69 )
70 {
71 return value;
72 }
73
74 return VtValue();
75}
76
77} // namespace
78
79Transform convert_transform(const GfMatrix4d &matrix)
80{
81 return make_transform(matrix[0][0],
82 matrix[1][0],
83 matrix[2][0],
84 matrix[3][0],
85 matrix[0][1],
86 matrix[1][1],
87 matrix[2][1],
88 matrix[3][1],
89 matrix[0][2],
90 matrix[1][2],
91 matrix[2][2],
92 matrix[3][2]);
93}
94
95HdCyclesMesh::HdCyclesMesh(const SdfPath &rprimId)
96 : HdCyclesGeometry(rprimId), _util(&_topology, rprimId)
97{
98}
99
101
103{
105 bits |= HdChangeTracker::DirtyPoints | HdChangeTracker::DirtyNormals |
106 HdChangeTracker::DirtyPrimvar | HdChangeTracker::DirtyTopology |
107 HdChangeTracker::DirtyDisplayStyle | HdChangeTracker::DirtySubdivTags;
108 return bits;
109}
110
111HdDirtyBits HdCyclesMesh::_PropagateDirtyBits(HdDirtyBits bits) const
112{
113 if (bits & (HdChangeTracker::DirtyMaterialId)) {
114 // Update used shaders from geometry subsets if any exist in the topology
115 bits |= HdChangeTracker::DirtyTopology;
116 }
117
118 if (bits & (HdChangeTracker::DirtyTopology | HdChangeTracker::DirtyDisplayStyle |
119 HdChangeTracker::DirtySubdivTags))
120 {
121 // Do full topology update when display style or subdivision changes
122 bits |= HdChangeTracker::DirtyTopology | HdChangeTracker::DirtyDisplayStyle |
123 HdChangeTracker::DirtySubdivTags;
124 }
125
126 if (bits & (HdChangeTracker::DirtyTopology)) {
127 // Changing topology clears the geometry, so need to populate everything again
128 bits |= HdChangeTracker::DirtyPoints | HdChangeTracker::DirtyNormals |
129 HdChangeTracker::DirtyPrimvar;
130 }
131
132 return bits;
133}
134
135void HdCyclesMesh::Populate(HdSceneDelegate *sceneDelegate, HdDirtyBits dirtyBits, bool &rebuild)
136{
137 if (HdChangeTracker::IsTopologyDirty(dirtyBits, GetId())) {
138 PopulateTopology(sceneDelegate);
139 }
140
141 if (dirtyBits & HdChangeTracker::DirtyPoints) {
142 PopulatePoints(sceneDelegate);
143 }
144
145 // Must happen after topology update, so that normals attribute size can be calculated
146 if (dirtyBits & HdChangeTracker::DirtyNormals) {
147 PopulateNormals(sceneDelegate);
148 }
149
150 // Must happen after topology update, so that appropriate attribute set can be selected
151 if (dirtyBits & HdChangeTracker::DirtyPrimvar) {
152 PopulatePrimvars(sceneDelegate);
153 }
154
155 rebuild = (_geom->triangles_is_modified()) || (_geom->subd_start_corner_is_modified()) ||
156 (_geom->subd_num_corners_is_modified()) || (_geom->subd_shader_is_modified()) ||
157 (_geom->subd_smooth_is_modified()) || (_geom->subd_ptex_offset_is_modified()) ||
158 (_geom->subd_face_corners_is_modified());
159}
160
161void HdCyclesMesh::PopulatePoints(HdSceneDelegate *sceneDelegate)
162{
163 const HdSceneIndexPrim prim = GetPrim(sceneDelegate, GetId());
164 const HdPrimvarsSchema primvars = HdPrimvarsSchema::GetFromParent(prim.dataSource);
165 const VtValue value = ReadPrimvar(primvars, HdTokens->points);
166
167 if (!value.IsHolding<VtVec3fArray>()) {
168 TF_WARN("Invalid points data for %s", GetId().GetText());
169 return;
170 }
171
172 const auto &points = value.UncheckedGet<VtVec3fArray>();
173
174 TF_VERIFY(points.size() >= static_cast<size_t>(_topology.GetNumPoints()));
175
176 const bool subdivision = _geom->get_subdivision_type() != Mesh::SUBDIVISION_NONE;
177 AttributeSet &attributes = (subdivision) ? _geom->subd_attributes : _geom->attributes;
178 Attribute *attr_P = attributes.add(ATTR_STD_POSITION);
179 packed_float3 *verts = attr_P->data_for_write<packed_float3>();
180
181 std::copy_n(
182 reinterpret_cast<const packed_float3 *>(points.data()), _topology.GetNumPoints(), verts);
183 _geom->tag_position_modified();
184}
185
186void HdCyclesMesh::PopulateNormals(HdSceneDelegate *sceneDelegate)
187{
188 _geom->attributes.remove(ATTR_STD_VERTEX_NORMAL);
189
190 // Authored normals should only exist on triangle meshes
191 if (_geom->get_subdivision_type() != Mesh::SUBDIVISION_NONE) {
192 return;
193 }
194
195 const HdSceneIndexPrim prim = GetPrim(sceneDelegate, GetId());
196 const HdPrimvarsSchema primvars = HdPrimvarsSchema::GetFromParent(prim.dataSource);
197 const HdInterpolation interpolation = ReadPrimvarInterpolation(primvars, HdTokens->normals);
198 if (interpolation == HdInterpolationCount) {
199 return; // Ignore missing normals
200 }
201 const VtValue value = ReadPrimvar(primvars, HdTokens->normals);
202
203 if (!value.IsHolding<VtVec3fArray>()) {
204 TF_WARN("Invalid normals data for %s", GetId().GetText());
205 return;
206 }
207
208 const auto &normals = value.UncheckedGet<VtVec3fArray>();
209
210 if (interpolation == HdInterpolationConstant) {
211 TF_VERIFY(normals.size() == 1);
212
213 const GfVec3f constantNormal = normals[0];
214
215 packed_normal *const N =
216 _geom->attributes.add(ATTR_STD_VERTEX_NORMAL)->data_for_write<packed_normal>();
217 for (size_t i = 0; i < _geom->num_verts(); ++i) {
218 N[i] = packed_normal(make_float3(constantNormal[0], constantNormal[1], constantNormal[2]));
219 }
220 }
221 else if (interpolation == HdInterpolationUniform) {
222 TF_VERIFY(normals.size() == static_cast<size_t>(_topology.GetNumFaces()));
223 /* Nothing to do, face normals are computed on demand in the kernel. */
224 }
225 else if (interpolation == HdInterpolationVertex || interpolation == HdInterpolationVarying) {
226 TF_VERIFY(normals.size() == static_cast<size_t>(_topology.GetNumPoints()) &&
227 static_cast<size_t>(_topology.GetNumPoints()) == _geom->num_verts());
228
229 packed_normal *const N =
230 _geom->attributes.add(ATTR_STD_VERTEX_NORMAL)->data_for_write<packed_normal>();
231 for (size_t i = 0; i < _geom->num_verts(); ++i) {
232 N[i] = packed_normal(make_float3(normals[i][0], normals[i][1], normals[i][2]));
233 }
234 }
235 else if (interpolation == HdInterpolationFaceVarying) {
236 TF_VERIFY(normals.size() == static_cast<size_t>(_topology.GetNumFaceVaryings()));
237
238 // TODO: Cycles has no per-corner normals, so ignore until supported.
239#if 0
240 if (!_util.ComputeTriangulatedFaceVaryingPrimvar(
241 normals.data(), normals.size(), HdTypeFloatVec3, &value))
242 {
243 return;
244 }
245
246 const auto &normalsTriangulated = value.UncheckedGet<VtVec3fArray>();
247#endif
248 }
249}
250
251void HdCyclesMesh::PopulatePrimvars(HdSceneDelegate *sceneDelegate)
252{
253 Scene *const scene = (Scene *)_geom->get_owner();
254
255 const bool subdivision = _geom->get_subdivision_type() != Mesh::SUBDIVISION_NONE;
256 AttributeSet &attributes = subdivision ? _geom->subd_attributes : _geom->attributes;
257
258 const HdSceneIndexPrim prim = GetPrim(sceneDelegate, GetId());
259 const HdPrimvarsSchema primvars = HdPrimvarsSchema::GetFromParent(prim.dataSource);
260
261 const std::pair<HdInterpolation, AttributeElement> interpolations[] = {
262 std::make_pair(HdInterpolationFaceVarying, ATTR_ELEMENT_CORNER),
263 std::make_pair(HdInterpolationUniform, ATTR_ELEMENT_FACE),
264 std::make_pair(HdInterpolationVertex, ATTR_ELEMENT_VERTEX),
265 std::make_pair(HdInterpolationVarying, ATTR_ELEMENT_VERTEX),
266 std::make_pair(HdInterpolationConstant, ATTR_ELEMENT_OBJECT),
267 };
268
269 for (const auto &interpolation : interpolations) {
270 for (const TfToken &primvarName : PrimvarNamesAtInterpolation(primvars, interpolation.first)) {
271 // Skip special primvars that are handled separately
272 if (primvarName == HdTokens->points || primvarName == HdTokens->normals) {
273 continue;
274 }
275
276 VtValue value = ReadPrimvar(primvars, primvarName);
277 if (value.IsEmpty()) {
278 continue;
279 }
280
281 const TfToken role = ReadPrimvarRole(primvars, primvarName);
282 const ustring name(primvarName.GetString());
283
285 if (role == HdPrimvarRoleTokens->textureCoordinate) {
286 std = ATTR_STD_UV;
287 }
288 else if (interpolation.first == HdInterpolationVertex) {
289 if (primvarName == HdTokens->displayColor || role == HdPrimvarRoleTokens->color) {
291 }
292 else if (primvarName == HdTokens->normals) {
294 }
295 }
296 else if (primvarName == HdTokens->displayColor &&
297 interpolation.first == HdInterpolationConstant)
298 {
299 if (value.IsHolding<VtVec3fArray>() && value.GetArraySize() == 1) {
300 const GfVec3f color = value.UncheckedGet<VtVec3fArray>()[0];
301 _instances[0]->set_color(make_float3(color[0], color[1], color[2]));
302 }
303 }
304
305 // Skip attributes that are not needed
306 if ((std != ATTR_STD_NONE && _geom->need_attribute(scene, std)) ||
307 _geom->need_attribute(scene, name))
308 {
309 const HdType valueType = HdGetValueTupleType(value).type;
310
311 if (!subdivision) {
312 // Adjust attributes for polygons that were triangulated
313 if (interpolation.first == HdInterpolationUniform) {
314 value = ComputeTriangulatedUniformPrimvar(value, valueType, _primitiveParams);
315 if (value.IsEmpty()) {
316 continue;
317 }
318 }
319 else if (interpolation.first == HdInterpolationFaceVarying) {
320 value = ComputeTriangulatedFaceVaryingPrimvar(value, valueType, _util);
321 if (value.IsEmpty()) {
322 continue;
323 }
324 }
325 }
326
327 ApplyPrimvars(attributes, name, value, interpolation.second, std);
328 }
329 }
330 }
331}
332
333void HdCyclesMesh::PopulateTopology(HdSceneDelegate *sceneDelegate)
334{
335 // Clear geometry before populating it again with updated topology
336 _geom->clear(true);
337
338 const HdSceneIndexPrim prim = GetPrim(sceneDelegate, GetId());
339 const HdLegacyDisplayStyleSchema displayStyleSchema = HdLegacyDisplayStyleSchema::GetFromParent(
340 prim.dataSource);
341
342 int refineLevel = 0;
343 if (auto ds = displayStyleSchema.GetRefineLevel()) {
344 refineLevel = ds->GetTypedValue(0.0f);
345 }
346 bool flatShadingEnabled = false;
347 if (auto ds = displayStyleSchema.GetFlatShadingEnabled()) {
348 flatShadingEnabled = ds->GetTypedValue(0.0f);
349 }
350
351 const HdMeshSchema meshSchema = HdMeshSchema::GetFromParent(prim.dataSource);
352 const HdMeshTopologySchema topoSchema = meshSchema.GetTopology();
353
354 TfToken scheme = PxOsdOpenSubdivTokens->none;
355 if (auto ds = meshSchema.GetSubdivisionScheme()) {
356 scheme = ds->GetTypedValue(0.0f);
357 }
358 TfToken orientation = HdTokens->rightHanded;
359 if (auto ds = topoSchema.GetOrientation()) {
360 orientation = ds->GetTypedValue(0.0f);
361 }
362 VtIntArray faceVertexCounts;
363 if (auto ds = topoSchema.GetFaceVertexCounts()) {
364 faceVertexCounts = ds->GetTypedValue(0.0f);
365 }
366 VtIntArray faceVertexIndices;
367 if (auto ds = topoSchema.GetFaceVertexIndices()) {
368 faceVertexIndices = ds->GetTypedValue(0.0f);
369 }
370 VtIntArray holeIndices;
371 if (auto ds = topoSchema.GetHoleIndices()) {
372 holeIndices = ds->GetTypedValue(0.0f);
373 }
374
375 _topology = HdMeshTopology(
376 scheme, orientation, faceVertexCounts, faceVertexIndices, holeIndices, refineLevel);
377
378 /* Geom subsets are published as child prims of the mesh in the scene index. */
379 HdGeomSubsets geomSubsetsList;
380 if (HdSceneIndexBaseRefPtr si = sceneDelegate->GetRenderIndex().GetTerminalSceneIndex()) {
381 for (const SdfPath &childPath : si->GetChildPrimPaths(GetId())) {
382 const HdSceneIndexPrim childPrim = si->GetPrim(childPath);
383 if (childPrim.primType != HdPrimTypeTokens->geomSubset) {
384 continue;
385 }
386 const HdGeomSubsetSchema subsetSchema = HdGeomSubsetSchema::GetFromParent(
387 childPrim.dataSource);
388 /* Only face subsets supported here, not point or curve subsets. */
389 if (auto typeDs = subsetSchema.GetType()) {
390 if (typeDs->GetTypedValue(0.0f) != HdGeomSubsetSchemaTokens->typeFaceSet) {
391 continue;
392 }
393 }
394 HdGeomSubset subset;
395 subset.type = HdGeomSubset::TypeFaceSet;
396 if (auto ds = subsetSchema.GetIndices()) {
397 subset.indices = ds->GetTypedValue(0.0f);
398 }
399 if (auto pathDs = HdMaterialBindingsSchema::GetFromParent(childPrim.dataSource)
400 .GetMaterialBinding()
401 .GetPath())
402 {
403 subset.materialId = pathDs->GetTypedValue(0.0f);
404 }
405 geomSubsetsList.push_back(subset);
406 }
407 }
408 _topology.SetGeomSubsets(geomSubsetsList);
409
410 const TfToken subdivScheme = _topology.GetScheme();
411 if (subdivScheme == PxOsdOpenSubdivTokens->bilinear && _topology.GetRefineLevel() > 0) {
412 _geom->set_subdivision_type(Mesh::SUBDIVISION_LINEAR);
413 }
414 else if (subdivScheme == PxOsdOpenSubdivTokens->catmullClark && _topology.GetRefineLevel() > 0) {
415 _geom->set_subdivision_type(Mesh::SUBDIVISION_CATMULL_CLARK);
416 }
417 else {
418 _geom->set_subdivision_type(Mesh::SUBDIVISION_NONE);
419 }
420
421 const bool smooth = !flatShadingEnabled;
422 const bool subdivision = _geom->get_subdivision_type() != Mesh::SUBDIVISION_NONE;
423
424 // Initialize lookup table from polygon face to material shader index
425 VtIntArray faceShaders(_topology.GetNumFaces(), 0);
426
427 const HdGeomSubsets &geomSubsets = _topology.GetGeomSubsets();
428 if (!geomSubsets.empty()) {
429 array<Node *> usedShaders = std::move(_geom->get_used_shaders());
430 // Remove any previous materials except for the material assigned to the prim
431 usedShaders.resize(1);
432
433 std::unordered_map<SdfPath, int, SdfPath::Hash> materials;
434
435 for (const HdGeomSubset &geomSubset : geomSubsets) {
436 TF_VERIFY(geomSubset.type == HdGeomSubset::TypeFaceSet);
437
438 int shader = 0;
439 const auto it = materials.find(geomSubset.materialId);
440 if (it != materials.end()) {
441 shader = it->second;
442 }
443 else {
444 const auto *const material = static_cast<const HdCyclesMaterial *>(
445 sceneDelegate->GetRenderIndex().GetSprim(HdPrimTypeTokens->material,
446 geomSubset.materialId));
447
448 if (material && material->GetCyclesShader()) {
449 shader = static_cast<int>(usedShaders.size());
450 usedShaders.push_back_slow(material->GetCyclesShader());
451
452 materials.emplace(geomSubset.materialId, shader);
453 }
454 }
455
456 for (const int face : geomSubset.indices) {
457 faceShaders[face] = shader;
458 }
459 }
460
461 _geom->set_used_shaders(usedShaders);
462 }
463
464 const VtIntArray vertIndx = _topology.GetFaceVertexIndices();
465 const VtIntArray vertCounts = _topology.GetFaceVertexCounts();
466
467 if (!subdivision) {
468 VtVec3iArray triangles;
469 _util.ComputeTriangleIndices(&triangles, &_primitiveParams);
470
471 _geom->resize_mesh(_topology.GetNumPoints(), triangles.size());
472
473 int *geom_indices = _geom->get_triangles().data();
474 for (size_t i = 0; i < _primitiveParams.size(); ++i) {
475 const GfVec3i triangle = triangles[i];
476 geom_indices[i * 3 + 0] = triangle[0];
477 geom_indices[i * 3 + 1] = triangle[1];
478 geom_indices[i * 3 + 2] = triangle[2];
479 }
480
481 int *shader = _geom->get_shader().data();
482 for (size_t i = 0; i < _primitiveParams.size(); ++i) {
483 const int faceIndex = HdMeshUtil::DecodeFaceIndexFromCoarseFaceParam(_primitiveParams[i]);
484 shader[i] = faceShaders[faceIndex];
485 }
486
487 std::ranges::fill(_geom->get_smooth(), smooth);
488
489 _geom->tag_triangles_modified();
490 _geom->tag_shader_modified();
491 _geom->tag_smooth_modified();
492 }
493 else {
494 const HdSubdivisionTagsSchema subdivSchema = HdSubdivisionTagsSchema::GetFromParent(
495 prim.dataSource);
496 PxOsdSubdivTags subdivTags;
497 if (auto ds = subdivSchema.GetInterpolateBoundary()) {
498 subdivTags.SetVertexInterpolationRule(ds->GetTypedValue(0.0f));
499 }
500 if (auto ds = subdivSchema.GetFaceVaryingLinearInterpolation()) {
501 subdivTags.SetFaceVaryingInterpolationRule(ds->GetTypedValue(0.0f));
502 }
503 if (auto ds = subdivSchema.GetTriangleSubdivisionRule()) {
504 subdivTags.SetTriangleSubdivision(ds->GetTypedValue(0.0f));
505 }
506 if (auto ds = subdivSchema.GetCornerIndices()) {
507 subdivTags.SetCornerIndices(ds->GetTypedValue(0.0f));
508 }
509 if (auto ds = subdivSchema.GetCornerSharpnesses()) {
510 subdivTags.SetCornerWeights(ds->GetTypedValue(0.0f));
511 }
512 if (auto ds = subdivSchema.GetCreaseIndices()) {
513 subdivTags.SetCreaseIndices(ds->GetTypedValue(0.0f));
514 }
515 if (auto ds = subdivSchema.GetCreaseLengths()) {
516 subdivTags.SetCreaseLengths(ds->GetTypedValue(0.0f));
517 }
518 if (auto ds = subdivSchema.GetCreaseSharpnesses()) {
519 subdivTags.SetCreaseWeights(ds->GetTypedValue(0.0f));
520 }
521 _topology.SetSubdivTags(subdivTags);
522
523 size_t numCorners = 0;
524 for (const int vertCount : vertCounts) {
525 numCorners += vertCount;
526 }
527
528 _geom->resize_subd_faces(_topology.GetNumFaces(), numCorners);
529 _geom->resize_mesh(_topology.GetNumPoints(), 0);
530 Attribute *subd_attr_P = _geom->subd_attributes.add(ATTR_STD_POSITION);
531 subd_attr_P->resize(_topology.GetNumPoints());
532
533 std::copy_n(vertIndx.data(), vertIndx.size(), _geom->get_subd_face_corners().data());
534
535 int *subd_start_corner = _geom->get_subd_start_corner().data();
536 int *subd_num_corners = _geom->get_subd_num_corners().data();
537 int *subd_ptex_offset = _geom->get_subd_ptex_offset().data();
538
539 // TODO: Handle hole indices
540 int ptex_offset = 0;
541 size_t faceIndex = 0;
542 size_t indexOffset = 0;
543 for (const int vertCount : vertCounts) {
544 subd_start_corner[faceIndex] = indexOffset;
545 subd_num_corners[faceIndex] = vertCount;
546 subd_ptex_offset[faceIndex] = ptex_offset;
547 const int num_ptex = (vertCount == 4) ? 1 : vertCount;
548 ptex_offset += num_ptex;
549
550 faceIndex++;
551 indexOffset += vertCount;
552 }
553
554 std::copy_n(faceShaders.data(), faceShaders.size(), _geom->get_subd_shader().data());
555 std::ranges::fill(_geom->get_subd_smooth(), smooth);
556
557 _geom->tag_subd_face_corners_modified();
558 _geom->tag_subd_start_corner_modified();
559 _geom->tag_subd_num_corners_modified();
560 _geom->tag_subd_shader_modified();
561 _geom->tag_subd_smooth_modified();
562 _geom->tag_subd_ptex_offset_modified();
563
564 const VtIntArray creaseLengths = subdivTags.GetCreaseLengths();
565 if (!creaseLengths.empty()) {
566 size_t numCreases = 0;
567 for (const int creaseLength : creaseLengths) {
568 numCreases += creaseLength - 1;
569 }
570
571 _geom->reserve_subd_creases(numCreases);
572
573 const VtIntArray creaseIndices = subdivTags.GetCreaseIndices();
574 const VtFloatArray creaseWeights = subdivTags.GetCreaseWeights();
575
576 indexOffset = 0;
577 size_t creaseLengthOffset = 0;
578 size_t createWeightOffset = 0;
579 for (const int creaseLength : creaseLengths) {
580 for (int j = 0; j < creaseLength - 1; ++j, ++createWeightOffset) {
581 const int v0 = creaseIndices[indexOffset + j];
582 const int v1 = creaseIndices[indexOffset + j + 1];
583
584 const float weight = creaseWeights.size() == creaseLengths.size() ?
585 creaseWeights[creaseLengthOffset] :
586 creaseWeights[createWeightOffset];
587
588 _geom->add_edge_crease(v0, v1, weight);
589 }
590
591 indexOffset += creaseLength;
592 creaseLengthOffset++;
593 }
594
595 const VtIntArray cornerIndices = subdivTags.GetCornerIndices();
596 const VtFloatArray cornerWeights = subdivTags.GetCornerWeights();
597
598 for (size_t i = 0; i < cornerIndices.size(); ++i) {
599 _geom->add_vertex_crease(cornerIndices[i], cornerWeights[i]);
600 }
601 }
602
603 _geom->set_subd_dicing_rate(1.0f);
604 _geom->set_subd_max_level(_topology.GetRefineLevel());
605 _geom->set_subd_objecttoworld(_instances[0]->get_tfm());
606 }
607}
608
609void HdCyclesMesh::Finalize(PXR_NS::HdRenderParam *renderParam)
610{
611 _topology = HdMeshTopology();
612 _primitiveParams.clear();
613
615}
616
blender::float3 packed_float3
#define output
Attribute * add(ustring name, const TypeDesc type, AttributeElement element)
void resize(Geometry *geom, AttributePrimitive prim)
T * data_for_write(const int step=0)
void Finalize(PXR_NS::HdRenderParam *renderParam) override
Definition geometry.inl:187
HdCyclesGeometry(const PXR_NS::SdfPath &rprimId)
Definition geometry.inl:27
PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override
Definition geometry.inl:41
std::vector< CCL_NS::Object * > _instances
PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override
HdCyclesMesh(const PXR_NS::SdfPath &rprimId)
void Finalize(PXR_NS::HdRenderParam *renderParam) override
~HdCyclesMesh() override
@ SUBDIVISION_NONE
Definition scene/mesh.h:114
@ SUBDIVISION_LINEAR
Definition scene/mesh.h:115
@ SUBDIVISION_CATMULL_CLARK
Definition scene/mesh.h:116
size_t size() const
T * resize(const size_t newsize)
void push_back_slow(const T &t)
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define smooth
HDCYCLES_NAMESPACE_OPEN_SCOPE Transform convert_transform(const GfMatrix4d &matrix)
#define HDCYCLES_NAMESPACE_CLOSE_SCOPE
HdInterpolation ReadPrimvarInterpolation(const HdPrimvarsSchema &primvars, const TfToken &name)
TfToken ReadPrimvarRole(const HdPrimvarsSchema &primvars, const TfToken &name)
HDCYCLES_NAMESPACE_OPEN_SCOPE HdSceneIndexPrim GetPrim(HdSceneDelegate *delegate, const SdfPath &id)
TfTokenVector PrimvarNamesAtInterpolation(const HdPrimvarsSchema &primvars, HdInterpolation interpolation)
VtValue ReadPrimvar(const HdPrimvarsSchema &primvars, const TfToken &name)
void ApplyPrimvars(AttributeSet &attributes, const ustring &name, VtValue value, AttributeElement elem, AttributeStandard std)
@ ATTR_ELEMENT_CORNER
@ ATTR_ELEMENT_OBJECT
@ ATTR_ELEMENT_VERTEX
@ ATTR_ELEMENT_FACE
AttributeStandard
@ ATTR_STD_UV
@ ATTR_STD_VERTEX_NORMAL
@ ATTR_STD_NONE
@ ATTR_STD_VERTEX_COLOR
@ ATTR_STD_POSITION
#define N
#define T
VtValue ComputeTriangulatedUniformPrimvar(VtValue value, const VtIntArray &primitiveParams)
VtValue ComputeTriangulatedFaceVaryingPrimvar(VtValue value, const HdType valueType, HdMeshUtil &meshUtil)
packed_normal()=default
ccl_device_inline Transform make_transform(const float a, const float b, const float c, const float d, const float e, const float f, const float g, const float h, const float i, const float j, const float k, const float l)
Definition transform.h:185