Ralf61 opened this issue on Jul 04, 2003 ยท 15 posts
Ralf61 posted Fri, 04 July 2003 at 10:49 AM
I'm just working on a Python Script which makes it possible to combine a so called "studio-file" with several Characters or faces or hairs and so on. The camera can automatically rotated. Its like a very intelligent batch-program.
For this it would be very nice, if the camera is adjusted correctly.
I know, that I could point the camera to one object, but this does not guarantee that everything is visible.
Any help would be very helpful
Please find below a snapshot of my "studio-batch-program" (in Python) which has until now, no name ...
ockham posted Fri, 04 July 2003 at 1:55 PM
ockham posted Fri, 04 July 2003 at 1:59 PM
"max-min loop on WorldVert.X and WorldVert.Y" should be "max-min loop on WorldVert.X and WorldVert.Z"
maclean posted Fri, 04 July 2003 at 2:25 PM
In 3d max, this is known as 'zoom extents', and is a 1-keystroke operation. One of the many, badly-needed things that poser lacks. If DAZ|Studio has it, I'll go down on my knees and cry with relief. mac
Ralf61 posted Fri, 04 July 2003 at 4:13 PM
ockham posted Fri, 04 July 2003 at 4:56 PM
Ah. Now I understand. VERY useful idea. I hope you've thought about multiplication... Numbers can get huge in this situation. Trying 20 hairs and 20 costumes and 10 lighting schemes, makes 4000 renders. At least you should warn the user of the number of combinations. On the camera question, I'm sure you can reach all the necessary values in Python. Hmmmm... You've caught my interest. I'll try to make a simple "Zoom-to-extent" script, as Maclean suggests; you can then incorporate this code in your larger script if you want.
maclean posted Fri, 04 July 2003 at 5:02 PM
I know nothing about python, so I can't help, but a 'zoom extents' shouldn't be difficult, I'd imagine. It's just a question of calculating the maximum extents of whatever's in the scene. I would assume that max, et al, do it with bounding boxes, and since poor poser at least has those, that might be a hook to start from. mac
Ralf61 posted Fri, 04 July 2003 at 5:17 PM
many thanks again for your replay. it would be great, ockham if you could find a solution. as soon as there is a "testable" version of my studio, you will hear about it first ...
ockham posted Fri, 04 July 2003 at 6:02 PM
Yup, the zoom itself turned out to be easy. (And it works -fairly- fast, which surprised me; I assumed it would take a long time to run all the vertices.) What's harder is moving the camera back and forth (DollyX and Orbit Y) so that it points straight into the center of the actual scene. Should get that solved later tonight.
ockham posted Fri, 04 July 2003 at 6:33 PM
Question: should ZTE act on all cameras in the name of "automation", or should it skip the Face and Pose, or what?
Ralf61 posted Fri, 04 July 2003 at 6:48 PM
sorry ... i'm not sure what you mean by skipping of face and pose ... the camera has to be "corrected" for each frame which has to be rendered. so there is no need for automation in the ZTE act please give me a little hint how i can help you
ockham posted Sun, 06 July 2003 at 11:21 PM
Attached Link: http://ockhamsbungalow.com/Python/ZoomToExtent.zip
In case anybody's following this thread, I made a pretty good ZTE script. See later message with "Zoom To Extent" in title, for more detail.Ralf61 posted Mon, 07 July 2003 at 2:17 AM
Thanks so much ockham ... i'll test it later and come back to you .. Again: thank you!
Ralf61 posted Mon, 07 July 2003 at 7:23 PM
Hello Again!
I just made some tests with your script, ockham. It pointed me to the right direction. But I found, that it would be better for me, not to move the camera, but instead "point it" to the center of the scene and adjust the scaling. Here is the result:
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
import math
import poser
scene = poser.Scene()
RadToDeg = 360.0 / math.pi
DegToRad = math.pi / 360.0
#-----------------------------------------------------------------------------
MaxX = -10000.0
MinX = 10000.0
MaxY = -10000.0
MinY = 10000.0
MaxZ = -10000.0
MinZ = 10000.0
for OneActor in scene.Actors():
if OneActor.IsBodyPart() or OneActor.IsProp():
if OneActor.IsLight(): continue
if OneActor.IsCamera(): continue
if OneActor.Name() == "UNIVERSE": continue
elif OneActor.Name() == "GROUND": continue
try:
OneGeom = OneActor.Geometry()
VertCount = OneGeom.NumVertices()
for i in range(VertCount):
OneWV = OneGeom.WorldVertex(i)
X = OneWV.X()
Y = OneWV.Y()
Z = OneWV.Z()
if X < MinX: MinX = X
elif X > MaxX: MaxX = X
if Y < MinY: MinY = Y
elif Y > MaxY: MaxY = Y
if Z < MinZ: MinZ = Z
elif Z > MaxZ: MaxZ = Z
except:
pass
CenterX = (MaxX + MinX) / 2.0
CenterY = (MaxY + MinY) / 2.0
CenterZ = (MaxZ + MinZ) / 2.0
ExtentX = abs(MaxX - MinX)
ExtentY = abs(MaxY - MinY)
ExtentZ = abs(MaxZ - MinZ)
try:
actor = scene.Actor("CenterBall")
print "Delete CenterBall"
except:
pass
else:
scene.SelectActor(actor)
scene.DeleteCurrentProp()
scene.LoadLibraryProp("Runtime:Libraries:Props:Primitives:Box.ppz")
actor = scene.CurrentActor()
actor.SetName("CenterBall")
actor.SetParameter("Scale", 0.0)
print "Created CenterBall"
print actor.Name()
actor.SetParameter("xTran", CenterX)
actor.SetParameter("yTran", CenterY)
actor.SetParameter("zTran", CenterZ)
cam = scene.CurrentCamera()
cam.PointAt(actor)
cam.SetParameter("Point At", 0.5)
scene.DrawAll()
print "x", cam.Parameter("DollyX").Value()
print "y", cam.Parameter("DollyY").Value()
print "z", cam.Parameter("DollyZ").Value()
print "focal", cam.Parameter("Focal").Value()
print "scale", cam.Parameter("Scale").Value()
print "ExtentX", ExtentX
print "ExtentY", ExtentY
Extent = max(ExtentX, ExtentY)
print "Extent", Extent
dx = cam.Parameter("DollyX").Value() - CenterX
dy = cam.Parameter("DollyY").Value() - CenterY
dz = cam.Parameter("DollyZ").Value() - CenterZ
d = math.sqrt(dx * dx + dy * dy + dz * dz)
print dx, dy, dz, "distance", d
f = cam.Parameter("Focal").Value()
r1 = Extent * 4 * f
r2 = d + 1.41
s = r1 / (r2*100)
print "Scale", s
cam.SetParameter("Scale", s)
This works .. mostly .. or should I say sometimes? Perhaps someone have suggestions how to improve it a little bit more?
Thanks again to you ockham, your help is very usefull ...
Ralf61 posted Tue, 08 July 2003 at 12:01 PM
Attached Link: http://www.pmrk.de/Haare/ZoomToExtentV2.py
Here is the newest Version of ZoomToExtent. Now it works pretty fine. If anyone is interested, follow the link Ralf