重映射houdini相机(解决相机缩放后渲染出现的问题)

来源:互联网 发布:开过淘宝店铺能注销吗 编辑:程序博客网 时间:2024/06/03 20:36

2016-12-17 17:40 重新上传代码

三维制作人员应该都知道,软件内的相机是不能随便缩放的,如果缩放过了必须要过滤掉缩放属性否则渲染会出现各种不正常现象,我说一下在houdini里面就用一个小脚本滤掉相机的缩放。

这是节点图


就是获得上层节点的变换信息去变换下层的节点。Blend可以过滤掉缩放,然后用Fetch第二个选项勾上获得上层所有节点的变换去变换下层节点。

如果每哥文件都连一下这个节点会很麻烦,对于重复的工作还是用脚本解决。

使用方法就是新建工具然后粘贴到Script下然后手动添加代码调用主函数。或者直接放在houdini的pylib里面然后新建工具import进来调用主函数。

写这个代码的时候借鉴了我的一个好朋友的代码让我缩小了代码量,再此感谢。

# -*- coding: utf-8 -*-import houimport toolutilsdef setfit(oldCam, resx, resy):        oldCam.setDisplayFlag(False)        oldCam.parm(oldCam.path() + "/resx").set(resx)        oldCam.parm(oldCam.path() + "/resy").set(resy)        camups = oldCam.inputAncestors()        if camups == ():                camup = oldCam        else:                camup = camups = oldCam.inputAncestors()[-1]        null = hou.node('obj').createNode('null', 'ScaleWorld')        blend = hou.node('obj').createNode('blend', 'Blend_position')        fetch = hou.node('obj').createNode('fetch', 'Fetch_NewCam')        newCam = hou.node('obj').createNode('cam', 'Render_Camera')        null.move(camup.position() + hou.Vector2(0, 1))        blend.move(oldCam.position() + hou.Vector2(0, -1))        fetch.move(oldCam.position() + hou.Vector2(0, -2))        newCam.move(oldCam.position() + hou.Vector2(0, -3))        camup.setNextInput(null)        blend.setNextInput(oldCam)        fetch.setNextInput(blend)        newCam.setNextInput(fetch)        null.setDisplayFlag(False)        blend.setDisplayFlag(False)        fetch.setDisplayFlag(False)        blend.parm(blend.path() + "/blendm1").set(63)        fetch.parm(fetch.path() + "/useinputoffetched").set(1)        oldCamPath = oldCam.path()        relativePath = newCam.relativePathTo(oldCam)        resx = " ch(\"" + relativePath + "/resx\")"        resy = " ch(\"" + relativePath + "/resy\")"        focal = " ch(\"" + relativePath + "/focal\")"        aperture = " ch(\"" + relativePath + "/aperture\")"        vm_background = " ch(\"" + relativePath + "/vm_background\")"        newCam.setParmExpressions(dict(resx=resx, resy=resy, focal=focal,   aperture=aperture, vm_background=vm_background))        newCam.parm("vm_bgenable").set(0)        newCam.parm("vm_bgenable").set(0)        newCam.parm("vm_bgenable").lock(True)def main():        view = toolutils.sceneViewer()        sel = view.selectObjects('请选择一个相机')        if len(sel) > 0:            if sel[0].type().name()=='cam':                resolution = hou.ui.readInput('set Resolution',buttons = ('Set','close'),title = 'set Resolution',initial_contents = '1920-1080',close_choice = 1,default_choice = 0)                resx = resolution[1].split('-')[0]                resy = resolution[1].split('-')[1]                oldCam = sel[0]                if resolution[0] == 0:                    setfit(oldCam, resx, resy)


     
1 0
原创粉丝点击