Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/cdderivedmesh.c
| Show First 20 Lines • Show All 576 Lines • ▼ Show 20 Lines | DerivedMesh *CDDM_new(int numVerts, int numEdges, int numTessFaces, int numLoops, int numPolys) | ||||
| cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP); | cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP); | ||||
| cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY); | cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY); | ||||
| return dm; | return dm; | ||||
| } | } | ||||
| DerivedMesh *CDDM_from_mesh(Mesh *mesh) | DerivedMesh *CDDM_from_mesh(Mesh *mesh) | ||||
| { | { | ||||
| return CDDM_from_mesh_ex(mesh, CD_REFERENCE, CD_MASK_MESH); | return CDDM_from_mesh_ex(mesh, CD_REFERENCE, &CD_MASK_MESH); | ||||
| } | } | ||||
| DerivedMesh *CDDM_from_mesh_ex(Mesh *mesh, eCDAllocType alloctype, CustomDataMask mask) | DerivedMesh *CDDM_from_mesh_ex(Mesh *mesh, eCDAllocType alloctype, const CustomData_Masks *mask) | ||||
| { | { | ||||
| CDDerivedMesh *cddm = cdDM_create(__func__); | CDDerivedMesh *cddm = cdDM_create(__func__); | ||||
| DerivedMesh *dm = &cddm->dm; | DerivedMesh *dm = &cddm->dm; | ||||
| CustomData_Masks cddata_masks = *mask; | |||||
| mask &= ~CD_MASK_MDISPS; | cddata_masks.lmask &= ~CD_MASK_MDISPS; | ||||
| /* this does a referenced copy, with an exception for fluidsim */ | /* this does a referenced copy, with an exception for fluidsim */ | ||||
| DM_init(dm, DM_TYPE_CDDM, mesh->totvert, mesh->totedge, 0 /* mesh->totface */, | DM_init(dm, DM_TYPE_CDDM, mesh->totvert, mesh->totedge, 0 /* mesh->totface */, | ||||
| mesh->totloop, mesh->totpoly); | mesh->totloop, mesh->totpoly); | ||||
| /* This should actually be dm->deformedOnly = mesh->runtime.deformed_only, | /* This should actually be dm->deformedOnly = mesh->runtime.deformed_only, | ||||
| * but only if the original mesh had its deformed_only flag correctly set | * but only if the original mesh had its deformed_only flag correctly set | ||||
| * (which isn't generally the case). */ | * (which isn't generally the case). */ | ||||
| dm->deformedOnly = 1; | dm->deformedOnly = 1; | ||||
| dm->cd_flag = mesh->cd_flag; | dm->cd_flag = mesh->cd_flag; | ||||
| if (mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) { | if (mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) { | ||||
| dm->dirty |= DM_DIRTY_NORMALS; | dm->dirty |= DM_DIRTY_NORMALS; | ||||
| } | } | ||||
| /* TODO DM_DIRTY_TESS_CDLAYERS ? Maybe not though, since we probably want to switch to looptris ? */ | /* TODO DM_DIRTY_TESS_CDLAYERS ? Maybe not though, since we probably want to switch to looptris ? */ | ||||
| CustomData_merge(&mesh->vdata, &dm->vertData, mask, alloctype, | CustomData_merge(&mesh->vdata, &dm->vertData, cddata_masks.vmask, alloctype, | ||||
| mesh->totvert); | mesh->totvert); | ||||
| CustomData_merge(&mesh->edata, &dm->edgeData, mask, alloctype, | CustomData_merge(&mesh->edata, &dm->edgeData, cddata_masks.emask, alloctype, | ||||
| mesh->totedge); | mesh->totedge); | ||||
| CustomData_merge(&mesh->fdata, &dm->faceData, mask | CD_MASK_ORIGINDEX, alloctype, | CustomData_merge(&mesh->fdata, &dm->faceData, cddata_masks.fmask | CD_MASK_ORIGINDEX, alloctype, | ||||
| 0 /* mesh->totface */); | 0 /* mesh->totface */); | ||||
| CustomData_merge(&mesh->ldata, &dm->loopData, mask, alloctype, | CustomData_merge(&mesh->ldata, &dm->loopData, cddata_masks.lmask, alloctype, | ||||
| mesh->totloop); | mesh->totloop); | ||||
| CustomData_merge(&mesh->pdata, &dm->polyData, mask, alloctype, | CustomData_merge(&mesh->pdata, &dm->polyData, cddata_masks.pmask, alloctype, | ||||
| mesh->totpoly); | mesh->totpoly); | ||||
| cddm->mvert = CustomData_get_layer(&dm->vertData, CD_MVERT); | cddm->mvert = CustomData_get_layer(&dm->vertData, CD_MVERT); | ||||
| cddm->medge = CustomData_get_layer(&dm->edgeData, CD_MEDGE); | cddm->medge = CustomData_get_layer(&dm->edgeData, CD_MEDGE); | ||||
| cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP); | cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP); | ||||
| cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY); | cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY); | ||||
| #if 0 | #if 0 | ||||
| cddm->mface = CustomData_get_layer(&dm->faceData, CD_MFACE); | cddm->mface = CustomData_get_layer(&dm->faceData, CD_MFACE); | ||||
| ▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | static DerivedMesh *cddm_from_bmesh_ex( | ||||
| MVert *mvert = cddm->mvert; | MVert *mvert = cddm->mvert; | ||||
| MEdge *medge = cddm->medge; | MEdge *medge = cddm->medge; | ||||
| MFace *mface = cddm->mface; | MFace *mface = cddm->mface; | ||||
| MLoop *mloop = cddm->mloop; | MLoop *mloop = cddm->mloop; | ||||
| MPoly *mpoly = cddm->mpoly; | MPoly *mpoly = cddm->mpoly; | ||||
| int numCol = CustomData_number_of_layers(&bm->ldata, CD_MLOOPCOL); | int numCol = CustomData_number_of_layers(&bm->ldata, CD_MLOOPCOL); | ||||
| int numUV = CustomData_number_of_layers(&bm->ldata, CD_MLOOPUV); | int numUV = CustomData_number_of_layers(&bm->ldata, CD_MLOOPUV); | ||||
| int *index, add_orig; | int *index, add_orig; | ||||
| CustomDataMask mask; | CustomData_Masks mask = {0}; | ||||
| unsigned int i, j; | unsigned int i, j; | ||||
| const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT); | const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT); | ||||
| const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT); | const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT); | ||||
| const int cd_edge_crease_offset = CustomData_get_offset(&bm->edata, CD_CREASE); | const int cd_edge_crease_offset = CustomData_get_offset(&bm->edata, CD_CREASE); | ||||
| dm->deformedOnly = 1; | dm->deformedOnly = 1; | ||||
| /* don't add origindex layer if one already exists */ | /* don't add origindex layer if one already exists */ | ||||
| add_orig = !CustomData_has_layer(&bm->pdata, CD_ORIGINDEX); | add_orig = !CustomData_has_layer(&bm->pdata, CD_ORIGINDEX); | ||||
| mask = use_mdisps ? CD_MASK_DERIVEDMESH | CD_MASK_MDISPS : CD_MASK_DERIVEDMESH; | mask = CD_MASK_DERIVEDMESH; | ||||
| if (use_mdisps) { | |||||
| mask.lmask |= CD_MASK_MDISPS; | |||||
| } | |||||
| /* don't process shapekeys, we only feed them through the modifier stack as needed, | /* don't process shapekeys, we only feed them through the modifier stack as needed, | ||||
| * e.g. for applying modifiers or the like*/ | * e.g. for applying modifiers or the like*/ | ||||
| mask &= ~CD_MASK_SHAPEKEY; | mask.vmask &= ~CD_MASK_SHAPEKEY; | ||||
| CustomData_merge(&bm->vdata, &dm->vertData, mask, | CustomData_merge(&bm->vdata, &dm->vertData, mask.vmask, | ||||
| CD_CALLOC, dm->numVertData); | CD_CALLOC, dm->numVertData); | ||||
| CustomData_merge(&bm->edata, &dm->edgeData, mask, | CustomData_merge(&bm->edata, &dm->edgeData, mask.emask, | ||||
| CD_CALLOC, dm->numEdgeData); | CD_CALLOC, dm->numEdgeData); | ||||
| CustomData_merge(&bm->ldata, &dm->loopData, mask, | CustomData_merge(&bm->ldata, &dm->loopData, mask.lmask, | ||||
| CD_CALLOC, dm->numLoopData); | CD_CALLOC, dm->numLoopData); | ||||
| CustomData_merge(&bm->pdata, &dm->polyData, mask, | CustomData_merge(&bm->pdata, &dm->polyData, mask.pmask, | ||||
| CD_CALLOC, dm->numPolyData); | CD_CALLOC, dm->numPolyData); | ||||
| /* add tessellation mface layers */ | /* add tessellation mface layers */ | ||||
| if (use_tessface) { | if (use_tessface) { | ||||
| CustomData_from_bmeshpoly(&dm->faceData, &dm->loopData, em_tottri); | CustomData_from_bmeshpoly(&dm->faceData, &dm->loopData, em_tottri); | ||||
| } | } | ||||
| index = dm->getVertDataArray(dm, CD_ORIGINDEX); | index = dm->getVertDataArray(dm, CD_ORIGINDEX); | ||||
| ▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | DerivedMesh *CDDM_copy(DerivedMesh *source) | ||||
| cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP); | cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP); | ||||
| cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY); | cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY); | ||||
| return dm; | return dm; | ||||
| } | } | ||||
| /* note, the CD_ORIGINDEX layers are all 0, so if there is a direct | /* note, the CD_ORIGINDEX layers are all 0, so if there is a direct | ||||
| * relationship between mesh data this needs to be set by the caller. */ | * relationship between mesh data this needs to be set by the caller. */ | ||||
| DerivedMesh *CDDM_from_template_ex( | DerivedMesh *CDDM_from_template_ex(DerivedMesh *source, | ||||
| DerivedMesh *source, | |||||
| int numVerts, int numEdges, int numTessFaces, | int numVerts, int numEdges, int numTessFaces, | ||||
| int numLoops, int numPolys, | int numLoops, int numPolys, | ||||
| CustomDataMask mask) | const CustomData_Masks *mask) | ||||
| { | { | ||||
| CDDerivedMesh *cddm = cdDM_create("CDDM_from_template dest"); | CDDerivedMesh *cddm = cdDM_create("CDDM_from_template dest"); | ||||
| DerivedMesh *dm = &cddm->dm; | DerivedMesh *dm = &cddm->dm; | ||||
| /* ensure these are created if they are made on demand */ | /* ensure these are created if they are made on demand */ | ||||
| source->getVertDataArray(source, CD_ORIGINDEX); | source->getVertDataArray(source, CD_ORIGINDEX); | ||||
| source->getEdgeDataArray(source, CD_ORIGINDEX); | source->getEdgeDataArray(source, CD_ORIGINDEX); | ||||
| source->getTessFaceDataArray(source, CD_ORIGINDEX); | source->getTessFaceDataArray(source, CD_ORIGINDEX); | ||||
| Show All 31 Lines | |||||
| DerivedMesh *CDDM_from_template( | DerivedMesh *CDDM_from_template( | ||||
| DerivedMesh *source, | DerivedMesh *source, | ||||
| int numVerts, int numEdges, int numTessFaces, | int numVerts, int numEdges, int numTessFaces, | ||||
| int numLoops, int numPolys) | int numLoops, int numPolys) | ||||
| { | { | ||||
| return CDDM_from_template_ex( | return CDDM_from_template_ex( | ||||
| source, numVerts, numEdges, numTessFaces, | source, numVerts, numEdges, numTessFaces, | ||||
| numLoops, numPolys, | numLoops, numPolys, | ||||
| CD_MASK_DERIVEDMESH); | &CD_MASK_DERIVEDMESH); | ||||
| } | } | ||||
| void CDDM_apply_vert_coords(DerivedMesh *dm, float (*vertCoords)[3]) | void CDDM_apply_vert_coords(DerivedMesh *dm, float (*vertCoords)[3]) | ||||
| { | { | ||||
| CDDerivedMesh *cddm = (CDDerivedMesh *)dm; | CDDerivedMesh *cddm = (CDDerivedMesh *)dm; | ||||
| MVert *vert; | MVert *vert; | ||||
| int i; | int i; | ||||
| ▲ Show 20 Lines • Show All 353 Lines • Show Last 20 Lines | |||||