Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/softbody.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| int a; | int a; | ||||
| if (ob->soft) { | if (ob->soft) { | ||||
| int nofquads; | int nofquads; | ||||
| // float s_shear = ob->soft->shearstiff*ob->soft->shearstiff; | // float s_shear = ob->soft->shearstiff*ob->soft->shearstiff; | ||||
| nofquads = count_mesh_quads(me); | nofquads = count_mesh_quads(me); | ||||
| if (nofquads) { | if (nofquads) { | ||||
| const MLoop *mloop = BKE_mesh_loops(me); | const int *corner_verts = BKE_mesh_corner_verts(me); | ||||
| const MPoly *mp = BKE_mesh_polys(me); | const MPoly *mp = BKE_mesh_polys(me); | ||||
| BodySpring *bs; | BodySpring *bs; | ||||
| /* resize spring-array to hold additional quad springs */ | /* resize spring-array to hold additional quad springs */ | ||||
| ob->soft->bspring = MEM_recallocN(ob->soft->bspring, | ob->soft->bspring = MEM_recallocN(ob->soft->bspring, | ||||
| sizeof(BodySpring) * (ob->soft->totspring + nofquads * 2)); | sizeof(BodySpring) * (ob->soft->totspring + nofquads * 2)); | ||||
| /* fill the tail */ | /* fill the tail */ | ||||
| a = 0; | a = 0; | ||||
| bs = &ob->soft->bspring[ob->soft->totspring]; | bs = &ob->soft->bspring[ob->soft->totspring]; | ||||
| // bp = ob->soft->bpoint; /* UNUSED */ | // bp = ob->soft->bpoint; /* UNUSED */ | ||||
| for (a = me->totpoly; a > 0; a--, mp++) { | for (a = me->totpoly; a > 0; a--, mp++) { | ||||
| if (mp->totloop == 4) { | if (mp->totloop == 4) { | ||||
| bs->v1 = mloop[mp->loopstart + 0].v; | bs->v1 = corner_verts[mp->loopstart + 0]; | ||||
| bs->v2 = mloop[mp->loopstart + 2].v; | bs->v2 = corner_verts[mp->loopstart + 2]; | ||||
| bs->springtype = SB_STIFFQUAD; | bs->springtype = SB_STIFFQUAD; | ||||
| bs++; | bs++; | ||||
| bs->v1 = mloop[mp->loopstart + 1].v; | bs->v1 = corner_verts[mp->loopstart + 1]; | ||||
| bs->v2 = mloop[mp->loopstart + 3].v; | bs->v2 = corner_verts[mp->loopstart + 3]; | ||||
| bs->springtype = SB_STIFFQUAD; | bs->springtype = SB_STIFFQUAD; | ||||
| bs++; | bs++; | ||||
| } | } | ||||
| } | } | ||||
| /* now we can announce new springs */ | /* now we can announce new springs */ | ||||
| ob->soft->totspring += nofquads * 2; | ob->soft->totspring += nofquads * 2; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| SoftBody *sb = ob->soft; | SoftBody *sb = ob->soft; | ||||
| const Mesh *me = ob->data; | const Mesh *me = ob->data; | ||||
| MLoopTri *looptri, *lt; | MLoopTri *looptri, *lt; | ||||
| BodyFace *bodyface; | BodyFace *bodyface; | ||||
| int a; | int a; | ||||
| const float(*vert_positions)[3] = BKE_mesh_vert_positions(me); | const float(*vert_positions)[3] = BKE_mesh_vert_positions(me); | ||||
| const MPoly *polys = BKE_mesh_polys(me); | const MPoly *polys = BKE_mesh_polys(me); | ||||
| const MLoop *loops = BKE_mesh_loops(me); | const int *corner_verts = BKE_mesh_corner_verts(me); | ||||
| /* Allocate and copy faces. */ | /* Allocate and copy faces. */ | ||||
| sb->scratch->totface = poly_to_tri_count(me->totpoly, me->totloop); | sb->scratch->totface = poly_to_tri_count(me->totpoly, me->totloop); | ||||
| looptri = lt = MEM_mallocN(sizeof(*looptri) * sb->scratch->totface, __func__); | looptri = lt = MEM_mallocN(sizeof(*looptri) * sb->scratch->totface, __func__); | ||||
| BKE_mesh_recalc_looptri(loops, polys, vert_positions, me->totloop, me->totpoly, looptri); | BKE_mesh_recalc_looptri(corner_verts, polys, vert_positions, me->totloop, me->totpoly, looptri); | ||||
| bodyface = sb->scratch->bodyface = MEM_mallocN(sizeof(BodyFace) * sb->scratch->totface, | bodyface = sb->scratch->bodyface = MEM_mallocN(sizeof(BodyFace) * sb->scratch->totface, | ||||
| "SB_body_Faces"); | "SB_body_Faces"); | ||||
| for (a = 0; a < sb->scratch->totface; a++, lt++, bodyface++) { | for (a = 0; a < sb->scratch->totface; a++, lt++, bodyface++) { | ||||
| bodyface->v1 = loops[lt->tri[0]].v; | bodyface->v1 = corner_verts[lt->tri[0]]; | ||||
| bodyface->v2 = loops[lt->tri[1]].v; | bodyface->v2 = corner_verts[lt->tri[1]]; | ||||
| bodyface->v3 = loops[lt->tri[2]].v; | bodyface->v3 = corner_verts[lt->tri[2]]; | ||||
| zero_v3(bodyface->ext_force); | zero_v3(bodyface->ext_force); | ||||
| bodyface->ext_force[0] = bodyface->ext_force[1] = bodyface->ext_force[2] = 0.0f; | bodyface->ext_force[0] = bodyface->ext_force[1] = bodyface->ext_force[2] = 0.0f; | ||||
| bodyface->flag = 0; | bodyface->flag = 0; | ||||
| } | } | ||||
| MEM_freeN(looptri); | MEM_freeN(looptri); | ||||
| } | } | ||||
| static void reference_to_scratch(Object *ob) | static void reference_to_scratch(Object *ob) | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||