Nach nu drei oder vier Tagen (Nächten) hab ich verzweifelt versucht die mit dem PlugIn in C4D geladenen Charaktere zu animieren...
Nu hab ich ganz nebenbei auch noch bisschen Phyton gelernt ^^
mit diesem Script kann man die kontrolle ans skelett übergeben und einfach los legen...
Edit: etwas verbessert:
Code:
import c4d
#Welcome to the world of Python
def getfirstobject():
object = doc.GetFirstObject()
if object == None:
return None
while True:
if object.GetUp() != None:
object = object.GetUp()
elif object.GetPred() != None:
object = object.GetPred()
else:
break
#print "firstobject() ret:",object
return object
def getskelett():
object = getfirstobject()
if object == None:
return None
while True:
while True:
control = object.GetDown()
if object == None:
return None
elif control == None:
object = object.GetNext()
else:
break
if object.GetType() == 1019362 and control.GetType() == 1019362:
return object
else:
object = object.GetNext()
def nextjoint(joint):
if joint == None:
return None
if joint.GetDown() != None:
##
## print joint.GetDown().GetName()
##
return joint.GetDown()
elif joint.GetNext() != None:
##
## print joint.GetNext().GetName()
##
return joint.GetNext()
else:
while True:
if joint.GetUp() != None:
joint = joint.GetUp()
else:
return None
if joint.GetNext() != None:
##
## print joint.GetNext().GetName()
##
return joint.GetNext()
def getskelettjoint(jointname):
skelett = getskelett()
joint = skelett
#print "searching...",jointname
while True:
joint = nextjoint(joint)
if joint != None:
if joint.GetType() == 1019362 and joint.GetName() == jointname:
return joint
else:
return None
def getfirstmesh():
mesh = getfirstobject()
if mesh == None:
return None
while True:
#// 5140 "Null-Objekt"
#// 5100 "Polygon-Objekt"
while True:
control = mesh.GetDown()
if mesh == None:
return None
elif control == None:
mesh = mesh.GetNext()
else:
break
if mesh.GetType() == 5140 and control.GetType() == 5100:
return mesh
else:
mesh = mesh.GetNext()
def getnextmesh(lastmesh):
mesh = lastmesh
if mesh == None:
return None
mesh = mesh.GetNext()
if mesh != None:
control = mesh.GetDown()
else:
return None
while True:
while True:
if mesh == None:
return None
else:
control = mesh.GetDown()
if control != None:
break
mesh = mesh.GetNext()
if mesh.GetType() == 5140 and control.GetType() == 5100:
return mesh
else:
mesh = mesh.GetNext()
def getfirstmeshjoint(thismesh):
mesh = thismesh
if mesh == None:
return None
joint = mesh.GetDown()
while True:
#// 1019362 "Joint"
if joint.GetType() == 1019362:
return joint
joint = joint.GetNext()
if joint == None:
return None
def getnextmeshjoint(meshjoint):
joint = meshjoint
if joint == None:
return None
while True:
joint = joint.GetNext()
if joint == None:
return None
else:
if joint.GetType() == 1019362:
return joint
def getfirstpoly(thismesh):
if thismesh == None:
return None
poly = thismesh.GetDown()
while True:
if poly.GetType() == 5100:
return poly
poly = poly.GetNext()
if poly == None:
return None
def getnextpoly(poly):
if poly == None:
return None
while True:
poly = poly.GetNext()
if poly == None:
return None
if poly.GetType() == 5100:
return poly
def disableskin(thismesh):
if thismesh == None:
return False
poly = getfirstpoly(thismesh)
if poly == None:
return False
while True:
skin = poly.GetDown()
if skin != None:
skin[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = False
poly = getnextpoly(poly)
if poly == None:
return True
def enableskin(thismesh):
if thismesh == None:
return False
poly = getfirstpoly(thismesh)
if poly == None:
return False
while True:
meshtag = poly.GetFirstTag()
#meshtag[c4d.ID_CA_WEIGHT_TAG_SET] = c4d.MSG_DESCRIPTION_COMMAND
doc.SetActiveTag(meshtag)
c4d.CallButton(meshtag, c4d.ID_CA_WEIGHT_TAG_SET)
c4d.EventAdd()
skin = poly.GetDown()
if skin != None:
skin[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = True
poly = getnextpoly(poly)
if poly == None:
return True
def jointreset(mesh):
dummycounter = 10
if mesh == None:
print "ERROR: no input."
return False
#disable skin object
disableskin(mesh)
#link und reposition joints
meshjoint = getfirstmeshjoint(mesh)
if meshjoint == None:
print "ERROR: couldn't find any Joints."
return False
while True:
skelettjoint = getskelettjoint(meshjoint.GetName())
if skelettjoint == None:
print "Warning: No Joint matching found."
dummycounter -= 1
if dummycounter == 0:
print "overflow"
return False
else:
#set meshjoint position to skelettjoint position
skelettjoint.CopyMatrixTo(meshjoint)
#globalmeshjointmatrix = meshjoint.GetMg()
globalskelettjointmatrix = skelettjoint.GetMg()
meshjoint.SetMg(globalskelettjointmatrix)
#print globalmeshjointmatrix,globalskelettjointmatrix
#hidden visibility
meshjoint[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR] = 1 #//Aus
meshjoint[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 1 #//Aus
#add Contrain Expression Tag from meshjoint to skelettjoint
NewTag = c4d.BaseTag(1019364) #// 1019364 == Contraint Expression
NewTag[c4d.ID_CA_CONSTRAINT_TAG_PARENT] = True
NewTag[30001] = skelettjoint #30001 Target/Ziel
NewTag[30004] = True #// Pos ON
NewTag[30005] = True #// Scale ON
NewTag[30006] = True #// Rot ON
meshjoint.InsertTag(NewTag) #done
meshjoint = getnextmeshjoint(meshjoint)
if meshjoint == None:
break
#enable skin object
enableskin(mesh)
def main():
initialobject = doc.GetActiveObject()
mesh = getfirstmesh()
while True:
if mesh != None:
jointreset(mesh)
else:
print "All done."
initialobject.KillTag(1022749)
break
mesh = getnextmesh(mesh)
i'm not sure, but i think the data values from the bone or mesh by "Bip01 R/L ForeTwist" and "Bip01 R/L Forearm" not right... and some other looks wrong too
maybe you could take a look at these?!
[Only registered and activated users can see links. Click Here To Register...]