Revision 25106
trunk/libraries/libGPE-OSG/src/main/java/org/gvsig/gpe/osg/OSGParser.java | ||
---|---|---|
1 | 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 |
*/ |
|
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 | 23 |
/* |
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 Instituto de Automática e Informática Industrial, UPV. |
|
26 |
*/ |
|
24 |
* AUTHORS (In addition to CIT):
|
|
25 |
* 2008 Instituto de Automática e Informática Industrial, UPV.
|
|
26 |
*/
|
|
27 | 27 |
|
28 |
|
|
29 | 28 |
package org.gvsig.gpe.osg; |
30 | 29 |
|
31 | 30 |
import java.awt.Color; |
... | ... | |
75 | 74 |
private String name; |
76 | 75 |
|
77 | 76 |
public OSGParser(String name, String description) { |
78 |
// super(name, description);
|
|
77 |
// super(name, description);
|
|
79 | 78 |
this.name = name; |
80 | 79 |
this.description = description; |
81 | 80 |
} |
82 |
|
|
81 |
|
|
83 | 82 |
@Override |
84 | 83 |
public String getDescription() { |
85 | 84 |
// TODO Auto-generated method stub |
... | ... | |
120 | 119 |
|
121 | 120 |
@Override |
122 | 121 |
protected void parseStream() { |
123 |
|
|
124 |
|
|
122 |
|
|
125 | 123 |
} |
126 | 124 |
|
127 | 125 |
@Override |
... | ... | |
139 | 137 |
Node root=null; |
140 | 138 |
|
141 | 139 |
try { |
142 |
// root = osgDB.readNodeFile(getMainFile().getPath()); |
|
143 |
root = osgDB.readNodeFile(getMainFile().getPath().substring(1, getMainFile().getPath().length())); |
|
140 |
String os = System.getProperty("os.name"); |
|
141 |
String path; |
|
142 |
if (os.toLowerCase().startsWith("windows")) { |
|
143 |
|
|
144 |
path = getMainFile().getPath().substring(1, |
|
145 |
getMainFile().getPath().length()); |
|
146 |
} else { |
|
147 |
path = getMainFile().getPath(); |
|
148 |
} |
|
144 | 149 |
|
150 |
root = osgDB.readNodeFile(path); |
|
151 |
// root = osgDB.readNodeFile(getMainFile().getPath().substring(1, getMainFile().getPath().length())); |
|
152 |
|
|
145 | 153 |
} catch (LoadNodeException e) { |
146 | 154 |
// TODO Auto-generated catch block |
147 | 155 |
e.printStackTrace(); |
... | ... | |
251 | 259 |
} |
252 | 260 |
|
253 | 261 |
protected void parseNode(Node node, Object parent) { |
254 |
// Util.logger.log(Level.FINEST, "node init");
|
|
262 |
// Util.logger.log(Level.FINEST, "node init");
|
|
255 | 263 |
Node instance; |
256 | 264 |
boolean isTransform = false; |
257 | 265 |
boolean addedMaterial = false; |
... | ... | |
289 | 297 |
if (_blendings.lastElement()) |
290 | 298 |
_blendings.push(true); |
291 | 299 |
else |
292 |
_blendings.push(instance.getOrCreateStateSet().getEnabledBlending()); |
|
300 |
_blendings.push(instance.getOrCreateStateSet() |
|
301 |
.getEnabledBlending()); |
|
293 | 302 |
for (int i = 0; i < ((Group) instance).getNumChildren(); i++) { |
294 | 303 |
|
295 | 304 |
try { |
... | ... | |
326 | 335 |
if (_blendings.lastElement()) |
327 | 336 |
_blendings.push(true); |
328 | 337 |
else |
329 |
_blendings.push(instance.getOrCreateStateSet().getEnabledBlending()); |
|
338 |
_blendings.push(instance.getOrCreateStateSet() |
|
339 |
.getEnabledBlending()); |
|
330 | 340 |
for (int i = 0; i < ((Geode) instance).getNumDrawables(); i++) { |
331 | 341 |
|
332 | 342 |
try { |
... | ... | |
345 | 355 |
_content.endMultiSolid(multiSolid); |
346 | 356 |
|
347 | 357 |
} |
348 |
// Util.logger.log(Level.FINEST, "Node parsed-0");
|
|
358 |
// Util.logger.log(Level.FINEST, "Node parsed-0");
|
|
349 | 359 |
// else Util.logger.log(Level.FINEST,instance.className() + " is not |
350 | 360 |
// instanceof |
351 | 361 |
// Group or Geode"); |
... | ... | |
370 | 380 |
|
371 | 381 |
} |
372 | 382 |
|
373 |
// Util.logger.log(Level.FINEST, "transforms");
|
|
383 |
// Util.logger.log(Level.FINEST, "transforms");
|
|
374 | 384 |
|
375 | 385 |
Vector<Vec3> vertices = ((Geometry) drawable).getVertexArray(); |
376 | 386 |
if (vertices == null) |
377 | 387 |
vertices = new Vector<Vec3>(); |
378 | 388 |
Vec3 vertex; |
379 | 389 |
int i; |
380 |
// Util.logger.log(Level.FINEST, "vertex starts");
|
|
390 |
// Util.logger.log(Level.FINEST, "vertex starts");
|
|
381 | 391 |
_content.startSolidVertexArray(solid); |
382 | 392 |
for (i = 0; i < vertices.size(); i++) { |
383 | 393 |
|
... | ... | |
396 | 406 |
_content.endSolidVertexArray(); |
397 | 407 |
|
398 | 408 |
Vector<Vec3> normals = ((Geometry) drawable).getNormalArray(); |
399 |
// Util.logger.log(Level.FINEST, "talla normals" + normals.size());
|
|
409 |
// Util.logger.log(Level.FINEST, "talla normals" + normals.size());
|
|
400 | 410 |
|
401 | 411 |
if (normals == null) |
402 | 412 |
normals = new Vector<Vec3>(); |
... | ... | |
407 | 417 |
for (i = 0; i < normals.size(); i++) { |
408 | 418 |
|
409 | 419 |
normal = normals.get(i); |
410 |
// Util.logger.log(Level.FINEST, " normal bucleee" + normal);
|
|
420 |
// Util.logger.log(Level.FINEST, " normal bucleee" + normal);
|
|
411 | 421 |
normal = matrix.prod(normal, matrix); |
412 | 422 |
normal.normalize(); |
413 | 423 |
_content.addNormalToSolid(solid, normal.x(), normal.y(), normal |
... | ... | |
424 | 434 |
if (colors == null) |
425 | 435 |
colors = new Vector<Vec4>(); |
426 | 436 |
Vec4 color; |
427 |
// Util.logger.log(Level.FINEST, "color starts" + colors.size()); |
|
437 |
// Util.logger.log(Level.FINEST, "color starts" + |
|
438 |
// colors.size()); |
|
428 | 439 |
_content.startSolidColorArray(solid); |
429 | 440 |
for (i = 0; i < colors.size(); i++) { |
430 |
// Util.logger.log(Level.FINEST, "bucleeeeee 0");
|
|
441 |
// Util.logger.log(Level.FINEST, "bucleeeeee 0");
|
|
431 | 442 |
color = colors.get(i); |
432 |
_content |
|
433 |
.addColorToSolid(solid, (float) color.x(), |
|
434 |
(float) color.y(), (float) color.z(), |
|
435 |
(float) color.w()); |
|
436 |
//Util.logger.log(Level.FINEST, "bucleeeeee"); |
|
443 |
_content.addColorToSolid(solid, (float) color.x(), |
|
444 |
(float) color.y(), (float) color.z(), (float) color |
|
445 |
.w()); |
|
446 |
// Util.logger.log(Level.FINEST, "bucleeeeee"); |
|
437 | 447 |
} |
438 | 448 |
|
439 | 449 |
_content.endSolidColorArray(); |
440 | 450 |
|
441 | 451 |
} catch (NullPointerException e) { |
442 | 452 |
|
443 |
|
|
444 |
|
|
445 | 453 |
} |
446 |
|
|
447 |
//Util.logger.log(Level.FINEST, "primitiveSets: " |
|
448 |
// + ((Geometry) drawable).getNumPrimitiveSets()); |
|
449 | 454 |
|
455 |
// Util.logger.log(Level.FINEST, "primitiveSets: " |
|
456 |
// + ((Geometry) drawable).getNumPrimitiveSets()); |
|
457 |
|
|
450 | 458 |
for (int k = 0; k < ((Geometry) drawable).getNumPrimitiveSets(); k++) { |
451 | 459 |
int mode = ((Geometry) drawable).getPrimitiveSet(k).getMode(); |
452 | 460 |
int type = ((Geometry) drawable).getPrimitiveSet(k).getType(); |
... | ... | |
494 | 502 |
_content.startPrimitiveSetIndexArray(primitiveSet, |
495 | 503 |
((Geometry) drawable).getPrimitiveSet(k) |
496 | 504 |
.getNumIndices()); |
497 |
//Util.logger.log(Level.FINEST, "Num Indices: " |
|
498 |
// + String.valueOf(((Geometry) drawable)
|
|
499 |
// .getPrimitiveSet(k).getNumIndices()));
|
|
505 |
// Util.logger.log(Level.FINEST, "Num Indices: "
|
|
506 |
// + String.valueOf(((Geometry) drawable)
|
|
507 |
// .getPrimitiveSet(k).getNumIndices()));
|
|
500 | 508 |
for (int ps = 0; ps < ((Geometry) drawable) |
501 | 509 |
.getPrimitiveSet(k).getNumIndices(); ps++) { |
502 | 510 |
|
503 |
//Util.logger.log(Level.FINEST, "adding index"); |
|
511 |
// Util.logger.log(Level.FINEST, "adding index");
|
|
504 | 512 |
_content.addIndexToPrimitiveSet(primitiveSet, |
505 | 513 |
((Geometry) drawable).getPrimitiveSet(k).index( |
506 | 514 |
ps)); |
507 |
//Util.logger.log(Level.FINEST, String.valueOf(t)); |
|
508 |
// t++;
|
|
515 |
// Util.logger.log(Level.FINEST, String.valueOf(t));
|
|
516 |
// t++;
|
|
509 | 517 |
} |
510 | 518 |
_content.endPrimitiveSetIndexArray(); |
511 | 519 |
_content.endPrimitiveSet(primitiveSet); |
... | ... | |
518 | 526 |
|
519 | 527 |
addedTextures = pushTexturesDrawable(drawable); |
520 | 528 |
|
521 |
//Util.logger.log(Level.FINEST, "Added textures: " + addedTextures); |
|
529 |
// Util.logger.log(Level.FINEST, "Added textures: " + |
|
530 |
// addedTextures); |
|
522 | 531 |
|
523 | 532 |
try { |
524 | 533 |
addTexturesToGeometry(solid); |
... | ... | |
527 | 536 |
e.printStackTrace(); |
528 | 537 |
} |
529 | 538 |
|
530 |
//Util.logger.log(Level.FINEST, "getNumTextures" |
|
531 |
// + drawable.getOrCreateStateSet().getNumTextureStages()); |
|
532 |
for (j = 0; j < drawable.getOrCreateStateSet().getNumTextureStages(); j++) { |
|
539 |
// Util.logger.log(Level.FINEST, "getNumTextures" |
|
540 |
// + drawable.getOrCreateStateSet().getNumTextureStages()); |
|
541 |
for (j = 0; j < drawable.getOrCreateStateSet() |
|
542 |
.getNumTextureStages(); j++) { |
|
533 | 543 |
|
534 | 544 |
try { |
535 | 545 |
if (drawable.getOrCreateStateSet().getTextureAttribute(j) != null) { |
... | ... | |
539 | 549 |
texCoords = new Vector<Vec2>(); |
540 | 550 |
Vec2 texCoord; |
541 | 551 |
|
542 |
_content |
|
543 |
.startSolidTexCoordArray(solid, texCoords.size(), j);
|
|
552 |
_content.startSolidTexCoordArray(solid, texCoords
|
|
553 |
.size(), j); |
|
544 | 554 |
|
545 | 555 |
for (i = 0; i < texCoords.size(); i++) { |
546 | 556 |
|
547 | 557 |
texCoord = texCoords.get(i); |
548 |
_content.addTextureCoordinateToSolid(solid, texCoord
|
|
549 |
.x(), texCoord.y(), j); |
|
558 |
_content.addTextureCoordinateToSolid(solid, |
|
559 |
texCoord.x(), texCoord.y(), j);
|
|
550 | 560 |
|
551 | 561 |
} |
552 | 562 |
_content.endSolidTexCoordArray(); |
... | ... | |
617 | 627 |
if (_blendings.lastElement()) |
618 | 628 |
_content.addBlendingToSolid(solid, true); |
619 | 629 |
else |
620 |
_content.addBlendingToSolid(solid, drawable.getOrCreateStateSet()
|
|
621 |
.getEnabledBlending()); |
|
630 |
_content.addBlendingToSolid(solid, drawable |
|
631 |
.getOrCreateStateSet().getEnabledBlending());
|
|
622 | 632 |
|
623 | 633 |
popTextures(addedTextures); |
624 | 634 |
|
625 | 635 |
_content.endSolid(solid); |
626 | 636 |
|
627 | 637 |
} |
628 |
//Util.logger.log(Level.FINEST, "drawable parsed"); |
|
638 |
// Util.logger.log(Level.FINEST, "drawable parsed");
|
|
629 | 639 |
} |
630 | 640 |
|
631 | 641 |
protected boolean pushTransform(Group group) { |
... | ... | |
654 | 664 |
.translate(((PositionAttitudeTransform) group) |
655 | 665 |
.getPosition()); |
656 | 666 |
|
657 |
// rotateMatrix.postMult(scaleMatrix);
|
|
658 |
// transMatrix.postMult(rotateMatrix);
|
|
667 |
// rotateMatrix.postMult(scaleMatrix);
|
|
668 |
// transMatrix.postMult(rotateMatrix);
|
|
659 | 669 |
rotateMatrix.preMult(scaleMatrix); |
660 | 670 |
transMatrix.preMult(rotateMatrix); |
661 | 671 |
|
... | ... | |
676 | 686 |
Matrix transMatrix = Matrix.translate(((AutoTransform) group) |
677 | 687 |
.getPosition()); |
678 | 688 |
|
679 |
// rotateMatrix.postMult(scaleMatrix);
|
|
680 |
// transMatrix.postMult(rotateMatrix);
|
|
681 |
|
|
689 |
// rotateMatrix.postMult(scaleMatrix);
|
|
690 |
// transMatrix.postMult(rotateMatrix);
|
|
691 |
|
|
682 | 692 |
rotateMatrix.preMult(scaleMatrix); |
683 | 693 |
transMatrix.preMult(rotateMatrix); |
684 | 694 |
|
... | ... | |
696 | 706 |
|
697 | 707 |
int numTextures; |
698 | 708 |
numTextures = node.getOrCreateStateSet().getNumTextureStages(); |
699 |
Vector<Texture2D> vector = node.getOrCreateStateSet().getTextureAttributeVector(); |
|
709 |
Vector<Texture2D> vector = node.getOrCreateStateSet() |
|
710 |
.getTextureAttributeVector(); |
|
700 | 711 |
Vector<Integer> stages = new Vector<Integer>(); |
701 | 712 |
|
702 | 713 |
for (int i = 0; i < numTextures; i++) { |
... | ... | |
732 | 743 |
|
733 | 744 |
int numTextures; |
734 | 745 |
numTextures = drawable.getOrCreateStateSet().getNumTextureStages(); |
735 |
Vector<Texture2D> vector = drawable.getOrCreateStateSet().getTextureAttributeVector(); |
|
746 |
Vector<Texture2D> vector = drawable.getOrCreateStateSet() |
|
747 |
.getTextureAttributeVector(); |
|
736 | 748 |
Vector<Integer> stages = new Vector<Integer>(); |
737 | 749 |
|
738 |
//Util.logger.log(Level.FINEST, "NumTextures: " + numTextures); |
|
750 |
// Util.logger.log(Level.FINEST, "NumTextures: " + numTextures);
|
|
739 | 751 |
for (int i = 0; i < numTextures; i++) { |
740 | 752 |
|
741 | 753 |
try { |
... | ... | |
802 | 814 |
for (int i = 0; i < _textures.size(); i++) { |
803 | 815 |
|
804 | 816 |
try { |
805 |
//Util.logger.log(Level.FINEST, "Num textures in stack: " |
|
806 |
// + _textures.get(i).size());
|
|
817 |
// Util.logger.log(Level.FINEST, "Num textures in stack: "
|
|
818 |
// + _textures.get(i).size());
|
|
807 | 819 |
_textures.get(i).lastElement(); |
808 | 820 |
try { |
809 |
//Util.logger.log(Level.FINEST, "TRYING STAGE: " + i); |
|
821 |
// Util.logger.log(Level.FINEST, "TRYING STAGE: " + i);
|
|
810 | 822 |
image = _textures.get(i).lastElement().getImage() |
811 | 823 |
.getBufferedImage(); |
812 | 824 |
_content.addTextureToSolid(solid, i, image); |
... | ... | |
829 | 841 |
return null; |
830 | 842 |
} |
831 | 843 |
|
832 |
|
|
833 | 844 |
} |
Also available in: Unified diff