Normand Briere
2019-10-01 65bdec7ae2c99ca2102c55f92bd62b48c9f14847
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
/*
 * Copyright (c) 2003-2009 jMonkeyEngine
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
 *   may be used to endorse or promote products derived from this software
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
//package com.jme.scene;
import java.io.IOException;
import java.io.Serializable;
//import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
 
import com.jme.bounding.BoundingVolume;
import com.jme.intersection.PickResults;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Ray;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
//import com.jme.renderer.Renderer;
//import com.jme.scene.state.LightState;
//import com.jme.scene.state.LightUtil;
//import com.jme.scene.state.RenderState;
//import com.jme.scene.state.TextureState;
import com.jme.util.export.InputCapsule;
import com.jme.util.export.JMEExporter;
import com.jme.util.export.JMEImporter;
import com.jme.util.export.OutputCapsule;
import com.jme.util.export.Savable;
import com.jme.util.geom.BufferUtils;
 
//
import com.jme.scene.TexCoords;
 
/**
 * <code>Geometry</code> defines a leaf node of the scene graph. The leaf node
 * contains the geometric data for rendering objects. It manages all rendering
 * information such as a collection of states and the data for a model.
 * Subclasses define what the model data is.
 * 
 * @author Mark Powell
 * @author Joshua Slack
 */
public abstract class Geometry implements Serializable // extends Object3D // BoundaryRep // Spatial implements Serializable, Savable
{
    static final long serialVersionUID = 0;
    
    abstract void DrawParticles(iCameraPane display, Object3D geo, boolean selected, boolean rotate);
 
    private static final Logger logger = Logger.getLogger(Geometry.class.getName());
//    private static final long serialVersionUID = 1;
    /** The local bounds of this Geometry object. */
    protected BoundingVolume bound;
    /** The number of vertexes in this geometry. */
    protected int vertQuantity = 0;
    /** The geometry's per vertex color information. */
    protected FloatBuffer colorBuf;
    /** The geometry's per vertex normal information. */
    protected FloatBuffer normBuf;
    /** The geometry's vertex information. */
    protected FloatBuffer vertBuf;
    /** The geometry's vertex information. */
    protected FloatBuffer sizeBuf;
    /** The geometry's per Texture per vertex texture coordinate information. */
    protected transient ArrayList<TexCoords> texBuf;
    /** The geometry's per vertex color information. */
    protected FloatBuffer tangentBuf;
    /** The geometry's per vertex normal information. */
    protected FloatBuffer binormalBuf;
    /** The geometry's per vertex fog buffer depth values */
    protected FloatBuffer fogBuf;
    /** The geometry's VBO information. */
//    protected transient VBOInfo vboInfo;
    protected boolean enabled = true;
    protected boolean castsShadows = true;
    protected boolean hasDirtyVertices = false;
    /**
     * The compiled list of renderstates for this geometry, taking into account
     * ancestors' states - updated with updateRenderStates()
     */
//    public RenderState[] states = new RenderState[RenderState.StateType.values().length];
 
//    private LightState lightState;
    protected ColorRGBA defaultColor = new ColorRGBA(ColorRGBA.white);
    /**
     * Non -1 values signal that drawing this scene should use the provided
     * display list instead of drawing from the buffers.
     */
    protected int displayListID = -1;
    /** Static computation field */
    protected static final Vector3f compVect = new Vector3f();
 
    /**
     * Empty Constructor to be used internally only.
     */
    public Geometry()
    {
        super();
        texBuf = new ArrayList<TexCoords>(1);
        texBuf.add(null);
    }
 
    /**
     * Constructor instantiates a new <code>Geometry</code> object. This is
     * the default object which has an empty vertex array. All other data is
     * null.
     * 
     * @param name
     *            the name of the scene element. This is required for
     *            identification and comparision purposes.
     */
    public Geometry(String name)
    {
        //super(name);
        texBuf = new ArrayList<TexCoords>(1);
        texBuf.add(null);
    //    if (!(this instanceof SharedMesh))
        {
            reconstruct(null, null, null, null);
        }
    }
 
    /**
     * Constructor creates a new <code>Geometry</code> object. During
     * instantiation the geometry is set including vertex, normal, color and
     * texture information.
     * 
     * @param name
     *            the name of the scene element. This is required for
     *            identification and comparision purposes.
     * @param vertex
     *            the points that make up the geometry.
     * @param normal
     *            the normals of the geometry.
     * @param color
     *            the color of each point of the geometry.
     * @param coords
     *            the texture coordinates of the geometry (position 0.)
     */
    public Geometry(String name, FloatBuffer vertex, FloatBuffer normal,
            FloatBuffer color, TexCoords coords)
    {
        //super(name);
        texBuf = new ArrayList<TexCoords>(1);
        texBuf.add(null);
        reconstruct(vertex, normal, color, coords);
    }
 
    /**
     * returns the number of vertices contained in this geometry.
     */
//    @Override
    public int getVertexCount()
    {
        //if (bRep == null)
        //    return 0;
        
        return vertQuantity; //bRep.VertexCount(); // vertQuantity;
    }
 
    public void setVertexCount(int vertQuantity)
    {
//        assert(false);
        this.vertQuantity = vertQuantity;
    }
 
//    @Override
    public int getTriangleCount()
    {
        return 0; // bRep.FaceCount(); // 0;
    }
 
    /**
     * <code>reconstruct</code> reinitializes the geometry with new data. This
     * will reuse the geometry object.
     * 
     * @param vertices
     *            the new vertices to use.
     * @param normals
     *            the new normals to use.
     * @param colors
     *            the new colors to use.
     * @param coords
     *            the new texture coordinates to use (position 0).
     */
    public void reconstruct(FloatBuffer vertices, FloatBuffer normals,
            FloatBuffer colors, TexCoords coords)
    {
        if (vertices == null)
        {
            setVertexCount(0);
        } else
        {
            setVertexCount(vertices.limit() / 3);
        }
 
        setVertexBuffer(vertices);
        setNormalBuffer(normals);
        setColorBuffer(colors);
        if (getTextureCoords() == null)
        {
            setTextureCoords(new ArrayList<TexCoords>(1));
        }
 
        clearTextureBuffers();
        addTextureCoordinates(coords);
 
   //     if (getVBOInfo() != null)
   //     {
   //         resizeTextureIds(1);
   //     }
    }
 
//    /**
//     * Sets VBO info on this Geometry.
//     * 
//     * @param info
//     *            the VBO info to set
//     * @see VBOInfo
//     */
//    public void setVBOInfo(VBOInfo info) {
//        vboInfo = info;
//        if (vboInfo != null) {
//            vboInfo.resizeTextureIds(texBuf.size());
//        }
//    }
//
//    /**
//     * @return VBO info object
//     * @see VBOInfo
//     */
//    public VBOInfo getVBOInfo() {
//        return vboInfo;
//    }
    /**
     * <code>setSolidColor</code> sets the color array of this geometry to a
     * single color. For greater efficiency, try setting the the ColorBuffer to
     * null and using DefaultColor instead.
     * 
     * @param color
     *            the color to set.
     */
//    public void setSolidColor(ColorRGBA color)
//    {
//        if (colorBuf == null)
//        {
//            colorBuf = FloatBuffer.allocate(vertQuantity * 4); // BufferUtils.createColorBuffer(vertQuantity);
//        }
//
//        colorBuf.rewind();
//        for (int x = 0,  cLength = colorBuf.remaining(); x < cLength; x += 4)
//        {
//            colorBuf.put(color.r);
//            colorBuf.put(color.g);
//            colorBuf.put(color.b);
//            colorBuf.put(color.a);
//        }
//        colorBuf.flip();
//    }
 
    /**
     * Sets every color of this geometry's color array to a random color.
     */
//    public void setRandomColors()
//    {
//        if (colorBuf == null)
//        {
//            colorBuf = BufferUtils.createColorBuffer(vertQuantity);
//        }
//
//        for (int x = 0,  cLength = colorBuf.limit(); x < cLength; x += 4)
//        {
//            colorBuf.put(FastMath.nextRandomFloat());
//            colorBuf.put(FastMath.nextRandomFloat());
//            colorBuf.put(FastMath.nextRandomFloat());
//            colorBuf.put(1);
//        }
//        colorBuf.flip();
//    }
 
    /**
     * <code>getVertexBuffer</code> returns the float buffer that contains
     * this geometry's vertex information.
     * 
     * @return the float buffer that contains this geometry's vertex
     *         information.
     */
    public FloatBuffer getVertexBuffer()
    {
        return vertBuf;
    }
 
    /**
     * <code>setVertexBuffer</code> sets this geometry's vertices via a float
     * buffer consisting of groups of three floats: x,y and z.
     * 
     * @param vertBuf
     *            the new vertex buffer.
     */
    public void setVertexBuffer(FloatBuffer vertBuf)
    {
        this.vertBuf = vertBuf;
        if (vertBuf != null)
        {
            vertQuantity = vertBuf.limit() / 3;
        } else
        {
            vertQuantity = 0;
        }
    }
 
    /**
     * Set the fog coordinates buffer. This should have the vertex count entries
     * 
     * @param fogBuf The fog buffer to use in this geometry
     */
    public void setFogCoordBuffer(FloatBuffer fogBuf)
    {
        this.fogBuf = fogBuf;
    }
 
    /**
     * The fog depth coord buffer
     * 
     * @return The per vertex depth values for fog coordinates
     */
    public FloatBuffer getFogBuffer()
    {
        return fogBuf;
    }
 
    /**
     * <code>getNormalBuffer</code> retrieves this geometry's normal
     * information as a float buffer.
     * 
     * @return the float buffer containing the geometry information.
     */
    public FloatBuffer getNormalBuffer()
    {
        return normBuf;
    }
 
    /**
     * <code>setNormalBuffer</code> sets this geometry's normals via a float
     * buffer consisting of groups of three floats: x,y and z.
     * 
     * @param normBuf
     *            the new normal buffer.
     */
    public void setNormalBuffer(FloatBuffer normBuf)
    {
        this.normBuf = normBuf;
    }
 
    /**
     * <code>getColorBufferfer</code> retrieves the float buffer that contains
     * this geometry's color information.
     * 
     * @return the buffer that contains this geometry's color information.
     */
    public FloatBuffer getColorBuffer()
    {
        return colorBuf;
    }
 
    /**
     * <code>setColorBuffer</code> sets this geometry's colors via a float
     * buffer consisting of groups of four floats: r,g,b and a.
     * 
     * @param colorBuf
     *            the new color buffer.
     */
    public void setColorBuffer(FloatBuffer colorBuf)
    {
        this.colorBuf = colorBuf;
    }
 
    public FloatBuffer getSizeBuffer()
    {
        return sizeBuf;
    }
 
    public void setSizeBuffer(FloatBuffer sizeBuf)
    {
        this.sizeBuf = sizeBuf;
    }
 
    /**
     * <code>copyTextureCoords</code> copys the texture coordinates of a given
     * texture unit to another location. If the texture unit is not valid, then
     * the coordinates are ignored. Coords are multiplied by the given factor.
     * 
     * @param fromIndex
     *            the coordinates to copy.
     * @param toIndex
     *            the texture unit to set them to.
     * @param factor
     *            a multiple to apply when copying
     */
    public void copyTextureCoordinates(int fromIndex, int toIndex, float factor)
    {
        if (texBuf == null)
        {
            return;
        }
 
        if (fromIndex < 0 || fromIndex >= texBuf.size() || texBuf.get(fromIndex) == null)
        {
            return;
        }
 
        TexCoords src = texBuf.get(fromIndex);
        float[] factors = new float[src.perVert];
        for (int i = 0; i < factors.length; i++)
        {
            factors[i] = factor;
        }
        copyTextureCoordinates(fromIndex, toIndex, factors);
 
    }
 
    /**
     * <code>copyTextureCoords</code> copys the texture coordinates of a given
     * texture unit to another location. If the texture unit is not valid, then
     * the coordinates are ignored. Coords are multiplied by the given factor.
     * 
     * @param fromIndex
     *            the coordinates to copy.
     * @param toIndex
     *            the texture unit to set them to.
     * @param factor
     *            a multiple to apply when copying
     */
    public void copyTextureCoordinates(int fromIndex, int toIndex, float[] factor)
    {
        if (texBuf == null)
        {
            return;
        }
 
        if (fromIndex < 0 || fromIndex >= texBuf.size() || texBuf.get(fromIndex) == null)
        {
            return;
        }
 
        if (toIndex < 0 || toIndex == fromIndex)
        {
            return;
        }
 
        // make sure we are big enough
        while (toIndex >= texBuf.size())
        {
            texBuf.add(null);
        }
 
        TexCoords dest = texBuf.get(toIndex);
        TexCoords src = texBuf.get(fromIndex);
        if (dest == null || dest.coords.capacity() != src.coords.limit())
        {
            dest = new TexCoords(BufferUtils.createFloatBuffer(src.coords.capacity()), src.perVert);
            texBuf.set(toIndex, dest);
        }
        dest.coords.clear();
        int oldLimit = src.coords.limit();
        src.coords.clear();
        for (int i = 0,  len = dest.coords.capacity(); i < len; i += dest.perVert)
        {
            for (int j = 0; j < dest.perVert; j++)
            {
                dest.coords.put(factor[j] * src.coords.get());
            }
        }
        src.coords.limit(oldLimit);
        dest.coords.limit(oldLimit);
 
//        if (vboInfo != null)
//        {
//            vboInfo.resizeTextureIds(this.texBuf.size());
//        }
 
        checkTextureCoordinates();
    }
 
    /**
     * <code>getTextureBuffers</code> retrieves this geometry's texture
     * information contained within a float buffer array.
     * 
     * @return the float buffers that contain this geometry's texture
     *         information.
     */
    public ArrayList<TexCoords> getTextureCoords()
    {
        return texBuf;
    }
 
    /**
     * <code>getTextureAsFloatBuffer</code> retrieves the texture buffer of a
     * given texture unit.
     * 
     * @param textureUnit
     *            the texture unit to check.
     * @return the texture coordinates at the given texture unit.
     */
    public TexCoords getTextureCoords(int textureUnit)
    {
        if (texBuf == null)
        {
            return null;
        }
        if (textureUnit >= texBuf.size())
        {
            return null;
        }
        return texBuf.get(textureUnit);
    }
 
    /**
     * <code>setTextureBuffer</code> sets this geometry's textures (position
     * 0) via a float buffer. This convenience method assumes we are setting
     * coordinates for texture unit 0 and that there are 2 coordinate values per
     * vertex.
     * 
     * @param coords
     *            the new coords for unit 0.
     */
    public void setTextureCoords(TexCoords coords)
    {
        setTextureCoords(coords, 0);
    }
 
    /**
     * <code>setTextureBuffer</code> sets this geometry's textures at the
     * position given via a float buffer. This convenience method assumes that
     * there are 2 coordinate values per vertex.
     * 
     * @param coords
     *            the new coords.
     * @param unit
     *            the texture unit we are providing coordinates for.
     */
    public void setTextureCoords(TexCoords coords, int unit)
    {
        while (unit >= texBuf.size())
        {
            texBuf.add(null);
        }
        texBuf.set(unit, coords);
 
//        if (vboInfo != null)
//        {
//            vboInfo.resizeTextureIds(texBuf.size());
//        }
        checkTextureCoordinates();
    }
 
    /**
     * Clears all vertex, normal, texture, and color buffers by setting them to
     * null.
     */
    public void clearBuffers()
    {
        reconstruct(null, null, null, null);
    }
 
    /**
     * <code>updateBound</code> recalculates the bounding object assigned to
     * the geometry. This resets it parameters to adjust for any changes to the
     * vertex information.
     */
//    public void updateModelBound()
//    {
//        if (bound != null && getVertexBuffer() != null)
//        {
//            bound.computeFromPoints(getVertexBuffer());
////            updateWorldBound();
//        }
//    }
 
    /**
     * <code>setModelBound</code> sets the bounding object for this geometry.
     * 
     * @param modelBound
     *            the bounding object for this geometry.
     */
    public void setModelBound(BoundingVolume modelBound)
    {
//        this.worldBound = null;
        this.bound = modelBound;
    }
 
//    /**
//     * <code>draw</code> prepares the geometry for rendering to the display.
//     * The renderstate is set and the subclass is responsible for rendering the
//     * actual data.
//     * 
//     * @see com.jme.scene.Spatial#draw(com.jme.renderer.Renderer)
//     * @param r
//     *            the renderer that displays to the context.
//     */
//    @Override
//    public void draw(Renderer r) {
//    }
//
//    /**
//     * <code>updateWorldBound</code> updates the bounding volume that contains
//     * this geometry. The location of the geometry is based on the location of
//     * all this node's parents.
//     * 
//     * @see com.jme.scene.Spatial#updateWorldBound()
//     */
//    public void updateWorldBound() {
//        if (bound != null) {
//            worldBound = bound.transform(getWorldRotation(),
//                    getWorldTranslation(), getWorldScale(), worldBound);
//        }
//    }
//
//    /**
//     * <code>applyRenderState</code> determines if a particular render state
//     * is set for this Geometry. If not, the default state will be used.
//     */
//    @Override
//    protected void applyRenderState(Stack<? extends RenderState>[] states) {
//        for (int x = 0; x < states.length; x++) {
//            if (states[x].size() > 0) {
//                this.states[x] = ((RenderState) states[x].peek()).extract(
//                        states[x], this);
//            } else {
//                this.states[x] = Renderer.defaultStateList[x];
//            }
//        }
//    }
//
//    /**
//     * sorts the lights based on distance to geometry bounding volume
//     */
//    public void sortLights() {
//        if (lightState != null && lightState.getLightList().size() > LightState.MAX_LIGHTS_ALLOWED) {
//            LightUtil.sort(this, lightState.getLightList());
//        }
//    }
    /**
     * <code>randomVertex</code> returns a random vertex from the list of
     * vertices set to this geometry. If there are no vertices set, null is
     * returned.
     * 
     * @param fill
     *            a Vector3f to fill with the results. If null, one is created.
     *            It is more efficient to pass in a non-null vector.
     * @return Vector3f a random vertex from the vertex list. Null is returned
     *         if the vertex list is not set.
     */
    public Vector3f randomVertex(Vector3f fill)
    {
        if (getVertexBuffer() == null)
        {
            return null;
        }
        int i = (int) (FastMath.nextRandomFloat() * getVertexCount());
 
        if (fill == null)
        {
            fill = new Vector3f();
        }
        //BufferUtils.populateFromBuffer(fill, getVertexBuffer(), i);
        getVertexBuffer().get(i, fill);
 
//NOTODO        localToWorld(fill, fill);
 
        return fill;
    }
 
    /**
     * Check if this geometry intersects the ray if yes add it to the results.
     * 
     * @param ray ray to check intersection with. The direction of the ray must
     *            be normalized (length 1).
     * @param requiredOnBits Collision will only be considered if 'this'
     *        has these bits of its collision mask set.
     * @param results
     *            result list
     */
//    @Override
    public void findPick(Ray ray, PickResults results, int requiredOnBits)
    {
//        if (getWorldBound() == null || !isCollidable(requiredOnBits))
//        {
//            return;
//        }
//        if (getWorldBound().intersects(ray))
//        {
//            // find the triangle that is being hit.
//            // add this node and the triangle to the PickResults list.
//            results.addPick(ray, this);
//        }
    }
 
    /**
     * <code>setDefaultColor</code> sets the color to be used if no per vertex
     * color buffer is set.
     * 
     * @param color
     */
    public void setDefaultColor(ColorRGBA color)
    {
        defaultColor = color;
    }
 
    /**
     * <code>getWorldCoords</code> translates/rotates and scales the
     * coordinates of this Geometry to world coordinates based on its world
     * settings. The results are stored in the given FloatBuffer. If given
     * FloatBuffer is null, one is created.
     * 
     * @param store
     *            the FloatBuffer to store the results in, or null if you want
     *            one created.
     * @return store or new FloatBuffer if store == null.
     */
//    public FloatBuffer getWorldCoords(FloatBuffer store)
//    {
//        final FloatBuffer vertBuf = getVertexBuffer();
//        if (store == null || store.capacity() != vertBuf.limit())
//        {
//            store = BufferUtils.createFloatBuffer(vertBuf.limit());
//            if (store == null)
//            {
//                return null;
//            }
//        }
//
//        for (int v = 0,  vSize = store.capacity() / 3; v < vSize; v++)
//        {
//            BufferUtils.populateFromBuffer(compVect, vertBuf, v);
////            localToWorld(compVect, compVect);
//            BufferUtils.setInBuffer(compVect, store, v);
//        }
//        return store;
//    }
 
    /**
     * <code>getWorldNormals</code> rotates the normals of this Geometry to
     * world normals based on its world settings. The results are stored in the
     * given FloatBuffer. If given FloatBuffer is null, one is created.
     * 
     * @param store
     *            the FloatBuffer to store the results in, or null if you want
     *            one created.
     * @return store or new FloatBuffer if store == null.
     */
//    public FloatBuffer getWorldNormals(FloatBuffer store)
//    {
//        final FloatBuffer normBuf = getNormalBuffer();
//        if (store == null || store.capacity() != normBuf.limit())
//        {
//            store = BufferUtils.createFloatBuffer(normBuf.limit());
//            if (store == null)
//            {
//                return null;
//            }
//        }
//
//        for (int v = 0,  vSize = store.capacity() / 3; v < vSize; v++)
//        {
//            BufferUtils.populateFromBuffer(compVect, normBuf, v);
////            getWorldRotation().multLocal(compVect);
//            BufferUtils.setInBuffer(compVect, store, v);
//        }
//        return store;
//    }
 
    public int getDisplayListID()
    {
        return displayListID;
    }
 
    public void setDisplayListID(int displayListID)
    {
        this.displayListID = displayListID;
    }
 
    public void setTextureCoords(ArrayList<TexCoords> texBuf)
    {
        this.texBuf = texBuf;
        checkTextureCoordinates();
    }
 
    public void clearTextureBuffers()
    {
        if (texBuf != null)
        {
            texBuf.clear();
        }
    }
 
    public void addTextureCoordinates(TexCoords textureCoords)
    {
        addTextureCoordinates(textureCoords, 2);
    }
 
    public void addTextureCoordinates(TexCoords textureCoords, int coordSize)
    {
        if (texBuf != null)
        {
            texBuf.add(textureCoords);
        }
        checkTextureCoordinates();
    }
 
    public void resizeTextureIds(int i)
    {
//        vboInfo.resizeTextureIds(i);
    }
 
    protected void checkTextureCoordinates()
    {
        int max = -1; // TextureState.getNumberOfFragmentTexCoordUnits();
        if (max == -1)
        {
            return;
        } // No texture state created yet.
        if (texBuf != null && texBuf.size() > max)
        {
            for (int i = max; i < texBuf.size(); i++)
            {
                if (texBuf.get(i) != null)
                {
                    logger.log(Level.WARNING, "Texture coordinates set for unit {0}." + " Only {1} units are available.", new Integer[]{i, max});
                }
            }
        }
    }
 
    public void scaleTextureCoordinates(int index, float factor)
    {
        scaleTextureCoordinates(index, new Vector2f(factor, factor));
    }
 
    public void scaleTextureCoordinates(int index, Vector2f factor)
    {
        if (texBuf == null)
        {
            return;
        }
 
        if (index < 0 || index >= texBuf.size() || texBuf.get(index) == null)
        {
            return;
        }
 
        TexCoords tc = texBuf.get(index);
 
        for (int i = 0,  len = tc.coords.limit() / 2; i < len; i++)
        {
            BufferUtils.multInBuffer(factor, tc.coords, i);
        }
 
//        if (vboInfo != null)
//        {
//            vboInfo.resizeTextureIds(this.texBuf.size());
//        }
    }
 
    public boolean isCastsShadows()
    {
        return castsShadows;
    }
 
    public void setCastsShadows(boolean castsShadows)
    {
        this.castsShadows = castsShadows;
    }
 
    /**
     * <code>getNumberOfUnits</code> returns the number of texture units this
     * geometry is currently using.
     * 
     * @return the number of texture units in use.
     */
    public int getNumberOfUnits()
    {
        if (texBuf == null)
        {
            return 0;
        }
        return texBuf.size();
    }
 
//    @Override
//    public void lockMeshes(Renderer r) {
//        if (getDisplayListID() != -1) {
//            logger.warning("This Geometry already has locked meshes."
//                    + "(Use unlockMeshes to clear)");
//            return;
//        }
//
//        updateRenderState();
//        lockedMode |= LOCKED_MESH_DATA;
//
//        setDisplayListID(r.createDisplayList(this));
//    }
//
//    @Override
//    public void unlockMeshes(Renderer r) {
//        lockedMode &= ~LOCKED_MESH_DATA;
//
//        if (getDisplayListID() != -1) {
//            r.releaseDisplayList(getDisplayListID());
//            setDisplayListID(-1);
//        }
//    }
//
//    /**
//     * Called just before renderer starts drawing this geometry. If it returns
//     * false, we'll skip rendering.
//     */
//    public boolean predraw(Renderer r) {
//        return true;
//    }
//
//    /**
//     * Called after renderer finishes drawing this geometry.
//     */
//    public void postdraw(Renderer r) {
//    }
//    public void translatePoints(float x, float y, float z)
//    {
//        translatePoints(new Vector3f(x, y, z));
//    }
//
//    public void translatePoints(Vector3f amount)
//    {
//        for (int x = 0; x < vertQuantity; x++)
//        {
//            BufferUtils.addInBuffer(amount, vertBuf, x);
//        }
//    }
//
//    public void rotatePoints(Quaternion rotate)
//    {
//        Vector3f store = new Vector3f();
//        for (int x = 0; x < vertQuantity; x++)
//        {
//            BufferUtils.populateFromBuffer(store, vertBuf, x);
//            rotate.mult(store, store);
//            BufferUtils.setInBuffer(store, vertBuf, x);
//        }
//    }
//
//    public void rotateNormals(Quaternion rotate)
//    {
//        Vector3f store = new Vector3f();
//        for (int x = 0; x < vertQuantity; x++)
//        {
//            BufferUtils.populateFromBuffer(store, normBuf, x);
//            rotate.mult(store, store);
//            BufferUtils.setInBuffer(store, normBuf, x);
//        }
//    }
 
    /**
     * <code>getDefaultColor</code> returns the color used if no per vertex
     * colors are specified.
     * 
     * @return default color
     */
    public ColorRGBA getDefaultColor()
    {
        return defaultColor;
    }
 
//    public void write(JMEExporter e) throws IOException
//    {
////        super.write(e);
//        OutputCapsule capsule = null; // e.getCapsule(this);
//        capsule.write(colorBuf, "colorBuf", null);
//        capsule.write(normBuf, "normBuf", null);
//        capsule.write(vertBuf, "vertBuf", null);
//        capsule.writeSavableArrayList(texBuf, "texBuf",
//                new ArrayList<TexCoords>(1));
//        capsule.write(tangentBuf, "tangentBuf", null);
//        capsule.write(binormalBuf, "binormalBuf", null);
//        capsule.write(enabled, "enabled", true);
//        capsule.write(castsShadows, "castsShadows", true);
//        capsule.write(bound, "bound", null);
//        capsule.write(defaultColor, "defaultColor", ColorRGBA.white);
//   //     capsule.write(vboInfo, "vboInfo", null);
//    }
//
//    @SuppressWarnings("unchecked")
//    public void read(JMEImporter e) throws IOException
//    {
////        super.read(e);
//        InputCapsule capsule = null; // e.getCapsule(this);
//
//        colorBuf = capsule.readFloatBuffer("colorBuf", null);
//        normBuf = capsule.readFloatBuffer("normBuf", null);
//        vertBuf = capsule.readFloatBuffer("vertBuf", null);
//        if (vertBuf != null)
//        {
//            vertQuantity = vertBuf.limit() / 3;
//        } else
//        {
//            vertQuantity = 0;
//        }
//        tangentBuf = capsule.readFloatBuffer("tangentBuf", null);
//        binormalBuf = capsule.readFloatBuffer("binormalBuf", null);
//        texBuf = capsule.readSavableArrayList("texBuf",
//                new ArrayList<TexCoords>(1));
//        checkTextureCoordinates();
//
//        enabled = capsule.readBoolean("enabled", true);
//        castsShadows = capsule.readBoolean("castsShadows", true);
//        bound = (BoundingVolume) capsule.readSavable("bound", null);
////        if (bound != null)
////        {
////            worldBound = bound.clone(null);
////        }
//        defaultColor = (ColorRGBA) capsule.readSavable("defaultColor",
//                ColorRGBA.white.clone());
////        vboInfo = (VBOInfo) capsule.readSavable("vboInfo", null);
//    }
 
    /**
     * <code>getModelBound</code> retrieves the bounding object that contains
     * the geometry's vertices.
     * 
     * @return the bounding object for this geometry.
     */
    public BoundingVolume getModelBound()
    {
        return bound;
    }
 
    public boolean hasDirtyVertices()
    {
        return hasDirtyVertices;
    }
 
    public void setHasDirtyVertices(boolean flag)
    {
        hasDirtyVertices = flag;
    }
 
    public void setTangentBuffer(FloatBuffer tangentBuf)
    {
        this.tangentBuf = tangentBuf;
    }
 
    public FloatBuffer getTangentBuffer()
    {
        return this.tangentBuf;
    }
 
    public void setBinormalBuffer(FloatBuffer binormalBuf)
    {
        this.binormalBuf = binormalBuf;
    }
 
    public FloatBuffer getBinormalBuffer()
    {
        return binormalBuf;
    }
//    public void setLightState(LightState lightState) {
//        this.lightState = lightState;
//    }
//
//    public LightState getLightState() {
//        return lightState;
//    }
}