Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE-OSG / src / main / java / org / gvsig / gpe / osg / OSGParser.java @ 22231

History | View | Annotate | Download (20.9 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*  osgVP. OSG Virtual Planets.
3
*
4
* Copyright (C) 2007-2008 Infrastructures and Transports Department
5
* of the Valencian Government (CIT)
6
*
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
* MA  02110-1301, USA.
21
*
22
*/
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 Instituto de Automática e Informática Industrial, UPV.
26
*/
27

    
28

    
29
package org.gvsig.gpe.osg;
30

    
31
import java.awt.Color;
32
import java.awt.image.BufferedImage;
33
import java.io.FileNotFoundException;
34
import java.lang.reflect.Constructor;
35
import java.net.URI;
36
import java.util.NoSuchElementException;
37
import java.util.Stack;
38
import java.util.Vector;
39
import java.util.logging.Level;
40

    
41
import org.gvsig.gpe.IGPEContentHandler3D;
42
import org.gvsig.gpe.parser.GPEParser;
43
import org.gvsig.osgvp.AutoTransform;
44
import org.gvsig.osgvp.DrawArrayLengths;
45
import org.gvsig.osgvp.Drawable;
46
import org.gvsig.osgvp.Geode;
47
import org.gvsig.osgvp.Geometry;
48
import org.gvsig.osgvp.Group;
49
import org.gvsig.osgvp.Material;
50
import org.gvsig.osgvp.Matrix;
51
import org.gvsig.osgvp.MatrixTransform;
52
import org.gvsig.osgvp.Node;
53
import org.gvsig.osgvp.PositionAttitudeTransform;
54
import org.gvsig.osgvp.PrimitiveSet;
55
import org.gvsig.osgvp.Quat;
56
import org.gvsig.osgvp.Texture2D;
57
import org.gvsig.osgvp.Vec2;
58
import org.gvsig.osgvp.Vec3;
59
import org.gvsig.osgvp.Vec4;
60
import org.gvsig.osgvp.osgDB;
61
import org.gvsig.osgvp.exceptions.node.ChildIndexOutOfBoundsExceptions;
62
import org.gvsig.osgvp.exceptions.node.LoadNodeException;
63
import org.gvsig.osgvp.exceptions.node.NodeException;
64
import org.gvsig.osgvp.exceptions.texture.TextureStageException;
65
import org.gvsig.osgvp.util.Util;
66

    
67
public class OSGParser extends GPEParser {
68

    
69
        Stack<Matrix> _transforms = new Stack<Matrix>();
70
        Vector<Stack<Texture2D>> _textures = new Vector<Stack<Texture2D>>();
71
        Stack<Material> _materials = new Stack<Material>();
72
        Stack<Boolean> _blendings = new Stack<Boolean>();
73
        private IGPEContentHandler3D _content;
74
        private String description;
75
        private String name;
76

    
77
        public OSGParser(String name, String description) {
78
//                super(name, description);
79
                this.name = name;
80
                this.description = description;
81
        }
82
        
83
        @Override
84
        public String getDescription() {
85
                // TODO Auto-generated method stub
86
                return this.description;
87
        }
88

    
89
        @Override
90
        public String getName() {
91
                // TODO Auto-generated method stub
92
                return this.name;
93
        }
94

    
95
        @Override
96
        public boolean accept(URI uri) {
97
                if ((uri.getPath().toUpperCase().endsWith("OSG"))
98
                                || (uri.getPath().toUpperCase().endsWith("3DS"))
99
                                || (uri.getPath().toUpperCase().endsWith("IVE"))
100
                                || (uri.getPath().toUpperCase().endsWith("OBJ"))) {
101
                        return true;
102
                }
103
                return false;
104
        }
105

    
106
        public String[] getFormats() {
107
                String[] formats = new String[4];
108
                formats[0] = "OSG";
109
                formats[1] = "3DS";
110
                formats[2] = "OBJ";
111
                formats[3] = "IVE";
112
                return formats;
113
        }
114

    
115
        public String[] getVersions() {
116
                String[] versions = new String[1];
117
                versions[0] = "All";
118
                return versions;
119
        }
120

    
121
        @Override
122
        protected void parseStream() {
123

    
124
        }
125

    
126
        @Override
127
        protected void parseURI() {
128

    
129
                // This is a very bad hack to avoid testing hangs in Mac OS Lepard
130
                Color color = new Color(0, 0, 0, 255);
131
                // TODO remove this hack
132

    
133
                Vector<Integer> addedTextures = new Vector<Integer>();
134
                boolean addedMaterial = false;
135

    
136
                _content = (IGPEContentHandler3D) getContentHandler();
137
//                Util.logger.log(Level.FINEST, getMainFile().getPath());
138
                Node root=null;
139

    
140
                try {
141
//                        root = osgDB.readNodeFile(getMainFile().getPath());
142
                        root = osgDB.readNodeFile(getMainFile().toString());
143
                        
144
                } catch (LoadNodeException e) {
145
                        // TODO Auto-generated catch block
146
                        e.printStackTrace();
147
                        return;
148
                } catch (FileNotFoundException e) {
149
                        // TODO Auto-generated catch block
150
                        e.printStackTrace();
151
                        return;
152
                }
153
                if (root == null)
154
//                        Util.logger.log(Level.FINEST, "Cannot open"
155
//                                        + getMainFile().getPath());
156
                System.out.println("error");
157
                else {
158

    
159
                        Object multiGeometry;
160
                        multiGeometry = _content.startMultiGeometry("", "");
161

    
162
                        if (root.className().equals("Geode")) {
163

    
164
                                Geode rootGeode = new Geode(root.getCPtr());
165
                                Object multiSolid;
166

    
167
                                multiSolid = _content.startMultiSolid("", "");
168

    
169
                                _content.addGeometryToMultiGeometry(multiSolid, multiGeometry);
170

    
171
                                try {
172
                                        addedTextures = pushTextures(rootGeode);
173
                                } catch (NodeException e) {
174
                                }
175
                                try {
176
                                        addedMaterial = pushMaterial(rootGeode);
177
                                } catch (NodeException e) {
178
                                }
179
                                
180
                                _blendings.push(rootGeode.getOrCreateStateSet().getEnabledBlending());
181

    
182
                                for (int i = 0; i < rootGeode.getNumDrawables(); i++) {
183

    
184
                                        try {
185
                                                parseDrawable(rootGeode.getDrawable(i), multiSolid);
186
                                        } catch (ChildIndexOutOfBoundsExceptions e) {
187
                                                e.printStackTrace();
188
                                                return;
189
                                        } catch (NodeException e) {
190
                                        }
191

    
192
                                }
193

    
194
                                _blendings.pop();
195
                                _content.endMultiSolid(multiSolid);
196

    
197
                        }
198

    
199
                        else if (root.className().equals("Group")) {
200
                                Group rootGroup;
201

    
202
                                try {
203
                                        rootGroup = new Group(root.getCPtr());
204
                                } catch (NodeException e) {
205
                                        // TODO Auto-generated catch block
206
                                        e.printStackTrace();
207
                                        return;
208
                                }
209
                                try {
210
                                        addedTextures = pushTextures(rootGroup);
211
                                } catch (NodeException e) {
212
                                }
213
                                try {
214
                                        addedMaterial = pushMaterial(rootGroup);
215
                                } catch (NodeException e) {
216
                                }
217
                                _blendings.push(rootGroup.getOrCreateStateSet().getEnabledBlending());
218

    
219
                                for (int i = 0; i < rootGroup.getNumChildren(); i++) {
220

    
221
                                        try {
222
                                                parseNode(rootGroup.getChild(i), multiGeometry);
223
                                        } catch (ChildIndexOutOfBoundsExceptions e) {
224
                                                e.printStackTrace();
225
                                                return;
226
                                        }
227
//                                        Util.logger.log(Level.FINEST, "Node parsed");
228
                                }
229

    
230
                                _blendings.pop();
231

    
232
                        }
233

    
234
                        else {
235

    
236
//                                Util.logger.log(Level.FINEST,
237
//                                                "First parsed object must be Group or Geode");
238

    
239
                        }
240

    
241
                        popTextures(addedTextures);
242
                        if (addedMaterial)
243
                                _materials.pop();
244
                        _content.endMultiGeometry(multiGeometry);
245

    
246
                }
247

    
248
        }
249

    
250
        protected void parseNode(Node node, Object parent) {
251
//                Util.logger.log(Level.FINEST, "node init");
252
                Node instance;
253
                boolean isTransform = false;
254
                boolean addedMaterial = false;
255
                Vector<Integer> addedTextures = new Vector<Integer>();
256

    
257
                try {
258

    
259
                        Class<?> reflect = Class.forName("org.gvsig.osgvp."
260
                                        + node.className());
261
                        Constructor<?> builder = reflect
262
                                        .getConstructor(new Class[] { long.class });
263
                        instance = (Node) builder
264
                                        .newInstance(new Object[] { node.getCPtr() });
265

    
266
                }
267

    
268
                catch (Exception e) {
269
                        instance = new Node(node.getCPtr());
270
                }
271

    
272
                if (instance instanceof Group) {
273

    
274
                        Object multiGeometry;
275
                        multiGeometry = _content.startMultiGeometry("", "");
276
                        _content.addGeometryToMultiGeometry(multiGeometry, parent);
277
                        isTransform = pushTransform((Group) instance);
278
                        try {
279
                                addedTextures = pushTextures(instance);
280
                        } catch (NodeException e) {
281
                        }
282
                        try {
283
                                addedMaterial = pushMaterial(instance);
284
                        } catch (NodeException e) {
285
                        }
286
                        if (_blendings.lastElement())
287
                                _blendings.push(true);
288
                        else
289
                                _blendings.push(instance.getOrCreateStateSet().getEnabledBlending());
290
                        for (int i = 0; i < ((Group) instance).getNumChildren(); i++) {
291

    
292
                                try {
293
                                        parseNode(((Group) instance).getChild(i), multiGeometry);
294
                                } catch (ChildIndexOutOfBoundsExceptions e) {
295
                                        e.printStackTrace();
296
                                        return;
297
                                }
298

    
299
                        }
300
                        if (isTransform)
301
                                _transforms.pop();
302
                        if (addedMaterial)
303
                                _materials.pop();
304
                        _blendings.pop();
305
                        popTextures(addedTextures);
306
                        _content.endMultiGeometry(multiGeometry);
307

    
308
                }
309

    
310
                else if (instance instanceof Geode) {
311

    
312
                        Object multiSolid;
313
                        multiSolid = _content.startMultiSolid("", "");
314
                        _content.addGeometryToMultiGeometry(multiSolid, parent);
315
                        try {
316
                                addedTextures = pushTextures(instance);
317
                        } catch (NodeException e) {
318
                        }
319
                        try {
320
                                addedMaterial = pushMaterial(instance);
321
                        } catch (NodeException e) {
322
                        }
323
                        if (_blendings.lastElement())
324
                                _blendings.push(true);
325
                        else
326
                                _blendings.push(instance.getOrCreateStateSet().getEnabledBlending());
327
                        for (int i = 0; i < ((Geode) instance).getNumDrawables(); i++) {
328

    
329
                                try {
330
                                        parseDrawable(((Geode) instance).getDrawable(i), multiSolid);
331
                                } catch (ChildIndexOutOfBoundsExceptions e) {
332
                                        e.printStackTrace();
333
                                        return;
334
                                } catch (NodeException e) {
335
                                }
336

    
337
                        }
338
                        if (addedMaterial)
339
                                _materials.pop();
340
                        _blendings.pop();
341
                        popTextures(addedTextures);
342
                        _content.endMultiSolid(multiSolid);
343

    
344
                }
345
//                Util.logger.log(Level.FINEST, "Node parsed-0");
346
                // else Util.logger.log(Level.FINEST,instance.className() + " is not
347
                // instanceof
348
                // Group or Geode");
349

    
350
        }
351

    
352
        protected void parseDrawable(Drawable drawable, Object feature)
353
                        throws NodeException {
354
                Util.logger.log(Level.FINEST, "drawable init");
355
                int t = 0;
356
                if (drawable instanceof Geometry) {
357

    
358
                        int j;
359
                        Object solid;
360
                        solid = _content.startSolid("", "");
361
                        _content.addSolidToMultiSolid(solid, feature);
362

    
363
                        Matrix matrix = new Matrix();
364
                        for (int i = 0; i < _transforms.size(); i++) {
365

    
366
                                matrix.mult(_transforms.get(i), matrix);
367

    
368
                        }
369

    
370
//                        Util.logger.log(Level.FINEST, "transforms");
371

    
372
                        Vector<Vec3> vertices = ((Geometry) drawable).getVertexArray();
373
                        if (vertices == null)
374
                                vertices = new Vector<Vec3>();
375
                        Vec3 vertex;
376
                        int i;
377
//                        Util.logger.log(Level.FINEST, "vertex starts");
378
                        _content.startSolidVertexArray(solid);
379
                        for (i = 0; i < vertices.size(); i++) {
380

    
381
                                vertex = vertices.get(i);
382

    
383
                                // Util.logger.log(Level.FINEST,"Vertice sin
384
                                // transformar"+vertex.x()+";"+vertex.y()+";"+vertex.z()+";");
385
                                vertex = matrix.prod(vertex, matrix);
386

    
387
                                // Util.logger.log(Level.FINEST,"Vertice
388
                                // transformado"+vertex.x()+";"+vertex.y()+";"+vertex.z()+";");
389
                                _content.addVertexToSolid(solid, vertex.x(), vertex.y(), vertex
390
                                                .z());
391

    
392
                        }
393
                        _content.endSolidVertexArray();
394

    
395
                        Vector<Vec3> normals = ((Geometry) drawable).getNormalArray();
396
//                        Util.logger.log(Level.FINEST, "talla normals" + normals.size());
397

    
398
                        if (normals == null)
399
                                normals = new Vector<Vec3>();
400

    
401
                        Vec3 normal;
402
                        _content.startSolidNormalArray(solid);
403

    
404
                        for (i = 0; i < normals.size(); i++) {
405

    
406
                                normal = normals.get(i);
407
//                                Util.logger.log(Level.FINEST, " normal bucleee" + normal);
408
                                normal = matrix.prod(normal, matrix);
409
                                normal.normalize();
410
                                _content.addNormalToSolid(solid, normal.x(), normal.y(), normal
411
                                                .z());
412

    
413
                        }
414
                        _content.endSolidNormalArray();
415

    
416
                        _content.setNormalBindingToSolid(solid, ((Geometry) drawable)
417
                                        .getNormalBinding());
418

    
419
                        try {
420
                                Vector<Vec4> colors = ((Geometry) drawable).getColorArray();
421
                                if (colors == null)
422
                                        colors = new Vector<Vec4>();
423
                                Vec4 color;
424
//                                Util.logger.log(Level.FINEST, "color starts" + colors.size());
425
                                _content.startSolidColorArray(solid);
426
                                for (i = 0; i < colors.size(); i++) {
427
//                                        Util.logger.log(Level.FINEST, "bucleeeeee 0");
428
                                        color = colors.get(i);
429
                                        _content
430
                                                        .addColorToSolid(solid, (float) color.x(),
431
                                                                        (float) color.y(), (float) color.z(),
432
                                                                        (float) color.w());
433
                                        //Util.logger.log(Level.FINEST, "bucleeeeee");
434
                                }
435

    
436
                                _content.endSolidColorArray();
437

    
438
                        } catch (NullPointerException e) {
439

    
440
                                
441

    
442
                        }
443
                        
444
                        //Util.logger.log(Level.FINEST, "primitiveSets: "
445
//                                        + ((Geometry) drawable).getNumPrimitiveSets());
446

    
447
                        for (int k = 0; k < ((Geometry) drawable).getNumPrimitiveSets(); k++) {
448
                                int mode = ((Geometry) drawable).getPrimitiveSet(k).getMode();
449
                                int type = ((Geometry) drawable).getPrimitiveSet(k).getType();
450

    
451
                                if (type == PrimitiveSet.Type.DrawArrayLengthsPrimitiveType) {
452

    
453
                                        int offset = 0;
454
                                        int accum = 0;
455
                                        DrawArrayLengths lengths = new DrawArrayLengths(
456
                                                        ((PrimitiveSet) ((Geometry) drawable)
457
                                                                        .getPrimitiveSet(k)).getCPtr());
458
                                        Vector<Integer> arrayLengths = lengths
459
                                                        .getElementLengthsVector();
460

    
461
                                        if (arrayLengths == null)
462
                                                arrayLengths = new Vector<Integer>();
463

    
464
                                        for (int h = 0; h < arrayLengths.size(); h++) {
465

    
466
                                                Object primitiveSet = _content.startPrimitiveSet(mode,
467
                                                                PrimitiveSet.Type.DrawArraysPrimitiveType);
468
                                                _content.addPrimitiveSetToSolid(solid, primitiveSet);
469

    
470
                                                accum = arrayLengths.get(h);
471

    
472
                                                for (int l = 0; l < accum; l++) {
473

    
474
                                                        _content.addIndexToPrimitiveSet(primitiveSet,
475
                                                                        ((Geometry) drawable).getPrimitiveSet(k)
476
                                                                                        .index(offset + l));
477

    
478
                                                }
479

    
480
                                                offset = offset + accum;
481
                                                _content.endPrimitiveSetIndexArray();
482
                                                _content.endPrimitiveSet(primitiveSet);
483

    
484
                                        }
485

    
486
                                } else {
487
                                        Object primitiveSet = _content
488
                                                        .startPrimitiveSet(mode, type);
489

    
490
                                        _content.addPrimitiveSetToSolid(solid, primitiveSet);
491
                                        _content.startPrimitiveSetIndexArray(primitiveSet,
492
                                                        ((Geometry) drawable).getPrimitiveSet(k)
493
                                                                        .getNumIndices());
494
                                        //Util.logger.log(Level.FINEST, "Num Indices: "
495
//                                                        + String.valueOf(((Geometry) drawable)
496
//                                                                        .getPrimitiveSet(k).getNumIndices()));
497
                                        for (int ps = 0; ps < ((Geometry) drawable)
498
                                                        .getPrimitiveSet(k).getNumIndices(); ps++) {
499

    
500
                                                //Util.logger.log(Level.FINEST, "adding index");
501
                                                _content.addIndexToPrimitiveSet(primitiveSet,
502
                                                                ((Geometry) drawable).getPrimitiveSet(k).index(
503
                                                                                ps));
504
                                                //Util.logger.log(Level.FINEST, String.valueOf(t));
505
//                                                t++;
506
                                        }
507
                                        _content.endPrimitiveSetIndexArray();
508
                                        _content.endPrimitiveSet(primitiveSet);
509
                                }
510

    
511
                        }
512

    
513
                        Vector<Integer> addedTextures = new Vector<Integer>();
514
                        boolean addedMaterial = false;
515

    
516
                        addedTextures = pushTexturesDrawable(drawable);
517

    
518
                        //Util.logger.log(Level.FINEST, "Added textures: " + addedTextures);
519

    
520
                        try {
521
                                addTexturesToGeometry(solid);
522
                        } catch (Exception e) {
523

    
524
                                e.printStackTrace();
525
                        }
526

    
527
                        //Util.logger.log(Level.FINEST, "getNumTextures"
528
//                                        + drawable.getOrCreateStateSet().getNumTextureStages());
529
                        for (j = 0; j < drawable.getOrCreateStateSet().getNumTextureStages(); j++) {
530

    
531
                                try {
532
                                        if (drawable.getOrCreateStateSet().getTextureAttribute(j) != null) {
533
                                                Vector<Vec2> texCoords = ((Geometry) drawable)
534
                                                                .getTexCoordArray(j);
535
                                                if (texCoords == null)
536
                                                        texCoords = new Vector<Vec2>();
537
                                                Vec2 texCoord;
538

    
539
                                                _content
540
                                                                .startSolidTexCoordArray(solid, texCoords.size(), j);
541

    
542
                                                for (i = 0; i < texCoords.size(); i++) {
543

    
544
                                                        texCoord = texCoords.get(i);
545
                                                        _content.addTextureCoordinateToSolid(solid, texCoord
546
                                                                        .x(), texCoord.y(), j);
547

    
548
                                                }
549
                                                _content.endSolidTexCoordArray();
550
                                        }
551
                                } catch (TextureStageException e) {
552
                                        // TODO Auto-generated catch block
553
                                        e.printStackTrace();
554
                                }
555
                        }
556

    
557
                        addedMaterial = pushMaterialDrawable(drawable);
558
                        try {
559

    
560
                                Material osgMaterial = _materials.lastElement();
561

    
562
                                float x, y, z, w;
563

    
564
                                Vec4 vectorAmb = new Vec4();
565
                                Vec4 vectorDif = new Vec4();
566
                                Vec4 vectorEmi = new Vec4();
567
                                Vec4 vectorSpe = new Vec4();
568

    
569
                                vectorAmb = osgMaterial.getAmbient(Material.Face.FRONT);
570
                                vectorDif = osgMaterial.getDiffuse(Material.Face.FRONT);
571
                                vectorEmi = osgMaterial.getEmission(Material.Face.FRONT);
572
                                vectorSpe = osgMaterial.getSpecular(Material.Face.FRONT);
573

    
574
                                Object material = _content.startMaterial();
575
                                x = (float) vectorAmb.x();
576
                                y = (float) vectorAmb.y();
577
                                z = (float) vectorAmb.z();
578
                                w = (float) vectorAmb.w();
579

    
580
                                _content.addAmbientToMaterial(material, x, y, z, w);
581

    
582
                                x = (float) vectorDif.x();
583
                                y = (float) vectorDif.y();
584
                                z = (float) vectorDif.z();
585
                                w = (float) vectorDif.w();
586

    
587
                                _content.addDiffuseToMaterial(material, x, y, z, w);
588

    
589
                                x = (float) vectorSpe.x();
590
                                y = (float) vectorSpe.y();
591
                                z = (float) vectorSpe.z();
592
                                w = (float) vectorSpe.w();
593

    
594
                                _content.addSpecularToMaterial(material, x, y, z, w);
595

    
596
                                x = (float) vectorEmi.x();
597
                                y = (float) vectorEmi.y();
598
                                z = (float) vectorEmi.z();
599
                                w = (float) vectorEmi.w();
600

    
601
                                _content.addEmissionToMaterial(material, x, y, z, w);
602

    
603
                                _content.addShininessToMaterial(material, osgMaterial
604
                                                .getShininess(Material.Face.FRONT));
605

    
606
                                _content.addMaterialToSolid(solid, material);
607

    
608
                                _content.endMaterial(material);
609

    
610
                        } catch (ArrayIndexOutOfBoundsException ex) {
611

    
612
                        }
613

    
614
                        if (_blendings.lastElement())
615
                                _content.addBlendingToSolid(solid, true);
616
                        else
617
                                _content.addBlendingToSolid(solid, drawable.getOrCreateStateSet()
618
                                                .getEnabledBlending());
619

    
620
                        popTextures(addedTextures);
621

    
622
                        _content.endSolid(solid);
623

    
624
                }
625
                //Util.logger.log(Level.FINEST, "drawable parsed");
626
        }
627

    
628
        protected boolean pushTransform(Group group) {
629

    
630
                if (group instanceof MatrixTransform) {
631

    
632
                        // Util.logger.log(Level.FINEST,"Push a MatrixTransform");
633
                        _transforms.push(((MatrixTransform) group).getMatrix());
634

    
635
                        return true;
636

    
637
                }
638

    
639
                if (group instanceof PositionAttitudeTransform) {
640

    
641
                        // Util.logger.log(Level.FINEST,"Push a PAT");
642
                        Matrix scaleMatrix = Matrix
643
                                        .scale(((PositionAttitudeTransform) group).getScale());
644

    
645
                        Quat quat = new Quat((((PositionAttitudeTransform) group)
646
                                        .getAttitudeAngle()), (((PositionAttitudeTransform) group)
647
                                        .getAttitudeAxis()));
648
                        Matrix rotateMatrix = Matrix.rotate(quat);
649

    
650
                        Matrix transMatrix = Matrix
651
                                        .translate(((PositionAttitudeTransform) group)
652
                                                        .getPosition());
653

    
654
                        rotateMatrix.postMult(scaleMatrix);
655
                        transMatrix.postMult(rotateMatrix);
656

    
657
                        _transforms.push(transMatrix);
658

    
659
                        return true;
660

    
661
                }
662

    
663
                if (group instanceof AutoTransform) {
664

    
665
                        // Util.logger.log(Level.FINEST,"Push a AutoTransform");
666
                        Matrix scaleMatrix = Matrix.scale(((AutoTransform) group)
667
                                        .getScale());
668
                        Quat quat = new Quat((((AutoTransform) group).getRotationAngle()),
669
                                        (((AutoTransform) group).getRotationAxis()));
670
                        Matrix rotateMatrix = Matrix.rotate(quat);
671
                        Matrix transMatrix = Matrix.translate(((AutoTransform) group)
672
                                        .getPosition());
673

    
674
                        rotateMatrix.postMult(scaleMatrix);
675
                        transMatrix.postMult(rotateMatrix);
676

    
677
                        _transforms.push(transMatrix);
678

    
679
                        return true;
680

    
681
                }
682

    
683
                return false;
684

    
685
        }
686

    
687
        protected Vector<Integer> pushTextures(Node node) throws NodeException {
688

    
689
                int numTextures;
690
                numTextures = node.getOrCreateStateSet().getNumTextureStages();
691
                Vector<Texture2D> vector = node.getOrCreateStateSet().getTextureAttributeVector();
692
                Vector<Integer> stages = new Vector<Integer>();
693

    
694
                for (int i = 0; i < numTextures; i++) {
695

    
696
                        _textures.get(i);
697

    
698
                        _textures.add(i, new Stack<Texture2D>());
699

    
700
                        _textures.get(i).push(vector.get(i));
701
                        // Util.logger.log(Level.FINEST,"PUSH");
702
                        stages.add(i);
703

    
704
                }
705

    
706
                return stages;
707
        }
708

    
709
        protected boolean pushMaterial(Node node) throws NodeException {
710

    
711
                boolean hasMaterial = false;
712

    
713
                Material material;
714
                material = node.getOrCreateStateSet().getMaterial();
715
                _materials.push(material);
716
                hasMaterial = true;
717

    
718
                return hasMaterial;
719

    
720
        }
721

    
722
        protected Vector<Integer> pushTexturesDrawable(Drawable drawable)
723
                        throws NodeException {
724

    
725
                int numTextures;
726
                numTextures = drawable.getOrCreateStateSet().getNumTextureStages();
727
                Vector<Texture2D> vector = drawable.getOrCreateStateSet().getTextureAttributeVector();
728
                Vector<Integer> stages = new Vector<Integer>();
729

    
730
                //Util.logger.log(Level.FINEST, "NumTextures: " + numTextures);
731
                for (int i = 0; i < numTextures; i++) {
732

    
733
                        try {
734

    
735
                                _textures.get(i);
736

    
737
                        } catch (ArrayIndexOutOfBoundsException ex) {
738

    
739
                                _textures.add(i, new Stack<Texture2D>());
740

    
741
                        }
742

    
743
                        try {
744

    
745
                                _textures.get(i).push(vector.get(i));
746
                                // Util.logger.log(Level.FINEST,"PUSH");
747
                                stages.add(i);
748
                                Util.logger.log(Level.FINEST, "Added textures: " + stages);
749
                        } catch (ArrayIndexOutOfBoundsException ex) {
750

    
751
                        }
752
                }
753

    
754
                return stages;
755
        }
756

    
757
        protected boolean pushMaterialDrawable(Drawable draw) throws NodeException {
758

    
759
                boolean hasMaterial = false;
760

    
761
                try {
762

    
763
                        Material material;
764
                        material = draw.getOrCreateStateSet().getMaterial();
765
                        _materials.push(material);
766
                        hasMaterial = true;
767

    
768
                } catch (ArrayIndexOutOfBoundsException ex) {
769

    
770
                        hasMaterial = false;
771

    
772
                } catch (NullPointerException e) {
773

    
774
                }
775

    
776
                return hasMaterial;
777

    
778
        }
779

    
780
        protected void popTextures(Vector<Integer> stages) {
781

    
782
                for (int i = 0; i < stages.size(); i++) {
783

    
784
                        // Util.logger.log(Level.FINEST,"POP");
785
                        _textures.get(stages.get(i)).pop();
786

    
787
                }
788

    
789
        }
790

    
791
        protected void addTexturesToGeometry(Object solid) throws Exception {
792

    
793
                BufferedImage image;
794
                for (int i = 0; i < _textures.size(); i++) {
795

    
796
                        try {
797
                                //Util.logger.log(Level.FINEST, "Num textures in stack: "
798
//                                                + _textures.get(i).size());
799
                                _textures.get(i).lastElement();
800
                                try {
801
                                        //Util.logger.log(Level.FINEST, "TRYING STAGE: " + i);
802
                                        image = _textures.get(i).lastElement().getImage()
803
                                                        .getBufferedImage();
804
                                        _content.addTextureToSolid(solid, i, image);
805

    
806
                                } catch (ArrayIndexOutOfBoundsException ex) {
807

    
808
                                }
809
                        }
810

    
811
                        catch (NoSuchElementException ex) {
812

    
813
                        }
814
                }
815

    
816
        }
817

    
818
        @Override
819
        public String getFormat() {
820
                // TODO Auto-generated method stub
821
                return null;
822
        }
823

    
824
        
825
}