animation script tutorial

hey there…

does any have or know of any good (basic) animation script tutorials/examples??? (for a sphere to be even more specific)

thanks!!

I’m going to have to second ro’s request…does anyone know??

I’d greatly appreciate it…thanks in advance.

Not sure from your question what it is you want but you can start here:

http://jmsoler.free.fr/didacticiel/blender/tutor/english/python_script05.htm

and if that’s not it look at the rest of jms’ python stuff starting here:

http://jmsoler.free.fr/didacticiel/blender/tutor/english/python_script00.htm

%<

What I need…and what I think ro needs is just an example of a python script for a simple animation of a sphere, moving from point A to point B. Then I’ll pluck what I can from that, and then write a more fitting script. I just need a basic idea of what is needed.

This is as simple as it gets :wink: Hope it helps:
anim Python file

/nozzy

Thanks nozzy…

I’m not that…ok, not well scripted at all in python…so bear with me…

First of all, what’s a float??

Second:

 Sphere.setLocation(0,frame,0)

Does the the 0, frame, 0 part mean x, y, z, respectively??

Thanks!

A variable type. There are many differant types:
A few, “Interger” a whole number 1,2,3. A “String” a letter, word or sentence, and our “Float” a decimal , eg, 1.556.

The “Curframe” is converted to a float because it returns a string, and
to a float to make the animation run smoother smaller steps, if I used a interger it would hack more.

Thats right, “frame” is the variable holding the current amount the sphere is going to be moved.

No probs, hope it makes things a little clearer.

/nozzy

Also… don’t go chasing the Python just because it’s the first approach to the problem which came to mind! You can easily accomplish the animation of a sphere by use of keyframes, actions and so-on without writing one drachma of procedural code.

thanks sliver and nozzy!!

sundialsvc4: i think i need to script it considering i need to put in a few thousand spheres for my thing. doing it normally will be way too hectic. :smiley:

speaking of which, now that i have this script for my sphere:

import Blender
from Blender import NMesh

import math
from math import * 

me=NMesh.GetRaw()

i=0.0
j=0.0

maxpoint=32.0*32.0

n=sqrt(maxpoint)
print n

radius = 2.0

for i in range(0,n):
	print i
	for j in range(0,n):
		print j
		x=sin(j*pi*2/(n-1))*cos(-pi/2+i*pi/(n-1))*radius
		y=cos(j*pi*2/(n-1))*cos(-pi/2+i*pi/(n-1))*radius
		z=sin(-pi/2+i*pi/(n-1))*radius
		v=NMesh.Vert(x,y,z)
		me.verts.append(v)

n0=len(range(0,n))
print n0

for i in range(0, n-1):
	for j in range(0, n-1):
		f=NMesh.Face()
		f.v.append(me.verts[i*n0+j])
		f.v.append(me.verts[i*n0+j+1])
		f.v.append(me.verts[(i+1)*n0+j+1])
		f.v.append(me.verts[(i+1)*n0+j])
		me.faces.append(f)

NMesh.PutRaw(me,"sphere", 1)
Blender.Redraw()

how do i loop it so that i get more than one sphere for each frame?? i’m going to need a few thousand moving around, each with different radii , so what and where do i do it?? i am so clueless… :expressionless:

I truly have difficulty imagining any image that has “literally thousands” of spheres in it. But perhaps.

Your script will presumably need to loop through all of the objects and calculate their new positions one-by-one.

I suggest that you look carefully to see if there is not some way to simplify the problem. For example, can the viewer really perceive a difference between 100 frenetic spheres and 1,000? Can the desired effect be achieved by 10 layers each containing 100 spheres, sandwiched one on top of the other and maybe offset by a few frames?

Maybe you can check this site out, with the basics in python :slight_smile:
learning to program

/nozzy

sundialsvc4: well, i kind of actually need all those spheres b/c i already have a designated number of spheres/molecules, each w/ different x,y,z coordinates, changing everytime they move. all these molecules are someway connected to each other, directly or indirectly, so i need all thousands of them. if i leave some out, the molecule interaction becomes inaccurate, or well, simply wrong.

nozzy: thanks!! i’ll see what i can wrap around my computer illiterate brain :-?

Hey, it sounds like you are doing something similar to a project I was working on a few months ago. We were running polymer simulations and needed a good visualization program.

Your script just makes a sphere, yea?

Theeth suggested just putting a sphere (or other object) in another layer, then just getting the mesh from that. It makes things MUCH simpler when you need more complex objects like cylinders for bonds and such.

Basically this is all you need:



for i in range( 0, blah):

    beadMesh = NMesh.GetRaw( "Sphere" )
    beadMesh.addMaterial( someMaterial )

    tempSph = NMesh.PutRaw( beadMesh, "MyName" + `i`, 1)
    tempSph.setLocation( someX, someY, someZ )
#end i

the “Sphere” above is the name of a sphere object that is hidden on say layer 3, and put in only once just before you run the script. I just saved it as a .blend file, and ran the script with different coordinate files.

the tempSph handle is important because then you can do things like add materials, which you set up in advance, or can be set up with code, depending on how you do it. The “MyName” + i part is extremely important because each object must be named differently, or it will just over write the old one.

I hope that helps, it is kind of the product of months of head banging and lots of help from this forum. (If you do a post search for Squirrel, you can see most of this. There also might be some interesting tid bits for you there too.)

Good luck, and let me know if this helps!
Squirrel

Hope he is still watching this post…

Do not forget to give the original addresses of this script:
http://jmsoler.free.fr/didacticiel/blender/tutor/python_script05.htm
https://blenderartists.org/forum/viewtopic.php?t=28834&highlight=

squirrel: thanks!! i’ll see what i can wrap my head around :-?

jms: sorry bout that :expressionless: …but thanks for the guidance!! :smiley: