Fri, Nov 29, 9:29 PM CST

Renderosity Forums / Poser - OFFICIAL



Welcome to the Poser - OFFICIAL Forum

Forum Coordinators: RedPhantom

Poser - OFFICIAL F.A.Q (Last Updated: 2024 Nov 29 7:57 am)



Subject: Camera scaling to whole scene


Ralf61 ( ) posted Fri, 04 July 2003 at 10:49 AM · edited Fri, 29 November 2024 at 7:50 PM

file_65463.jpg

Does anybody know, how to automaticly point and scale the camera, that the whole scene (or character or whatever) is visible?

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

file_65464.jpg

Looks interesting, though I don't quite understand the basic purpose of the "studio". I've thought before about auto-scaling cameras. Here's a starting point: First, get a formula for the basic geometry of the camera focus. (Probably, somebody has figured this out already: given the camera's focal length and Dolly Z, what is the width of its visible rectangle in Poser units? If it hasn't been figured, you should be able to figure it with a little experimentation. Once you get the formula, it should work for both the Main and Aux cameras; the others may be different. Second, within the script itself, you would need to examine the WorldVertices of all the figures and props in the scene. (It's not enough to use just the X-tran and Z-tran of each figure; the real objects may have protruding arms, or may be way off center.) Run a max-min loop on WorldVert.X and WorldVert.Y to get the bounding rectangle of actual objects. (See my Eureka script, in freestuff under keyword "Deform", for an example of using this method.) After you have this "bounding rectangle", use trigonometry to get the horizontal width perpendicular to the camera's axis. ("Extent of scene" in the figure) Then alter the camera's Dolly Z until its horizontal field of vision is just a bit larger than the scene width.

My python page
My ShareCG freebies


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"

My python page
My ShareCG freebies


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

file_65465.jpg

maclean: I know! Most other 3D-programs has such function. too bad that Poser hasn't such a feature. ockham: thanks for this. seems to need a lot of mathematics and im not sure, if it is possible to access all the neccessary values with Python. I have to check. I still have the hope, that there is a solution with the boundary boxes of the objects. what my "studio" does is very simple (even though very interesting - i hope): lety say you want to see how one character looks with different hairs, of different expressions, or several lights ... or you just need renderings from a prop from different views: thats where you need this studio. you select a file or a complete folder and everything in it will be combined, rendered and saved as a image. as an example: you want to test how vicki looks with some faces and hairs to find the best one. choose vickie-cr2 and select the folders with the hairs and faces and everything will be combined. all possible solutions .. from every angle you choose .. thanks for your help so far ...


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.

My python page
My ShareCG freebies


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.

My python page
My ShareCG freebies


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?

My python page
My ShareCG freebies


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.

My python page
My ShareCG freebies


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:

#-----------------------------------------------------------------------------

Zoom-to-extent

July 4, 2003

Suggested by maclean.

PUBLIC DOMAIN, by Ockham

Changes by Ralf61

#-----------------------------------------------------------------------------

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

Run a long max-min check on X,Y,Z of all WorldVerts

in all 'solid' objects, leaving aside the cameras, lights, and such.

Start with figures:

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


Privacy Notice

This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.