Revision 29088
tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/libGPE-OSG/src/main/java/org/gvsig/driver/OSGDriver.java | ||
---|---|---|
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 |
* |
|
30 |
*/ |
|
31 |
package org.gvsig.driver; |
|
32 |
|
|
33 |
import java.awt.Color; |
|
34 |
import java.awt.geom.Point2D; |
|
35 |
import java.awt.image.BufferedImage; |
|
36 |
import java.util.Vector; |
|
37 |
import java.util.logging.Level; |
|
38 |
|
|
39 |
import org.gvsig.GeometryFactory3D; |
|
40 |
import org.gvsig.fmap.geom.GeometryManager; |
|
41 |
import org.gvsig.fmap.geom.primitive.AbstractPrimitive; |
|
42 |
import org.gvsig.geometries3D.Material; |
|
43 |
import org.gvsig.geometries3D.MultiGeometry; |
|
44 |
import org.gvsig.geometries3D.MultiSolid; |
|
45 |
import org.gvsig.geometries3D.Point3D; |
|
46 |
import org.gvsig.geometries3D.PrimitiveSet; |
|
47 |
import org.gvsig.geometries3D.Solid; |
|
48 |
import org.gvsig.gpe.IGPEContentHandler3D; |
|
49 |
import org.gvsig.gpe.parser.GPEContentHandler; |
|
50 |
import org.gvsig.osgvp.util.Util; |
|
51 |
|
|
52 |
/** |
|
53 |
* @author rgaitan |
|
54 |
* |
|
55 |
*/ |
|
56 |
public class OSGDriver extends GPEContentHandler implements |
|
57 |
IGPEContentHandler3D { |
|
58 |
|
|
59 |
private MultiGeometry _root; |
|
60 |
|
|
61 |
@Override |
|
62 |
public Object startMultiGeometry(String id, String srs) { |
|
63 |
Util.logger.log(Level.FINEST, "Starting MultiGeometry"); |
|
64 |
MultiGeometry feature = (MultiGeometry) ((GeometryFactory3D) GeometryManager |
|
65 |
.getInstance().getGeometryFactory()).createMultiGeometry(id); |
|
66 |
if (_root == null) |
|
67 |
_root = feature; |
|
68 |
return feature; |
|
69 |
} |
|
70 |
|
|
71 |
public Object startMultiSolid(String id, String srs) { |
|
72 |
Util.logger.log(Level.FINEST, "Starting MultiSolid"); |
|
73 |
return (MultiSolid) ((GeometryFactory3D) GeometryManager.getInstance() |
|
74 |
.getGeometryFactory()).createMultiSolid(id); |
|
75 |
} |
|
76 |
|
|
77 |
public void endMultiSolid(Object solid) { |
|
78 |
} |
|
79 |
|
|
80 |
public Object startSolid(String id, String srs) { |
|
81 |
// Util.logger.log(Level.FINEST,"Starting Geometry"); |
|
82 |
Solid geometry = (Solid) ((GeometryFactory3D) GeometryManager |
|
83 |
.getInstance().getGeometryFactory()).createSolid(id); |
|
84 |
return geometry; |
|
85 |
} |
|
86 |
|
|
87 |
public void endSolid(Object geometry) { |
|
88 |
// Util.logger.log(Level.FINEST,"Ending Geometry"); |
|
89 |
|
|
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
public void addGeometryToMultiGeometry(Object geometry, Object multiGeometry) { |
|
94 |
// Util.logger.log(Level.FINEST,"Adding Feature to Feature"); |
|
95 |
((MultiGeometry) multiGeometry) |
|
96 |
.addGeometry((AbstractPrimitive) geometry); |
|
97 |
} |
|
98 |
|
|
99 |
public void addSolidToMultiSolid(Object solid, Object multiSolid) { |
|
100 |
// Util.logger.log(Level.FINEST,"Adding Geometry to Feature"); |
|
101 |
((MultiSolid) multiSolid).addSolid((Solid) solid); |
|
102 |
} |
|
103 |
|
|
104 |
public void startSolidVertexArray(Object geometry) { |
|
105 |
} |
|
106 |
|
|
107 |
public void endSolidVertexArray() { |
|
108 |
} |
|
109 |
|
|
110 |
public void startSolidNormalArray(Object geometry) { |
|
111 |
} |
|
112 |
|
|
113 |
public void endSolidNormalArray() { |
|
114 |
} |
|
115 |
|
|
116 |
public void startSolidColorArray(Object geometry) { |
|
117 |
|
|
118 |
} |
|
119 |
|
|
120 |
public void endSolidColorArray() { |
|
121 |
} |
|
122 |
|
|
123 |
public void startSolidTexCoordArray(Object geometry, int nTexCoords, |
|
124 |
int stage) { |
|
125 |
} |
|
126 |
|
|
127 |
public void endSolidTexCoordArray() { |
|
128 |
} |
|
129 |
|
|
130 |
public void addVertexToSolid(Object geometry, double x, double y, double z) { |
|
131 |
|
|
132 |
Point3D point = (Point3D) ((GeometryFactory3D) GeometryManager |
|
133 |
.getInstance().getGeometryFactory()).createPoint3D(""); |
|
134 |
point.setX(x); |
|
135 |
point.setY(y); |
|
136 |
point.setZ(z); |
|
137 |
((Solid) geometry).getVertices().add(point); |
|
138 |
// Util.logger.log(Level.FINEST,"Adding Vertex"); |
|
139 |
} |
|
140 |
|
|
141 |
public void addNormalToSolid(Object geometry, double x, double y, double z) { |
|
142 |
Point3D point = (Point3D) ((GeometryFactory3D) GeometryManager |
|
143 |
.getInstance().getGeometryFactory()).createPoint3D(""); |
|
144 |
point.setX(x); |
|
145 |
point.setY(y); |
|
146 |
point.setZ(z); |
|
147 |
((Solid) geometry).getNormals().add(point); |
|
148 |
Util.logger.log(Level.FINEST, "Adding Normal" + point.getX()); |
|
149 |
} |
|
150 |
|
|
151 |
public void addTextureToSolid(Object geometry, int stage, |
|
152 |
BufferedImage image) { |
|
153 |
|
|
154 |
((Solid) geometry).getTextures().add(stage, image); |
|
155 |
|
|
156 |
} |
|
157 |
|
|
158 |
public void setNormalBindingToSolid(Object geometry, int mode) { |
|
159 |
|
|
160 |
((Solid) geometry).setNormalBinding(mode); |
|
161 |
|
|
162 |
} |
|
163 |
|
|
164 |
public void setColorBindingToSolid(Object geometry, int mode) { |
|
165 |
|
|
166 |
((Solid) geometry).setColorBinding(mode); |
|
167 |
|
|
168 |
} |
|
169 |
|
|
170 |
public void addColorToSolid(Object geometry, float r, float g, float b, |
|
171 |
float a) { |
|
172 |
|
|
173 |
((Solid) geometry).getColors().add(convertColor(r, g, b, a)); |
|
174 |
|
|
175 |
} |
|
176 |
|
|
177 |
public void addTextureCoordinateToSolid(Object geometry, double x, |
|
178 |
double y, int stage) { |
|
179 |
try { |
|
180 |
((Solid) geometry).getTexcoord().get(stage); |
|
181 |
} catch (ArrayIndexOutOfBoundsException ex) { |
|
182 |
((Solid) geometry).getTexcoord().add(stage, new Vector<Point2D>()); |
|
183 |
} |
|
184 |
Point2D point = new Point2D.Double(); |
|
185 |
point.setLocation(x, y); |
|
186 |
((Solid) geometry).getTexcoord().get(stage).add(point); |
|
187 |
|
|
188 |
} |
|
189 |
|
|
190 |
public MultiGeometry getRootFeature() { |
|
191 |
return _root; |
|
192 |
} |
|
193 |
|
|
194 |
public void addPrimitiveSetToSolid(Object geometry, Object primitiveSet) { |
|
195 |
((Solid) geometry).getPrimitiveSets().add((PrimitiveSet) primitiveSet); |
|
196 |
} |
|
197 |
|
|
198 |
public void addIndexToPrimitiveSet(Object primitiveSet, int i) { |
|
199 |
((PrimitiveSet) primitiveSet).getIndices().add(i); |
|
200 |
} |
|
201 |
|
|
202 |
public void endPrimitiveSet(Object primitiveSet) { |
|
203 |
} |
|
204 |
|
|
205 |
public void endPrimitiveSetIndexArray() { |
|
206 |
} |
|
207 |
|
|
208 |
public Object startPrimitiveSet(int mode, int type) { |
|
209 |
return new PrimitiveSet(mode, type); |
|
210 |
} |
|
211 |
|
|
212 |
public void startPrimitiveSetIndexArray(Object primitiveSet, int indices) { |
|
213 |
((PrimitiveSet) primitiveSet).setIndices(new Vector<Integer>()); |
|
214 |
} |
|
215 |
|
|
216 |
public void addMaterialToSolid(Object solid, Object material) { |
|
217 |
((Solid) solid).setMaterial((Material) material); |
|
218 |
|
|
219 |
} |
|
220 |
|
|
221 |
public void endMaterial(Object material) { |
|
222 |
|
|
223 |
} |
|
224 |
|
|
225 |
public Object startMaterial() { |
|
226 |
Material material = new Material(); |
|
227 |
return material; |
|
228 |
} |
|
229 |
|
|
230 |
public void addAmbientToMaterial(Object material, float r, float g, |
|
231 |
float b, float a) { |
|
232 |
|
|
233 |
((Material) material).setAmbient(convertColor(r, g, b, a)); |
|
234 |
|
|
235 |
} |
|
236 |
|
|
237 |
public void addDiffuseToMaterial(Object material, float r, float g, |
|
238 |
float b, float a) { |
|
239 |
|
|
240 |
((Material) material).setDiffuse(convertColor(r, g, b, a)); |
|
241 |
|
|
242 |
} |
|
243 |
|
|
244 |
public void addEmissionToMaterial(Object material, float r, float g, |
|
245 |
float b, float a) { |
|
246 |
|
|
247 |
((Material) material).setEmission(convertColor(r, g, b, a)); |
|
248 |
|
|
249 |
} |
|
250 |
|
|
251 |
public void addShininessToMaterial(Object material, float s) { |
|
252 |
|
|
253 |
((Material) material).setShininess(s); |
|
254 |
|
|
255 |
} |
|
256 |
|
|
257 |
public void addSpecularToMaterial(Object material, float r, float g, |
|
258 |
float b, float a) { |
|
259 |
|
|
260 |
((Material) material).setSpecular(convertColor(r, g, b, a)); |
|
261 |
|
|
262 |
} |
|
263 |
|
|
264 |
protected Color convertColor(float r, float g, float b, float a) { |
|
265 |
|
|
266 |
int _r, _g, _b, _a; |
|
267 |
|
|
268 |
_r = Math.min((int) (r * 255), 255); |
|
269 |
_g = Math.min((int) (g * 255), 255); |
|
270 |
_b = Math.min((int) (b * 255), 255); |
|
271 |
_a = Math.min((int) (a * 255), 255); |
|
272 |
|
|
273 |
Color color = new Color(_r, _g, _b, _a); |
|
274 |
|
|
275 |
return color; |
|
276 |
|
|
277 |
} |
|
278 |
|
|
279 |
public void addBlendingToSolid(Object solid, boolean blending) { |
|
280 |
|
|
281 |
((Solid) solid).setBlending(blending); |
|
282 |
|
|
283 |
} |
|
284 |
|
|
285 |
} |
tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/libGPE-OSG/src/main/java/org/gvsig/gpe/IGPEContentHandler3D.java | ||
---|---|---|
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; |
|
30 |
|
|
31 |
import java.awt.image.BufferedImage; |
|
32 |
|
|
33 |
import org.gvsig.gpe.parser.IGPEContentHandler; |
|
34 |
|
|
35 |
public interface IGPEContentHandler3D extends IGPEContentHandler { |
|
36 |
|
|
37 |
public Object startSolid(String id, String srs); |
|
38 |
|
|
39 |
public void endSolid(Object solid); |
|
40 |
|
|
41 |
public Object startMultiSolid(String id, String srs); |
|
42 |
|
|
43 |
public void endMultiSolid(Object solid); |
|
44 |
|
|
45 |
public void addSolidToMultiSolid(Object solid, Object feature); |
|
46 |
|
|
47 |
public void startSolidVertexArray(Object solid); |
|
48 |
|
|
49 |
public void endSolidVertexArray(); |
|
50 |
|
|
51 |
public void startSolidNormalArray(Object solid); |
|
52 |
|
|
53 |
public void endSolidNormalArray(); |
|
54 |
|
|
55 |
public void startSolidColorArray(Object solid); |
|
56 |
|
|
57 |
public void endSolidColorArray(); |
|
58 |
|
|
59 |
public void startSolidTexCoordArray(Object solid, int nTexCoords, int stage); |
|
60 |
|
|
61 |
public void endSolidTexCoordArray(); |
|
62 |
|
|
63 |
public void addVertexToSolid(Object solid, double x, double y, double z); |
|
64 |
|
|
65 |
public void addNormalToSolid(Object solid, double x, double y, double z); |
|
66 |
|
|
67 |
public void addTextureToSolid(Object geometry, int stage, BufferedImage image); |
|
68 |
|
|
69 |
public void setNormalBindingToSolid(Object solid, int mode ); |
|
70 |
|
|
71 |
public void setColorBindingToSolid(Object solid, int mode ); |
|
72 |
|
|
73 |
public void addColorToSolid(Object solid, float r, float g, float b, float a); |
|
74 |
|
|
75 |
public void addTextureCoordinateToSolid(Object solid, double x, double y, int stage); |
|
76 |
|
|
77 |
public Object startPrimitiveSet(int mode, int type); |
|
78 |
|
|
79 |
public void endPrimitiveSet(Object primitiveSet); |
|
80 |
|
|
81 |
public void addPrimitiveSetToSolid(Object solid, Object primitiveSet); |
|
82 |
|
|
83 |
public void startPrimitiveSetIndexArray(Object primitiveSet, int nIndices); |
|
84 |
|
|
85 |
public void endPrimitiveSetIndexArray(); |
|
86 |
|
|
87 |
public void addIndexToPrimitiveSet(Object primitiveSet, int i); |
|
88 |
|
|
89 |
public Object startMaterial(); |
|
90 |
|
|
91 |
public void addMaterialToSolid(Object solid, Object material); |
|
92 |
|
|
93 |
public void endMaterial(Object material); |
|
94 |
|
|
95 |
public void addAmbientToMaterial(Object material, float r, float g, float b, float a); |
|
96 |
|
|
97 |
public void addDiffuseToMaterial(Object material, float r, float g, float b, float a); |
|
98 |
|
|
99 |
public void addSpecularToMaterial(Object material, float r, float g, float b, float a); |
|
100 |
|
|
101 |
public void addEmissionToMaterial(Object material, float r, float g, float b, float a); |
|
102 |
|
|
103 |
public void addShininessToMaterial(Object material, float s); |
|
104 |
|
|
105 |
public void addBlendingToSolid(Object solid, boolean blending); |
|
106 |
|
|
107 |
} |
tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/libGPE-OSG/src/main/java/org/gvsig/gpe/osg/OSGParser.java | ||
---|---|---|
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 |
package org.gvsig.gpe.osg; |
|
29 |
|
|
30 |
import java.awt.Color; |
|
31 |
import java.awt.image.BufferedImage; |
|
32 |
import java.io.FileNotFoundException; |
|
33 |
import java.lang.reflect.Constructor; |
|
34 |
import java.net.URI; |
|
35 |
import java.util.NoSuchElementException; |
|
36 |
import java.util.Stack; |
|
37 |
import java.util.Vector; |
|
38 |
import java.util.logging.Level; |
|
39 |
|
|
40 |
import org.gvsig.gpe.IGPEContentHandler3D; |
|
41 |
import org.gvsig.gpe.parser.GPEParser; |
|
42 |
import org.gvsig.osgvp.AutoTransform; |
|
43 |
import org.gvsig.osgvp.DrawArrayLengths; |
|
44 |
import org.gvsig.osgvp.Drawable; |
|
45 |
import org.gvsig.osgvp.Geode; |
|
46 |
import org.gvsig.osgvp.Geometry; |
|
47 |
import org.gvsig.osgvp.Group; |
|
48 |
import org.gvsig.osgvp.Material; |
|
49 |
import org.gvsig.osgvp.Matrix; |
|
50 |
import org.gvsig.osgvp.MatrixTransform; |
|
51 |
import org.gvsig.osgvp.Node; |
|
52 |
import org.gvsig.osgvp.PositionAttitudeTransform; |
|
53 |
import org.gvsig.osgvp.PrimitiveSet; |
|
54 |
import org.gvsig.osgvp.Quat; |
|
55 |
import org.gvsig.osgvp.Texture2D; |
|
56 |
import org.gvsig.osgvp.Vec2; |
|
57 |
import org.gvsig.osgvp.Vec3; |
|
58 |
import org.gvsig.osgvp.Vec4; |
|
59 |
import org.gvsig.osgvp.osgDB; |
|
60 |
import org.gvsig.osgvp.exceptions.node.ChildIndexOutOfBoundsExceptions; |
|
61 |
import org.gvsig.osgvp.exceptions.node.LoadNodeException; |
|
62 |
import org.gvsig.osgvp.exceptions.node.NodeException; |
|
63 |
import org.gvsig.osgvp.exceptions.texture.TextureStageException; |
|
64 |
import org.gvsig.osgvp.util.Util; |
|
65 |
|
|
66 |
public class OSGParser extends GPEParser { |
|
67 |
|
|
68 |
Stack<Matrix> _transforms = new Stack<Matrix>(); |
|
69 |
Vector<Stack<Texture2D>> _textures = new Vector<Stack<Texture2D>>(); |
|
70 |
Stack<Material> _materials = new Stack<Material>(); |
|
71 |
Stack<Boolean> _blendings = new Stack<Boolean>(); |
|
72 |
private IGPEContentHandler3D _content; |
|
73 |
private String description; |
|
74 |
private String name; |
|
75 |
|
|
76 |
public OSGParser(String name, String description) { |
|
77 |
// super(name, description); |
|
78 |
this.name = name; |
|
79 |
this.description = description; |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public String getDescription() { |
|
84 |
// TODO Auto-generated method stub |
|
85 |
return this.description; |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
89 |
public String getName() { |
|
90 |
// TODO Auto-generated method stub |
|
91 |
return this.name; |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public boolean accept(URI uri) { |
|
96 |
if ((uri.getPath().toUpperCase().endsWith("OSG")) |
|
97 |
|| (uri.getPath().toUpperCase().endsWith("3DS")) |
|
98 |
|| (uri.getPath().toUpperCase().endsWith("IVE")) |
|
99 |
|| (uri.getPath().toUpperCase().endsWith("OBJ"))) { |
|
100 |
return true; |
|
101 |
} |
|
102 |
return false; |
|
103 |
} |
|
104 |
|
|
105 |
public String[] getFormats() { |
|
106 |
String[] formats = new String[4]; |
|
107 |
formats[0] = "OSG"; |
|
108 |
formats[1] = "3DS"; |
|
109 |
formats[2] = "OBJ"; |
|
110 |
formats[3] = "IVE"; |
|
111 |
return formats; |
|
112 |
} |
|
113 |
|
|
114 |
public String[] getVersions() { |
|
115 |
String[] versions = new String[1]; |
|
116 |
versions[0] = "All"; |
|
117 |
return versions; |
|
118 |
} |
|
119 |
|
|
120 |
@Override |
|
121 |
protected void parseStream() { |
|
122 |
|
|
123 |
} |
|
124 |
|
|
125 |
@Override |
|
126 |
protected void parseURI() { |
|
127 |
|
|
128 |
// This is a very bad hack to avoid testing hangs in Mac OS Lepard |
|
129 |
Color color = new Color(0, 0, 0, 255); |
|
130 |
// TODO remove this hack |
|
131 |
|
|
132 |
Vector<Integer> addedTextures = new Vector<Integer>(); |
|
133 |
boolean addedMaterial = false; |
|
134 |
|
|
135 |
_content = (IGPEContentHandler3D) getContentHandler(); |
|
136 |
// Util.logger.log(Level.FINEST, getMainFile().getPath()); |
|
137 |
Node root=null; |
|
138 |
|
|
139 |
try { |
|
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 |
} |
|
149 |
|
|
150 |
root = osgDB.readNodeFile(path); |
|
151 |
// root = osgDB.readNodeFile(getMainFile().getPath().substring(1, getMainFile().getPath().length())); |
|
152 |
|
|
153 |
} catch (LoadNodeException e) { |
|
154 |
// TODO Auto-generated catch block |
|
155 |
e.printStackTrace(); |
|
156 |
return; |
|
157 |
} catch (FileNotFoundException e) { |
|
158 |
// TODO Auto-generated catch block |
|
159 |
e.printStackTrace(); |
|
160 |
return; |
|
161 |
} |
|
162 |
if (root == null) |
|
163 |
// Util.logger.log(Level.FINEST, "Cannot open" |
|
164 |
// + getMainFile().getPath()); |
|
165 |
System.out.println("error"); |
|
166 |
else { |
|
167 |
|
|
168 |
Object multiGeometry; |
|
169 |
multiGeometry = _content.startMultiGeometry("", ""); |
|
170 |
|
|
171 |
if (root.className().equals("Geode")) { |
|
172 |
|
|
173 |
Geode rootGeode = new Geode(root.getCPtr()); |
|
174 |
Object multiSolid; |
|
175 |
|
|
176 |
multiSolid = _content.startMultiSolid("", ""); |
|
177 |
|
|
178 |
_content.addGeometryToMultiGeometry(multiSolid, multiGeometry); |
|
179 |
|
|
180 |
try { |
|
181 |
addedTextures = pushTextures(rootGeode); |
|
182 |
} catch (NodeException e) { |
|
183 |
} |
|
184 |
try { |
|
185 |
addedMaterial = pushMaterial(rootGeode); |
|
186 |
} catch (NodeException e) { |
|
187 |
} |
|
188 |
|
|
189 |
_blendings.push(rootGeode.getOrCreateStateSet().getEnabledBlending()); |
|
190 |
|
|
191 |
for (int i = 0; i < rootGeode.getNumDrawables(); i++) { |
|
192 |
|
|
193 |
try { |
|
194 |
parseDrawable(rootGeode.getDrawable(i), multiSolid); |
|
195 |
} catch (ChildIndexOutOfBoundsExceptions e) { |
|
196 |
e.printStackTrace(); |
|
197 |
return; |
|
198 |
} catch (NodeException e) { |
|
199 |
} |
|
200 |
|
|
201 |
} |
|
202 |
|
|
203 |
_blendings.pop(); |
|
204 |
_content.endMultiSolid(multiSolid); |
|
205 |
|
|
206 |
} |
|
207 |
|
|
208 |
else if (root.className().equals("Group")) { |
|
209 |
Group rootGroup; |
|
210 |
|
|
211 |
try { |
|
212 |
rootGroup = new Group(root.getCPtr()); |
|
213 |
} catch (NodeException e) { |
|
214 |
// TODO Auto-generated catch block |
|
215 |
e.printStackTrace(); |
|
216 |
return; |
|
217 |
} |
|
218 |
try { |
|
219 |
addedTextures = pushTextures(rootGroup); |
|
220 |
} catch (NodeException e) { |
|
221 |
} |
|
222 |
try { |
|
223 |
addedMaterial = pushMaterial(rootGroup); |
|
224 |
} catch (NodeException e) { |
|
225 |
} |
|
226 |
_blendings.push(rootGroup.getOrCreateStateSet().getEnabledBlending()); |
|
227 |
|
|
228 |
//System.out.println("CHILDREN: " + rootGroup.getNumChildren()); |
|
229 |
|
|
230 |
for (int i = 0; i < rootGroup.getNumChildren(); i++) { |
|
231 |
|
|
232 |
try { |
|
233 |
parseNode(rootGroup.getChild(i), multiGeometry); |
|
234 |
} catch (ChildIndexOutOfBoundsExceptions e) { |
|
235 |
e.printStackTrace(); |
|
236 |
return; |
|
237 |
} |
|
238 |
// Util.logger.log(Level.FINEST, "Node parsed"); |
|
239 |
} |
|
240 |
|
|
241 |
_blendings.pop(); |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
else { |
|
246 |
|
|
247 |
// Util.logger.log(Level.FINEST, |
|
248 |
// "First parsed object must be Group or Geode"); |
|
249 |
|
|
250 |
} |
|
251 |
|
|
252 |
popTextures(addedTextures); |
|
253 |
if (addedMaterial) |
|
254 |
_materials.pop(); |
|
255 |
_content.endMultiGeometry(multiGeometry); |
|
256 |
|
|
257 |
} |
|
258 |
|
|
259 |
} |
|
260 |
|
|
261 |
protected void parseNode(Node node, Object parent) { |
|
262 |
// Util.logger.log(Level.FINEST, "node init"); |
|
263 |
Node instance; |
|
264 |
boolean isTransform = false; |
|
265 |
boolean addedMaterial = false; |
|
266 |
Vector<Integer> addedTextures = new Vector<Integer>(); |
|
267 |
|
|
268 |
try { |
|
269 |
|
|
270 |
Class<?> reflect = Class.forName("org.gvsig.osgvp." |
|
271 |
+ node.className()); |
|
272 |
Constructor<?> builder = reflect |
|
273 |
.getConstructor(new Class[] { long.class }); |
|
274 |
instance = (Node) builder |
|
275 |
.newInstance(new Object[] { node.getCPtr() }); |
|
276 |
|
|
277 |
} |
|
278 |
|
|
279 |
catch (Exception e) { |
|
280 |
instance = new Node(node.getCPtr()); |
|
281 |
} |
|
282 |
|
|
283 |
if (instance instanceof Group) { |
|
284 |
|
|
285 |
Object multiGeometry; |
|
286 |
multiGeometry = _content.startMultiGeometry("", ""); |
|
287 |
_content.addGeometryToMultiGeometry(multiGeometry, parent); |
|
288 |
isTransform = pushTransform((Group) instance); |
|
289 |
try { |
|
290 |
addedTextures = pushTextures(instance); |
|
291 |
} catch (NodeException e) { |
|
292 |
} |
|
293 |
try { |
|
294 |
addedMaterial = pushMaterial(instance); |
|
295 |
} catch (NodeException e) { |
|
296 |
} |
|
297 |
if (_blendings.lastElement()) |
|
298 |
_blendings.push(true); |
|
299 |
else |
|
300 |
_blendings.push(instance.getOrCreateStateSet() |
|
301 |
.getEnabledBlending()); |
|
302 |
for (int i = 0; i < ((Group) instance).getNumChildren(); i++) { |
|
303 |
|
|
304 |
try { |
|
305 |
parseNode(((Group) instance).getChild(i), multiGeometry); |
|
306 |
} catch (ChildIndexOutOfBoundsExceptions e) { |
|
307 |
e.printStackTrace(); |
|
308 |
return; |
|
309 |
} |
|
310 |
|
|
311 |
} |
|
312 |
if (isTransform) |
|
313 |
_transforms.pop(); |
|
314 |
if (addedMaterial) |
|
315 |
_materials.pop(); |
|
316 |
_blendings.pop(); |
|
317 |
popTextures(addedTextures); |
|
318 |
_content.endMultiGeometry(multiGeometry); |
|
319 |
|
|
320 |
} |
|
321 |
|
|
322 |
else if (instance instanceof Geode) { |
|
323 |
|
|
324 |
Object multiSolid; |
|
325 |
multiSolid = _content.startMultiSolid("", ""); |
|
326 |
_content.addGeometryToMultiGeometry(multiSolid, parent); |
|
327 |
try { |
|
328 |
addedTextures = pushTextures(instance); |
|
329 |
} catch (NodeException e) { |
|
330 |
} |
|
331 |
try { |
|
332 |
addedMaterial = pushMaterial(instance); |
|
333 |
} catch (NodeException e) { |
|
334 |
} |
|
335 |
if (_blendings.lastElement()) |
|
336 |
_blendings.push(true); |
|
337 |
else |
|
338 |
_blendings.push(instance.getOrCreateStateSet() |
|
339 |
.getEnabledBlending()); |
|
340 |
for (int i = 0; i < ((Geode) instance).getNumDrawables(); i++) { |
|
341 |
|
|
342 |
try { |
|
343 |
parseDrawable(((Geode) instance).getDrawable(i), multiSolid); |
|
344 |
} catch (ChildIndexOutOfBoundsExceptions e) { |
|
345 |
e.printStackTrace(); |
|
346 |
return; |
|
347 |
} catch (NodeException e) { |
|
348 |
} |
|
349 |
|
|
350 |
} |
|
351 |
if (addedMaterial) |
|
352 |
_materials.pop(); |
|
353 |
_blendings.pop(); |
|
354 |
popTextures(addedTextures); |
|
355 |
_content.endMultiSolid(multiSolid); |
|
356 |
|
|
357 |
} |
|
358 |
// Util.logger.log(Level.FINEST, "Node parsed-0"); |
|
359 |
// else Util.logger.log(Level.FINEST,instance.className() + " is not |
|
360 |
// instanceof |
|
361 |
// Group or Geode"); |
|
362 |
|
|
363 |
} |
|
364 |
|
|
365 |
protected void parseDrawable(Drawable drawable, Object feature) |
|
366 |
throws NodeException { |
|
367 |
Util.logger.log(Level.FINEST, "drawable init"); |
|
368 |
int t = 0; |
|
369 |
if (drawable instanceof Geometry) { |
|
370 |
|
|
371 |
int j; |
|
372 |
Object solid; |
|
373 |
solid = _content.startSolid("", ""); |
|
374 |
_content.addSolidToMultiSolid(solid, feature); |
|
375 |
|
|
376 |
Matrix matrix = new Matrix(); |
|
377 |
for (int i = 0; i < _transforms.size(); i++) { |
|
378 |
|
|
379 |
matrix.mult(_transforms.get(i), matrix); |
|
380 |
|
|
381 |
} |
|
382 |
|
|
383 |
// Util.logger.log(Level.FINEST, "transforms"); |
|
384 |
|
|
385 |
Vector<Vec3> vertices = ((Geometry) drawable).getVertexArray(); |
|
386 |
if (vertices == null) |
|
387 |
vertices = new Vector<Vec3>(); |
|
388 |
Vec3 vertex; |
|
389 |
int i; |
|
390 |
// Util.logger.log(Level.FINEST, "vertex starts"); |
|
391 |
_content.startSolidVertexArray(solid); |
|
392 |
for (i = 0; i < vertices.size(); i++) { |
|
393 |
|
|
394 |
vertex = vertices.get(i); |
|
395 |
|
|
396 |
// Util.logger.log(Level.FINEST,"Vertice sin |
|
397 |
// transformar"+vertex.x()+";"+vertex.y()+";"+vertex.z()+";"); |
|
398 |
vertex = matrix.prod(vertex, matrix); |
|
399 |
|
|
400 |
// Util.logger.log(Level.FINEST,"Vertice |
|
401 |
// transformado"+vertex.x()+";"+vertex.y()+";"+vertex.z()+";"); |
|
402 |
_content.addVertexToSolid(solid, vertex.x(), vertex.y(), vertex |
|
403 |
.z()); |
|
404 |
|
|
405 |
} |
|
406 |
_content.endSolidVertexArray(); |
|
407 |
|
|
408 |
Vector<Vec3> normals = ((Geometry) drawable).getNormalArray(); |
|
409 |
// Util.logger.log(Level.FINEST, "talla normals" + normals.size()); |
|
410 |
|
|
411 |
if (normals == null) |
|
412 |
normals = new Vector<Vec3>(); |
|
413 |
|
|
414 |
Vec3 normal; |
|
415 |
_content.startSolidNormalArray(solid); |
|
416 |
|
|
417 |
for (i = 0; i < normals.size(); i++) { |
|
418 |
|
|
419 |
normal = normals.get(i); |
|
420 |
// Util.logger.log(Level.FINEST, " normal bucleee" + normal); |
|
421 |
normal = matrix.prod(normal, matrix); |
|
422 |
normal.normalize(); |
|
423 |
_content.addNormalToSolid(solid, normal.x(), normal.y(), normal |
|
424 |
.z()); |
|
425 |
|
|
426 |
} |
|
427 |
_content.endSolidNormalArray(); |
|
428 |
|
|
429 |
_content.setNormalBindingToSolid(solid, ((Geometry) drawable) |
|
430 |
.getNormalBinding()); |
|
431 |
|
|
432 |
try { |
|
433 |
Vector<Vec4> colors = ((Geometry) drawable).getColorArray(); |
|
434 |
if (colors == null) |
|
435 |
colors = new Vector<Vec4>(); |
|
436 |
Vec4 color; |
|
437 |
// Util.logger.log(Level.FINEST, "color starts" + |
|
438 |
// colors.size()); |
|
439 |
_content.startSolidColorArray(solid); |
|
440 |
for (i = 0; i < colors.size(); i++) { |
|
441 |
// Util.logger.log(Level.FINEST, "bucleeeeee 0"); |
|
442 |
color = colors.get(i); |
|
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"); |
|
447 |
} |
|
448 |
|
|
449 |
_content.endSolidColorArray(); |
|
450 |
|
|
451 |
} catch (NullPointerException e) { |
|
452 |
|
|
453 |
} |
|
454 |
|
|
455 |
// Util.logger.log(Level.FINEST, "primitiveSets: " |
|
456 |
// + ((Geometry) drawable).getNumPrimitiveSets()); |
|
457 |
|
|
458 |
for (int k = 0; k < ((Geometry) drawable).getNumPrimitiveSets(); k++) { |
|
459 |
int mode = ((Geometry) drawable).getPrimitiveSet(k).getMode(); |
|
460 |
int type = ((Geometry) drawable).getPrimitiveSet(k).getType(); |
|
461 |
|
|
462 |
if (type == PrimitiveSet.Type.DrawArrayLengthsPrimitiveType) { |
|
463 |
|
|
464 |
int offset = 0; |
|
465 |
int accum = 0; |
|
466 |
DrawArrayLengths lengths = new DrawArrayLengths( |
|
467 |
((PrimitiveSet) ((Geometry) drawable) |
|
468 |
.getPrimitiveSet(k)).getCPtr()); |
|
469 |
Vector<Integer> arrayLengths = lengths |
|
470 |
.getElementLengthsVector(); |
|
471 |
|
|
472 |
if (arrayLengths == null) |
|
473 |
arrayLengths = new Vector<Integer>(); |
|
474 |
|
|
475 |
for (int h = 0; h < arrayLengths.size(); h++) { |
|
476 |
|
|
477 |
Object primitiveSet = _content.startPrimitiveSet(mode, |
|
478 |
PrimitiveSet.Type.DrawArraysPrimitiveType); |
|
479 |
_content.addPrimitiveSetToSolid(solid, primitiveSet); |
|
480 |
|
|
481 |
accum = arrayLengths.get(h); |
|
482 |
|
|
483 |
for (int l = 0; l < accum; l++) { |
|
484 |
|
|
485 |
_content.addIndexToPrimitiveSet(primitiveSet, |
|
486 |
((Geometry) drawable).getPrimitiveSet(k) |
|
487 |
.index(offset + l)); |
|
488 |
|
|
489 |
} |
|
490 |
|
|
491 |
offset = offset + accum; |
|
492 |
_content.endPrimitiveSetIndexArray(); |
|
493 |
_content.endPrimitiveSet(primitiveSet); |
|
494 |
|
|
495 |
} |
|
496 |
|
|
497 |
} else { |
|
498 |
Object primitiveSet = _content |
|
499 |
.startPrimitiveSet(mode, type); |
|
500 |
|
|
501 |
_content.addPrimitiveSetToSolid(solid, primitiveSet); |
|
502 |
_content.startPrimitiveSetIndexArray(primitiveSet, |
|
503 |
((Geometry) drawable).getPrimitiveSet(k) |
|
504 |
.getNumIndices()); |
|
505 |
// Util.logger.log(Level.FINEST, "Num Indices: " |
|
506 |
// + String.valueOf(((Geometry) drawable) |
|
507 |
// .getPrimitiveSet(k).getNumIndices())); |
|
508 |
for (int ps = 0; ps < ((Geometry) drawable) |
|
509 |
.getPrimitiveSet(k).getNumIndices(); ps++) { |
|
510 |
|
|
511 |
// Util.logger.log(Level.FINEST, "adding index"); |
|
512 |
_content.addIndexToPrimitiveSet(primitiveSet, |
|
513 |
((Geometry) drawable).getPrimitiveSet(k).index( |
|
514 |
ps)); |
|
515 |
// Util.logger.log(Level.FINEST, String.valueOf(t)); |
|
516 |
// t++; |
|
517 |
} |
|
518 |
_content.endPrimitiveSetIndexArray(); |
|
519 |
_content.endPrimitiveSet(primitiveSet); |
|
520 |
} |
|
521 |
|
|
522 |
} |
|
523 |
|
|
524 |
Vector<Integer> addedTextures = new Vector<Integer>(); |
|
525 |
boolean addedMaterial = false; |
|
526 |
|
|
527 |
addedTextures = pushTexturesDrawable(drawable); |
|
528 |
|
|
529 |
// Util.logger.log(Level.FINEST, "Added textures: " + |
|
530 |
// addedTextures); |
|
531 |
|
|
532 |
try { |
|
533 |
addTexturesToGeometry(solid); |
|
534 |
} catch (Exception e) { |
|
535 |
|
|
536 |
e.printStackTrace(); |
|
537 |
} |
|
538 |
|
|
539 |
// Util.logger.log(Level.FINEST, "getNumTextures" |
|
540 |
// + drawable.getOrCreateStateSet().getNumTextureStages()); |
|
541 |
for (j = 0; j < drawable.getOrCreateStateSet() |
|
542 |
.getNumTextureStages(); j++) { |
|
543 |
|
|
544 |
try { |
|
545 |
if (drawable.getOrCreateStateSet().getTextureAttribute(j) != null) { |
|
546 |
Vector<Vec2> texCoords = ((Geometry) drawable) |
|
547 |
.getTexCoordArray(j); |
|
548 |
if (texCoords == null) |
|
549 |
texCoords = new Vector<Vec2>(); |
|
550 |
Vec2 texCoord; |
|
551 |
|
|
552 |
_content.startSolidTexCoordArray(solid, texCoords |
|
553 |
.size(), j); |
|
554 |
|
|
555 |
for (i = 0; i < texCoords.size(); i++) { |
|
556 |
|
|
557 |
texCoord = texCoords.get(i); |
|
558 |
_content.addTextureCoordinateToSolid(solid, |
|
559 |
texCoord.x(), texCoord.y(), j); |
|
560 |
|
|
561 |
} |
|
562 |
_content.endSolidTexCoordArray(); |
|
563 |
} |
|
564 |
} catch (TextureStageException e) { |
|
565 |
// TODO Auto-generated catch block |
|
566 |
e.printStackTrace(); |
|
567 |
} |
|
568 |
} |
|
569 |
|
|
570 |
addedMaterial = pushMaterialDrawable(drawable); |
|
571 |
try { |
|
572 |
|
|
573 |
Material osgMaterial = _materials.lastElement(); |
|
574 |
|
|
575 |
float x, y, z, w; |
|
576 |
|
|
577 |
Vec4 vectorAmb = new Vec4(); |
|
578 |
Vec4 vectorDif = new Vec4(); |
|
579 |
Vec4 vectorEmi = new Vec4(); |
|
580 |
Vec4 vectorSpe = new Vec4(); |
|
581 |
|
|
582 |
vectorAmb = osgMaterial.getAmbient(Material.Face.FRONT); |
|
583 |
vectorDif = osgMaterial.getDiffuse(Material.Face.FRONT); |
|
584 |
vectorEmi = osgMaterial.getEmission(Material.Face.FRONT); |
|
585 |
vectorSpe = osgMaterial.getSpecular(Material.Face.FRONT); |
|
586 |
|
|
587 |
Object material = _content.startMaterial(); |
|
588 |
x = (float) vectorAmb.x(); |
|
589 |
y = (float) vectorAmb.y(); |
|
590 |
z = (float) vectorAmb.z(); |
|
591 |
w = (float) vectorAmb.w(); |
|
592 |
|
|
593 |
_content.addAmbientToMaterial(material, x, y, z, w); |
|
594 |
|
|
595 |
x = (float) vectorDif.x(); |
|
596 |
y = (float) vectorDif.y(); |
|
597 |
z = (float) vectorDif.z(); |
|
598 |
w = (float) vectorDif.w(); |
|
599 |
|
|
600 |
_content.addDiffuseToMaterial(material, x, y, z, w); |
|
601 |
|
|
602 |
x = (float) vectorSpe.x(); |
|
603 |
y = (float) vectorSpe.y(); |
|
604 |
z = (float) vectorSpe.z(); |
|
605 |
w = (float) vectorSpe.w(); |
|
606 |
|
|
607 |
_content.addSpecularToMaterial(material, x, y, z, w); |
|
608 |
|
|
609 |
x = (float) vectorEmi.x(); |
|
610 |
y = (float) vectorEmi.y(); |
|
611 |
z = (float) vectorEmi.z(); |
|
612 |
w = (float) vectorEmi.w(); |
|
613 |
|
|
614 |
_content.addEmissionToMaterial(material, x, y, z, w); |
|
615 |
|
|
616 |
_content.addShininessToMaterial(material, osgMaterial |
|
617 |
.getShininess(Material.Face.FRONT)); |
|
618 |
|
|
619 |
_content.addMaterialToSolid(solid, material); |
|
620 |
|
|
621 |
_content.endMaterial(material); |
|
622 |
|
|
623 |
} catch (ArrayIndexOutOfBoundsException ex) { |
|
624 |
|
|
625 |
} |
|
626 |
|
|
627 |
if (_blendings.lastElement()) |
|
628 |
_content.addBlendingToSolid(solid, true); |
|
629 |
else |
|
630 |
_content.addBlendingToSolid(solid, drawable |
|
631 |
.getOrCreateStateSet().getEnabledBlending()); |
|
632 |
|
|
633 |
popTextures(addedTextures); |
|
634 |
|
|
635 |
_content.endSolid(solid); |
|
636 |
|
|
637 |
} |
|
638 |
// Util.logger.log(Level.FINEST, "drawable parsed"); |
|
639 |
} |
|
640 |
|
|
641 |
protected boolean pushTransform(Group group) { |
|
642 |
|
|
643 |
if (group instanceof MatrixTransform) { |
|
644 |
|
|
645 |
// Util.logger.log(Level.FINEST,"Push a MatrixTransform"); |
|
646 |
_transforms.push(((MatrixTransform) group).getMatrix()); |
|
647 |
|
|
648 |
return true; |
|
649 |
|
|
650 |
} |
|
651 |
|
|
652 |
if (group instanceof PositionAttitudeTransform) { |
|
653 |
|
|
654 |
// Util.logger.log(Level.FINEST,"Push a PAT"); |
|
655 |
Matrix scaleMatrix = Matrix |
|
656 |
.scale(((PositionAttitudeTransform) group).getScale()); |
|
657 |
|
|
658 |
Quat quat = new Quat((((PositionAttitudeTransform) group) |
|
659 |
.getAttitudeAngle()), (((PositionAttitudeTransform) group) |
|
660 |
.getAttitudeAxis())); |
|
661 |
Matrix rotateMatrix = Matrix.rotate(quat); |
|
662 |
|
|
663 |
Matrix transMatrix = Matrix |
|
664 |
.translate(((PositionAttitudeTransform) group) |
|
665 |
.getPosition()); |
|
666 |
|
|
667 |
// rotateMatrix.postMult(scaleMatrix); |
|
668 |
// transMatrix.postMult(rotateMatrix); |
|
669 |
rotateMatrix.preMult(scaleMatrix); |
|
670 |
transMatrix.preMult(rotateMatrix); |
|
671 |
|
|
672 |
_transforms.push(transMatrix); |
|
673 |
|
|
674 |
return true; |
|
675 |
|
|
676 |
} |
|
677 |
|
|
678 |
if (group instanceof AutoTransform) { |
|
679 |
|
|
680 |
// Util.logger.log(Level.FINEST,"Push a AutoTransform"); |
|
681 |
Matrix scaleMatrix = Matrix.scale(((AutoTransform) group) |
|
682 |
.getScale()); |
|
683 |
Quat quat = new Quat((((AutoTransform) group).getRotationAngle()), |
|
684 |
(((AutoTransform) group).getRotationAxis())); |
|
685 |
Matrix rotateMatrix = Matrix.rotate(quat); |
|
686 |
Matrix transMatrix = Matrix.translate(((AutoTransform) group) |
|
687 |
.getPosition()); |
|
688 |
|
|
689 |
// rotateMatrix.postMult(scaleMatrix); |
|
690 |
// transMatrix.postMult(rotateMatrix); |
|
691 |
|
|
692 |
rotateMatrix.preMult(scaleMatrix); |
|
693 |
transMatrix.preMult(rotateMatrix); |
|
694 |
|
|
695 |
_transforms.push(transMatrix); |
|
696 |
|
|
697 |
return true; |
|
698 |
|
|
699 |
} |
|
700 |
|
|
701 |
return false; |
|
702 |
|
|
703 |
} |
|
704 |
|
|
705 |
protected Vector<Integer> pushTextures(Node node) throws NodeException { |
|
706 |
|
|
707 |
int numTextures; |
|
708 |
numTextures = node.getOrCreateStateSet().getNumTextureStages(); |
|
709 |
Vector<Texture2D> vector = node.getOrCreateStateSet() |
|
710 |
.getTextureAttributeVector(); |
|
711 |
Vector<Integer> stages = new Vector<Integer>(); |
|
712 |
|
|
713 |
for (int i = 0; i < numTextures; i++) { |
|
714 |
|
|
715 |
_textures.get(i); |
|
716 |
|
|
717 |
_textures.add(i, new Stack<Texture2D>()); |
|
718 |
|
|
719 |
_textures.get(i).push(vector.get(i)); |
|
720 |
// Util.logger.log(Level.FINEST,"PUSH"); |
|
721 |
stages.add(i); |
|
722 |
|
|
723 |
} |
|
724 |
|
|
725 |
return stages; |
|
726 |
} |
|
727 |
|
|
728 |
protected boolean pushMaterial(Node node) throws NodeException { |
|
729 |
|
|
730 |
boolean hasMaterial = false; |
|
731 |
|
|
732 |
Material material; |
|
733 |
material = node.getOrCreateStateSet().getMaterial(); |
|
734 |
_materials.push(material); |
|
735 |
hasMaterial = true; |
|
736 |
|
|
737 |
return hasMaterial; |
|
738 |
|
|
739 |
} |
|
740 |
|
|
741 |
protected Vector<Integer> pushTexturesDrawable(Drawable drawable) |
|
742 |
throws NodeException { |
|
743 |
|
|
744 |
int numTextures; |
|
745 |
numTextures = drawable.getOrCreateStateSet().getNumTextureStages(); |
|
746 |
Vector<Texture2D> vector = drawable.getOrCreateStateSet() |
|
747 |
.getTextureAttributeVector(); |
|
748 |
Vector<Integer> stages = new Vector<Integer>(); |
|
749 |
|
|
750 |
// Util.logger.log(Level.FINEST, "NumTextures: " + numTextures); |
|
751 |
for (int i = 0; i < numTextures; i++) { |
|
752 |
|
|
753 |
try { |
|
754 |
|
|
755 |
_textures.get(i); |
|
756 |
|
|
757 |
} catch (ArrayIndexOutOfBoundsException ex) { |
|
758 |
|
|
759 |
_textures.add(i, new Stack<Texture2D>()); |
|
760 |
|
|
761 |
} |
|
762 |
|
|
763 |
try { |
|
764 |
|
|
765 |
_textures.get(i).push(vector.get(i)); |
|
766 |
// Util.logger.log(Level.FINEST,"PUSH"); |
|
767 |
stages.add(i); |
|
768 |
Util.logger.log(Level.FINEST, "Added textures: " + stages); |
|
769 |
} catch (ArrayIndexOutOfBoundsException ex) { |
|
770 |
|
|
771 |
} |
|
772 |
} |
|
773 |
|
|
774 |
return stages; |
|
775 |
} |
|
776 |
|
|
777 |
protected boolean pushMaterialDrawable(Drawable draw) throws NodeException { |
|
778 |
|
|
779 |
boolean hasMaterial = false; |
|
780 |
|
|
781 |
try { |
|
782 |
|
|
783 |
Material material; |
|
784 |
material = draw.getOrCreateStateSet().getMaterial(); |
|
785 |
_materials.push(material); |
|
786 |
hasMaterial = true; |
|
787 |
|
|
788 |
} catch (ArrayIndexOutOfBoundsException ex) { |
|
789 |
|
|
790 |
hasMaterial = false; |
|
791 |
|
|
792 |
} catch (NullPointerException e) { |
|
793 |
|
|
794 |
} |
|
795 |
|
|
796 |
return hasMaterial; |
|
797 |
|
|
798 |
} |
|
799 |
|
|
800 |
protected void popTextures(Vector<Integer> stages) { |
|
801 |
|
|
802 |
for (int i = 0; i < stages.size(); i++) { |
|
803 |
|
|
804 |
// Util.logger.log(Level.FINEST,"POP"); |
|
805 |
_textures.get(stages.get(i)).pop(); |
|
806 |
|
|
807 |
} |
|
808 |
|
|
809 |
} |
|
810 |
|
|
811 |
protected void addTexturesToGeometry(Object solid) throws Exception { |
|
812 |
|
|
813 |
BufferedImage image; |
|
814 |
for (int i = 0; i < _textures.size(); i++) { |
|
815 |
|
|
816 |
try { |
|
817 |
// Util.logger.log(Level.FINEST, "Num textures in stack: " |
|
818 |
// + _textures.get(i).size()); |
|
819 |
_textures.get(i).lastElement(); |
|
820 |
try { |
|
821 |
// Util.logger.log(Level.FINEST, "TRYING STAGE: " + i); |
|
822 |
image = _textures.get(i).lastElement().getImage() |
|
823 |
.getBufferedImage(); |
|
824 |
_content.addTextureToSolid(solid, i, image); |
|
825 |
|
|
826 |
} catch (ArrayIndexOutOfBoundsException ex) { |
|
827 |
|
|
828 |
} |
|
829 |
} |
|
830 |
|
|
831 |
catch (NoSuchElementException ex) { |
|
832 |
|
|
833 |
} |
|
834 |
} |
|
835 |
|
|
836 |
} |
|
837 |
|
|
838 |
@Override |
|
839 |
public String getFormat() { |
|
840 |
// TODO Auto-generated method stub |
|
841 |
return null; |
|
842 |
} |
|
843 |
|
|
844 |
} |
tags/gvSIG_3D_Animation_1_0_SNAPSHOT_build_9/libraries/libGPE-OSG/src/main/resources/dumptruck.osg | ||
---|---|---|
1 |
Group { |
|
2 |
UniqueID Group_0 |
|
3 |
DataVariance STATIC |
|
4 |
cullingActive TRUE |
|
5 |
num_children 1 |
|
6 |
Geode { |
|
7 |
DataVariance DYNAMIC |
|
8 |
name "dumptruck.osg" |
|
9 |
cullingActive TRUE |
|
10 |
num_drawables 3 |
|
11 |
Geometry { |
|
12 |
DataVariance DYNAMIC |
|
13 |
StateSet { |
|
14 |
UniqueID StateSet_1 |
|
15 |
DataVariance STATIC |
|
16 |
rendering_hint OPAQUE_BIN |
|
17 |
renderBinMode INHERIT |
|
18 |
GL_CULL_FACE OFF |
|
19 |
GL_LIGHTING ON |
|
20 |
Material { |
|
21 |
DataVariance STATIC |
|
22 |
ColorMode OFF |
|
23 |
ambientColor 0.2 0.2 0.2 1 |
|
24 |
diffuseColor 0.8 0.8 0.8 1 |
|
25 |
specularColor 0 0 0 1 |
|
26 |
emissionColor 0 0 0 1 |
|
27 |
shininess 0 |
|
28 |
} |
|
29 |
} |
|
30 |
useDisplayList TRUE |
|
31 |
Primitives 1 |
|
32 |
{ |
|
33 |
DrawArrayLengths TRIANGLE_STRIP 0 907 |
|
34 |
{ |
|
35 |
3 3 3 3 3 3 3 3 |
|
36 |
3 3 3 3 3 3 3 3 |
|
37 |
3 3 3 3 3 3 3 3 |
|
38 |
3 3 3 3 3 3 3 3 |
|
39 |
3 3 3 3 3 3 3 3 |
|
40 |
3 3 3 3 3 3 3 3 |
|
41 |
3 3 3 3 3 3 3 3 |
|
42 |
4 4 4 4 4 4 4 4 |
|
43 |
4 4 4 4 4 4 4 4 |
|
44 |
4 4 4 4 4 4 4 4 |
|
45 |
4 4 4 4 4 4 4 4 |
|
46 |
4 4 4 4 4 4 4 4 |
|
47 |
4 4 4 4 4 4 4 4 |
|
48 |
4 4 4 4 4 4 4 4 |
|
49 |
4 4 4 4 4 4 4 4 |
|
50 |
4 4 4 4 4 4 4 4 |
|
51 |
4 4 4 4 4 4 4 4 |
|
52 |
4 4 4 4 4 4 4 4 |
|
53 |
4 4 4 4 4 4 4 4 |
|
54 |
4 4 4 4 4 4 4 4 |
|
55 |
4 4 4 4 4 4 4 4 |
|
56 |
4 4 4 4 4 4 4 4 |
|
57 |
4 4 4 4 4 4 4 4 |
|
58 |
4 4 4 4 4 4 4 4 |
|
59 |
4 4 4 4 4 4 4 4 |
|
60 |
4 4 4 4 4 4 4 4 |
|
61 |
4 4 4 4 4 4 4 4 |
|
62 |
4 4 4 4 4 4 4 4 |
|
63 |
4 4 4 4 4 4 4 4 |
|
64 |
4 4 4 4 4 4 4 4 |
|
65 |
4 4 4 4 4 4 4 4 |
|
66 |
4 4 4 4 4 4 4 4 |
|
67 |
4 4 4 4 4 4 4 4 |
|
68 |
4 4 4 4 4 4 4 4 |
|
69 |
4 4 4 4 4 4 4 4 |
|
70 |
4 4 4 4 4 4 4 4 |
|
71 |
4 4 4 4 4 4 4 4 |
|
72 |
4 4 4 4 4 4 4 4 |
|
73 |
4 4 4 4 4 4 4 4 |
|
74 |
4 4 4 4 4 4 4 4 |
|
75 |
4 4 4 4 4 4 4 4 |
|
76 |
4 4 4 4 4 4 4 4 |
|
77 |
4 4 4 4 4 4 4 4 |
|
78 |
4 4 4 4 4 4 4 4 |
|
79 |
4 4 4 4 4 4 4 4 |
|
80 |
4 4 4 4 4 4 4 4 |
|
81 |
4 4 4 4 4 4 4 4 |
|
82 |
4 4 4 4 4 4 62 62 |
|
83 |
62 62 62 62 30 62 62 62 |
|
84 |
62 62 62 62 62 62 62 62 |
|
85 |
62 62 62 42 42 42 42 42 |
|
86 |
42 42 42 82 42 42 42 42 |
|
87 |
42 42 42 42 42 42 42 42 |
|
88 |
82 42 42 42 42 20 42 42 |
|
89 |
42 42 42 42 42 42 42 42 |
|
90 |
42 42 42 42 42 42 22 22 |
|
91 |
22 22 22 22 22 22 22 22 |
|
92 |
22 22 22 22 22 22 22 22 |
|
93 |
22 22 22 22 22 22 22 22 |
|
94 |
22 22 22 22 22 22 22 22 |
|
95 |
22 22 22 22 22 22 22 22 |
|
96 |
10 22 22 22 22 10 22 22 |
|
97 |
22 22 22 22 22 22 22 22 |
|
98 |
22 10 22 22 22 22 10 22 |
|
99 |
22 22 22 22 22 22 62 62 |
|
100 |
62 62 30 62 62 62 62 30 |
|
101 |
62 62 62 62 62 62 62 62 |
|
102 |
62 62 62 30 62 62 62 62 |
|
103 |
30 62 62 62 62 62 62 62 |
|
104 |
36 26 9 10 10 9 15 34 |
|
105 |
10 12 26 26 11 12 26 12 |
|
106 |
24 5 10 11 42 6 14 14 |
|
107 |
6 6 8 9 5 9 5 6 |
|
108 |
10 6 5 6 5 6 8 8 |
|
109 |
11 6 5 12 6 14 14 6 |
|
110 |
14 14 8 5 8 5 5 6 |
|
111 |
7 6 8 5 9 6 9 5 |
|
112 |
5 5 21 8 19 6 6 6 |
|
113 |
10 7 7 9 8 14 6 14 |
|
114 |
12 10 30 6 6 6 6 5 |
|
115 |
6 6 5 13 8 6 7 5 |
|
116 |
6 10 8 8 8 8 6 10 |
|
117 |
8 8 8 8 6 10 8 7 |
|
118 |
6 6 5 8 6 6 6 5 |
|
119 |
6 6 11 14 6 11 14 6 |
|
120 |
8 12 6 12 6 14 11 7 |
|
121 |
5 7 8 7 5 15 9 8 |
|
122 |
8 11 27 7 5 8 5 90 |
|
123 |
5 14 5 5 17 8 6 9 |
|
124 |
11 18 16 5 8 8 8 8 |
|
125 |
8 8 8 6 10 8 8 8 |
|
126 |
8 6 10 8 6 6 7 6 |
|
127 |
6 8 7 8 8 8 8 6 |
|
128 |
19 5 8 8 8 10 5 7 |
|
129 |
9 12 12 7 12 11 6 9 |
|
130 |
10 5 8 5 7 20 7 5 |
|
131 |
7 15 14 7 9 24 11 11 |
|
132 |
12 6 19 17 19 5 7 48 |
|
133 |
38 6 6 55 12 7 6 6 |
|
134 |
13 11 9 8 11 8 7 12 |
|
135 |
8 8 5 12 6 6 6 28 |
|
136 |
8 24 28 28 20 8 24 5 |
|
137 |
6 6 5 10 5 6 9 7 |
|
138 |
6 6 6 6 5 6 6 6 |
|
139 |
6 6 6 6 5 6 6 6 |
|
140 |
38 20 20 6 6 14 14 14 |
|
141 |
14 14 14 14 14 10 10 10 |
|
142 |
10 5 6 5 6 9 9 10 |
|
143 |
10 10 10 16 16 16 16 16 |
|
144 |
16 16 16 6 5 6 9 6 |
|
145 |
13 5 8 6 12 12 10 10 |
|
146 |
10 10 16 16 16 16 16 16 |
|
147 |
16 16 6 6 5 8 9 7 |
|
148 |
6 12 12 |
|
149 |
} |
|
150 |
} |
|
151 |
VertexArray 11813 |
|
152 |
{ |
|
153 |
0.912526 5.25919 2.51182 |
|
154 |
0.983379 5.26351 2.53055 |
|
155 |
0.911395 5.16927 2.56377 |
|
156 |
0.980369 5.26365 2.88188 |
|
157 |
1.03139 5.33888 2.81326 |
|
158 |
0.98109 5.35779 2.88185 |
|
159 |
0.909998 5.36319 2.89936 |
|
160 |
0.98109 5.35779 2.88185 |
|
161 |
0.911127 5.45311 2.84741 |
|
162 |
1.40123 -0.66679 0.82615 |
|
163 |
0.81107 -0.72166 0.68056 |
|
164 |
1.24693 -0.68022 0.67832 |
|
165 |
8.00494 4.90679 -2.17661 |
|
166 |
8.05065 4.75217 -2.01154 |
|
167 |
8.00487 4.70141 -2.17659 |
|
168 |
8.07061 5.41762 -1.58063 |
|
169 |
8.01113 5.13042 -1.7139 |
|
170 |
8.06831 5.41759 -1.75462 |
|
171 |
2.6651 2.36112 0.54797 |
|
172 |
2.50071 2.35788 0.65041 |
|
173 |
2.66463 1.5618 0.54797 |
|
174 |
-0.72413 -0.92084 -2.02524 |
|
175 |
1.24014 -0.8774 -2.04662 |
|
176 |
-0.709098 -0.92715 -1.96685 |
|
177 |
1.85515 3.8041 2.93252 |
|
178 |
1.94398 3.84689 2.88252 |
|
179 |
1.84478 3.84695 2.88252 |
|
180 |
1.97795 2.937 2.93252 |
|
181 |
2.06678 2.97982 2.88906 |
|
182 |
1.96758 2.97988 2.88906 |
|
183 |
-0.741482 4.82057 -2.12957 |
|
184 |
1.2435 4.80199 -2.04662 |
|
185 |
1.23732 4.79579 -2.15336 |
|
186 |
2.66611 4.75493 -2.20671 |
|
187 |
3.50519 4.9885 -2.35739 |
|
188 |
3.49545 4.92738 -2.42669 |
|
189 |
-1.07378 4.79543 0.24847 |
|
190 |
1.6295 4.73294 0.24847 |
|
191 |
-1.03116 4.87393 -1.27463 |
|
192 |
3.93119 -0.86987 -0.989677 |
|
193 |
4.49223 -0.65996 -0.92682 |
|
194 |
3.18164 -0.92128 -1.02674 |
|
195 |
6.56315 -1.9181 -1.31203 |
|
196 |
4.82088 -1.76135 -1.14517 |
|
197 |
4.84026 -1.89248 -1.30202 |
|
198 |
7.81534 -1.86797 -1.36381 |
|
199 |
7.88025 -1.84835 -1.32664 |
|
200 |
7.82223 -1.86455 -1.32178 |
|
201 |
7.88408 0.33768 -2.8309 |
|
202 |
7.82644 0.20219 -2.91162 |
|
203 |
7.82662 0.50406 -2.91162 |
|
204 |
8.05658 3.62542 -2.59138 |
|
205 |
7.82852 3.71461 -2.91162 |
|
206 |
7.82428 5.71737 -2.917 |
|
207 |
7.90816 1.95835 -2.0004 |
|
208 |
7.90741 0.84053 -2.00175 |
|
209 |
7.90873 3.07616 -2.00175 |
|
210 |
7.55832 5.75263 -2.8734 |
|
211 |
7.58808 5.72242 -2.877 |
|
212 |
7.55826 5.65943 -2.8734 |
|
213 |
7.69997 5.85163 -2.91162 |
|
214 |
7.69997 5.85163 -2.71922 |
|
215 |
7.70006 5.99986 -2.71922 |
|
216 |
1.65149 4.39695 2.51895 |
|
217 |
1.50263 4.47952 2.37171 |
|
218 |
1.16645 4.58601 2.4733 |
|
219 |
1.99869 2.85124 2.88839 |
|
220 |
1.64938 2.88416 2.93252 |
|
221 |
1.65289 2.83951 2.91265 |
|
222 |
1.87589 3.7184 2.88252 |
|
223 |
1.57515 3.76203 2.93252 |
|
224 |
1.57865 3.71745 2.89648 |
|
225 |
-1.13143 -0.79911 0.37352 |
|
226 |
-1.03971 -0.65804 2.18329 |
|
227 |
-1.52619 -0.73697 0.37353 |
|
228 |
-1.07714 -0.86809 0.24847 |
|
229 |
-1.07176 -0.80297 0.37352 |
|
230 |
-1.13681 -0.86438 0.24847 |
|
231 |
1.68982 4.43889 2.10838 |
|
232 |
1.79855 4.49407 0.91837 |
|
233 |
1.60973 4.45854 2.11338 |
|
234 |
7.69535 -1.93468 -3.42082 |
|
235 |
7.69535 -1.93468 -3.84602 |
|
236 |
7.69526 -2.08291 -3.84602 |
|
237 |
7.99905 4.24552 -1.06405 |
|
238 |
7.94566 3.79099 0.1857 |
|
239 |
8.03058 4.21573 -1.10895 |
|
240 |
8.03189 5.43741 -1.20559 |
|
241 |
8.03378 5.51106 -1.24934 |
|
242 |
8.00097 5.45279 -1.15911 |
|
243 |
8.01254 4.56692 -1.58371 |
|
244 |
8.05508 4.75218 -1.67282 |
|
245 |
8.01362 4.70143 -1.50661 |
Also available in: Unified diff