Moi Version 4

 From:  mkdm
8779.15 In reply to 8779.13 
Hi DIMITRI.

What you ask is already feasible in V3, but I assume that the same method works also in V4.

Is is very simple and I use it a lot in order to create high-resolution image composition.

What actually Mois miss is the chance to capture the viewport without the background, that is with the background transparent.
Ok, you can always do some "selection" and "masking" stuff in the image composition software (Affinity Photo or any other ) but it could be
better if Moi could make the capture without the background.

Anyway...this is the way I use. I have modified an old script made by someone long time ago (I don't remember who made it) :

1) I have this bunch of JS code placed into a custom Panel, but you can attach it whenever you want :

code:
<script type="text/javascript" >
	function gfx(w, h, button, shiftkey, ctrlkey, altKey)
	{		
		var v = moi.ui.getLastClickedViewport();
		if (!v) { v = moi.ui.mainWindow.viewpanel.getViewport('3D'); }
		
		var curGridDisplay = moi.grid.display;
		var curshowXYAxes = moi.grid.showXYAxes;
		var curshowAxisIcon = moi.view.showAxisIcon;
		var cursshowViewTitles = moi.view.showViewTitles;
		var curlineWidth = moi.view.lineWidth;
		var curmeshAngle = moi.view.meshAngle;
		var curshowHiddenLines = moi.view.showHiddenLines;
		var curlightingStyle = moi.view.lightingStyle;
		var curviewportBackgroundColor = moi.view.viewportBackgroundColor;
		
		var m = (ctrlkey)?1.5:1;
		if (shiftkey) {w = w*m*2; h = h*m*2;}		
		
		moi.grid.display = (button === 2 )?false:true;
		moi.grid.showXYAxes = false;
		moi.view.showHiddenLines = false;
		moi.view.showAxisIcon = false;
		moi.view.showViewTitles = false;		
		//moi.view.viewportBackgroundColor = 0xFFFFFF;
		
		if (altKey) {
			w = w*2; h = h*2;
		}
		
		v.renderToClipboard(w, h);
				
		moi.view.lineWidth = curlineWidth;
		moi.grid.display = curGridDisplay;
		moi.view.meshAngle = curmeshAngle;
		moi.grid.showXYAxes = curshowXYAxes;
		moi.view.showHiddenLines = curshowHiddenLines;	
		moi.view.showAxisIcon = curshowAxisIcon;
		moi.view.showViewTitles = cursshowViewTitles;
		moi.view.viewportBackgroundColor = curviewportBackgroundColor;
		
		var msg = "Rendered To clipboard";
		
		alert(msg);
	}	
</script>


2) I launch the code actually in this way (pressing a UI button)

code:
<moi:CommandButton onbuttonclick="gfx(1600,1200, event.button, event.shiftKey, event.ctrlKey, event.altKey);">CAPTURE</moi:CommandButton>


1600 is my default capture width
1200 is my default capture height

The capture work in this way :

0) The script will capture the last clicked viewport or the 3D viewport if there isn't any last clicked viewport

1) If you press the button with ONLY the LMB then the capture will be 1600x1200
2) If you press the button also keeping the CTRL key pressed then capture resolution will be multiplied by 1.5
3) If you press the button also keeping the SHIFT key pressed then capture resolution will be multiplied by 2
4) If you press the button also keeping the ALT key pressed then capture resolution will be multiplied by 2 again

So :
LMB alone = 1600 x 1200
LMB + CTRL = 2400 x 1800
LMB + SHIFT = 3200 x 2400
LMB + ALT = 3200 x 2400
LMB + CTRL + SHIFT = 4800 x 3600
LMB + CTRL + ALT = 4800 x 3600
LMB + SHIFT + ALT = 6400 x 4800
LMB + CTRL + SHIFT + ALT = 9600 x 7200

The image will be rendered to clipboard.

If you press the RMB instead of LMB then the capture will EXCLUDE the viewport grid.

if you want you can change the background color of the viewport by deleting the comment to this line :
"//moi.view.viewportBackgroundColor = 0xFFFFFF;" where FFFFFF is the Hex color.


Ciao!

Marco (mkdm)

EDITED: 26 Jan 2018 by MKDM