Getting Maya camera information into Houdini Engine

   5127   3   2
User Avatar
Member
818 posts
Joined: 9月 2013
Offline
This question comes up occasionally, so I thought I'd post up an example. Houdini Engine doesn't have support for inputting cameras (yet?). However, since all the Maya camera information is available as attributes, it's not difficult to create an asset that takes in the Maya camera information as asset parameters, and use these parameters to set the Houdini camera.

I've made an example asset that demonstrate this. The asset simple takes in a Maya geometry and the camera parameters, and cull the geometry based on the camera frustum.

The following MEL can be used to connect the Maya camera to the Houdini Engine asset.
proc connect_camera(string $camera, string $engine_asset)
{
string $children = `listRelatives -shapes -type camera $camera`;
string $camera_shape = $children;

connectAttr -f ($camera + “.translate”) ($engine_asset + “.houdiniAssetParm_camera_translate”);
connectAttr -f ($camera + “.rotate”) ($engine_asset + “.houdiniAssetParm_camera_rotate”);
connectAttr -f ($camera_shape + “.focalLength”) ($engine_asset + “.houdiniAssetParm_focal_length”);
connectAttr -f ($camera_shape + “.cameraAperture”) ($engine_asset + “.houdiniAssetParm_camera_aperture”);
connectAttr -f ($camera_shape + “.nearClipPlane”) ($engine_asset + “.houdiniAssetParm_near_plane”);
connectAttr -f ($camera_shape + “.farClipPlane”) ($engine_asset + “.houdiniAssetParm_far_plane”);
}

connect_camera(“camera1”, “camera_culling1”);

Hope this helps some of you out there.

Attachments:
camera_culling.jpg (154.0 KB)
camera_culling.ma (12.0 KB)
camera_culling.hda (12.5 KB)

Andrew / アンドリュー
User Avatar
Member
52 posts
Joined: 6月 2012
Offline
Thx Andrew for posting this solution. So far I've been creating a camera in my otl and promote parameters to finally use some expression in Maya to apply the camera settings but I'm happy to see an other way.

Thanks again !
Chris
User Avatar
Member
14 posts
Joined: 1月 2016
Offline
It seems listRelatives returns a string. So the script ends with this error:
// Error: line 3: Cannot convert data of type string to type string. //

This worked for me with Maya 2020.1
:
proc connect_camera(string $camera, string $engine_asset)
{
string $children[] = `listRelatives -shapes -type camera $camera`;
string $camera_shape = $children[0];

connectAttr -f ($camera+".translate") ($engine_asset+".houdiniAssetParm_camera_translate");
connectAttr -f ($camera+".rotate") ($engine_asset+".houdiniAssetParm_camera_rotate");
connectAttr -f ($camera_shape+".focalLength") ($engine_asset+".houdiniAssetParm_focal_length");
connectAttr -f ($camera_shape+".cameraAperture") ($engine_asset+".houdiniAssetParm_camera_aperture");
connectAttr -f ($camera_shape+".nearClipPlane") ($engine_asset+".houdiniAssetParm_near_plane");
connectAttr -f ($camera_shape+".farClipPlane") ($engine_asset+".houdiniAssetParm_far_plane");
}

connect_camera("camera1","asset1");
Edited by Haki - 2020年5月29日 05:35:41
3D Generalist
https://hristo.one [hristo.one]
User Avatar
スタッフ
525 posts
Joined: 8月 2019
Offline
I think part of the error message above may have been eaten by the forum. The error is:

// Error: line 3: Cannot convert data of type string[] to type string. //

Thanks for posting. That is indeed the correct solution.
  • Quick Links