Typgraphical Illusion Python Script
Sample render using Blender 2.8 at 500 samples and 256x256 tiles.
Purpose
I created a Python script that functions in the open-source 3D computer graphics software Blender. The script utilzes the boolean intersection modifier to create perspective-based illusions in real time. The script includes an .obj file auto-export so the model can be used in other 3D programs and even 3D printing.
Functionality
The script begins by importing the necessary Blender libraries into the workspace. The script then clears the current scene with the following lines of code:
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
The following code is all of the parameters that the user would change to specifiy the given result.
#Get font from font library. Change directory here.
fnt = bpy.data.fonts.load('C:\\WINDOWS\\Fonts\\impact.ttf')
#Change text here
firstChar = "A"
secondChar = "B"
size = 3
resizeFactor = 0.986549
#Obj/mtl export directory. Change directory here
directory = "C:\\Users\\Username\\Desktop"
This is the part of the code that should change based off of the desired result. Here, you can change the actual letters of the output. The variables firstChar and secondChar store the strings that the text objects in Blender will contain. The font is also interchangable, just change the directory to the desired .ttf file. The default font is impact.ttf and is a default font that comes with most versions of Windows. The size parameter changes the scaling of the output mesh. The resizeFactor variable will have its own explanation later on. Lastly, the directory variable specifies the .obj and .mtl output directories.
The main portion of the script creates two text objects, sets their font, scales them to the extrudes them, and sets them to the set parameter size. The second text objected created is rotated 90 degrees along the z-axis to create an intersection between the two text objects. The intersection of the two perpendicular text objects is the basis for how the illusion is created.