PDA

View Full Version : Camera Background Plane (Maya Style)


Masquerade
01-24-2008, 11:34 PM
Hi everyone,
I have written a simple script which creates a camera and a background plane attached to it. Plane stays in the place where camera's far range is and scales according to the FOV.

Script creates a wire between length and width values of plane and an expression controller for length value.

I have two problems which I couldnt find solution.
- I want to take aspect ratio of the current output size (getRendImageAspect()) and use this value in the expression wiring string. Since they are strings, I couldnt figure out how to do it.
-First Time I run the script, everything is ok. But if I want to make another Camera with BG and re-run the script. It messes everything. How can I make it create uniqe names and connections everytime I run it.

Here is the code:


difmap = selectBitMap ()
if difmap != undefined do
(
macros.run "Lights and Cameras" "Camera_CreateFromView"
$.name = "camera_with_bg"
bgcam = $camera_with_bg

bgcam.fov.controller = bezier_float ()
bgcam.farrange.controller = bezier_float ()
bgp = plane()
bgp.name = "bg_plane"
bgp.renderable = off
bgp.showFrozenInGray = false
freeze bgp
bgp.rotation = bgcam.target.rotation
bgp.pos = bgcam.pos
in coordsys local move bgp [0,0,-bgcam.farrange]
bgp.parent = bgcam
paramWire.connect bgcam.baseObject[#Far_Env_Range] bgp.pos.controller[#Z_Position] "-Far_Env_Range"
ab = getRendImageAspect()

$bg_plane.length.controller = Float_Expression ()
$bg_plane.length.controller.AddScalarTarget "Angle_a" $camera_with_bg.fov.controller
$bg_plane.length.controller.AddScalarTarget "Edge_b" $camera_with_bg.farrange.controller
$bg_plane.length.controller.SetExpression "((Edge_b/sin(180 - (90+((radToDeg (Angle_a))/2)))) * (sin((radToDeg (Angle_a))/2)) * 2) / 1.33"

paramWire.connect bgp.baseObject[#length] bgp.baseObject[#width] "length * 1.33"



text_mat = bitmaptexture ()
text_mat.bitmap = difmap

bgp_mat = standardMaterial diffusemap:text_mat selfIllumAmount:100 showInViewport:true
bgp.material = bgp_mat
)


Thank everyone for help and support in advance.

focomoso
01-25-2008, 01:12 AM
Just looking at the code (no testing) two things come to mind:

Replace:
$.name = "camera_with_bg"
bgcam = $camera_with_bg

with:
bgcam = $

That should ensure that you're working with the camera you just created.

And with the plane, replace all the lines that start with:

$bg_plane.

with:

bgp.

Once you have your two objects, you don't need to be looking at the $ anymore. Just use the variables you've already created.

fferro2
01-25-2008, 02:32 PM
macros.run "Lights and Cameras" "Camera_CreateFromView"



This line returns always "undefined" but, it you have any camera selected or, you are executing it from a camera view, it will do nothing.
So, you would have to include it inside a if ... sentence, and may be deselect any object before.
I guess there are another (and better) ways to create a camera from view.
There is not good to select objects with "$", better to do it with "selection"

fferro2
01-25-2008, 02:44 PM
From here: http://forums.cgsociety.org/showthread.php?f=98&t=228177&highlight=FOV (http://http://forums.cgsociety.org/showthread.php?f=98&t=228177&highlight=FOV)

"Here is some code that does the same as the View>Create Camera From View, but using a simples, Free camera without a target:"

newCam = FreeCamera() --create new free camera
newCam.transform = inverse (viewport.getTM()) --set the transform (PRS) to the viewport's ones
newCam.FOV = viewport.getFOV() --set the FOV to match the view
viewport.setCamera newCam --set the camera into the current viewport

Masquerade
01-25-2008, 11:26 PM
Thank you everyone. That was very helpful. I revised the script. Though I still have one remaining question. Is it possible to create variables for aspect ratio or something else in order to be used in the strings?

here is the revised piece. I will next try to add custom attributes to change the fitting style of the image to the background. Thanks again to everyone.


macroscript TIK_CameraBG
category: "Tik Works"
tooltip: "Maya Style Camera BG"
(
animbuttonstate = false
difmap = selectBitMap ()
if difmap != undefined do
(
bgcam = FreeCamera() --create new free camera
bgcam.transform = inverse (viewport.getTM()) --set the transform (PRS) to the viewport's ones
bgcam.FOV = viewport.getFOV() --set the FOV to match the view
viewport.setCamera bgcam --set the camera into the current viewport

bgcam.name = uniquename "camera_with_bg"


bgcam.fov.controller = bezier_float ()
bgcam.farrange.controller = bezier_float ()
bgp = plane()
bgp.name = uniquename "bg_plane"
bgp.primaryVisibility = false
bgp.receiveShadows = false
bgp.castShadows = false
bgp.showFrozenInGray = false
bgp.motionBlurOn = false
freeze bgp
bgp.rotation = bgcam.rotation
bgp.pos = bgcam.pos
in coordsys local move bgp [0,0,-bgcam.farrange]
bgp.parent = bgcam
paramWire.connect bgcam.baseObject[#Far_Env_Range] bgp.pos.controller[#Z_Position] "-Far_Env_Range"
ab = getRendImageAspect()

bgp.length.controller = Float_Expression ()
bgp.length.controller.AddScalarTarget "Angle_a" bgcam.fov.controller
bgp.length.controller.AddScalarTarget "Edge_b" bgcam.farrange.controller
bgp.length.controller.SetExpression "((Edge_b/sin(180 - (90+((radToDeg (Angle_a))/2)))) * (sin((radToDeg (Angle_a))/2)) * 2) / 1.33"

paramWire.connect bgp.baseObject[#length] bgp.baseObject[#width] "length * 1.33"



text_mat = bitmaptexture ()
text_mat.bitmap = difmap

bgp_mat = standardMaterial diffusemap:text_mat selfIllumAmount:100 showInViewport:true
bgp.material = bgp_mat
)
)

fferro2
01-26-2008, 01:09 PM
1.33 Uhmmm not always...
replace it with getRendImageAspect()

Where do you want to use it as string?

Masquerade
01-26-2008, 02:57 PM
1.33 Uhmmm not always...
replace it with getRendImageAspect()

exactly...

I want to use getRendImageAspect() value in here:
---------------------------------------------------------------------------------------
bgp.length.controller.SetExpression "((Edge_b/sin(180 - (90+((radToDeg (Angle_a))/2)))) * (sin((radToDeg (Angle_a))/2)) * 2) / 1.33"
---------------------------------------------------------------------------------------

and here:
----------------------------------------------------------------------------------
paramWire.connect bgp.baseObject[#length] bgp.baseObject[#width] "length * 1.33"
----------------------------------------------------------------------------------
since they are in strings, I cannot use a variable referring to the main script.

fferro2
01-29-2008, 01:53 PM
tempVar = "((" + Edge_b + "/sin(180 - (90+((radToDeg (" + Angle_a + "))/2)))) * (sin((radToDeg (" + Angle_a + "))/2)) * 2) / " + getRendImageAspect() as string
bgp.length.controller.SetExpression tempVar


if Edge_b or Angle_a are floaters or integerers, add as string after them

Masquerade
01-29-2008, 09:58 PM
just what I was looking for! Thank you very much. I will share my progress here. Thanks again.

Masquerade
01-29-2008, 10:07 PM
Here it is,

it is simple though may help someone.


-- date: 30.01.2008
-- script: Tik Works Alternative Camera BG (Maya Style)
-- version: 1.6
-- written by: Arda Kutlu
-- e-mail: ardakutlu@gmail.com

macroscript TIK_CameraBG
category: "Tik Works"
tooltip: "Maya Style Camera BG"
ButtonText: "Maya Style Camera BG"
(
animbuttonstate = false
difmap = selectBitMap ()
if difmap != undefined do
(
bgcam = FreeCamera() --create new free camera
bgcam.transform = inverse (viewport.getTM()) --set the transform (PRS) to the viewport's ones
bgcam.FOV = viewport.getFOV() --set the FOV to match the view
viewport.setCamera bgcam --set the camera into the current viewport

bgcam.name = uniquename "camera_with_bg"


bgcam.fov.controller = bezier_float ()
bgcam.farrange.controller = bezier_float ()
bgp = plane()
bgp.name = uniquename "bg_plane"
bgp.primaryVisibility = false
bgp.receiveShadows = false
bgp.castShadows = false
bgp.showFrozenInGray = false
bgp.motionBlurOn = false
freeze bgp
bgp.rotation = bgcam.rotation
bgp.pos = bgcam.pos
in coordsys local move bgp [0,0,-bgcam.farrange]
bgp.parent = bgcam
paramWire.connect bgcam.baseObject[#Far_Env_Range] bgp.pos.controller[#Z_Position] "-Far_Env_Range"

tempex = "((Edge_b/sin(180 - (90+((radToDeg (Angle_a))/2)))) * (sin((radToDeg (Angle_a))/2)) * 2) / " + getRendImageAspect() as string

bgp.length.controller = Float_Expression ()
bgp.length.controller.AddScalarTarget "Angle_a" bgcam.fov.controller
bgp.length.controller.AddScalarTarget "Edge_b" bgcam.farrange.controller
bgp.length.controller.SetExpression tempex

temppar = "length *" + getRendImageAspect() as string

paramWire.connect bgp.baseObject[#length] bgp.baseObject[#width] temppar



text_mat = bitmaptexture ()
text_mat.bitmap = difmap

bgp_mat = standardMaterial diffusemap:text_mat selfIllumAmount:100 showInViewport:true
bgp.material = bgp_mat
)
)

CGTalk Moderation
01-29-2008, 10:07 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.