CGTalk > Software > Autodesk 3ds max
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 01-28-2013, 09:38 PM   #1
Mike Truly
Expert
Mike Truly
Truly Media
Crested Butte, CO, USA
 
Join Date: Apr 2004
Posts: 982
Create Object from Camera Cone?

Is there any tool for automatically creating an object which duplicates a Camera's cone?

The PFlow Camera Culling operator doesn't work for me so I need to create an object to use for culling particles in PFlow based on the camera view. If the camera was squared up to the world axes, it would be easy to create the object by hand. But since the camera is not, it would be nice if there was a tool to automatically create an object based on the camera's cone.

Thanks for any ideas!
__________________
Sincerely,

Mike Truly
-----------------------
Truly Media
970.349.5651
www.trulymedia.com
 
Old 01-29-2013, 08:36 AM   #2
Swordslayer
isKindOf Artist
 
Swordslayer's Avatar
portfolio
Vojtech Cada
3D generalist
Czech Republic
 
Join Date: Jun 2006
Posts: 365
Send a message via ICQ to Swordslayer
Maybe a script could help here. For a standard target camera (provided that the aspect ratio used in common render parameters is the same as the one used for rendering), the most basic version would be something like

Code:
fn cameraCone cam = ( local dist = distance cam.target.pos cam.pos local width = 2 * dist * tan (cam.fov/2) local depth = (width * renderHeight)/renderWidth pyramid pos:cam.target.pos dir:cam.dir \ height:dist width:width depth:depth ) cameraCone $Camera01
__________________
Blog :: LinkedIn profile
 
Old 01-29-2013, 10:12 AM   #3
Swordslayer
isKindOf Artist
 
Swordslayer's Avatar
portfolio
Vojtech Cada
3D generalist
Czech Republic
 
Join Date: Jun 2006
Posts: 365
Send a message via ICQ to Swordslayer
If you'd want to move the camera and/or change its fov or target distance, here is the same converted to controllers:

Code:
fn setupCameraCone cam = ( local cameraCone = pyramid pos:cam.target.pos dir:cam.dir parent:cam local ctrl = float_script() local ctrlPos = position_constraint() ctrl.addObject #cam cam ctrlPos.constraints.appendTarget cam.target 100.0 cameraCone.height.controller = ctrl cameraCone.height.controller.script = "(distance cam.target.pos cam.pos)" cameraCone.width.controller = (ctrl = copy ctrl) cameraCone.width.controller.script += " * tan(cam.fov/2) * 2" cameraCone.depth.controller = (ctrl = copy ctrl) cameraCone.depth.controller.script += " * (renderHeight as float)/ renderWidth" cameraCone.position.controller = ctrlPos cameraCone ) setupCameraCone $Camera001
__________________
Blog :: LinkedIn profile
 
Old 01-29-2013, 03:58 PM   #4
Mike Truly
Expert
Mike Truly
Truly Media
Crested Butte, CO, USA
 
Join Date: Apr 2004
Posts: 982
Vojtech,

Thank you very much for this great tool! I am not a scripter so I really appreciate you writing this.

Thanks again.
__________________
Sincerely,

Mike Truly
-----------------------
Truly Media
970.349.5651
www.trulymedia.com
 
Old 01-29-2013, 04:49 PM   #5
Swordslayer
isKindOf Artist
 
Swordslayer's Avatar
portfolio
Vojtech Cada
3D generalist
Czech Republic
 
Join Date: Jun 2006
Posts: 365
Send a message via ICQ to Swordslayer
My pleasure, let me know if you would like to change anything to better fit your purpose.
__________________
Blog :: LinkedIn profile
 
Old 01-29-2013, 08:00 PM   #6
Mike Truly
Expert
Mike Truly
Truly Media
Crested Butte, CO, USA
 
Join Date: Apr 2004
Posts: 982
Vojtech,

*So far, I have only used the first script you wrote.

So from my understanding of the script you wrote, it creates an object based on the camera cone of an object called 'Camera01'. If I want to create an object based on the camera cone of a differently named camera, I must edit the script to use the proper name in order for it to work.

Can the script be made to work on the selected camera instead? This would be easier than having to edit the script each time.

After the cone object is made from the camera cone, I must convert to Editable Poly or Editable Mesh and edit the object a bit so the cone is slightly larger than the original camera cone. The reason the cone object must be larger than the camera cone is so that future particles created within the new cone object do not pop on in the resulting camera render. If it's a bit larger than the camera cone, the particles will appear outside the view of the camera instead of popping on in view. I also must link the new cone object to the camera.

If it was possible to make the resulting cone object slightly larger and linked to the selected camera, that would be great too. Perhaps a percentage in the script would make the cone 10% larger than the original camera cone?

Thanks again for your script!!
__________________
Sincerely,

Mike Truly
-----------------------
Truly Media
970.349.5651
www.trulymedia.com
 
Old 01-29-2013, 08:24 PM   #7
Swordslayer
isKindOf Artist
 
Swordslayer's Avatar
portfolio
Vojtech Cada
3D generalist
Czech Republic
 
Join Date: Jun 2006
Posts: 365
Send a message via ICQ to Swordslayer
The second one already does the linking together with automatically changing the cone dimensions based on camera/target distance and change in aspect ratio or fov. Basically, it's just a function and a function call; to make it work on a selection, it would be enough to replace the sample $Camera01 token with $ or selection. However if used on something that's not a camera it would only print some error message in the listener.

I've wrapped it in a simple UI to make it more user friendly, did some basic error-checking and added the cone scaling in percentage:

Code:
try destroyDialog ::cameraPicker catch() rollout cameraPicker "" width:100 ( pickButton pbtPickCamera "Pick Camera" width:80 autoDisplay:true align:#left spinner spnScale "Scale" range:[0, 1e3, 110] fieldWidth:40 align:#left button btnCreate "Create Cone" width:80 height:25 align:#left offset:[0,5] fn setupCameraCone cam scale: = ( local cameraCone = pyramid pos:cam.target.pos dir:cam.dir parent:cam scale:scale local ctrl = float_script() local ctrlPos = position_constraint() ctrl.addObject #cam cam ctrlPos.constraints.appendTarget cam.target 100.0 cameraCone.height.controller = ctrl cameraCone.height.controller.script = "(distance cam.target.pos cam.pos)" cameraCone.width.controller = (ctrl = copy ctrl) cameraCone.width.controller.script += " * tan(cam.fov/2) * 2" cameraCone.depth.controller = (ctrl = copy ctrl) cameraCone.depth.controller.script += " * (renderHeight as float)/ renderWidth" cameraCone.position.controller = ctrlPos cameraCone ) on btnCreate pressed do ( local cam = pbtPickCamera.object if cam == undefined do return messageBox "No object picked." if NOT isKindOf cam Camera do return messageBox "Not a camera." if cam.target == undefined do return messageBox "Not a target camera." setupCameraCone cam scale:([0.01, 0.01, 0.01] * spnScale.value) ) ) createDialog cameraPicker
__________________
Blog :: LinkedIn profile
 
Old 01-29-2013, 10:32 PM   #8
Mike Truly
Expert
Mike Truly
Truly Media
Crested Butte, CO, USA
 
Join Date: Apr 2004
Posts: 982
Vojtech,

That works great!! Thank you very much for this tool.
__________________
Sincerely,

Mike Truly
-----------------------
Truly Media
970.349.5651
www.trulymedia.com
 
Old 01-29-2013, 10:51 PM   #9
Mike Truly
Expert
Mike Truly
Truly Media
Crested Butte, CO, USA
 
Join Date: Apr 2004
Posts: 982
Vojtech,

I just ran into an issue with this.

The cone should ideally be created based on the far clipping plane rather than the camera target distance. (Or perhaps the user could type in a distance for the far end of the cone).

For example, if I have an aircraft flying and a camera linked to the aircraft and looking at the aircraft... the camera target is at the aircraft but we want the new culling cone to extend far beyond the aircraft so particle clouds can be created behind the aircraft.

I can make the script work if I temporarily change the camera target distance, but I must save the original target distance and replace it when I'm done creating the new culling cone. It's easier not to mess with the camera target but rather use the far clipping plane.

Thanks again.
__________________
Sincerely,

Mike Truly
-----------------------
Truly Media
970.349.5651
www.trulymedia.com
 
Old 01-30-2013, 07:24 AM   #10
Swordslayer
isKindOf Artist
 
Swordslayer's Avatar
portfolio
Vojtech Cada
3D generalist
Czech Republic
 
Join Date: Jun 2006
Posts: 365
Send a message via ICQ to Swordslayer
Sure, not a problem at all:

Code:
try destroyDialog ::cameraPicker catch() rollout cameraPicker "" width:100 ( pickButton pbtPickCamera "Pick Camera" width:80 autoDisplay:true align:#left spinner spnScale "Scale" range:[0, 1e3, 110] fieldWidth:40 align:#left button btnCreate "Create Cone" width:80 height:25 align:#left offset:[0,5] fn setupCameraCone cam scale: = ( local cameraCone = pyramid pos:cam.target.pos dir:cam.dir parent:cam scale:scale local ctrl = float_script() local ctrlPos = position_script() ctrl.addObject #cam cam ctrlPos.addObject #cam cam cameraCone.height.controller = ctrl cameraCone.height.controller.script = "cam.farclip" cameraCone.width.controller = (ctrl = copy ctrl) cameraCone.width.controller.script += " * tan(cam.fov/2) * 2" cameraCone.depth.controller = (ctrl = copy ctrl) cameraCone.depth.controller.script += " * (renderHeight as float)/ renderWidth" cameraCone.position.controller = ctrlPos cameraCone.position.controller.script = "(cam.pos - cam.dir * cam.farclip) * inverse cam.transform" cameraCone ) on btnCreate pressed do ( local cam = pbtPickCamera.object if cam == undefined do return messageBox "No object picked." if NOT isKindOf cam Camera do return messageBox "Not a camera." setupCameraCone cam scale:([0.01, 0.01, 0.01] * spnScale.value) ) ) createDialog cameraPicker
__________________
Blog :: LinkedIn profile
 
Old 01-30-2013, 03:34 PM   #11
Mike Truly
Expert
Mike Truly
Truly Media
Crested Butte, CO, USA
 
Join Date: Apr 2004
Posts: 982
Excellent! Thanks again for your work on this... works great!
__________________
Sincerely,

Mike Truly
-----------------------
Truly Media
970.349.5651
www.trulymedia.com
 
Old 01-30-2013, 03:34 PM   #12
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 04:47 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.