Accessing the locations of trail particles or approx alg?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
dustractor
Posts: 0
Joined: Mon Dec 10, 2007 1:52 am
Location: arkansas

Accessing the locations of trail particles or approx alg?

Post by dustractor » Fri Aug 16, 2013 9:42 pm

I made a simple script to rip particle locations to a point mesh, but the trail particles are not included. Do I need to manipulate the current_frame and repeat the rip at various points in time?
How would I get the particle locations at sub-step resolution in time? Just set the frame to a non-integer value?

dustractor
Posts: 0
Joined: Mon Dec 10, 2007 1:52 am
Location: arkansas

Post by dustractor » Fri Aug 16, 2013 11:05 pm

So far this is what I've got:

Code: Select all


import bpy
from math import modf
class PTZ_OT_convert(bpy.types.Operator):
    bl_idname = "parts.to_verts"
    bl_label = "r2p:particles to Points"
    @classmethod
    def poll(self,context):
        try:
            assert context.active_object.particle_systems.active != None
            has = True
        except (AssertionError,ValueError):
            has = False
        finally:
            return has

    def execute(self,context):
        scn = context.scene
        frame = scn.frame_current
        psys = context.object.particle_systems.active
        pset = psys.settings
        m = bpy.data.meshes.new('P-cloud_verts')
        v = []
        tc = pset.trail_count
        span = (frame - pset.frame_start) * pset.path_end
        step = span / tc
        cf = frame - span
        for r in range(tc):
            sub,f = modf(cf + (step * r))
            scn.frame_set(frame=f,subframe=sub)
            scn.update()
            print("scn.frame_current_final:",scn.frame_current_final)
            for p in psys.particles:
                v.append(p.location)
        m.from_pydata(v,[],[])
        o = bpy.data.objects.new('P-cloud',object_data=m)
        bpy.context.scene.objects.link(o)
        return {'FINISHED'}

def register():
    bpy.utils.register_class(PTZ_OT_convert)
def unregister():
    bpy.utils.unregister_class(PTZ_OT_convert)
if __name__ == '__main__':
    register()


dustractor
Posts: 0
Joined: Mon Dec 10, 2007 1:52 am
Location: arkansas

It was a problem with the wrapped location vectors!

Post by dustractor » Fri Aug 16, 2013 11:44 pm

Looked closely at the vertex count of the output object.

They were all stacked at the ending particle location. I thought it was a problem with setting the frame which it was apparently not.

changed the line

Code: Select all

                    v.append(p.location)
to

Code: Select all

                    v.append(p.location[:])
and it worked. ( also had to filter out particles that were not alive)

Still have to adjust the spacing to be WYSIWIG

Post Reply