Simple dynamics

I’m starting with a simple script which adds a couple of objects to a scene:



import bpy

def add_prim(segs,r1,r2,h,x,y,z):
    
    #   add primitive mesh object
    bpy.ops.mesh.primitive_cone_add(vertices=segs,    radius1=r1,    radius2=r2,    depth=h)
    
    #   set basic properties
    o= bpy.context.active_object
    o.location[0]=x
    o.location[1]=y
    o.location[2]=z
    o.game.physics_type = 'RIGID_BODY'
    o.game.use_collision_bounds = 1
    
    #   set: bounce, friction, damping, etc
    return o

def apply_impulse(o,x,y,z):
    
    #   *** apply impulse force vector to the object o
    
    pass
    
o1=add_prim(4,1,2,1,   0,0,0)
o2=add_prim(4,1,2,1,   5,0,0)

apply_impulse(o1,0,0,1)

STEP 1:

What are the ways to apply an initial impulse to an object


def apply_impulse(o,x,y,z):
    
    #   *** apply impulse force vector to the object o
    
    pass

ALSO: automatically play, record keyframes

Don’t use bpy, as it’s only available under Blender (not using the BlenderPlayer alone). You can’t create objects dynamically using the BGE by default.

As for your question, why are you writing your own impulse application function instead of using the onethat already exists in the BGE API?

I see… its been a while, also my approach started from the thought of generating a scene, starting the game/physics engine whilst recording keyframes, stop it, clean up the keys and then save the file for later render. i.e. i’m after doing these in a background process too.

I see the issue with applying the impulse, its BPY not BGE, i’d apply the impulse to an object in game via logic attachment… Is it possible to run blenderplayer headless in the background?

Ignoring impulse for now, how do I run a scene (started & stopped by script) to calculate the keyframes, (*next part is done) in Blender started in a background process?

just do record animations in the game dropdown settings, and then in the object physics check record.

:smiley: cheers.

via code…

Ok if you really don’t want to press ‘p’ you can ‘code it’ : bpy.ops.view3d.game_start()
:smiley:

Anyway, BluePrintRandom gives you the right answer

OK again, Blender is being started in a background process from the command line, no GUI!

As for start, yes i’d done that, however the stop is the real issue there! (Not tried exit call from blenderplayer yet though! Would rather managae that from BPY side. Is there a way to send events to the game?)

OK, perhaps it would help if you said exactly what you’re trying to do.

You can’t use the bpy module in a standalone game. If you’re trying to record keyframes, you might only be able to do that using the BPY module and Python. HOWEVER, the bpy module doesn’t change the game as it runs, but rather the underlying blend file. So I don’t know if you’ll be able to use the bpy module to record the keyframes, since the objects won’t be changing, to Blender.

The most important part is it being headless, i.e. so it can be run on a server.

I was originally coming from the BPY approach because its in Blender that I make sims for use in Blender. Basically I use the process that BluePrintRandom suggested.

So this thread is Blender related (rather than BGE related?)

It’s both, I guess.

Its either or depending upon the solution…?

It started as Blender specific before the suggestion of BGE use… However even if it is Blender it does use BGE, so…

I think this thread is not BGE related.

Does using BGE headless on a server makes any sense ?!

If you want to do a non interactive physical simulation why using BGE ?