@@ -40,6 +40,26 @@ struct MakeTri {
40
40
}
41
41
};
42
42
43
+ struct UpdateProperties {
44
+ float * properties;
45
+ const int numProp;
46
+ const float * oldProperties;
47
+ const int numOldProp;
48
+ const glm::vec3* vertPos;
49
+ const glm::ivec3* triProperties;
50
+ const Halfedge* halfedges;
51
+ std::function<void (glm::vec3, const float * const , float * const )> propFunc;
52
+
53
+ __host__ __device__ void operator ()(int tri) {
54
+ for (int i : {0 , 1 , 2 }) {
55
+ const int vert = halfedges[3 * tri + i].startVert ;
56
+ const int propVert = triProperties[tri][i];
57
+ propFunc (vertPos[vert], oldProperties + numOldProp * propVert,
58
+ properties + numProp * propVert);
59
+ }
60
+ }
61
+ };
62
+
43
63
Manifold Halfspace (Box bBox, glm::vec3 normal, float originOffset) {
44
64
normal = glm::normalize (normal);
45
65
Manifold cutter =
@@ -555,6 +575,58 @@ Manifold Manifold::Warp(std::function<void(glm::vec3&)> warpFunc) const {
555
575
return Manifold (std::make_shared<CsgLeafNode>(pImpl));
556
576
}
557
577
578
+ /* *
579
+ * Create a new copy of this manifold with updated vertex properties by
580
+ * supplying a function that takes the existing position and properties as
581
+ * input. You may specify any number of output properties, allowing creation and
582
+ * removal of channels. Note: undefined behavior will result if you read past
583
+ * the number of input properties or write past the number of output properties.
584
+ *
585
+ * @param numProp The new number of properties per vertex.
586
+ * @param propFunc A function that modifies the properties of a given vertex.
587
+ */
588
+ Manifold Manifold::SetProperties (
589
+ int numProp, std::function<void (glm::vec3 position, const float * oldProp,
590
+ float * newProp)>
591
+ propFunc) const {
592
+ auto pImpl = std::make_shared<Impl>(*GetCsgLeafNode ().GetImpl ());
593
+ const int oldNumProp = NumProp ();
594
+ const VecDH<float > oldProperties = pImpl->meshRelation_ .properties ;
595
+
596
+ auto & triProperties = pImpl->meshRelation_ .triProperties ;
597
+ if (numProp == 0 ) {
598
+ triProperties.resize (0 );
599
+ pImpl->meshRelation_ .properties .resize (0 );
600
+ } else {
601
+ if (triProperties.size () == 0 ) {
602
+ const int numTri = NumTri ();
603
+ triProperties.resize (numTri);
604
+ int idx = 0 ;
605
+ for (int i = 0 ; i < numTri; ++i) {
606
+ for (const int j : {0 , 1 , 2 }) {
607
+ triProperties[i][j] = idx++;
608
+ }
609
+ }
610
+ pImpl->meshRelation_ .properties = VecDH<float >(numProp * idx, 0 );
611
+ } else {
612
+ pImpl->meshRelation_ .properties =
613
+ VecDH<float >(numProp * NumPropVert (), 0 );
614
+ }
615
+ thrust::for_each_n (
616
+ thrust::host, countAt (0 ), NumTri (),
617
+ UpdateProperties ({pImpl->meshRelation_ .properties .ptrH (), numProp,
618
+ oldProperties.ptrH (), oldNumProp,
619
+ pImpl->vertPos_ .ptrH (), triProperties.ptrH (),
620
+ pImpl->halfedge_ .ptrH (), propFunc}));
621
+ }
622
+
623
+ pImpl->meshRelation_ .numProp = numProp;
624
+ pImpl->CreateFaces ();
625
+ pImpl->SimplifyTopology ();
626
+ pImpl->Finish ();
627
+ return Manifold (std::make_shared<CsgLeafNode>(pImpl));
628
+ }
629
+
558
630
/* *
559
631
* Increase the density of the mesh by splitting every edge into n pieces. For
560
632
* instance, with n = 2, each triangle will be split into 4 triangles. These
0 commit comments