Canvas 3d JS Library

WebGL made easy!
  • rss
  • What is C3DL?
  • Download
  • Tutorials
    • Tutorial #1: WebGL Browsers
    • Tutorial #2: A simple scene
    • Tutorial #3: Callback
    • Tutorial #4: Models
    • Tutorial #5: Light effects
    • Tutorial #6: Picking
    • Tutorial #7: Materials
    • Tutorial #8: Particle Systems
    • Tutorial #9: Camera Basics
    • Tutorial #10: Advanced FreeCamera
    • Tutorial #11: OrbitCamera
    • Tutorial #12: Advanced Camera Functions
  • Development News
  • Documentation
  • Community
  • Resources
  • Contact
  • About

Lines and Points

Andor Salga | 17 March, 2009 | 11:20
We have spent quite a bit of effort writing code which loads and renders models. However, users may want to draw simpler things such as lines and points. One example of rendering points and lines would include the mocap demo. The demo renders a sphere for each marker, which is a bit of a waste, even if the spheres are low quality. Points can be rendered instead, potentially speeding up rendering times. Lines could also be used for this demo to further ease the understanding how the model is structured. Before adding this functionality, I ask for feedback on the following requirements.

Requirements for points

  • Must be simple to use
  • Must be able to specify position
  • Must be able to specify point color
  • Must be able to specify point size

Optional features for points

  • Possibly allow attenuation factors for all points

Requirements for lines

  • Must be able to specify start and end points
  • Must be able to specify line color
  • Must be able to specify line width

Optional features for lines

  • Possibly allow user to specify different colors for each point in a line to create a gradient of color change in the line
  • Possibly allow user to specify stippling

Concerns

It is possible users may want to set things like velocity and angular velocity for points and lines, but I don’t see it as very likely. For example, specifying start and end points for a line and allowing users to rotate it would increase the object’s complexity too much. Does it rotate about the start point, middle or end? Should the user be able to specify it? This can be provided in the future, but for now, we will keep the implementation and interface as simple as possible. Taking the earlier notes into account, how will the user want to draw point and lines? I provided a couple of scenarios how a user would specify these primitives:

Interface 1 – Provide drawing functions

// user creates and manages an array of coordinates. var arr = [0,0,0, 1,0,0, 2,0,0, 3,0,0]; // all points which will be drawn will have size = 5 c3dl.setPointSize(5); // draw all following points red. c3dl.setPointColor(1,0,0,1); // this will draw 4 red points with size 5 along the x axis. c3dl.drawPoints(arr);

Advantages

  • It’s straightforward
  • Encourages users to group point sizes together, reducing state changes.

Disadvantages

  • Setting colors of individual points may be awkward
  • To make the library call drawPoints, the user would have to specify a callback function, which is counter intuitive.

interface 2 – provide classes

var point = new c3dl.Point(); // set this points size to 5 point.setSize(5); // set its color to red and fully opaque. point.setColor([1,0,0,1]); // place it at world origin point.setPosition([0,0,0]); // rendering is handled by the library scn.addObjectToScene(point); The Point class would also offer accessor functions to get its size, color and position. Also, if points are implemented using this method, visibility accessor and mutator functions would have to be provided. var line = new c3dl.Line(); line.setStart([0,0,0]); line.setEnd([10,0,0]); line.setColor([0,1,0,1]); line.setWidth(2); scn.addObjectToScene(line);

Advantages

  • Mostly just advantages of using objects

Disadvantages

  • If a large number of points and lines are specified, this could slow things down, but this needs to be tested

Issues and Next Steps

Technical Issues

When implementing the particle system I couldn’t use the point primitives since they were not supported. Quadrilaterals had to be made so we could have a textured quad which also had to be billboarded. When I first started thinking about how to make points, I was thinking we could use the particle class. Then I remembered that even thought ES does not support point primitives, it still supports point types. I set objects to render using points instead of triangles and saw they are perfect for this purpose as they are automatically billboarded. Attenuation factors can also be set and are calculated by ES.

Picking Points

When a user wants to pick an object, they can do so because the object is composed of triangles. When the user clicks on the canvas, a ray is shot into the scene and any object which has triangles which intersect that ray is considered picked. Points do not have triangles, so one option is placing a bounding sphere on each point. Since the bounding sphere/ray test is already written, it can be used to test if the user clicked on the point. Another option to add point picking is write a separate function such as: rayIntersectsPoint(point, rayOrigin, rayDirection);

Picking Lines

I see drawing lines as a necessity of the library, however picking them must be put off due to other priorities. I imagine picking a line would not be too difficult: A vector collinear with the drawn line and another vector from one of the line’s points pointing towards the camera can define a plane. The ray shot into the scene can then be checked to see if it lies on the plane, if so, the line is picked.

Line Stippling

Line stippling would be a nice feature, unfortunately ES does not support it. Providing the same functionality in the library seems unlikely as there are already too many things to add and iron out. Since this is just a feature which would be nice to have, it won’t be included in the library for the time being.

Next Steps

I see point and line classes more intuitive and offer more advantages than the first method. Therefore, unless I receive objections or other important concerns are brought to my attention, I will begin to write these classes.
Categories
c3dl development
Comments rss
Comments rss

« Performace test without validation code Discouraging results for memory pooling »

3 responses

HI dear developers. Can you tell me when you planned to

Mohsen Afshin | 20 April, 2009 | 5:46

HI dear developers.
Can you tell me when you planned to add Point and Line features to C3dl?
I need these primitives so much in my project.
Please inform me about the time that this functionality will be added.

Thanks a lot for bringing 3D to Web.

This will be added very soon as we will need

Cathy Leung | 20 April, 2009 | 9:17

This will be added very soon as we will need it for the motion capture project. Probably for version 1.1

Mohsen, Can you please tell us how you plan

Andor Salga | 21 April, 2009 | 9:15

Mohsen,
Can you please tell us how you plan to use these primitives? It will give us a better understanding of how users will be using the library and allow us to tailor the code to a more general format.

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>

Videos

Demos

  • Asteroids-3D
  • RTS Prototype
  • Particle Systems Demo
  • Cross-Browser Orbiter
  • Mocap Demo With Spheres
  • Google Maps-3D

C3DL Development News

A spec change that keeps coming back to haunt me

At some point, the way firefox handles keyboard events changed. I’m not sure exactly when it happened, all I know is that it broke how I was dealing with keyboard interaction on almost every demo I’ve written (for example,the mocap demo and MotionView). When I wrote the demos, the keydown event would be fired once, [...]

Release 2.2

The 2.2 Release of the Canvas 3D Library includes a number of new features, updates to old features and fixes for several bugs along with the requisite changes to meet the evolving WebGL spec. Some of the things included (in no particular order) are: Better picking code. The ability to swap textures as a scene [...]

Tutorials

  • Tutorial #1: WebGL Browsers
  • Tutorial #2: A simple scene
  • Tutorial #3: Callback
  • Tutorial #4: Models
  • Tutorial #5: Light effects
  • Tutorial #6: Picking
  • Tutorial #7: Materials
  • Tutorial #8: Particle Systems
  • Tutorial #9: Camera Basics
    • Tutorial9-YawPitchRoll
  • Tutorial #10: Advanced FreeCamera
  • Tutorial #11: OrbitCamera
  • Tutorial #12: Advanced Camera Functions

Documentation

Archives

Archives

C3DL Development News

Recent Comments

  • June 2011
  • March 2011
  • October 2010
  • July 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • A spec change that keeps coming back to haunt me
  • Release 2.2
  • 2.1 Release and things to come
  • Level Up! An Open Web Game Jam
  • Site moved!
  • SceneCreator0.3
  • WWW2010 in Raleigh
  • Motionview
  • On the train to Mountainview
  • C3DL 2.0-WebGL and beyond
  • That depends on what... - peter
  • This application is ... - Haisens
  • I think that example... - peter
  • The above links are ... - Atash
  • Hi there, just wante... - Patrick H. Lauke
  • Firefox 4 was releas... - Cathy Leung
  • In order to access l... - peter
  • I am not able to dis... - preksha
  • "JavaScript can’t di... - Joe Hocking
  • I should point out t... - peter



Canvas 3d JS Library

©2007- 2010 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