Home Pictures of 3D objects

IHere is how to create a box object:

mybox = box(   pos=vec(x0,y0,z0),
  size=vec(L,H,W) )

The given position is in the center of the box, at (x0, y0, z0). This is different from cylinder, whose pos attribute is at one end of the cylinder. Just as with a cylinder, we can refer to the individual vector components of the box as mybox.pos.x, mybox.pos.y, and mybox.pos.z. For this box, we have mybox.axis = vec(1, 0, 0). Note that the axis of a box is just like the axis of a cylinder.

For a box that isn't aligned with the coordinate axes, additional issues come into play. The orientation of the length of the box is given by the axis:box

mybox = box(  pos=vec(x0,y0,z0),  axis=vec(a,b,c),  size=vec(L,H,W) )

The axis attribute gives a direction for the length of the box, and the length, height, and width of the box are given as before.

You can rotate the box around its own axis by changing which way is "up" for the box, by specifying an up attribute for the box that is different from the up vector of the coordinate system:

mybox = box( pos=vec(x0,y0,z0),              axis=vec(a,b,c),              size=vec(L,H,W),              up=vec(q,r,s) )

With this statement, the width of the box will lie in a plane perpendicular to the (q,r,s) vector, and the height of the box will be perpendicular to the width and to the (a,b,c) vector.

Here is a full list of attributes for a box. All 3D objects have all of these attributes, other than arrow and curve:

pos Position: the center of the box; default = vec(0,0,0).

size The length, width, and height of the box; default = vec(1,1,1).

axis The axis points in the direction of the length of the box, default = vec(1,0,0). Only the direction of the axis is meaningful, not its magnitude. The length of the box is size.x, not the magnitude of the axis. An object's axis and up attributes are always perpendicular to each other. Changing the direction of axis also changes the direction of up so that the two directions always remain at right angles to each other.

up Which side of the box is "up". An object's axis and up attributes are always perpendicular to each other. Changing the direction of up also changes the direction of axis so that the two directions always remain at right angles to each other.

color Color of object, as a red-green-blue (RGB) triple: vec(1,0,0) is the same as color.red, default = vec(1,1,1), which is color.white.

opacity Opacity of object, default = 1 (fully opaque); 0 is completely transparent.

shininess 0 to 1, default 0.6; governs the amount of specular reflections.

emissive If True, local and distant lights are ignored, and the brightness is governed by the object's own color. An example of its use is to put an emissive sphere at the location of a local_light, which looks like a glowing lamp. The default for emissive is False.

visible If False, object is not displayed; e.g. mybox.visible = False
Use mybox.visible = True to make the object visible again.

texture You can specify a texture to apply to the object's surface. See the Textures documentation.

End vs center: The pos attribute for arrow, cone, cylinder, helix, and pyramid corresponds to one end of the object, whereas for a box, ring, or sphere it corresponds to the center of the object.

To display a trail or an arrow along the path of a moving object, see Attach a trail or arrow.

See Rotating an Object for an easy way to change the orientation of an object.

When you run a program, for convenience GlowScript creates a canvas on the web page and names it scene. Objects that you create are drawn on this canvas. If you have more than one canvas, you can specify in which canvas to place a new object, as in box(canvas=myscene); in JavaScript this would be box( {canvas:myscene} ). If you don't specify a canvas, the new object goes into the most recently created canvas, or the most recently selected canvas as specified by setting canvas.selected.


See the cylinder documentation for how to create an object in JavaScript.

Top of page