11/*
2- * Copyright (c) 2009-2021 jMonkeyEngine
2+ * Copyright (c) 2009-2025 jMonkeyEngine
33 * All rights reserved.
44 *
55 * Redistribution and use in source and binary forms, with or without
2929 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131 */
32-
3332package jme3test .model .shape ;
3433
3534import com .jme3 .app .SimpleApplication ;
3635import com .jme3 .material .Material ;
3736import com .jme3 .math .ColorRGBA ;
3837import com .jme3 .math .Vector3f ;
3938import com .jme3 .scene .Geometry ;
39+ import com .jme3 .scene .Mesh ;
4040import com .jme3 .scene .Node ;
4141import com .jme3 .scene .control .BillboardControl ;
42- import com .jme3 .scene .shape .Box ;
42+ import com .jme3 .scene .debug .Arrow ;
43+ import com .jme3 .scene .debug .Grid ;
4344import com .jme3 .scene .shape .Quad ;
4445
4546/**
46- *
47- * @author Kirill Vainer
47+ * @author capedvon
4848 */
4949public class TestBillboard extends SimpleApplication {
5050
51+ public static void main (String [] args ) {
52+ TestBillboard app = new TestBillboard ();
53+ app .start ();
54+ }
55+
5156 @ Override
5257 public void simpleInitApp () {
53- flyCam .setMoveSpeed (10 );
54-
55- Quad q = new Quad (2 , 2 );
56- Geometry g = new Geometry ("Quad" , q );
57- Material mat = new Material (assetManager , "Common/MatDefs/Misc/Unshaded.j3md" );
58- mat .setColor ("Color" , ColorRGBA .Blue );
59- g .setMaterial (mat );
60-
61- Quad q2 = new Quad (1 , 1 );
62- Geometry g3 = new Geometry ("Quad2" , q2 );
63- Material mat2 = new Material (assetManager , "Common/MatDefs/Misc/Unshaded.j3md" );
64- mat2 .setColor ("Color" , ColorRGBA .Yellow );
65- g3 .setMaterial (mat2 );
66- g3 .setLocalTranslation (.5f , .5f , .01f );
67-
68- Box b = new Box (.25f , .5f , .25f );
69- Geometry g2 = new Geometry ("Box" , b );
70- g2 .setLocalTranslation (0 , 0 , 3 );
71- g2 .setMaterial (mat );
58+ flyCam .setMoveSpeed (15f );
59+ flyCam .setDragToRotate (true );
7260
73- Node bb = new Node ( "billboard" );
61+ viewPort . setBackgroundColor ( ColorRGBA . DarkGray );
7462
75- BillboardControl control =new BillboardControl ();
76-
77- bb .addControl (control );
78- bb .attachChild (g );
79- bb .attachChild (g3 );
80-
63+ Geometry grid = makeShape ("DebugGrid" , new Grid (21 , 21 , 2 ), ColorRGBA .Gray );
64+ grid .center ().move (0 , 0 , 0 );
65+ rootNode .attachChild (grid );
8166
82- n =new Node ("parent" );
83- n .attachChild (g2 );
84- n .attachChild (bb );
85- rootNode .attachChild (n );
67+ Node node = createBillboard (BillboardControl .Alignment .Screen , ColorRGBA .Red );
68+ node .setLocalTranslation (-6f , 0 , 0 );
69+ rootNode .attachChild (node );
8670
87- n2 = new Node ( "parentParent" );
88- n2 .setLocalTranslation (Vector3f . UNIT_X . mult ( 5 ) );
89- n2 .attachChild (n );
71+ node = createBillboard ( BillboardControl . Alignment . Camera , ColorRGBA . Green );
72+ node .setLocalTranslation (- 2f , 0 , 0 );
73+ rootNode .attachChild (node );
9074
91- rootNode .attachChild (n2 );
75+ node = createBillboard (BillboardControl .Alignment .AxialY , ColorRGBA .Blue );
76+ node .setLocalTranslation (2f , 0 , 0 );
77+ rootNode .attachChild (node );
9278
93-
94- // rootNode.attachChild(bb);
95- // rootNode.attachChild(g2);
96- }
97- private Node n ;
98- private Node n2 ;
99- @ Override
100- public void simpleUpdate (float tpf ) {
101- super .simpleUpdate (tpf );
102- n .rotate (0 , tpf , 0 );
103- n .move (0.1f *tpf , 0 , 0 );
104- n2 .rotate (0 , 0 , -tpf );
79+ node = createBillboard (BillboardControl .Alignment .AxialZ , ColorRGBA .Yellow );
80+ node .setLocalTranslation (6f , 0 , 0 );
81+ rootNode .attachChild (node );
10582 }
10683
84+ private Node createBillboard (BillboardControl .Alignment alignment , ColorRGBA color ) {
85+ Node node = new Node ("Parent" );
86+ Quad quad = new Quad (2 , 2 );
87+ Geometry g = makeShape (alignment .name (), quad , color );
88+ g .addControl (new BillboardControl (alignment ));
89+ node .attachChild (g );
90+ node .attachChild (makeShape ("ZAxis" , new Arrow (Vector3f .UNIT_Z ), ColorRGBA .Blue ));
91+ return node ;
92+ }
10793
108-
109- public static void main (String [] args ) {
110- TestBillboard app = new TestBillboard ();
111- app .start ();
94+ private Geometry makeShape (String name , Mesh shape , ColorRGBA color ) {
95+ Geometry geo = new Geometry (name , shape );
96+ Material mat = new Material (assetManager , "Common/MatDefs/Misc/Unshaded.j3md" );
97+ mat .setColor ("Color" , color );
98+ geo .setMaterial (mat );
99+ return geo ;
112100 }
113- }
101+
102+ }
0 commit comments