Canvas 3D Graphics Library - arc .id.au
文章推薦指數: 80 %
Cango3D is a graphics library for the HTML canvas element which simplifies the drawing and animation of 3D shapes on the 2D canvas. Cango3D uses the fact ...
Canvas3DGraphicsLibrary
Cango3DgraphicslibraryforHTMLcanvas
Cango3DisagraphicslibraryfortheHTMLcanvaselementwhichsimplifiesthedrawingandanimationof3Dshapesonthe2Dcanvas.Cango3DusesthefactthatstraightlinesandBéziercurvesmaintaintheirshapeunder3Dtransformation.Restrictingobjectoutlinedefinitionstothesetypesmeansthatsmoothcurvescanbedrawnin3Dwithveryfewpointsneedingtobetransformedandprojectedontothecanvas.
Herearevariousexamplesofobjects,drawnandanimatedbytheCango3Dgraphicslibrary.
Cang3Dbasicdrawingcapability
Figure1.Examplesofdrawingusingthe3Dgraphicslibrary.
Cango3D
Cango3Dprovidesmethodsforcreating,renderingandanimating3Doutlinepaths,filledshapesandstroketextona2Dcanvas.Complex3Dobjectscanbeconstructedbymaneuveringshapes,actingaspanels,formingthe3Dobject.
ThecurrentversionofCango3Dis11v00,andthesourcecodeisavailableatCango3D-11v00.js.
FeaturesoftheCango3D
Simpleandlightweight-Cango3Ddrawsfourobjecttypes:Path3D,Panel3D,Shape3DandText3D.AlltheseinheritmethodsfromthegenericObj3Dobject.ObjectscanbegroupedaschildrenofaGroup3Dobject.Group3DcanalsohavemoreGroup3DsaschildrenandsoontoformatreeofObjectsarbitrarilydeep.
WorldCoordinates-Cango3DusestheRightHandedCartesiancoordinatesystem.ThecanvassitsintheXYplane,theviewpointisatsomedistancealongthepositiveZaxis(outofthescreen)XvaluesincreasetotheRIGHTandYaxisvaluesincreaseUPthescreen.Thefieldofviewisuserdefined.Theworldcoordinatesarealsouseddefined,mappingof3Dworldcoordinatesto2DcanvaspixelsishandledbytheCango3D.
Shading-WhenaShape3Darerenderedtheirfillcolorisshadedaccordingtothecurrentpositiondirectionoftheuserdefinedlightsource.
Animationusingmatrixtransforms-AllObj3DandGroup3Dhaveamethodstranslate,rotate,rotateX,rotateY,rotateZ,scaleandscaleNonUniformwhichapplytemporarytransformstotheobjectcoordinatesastheyarerendered.Thetransformsareresetafterrendering,newtransformscanthenbeappliedateveryframeofananimationwithoutchangingtheunderlyingcoordinatesoftheObj3D.Childreninherittheeffectofanytransformsappliedtotheparentrecursively.
DragandDrop-AnyObj3DorGroup3Dcanbesimplyenabledfordrag-n-drop,justspecifythecallbackfunctions,alltheeventhandlingsupportcodeisbuilt-in.
TaggingofPanel3D-APanel3DmayhaveTextorotherPanel3Dsgroupedsoitappearstheyaredrawnonthepanel.
ObjectcreationbyExtrusionorRotation-Utilityfunctions'objectByExtrusion3D'and'objectByRevolution3D'areprovidedforeasycreationof3Dobjectsofthesestyles.
UsingCango3D
Firstly,downloadtheCango3DJavaScriptsourcefile:Cango3D-11v00.jsortheminifiedversionCango3D-11v00-min.js.ThiscanbeplacedinthesamedirectoryasthewebpageHTMLfile.Addthefollowinglinetothewebpageheader:
延伸文章資訊
- 1[HTML5試試看-11] canvas 與3d context - iT 邦幫忙
- 23D Graphics in HTML5 Canvas - Kevs 3D
3D Graphics in HTML5 Canvas. by Kevin Roast. More HTML5 trickery at kevs3d.co.uk/dev and updates ...
- 3Can you use canvas.getContext('3d')? If yes, how? - Stack ...
I tried 3D before, but didn't really understand (due to a non-explaining tutorial). Any Tutorials...
- 43D 網站開發入門筆記_WebGL 觀念
3使用WebGL 繪圖的基本步驟. 使用HTML5 Canvas 元素,需為HTMLCanvasElement.getContext() 方法傳遞參數“webgl” 就可以傳回一個WebGLRe...
- 5WebGL 入門- Web APIs
WebGL 元素可以加入其他HTML 元素之中並與網頁或網頁背景的其他部分混合。 ... 有初學者指南讓你完成編程任務:Learn WebGL for 2D and 3D graphics.