Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/multires.c
| Show First 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | |||||
| Mesh *BKE_multires_create_mesh( | Mesh *BKE_multires_create_mesh( | ||||
| struct Depsgraph *depsgraph, | struct Depsgraph *depsgraph, | ||||
| Scene *scene, | Scene *scene, | ||||
| MultiresModifierData *mmd, | MultiresModifierData *mmd, | ||||
| Object *ob) | Object *ob) | ||||
| { | { | ||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | ||||
| Mesh *deformed_mesh = mesh_get_eval_deform(depsgraph, scene, ob_eval, CD_MASK_BAREMESH); | Mesh *deformed_mesh = mesh_get_eval_deform(depsgraph, scene, ob_eval, &CD_MASK_BAREMESH); | ||||
| ModifierEvalContext modifier_ctx = { | ModifierEvalContext modifier_ctx = { | ||||
| .depsgraph = depsgraph, | .depsgraph = depsgraph, | ||||
| .object = ob_eval, | .object = ob_eval, | ||||
| .flag = MOD_APPLY_USECACHE | MOD_APPLY_IGNORE_SIMPLIFY, | .flag = MOD_APPLY_USECACHE | MOD_APPLY_IGNORE_SIMPLIFY, | ||||
| }; | }; | ||||
| const ModifierTypeInfo *mti = modifierType_getInfo(mmd->modifier.type); | const ModifierTypeInfo *mti = modifierType_getInfo(mmd->modifier.type); | ||||
| Mesh *result = mti->applyModifier(&mmd->modifier, &modifier_ctx, deformed_mesh); | Mesh *result = mti->applyModifier(&mmd->modifier, &modifier_ctx, deformed_mesh); | ||||
| ▲ Show 20 Lines • Show All 462 Lines • ▼ Show 20 Lines | void multiresModifier_base_apply(MultiresModifierData *mmd, Scene *scene, Object *ob) | ||||
| /* nothing to do */ | /* nothing to do */ | ||||
| if (!totlvl) | if (!totlvl) | ||||
| return; | return; | ||||
| /* XXX - probably not necessary to regenerate the cddm so much? */ | /* XXX - probably not necessary to regenerate the cddm so much? */ | ||||
| /* generate highest level with displacements */ | /* generate highest level with displacements */ | ||||
| cddm = CDDM_from_mesh(me); | cddm = CDDM_from_mesh(me); | ||||
| DM_set_only_copy(cddm, CD_MASK_BAREMESH); | DM_set_only_copy(cddm, &CD_MASK_BAREMESH); | ||||
| dispdm = multires_dm_create_local(scene, ob, cddm, totlvl, totlvl, 0, 0, MULTIRES_IGNORE_SIMPLIFY); | dispdm = multires_dm_create_local(scene, ob, cddm, totlvl, totlvl, 0, 0, MULTIRES_IGNORE_SIMPLIFY); | ||||
| cddm->release(cddm); | cddm->release(cddm); | ||||
| /* copy the new locations of the base verts into the mesh */ | /* copy the new locations of the base verts into the mesh */ | ||||
| offset = dispdm->getNumVerts(dispdm) - me->totvert; | offset = dispdm->getNumVerts(dispdm) - me->totvert; | ||||
| for (i = 0; i < me->totvert; ++i) { | for (i = 0; i < me->totvert; ++i) { | ||||
| dispdm->getVertCo(dispdm, offset + i, me->mvert[i].co); | dispdm->getVertCo(dispdm, offset + i, me->mvert[i].co); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | void multiresModifier_base_apply(MultiresModifierData *mmd, Scene *scene, Object *ob) | ||||
| /* Vertices were moved around, need to update normals after all the vertices are updated | /* Vertices were moved around, need to update normals after all the vertices are updated | ||||
| * Probably this is possible to do in the loop above, but this is rather tricky because | * Probably this is possible to do in the loop above, but this is rather tricky because | ||||
| * we don't know all needed vertices' coordinates there yet. | * we don't know all needed vertices' coordinates there yet. | ||||
| */ | */ | ||||
| BKE_mesh_calc_normals(me); | BKE_mesh_calc_normals(me); | ||||
| /* subdivide the mesh to highest level without displacements */ | /* subdivide the mesh to highest level without displacements */ | ||||
| cddm = CDDM_from_mesh(me); | cddm = CDDM_from_mesh(me); | ||||
| DM_set_only_copy(cddm, CD_MASK_BAREMESH); | DM_set_only_copy(cddm, &CD_MASK_BAREMESH); | ||||
| origdm = subsurf_dm_create_local( | origdm = subsurf_dm_create_local( | ||||
| scene, ob, cddm, totlvl, 0, 0, mmd->uv_smooth == SUBSURF_UV_SMOOTH_NONE, | scene, ob, cddm, totlvl, 0, 0, mmd->uv_smooth == SUBSURF_UV_SMOOTH_NONE, | ||||
| 0, false, SUBSURF_IGNORE_SIMPLIFY); | 0, false, SUBSURF_IGNORE_SIMPLIFY); | ||||
| cddm->release(cddm); | cddm->release(cddm); | ||||
| /* calc disps */ | /* calc disps */ | ||||
| multiresModifier_disp_run(dispdm, me, NULL, CALC_DISPLACEMENTS, origdm->getGridData(origdm), totlvl); | multiresModifier_disp_run(dispdm, me, NULL, CALC_DISPLACEMENTS, origdm->getGridData(origdm), totlvl); | ||||
| Show All 26 Lines | if (mdisps->disps && !updateblock && lvl != 0) { | ||||
| CCGElem **highGridData, **lowGridData, **subGridData; | CCGElem **highGridData, **lowGridData, **subGridData; | ||||
| CCGKey highGridKey, lowGridKey; | CCGKey highGridKey, lowGridKey; | ||||
| CCGSubSurf *ss; | CCGSubSurf *ss; | ||||
| int i, numGrids, highGridSize; | int i, numGrids, highGridSize; | ||||
| const bool has_mask = CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK); | const bool has_mask = CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK); | ||||
| /* create subsurf DM from original mesh at high level */ | /* create subsurf DM from original mesh at high level */ | ||||
| cddm = CDDM_from_mesh(me); | cddm = CDDM_from_mesh(me); | ||||
| DM_set_only_copy(cddm, CD_MASK_BAREMESH); | DM_set_only_copy(cddm, &CD_MASK_BAREMESH); | ||||
| highdm = subsurf_dm_create_local( | highdm = subsurf_dm_create_local( | ||||
| NULL, ob, cddm, totlvl, simple, 0, mmd->uv_smooth == SUBSURF_UV_SMOOTH_NONE, | NULL, ob, cddm, totlvl, simple, 0, mmd->uv_smooth == SUBSURF_UV_SMOOTH_NONE, | ||||
| has_mask, false, SUBSURF_IGNORE_SIMPLIFY); | has_mask, false, SUBSURF_IGNORE_SIMPLIFY); | ||||
| ss = ((CCGDerivedMesh *)highdm)->ss; | ss = ((CCGDerivedMesh *)highdm)->ss; | ||||
| /* create multires DM from original mesh at low level */ | /* create multires DM from original mesh at low level */ | ||||
| lowdm = multires_dm_create_local(scene, ob, cddm, lvl, lvl, simple, has_mask, MULTIRES_IGNORE_SIMPLIFY); | lowdm = multires_dm_create_local(scene, ob, cddm, lvl, lvl, simple, has_mask, MULTIRES_IGNORE_SIMPLIFY); | ||||
| BLI_assert(lowdm != cddm); | BLI_assert(lowdm != cddm); | ||||
| ▲ Show 20 Lines • Show All 305 Lines • ▼ Show 20 Lines | if (lvl < totlvl) { | ||||
| CCGKey highGridKey, lowGridKey; | CCGKey highGridKey, lowGridKey; | ||||
| CCGSubSurf *ss; | CCGSubSurf *ss; | ||||
| int i, j, numGrids, highGridSize, lowGridSize; | int i, j, numGrids, highGridSize, lowGridSize; | ||||
| const bool has_mask = CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK); | const bool has_mask = CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK); | ||||
| /* create subsurf DM from original mesh at high level */ | /* create subsurf DM from original mesh at high level */ | ||||
| if (ob->derivedDeform) cddm = CDDM_copy(ob->derivedDeform); | if (ob->derivedDeform) cddm = CDDM_copy(ob->derivedDeform); | ||||
| else cddm = CDDM_from_mesh(me); | else cddm = CDDM_from_mesh(me); | ||||
| DM_set_only_copy(cddm, CD_MASK_BAREMESH); | DM_set_only_copy(cddm, &CD_MASK_BAREMESH); | ||||
| highdm = subsurf_dm_create_local( | highdm = subsurf_dm_create_local( | ||||
| scene, ob, cddm, totlvl, mmd->simple, 0, mmd->uv_smooth == SUBSURF_UV_SMOOTH_NONE, | scene, ob, cddm, totlvl, mmd->simple, 0, mmd->uv_smooth == SUBSURF_UV_SMOOTH_NONE, | ||||
| has_mask, false, SUBSURF_IGNORE_SIMPLIFY); | has_mask, false, SUBSURF_IGNORE_SIMPLIFY); | ||||
| ss = ((CCGDerivedMesh *)highdm)->ss; | ss = ((CCGDerivedMesh *)highdm)->ss; | ||||
| /* create multires DM from original mesh and displacements */ | /* create multires DM from original mesh and displacements */ | ||||
| lowdm = multires_dm_create_local(scene, ob, cddm, lvl, totlvl, mmd->simple, has_mask, MULTIRES_IGNORE_SIMPLIFY); | lowdm = multires_dm_create_local(scene, ob, cddm, lvl, totlvl, mmd->simple, has_mask, MULTIRES_IGNORE_SIMPLIFY); | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | if (lvl < totlvl) { | ||||
| MEM_freeN(subGridData); | MEM_freeN(subGridData); | ||||
| } | } | ||||
| else { | else { | ||||
| DerivedMesh *cddm, *subdm; | DerivedMesh *cddm, *subdm; | ||||
| const bool has_mask = CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK); | const bool has_mask = CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK); | ||||
| if (ob->derivedDeform) cddm = CDDM_copy(ob->derivedDeform); | if (ob->derivedDeform) cddm = CDDM_copy(ob->derivedDeform); | ||||
| else cddm = CDDM_from_mesh(me); | else cddm = CDDM_from_mesh(me); | ||||
| DM_set_only_copy(cddm, CD_MASK_BAREMESH); | DM_set_only_copy(cddm, &CD_MASK_BAREMESH); | ||||
| subdm = subsurf_dm_create_local( | subdm = subsurf_dm_create_local( | ||||
| scene, ob, cddm, mmd->totlvl, mmd->simple, 0, mmd->uv_smooth == SUBSURF_UV_SMOOTH_NONE, | scene, ob, cddm, mmd->totlvl, mmd->simple, 0, mmd->uv_smooth == SUBSURF_UV_SMOOTH_NONE, | ||||
| has_mask, false, SUBSURF_IGNORE_SIMPLIFY); | has_mask, false, SUBSURF_IGNORE_SIMPLIFY); | ||||
| cddm->release(cddm); | cddm->release(cddm); | ||||
| multiresModifier_disp_run(dm, me, NULL, CALC_DISPLACEMENTS, subdm->getGridData(subdm), mmd->totlvl); | multiresModifier_disp_run(dm, me, NULL, CALC_DISPLACEMENTS, subdm->getGridData(subdm), mmd->totlvl); | ||||
| ▲ Show 20 Lines • Show All 1,008 Lines • Show Last 20 Lines | |||||