pythonnuke

3D Texture Mapping in The Foundry Nuke


Here's a Nuke's Python script for creating a camera’s projection matrix and using paint strokes as a texture map. The idea behind it, is to project 3D texture of all objects in the Viewer to screen space through the currently selected camera using paint strokes.

Method .getGeometry() isn't working.

How to fix it?

enter image description here

Here's a code:

import nuke
import nukescripts

def paintPoints():

    geoNode = nuke.activeViewer().node()       
    camera = nuke.selectedNode()

    if not camera.Class() in ('Camera', 'Camera2'):
        nuke.message('Por favor, seleccione un nodo de la cámara primera')
        return

    geoKnob = geoNode['geo']
    objects = geoKnob.getGeometry()

    if not objects:
        nuke.message('No se han encontrado geometría en %s' % geoNode.name())

    pts = []

    for o in objects:    
        objTransform = o.transform()

        for p in o.points():    
            worldP = objTransform * nuke.math.Vector4(p.x, p.y, p.z, 1)
            pts.append([worldP.x, worldP.y, worldP.z])

    curvesKnob = nuke.createNode('RotoPaint')['curves']
    task  = nuke.ProgressTask('painting points')

    for i, pt in enumerate(pts):
        if task.isCancelled():
            break

        task.setMessage('painting point %s' % i)
        stroke = nuke.rotopaint.Stroke(curvesKnob)
        pos = nukescripts.snap3d.projectPoint(camera, pt)
        ctrlPoint = nuke.rotopaint.AnimControlPoint(pos)
        stroke.append(ctrlPoint)
        curvesKnob.rootLayer.append(stroke)
        task.setProgress(int(float(i)/len(pts)*100))

paintPoints()

enter image description here


Solution

  • Since The Foundry engineers deprecated geo knob as well as its .getGeometry() method, we should use .getGeometryNodes() method instead.

    If you need more detailed information about it go here and write your question.