Transform George command?

A forum dedicated to George scripting questions
Post Reply
User avatar
Lukas
Posts: 508
Joined: 14 Jan 2011, 11:15
Contact:

Transform George command?

Post by Lukas »

Is there a George command that acts like the Transform tool? Or is there a way to achieve the same thing?

I want to create a script that crops a clip to the camera, without actually cropping or changing the resolution. I would read the camera (which is not animated, just a single camera position) parameters and transform the content of the clip to match the camera frame.

I can find a command for panning (TV_Panning), but not transforming. But maybe it's hidden somewhere or maybe there is another way?

The code would look something like this, perhaps I'd need to run it on all frames and layers too, but I can't figure out how to transform:

Code: Select all

tv_CameraEnumPoints
PARSE result camX camY camAngle camSize
tv_Transform -camX -camY -camAngle camSize
  • Club Baboo
  • TVPaint Pro 11.7.2
  • macOS Ventura 13.4.1 & Windows 10
  • Cintiq 27QHD
User avatar
NathanOtano
Posts: 1187
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Transform George command?

Post by NathanOtano »

You have to use tv_brushcut and tv_brushrestore to transform pixels (yeah... sorry)

Here is a sample scritpt I made some time ago to stick a layer to the camera movement, maybe it can help

Code: Select all

tv_undoopenstack
tv_updateundo
tv_lockdisplay "Sticking Layer to Cam..."  

tv_getWidth
parse result ProjW
tv_getHeight
parse result ProjH
centX = ProjW/2
centY = ProjH/2

tv_layergetimage
curimg = result
tv_firstimage
firstimg = result
tv_lastimage
lastimg = result

curpathpoint = curimg/(lastimg-firstimg)

tv_camerainterpolation curpathpoint
parse result BaseX BaseY BaseA BaseS

FOR i=firstimg to lastimg
	Message = CONCAT("Sticking Layer to Cam : Image ",(lastimg-i))
	tv_lockdisplay Message
	curpathpoint = (lastimg-i)/(lastimg-firstimg)
	tv_camerainterpolation curpathpoint
	parse result camX camY camA camS

	tv_layerimage lastimg-i
	tv_brushcut 0 0 999999 999999 1 0 0 0

	newA = BaseA - camA
	newS = camS*100/BaseS

	tv_brushrestore "size" newS "rotate" newA "handle" camX camY

	newX = (camX - Base X)*(camS/BaseS) + camX
	newY = (camY - Base Y)*(camS/BaseS) + camY

	tv_dot newX newY
END

tv_undoclosestack
tv_unlockdisplay
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
User avatar
Lukas
Posts: 508
Joined: 14 Jan 2011, 11:15
Contact:

Re: Transform George command?

Post by Lukas »

Thanks NathanOtano, that'll push me in the right direction!

The tv_camerainterpolation command isn't available my version of TVP, but I'll work around it
  • Club Baboo
  • TVPaint Pro 11.7.2
  • macOS Ventura 13.4.1 & Windows 10
  • Cintiq 27QHD
User avatar
Lukas
Posts: 508
Joined: 14 Jan 2011, 11:15
Contact:

Re: Transform George command?

Post by Lukas »

Thanks again NathanOtano. Here's the code I use now. Works great for our purposes. Doesn't work with a moving camera obviously, but that's ok in this case.

Code: Select all

//Preparing
tv_undoopenstack
tv_updateundo
tv_lockdisplay "Cropping clip to camera..."

//Remembering current layer and frame
tv_LayerCurrentID
beginLayer = result
tv_LayerGetImage
beginImage = result

//Getting project size
tv_getWidth
parse result projectWidth
tv_getHeight
parse result projectHeight
centX = projectWidth/2
centY = projectHeight/2
tv_frameRate 666 info
PARSE result projectFramerate previewFramerate
//Getting cam info
tv_CameraEnumPoints
parse result camX camY camAngle camSize

//Loop trough all layers/instances
LayerRun = 1
i = 0
WHILE LayerRun
	tv_LayerGetID i
	curLID= result	
	IF CMP(curLID,"NONE") == 0
		//*** START RUN ON LAYER
        tv_layerSet curLID
        tv_LayerInfo
		PARSE result layerDisplay layerPosition layerOpacity layerName layerType layerStart layerEnd layerPrelighttable layerPostlighttable layerSelection
       	curImage = layerStart
       	InstanceRun = 1
		WHILE InstanceRun
			tv_layerImage curImage
			//*** START RUN ON INSTANCE
			//Show message
			Message = CONCAT("Cropping layer to camera | Layer ",(layerName))
			Message = CONCAT(Message, (" | Image : "))
			Message = CONCAT(Message, (curImage))
			tv_lockdisplay Message
			//Getting image
			tv_brushcut 0 0 projectWidth projectHeight 1 0
			//Adjusting image
			newSize = projectHeight / (projectHeight*camSize) * 100
			newAngle = -camAngle
			tv_restorebrush "size" newSize
			tv_restorebrush "handle" camX camY
			tv_restorebrush "angle" newAngle
			//Pasting image
			tv_dot centX centY
			//*** END RUN ON INSTANCE
			tv_exposureNext //Goes to next exposure
			curImage = result
			tv_exposureinfo curImage
			PARSE result type rest
			IF CMP(type,"Head") == 0
				InstanceRun = 0
			END
		END
		//Recompute exposures because a lot might be ofscreen and we need less frames now.
		tv_layerRecomputeExposure
  		//*** END RUN ON LAYER
		i = i + 1
	ELSE		
		LayerRun = 0
	END
END
//Resetting camera
tv_camerainfo projectWidth projectHeight none projectFramerate 1
tv_CameraSetPoint 0 centX centY 0 1

//Resetting layer and frame to starting position
tv_LayerImage beginImage
tv_layerSet beginLayer

//Finishing
tv_undoclosestack
tv_unlockdisplay
  • Club Baboo
  • TVPaint Pro 11.7.2
  • macOS Ventura 13.4.1 & Windows 10
  • Cintiq 27QHD
User avatar
NathanOtano
Posts: 1187
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: Transform George command?

Post by NathanOtano »

Great thanks :)
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
Post Reply