Removing unwanted polygons

Discussions about the use of Realflow 2012
User avatar
stascrash
Posts: 65
Joined: Tue Sep 18, 2012 8:21 pm
Location: World Wide Web
Contact:

Re: Removing unwanted polygons

Postby stascrash » Fri May 17, 2013 4:53 pm

ok, so a little update, with more particles i can get the desired effect of removing polygon i dont need.
for the script that i posted earlier, i had to add few more lines,

Code: Select all

#Reposition HELPER based on the LOWES particle within range.
   sPzPos = []
   for p in sP:
      gPos = p.getPosition()
      zPos = gPos.getZ()
      sPzPos.append(zPos)
   sPzPos.sort()
   averageZpoz = sum(sPzPos)/len(sPzPos)

Basically i am collecting all particles from second emitter, get their zPosition stored in array and get an average position via SUM/LEN.
i then take the result averageZpoz and send this to the bottom of the script where i changed:

Code: Select all

#Removing particles outside of the scope of checks
      inside_volume = math.sqrt(xPos**2 + yPos**2)
      if (inside_volume <= abs(h_horKill) and zPos <= averageZpoz):
         pid = p.getId()
         secondE.removeParticle(pid)


Once these elements are simulating, realflow removes particles from INSIDE using the average height that it gets from second emitter, therefore, as my motions go up and down in the waves, the Zpoz does not create HOLES in the mesh/particles, since i dont have any particles going BELOW the zPoz limit.
Attachments
rf_03.JPG
rf_03.JPG (46.15 KiB) Viewed 496 times


User avatar
stascrash
Posts: 65
Joined: Tue Sep 18, 2012 8:21 pm
Location: World Wide Web
Contact:

Re: Removing unwanted polygons

Postby stascrash » Fri May 17, 2013 5:27 pm

the final version of the script:

Code: Select all

#--------------------------------------------------
# Function: onSimulationStep
#--------------------------------------------------

def onSimulationStep():
# Date: 05/17/2013
# Author: Stas Poritskiy
# Email: stascrash@gmail.com
# Web: stascrash.com
# Description: Scrip designed to run inside of "onSimulationStep()" function
# it performs the calculations of particle position for a specific emitter and removes
# the particles on the inside of the volume, alowing you to generate "CAP"-like meshes.
# Script is desinged around Z-UP-Axis orientation, you may need to modify it to fit your defaults.

   import math

#Defining main objects
   mainE = scene.getEmitter("Fill_Object01")
   secondE = scene.getEmitter("Circle01")
   helper = scene.getObject("Null01")

#Getting information about the objects
   mP = mainE.getParticles()

#getting information about the HELPER object
#HELPER can be animated/parented
   h_gPos = helper.getParameter("Position")
   h_horKill = h_gPos.getX()

#Setting height limit for the main emitter, if Z position is greater than set value,
# remove particles from the MAIN emitter and add them to the secondary
# We use main emitter to forward all of the behaviours to the Secondary emitter,
# comment-out this block if you are palnning to use a single emitter/alternatives
# the IF zPos - can be compared to a different value
   for p in mP:
      gPos = p.getPosition()
      zPos = gPos.getZ()
      vel = p.getVelocity()

      if zPos > 0.2:
         pid = p.getId()
         mainE.removeParticle(pid)
         secondE.addParticle(gPos, vel)
#get all created particles in SECONDARY emitter to array
   sP = secondE.getParticles()

# Reposition HELPER based on the LOWES particle within range.
# You can replace the variable "averageZpoz" with another, that tracks the
# Z-orientation of another object to control the depth of extraction for the particles
# Instead of using the Locators(HELPER) zPos. i am generating Z using
# average from the array of floats, that collect zPoz for each particle generated by second emitter.
   sPzPos = []
   for p in sP:
      gPos = p.getPosition()
      zPos = gPos.getZ()
      sPzPos.append(zPos)
   sPzPos.sort()
   averageZpoz = sum(sPzPos)/len(sPzPos)

# Getting position and speed information for secondary particles
# This block can also be used to add to the behaviour of newly generated particles.
# I am using it to slow them down a little bit, and preformint a vector (velocity) reduction.

   for p in sP:
      vel = p.getVelocity()
      velX =vel.getX()
      velY =vel.getY()
      velZ =vel.getZ()

      gPos = p.getPosition()
      xPos = gPos.getX()
      yPos = gPos.getY()
      zPos = gPos.getZ()
#slowing down particles
      vel_r = Vector.new(velX*0.9, velY*0.9, velZ*0.9)
      if vel > 0.1:
         p.setVelocity(vel_r)

#getting particles that are diving too deep into the main volume
#to avoid streched geometry
      if zPos < 0.14:
         pid = p.getId()
         secondE.removeParticle(pid)

#Implementing Pythagoras' theorem to calculate the
#INSIDE particles.
# using zPos (vertical Kill) to determin the heigh(thinknes of top layer)
# i have replaced the verticla kill from HELPER to the averageZpoz
# this is where you should place alternative varibales to determing
# the ammount of particles that you want to be removed.
#Removing particles outside of the scope of checks
      inside_volume = math.sqrt(xPos**2 + yPos**2)
      if (inside_volume <= abs(h_horKill) and zPos <= averageZpoz):
         pid = p.getId()
         secondE.removeParticle(pid)
   pass


Return to “Realflow 2012”

Who is online

Users browsing this forum: No registered users and 2 guests