Ejemplo n.º 1
0
static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
  ExplodeModifierData *emd = (ExplodeModifierData *)md;
  ParticleSystemModifierData *psmd = findPrecedingParticlesystem(ctx->object, md);

  if (psmd) {
    ParticleSystem *psys = psmd->psys;

    if (psys == NULL || psys->totpart == 0) {
      return mesh;
    }
    if (psys->part == NULL || psys->particles == NULL) {
      return mesh;
    }
    if (psmd->mesh_final == NULL) {
      return mesh;
    }

    BKE_mesh_tessface_ensure(mesh); /* BMESH - UNTIL MODIFIER IS UPDATED FOR MPoly */

    /* 1. find faces to be exploded if needed */
    if (emd->facepa == NULL || psmd->flag & eParticleSystemFlag_Pars ||
        emd->flag & eExplodeFlag_CalcFaces ||
        MEM_allocN_len(emd->facepa) / sizeof(int) != mesh->totface) {
      if (psmd->flag & eParticleSystemFlag_Pars) {
        psmd->flag &= ~eParticleSystemFlag_Pars;
      }
      if (emd->flag & eExplodeFlag_CalcFaces) {
        emd->flag &= ~eExplodeFlag_CalcFaces;
      }
      createFacepa(emd, psmd, mesh);
    }
    /* 2. create new mesh */
    Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
    if (emd->flag & eExplodeFlag_EdgeCut) {
      int *facepa = emd->facepa;
      Mesh *split_m = cutEdges(emd, mesh);
      Mesh *explode = explodeMesh(emd, psmd, ctx, scene, split_m);

      MEM_freeN(emd->facepa);
      emd->facepa = facepa;
      BKE_id_free(NULL, split_m);
      return explode;
    }
    else {
      return explodeMesh(emd, psmd, ctx, scene, mesh);
    }
  }
  return mesh;
}
Ejemplo n.º 2
0
static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
                                  DerivedMesh *derivedData,
                                  ModifierApplyFlag UNUSED(flag))
{
	DerivedMesh *dm = derivedData;
	ExplodeModifierData *emd = (ExplodeModifierData *) md;
	ParticleSystemModifierData *psmd = findPrecedingParticlesystem(ob, md);

	DM_ensure_tessface(dm); /* BMESH - UNTIL MODIFIER IS UPDATED FOR MPoly */

	if (psmd) {
		ParticleSystem *psys = psmd->psys;

		if (psys == NULL || psys->totpart == 0) return derivedData;
		if (psys->part == NULL || psys->particles == NULL) return derivedData;
		if (psmd->dm == NULL) return derivedData;

		/* 1. find faces to be exploded if needed */
		if (emd->facepa == NULL ||
		    psmd->flag & eParticleSystemFlag_Pars ||
		    emd->flag & eExplodeFlag_CalcFaces ||
		    MEM_allocN_len(emd->facepa) / sizeof(int) != dm->getNumTessFaces(dm))
		{
			if (psmd->flag & eParticleSystemFlag_Pars)
				psmd->flag &= ~eParticleSystemFlag_Pars;
			
			if (emd->flag & eExplodeFlag_CalcFaces)
				emd->flag &= ~eExplodeFlag_CalcFaces;

			createFacepa(emd, psmd, derivedData);
		}
		/* 2. create new mesh */
		if (emd->flag & eExplodeFlag_EdgeCut) {
			int *facepa = emd->facepa;
			DerivedMesh *splitdm = cutEdges(emd, dm);
			DerivedMesh *explode = explodeMesh(emd, psmd, md->scene, ob, splitdm);

			MEM_freeN(emd->facepa);
			emd->facepa = facepa;
			splitdm->release(splitdm);
			return explode;
		}
		else
			return explodeMesh(emd, psmd, md->scene, ob, derivedData);
	}
	return derivedData;
}