Boxshot Scripts from Command Line

Boxshot can run scripts without user interface at all. You make a text file, put the script there and feed it to Boxshot for processing. Below are some simple examples that you can use as a starting point.

Rendering a book

Lets make a script that makes a hard cover book for us:

var m = scene.root.addMesh("book", "generator.book2.HardCover");
var g = m.generator;

// assuming all the files are next to the script file we're making
g.material("Front").diffuseTexture = "front.jpg";
g.material("Side").diffuseTexture = "side.jpg";
g.material("Back").diffuseTexture = "back.jpg";

// rotate the camera
scene.camera.setAngles(55, 30);

// fit the shape to images
g.fitToImages();

// point the camera to the book
var params = {
	padding : 0.1,
	keepAspect : false
};
tools.fitToView(params);

// render the scene
var params = {"width": 800, "height": 600, "passes": 50};
scene.render("renderer.raytracer3", "result.png", params);

Save this script as a file named “book.boxshotJs”, place the three cover images mentioned above next to the script and open the terminal/console application in that folder. Then do this:

"C:\Program Files\Appsforlife\Boxshot 5\Boxshot.exe" --run book.boxshotJs

Mac users need to do this:

/Applications/Boxshot\ 5.app/Contents/MacOS/Boxshot --run book.boxshotJs

After some waiting you’ll get the “result.png” file created next to the script with your book.

Rendering turn–table animation

Boxshot has an easier way to do this, but let’s make a script that does the same. Why not?

We’ll start it the same way by setting up the scene and then will do a number of rendering, saving the output to files with different names. Here is the code:

// setup the scene first
var m = scene.root.addMesh("book", "generator.book2.HardCover");
var g = m.generator;

// assuming all the files are next to the script file we're making
g.material("Front").diffuseTexture = "front.jpg";
g.material("Side").diffuseTexture = "side.jpg";
g.material("Back").diffuseTexture = "back.jpg";

// rotate the camera
scene.camera.setAngles(55, 30);

// fit the shape to images
g.fitToImages();

// point the camera to the book
var params = {
	padding : 0.1,
	keepAspect : false
};
tools.fitToView(params);

// from here we'll rotate the camera around the shape by keeping the vertical angle and changing the horizontal one

// rendering params will always be the same
var params = {"width": 800, "height": 600, "passes": 50};
var pitch = scene.camera.vangle;
var yaw = scene.camera.hangle;
var steps = 10;
var step = 360 / steps;

for (var i = 0; i < steps; i++) {
	// setup camera
	scene.camera.setAngles(yaw + i * step, pitch);

	// make a name
	var frame = (i < 10 ? "frame0" : "frame") + i + ".png";

	// render the scene
	scene.render("renderer.raytracer3", frame, params);
}

Save the script and run it the same way as the previous one. After some time you’ll get a 10 frames turntable animation of the book.

More Scripting Tutorials