Groups > Design > Adobe Acrobat 3D > advanced: JavaScript for billboards?




advanced: JavaScript for billboards?

advanced: JavaScript for billboards?
Tue, 1 Apr 2008 15:58:12 -0700
Hi, I have an interest in implementing billboards in 3-d PDF figures. This
allows us to do things like eg. place soft blobby textures at particle positions
to produce really nice visualisations of star clusters etc.

I've made some progress, but need help / ideas for going further.

So far, I can import a VRML file with a textured quad at the origin of the
coordinate system. By querying the camera view direction on every redraw, I can
apply a rotation to the quad so that it always faces the camera. That code looks
roughly like this:

// rightObjsArray contains the meshes the quad

// undo the previous rotation/s
  for (j = 0; j < rightObjsArray.length; j++) {
rightObjsArray[j].transform.rotateAboutVectorInPlace(-angle, normal); }

// fetch camera
  var camera = scene.cameras.getByIndex(0);

// calculate and normalise camera view direction
  var camdir = camera.position.subtract(camera.targetPosition);
  camdir.normalize();

// create a z-aligned vector
  var zax = new Vector3(0., 0., 1.);

// my quad is drawn in the XY plane, so the following calculates
  // a normal (vector) to rotate about, and the angle of rotation,
  // such that our quad's Z axis will become aligned with the camera
  // view direction
  normal = camdir.cross(zax);
  angle = -Math.acos(camdir.dot(zax));

// apply the rotation to objects, eg...
  for (j = 0; j < rightObjsArray.length; j++) {
rightObjsArray[j].transform.rotateAboutVectorInPlace(angle, normal); }

Now, this works pretty well, but there are two things that I still need to do:

1. rotate the quad in the viewing plane (plane for which the camera view
direction is a normal) so that it is "upright" on the screen. I wanted
to use the camera.up vector for this but my calculations show that camera.up is
not orthogonal to the camera view direction I calculate above.

2. get it working for quads NOT at the origin of the coordinate system. I had
hoped I could do this with a transform of the object to the origin, do the
rotation, then transform back to the original position, but I can't seem to come
up with any properties of the quad accessible from JavaScript that let me do
this.

I would be delighted to hear suggestions on the above, either in this forum, or
directly by email to

david.g.barnes at google's mail service

thanks -

Post Reply
about | contact