Orbit Maker

I made my another simple script. No GUI yet.


"""
OrbitMaker v.1.0 (for Spiral Generator)

How to use:
Select the spiral(orbit) and
push alt+p to generate ipodata.
Add the ipodata to the UFO with IpoCurveEditor, by hand:).
push alt+a on the 3dviewpoint to check the animation.


"""
###setting###
ipname = "ufomove"	#change ipodataname as you like.
startf = 1;endf = 100	#startf is the startframe of animation.
locOn = 1		#1 is for loc, 2 is for dloc
s = 1.0			#parametor of mystery...
#flen = endf - startf

#############

import Blender
from Blender import Object,NMesh,Ipo

print 
try:
	spiname = Object.GetSelected()[0].name
except:
	print "Just select a Spiral!"
	
meverts = NMesh.GetRawFromObject(spiname)

vlist=[]
for v in meverts.verts:
	vlist.append(v.co)

ipo = Ipo.New('Object',ipname)
	
if locOn == 1:
	locxc = ipo.addCurve('LocX')
	locyc = ipo.addCurve('LocY')
	loczc = ipo.addCurve('LocZ')
elif locOn == 2:
	locxc = ipo.addCurve('dLocX')
	locyc = ipo.addCurve('dLocY')
	loczc = ipo.addCurve('dLocZ')
else:pass

for c in [locxc,locyc,loczc]:
	c.setInterpolation('Linear')
	c.setExtrapolation('Constant')

i = 0
for v in vlist:
	locxc.addBezier((i+startf,v[0]))
	locyc.addBezier((i+startf,v[1]))
	loczc.addBezier((i+startf,v[2]))
	i+=s
locxc.update();locyc.update();loczc.update()

print "done!"

"""
(c)Soni Bardot

[email protected]

"""

Demo file is here.
http://runble2.tripod.co.jp/pyscript/orbitmaker.zip
I tested with 2.28a. It worked fine.

Very nice script, thanks.

Would there be any way that you could add a ‘CurveFollow’ feature, as appears with the path feature? I have a feeling the answer is no, but I thought I would ask anyway.

Thanks again :slight_smile:

Make the object track to Empty, and put the Empty at the center point of Orbit-Object. For now, this is only way of imitating ‘CurveFollow’, I think. There is the example in layer-2 of the demo blend.
I’ll try to make this script better anyway. Thank you for your comment :slight_smile:

Hi Soni

Yes, that looks better than the “UFO” always oriented in the same ‘direction’ as it is following the spiral, but still isn’t always truly the correct orientation is it?

I was thinking that (for example) for a 2 dimensional sine wave, at each “step” one could calculate the slope of the section of the “curve” and then assign it to the object via a rotation ipo. Could something like this be done in your script, except of course, for in 3 dimensions? Or could the spiral be generated as a curve to begin with using the new Python API?

Thanks for your help.

I think that is good idea. But frankly that is difficult for me to make.
I found an easy way of simulating ‘CurveFollow’ without rotationIPO.
The new demo is here.
http://runble2.tripod.co.jp/pyscript/orbitmakerDemo.zip
See the ipo datablock linked to Empty.

Thanks Soni

That works quite well, except for the first frame transition, it “jumps” a bit; but I’m sure that can be easily corrected by careful initial alignment.

I assume you intend to join your 2 scripts together. Any additional features you were planning on adding?

I appreciate the help and the script. Should come in handy, just trying to think up some applications for it now :slight_smile:

I will add GUI to this script, sooner or later. I’m not sure to join this script and Spiral Generator. I’m still new to Python API. But additional feature I’m thinking now is more accurate way of “fake-CurveFollow”.

And here is just my trial of coding with ‘map’.
This version generate two ipodata blocks, “target” and “chaser”.

"""
OrbitMaker v.1.1 (work only with 2.28a)

<How to use>
Select a mesh object(spiral, or whatever Meshes) and
push alt+p to generate two IpoDatabBlocks.
With IpoCurveEditor, link the IpoDataBlock "chaser"
to the object you want to add the movement.
And link the another IpoDataBlock "target" to the Empty.
Push alt+a on the 3dviewpoint to check the animation.
"""

###global variables###

ipname = "chaser"	#change ipodataname as you like.
ipnameb = "target"
s = 1.0
p = 2.0		#interval
f = 1		#startframe of animation.
k = 0		#0 is for loc, 1 is for dloc.

fb = f + p	
k = k*3

###functions#########

def myAddCurve(ipos,curlists):
	for n in range(3):
		curlists.append(ipos.addCurve(locs[n+k]))

def mySetPol(cls):
	for c in cls:
		c.setInterpolation('Linear')
		c.setExtrapolation('Constant')

def myAddBez(curlists,frame):
	for v in vlist:
		for n in range(3):
			curlists[n].addBezier((frame,v[n]))
			curlists[n].Recalc()
		frame += s

#####main###########

import Blender
from Blender import Object,NMesh,Ipo,Types

print
selob = Object.GetSelected()[0]
dta = selob.getData()

if type(dta) == Types.NMeshType:
	obtname = selob.name
else:	
	print "Select a Mesh object!"
	
meverts = NMesh.GetRawFromObject(obtname)

vlist=[]
for v in meverts.verts:
	vlist.append(v.co)

ipo = Ipo.New('Object',ipname);ipob = Ipo.New('Object',ipnameb)

curlist = [];curlistb = []
locs = ['LocX','LocY','LocZ','dLocX','dLocY','dLocZ']

ipoz = [ipo,ipob]; clistz = [curlist,curlistb]; fz = [f,fb]

map(myAddCurve,ipoz,clistz)
map(mySetPol,clistz)
map(myAddBez,clistz,fz)

print "done!"
print ipname + " and " + ipnameb + " were genarated."

"""
(c)Soni Bardot

[email protected]

"""

But sometimes this script generate “frozen” ipocurves. What’s wrong with this code? I appreciate if anyone point the bug out. Thanks.

I made GUI version.
http://runble2.tripod.co.jp/pyscript/orbitmakerGui.txt
and the new demo blend.
http://runble2.tripod.co.jp/pyscript/orbitmakergui.zip