Canvas3D provides a simple wire-frame 3D vector graphics canvas. It displays a list of Canvas3DItems, and can be transformed and animated.
Create a new canvas view.
parent |
Parent View |
bounds |
A Rect describing the position and size of this view inside the parent. |
A new Canvas3D instance.
The following methods are used to create and apply matrix transforms, for translating, scaling and rotating.
Create an identity matrix.
Create a matrix for translation.
tx |
X translation |
ty |
Y translation |
tz |
Z translation |
Create a matrix for scaling.
sX |
X scaling |
sY |
Y scaling |
sZ |
Z scaling |
Create a matrix for rotating around X axis.
ax |
X rotation |
Create a matrix for rotating around Y axis.
ay |
Y rotation |
Create a matrix for rotating around Z axis.
az |
Z rotation |
Multiply a matrix with another matrix.
A matrix.
Multiply a vector with a matrix.
vector |
A 3-element Array describing a 3D vector: |
matrix |
A matrix |
A vector.
Get/set the array of items in this canvas. The items should be instances of Canvas3DItem
Get/set the global pixel scale.
Get/set the perspective factor. Useful range is 0.0 (no perspective) to below 1.0.
Get/set the view distance. Useful range is around 2.0.
Get/set an array of transformation matrices to be applied to the whole canvas.
Update the canvas.
Function to evaluate at the beginning of the draw function.
Function to evaluate at the end of the draw function.
Start animation.
rate |
Animation rate in frames per second. If |
func |
Animation callback. This function is called once for each frame, and is passed the frame count as argument. |
See Animated canvas example below.
First a very simple example. Set up a canvas and add a slightly rotated cube.
In this example, we add a cube and a custom spiral-shape, and set up a mouseMoveAction to rotate the canvas.
A more advanced example, with three items and animation where we spin both the canvas and one of the items.
Another more advanced example.
examples by redFrik
examples by jhr
examples by kymatica