From f35264706a403a666e7f3077c4b807bd1aaa3765 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 20 Jun 2013 13:27:48 +0000 Subject: Construct orco UV layer for curve when applying constructive modifier Also construct orco uv layer when converting curve to a mesh. This makes it possible to preserve automatically generated coordinates ("use uv for mapping" option) when using constructive modifiers or converting curve to the mesh. With cycles nothing special is needed to preserve texture mapping after such operations, in blender internal you'll need to change texture mapping from Generated to UV. This feature is useful on it's own and also would help in potential switch 3d viewport to always use DM to draw objects, which would help making drawing more thread-safe. --- source/blender/blenkernel/intern/cdderivedmesh.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source/blender/blenkernel/intern/cdderivedmesh.c') diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 64d6ca6666e..73c722a4849 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1823,16 +1823,19 @@ DerivedMesh *CDDM_from_curve(Object *ob) DerivedMesh *CDDM_from_curve_displist(Object *ob, ListBase *dispbase) { + Curve *cu = (Curve *) ob->data; DerivedMesh *dm; CDDerivedMesh *cddm; MVert *allvert; MEdge *alledge; MLoop *allloop; MPoly *allpoly; + MLoopUV *alluv = NULL; int totvert, totedge, totloop, totpoly; + bool use_orco_uv = (cu->flag & CU_UV_ORCO) != 0; if (BKE_mesh_nurbs_displist_to_mdata(ob, dispbase, &allvert, &totvert, &alledge, - &totedge, &allloop, &allpoly, NULL, + &totedge, &allloop, &allpoly, (use_orco_uv) ? &alluv : NULL, &totloop, &totpoly) != 0) { /* Error initializing mdata. This often happens when curve is empty */ @@ -1850,6 +1853,12 @@ DerivedMesh *CDDM_from_curve_displist(Object *ob, ListBase *dispbase) memcpy(cddm->mloop, allloop, totloop * sizeof(MLoop)); memcpy(cddm->mpoly, allpoly, totpoly * sizeof(MPoly)); + if (alluv) { + const char *uvname = "Orco"; + CustomData_add_layer_named(&cddm->dm.polyData, CD_MTEXPOLY, CD_DEFAULT, NULL, totpoly, uvname); + CustomData_add_layer_named(&cddm->dm.loopData, CD_MLOOPUV, CD_ASSIGN, alluv, totloop, uvname); + } + MEM_freeN(allvert); MEM_freeN(alledge); MEM_freeN(allloop); -- cgit v1.2.3