Statistics
| Revision:

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

History | View | Annotate | Download (20.7 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
        @Override
107
        public String[] getFormats() {
108
                String[] formats = new String[4];
109
                formats[0] = "OSG";
110
                formats[1] = "3DS";
111
                formats[2] = "OBJ";
112
                formats[3] = "IVE";
113
                return formats;
114
        }
115

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

    
123
        @Override
124
        protected void parseStream() {
125

    
126
        }
127

    
128
        @Override
129
        protected void parseURI() {
130

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

    
135
                Vector<Integer> addedTextures = new Vector<Integer>();
136
                boolean addedMaterial = false;
137

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

    
142
                try {
143
                        root = osgDB.readNodeFile(getMainFile().getPath());
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
                else {
157

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

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

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

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

    
168
                                _content.addGeometryToMultiGeometry(multiSolid, multiGeometry);
169

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

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

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

    
191
                                }
192

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

    
196
                        }
197

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

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

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

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

    
229
                                _blendings.pop();
230

    
231
                        }
232

    
233
                        else {
234

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

    
238
                        }
239

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

    
245
                }
246

    
247
        }
248

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

    
256
                try {
257

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

    
265
                }
266

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

    
271
                if (instance instanceof Group) {
272

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

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

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

    
307
                }
308

    
309
                else if (instance instanceof Geode) {
310

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

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

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

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

    
349
        }
350

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

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

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

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

    
367
                        }
368

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

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

    
380
                                vertex = vertices.get(i);
381

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

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

    
391
                        }
392
                        _content.endSolidVertexArray();
393

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

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

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

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

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

    
412
                        }
413
                        _content.endSolidNormalArray();
414

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

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

    
435
                                _content.endSolidColorArray();
436

    
437
                        } catch (NullPointerException e) {
438

    
439
                                
440

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

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

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

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

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

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

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

    
469
                                                accum = arrayLengths.get(h);
470

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

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

    
477
                                                }
478

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

    
483
                                        }
484

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

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

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

    
510
                        }
511

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

    
515
                        addedTextures = pushTexturesDrawable(drawable);
516

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

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

    
523
                                e.printStackTrace();
524
                        }
525

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

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

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

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

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

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

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

    
559
                                Material osgMaterial = _materials.lastElement();
560

    
561
                                float x, y, z, w;
562

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

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

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

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

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

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

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

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

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

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

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

    
605
                                _content.addMaterialToSolid(solid, material);
606

    
607
                                _content.endMaterial(material);
608

    
609
                        } catch (ArrayIndexOutOfBoundsException ex) {
610

    
611
                        }
612

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

    
619
                        popTextures(addedTextures);
620

    
621
                        _content.endSolid(solid);
622

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

    
627
        protected boolean pushTransform(Group group) {
628

    
629
                if (group instanceof MatrixTransform) {
630

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

    
634
                        return true;
635

    
636
                }
637

    
638
                if (group instanceof PositionAttitudeTransform) {
639

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

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

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

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

    
656
                        _transforms.push(transMatrix);
657

    
658
                        return true;
659

    
660
                }
661

    
662
                if (group instanceof AutoTransform) {
663

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

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

    
676
                        _transforms.push(transMatrix);
677

    
678
                        return true;
679

    
680
                }
681

    
682
                return false;
683

    
684
        }
685

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

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

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

    
695
                        _textures.get(i);
696

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

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

    
703
                }
704

    
705
                return stages;
706
        }
707

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

    
710
                boolean hasMaterial = false;
711

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

    
717
                return hasMaterial;
718

    
719
        }
720

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

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

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

    
732
                        try {
733

    
734
                                _textures.get(i);
735

    
736
                        } catch (ArrayIndexOutOfBoundsException ex) {
737

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

    
740
                        }
741

    
742
                        try {
743

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

    
750
                        }
751
                }
752

    
753
                return stages;
754
        }
755

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

    
758
                boolean hasMaterial = false;
759

    
760
                try {
761

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

    
767
                } catch (ArrayIndexOutOfBoundsException ex) {
768

    
769
                        hasMaterial = false;
770

    
771
                } catch (NullPointerException e) {
772

    
773
                }
774

    
775
                return hasMaterial;
776

    
777
        }
778

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

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

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

    
786
                }
787

    
788
        }
789

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

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

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

    
805
                                } catch (ArrayIndexOutOfBoundsException ex) {
806

    
807
                                }
808
                        }
809

    
810
                        catch (NoSuchElementException ex) {
811

    
812
                        }
813
                }
814

    
815
        }
816

    
817
        
818
}