Fastest way to projection matrix into CHOPs

What’s the most performant way to get a cameras projection matrix (op(“cam1”).projection(16,9)) into CHOPs?

from GitHub - DBraun/MatrixCHOP: Matrix Multiply CHOP which also demonstrates how to apply the projection matrix to values.

# me - this DAT
# scriptOp - the OP which is cooking

# press 'Setup Parameters' in the OP to call this function to re-create the parameters.
def onSetupParameters(scriptOp):

	scriptOp.destroyCustomPars()

	page = scriptOp.appendCustomPage('Custom')
	
	page.appendOBJ('Camera')
	page.appendXY('Resolution')

	return

# called whenever custom pulse parameter is pushed
def onPulse(par):
	return

def onCook(scriptOp):
	scriptOp.clear()
	
	scriptOp.numSamples = 16
	scriptOp.appendChan('mat')
		
	cam = op(scriptOp.par.Camera)
	
	resx = scriptOp.par.Resolutionx
	resy = scriptOp.par.Resolutiony
	
	world = cam.worldTransform
	world.invert()
	
	mat = cam.projection(resx,resy) * world
		
	for i, val in enumerate(mat.vals):
		scriptOp[0][i] = val
	
	return

You could also shuffle the values if you want 16 channels with one sample.

3 Likes

Thank you David ! Mich appreciated