Follow Path Python constraint

  • このフォーラムに新しいトピックを立てることはできません
  • このフォーラムではゲスト投稿が禁止されています
  • このトピックは管理者もしくはモデレータによりロックされています

投稿ツリー



前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 | 投稿日時 2007/12/29 9:02
tsurubaso  新米   投稿数: 17
hello,
Bonne annee, happy new year。
良い年を。。。
助けてください。Blender Clan, Blender Artists Forum に質問をしたが答えは見つかりませんでした。
Internetを探しても。。。

Pythonを使ってCameraにFollowPAthConstraintを付けたいですCurveには。。。
ここに例が分かりにくいから。。。
このconstraintの”書き方”の例を見たいです。
よろしくお願いします。
投票数:0 平均点:0.00
前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 | 投稿日時 2007/12/29 12:39
yamyam  管理人 居住地: そうや、うちはおおさかやー  投稿数: 4403
なぜ動的にContraintをつけるんですか?
先に Camera にFollowPath Constraint 追加しておいて、あとで influence を変更するのではダメなんでしょうか。

Why do you want to add constraint to the camera dynamically?
I think you can add it to the camera in advance, and then use the influence parameter for setting available/disable.

投票数:1 平均点:0.00
前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 | 投稿日時 2007/12/29 13:28
tsurubaso  新米   投稿数: 17
ok,
I think my japanese was not clear, sorry.
I made this

without python,
It showes what I whant to do.
I made a script, and on this script I add two constraints added to the camera, the first is a "Track to" and the second is " follow path".
I found on the internet exemples of "track to" that helped me to understand how to write the scipt code for the "track to" constraint.
my problem is that
I did find any exemple of "Follow path" script...
If you have an exemple, I will be glad to see how we write it.
thanks you for your really fast answer.
投票数:0 平均点:0.00
前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 | 投稿日時 2007/12/29 13:54
yamyam  管理人 居住地: そうや、うちはおおさかやー  投稿数: 4403
引用:
I found on the internet exemples of "track to" that helped me to understand how to write the scipt code for the "track to" constraint.
Show the code.
投票数:1 平均点:0.00
前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 | 投稿日時 2007/12/30 0:06
tsurubaso  新米   投稿数: 17
Ok I write here the code,
but It is full of mistakes...
I will Edit it,


import Blender
from Blender import *
from Blender import Camera,Object, Scene, Ipo,Window, Curve, BezTriple,  Mathutils, BezTriple, Mathutils,

# script author  80% enhzflep 20% tsurubaso

#isolate the selected object
cur = Scene.getCurrent()
object = cur.objects.active

#change the position of the moved object to (0,0,0)in order to be in the center of the circle
object.setLocation (0.0,0.0,0.0)

  
#create a new camera and set it active

c = Camera.New('ortho','Camera-Vue01')
ob = Object.New('Camera','Vue01')
ob.link(c)
cur.link(ob)
cur.setCurrentCamera(ob)
c.setLens(35.00)
c.setClipStart(0.10)
c.setClipEnd(200.00)
ob.Layer = 2

#put the active object in an empty layer
StartLayer = 1
EndLayer = 2

ObList = Blender.Object.GetSelected()

for Object in ObList:
    if Object.Layer == StartLayer:
        Object.Layer = EndLayer



#add a circle

cu = Curve.New() # create new curve data
cur = Scene.getCurrent() # get current scene
obcurve = Object.New('Curve') # make curve object
obcurve.link(cu) # link curve data with this object
cur.link(obcurve) # link object into scene

center = (0,0,0)



#Here you change the radius to change the distance of the camera
radius = 1

AUTO = BezTriple.HandleTypes.AUTO
# Build four points at radius distance in the four cardnal directions
p1 = (0, -radius, 0)
p2 = (radius, 0, 0)
p3 = (0, radius, 0)
p4 = (-radius, 0, 0)

p1 = BezTriple.New(p1)
p2 = BezTriple.New(p2)
p3 = BezTriple.New(p3)
p4 = BezTriple.New(p4)

# Can't have a curve without points...
curve = c.appendNurb(p1)
curve.append(p2)
curve.append(p3)
curve.append(p4)

# Set both handles to auto for each point
for point in curve:
    point.handleTypes = [AUTO, AUTO]
curve.flagU = 1 # Set curve cyclic
c.update()
ob.loc = center # Put it where it goes
Blender.Redraw()

#set a Track to constraint
ob.constraints.append(2)
const = ob.constraints[len(ob.constraints)-1] #last constraint in the list
const[Constraint.Settings.TARGET] = object
const.__setitem__(Constraint.Settings.TRACK, Constraint.Settings.TRACKNEGZ)
const.__setitem__(Constraint.Settings.UP, Constraint.Settings.UPY)
const2 = ob.constraints[len(ob.constraints)0]

#set a Follow Path constraint(hhhhhhhhhhhhhhhhhhhhhhhhheeeeeeeeeeeeeeeeeelllllllllllllllllllllllppppppppp)

#  Used by Follow Path (FOLLOWPATH) constraint:

    * FOLLOW (bool)
    * OFFSET (float): clamped to [-maxframe:maxframe]
    * FORWARD (int): values are TRACKX, TRACKY, TRACKZ, TRACKNEGX, TRACKNEGY, TRACKNEGZ
    * UP (int): values are UPX, UPY, UPZ

# Used by Lock Track (FOLLOWPATH) constraint:

    * TRACK (int): values are TRACKX, TRACKY, TRACKZ, TRACKNEGX, TRACKNEGY, TRACKNEGZ
    * LOCK (int): values are LOCKX, LOCKY, LOCKZ





#ok I am not sure how to use the ipo but I give a try

ipo2 = Ipo.New('Object','Ipo2')

ob.setIpo(ipo2)


locy=ipo2.addCurve('LocY')

locy.setInterpolation('Bezier')

locy.setExtrapolation('Constant')

locy.addBezier((5.0,0.0))
locy.addBezier((10.0,radius.o))

Window.RedrawAll()

投票数:0 平均点:0.00
前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 | 投稿日時 2007/12/30 1:57
yamyam  管理人 居住地: そうや、うちはおおさかやー  投稿数: 4403
#set a Track to constraint
ob.constraints.append(2)
I think you can just modify this code for Followpath like below

#add a followpath constraint
const = ob.constraints.append(Constraint.Type.FOLLOWPATH)
In addition, the const(above) has constraint object. you can use it for setting this constraint. It means, you don't need below line in this situation.

const = ob.constraints[len(ob.constraints)-1] #last constraint in the list

I'm going to my bed...good night.

投票数:0 平均点:0.00
前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 | 投稿日時 2008/1/1 2:42
tsurubaso  新米   投稿数: 17
yahooo
akeomeeeeeeeeeeeeeeeeeee
Bonne annee,
happy new year!!
akemashiteomedetogozaimasuuuu
Every things looks find but it's not working.
引用:
import Blender
from Blender import *
from Blender import Camera,Object, Scene, Ipo,Window, Curve, BezTriple, Mathutils, BezTriple, Mathutils

# script author 80% enhzflep 20% tsurubaso

#isolate the selected object
cur = Scene.getCurrent()
object = cur.objects.active

#change the position of the moved object to (0,0,0)in order to be in the center of the circle
#this is not working!
object.setLocation (0.0,0.0,0.0)


#create a new camera and set it active

c = Camera.New('ortho','Camera-Vue01')
ob = Object.New('Camera','Vue01')
ob.link(c)
cur.link(ob)
cur.setCurrentCamera(ob)
c.setLens(35.00)
c.setClipStart(0.10)
c.setClipEnd(200.00)
ob.Layer = 2

#put the active object in an empty layer
StartLayer = 1
EndLayer = 2

ObList = Blender.Object.GetSelected()

for Object in ObList:
if Object.Layer == StartLayer:
Object.Layer = EndLayer



#add a circle
cu = Curve.New() # create new curve data
scn = Scene.GetCurrent() # get current scene
obcurve = scn.objects.new(cu) # make a new curve from the curve data
obcurve.link(cu) # link curve data with this object
obcurve.Layer = 2 # put curve in layer2

center = (0,0,0)



#Here you change the radius to change the distance of the camera
radius = 4

AUTO = BezTriple.HandleTypes.AUTO
# Build four points at radius distance in the four cardnal directions
p1 = (0, -radius, 0)
p2 = (radius, 0, 0)
p3 = (0, radius, 0)
p4 = (-radius, 0, 0)

p1 = BezTriple.New(p1)
p2 = BezTriple.New(p2)
p3 = BezTriple.New(p3)
p4 = BezTriple.New(p4)

# Can't have a curve without points...
curve = cu.appendNurb(p1)
curve.append(p2)
curve.append(p3)
curve.append(p4)

# Set both handles to auto for each point
for point in curve:
point.handleTypes = [AUTO, AUTO]
curve.flagU = 1 # Set curve cyclic
cu.update()
obcurve.loc = center # Put it where it goes


#set a Track to constraint
ob.constraints.append(2)
const = ob.constraints[len(ob.constraints)-1] #last constraint in the list
const[Constraint.Settings.TARGET] = object
const.__setitem__(Constraint.Settings.TRACK, Constraint.Settings.TRACKNEGZ)
const.__setitem__(Constraint.Settings.UP, Constraint.Settings.UPY)
#add a followpath constraint
const2 = ob.constraints.append(Constraint.Type.FOLLOWPATH)
const2[Constraint.Settings.TARGET] = obcurve



Window.RedrawAll()


投票数:6 平均点:0.00

通常 Re: Follow Path Python constraint

msg# 1.1.1.1.1.1.1.1
前の投稿 - 次の投稿 | 親投稿 - 子投稿.1 | 投稿日時 2008/1/3 1:21
tsurubaso  新米   投稿数: 17
ok Dragibus
help me on this
here is his code
import Blender
from Blender import *

def cercleBezier(rayon):
	h = 0.552 * rayon
	p = 1.0 * rayon
	p1 = [-p,-h,0.0,-p,0.0,0.0,-p,h,0.0]
	p2 = [-h,p,0.0,0.0,p,0.0,h,p,0.0]
	p3 = [p,h,0.0,p,0.0,0.0,p,-h,0.0]
	p4 = [h,-p,0.0,0.0,-p,0.0,-h,-p,0.0]
	cur = Curve.New('CercleBezier')
	cur.appendNurb(BezTriple.New(p1))
	cur[0].append(BezTriple.New(p2))
	cur[0].append(BezTriple.New(p3))
	cur[0].append(BezTriple.New(p4))
	cur[0].setFlagU(1)
	cur.setFlag(25)
	cur.setPathLen(250)
	return cur

scn = Scene.GetCurrent()
ob = scn.objects.active
cercle = scn.objects.new(cercleBezier(5.0))
cercle.setLocation(ob.loc)
cam = scn.objects.camera
cercle.makeParent([cam], 1)
cc = cam.constraints
cs = Constraint.Settings
cc.append(Constraint.Type.TRACKTO)
cc[0][cs.TARGET] = ob
cc[0][cs.TRACK] = 5
cc[0][cs.UP] = 1

Blender.Redraw()
#scn.play()

投票数:0 平均点:0.00

通常 Re: Follow Path Python constraint

msg# 1.1.1.1.1.1.1.1.1
前の投稿 - 次の投稿 | 親投稿 - 子投稿なし | 投稿日時 2008/1/3 12:17
yamyam  管理人 居住地: そうや、うちはおおさかやー  投稿数: 4403
Who is Dragibus?

http://blenderartists.org/forum/showthread.php?t=112591&page=2

I Locked this thread.

Please don't multipost. I'm really bored...
投票数:1 平均点:10.00

  条件検索へ


ログイン

ユーザ名:

パスワード:



パスワード紛失

クイックリンク

2021/07/01版
●Blender.org
BlenderFoundation
- Blenderのダウンロード
- 公式チュート等
- 公式マニュアル(和訳)

●ニュース(英文)
BlenderNation

●Blenderコミュニティ
blenderartists.org

●Blender Q&A
- Blender Stack Exchange

●テストビルド
Buildbot(自動生成)


●開発関連
公式開発サイト
Blender開発blog
Blender Wiki