Canvas 3d JS Library

where 3D is born!
  • rss
  • What is C3DL?
  • Download
  • Tutorials
    • Tutorial #1: Installing Canvas 3D Addon
    • Tutorial #2: A Scene and a Cube
    • Tutorial #3: Update Callback
    • Tutorial #4: Models 101
  • Development News
  • Demos
    • Typing Game V2.1
    • Typing Game V3 (0.3 Release)
    • Explorer
    • Flickr - Picking
    • Ricochet
    • FSOSS Pictures
    • Puzzler
  • Resources
  • Contact
  • About

c3dl text API

Andrew Smith | 6 September, 2008 | 15:20
Andor already mentioned we have text. The implementation is rather hacky, but it works. What we do is create a 2D canvas, render the text into it using its text API and then use that 2D canvas as the texture for the 3D canvas. The textre can be applied to any model, including a rectangle. Here’s the current c3d API for drawing text:
  • this.addFloatingText = function(text, fontStyle, fontColour, backgroundColour)
  • this.addTextToModel = function(model, text, fontStyle, fontColour, backgroundColour)
And here’s what the two of them look like when used: I’ve done a lot of cleanup this week so there isn’t much hard-coded in there (for example the text colour and style, the background colour all come from parameters now), but there are still problems:
  1. The text must be of a size where both the width and height are powers of two. So I end up making a bigger 2D canvas than needed. Right now I’m centering the text in that canvas (thanks to Jeremy Giberson for explaining the coordinate system to me), but that will cause problems when someone tries to allign a string with something when the background is transparent, since the size of the padding is unpredictable from the user’s point of view (it actually depends on the size of the rendered text). If I expand the rendered string to fill the whole 2D canvas it will end up stretched either horisontally or vertically.
  2. Neither of the functions takes a parameter to control the alpha of the text or the background. I’ll leave this to Andor as he’s been looking at that stuff.
  3. The rendered text is upside down or something on the teapot. At the meeting we’ve decided this is because of the teapot model. I think Cathy will put a fxed one into subversion and that will solve that problem.
  4. addFloatingText() doesn’t take a ‘location’ parameter to tell it where to place the floating text I don’t have any ideas about how to tell it where to go (I really don’t want to use Vectors, but that’s a problem, not a solution).
  5. By defalt the plane is rotated so that it’s not visible at all. I’ve just been setting angular velocity on it to be able to see if it works. For the user by default it should be facing the user. But that’s probably much harder than it sounds, since the camera can move all over the place.
  6. Even without location and transparency the functions already take too many paramenters. These have default values but still, they are too complicated. I tink after we see some use of these functions (in Chris’s coming demo, for example) we’ll have a better idea of what can be done to make the existing functions simpler.
  7. These two fnctions plus the create2Dcanvas() helper are in Scene. This may be a good idea for floating text, but probably not so good for a specific model. Would be nice if one of these could be moved to Model, but there are some mechanical problems with that and it’s not a big deal so I left it alone for now.
  8. To get the size of the text I need to create a <SPAN>, set the style on it, add some text to it, add it to <BODY>, measure it, and delete it from <BODY>. If I skip any of those steps I can’t get the proper size. Right now I don’t see the rendered <SPAN> in the webpage, not even a flicker, but with a lot more text it start being a visible problem. Also if there is already a style on <SPAN> it could cause a miscalculated size for the 2D canvas. This is another thing we should keep in mind.
Categories
c3dl development
Comments rss
Comments rss

« New Road Model Added to 3D Map Google Demo still coming…. »

One response

the upside down issue is a problem with the unwrap

Cathy Leung | 8 September, 2008 | 18:17

the upside down issue is a problem with the unwrap (the uv coordinates). I’m working on fixing up the models and posting them so that should be fixed soon. I think that the best way to handle the text positioning is to simply centre it on the 2D canvas. Any texture that you apply to a 3D model will be stretched funny if the unwrap is not properly done and it really can be fixed when figuring out the UV’s.

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Search

Demos

  • Explorer
  • Flickr - Picking
  • FSOSS Pictures
  • Puzzler
  • Ricochet
  • Typing Game V2.1
  • Typing Game V3 (0.3 Release)

C3DL Development News

Portable Canvas v0.2!

Portable Canvas version 0.2 is available!!

It is now a usable browser, but restricted to pages on c3dl.org only. It can display canvas elements right out of the box, and doesn’t require anything else to be on your system (not even FF3!)*. It’s only been tested on Windows XP, but in theory it should be easy [...]

Namespaces and const

As our library expands with more functions, classes and global variables, the need for namespacing increases.  I started placing code in a C3DL namespace when I wrote the matrix stack operations.  However, yesterday I was looking in the constants.js file and saw the ‘tolerance’ variable.  It’s a const variable used when comparing floats to check [...]

Tutorials

  • Tutorial #1: Installing Canvas 3D Addon
  • Tutorial #2: A Scene and a Cube
  • Tutorial #3: Update Callback
  • Tutorial #4: Models 101

Archives

C3DL Development News

Recent Comments

  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • Portable Canvas v0.2!
  • Namespaces and const
  • DAE Scenegraph
  • The Matrix Stack
  • .obj to .dae
  • 0.5 Release and Other News!
  • Tracemonkey performance
  • More memory usage improvements
  • Canvas3D crashes in tracemonkey
  • Patched one hole in floating text
  • For name spaces, my... - Jeremy Giberson
  • Great! Really really... - Edson Mattos
  • Beautiful!... - Funtomas
  • Was no need to conta... - Andrew Smith
  • Andrew, have you con... - Funtomas
  • Thanks for posting t... - Andrew Smith
  • Vlad was in town and... - Cathy Leung
  • the upside down issu... - Cathy Leung
  • Got it! the addon is... - Bill Mill
  • Yes it does. The ad... - Cathy Leung



Canvas 3d JS Library

©2007- 2008 Canvas 3d JS Library

Disclaimer: This website is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Canada License.
The Canvas 3d JS Library and Demos found on this website are licenced under the MIT License

Creative Commons License