HT-based CSG feature builds a HTML5 3D bookshelf

Source: Internet
Author: User

Construction entity geometry CSG full name constructive solid geometry, is a common technique for building models in 3D computer graphics, which combines the logical operations of the three collection of union, subtract subtraction, and intersect intersction to convert the cube , cylinder, and prisms are simple basic models that are nested together into more complex three-dimensional models.

CSG's algorithm has been implemented in various language platforms over the years, and the C + + version of http://opencsg.org/has many applications based on this open source class library, and the JavaScript language is implemented in earlier versions http://evanw.github.io/ csg.js/, many other JS derivative editions are based on this version of the improvement, including the Java version of the implementation of Https://github.com/miho/JCSG, can refer to the JavaFX-based 3D printing IDE https:// Github.com/miho/jfxscad, the mention of JavaFX depends on the total disappearance of the programmer's vision over the years, but there is still a group of advocates who continue to use JavaFX, which is now a bit awkward.

Back to the 3D Bookshelf example we're going to do today, we're going to do this with the HT for Web-based 3D engine, HT has built in the CSG feature model package, and we build the Csgnode primitive object, which is a collection of CSG technology for the entities adsorbed by the host, The three operations of the set and complement are generally used in the cropping mode, so the Csgnode default to the host entity is cropping.

Example effect shows that we have built a Datamodel data model that binds a TreeView tree component and a three-dimensional component of two graph3dview, and the upper part of the Graph3dview component adds Visiblefunc's visible filter. Hides the Graph3dview in the following section of the blue cube elements, these blue cube is Csgnode, its role is to cut its adsorption shelves shelf objects, so generally in the 3D editor state to appear, The Run-time section, like the Graph3dview component above, is hidden by adding visible filters, which enables the 3D bookshelf effect of a groove to place the contents of a book, in this case we only put a "CSS3 the Missing Manual" as an example, this book is actually by a hexahedral , front surface shows the book map, and then rotate a certain angle to display, btw "CSS3 the Missing Manual" Third edition is a very good CSS books, highly recommended!

Shelves on both sides of the two different styles of small books, through my drag and change the position of the blue Csgnode, we can more intuitively through the comparison of the two graphs to realize the operation of CSG, Glass door switch and photo album effect is directly using the HT for Web 3D engine to provide models, By setting transparency, photo mapping, and rotating animation, you can only function parameters.

The following is a reference to all JavaScript code for the 3D example of the HT for Web: http://v.youku.com/v_show/id_XODU2MTQ4NjI4.html

Ht. Default.setimage (' Ben12 ', {width:100,height:50,comps: [{type: ' image ', Name: ' Ben1 ', rect: [0, 0, +, 50]},{type: ' Image '            , name: ' Ben2 ', rect: [50, 0, 50, 50]}); function init () {DM = new ht.                Datamodel ();                                                                                                 TreeView = new Ht.widget.TreeView (DM);   GV1 = new Ht.graph3d.Graph3dView (DM);   Gv2 = new Ht.graph3d.Graph3dView (DM);   SplitView = new Ht.widget.SplitView (GV1, gv2, ' V ', 0.6);   Mainsplit = new Ht.widget.SplitView (TreeView, SplitView, ' H ', 0.27);  view = Mainsplit.getview ();    View.classname = ' main ';d ocument.body.appendChild (view);                           Window.addeventlistener (' Resize ', function (e) {mainsplit.invalidate ();}, False); Gv1.setmovestep (+); gv1.setgridvisible (true); Gv1.seteye (0, +, +); Gv1.setcenter (0, 0, 0); Gv1.getlabel = function () {return null;}; Gv1.getbrightness = function (data) {return null;}; Gv1.setvisiblefunc (function (data) {if (DATA.SHOWME) {return true;} if (data instanceof ht. Csgnode && Data.gethost ()) {return false;} return true;}); Gv2.setmovestep (+); gv2.seteditable (true); Gv2.setgridvisible (true);                Gv2.seteditable (True); Gv2.pan (0, $, true); Gv2.getlabel = function () {return null;};                       InitShelf1 ();                       InitShelf2 ();                       InitShelf3 (); Treeview.expandall (); var angle = 0;setinterval (function () {angle + = MATH.PI/40;EARTH.R3 (0, Angle, 0);p hotos.s ('                 Dw.angle ', angle);}, 50); } function InitShelf1 () {var shelf = new ht. Csgnode (SHELF.S3); shelf.p3 (0, 0); Shelf.setname (' Shelf1 '); Shelf.s ({' All.color ': ' #E5BB77 '}); Dm.add (shelf), for (Var i=0, i<2; i++) {for (Var j=0; j<5; J + +) {var clipnode = new ht. Csgnode (); Clipnode.sethost (shelf); Clipnode.s3 (+, +); Clipnode.p3 ( -200+j*100, 340-i*120, 20); Clipnode.setname (' substract-' +i+ '-' +j '); cLIPNODE.S (' Batch ', ' TT '); clipnode.setparent (shelf);d m.add (Clipnode);}} var leftnode = new ht. Csgnode (); Leftnode.sethost (shelf); Leftnode.s3 (380, +) LEFTNODE.P3 ( -255, 0); Leftnode.setname (' Substract Left '), leftnode.setparent (shelf);d m.add (Leftnode), var rightnode = new ht. Csgnode (); Rightnode.sethost (shelf); Rightnode.s3 (at 0, 380); Rightnode.p3 (255,); Rightnode.setname (' Substract right '); Rightnode.setparent (shelf);d m.add (Rightnode); var bottomnode = new ht. Csgnode (); Bottomnode.sethost (shelf); Bottomnode.s3 (480, N. 0, 0); BOTTOMNODE.P3 ('  Substract Bottom '), bottomnode.setparent (shelf);d m.add (Bottomnode); var topnode = new ht. Csgnode (); Topnode.sethost (shelf); Topnode.s3 (480, N.), topnode.p3 (0, 0); Topnode.setname (' Union top ');  TOPNODE.S (' attach.operation ', ' Union '), topnode.setparent (shelf);d m.add (Topnode); var book = new ht. Node (); Book.setname (' Css3:the Missing Manual '); Book.s3 (8); Book.p3 ( -100,); Book.r3 (-MATH.PI/6, math.pi/ 5, 0); Book.seticon (' book '); Book.s ({' front.image ': ' book ', ' Back.color ': ' White ', ' left.color ': ' White ', ' all.color ': '                                Gray '}); Book.sethost (shelf); book.setparent (shelf);d m.add (book); }function InitShelf2 () {var shelf = new ht. Csgnode (SHELF.S3); shelf.p3 (0, 0); Shelf.setname (' shelf2 '); Shelf.s ({' All.color ': ' #805642 ', ' Csg.color ': ' Yellow ', ' Csg.reverse.flip ': true});d M.add (shelf); var clipnode = new ht. Csgnode (); Clipnode.setname (' shelf2-substract-up '); clipnode.s3 (0, 180, 0); Clipnode.sethost (shelf); CLIPNODE.S (' Attach.cull ', true); Clipnode.setparent (shelf);d m.add (clipnode); clipnode = new Ht. Csgbox (); Clipnode.setname (' csgbox-expand-left '); CLIPNODE.S3 (0, 65, 0.1); Clipnode.sethost (shelf); clipnode.showme = True;clipnode.s ({' all.visible ': false, ' front.visible ': true, ' Front.toggleable ': True, ' front.reverse.flip ': true, ' front.transparent ': true, ' front.end ': Math.PI *0.7, ' front.color ': ' Rgba (0, +, 0.7) '}), clipnode.setparent (shelf); clipnode.setfaceexpanded (' Front ', true, true);                Dm.add (Clipnode); earth = new HT. Node (); Earth.setname (' Earth '); Earth.seticon (' Earth '); Earth.s3 ((), earth.p3 (0, 0); Earth.s ({' Shape3d ': '  Sphere ', ' shape3d.image ': ' Earth '}); Earth.sethost (shelf);                               Earth.setparent (shelf);d m.add (earth), Shelf.t3 ( -360, 0, 0), SHELF.R3 (0); } function InitShelf3 () {var shelf = new ht. Csgnode (SHELF.S3); shelf.p3 (0, 0); Shelf.setname (' shelf3 '); Shelf.seticon (' Ben '); Shelf.s ({'                                                             All.image ': ' Brick ', ' all.uv.scale ': [2, 4], ' Top.uv.scale ': [2, 2], ' Bottom.uv.scale ': [2, 2], ' Csg.image ': ' Ben ', ' csg.blend ': ' Yellow '});d M.add (shelf);p Hotos = new ht. Doorwindow ();p hotos.setname (' Doorwindow-photos ');p hotos.seticon (' ben12 ');p hotos.s3 ((a);p hotos.p3 (5,                180, 0); Photos.sEthost (shelf); Photos.showme = TRUE;PHOTOS.S ({' Bottom.uv ': [1,0, 0,0, 0,1], ' Bottom.uv.scale ': [1, 1], ' Left.uv.sc Ale ': [3, 3], ' Top.uv.scale ': [2, 2], ' DW.S3 ': [0.8, 0.9, 0.05], ' dw.t3 ': [0, -5, 0], ' dw.axis ': ' V ', ' dw.toggleable ': false, ' F Ront.image ': ' Ben1 ', ' back.image ': ' Ben2 ', ' all.color ': ' #F8CE8B '});p hotos.setparent (shelf);d m.add (photos); var Clipnode = new ht. Csgbox (); Clipnode.setname (' csgbox-expand-top '); Clipnode.s3 (0, +, CLIPNODE.P3); 0.1 (shelf); clipnode.showme = True;clipnode.s ({' all.visible ': false, ' front.visible ': true, ' front.color ': ' Red ', ' front.transparent ': true, ' front.opacity ': 0.7, ' front.reverse.flip ': true, ' front.toggleable ': Tru E, ' front.axis ': ' Top ', ' front.end ': Math.PI * 0.4}); clipnode.setparent (shelf); CLIPN                ode.setfaceexpanded (' front ', true, True);d M.add (Clipnode);  SHELF.T3 (0,-MATH.PI/7, 0), SHELF.R3 (0);    }


HT-based CSG feature builds a HTML5 3D bookshelf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.